02.05.2014 Views

Ocean Serialization - Saving Custom Data Made Easy

Ocean Serialization - Saving Custom Data Made Easy

Ocean Serialization - Saving Custom Data Made Easy

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Ocean</strong> <strong>Serialization</strong> -<br />

<strong>Saving</strong> <strong>Custom</strong> <strong>Data</strong> <strong>Made</strong> <strong>Easy</strong><br />

Priya Soni<br />

<strong>Ocean</strong> Training and Support Engineer


Agenda<br />

Managed Persistence API<br />

• Introduction<br />

• How to save custom data<br />

• Version handling<br />

• Resources


How should my plug-in save custom data??<br />

<strong>Custom</strong><br />

<strong>Data</strong> source<br />

domain<br />

describes saves<br />

objects<br />

and mechanism retrieves to data which<br />

data to/from is saved data and how<br />

it storage is resolved<br />

Argument Packages<br />

ArgPack<br />

<strong>Custom</strong> windows<br />

state<br />

....


Before 2012...<br />

.Net <strong>Serialization</strong> Mechanism<br />

<strong>Custom</strong> -Simple <strong>Data</strong> to Implement Source<br />

- Gives -Uses full control Petrel <strong>Data</strong> over Source persistence<br />

- -Cannot Handles/resolves control persistence identity mechanism of object<br />

--Backward May require<br />

compatibility<br />

some work<br />

and versioning<br />

to implement<br />

issues<br />

...


In 2012...<br />

Managed Persistence<br />

-Simple to implement<br />

- Explicit tagging of attributes<br />

-Convenient Structured Archive <strong>Data</strong> source available<br />

-Versioning Support<br />

- <strong>Custom</strong>ization available<br />

-<strong>Serialization</strong> with different backends<br />

- Load on demand<br />

-Forward compatibility can be implemented<br />

-...


How To Use Managed Persistence API<br />

Steps to persist a custom domain object<br />

• Tag class and members to serialize<br />

• Add them to Structured data source<br />

• Register <strong>Data</strong>SourceFactory implementation<br />

public class XYZObject: IIdentifiable<br />

{<br />

private double _position;<br />

private string _name;<br />

}<br />

private Droid _droid;<br />

public Droid Droid<br />

{ get { return _droid; } }<br />

...


Tagging <strong>Data</strong><br />

[Archivable(Version = 1, Release = "2012.1")]<br />

public class XYZObject: IIdentifiable<br />

{<br />

[Archived(Name="Position")]<br />

private double _position;<br />

[Archived(Name="Name")]<br />

private string _name;<br />

public double Position<br />

{ get { return _position; } set { _position = value; } }<br />

public string Name<br />

{ get { return _name; } set { _name = value; } }<br />

[Archived]<br />

private Droid _droid;<br />

Class Tagging<br />

Member Tagging<br />

}<br />

public Droid Droid{ get { return _droid; } }<br />

...


Implementing Factory<br />

class XYZ<strong>Data</strong>SourceFactory : <strong>Data</strong>SourceFactory<br />

{<br />

public static string <strong>Data</strong>SourceId = "XYZ<strong>Data</strong>SourceId";<br />

}<br />

public override I<strong>Data</strong>Source Get<strong>Data</strong>Source()<br />

{<br />

StructuredArchive<strong>Data</strong>Source dataSource =<br />

new StructuredArchive<strong>Data</strong>Source( <strong>Data</strong>SourceId,<br />

new[] { typeof(XYZObject) });<br />

return dataSource;<br />

}<br />

StructuredArchived<strong>Data</strong>Source – convenient<br />

datasource from framework


Registering <strong>Data</strong>Source<br />

public class Module: IModule<br />

{<br />

public void Integrate()<br />

{<br />

PetrelSystem.Add<strong>Data</strong>SourceFactory(new XYZ<strong>Data</strong>SourceFactory());<br />

}<br />

...<br />

}<br />

Adding XYZ<strong>Data</strong>SourceFactory


Add Objects to <strong>Data</strong> Source to Save<br />

public class XYZObject: IIdentifiable<br />

{<br />

public XYZObject(string name, Point3 position)<br />

{<br />

_name = name;<br />

_position = position;<br />

}<br />

}<br />

...<br />

// adding this to datasource<br />

I<strong>Data</strong>SourceManager dsm = <strong>Data</strong>Manager.<strong>Data</strong>SourceManager;<br />

string <strong>Data</strong>SourceId = XYZ<strong>Data</strong>SourceFactory.<strong>Data</strong>SourceId;<br />

