Lists the methods of the class `ICSSoft.STORMNET.Windows.Forms.Utils` for serialization-десериализации; specified which ones are used for the limit function, given примеры; described problem deserializing limitations when using signed and unsigned assemblies, the approach to the solution

Means serialization-deserialization in ICSSoft.STORMNET.Windows.Forms.Utils

In the Assembly ICSSoft.STORMNET.Windows.Forms class is implemented ICSSoft.STORMNET.Windows.Forms.Utils, providing, inter alia, methods for serialization-deserialization, which are applicable including for parental control. These methods are a wrapper over the respective methods of Assembly ICSSoft.STORMNET.Tools, and perform it.

serialization Methods class ICSSoft.STORMNET.Windows.Forms.Utils:

ObjectToString

Assign: Serialize to a string using SoapFormatter.

Settings:

o Object

The result is: String.

Signature:

public static string ObjectToString(object o)
{
	return ICSSoft.STORMNET.Tools.ToolXML.ObjectToString(o);
}

ObjectFromString

Assign: Deserialize from a string with SoapFormatter.

Settings:

s - Serialized object

The result is: the Restored object.

Signature:

public static object ObjectFromString(string s)
{
	return ICSSoft.STORMNET.Tools.ToolXML.ObjectFromString(s);
}

ObjectToBinaryString

Assign: Serialize to a string using BinaryFormatter.

Settings:

o Object

The result is: String.

Signature:

public static string ObjectToBinaryString(object o)
{
    return ICSSoft.STORMNET.Tools.ToolBinarySerializer.ObjectToString(o);
}

ObjectFromBinaryString

Assign: Deserialize from a string with BinaryFormatter (if it does not, then try SoapFormatter - for compatibility with legacy data).

Settings:

s - Serialized object

The result is: the Restored object.

Signature:

public static object ObjectFromBinaryString(string s)
{
    object retObj;
    try
    {
        retObj = ICSSoft.STORMNET.Tools.ToolBinarySerializer.ObjectFromString(s);
    }
    catch
    {
        retObj = ICSSoft.STORMNET.Tools.ToolXML.ObjectFromString(s);
    }
    return retObj;
}

[Form constraint] while maintaining (recovery) LimitFunction are used Utils.ObjectToBinaryString (Utils.ObjectFromBinaryString), i.e. restrictions are serialized using binary serialization, and restored as a binary string, and SOAP, as in earlier versions of the technology have used the SOAP serialization.

an Example SOAP serialization LimitFunction

            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"))
                )
                );

            string serializedFn = Utils.ObjectToString((new ExternalLangDef()).FunctionToSimpleStruct(fn));
            Assert.IsNotNull(serializedFn);
            Console.WriteLine(serializedFn);

            Function восставшийИзНебытия = (
                                new ExternalLangDef()).FunctionFromSimpleStruct(Utils.ObjectFromString(serializedFn));
            Assert.IsNotNull(восставшийИзНебытия);

Example binary serialization LimitFunction

This type of serialization is more productive and the rows get shorter.

    string fnStr = "";
    string serializedFn;
    AdvansedLimit advlimit = new AdvansedLimit();
    ExternalLangDef externalLangDef = ExternalLangDef.LanguageDef;
    advlimit.FromSimpleValue(Utils.ObjectFromString(_serializedFunc), externalLangDef);
    Function fn = advlimit.Function;

    serializedFn = Utils.ObjectToBinaryString(externalLangDef.FunctionToSimpleStruct(fn));
    Assert.IsNotNull(serializedFn);
    
    восставшийИзНебытия =
                externalLangDef.FunctionFromSimpleStruct(Utils.ObjectFromBinaryString(serializedFn));        
    Assert.IsNotNull(восставшийИзНебытия);

Possible problem deserializing

In the above code is used to design advlimit.FromSimpleValue, which is based on the object of a special type builds directly limit. In the structure of the transmitted object is a special type, among others, have AssemblyQualifiedName type, which can cause problems during deserialization: for example, if the constraint was created with an unsigned Assembly, you want to open already with the version that was signed (respectively, AssemblyQualifiedName the type of change and it is impossible to get through Type.GetType(...)), etc. For this case, added a delegate that allows you to define your own additional method to get type by its name.

namespace ICSSoft.STORMNET.Windows.Forms
{
    public class ExternalLangDef
    {
        /// <summary> Delegate for getting the type by its name in the method SimpleValueToDataObject </summary> 
        public static TypeResolveDelegate ExtraTypeResolver = null;
		
		//... 
	}
	
	/// <summary> 
	/// Delegate to retrieve a type by its name (used in special cases when the standard methods somehow) 
	/// </summary> 
	/// <param name="typeName">type Name.</param> 
	/// <returns> Generated name of the type </returns> 
	public delegate Type TypeResolveDelegate(string typeName);
}

Below is an example of using this delegate:

	// ... 
	var obj = ICSSoft.STORMNET.Windows.Forms.Utils.ObjectFromBinaryString(data);
	var advansedLimit = new AdvansedLimit();
	var externalLangDef = new ExternalLangDef();
	ExternalLangDef.ExtraTypeResolver = ExtraTypeResolver;
	advansedLimit.FromSimpleValue(obj, externalLangDef);
	ExternalLangDef.ExtraTypeResolver = null;
	var result = advansedLimit;

	//... 
}

private Type ExtraTypeResolver(string typeName)
{
	if (typeName == "IIS.University.Videokasete University(Objects), Version=1.0.0.1, Culture=neutral, PublicKeyToken=null")
	{
		return typeof(IIS.University.ВидПодразделения);
	}

	return null;
}
Переведено сервисом «Яндекс.Переводчик» http://translate.yandex.ru