ISWIX, LLC View Christopher Painter's profile on LinkedIn profile for Christopher Painter at Stack Overflow, Q&A for professional and enthusiast programmers

July 26, 2009

Maybe I Should Roll My Own Part II

Just over a year ago I played around with .NET object serialization for a day and came up with a simple little program that could build a WiX element tree, set the attributes and write the XML out. I blogged about it here.

Since then I've taken a .NET 3.5 / WCF / WPF / LINQ class and I now realize that LINQ to XML is perfect for this task. For example, consider the simple example of a tool that can switch between designer view and xml view. It can all be done in 10 simple steps:

1) Create a couple of tab pages. Put your designers on one and a richtext box on another.
2) Use XElement.Load() to load the WiX document into an in memory object model.
3) Use XElement.ToString() and pass it off to the RichTextBox.
4) Create an event handler and wire it up to the XElement changd event so that any time something changes in the object model you can refresh the XML view.
5) Use LINQ to query the object model and feed the data into your UI components.
6) Use your UI components to manipulate the objects using LINQ.
7) Wire up the RichTextBox TextChanged event to refresh your UI if the XML changes.
8) Use XElement.Save() to save your changes.
9) Use visual studio integration to wire the tool up to Votive. The concept is to not reinvent the wheel. Just edit the WXS/WXI files out of process and let votive reload the documents after you save your changes.
10) Profit! ( Sorry, Slashdot joke )

Sure, there's a lot of work to do it all correctly but the basic pattern is actually quite simple. So here's a couple screenshots of a (mostly working) program I was able to write in one day.



7 comments:

HUM4N said...

Would you be willing to post your source code for those of us who aint as smart you?

Lloyd said...

Just like human....
Will you share the source code?! :-)

Christopher Painter said...

I'm working on it. I'll make an announcement as soon as I can.

Andrew said...

How did you get the XML to automatically format and have the nice color syntax? I'm guessing that is a rich text box on the XML tab. Looks nice.

Christopher Painter said...

SharpDevelop comes with a nice LGPL syntax highlighting editor control.

Andrew said...

That is really cool ... trying to figure out how to present nice clean indented and colorized XML like that by hand in a richtext box is not fun.

Andrew said...

Thanks so much for the tip Christopher ... I found the control that you were talking about here ...

http://www.codeproject.com/KB/edit/TextEditorControl.aspx?display=Print

And I found some code to do exactly what I want displaying it in a nice format here:

http://community.sharpdevelop.net/forums/p/7534/21330.aspx#21330