Visual Studio Developer Center > Visual Studio Forums > Visual Studio Extensibility > Reading and writing models in June release?
Ask a questionAsk a question
 

AnswerReading and writing models in June release?

  • Tuesday, June 20, 2006 3:03 PMJos Warmer Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

  • Wednesday, June 21, 2006 1:47 PMJos Warmer Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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.
    public DtoModel LoadDtoModel(String fileName)

    {
    DtoModel result = null; Store store = new Store(); Type[] modelTypes = new Type[] { typeof(Microsoft.VisualStudio.Modeling.Diagrams.CoreDesignSurface), typeof(Ordina.DataContract.Designer.Ordina_DataContract_Designer) }; store.LoadDomainModels(modelTypes); using (Transaction t = store.TransactionManager.BeginTransaction("Reading diagram")) { result = Ordina_DataContract_DesignerSerializationHelper.LoadModel(store, fileName, null); t.Commit(); } return result; }  

    This code does read the model ok.

    Thanks for your help,

    Jos Warmer

  • Monday, June 26, 2006 10:45 PMJing Fan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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

  • Tuesday, June 20, 2006 9:08 PMJose Escrich Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.
  • Wednesday, June 21, 2006 11:56 AMSteve_CookMSFTUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

  • Wednesday, June 21, 2006 1:06 PMJos Warmer Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

  • Wednesday, June 21, 2006 1:47 PMJos Warmer Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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.
    public DtoModel LoadDtoModel(String fileName)

    {
    DtoModel result = null; Store store = new Store(); Type[] modelTypes = new Type[] { typeof(Microsoft.VisualStudio.Modeling.Diagrams.CoreDesignSurface), typeof(Ordina.DataContract.Designer.Ordina_DataContract_Designer) }; store.LoadDomainModels(modelTypes); using (Transaction t = store.TransactionManager.BeginTransaction("Reading diagram")) { result = Ordina_DataContract_DesignerSerializationHelper.LoadModel(store, fileName, null); t.Commit(); } return result; }  

    This code does read the model ok.

    Thanks for your help,

    Jos Warmer

  • Monday, June 26, 2006 10:45 PMJing Fan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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!