Reading and writing models in June release?
Hi,
I have used reading and writing of models from and to file in the previous release. This seems to be changed heavily in the June release. I am trying to figure out how to change this to work with the June release, but it would be most helpful if anyone already has some samples.
I am trying to setup a Store thourgh store.LoadDomainModels() method, but run into a
"Microsoft.VisualStudio.Modeling.DomainDataNotFoundException"
Jos Warmer
Answers
I did some more experimenting and found the following:
- If i add Microsoft.VisualStudio.Modeling.Diagrams.CoreDesignSurface to the types array for initalizing the store, the first exception disappears. In the previous release there were several more domain model that needed to be added, but this seems to be the only one left.
- the reading of the model must be within a Transaction, this is new, because it did not need to be inside a transaction in the previous release. When I put the reading inside a transaction the second exception dissappears.
This code does read the model ok.
Thanks for your help,
Jos Warmer
- You're correct that you need to call LoalDomainModels() first before calling SerializationHelper.LoadModel(). In June CTP release, loading CoreDesignSurface model is required as you have discovered; we've fixed it recently so that if your model takes no dependency to CoreDesignSurface model, loading that model will not be required any more. In general, "no dependency to CoreDesignSurface" means you have no Diagram, Shape, Connectors, Designer, or any other UI elements defined in your model. Thanks!
All Replies
- If you already know the domain model that you want to load, you can use the helper class to manage the model serialization. It has a name like [modelname]SerializationHelper. There has methods such as LoadModel and SaveModel also you could Load the diagram model. Although you could make your custom loader based on the generated code in that helper, to do that you will need to pass the DomainModelType, DomainModelMonikerResolverType, ModelElementRootType and the SerializationBehaviorType.
Jos
You have to load the domain models in the correct order: if B depends on A, load A first. That might be causing the problem you see.
-- Steve
jesc,
I found the SerializationHelper.LoadModel and do use it. However, this operation takes a Store as an argument and I am trying to initialize the Store before passing it to the LoadModel method.
My code is as follows:
public DtoModel LoadDtoModel(String fileName) { Store store = new Store(); Type[] modelTypes = new Type[] { typeof(Ordina.DataContract.Designer.Ordina_DataContract_Designer) }; store.LoadDomainModels(modelTypes); return Ordina_DataContract_DesignerSerializationHelper.LoadModel(store, fileName, null); }If I do not initialize the Store using LoadDomainModels(...) , I get an System.InvalidOperationException.
If I try to initialize the store (as shown) I get the orginal Microsoft.VisualStudio.Modeling.DomainDataNotFoundException
Steve, you refer to the correct order of loading domain models, but I am only loading one model. Is there be more that I need to load for one DSL ?
Jos
I did some more experimenting and found the following:
- If i add Microsoft.VisualStudio.Modeling.Diagrams.CoreDesignSurface to the types array for initalizing the store, the first exception disappears. In the previous release there were several more domain model that needed to be added, but this seems to be the only one left.
- the reading of the model must be within a Transaction, this is new, because it did not need to be inside a transaction in the previous release. When I put the reading inside a transaction the second exception dissappears.
This code does read the model ok.
Thanks for your help,
Jos Warmer
- You're correct that you need to call LoalDomainModels() first before calling SerializationHelper.LoadModel(). In June CTP release, loading CoreDesignSurface model is required as you have discovered; we've fixed it recently so that if your model takes no dependency to CoreDesignSurface model, loading that model will not be required any more. In general, "no dependency to CoreDesignSurface" means you have no Diagram, Shape, Connectors, Designer, or any other UI elements defined in your model. Thanks!


