Question

Google's not coming to my rescue, here, and I just know this is the perfect place to ask.

I'm writing a custom DirectiveProcessor for a DSL and I want to be able to access a diagram from within my T4 template.

Within my DirectiveProcessor, I've loaded the domain model and my diagram using (wait for it...) LoadModelAndDiagram(...).

So, now the diagram's loaded into the default partition in the Store, but I can't for the life of me work out how to resolve a reference to it later.

Can anyone guide the way?

Was it helpful?

Solution

Well, after lots of further work, I decided I didn't need to access my diagram **from within** a custom DirectiveProcessor.

I've still got a custom DirectiveProcessor because the standard generated one doesn't load the existing diagram when it loads the domain model.

Getting a custom DirectiveProcessor to load the diagram and model at the same time is trivially easy. You subclass the standard generated DirectiveProcessor base class and override:

protected override bool LoadDiagramData
{
    get
    {
        return true;
    }
}

Now, we have the diagram loaded, so to get back to the original question, how do we access it? Like this:

using (Transaction t = partition.Store.TransactionManager
           .BeginTransaction("MyTxn", true))
{
    MyDslDiagram diagram = partition.ElementDirectory
        .FindElements<MyDslDiagram>(true).SingleOrDefault();

    /*
     * Now, do stuff with your diagram.
     *
     */
}

Now, this code works just fine if you have a diagram loaded. If you don't, diagram will come back as null, in which case, we either have to load the diagram explicitly or create one dynamically.

I won't go into that, here. Maybe on my blog when I've had some sleep!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top