﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » BO Serialization Examples C#</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 06:05:39 GMT</lastBuildDate><ttl>20</ttl><item><title>BO Serialization Examples C#</title><link>http://forum.strataframe.net/FindPost11855.aspx</link><description>Greetings,&lt;br&gt;
&lt;br&gt;
I've read several posts about SF serialization, but could not find one complete solution to help me figure out a way of working an online/offline application.&lt;br&gt;
An WMS mobile application or even a simple Point of Sale, that works online with ES, but in case of failure, changes the stream to local storage, binary or XML. Using serialization.&lt;br&gt;
&lt;br&gt;
My main question is the approach to BO binding and ES connection status control.&lt;br&gt;
May I have to use 2 BO(online/offline) or may I change the stream type on-the-fly according to ES connection status?&lt;br&gt;
&lt;br&gt;
If you could point a pretty simple example in C# will help a lot.&lt;br&gt;
Thanks for the attention,&lt;br&gt;
&lt;br&gt;
[b]Alex[/b]</description><pubDate>Mon, 08 Oct 2007 08:32:31 GMT</pubDate><dc:creator>Alex M. Lana</dc:creator></item><item><title>RE: BO Serialization Examples C#</title><link>http://forum.strataframe.net/FindPost11901.aspx</link><description>With the ES, you could try to do a fill on a business object... something with a WHERE clause of 0=1 so no records are returned is fine.&amp;nbsp; If you get an exception, then you need to swap to local datasets.&amp;nbsp; You can do the same for a the SqlDataSourceItem, too, so if you're using ES/Sql and swapping back and forth, then this would be the way to go.</description><pubDate>Mon, 08 Oct 2007 08:32:31 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: BO Serialization Examples C#</title><link>http://forum.strataframe.net/FindPost11892.aspx</link><description>I've checked if the db was available just using a normal ADO.NET Connection object.  I retrieved the connection string from the DataLayer.DataSources dictionary, then just attempted to open it (inside a try/catch).  This keeps connection info encapsulated within the DataSources dictionary.&lt;br&gt;
&lt;br&gt;
This won't work with Enterprise Server, as it isn't using an ADO connection. &lt;br&gt;
&lt;br&gt;
Just an idea for you to ponder!  :D</description><pubDate>Fri, 05 Oct 2007 21:58:14 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: BO Serialization Examples C#</title><link>http://forum.strataframe.net/FindPost11891.aspx</link><description>Thanks Trent,&lt;br&gt;
I've managed to store/update/retrieve/synchronize using datasets as encripted XML, loaded on-the-fly onto the BOs.&lt;br&gt;
The question I have is how can I check database connection state with SF layers.&lt;br&gt;
Does SF has something like getConnetionState.&lt;br&gt;
Basically need to catch the DataSource connection error, when remote data is offline, so I can switch to offline datasets.&lt;br&gt;
I was thinking of something like:&lt;br&gt;
&lt;br&gt;
TcpClient tcpClient = new TcpClient ();&lt;br&gt;
tcpClient.Connect ("mySQLserver.com", 1433);&lt;br&gt;
//Connection is present&lt;br&gt;
tcpClient.Close();&lt;br&gt;
&lt;br&gt;
But would rather not go this way, since I want to control the most using SF.&lt;br&gt;
&lt;br&gt;
Thanks for the attention, regards,&lt;br&gt;
&lt;br&gt;
[b]Jacob[/b]... sorry... [b]Alex[/b]</description><pubDate>Fri, 05 Oct 2007 19:34:59 GMT</pubDate><dc:creator>Alex M. Lana</dc:creator></item><item><title>RE: BO Serialization Examples C#</title><link>http://forum.strataframe.net/FindPost11884.aspx</link><description>Alex,&lt;/P&gt;&lt;P&gt;There are many different ways to approach this.&amp;nbsp; First, you could use a local database such as SQLAnywhere while disconnected from the network or internet, talk to a ES server remotely, or simply serialize the BOs to disk the restore them and save once you get back to a network that can access the database.&amp;nbsp; The problem with the latter is that you may have static tables or information that needs to be queried while in the field.&amp;nbsp; In this case you would first have to perform a query to populate the business objects before you leave the office.&amp;nbsp; In this scenario, you would be better off using the ES if there will always be an internet connection available on the laptop, or creating a local SQLAnywhere or SQLExpress database that is used when access to the main database is not available.&lt;/P&gt;&lt;P&gt;If you choose to go down the serialization route, the logic to serialize and deserialize is actually pretty simple.&amp;nbsp; All business objects have a SerializeToStream and SerializeToByteArray method.&amp;nbsp; Below is a sample of how to use the SerializeToStream.&lt;/P&gt;&lt;P&gt;[codesnippet]void SaveToDisk()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //-- Establish Locals&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.IO.FileStream output = new System.IO.FileStream(@"c:\SavedBO.bin",&amp;nbsp; System.IO.FileMode.Create,&amp;nbsp; System.IO.FileAccess.ReadWrite);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //-- Save the BO to disk&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myBO1.SerializeToStream(output);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //-- Close the stream&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output.Close();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void ReadFromDisk()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //-- Establish Locals&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.IO.FileStream input = new System.IO.FileStream(@"c:\SavedBO.bin",&amp;nbsp; System.IO.FileMode.Open,&amp;nbsp; System.IO.FileAccess.Read);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //-- Read the BO from the saved state into an instance&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myBO1 = (MyBO)MicroFour.StrataFrame.Business.BusinessLayer.DeserializeBusinessObject(input);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //-- Close the stream&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input.Close();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }[/codesnippet]&lt;/P&gt;&lt;P&gt;As for swapping data sources, this can be done very easily.&amp;nbsp; Simply change the data source that is created in your applications SetDataSOurces (or someplace else if you have the need while the application is already running) in the program.cs file:&lt;/P&gt;&lt;P&gt;[codesnippet]if inOffice&lt;BR&gt;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp; //-- Connect directly to the SQL Server&lt;BR&gt;&amp;nbsp;&amp;nbsp; DataBasics.DataSources.Add(new SqlDataSourceItem("", "connection string"));&lt;BR&gt;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;else&lt;BR&gt;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp; //-- Connect to an Enterprise Server&lt;BR&gt;&amp;nbsp;&amp;nbsp; DataBasics.DataSources.Add(new EnterpriseDataSourceItem("", "connection string"));&lt;BR&gt;&amp;nbsp;&amp;nbsp; }[/codesnippet]</description><pubDate>Fri, 05 Oct 2007 13:24:17 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item></channel></rss>