Kishore Gopalan

Some basic questions.

Is the "Store" supposed to be used at the level of domain-model or the actual instance of a model

The code examples in the documentation create a Console Application and uses Store.LoadDomainModels() method which takes the type of the domain class as a parameter. Is this an external application that references the Debugging build's assembly, or am I missing something

I created an external application, added reference to the domain-model and wrote this code, but it threw an exception saying FlowGraph must inherit from Microsoft.VisualStudio.Modeling.DomainModel class. (FlowGraph is the root of my domain-model)

Code Snippet

Store store = new Store();

store.LoadDomainModels(typeof(BizModel.FlowGraph));

If I add reference to the Debugging.dll assembly generated by the running build of the domain-model, I don't get access to the model classes.


I'm sure I'm missing out something. Any help is appreciated.

TIA



Re: Visual Studio Extensibility Accessing elements in Store

Edward Bakker

Hi,

Have a look at this code example that loads and instance of a domain model.

Code Snippet

Type[] domainModels = { typeof(Microsoft.VisualStudio.Modeling.Diagrams.CoreDesignSurfaceDomainModel), typeof (MyCompany.TestLanguage.TestLanguageDomainModel),

}

Store store = new Store(domainModels);

using (Transaction transaction = store.TransactionManager.BeginTransaction("Load model", true))

{

TestLanguageSerializationHelper.Instance.LoadModel(store, @"D:\temp\testlanguage1.test", null, null);

transaction.Commit();

}

First we have to initialize the store with the types that exist in our domain model. There for we need to load the domain model MyCompany.TestLanguage.TestLanguageDomainModel (DSL project).

Because our DSL probably contains some shapes we also need to load the CoreDesignSurfaceDomainModel`. Once we have an initialized Store we can load a model instance within a transaction.

After the executing the `LoadModel` method our Store contains the instance of the model and we can do whatever we want with that.

Hope it helps

Edward





Re: Visual Studio Extensibility Accessing elements in Store

Kishore Gopalan

Hi Edward,

Thanks for the inputs. It works well.

Just continuing on the topic, I'm trying to save the changes made to the store by calling Instance.SaveModel method. But unlike while Loading, this time it requirs the SerializationResult to be passed, and not the Store itself. Firstly, why does the design not allow passing the modified Store directly to be saved, and secondly, what is to be seralized - the store I couldn't find a serialize method on Store, so, how is this different from a conventional XmlSerialization we do on objects

TIA





Re: Visual Studio Extensibility Accessing elements in Store

Edward Bakker

Hi,

Yes it is indeed the store (in memory representation of your model) that get's serialized to disk. The SerializationResult is used to warnings and/or errors that might occur during this action.

Have a look at this demo code to see how to load the model, add a new modelelement and save the model.

Code Snippet

Type[] domainModels = {

typeof(Microsoft.VisualStudio.Modeling.Diagrams.CoreDesignSurfaceDomainModel),

typeof(LogicaCMG.Language2.TestLanguageDomainModel),

};

Store store = new Store(domainModels);

ExampleModel modelRoot = null;

using (Transaction transaction = store.TransactionManager.BeginTransaction("Load model", true))

{

TestLanguageSerializationHelper.Instance.LoadModel(store, @"D:\temp\Language2\Debugging\testlanguage1.test", null, null);

ExampleElement newElement = new ExampleElement(store, null);

newElement.Name = "GeneratedFromCode";

ReadOnlyCollection<ModelElement> modelElements = store.ElementDirectory.FindElements(ExampleModel.DomainClassId);

modelRoot = (ExampleModel)modelElements[0];

modelRoot.Elements.Add(newElement);

transaction.Commit();

}

SerializationResult result = new SerializationResult();

TestLanguageSerializationHelper.Instance.SaveModel(result, modelRoot, @"D:\temp\Language2\Debugging\testlanguage1.test");

Edward





Re: Visual Studio Extensibility Accessing elements in Store

Kishore Gopalan

Thanks Edward. I got it working fine. I guess I understood SerializationResult a bit too literally.