Tim Murphy's .NET Software Architecture Blog

March 2010 Entries

Where I Am Speaking Soon

Open XML and document generation has been my focus lately.  With that being the case I will be speaking on the subject in the near future at the following event.

I hope to see you at one (or more) of these events.

Why Standards Only Get You So Far

Over the years I have been exposed to a number of standards.  EDI was the first.  More recently it has been the CIECA standard for Insurance and now the embattled document standards of Open XML and ODF.

Standards actually came up at the last CAG meeting.  The debate was over how effective they really are.  Even back in the late 80’s to early 90’s people found they had to customize these standards to get any work done.  I even had one vendor about a year ago tell me that they really weren’t standards, they were more of a guideline.

The problem is that standards are created either by committee or by companies trying to sell a product.  They never fit all situations.  This is why most of them leave extension points in their definition.  Of course if you use those extension points everyone has to have custom code to know how to consume the new product.

Standards increase reliability but they stifle innovation and slow the time to market cycle of products.  In this age of ever shortening windows of opportunity that could mean that a company could lose its competitive advantage.

I believe that standards are not only good, but essential.  I also believe that they are not a silver bullet.  People who turn competing standards into a type of holy war are really missing the point.  I think we should make the best standards we can, whether that is for a product so that customers can use API, or by committee so that they cross products.  But they also need to be as feature rich and flexible as possible.  They can’t be just the lowest common denominator since this type of standard will be broken the day it is published.  In the end though, it is the market will vote with their dollars.

del.icio.us Tags: ,,,

Chicago Code Camp Call For Speakers

The Chicago Code Camp is coming up on May 1st, 2010.  They are still looking for speaker.  If you have a rock’n code demonstration that you would like to present to the community be sure to sign up.  If you know someone else who has some ideas that you really think they should share with the world guilt them in to signing up. 


Open XML SDK 2 Released

Note: Cross posted from Coding The Document.

This post is a little late since the SDK was released about a week ago.  At PSC we have been using the Open XML SDK 2 since its earliest beta.  It is a very powerful tool for generating documents without using the Office DLLs.  It is also the main technology that I have been working with for the last six months.  I would suggest giving it a try. 

Stay tuned here.  In the near future I will be presenting at different locations on this and other document generation technologies.

Download the Open XML SDK here.

More Chicago Code Camp Information

It seems the guys have posted the venue.  The Chicago Code Camp will be held at the Illinois Institute of Technology on May 1, 2010.  Sign up and join in.

IIT- Stuart Building
10 West 31st
Chicago, IL 60616


del.icio.us Tags:

Copying A Slide From One Presentation To Another

There are many ways to generate a PowerPoint presentation using Open XML.  The first way is to build it by hand strictly using the SDK.  Alternately you can modify a copy of a base presentation in place.  The third approach to generate a presentation is to build a new presentation from the parts of an existing presentation by copying slides as needed.  This post will focus on the third option.

In order to make this solution a little more elegant I am going to create a VSTO add-in as I did in my previous post.  This one is going to insert Tags to identify slides instead of NonVisualDrawingProperties which I used to identify charts, tables and images.  The code itself is fairly short.

SlideNameForm dialog = new SlideNameForm();
Selection selection = Globals.ThisAddIn.Application.ActiveWindow.Selection;
if(dialog.ShowDialog() == DialogResult.OK)

Zeyad Rajabi has a good post here on combining slides from two presentations.  The example he gives is great if you are doing a straight merge.  But what if you want to use your source file as almost a supermarket where you pick and chose slides and may even insert them repeatedly?  The following code uses the tags we created in the previous step to pick a particular slide an copy it to a destination file.

using (PresentationDocument newDocument = PresentationDocument.Open(OutputFileText.Text,true))
    PresentationDocument templateDocument = PresentationDocument.Open(FileNameText.Text, false);
    uniqueId = GetMaxIdFromChild(newDocument.PresentationPart.Presentation.SlideMasterIdList);
    uint maxId = GetMaxIdFromChild(newDocument.PresentationPart.Presentation.SlideIdList);
    SlidePart oldPart = GetSlidePartByTagName(templateDocument, SlideToCopyText.Text);
    SlidePart newPart = newDocument.PresentationPart.AddPart<SlidePart>(oldPart, "sourceId1");
    SlideMasterPart newMasterPart = newDocument.PresentationPart.AddPart(newPart.SlideLayoutPart.SlideMasterPart);
    SlideIdList idList = newDocument.PresentationPart.Presentation.SlideIdList;
    // create new slide ID
    SlideId newId = new SlideId();
    newId.Id = maxId;
    newId.RelationshipId = "sourceId1";
    // Create new master slide ID
    SlideMasterId newMasterId = new SlideMasterId();
    newMasterId.Id = uniqueId;
    newMasterId.RelationshipId = newDocument.PresentationPart.GetIdOfPart(newMasterPart);
    // change slide layout ID

The GetMaxIDFromChild and FixSlideLayoutID methods are barrowed from Zeyad’s article.  The GetSlidePartByTagName method is listed below.  It is really one LINQ query that finds SlideParts with child Tags that have the requested Name.

private SlidePart GetSlidePartByTagName(PresentationDocument templateDocument, string tagName)
    return (from p in templateDocument.PresentationPart.SlideParts
                    <DocumentFormat.OpenXml.Presentation.Tag>().First().Name ==
            select p).First();

This is what really makes the difference from what Zeyad posted.  The most powerful thing you can have when generating documents from templates is a consistent way of naming items to be manipulated.  I will be show more approaches like this in upcoming posts.

April 2010 Chicago Architects Group Meeting


