Nevron Forum

PersistencyFormat.CutomBinary and NDrawingDocument clone problems

https://www.nevron.com/Forum/Topic7981.aspx

By Alexey Ochkov - Friday, July 19, 2013

1) When I save NDrawingDocument to PersistencyFormat.CutomBinary (from my program or from standard Nevron.Diagram.Designer.exe) links between ports and plugs are not saved. I send examples docs.zip with document saved in NDB (all links are ok) and CNDB (all links are broken).

2) NDrawingDocument implements ICloneable interface and CloneWithNewUniqueId method, but both possible clone methods fails when called. It is possible to clone NDrawingDocument without saving anl loading it from temporary file or memory stream? (on implementing cloning through save/restore from memory stream I found error with PersistencyFormat.CutomBinary).


By Nevron Support - Thursday, June 4, 2015

Hi,

The problems with connectors serialization in binary format is fixed in the latest version of Nevron Diagram for .NET. In order to clone a drawing document you can now create a simple method that serializes the drawing document to a memory stream in binary format and then deserializes it from the same stream. The following is a simple implementation of such method:

private static NDrawingDocument CloneDocument(NDrawingDocument document)
{
    NDrawingDocument clonedDocument;
    using (MemoryStream stream = new MemoryStream())
    {
        // Serialize the document to stream
        NPersistencyManager manager = new NPersistencyManager();
        manager.Persistentdocument.Sections.Add(new NPersistentSection("Drawing", document));
        manager.SaveToStream(stream, PersistencyFormat.Binary, null);

        // Deserialize the document from the stream
        manager.LoadFromStream(stream, PersistencyFormat.Binary, null);
        clonedDocument = (NDrawingDocument)manager.Persistentdocument.Sections.GetByName("Drawing").Object;
    }

    return clonedDocument;
}