StructuredArchive<strong>Data</strong>Source ds = dsm.GetSource(<strong>Data</strong>SourceId);<br />

_droid = ds.GenerateDroid();<br />

ds.AddItem(_droid, this);<br />

Adding object to data source on<br />

construction


Versioning<br />

Versions of object can be created if:<br />

• Member is added<br />

• Member is removed<br />

• Member is renamed<br />

• Member is removed from serialization only<br />

• ...


Versioning – Adding a Member<br />

Version 1<br />

[Archivable(Version = 1, Release = "2012.1")]<br />

public class XYZObject: IIdentifiable<br />

{<br />

[Archived(Name="Position")]<br />

private double _position;<br />

[Archived(Name="Name")]<br />

private string _name;<br />

...<br />

}<br />

Version 2<br />

[Archivable(Version = 2, Release = "2012.1")]<br />

public class XYZObject: IIdentifiable<br />

{<br />

[Archived(Name="Position")]<br />

private double _position;<br />

[Archived(Name="Name")]<br />

private string _name;<br />

Just add it with<br />

version it is<br />

added in<br />

}<br />

[Archived(Name="Property", FromVersion=2)]<br />

private double _propertyValue;


Versioning – Removing a Member<br />

Version 1<br />

[Archivable(Version = 1, Release = "2012.1")]<br />

public class XYZObject: IIdentifiable<br />

{<br />

[Archived(Name="Position")]<br />

private double _position;<br />

[Archived(Name="Name")]<br />

private string _name;<br />

}<br />

...<br />

Version 2<br />

[Archivable(Version = 2, Release = "2012.1")]<br />

public class XYZObject: IIdentifiable<br />

{<br />

[Archived(Name="Position")]<br />

private double _position;<br />

// [Archived(Name="Name")]<br />

// private string _name;<br />

Just remove it<br />

}<br />

[Archived(Name="Property", FromVersion=2)]<br />

private double _propertyValue;


Versioning – Renaming a Member<br />

Version 1<br />

[Archivable(Version = 1, Release = "2012.1")]<br />

public class XYZObject: IIdentifiable<br />

{<br />

[Archived(Name="Position")]<br />

private double _position;<br />

[Archived(Name="Name")]<br />

private string _name;<br />

}<br />

...<br />

Version 2<br />

[Archivable(Version = 2, Release = "2012.1")]<br />

public class XYZObject: IIdentifiable<br />

{<br />

[Archived(Name="Position")]<br />

[Archived(Name="Center", FromVersion=2)]<br />

private double _position;<br />

// [Archived(Name="Name")]<br />

// private string _name;<br />

Add another<br />

Archived tag<br />

}<br />

[Archived(Name="Property", FromVersion=2)]<br />

private double _propertyValue;


Versioning – Removing a Member from <strong>Serialization</strong><br />

Version 1<br />

[Archivable(Version = 1, Release = "2012.1")]<br />

public class XYZObject: IIdentifiable<br />

{<br />

[Archived(Name="Position")]<br />

private double _position;<br />

[Archived(Name="Name")]<br />

private string _name;<br />

}<br />

...<br />

Version 2<br />

[Archivable(Version = 2, Release = "2012.1")]<br />

public class XYZObject: IIdentifiable<br />

{<br />

[Archived(Name="Position")]<br />

[Archived(Name="Center", FromVersion=2)]<br />

private double _position;<br />

}<br />

[Archived(Name="Name")]<br />

[Archived(Name="Name", FromVersion = 2, IsRemoved = true)]<br />

private string _name;<br />

[Archived(Name="Property", FromVersion=2)]<br />

private double _propertyValue;<br />

Member is still<br />

in class but<br />

removed from<br />

serialization in<br />

version 2 and<br />

beyond


Advanced features available..<br />

<strong>Serialization</strong> callbacks can be implemented for any additional action that<br />

needs to be performed after automatic serialization and deserialization<br />

process<br />

<strong>Custom</strong> serialization can be implemented for handling complicated<br />

scenarios that cannot be handled automatically<br />

Forward compatibility can be implemented for an object so data can be<br />

loaded and saved in an older version without losing data from newer<br />

version on save<br />

Load-On-Demand can be implemented to load data only when<br />

accessed and not during project load


Resources<br />

You can find more information<br />

• <strong>Ocean</strong>.chm<br />

– Managed Persistence Whitepaper<br />

– Slb.<strong>Ocean</strong>.Petrel.<strong>Data</strong>.Persistence namespace<br />

• Developer’s Guide 2012 – Volume 9, Petrel customization<br />

• Sample Code - ...\<strong>Ocean</strong> 2012\Samples\Persistence

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!