02.05.2014 Views

Making custom domain objects RPT-enabled - Ocean - Schlumberger

Making custom domain objects RPT-enabled - Ocean - Schlumberger

Making custom domain objects RPT-enabled - Ocean - Schlumberger

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}<br />

// Called by the framework when user opens a Petrel project file<br />

public void Open()<br />

{<br />

(…)<br />

using (FileStream file = fileInfo.OpenRead())<br />

{<br />

BinaryFormatter bf = new BinaryFormatter();<br />

this.<strong>custom</strong>ObjectsDictionary = bf.Deserialize(file) as Hashtable;<br />

}<br />

}<br />

// Called by the framework when user saves a Petrel project file<br />

public void Save()<br />

{<br />

(…)<br />

using (FileStream fileStream = fileInfo.OpenWrite())<br />

{<br />

BinaryFormatter bf = new BinaryFormatter();<br />

bf.Serialize(fileStream, this.<strong>custom</strong>ObjectsDictionary);<br />

}<br />

}<br />

}<br />

The Add() function is used to store IIdentifiable <strong>objects</strong> and its droid in a hashtable. Open()<br />

deserializes a binary file in order to fill the hashtable and Save() serializes the hashtable into a file<br />

stream.<br />

4. Important notes about serialization<br />

There are two very important remarks to be done about serialization:<br />

1) 1. If a <strong>custom</strong> <strong>domain</strong> object contains references to other Petrel <strong>domain</strong> <strong>objects</strong>, it must serialize<br />

only the Droid’s of such references and not the <strong>objects</strong> themselves. Observe the example below:<br />

[NonSerialized]<br />

private SeismicCube internalSeismicCube;<br />

private Droid seismicCubeDroid;<br />

2) 2. Before calling the serialization (CustomDataSource.Save() method), any events on the <strong>objects</strong> to<br />

be serialized must be turned off.<br />

obj.Changed -= this .changedEventHandler;<br />

Such events must probably be linked again after the serialization has finished executing.<br />

<strong>Ocean</strong> Developer Best Practices: <strong>Ocean</strong> for Petrel framework Page 5 of 9<br />

Submitted by the developer community<br />

*Mark of <strong>Schlumberger</strong>. Other company, product, and service names are the properties of their respective owners. Copyright © 2011<br />

<strong>Schlumberger</strong>. All rights reserved.

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

Saved successfully!

Ooh no, something went wrong!