NOV comes with the following predefined data formats:
Besides the predefined data formats, you can also define custom formats, that can possibly exchange information between two different NOV application instances. To do so when declaring a data format you always need to provide a pair of serialize/deserialize delegates that serialize/deserialize your object instance to/from a byte array. The following code example declares a custom data format and implements a simple object, that can cross the application/process boundaries:
Example Title |
Copy Code
|
---|---|
public class MyFirstDataExchangeObject { // make some sample fields public int IntValue; public float FloatValue; public MyFirstDataExchangeObject() { FloatValue = 0; IntValue = 0; } static MyFirstDataExchangeObject() { // create the Data Format associated with MyFirstDataEchangeObject DataFormat = NDataFormat.Create("MyFirstDataEchangeFormat", new SerializeDataObjectDelegate(SerializeDataObject), new DeserializeDataObjectDelegate(DeserializeDataObject)); } // Serialization function for the data format private static byte[] SerializeDataObject(NDataFormat format, object obj) { MyFirstDataExchangeObject myObject = (MyFirstDataExchangeObject)obj; Nevron.IO.NByteWriter byteWriter = new Nevron.IO.NByteWriter(); byteWriter.WriteInt32LE(myObject.IntValue); byteWriter.WriteSingleLE(myObject.FloatValue); return byteWriter.ToArray(); } // Deserialization function for the custom data format private static object DeserializeDataObject(NDataFormat format, byte[] bytes) { MyFirstDataExchangeObject myObject = new MyFirstDataExchangeObject(); Nevron.IO.NByteReader reader = new Nevron.IO.NByteReader(bytes); myObject.IntValue = reader.ReadInt32LE(); myObject.FloatValue = reader.ReadSingleLE(); return myObject; } // reference to the singleton NDataFormat created by the static constructor of this type public static readonly NDataFormat DataFormat; } ... // publish a custom data exchange object to the clipboard // make a custom data exchange object and assign arbitrary values MyFirstDataExchangeObject obj = new MyFirstDataExchangeObject(); obj.FloatValue = 20.5f; obj.IntValue = 10; // make a data object and store the data exchange object in it NDataObject dataObject = new NDataObject(); dataObject.SetData(MyFirstDataExchangeObject.DataFormat, obj); // place the data object on the clipboard NClipboard.SetDataObject(dataObject); ... // consume the custom data exchange object from the clipboard // get a data object from the clipboard NDataObject dataObject = NClipboard.GetDataObject(); // try get our custom data exchange object from the data object MyFirstDataExchangeObject obj = (MyFirstDataExchangeObject)dataObject.GetData(MyFirstDataExchangeObject.DataFormat); if (obj != null) { // successfully obtained data exchange object from the clipboard } else { // failed to obtained data exchange object from the clipboard } |