Scott Hanselman

The Weekly Source Code 3

August 29, '07 Comments [10] Posted in Source Code
Sponsored By

In my new ongoing quest to read source code to be a better developer, I now present the third in an infinite number of a weekly series called "The Weekly Source Code." Here's some source I'm reading this week that I enjoyed.

  • Paint.NET - It's not just the world's shiniest free .NET paint program, but it's also 140,000 lines of yummy (and very well factored (in parts)) source code. It's all here. A plugin model, COM interop, a Command Dispatcher, crazy WinForms stuff, multi-platform support and even TabletPC usage. You can get the source from SkyOrb.
  • CoPilot.com - This is one of my favorite tools for connecting to a family member's PC when they are in trouble. Plus, it's an extension of VNC which is GPLed, so they make the source available for both Mac and Windows. Reminds me I'm happy to not be coding in C/C++ anymore.
  • JobObjectWrapper - I don't know why, but I love wrapper classes. I just like seeing really clean .NET wrappers to really horrible Win32 APIs. It's like watching a car crash for me; I can't look away. This is a simple API abstraction over the Win32 Job Object.
  • World of Solitaire - This isn't Open Source, but since it's AJAX/JavaScript goodness we can explore it. It's insane. Created by Robert at CosmicRealms, it's a brilliant and amazing piece of cross-browser DHTML.
  • Url Reservation Modifier - I wish utilities like this were built in. This is a GUI and a Library (separation is always nice) to modify URL Reservations in Http.sys (on systems that support it). This lets you hook up System.Net.HttpListeners as a limited user.

Feel free to send me links to cool source that you find hasn't been given a good read.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Speaking at the OCCA - Home Server and Zero Email Bounce

August 28, '07 Comments [5] Posted in Speaking
Sponsored By

I'll be speaking at the Oregon Computer Consultants Association (OCCA) tonight at 7pm-8:30pm. A no-host dinner starts at 6pm. The meeting is Free and Open to the Public.

Topics

"Join Scott Hanselman for a two part presentation:

First - Let go of the psychic weight of the 10000 emails in your Inbox and enjoy the bliss you can get with "zero email bounce." We'll talk about what that is, and how you can implement it in your daily email workflow, in Outlook, or in Gmail and other clients.

Second - We'll talk about Windows Home Server. Scott's been beta testing WHS for the last 6 months and living with it day to day. We'll see what it offers, if you should build or buy and what it provides over one of the off-the-shelf NAS solutions."

Location

Rheinlander German Restaurant
5035 NE Sandy Blvd
Portland OR 97213  (view map)

If you're in the neighborhood this evening, I hope to see you there!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Hanselman Forums - AspNetForum from JitBit

August 28, '07 Comments [5] Posted in Reviews
Sponsored By

WindowClippingI wanted to take a second to not only remind folks of the Forums over at http://hanselman.com/forums, but also to recognize AspNetForum from JitBit and what they've done in the last month or so.

in July I started evaluating Forums Software and tried a number of them and installed three.

I ended up picking the most bare-bones one, at the time, AspNetForum. It costs only US$85, which is insanely cheap. I paid it happily. It's not bare-bones now.

It's ridiculously fast. Head over to the Forums and try it out for yourself. It's easy to modify; It took me all of a half-hour to skin and modify the Master Page to make the forums look like this site, including the very-top navigation.

In the last month I've thrown a pile of suggestions at JitBit on ways they could improve the software and nearly every one has been added, cleanly, within a few weeks. I've since upgraded the forums four times, easily.

Here's some of the cool features (many new) since I launched the forums in July:

They've also got an RSS Feed for their Version History, which is a MicroISV Best Practice if ever I saw one.

JitBit doesn't know me from Adam, I'm just a fan. I paid for their product, they've paid me nothing. I just am really happy with the software I selected for the forums. For $85, I'm very happy with my purchase.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

New XML Schema Designer CTP released for Visual Studio 2008

August 28, '07 Comments [2] Posted in XML
Sponsored By

 A few months ago the XmlTeam teased us with some screenshots and screencasts of a newly redesigned XSD Designer for Visual Studio 2008. It's unclear if this will make it into RTM or if it'll be a quick download/add-in, but regardless today they released CTP1 of the XML Schema Designer (download).

XML Schema Designer