The Chicago Architects Group will be holding its next meeting on April 20th.  Please come and join us and get involved in our architect community.


Presenter: Matt Hidinger
Topic: Onion Architecture   
Location: Illinois Technology Association
200 S. Wacker Dr., Suite 1500
Room A/B
Chicago, IL 60606
Time: 5:30 - Doors open at 5:00

March 2010 Chicago Architects Group Wrap Up

I would like to thank everyone who came out to last night’s event and especially thank Mike Vogt for the presentation.

I think at first everyone glassed over since very few of us spend a lot of time with Integration Architecture and most of us live more in the application architecture space.  Learning about subject like BPEL and BPMN was refreshing.

The discussion after Mike’s talk was lively and I think that everyone came away with a good idea of areas they might want to know more about.  People stuck around long after the meeting was over.

If you are interested in the topic you can find the slides here.

Be sure to join us next month when Matt Hidinger talks about Onion Architecture.  Details are coming soon.

del.icio.us Tags: ,

200th Post

I didn’t break any speed records getting getting to 200 posts, but I am here.  So what is the prize for getting here?  You have to put out the obligatory post announcing the achievement.  It also means that it is time to put “Yes, I’m a geek” on your business card.  Well, there it is.  Now go about your business.  Nothing to see here.

del.icio.us Tags:

2010 Chicago Code Camp Coming In May

The Lake Count .NET User Group is putting on it’s second Chicago Code Camp on May 1st.  I would encourage everyone to come out and participate in the Chicago area .NET community.  You can register here.  Better yet come of with a presentation of your own.  I have submitted an abstract for a presentation on Office Open XML.

Naming PowerPoint Components With A VSTO Add-In

Note: Cross posted from Coding The Document.

Sometimes in order to work with Open XML we need a little help from other tools.  In this post I am going to describe  a fairly simple solution for marking up PowerPoint presentations so that they can be used as templates and processed using the Open XML SDK.

Add-ins are tools which it can be hard to find information on.  I am going to up the obscurity by adding a Ribbon button.  For my example I am using Visual Studio 2008 and creating a PowerPoint 2007 Add-in project.  To that add a Ribbon Visual Designer.  The new ribbon by default will show up on the Add-in tab.

Add a button to the ribbon.  Also add a WinForm to collect a new name for the object selected.  Make sure to set the OK button’s DialogResult to OK. In the ribbon button click event add the following code.

ObjectNameForm dialog = new ObjectNameForm();
Selection selection = Globals.ThisAddIn.Application.ActiveWindow.Selection;
dialog.objectName = selection.ShapeRange.Name;
if (dialog.ShowDialog() == DialogResult.OK)
    selection.ShapeRange.Name = dialog.objectName;

This code will first read the current Name attribute of the Shape object.  If the user clicks OK on the dialog it save the string value back to the same place.

Once it is done you can retrieve identify the control through Open XML via the NonVisualDisplayProperties objects.  The only problem is that this object is a child of several different classes.  This means that there isn’t just one way to retrieve the value.  Below are a couple of pieces of code to identify the container that you have named.

The first example is if you are naming placeholders in a layout slide.

foreach(var slideMasterPart in slideMasterParts)
    var layoutParts =  slideMasterPart.SlideLayoutParts;
    foreach(SlideLayoutPart slideLayoutPart in layoutParts)
        foreach (assmPresentation.Shape shape in slideLayoutPart.SlideLayout.CommonSlideData.ShapeTree.Descendants<assmPresentation.Shape>())
            var slideMasterProperties =
                from p in shape.Descendants<assmPresentation.NonVisualDrawingProperties>()
                where p.Name == TokenText.Text
                select p;
            if (slideMasterProperties.Count() > 0)
                tokenFound = true;

The second example allows you to find charts that you have named with the add-in.

foreach(var slidePart in slideParts)
    foreach(assmPresentation.Shape slideShape in slidePart.Slide.CommonSlideData.ShapeTree.Descendants<assmPresentation.Shape>())
        var slideProperties = from g in slidePart.Slide.Descendants<GraphicFrame>()
            where g.NonVisualGraphicFrameProperties.NonVisualDrawingProperties.Name == TokenText.Text
            select g;
        if(slideProperties.Count() > 0)
            tokenFound = true;


Together the combination of Open XML and VSTO add-ins make a powerful combination in creating a process for maintaining a template and generating documents from the template.

Architects – Can’t We All Be Friends

Lately I have had some run-ins with structural architects who have warned me that calling myself or our user group Architects is against the law in Illinois.  I still need to sort out if this is actually the case or not, but it makes me ask a number of questions.

Clearly the law was not intended to protect the word Architect.  It was meant to protect the profession and protect the public from people who were practicing architecture without proper training.  We wouldn’t want buildings and bridges falling down.

Since we are not representing ourselves as experts in the design of physical structures why is this such a hot topic?  Personally I don’t care what my title is as long as I am helping to build software that helps people do business.

I think we also need to take this situation as a warning to ourselves.  A lot of the IT community already looks at people with architect titles as being aloof ivory tower types.  Let’s make sure that it doesn’t get to the point where we are claiming that we own words because they were first applied to IT.  Hey, if a bank wants to call their vault a database, knock yourself out.  It is only a word and has meaning within context.

Personally I think they would have a tough time winning a court battle over this since architect has been a title in IT for well over a decade.  If I remember correctly it was the title that Bill Gates held in Microsoft.  Companies such as Allstate have an entire group in their IT call Protection Architecture.

I hope that the few structural architects who have contacted us are not representative of the profession as a whole.  I have to believe that most people with that level of education are much more reasonable.  I hope we can all be civil and not bring lawsuits about things as silly as words.