Skip to content

Flow documentation · legacy product

Using Objects instead of XML (C# Only) ​

The following functions return an objects configuration as XML when calling the "Load" functions, and takes the same format of XML when calling the "Save" functions. This allows you to load an object from the configuration database as XML, edit the required fields, and then pass it back to through a save function.

You can work with this XML using your favourite XML parser such as MS XML (XmlDocument), however an easier option is to define classes that represent the XML objects and then serialize the XML data to and from these classes. This enables you to work with the configuration in an object based manner.

Defining an representative class ​

You can define classes that represent the different modules of Flow such as DB Connections or File Connections. To determine what properties your class needs, simply load out a sample of XML by using the "Load" functions and then define a class containing properties that are the same name as the XML elements. For XML fields with enumerated values you can define your own Enums.

The following example class is representative of a DB Connection

csharp
namespace Flow.API.DBCon
{
public enum TRegConType
{
ctInterbase, ctMySQL, ctMSSQL, ctDB2, ctOracle,
ctMSAccess, ctInformix, ctODBC, ctADO, ctQB,
ctMYOB, ctPervasive
}
public enum TppSQLType
{
sqBDELocal, sqSQL1, sqSQL2
}
public enum TFloMySQLVerType
{
fvtServer, fvtServerSSL, fvtEmbedded, fvtEmbeddedSSL
}
public class TFloDBCon
{
public TFloDBCon()
{
}
public String FIDS;
public String ModuleName;
public String Version;
public TRegConType ConnectionType;
public TppSQLType SQLType = TppSQLType.sqSQL2;
public int SQLDialect = 1;
public String Hostname;
public String ProviderName;
public String Database;
public String Username;
public String Password;
public String[] OtherParams;
public Boolean IsTestDB = false;
public Boolean SingleQuoteDates = true;
public Boolean UseASAlias = false;
public int MaxFieldAlias = 35;
public TFloMySQLVerType MySQLVersion = TFloMySQLVerType.fvtServer;
public String SSLKey;
public String SSLCert;
}
}

Serializing XML into an instance of a class (Loading) ​

This helper function serializes the XML into an instance of the class.

csharp
public static object XMLToObject(string xml, Type objType)
{
try
{
System.Xml.Serialization.
XmlSerializer xs = new XmlSerializer(objType);
StringReader sr = new StringReader(xml);
return xs.Deserialize(sr);
}
catch (Exception ex)
{
throw ex;
}
}

The following example shows how to use this helper function based on the above defined DB Connection class

csharp
string XMLString;
string XMLString2; //some objects have 2 sets of configuration
Boolean result = Flo_LoadDBCon("00000000-0000-0000-0000-000000000000", out XMLString, out XMLString2);
if (result)
{
TFloDBCon DBCon = new TFloDBCon();
DBCon = (TFloDBCon)XMLToObject(XMLString,DBCon.GetType());
MessageBox.Show(DBCon.ModuleName);
}

Serializing an instance of a class into XML (Saving) ​

This helper function serializes an instance of the class into XML.

csharp
public static string ObjectToXML(object obj)
{
try
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
sw.NewLine = String.Empty;
XmlSerializer xs = new XmlSerializer(obj.GetType());
xs.Serialize(sw, obj);
return sw.ToString();
}
catch (Exception ex)
{
throw ex;
}
}

The following example shows how to use this helper function based on the above defined DB Connection class

csharp
TFloDBCon DBCon = new TFloDBCon();
DBCon.FIDS = "00000000-0000-0000-0000-000000000000"; //set FIDS to null or empty guid to create a new object, otherwise set to value of FID you wish to overwrite
DBCon.ModuleName = "My New DB Con";
DBCon.Hostname = "camtop\flow"
DBCon.Database = "Flow"
string XMLString = ObjectToXML(DBCon);
string XMLString2;
Boolean result = Flo_SaveDBCon(ref XMLString, ref XMLString2);