The original schema design surface was more DataSet focused and it would sometimes mess with your Schemas. It was clear (to me at least) that it was schizophrenic to have on designer taking on double duty, especially as folks are making more and more complex Schemas. Here's a books.xsd schema I use for examples, loaded into VS 2008 with the new Schema Explorer on the right.

Also, a tip when writing Xml Schemas in Visual Studio...don't forget to right-click and hit Insert Snippet. The XSD Editor includes a metric butt-load of XSD-specific snippets that are worth using.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Mixing XmlSerializers with XElements and LINQ to XML

August 28, '07 Comments [0] Posted in Learning .NET | LINQ | Programming | XML | XmlSerializer
Sponsored By

I used to mix and match XmlWriters and XmlSerializers when I had objects that I wanted to serialize in the middle of a larger chunk of XmlWriter-generated XML, like this, where the variable a is typeof(Author).

using (XmlWriter writer = 
        XmlWriter.Create(Response.OutputStream, settings))
{
    //Note the artificial, but useful, indenting
    writer.WriteStartDocument();
        writer.WriteStartElement("bookstore");
            writer.WriteStartElement("book");
                writer.WriteStartAttribute("publicationdate");
                    writer.WriteValue(publicationdate);
                writer.WriteEndAttribute();
                writer.WriteStartAttribute("ISBN");
                    writer.WriteValue(isbn);
                writer.WriteEndAttribute();
                writer.WriteElementString("title", "ASP.NET 2.0");
                writer.WriteStartElement("price");
                    writer.WriteValue(price);
                writer.WriteEndElement(); //price
                XmlSerializer xs = factory.CreateSerializer(typeof(Author));
                xs.Serialize(writer, a);
            writer.WriteEndElement(); //book
        writer.WriteEndElement(); //bookstore
    writer.WriteEndDocument();
}

See how there XmlSerializer just writes directly to the XmlWriter and the object is serialized in the middle of the XmlWriter calls? I found this very useful and used it often.

I wanted to do the same thing with LINQ to XML but was ever so frightened. Earlier I punted and just created the XML myself as an XElement tree. See the author "a" in the middle there?:

        XNamespace ns = "http://example.books.com";
        XDocument books = new XDocument(
            new XElement(ns + "bookstore",
                new XElement(ns + "book",
                    new XAttribute("publicationdate", publicationdate),
                    new XAttribute("ISBN", isbn),
                    new XElement(ns + "title", "ASP.NET 2.0 Book"),
                    new XElement(ns + "price", price),
                    new XElement(ns + "author", 
                        new XElement(ns + "first-name", a.FirstName),
                        new XElement(ns + "last-name", a.LastName)
                        )
                    )
               )
            );

Ion on the XmlTeam explained that the XmlWriter returned by calls to CreateWriter on both XDocument and XElement classes is special. After your done using the XmlWriter and it's Close()d, it will take all the generated XML and Add() it to the parent/owner XDocument or XElement.

So, now I can make an extension method and add my SerializeAsXElement method to XmlSerializer:

   static class XmlSerializerExtension {
       public static XElement SerializeAsXElement(this XmlSerializer xs, object o) {
           XDocument d = new XDocument();
           using (XmlWriter w = d.CreateWriter()) xs.Serialize(w, o);
           XElement e = d.Root;
           e.Remove();
           return e;
       }
   }

Notice the use of using to ensure the XmlWriter is close (Close is called in the Dispose of XmlWriter) and that the root element is removed from the document. Ion explains that "This avoids the cloning of the returned element during any subsequent Add() (eg. functional construction)."

Now, I can use the extension method in the middle of my XElement expression.

        XmlSerializer xs = new XmlSerializer(typeof(Author));
        XDocument books = new XDocument(
            new XElement(ns + "bookstore",
                new XElement(ns + "book",
                    new XAttribute("publicationdate", publicationdate),
                    new XAttribute("ISBN", isbn),
                    new XElement(ns + "title", "ASP.NET 2.0 Book"),
                    new XElement(ns + "price", price),
                    xs.SerializeAsXElement(a)
                    )
               )
            );

And it produces XML identical to the XmlWriter example at the beginning. Big thanks to Ion Vasilian (brilliant moderator of the LINQ Project forums and XmlTeam blogger) for all the help with this question.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.