Approach and example of serialization functions limitations

Approach to serialization LimitFunction

Class Function implements the interface ISerializable. Therefore, for functions of limited available as SOAP and binary serialization.

It is recommended to use library tools ICSSoft.STORMNET.Tools.XmlTools instead of a direct appeal to System.Runtime.Serialization.Formatters.Soap.SoapFormatter or System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.

In the specified library classes available:

  • ToolXML - allows to serialize means SoapFormatter,
  • ToolBinarySerializer - allows to serialize means BinaryFormatter.

Example comparing binary and SOAP serialization LimitFunction

Binary form serialization is more productive and the rows get shorter.

[TestMethod]        
public void FunctionSerializeTst()        
{
    Serialize(true);            
    Serialize(false);        
}

private void Serialize(bool binary)
{
    DateTime start = DateTime.Now;
    string fnStr = "";

    ExternalLangDef externalLangDef = ExternalLangDef.LanguageDef;
    SQLWhereLanguageDef ldef = SQLWhereLanguageDef.LanguageDef;
    Function fn = ldef.GetFunction(
                ldef.funcAND,
                ldef.GetFunction(
                ldef.funcEQ, new VariableDef(ldef.StringType,"Parampampam"), "who goes to visit in the morning"
                ),
                ldef.GetFunction(
                ldef.funcOR,
                ldef.GetFunction(ldef.funcEQ, new VariableDef(ldef.StringType, "Compositepicture"), Environment.UserName),
                ldef.GetFunction(ldef.funcIsNull, new VariableDef(ldef.StringType, "Nationair"))
                )
                );


    for (int i = 0; i < 1000; i++)
    {
        string serializedFn;
        if (binary)
        {
            serializedFn = ToolBinarySerializer.ObjectToString(externalLangDef.FunctionToSimpleStruct(fn));
        }
        else
        {
            serializedFn = ToolXML.ObjectToString(externalLangDef.FunctionToSimpleStruct(fn));
        }
        Assert.IsNotNull(serializedFn);
        Function восставшийИзНебытия;
        if (binary)
        {
            восставшийИзНебытия =
                externalLangDef.FunctionFromSimpleStruct(ToolBinarySerializer.ObjectFromString(serializedFn));
        }
        else
        {
            восставшийИзНебытия = externalLangDef.FunctionFromSimpleStruct(ToolXML.ObjectFromString(serializedFn));
        }
        Assert.IsNotNull(восставшийИзНебытия);
        fnStr = "The length of the serialized string: " + serializedFn.Length + Environment.NewLine
                + serializedFn.Substring(0, 50) + Environment.NewLine + "lf: " + восставшийИзНебытия;
    }            
    Console.WriteLine("Run time " + (DateTime.Now - start).TotalMilliseconds);
}