Profile Picture

Diagram custom serialization

Posted By Eric Taymans 12 Years Ago
Author
Message
Eric Taymans
Posted 12 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 0, Visits: 1

Dear Support Team,

You are right. The cloning of the sheet in the sub ResetStyleSheets solves also the problem.

Thanks again...

Eric



Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hi Eric,

It seams that the problem is caused by objects reuse. In general in the DDOM you cannot have two parent elements for a single element - in your case there is a probabilty your global stylesheets to be present in two documents, which can lead to unpredictable errors. So when you add your global stylesheets to a document - clone them to create a new stylesheet instance:

Protected Sub ResetStyleSheets()
Dim styleSheets As NStyleSheetCollection = NDrawingDocument1.StyleSheets
Dim GuidelinesSheet As NStyleSheet = styleSheets.GetChildByName("Guidelines")
Dim ConnectorsSheet As NStyleSheet = styleSheets.GetChildByName("Connectors")
styleSheets.RemoveAllChildren()
styleSheets.AddChild(GuidelinesSheet)
styleSheets.AddChild(ConnectorsSheet)

For Each sheet As NStyleSheet In gStyleSheets
NDrawingDocument1.StyleSheets.AddChild(sheet.Clone()) // clone the global sheet here
Next
End Sub

Please let us know if that fixes the error...

Best Regards,
Nevron Support Team



Eric Taymans
Posted 12 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 0, Visits: 1

Dear Support Team,

During the building of the sample project, I found the cause of the problem.

When an NDrawingDocument is viewed, the form that contains the view executes the following code in the Form1_Load

 

Protected Sub ResetStyleSheets()

        Dim styleSheets As NStyleSheetCollection = NDrawingDocument1.StyleSheets

        Dim GuidelinesSheet As NStyleSheet = styleSheets.GetChildByName("Guidelines")

        Dim ConnectorsSheet As NStyleSheet = styleSheets.GetChildByName("Connectors")

        styleSheets.RemoveAllChildren()

        styleSheets.AddChild(GuidelinesSheet)

        styleSheets.AddChild(ConnectorsSheet)

 

        For Each sheet As NStyleSheet In gStyleSheets

            NDrawingDocument1.StyleSheets.AddChild(sheet)

        Next

    End Sub

 

gStyleSheets is a global list of my own StyleSheets.

 

If I remove this code, the problem disappears. If I let it, the problem appears always on the second document after two consecutive save/loads.

 

So, I replaced this Sub by the following code:

 

Protected Sub UpdateStyleSheets()

        Dim styleSheets As NStyleSheetCollection = NDrawingDocument1.StyleSheets

     

        For Each sheet As NStyleSheet In gStyleSheets

            Dim matchingSheet As NStyleSheet = styleSheets.GetChildByName(sheet.Name)

            If matchingSheet Is Nothing Then

                styleSheets.AddChild(sheet)

            End If

        Next

    End Sub

 

It seems to solve the problem!

Let me know If you need the sample project for your own information, I’ll send it to you.

Thanks,

Eric



Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Can you please send us a sample project that demonstrates the issue. It is hard to tell why the element index rebuild fails after a second save/load, without actually debugging the application.

Best Regards,
Nevron Support Team



Eric Taymans
Posted 12 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 0, Visits: 1

I use Nevron Diagram for .Net (Windows forms) to create an object model. I have subclassed shapes to hold my own objects. I want to store the NDocuments with their shapes and my own objects related to the shapes in one binary file.

 

I use one object, myModel, of my class Model containing all related objects and NDocuments.

Before serializing my model object with the following code:

 

  Dim fs As FileStream = New FileStream(filePath, FileMode.Create)

  Dim bf As New BinaryFormatter(Nothing, New StreamingContext(StreamingContextStates.File))

   bf.Serialize(fs, myModel)

   fs.Close()

the following code is executed on each NDocument:

aNDocument.OnSerializing()

 

To load the binary file, the following code is used:

 Dim fs As FileStream = New FileStream(filePath, FileMode.Open)

        Dim bf As New BinaryFormatter(Nothing, New StreamingContext(StreamingContextStates.File))

        mModel = bf.Deserialize(fs)

        fs.Close()

 

After the loading, the following code is executed on each NDocument:

aNDocument.OnDeserialized()

 

It works fine the first time. But after a second save and load the following error occurs on the OnDeserialized method:

 

System.Exception occurred

  Message=The element or one of its descendants has an invalid id

  Source=Nevron.System

  StackTrace:

       at Nevron.Dom.NElementIndex.Rebuild(INElement element)

       at Nevron.Diagram.NDocument.OnDeserialized()

       at SF.Model.OnDeserialized() in C:\Users\ET\Documents\Visual Studio 2010\Projects\SF5\SF5\Model.vb:line 786

  InnerException:

 

Looking at the documentation, I know that there is a Persistency Manager that can be used to save drawings to file but I need to save a whole graph of Nevron objects with my own objects.

I have also seen NReflector.UpdateReferences but I am not sure how and when to use it.

 

Could you help me?

 

Thanks

 

Eric

 





Similar Topics


Reading This Topic