Nevron .NET Vision Documentation
Persistency Manager

The persistency manager extension facilitates the persistency management of different document types. It supports binary, XML and SOAP document serialization. The persistency manager is represented by the NPersistencyManager class, an instance of which can be created on demand:
C#
Copy Code
// create a new persistency manager
NPersistencyManager persistencyManager = new NPersistencyManager();
Visual Basic
Copy Code
' create a new persistency manager
Dim persistencyManager As NPersistencyManager = New NPersistencyManager()
Persistency document and sections

The persistency manager serializes a document, which is organized in sections. The persistent document is represented by the NPersistentDocument class, which contains a collection of NPersistentSection instances. Each section is in fact a named object, which must be serialized. The following code will serialize in XML only one path node:

C#
Copy Code
// create a rectangle
rect = new NRectangleShape(10, 10, 20, 20);

// create a new persistent document NPersistentDocument
document = new NPersistentDocument("My document");

// create a new section which will store the rect
document.Sections.Add(new NPersistentSection("Rectangle", rect);

// set the document to the manager
persistencyManager.PersistentDocument = document;

// save the document to a file
persistencyManager.SaveToFile("c:\\temp\\mysavefile.ndx", PersistencyFormat.XML);

// load the same document from the file
persistencyManager.LoadFromFile("c:\\temp\\mysavefile.ndx", PersistencyFormat.XML);

// get the loaded rectangle
NRectangleShape loadedRect = (persistencyManager.PersistentDocument.Sections[0].Object as NRectangleShape);
Visual Basic
Copy Code
' create a rectangle
Dim rect As New NRectangleShape(10, 10, 20, 20)

' create a new persistency document NPersistencyDocument
Dim document As New NPersistentDocument("My document")

' create a new section which will store the rect
document.Sections.Add(New NPersistentSection("Rectangle", rect))

' set the document to the manager
persistencyManager.PersistentDocument = document

' save the document to a file
persistencyManager.SaveToFile("c:\\temp\\mysavefile.ndx", PersistencyFormat.XML)

' load the same document from the file
persistencyManager.LoadFromFile("c:\\temp\\mysavefile.ndx", PersistencyFormat.XML)

' get the loaded rectangle
Dim loadedRect as NRectangleShape = (persistencyManager.PersistentDocument.Sections.Item(0).Object as NRectangleShape)
Persistency formats

As mentioned the persistency manager supports binary, XML and SOAP serialization. The basic SaveToFile, LoadFromFile, SaveToStream and LoadFromStream methods of the manager request as argument the format which must be used.

In order to dynamically recognize the type of document being loaded from a file the persistency manager assumes that the library and drawing documents are saved in files with the following extensions:

Format Extension
Binary drawing .ndb (stands for Nevron drawing binary)
XML drawing .ndx (stands for Nevron drawing XML)
SOAP drawing .nds (stands for Nevron drawing SOAP)
Binary library .nlb (stands for Nevron library binary)
XML library .nlx (stands for Nevron library XML)
SOAP library .nls (stands for Nevron library SOAP)
Saving documents

The persistency manager provides several methods, which can facilitate the saving of drawing and library documents to files. These are SaveDocumentToFile , SaveLibraryToFile and SaveDrawingToFile . They all have two overrides - the first one accepts only one argument - the document which must be saved, while the second one also accepts the file name in which the document must be saved. The Save methods which do not have a file name argument show a Save File Dialog. In all save methods the persistency format is determined by the file extension. For example:

C#
Copy Code
// save a drawing document to SOAP
NDrawingDocument drawing = new NDrawingDocument();
persistencyManager.SaveDocumentToFile(drawing, "c:\\temp\\drawing1.nds");

// save a drawing document to user selected file (format is determined by the extension)
persistencyManager.SaveDocumentToFile(drawing);
Visual Basic
Copy Code
' save a drawing document to SOAP
Dim drawing As New NDrawingDocument
persistencyManager.SaveDocumentToFile(drawing, "c:\\temp\\drawing1.nds")

' save a drawing document to user selected file (format is determined by the extension)
persistencyManager.SaveDocumentToFile(drawing)
Loading documents

Analogously to document saving the manager provides the following set of methods which can help you load documents from files: LoadDocumentFromFile , LoadLibraryFromFile and LoadDrawingFromFile . The following code loads the drawing saved by the previous example:

C#
Copy Code
// load a drawing from a file
drawing = persistencyManager.LoadDrawingFromFile("c:\\temp\\drawing1.nds");
Visual Basic
Copy Code
' load a drawing from a file
drawing = persistencyManager.LoadDrawingFromFile("c:\\temp\\drawing1.nds")
Related Examples

Windows Forms: Extensions - Persistency Manager 

 

See Also

 

 


©2017. Nevron Software LLC.

Send Feedback