Alex,There are many different ways to approach this. 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. The problem with the latter is that you may have static tables or information that needs to be queried while in the field. In this case you would first have to perform a query to populate the business objects before you leave the office. 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.
If you choose to go down the serialization route, the logic to serialize and deserialize is actually pretty simple. All business objects have a SerializeToStream and SerializeToByteArray method. Below is a sample of how to use the SerializeToStream.
void SaveToDisk()
{
//-- Establish Locals
System.IO.FileStream output = new System.IO.FileStream(@"c:\SavedBO.bin", System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite);
//-- Save the BO to disk
myBO1.SerializeToStream(output);
//-- Close the stream
output.Close();
}
void ReadFromDisk()
{
//-- Establish Locals
System.IO.FileStream input = new System.IO.FileStream(@"c:\SavedBO.bin", System.IO.FileMode.Open, System.IO.FileAccess.Read);
//-- Read the BO from the saved state into an instance
myBO1 = (MyBO)MicroFour.StrataFrame.Business.BusinessLayer.DeserializeBusinessObject(input);
//-- Close the stream
input.Close();
}
As for swapping data sources, this can be done very easily. 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:
if inOffice
{
//-- Connect directly to the SQL Server
DataBasics.DataSources.Add(new SqlDataSourceItem("", "connection string"));
}
else
{
//-- Connect to an Enterprise Server
DataBasics.DataSources.Add(new EnterpriseDataSourceItem("", "connection string"));
}