BatchExecResult BatchExec(BatchExecArg tArg)
tArg. Operation execution parameters.
The BatchExec operation is used for batch execution of other operations.
This operation enables the user to execute operations at once. The BatchExec operation result is formed from the results of all executed operations. To execute batch operation, set a collection of separate operation execution parameters serialized in JSON/XML in the tArg.its field. The BatchExec operation execution results in the collection of separate operation execution results also presented as JSON/XML. To further work with the results, deserialize them from JSON/XML. If on executing of any operation an error occurs, error information is displayed instead of the actual result. The mode of operation execution in case of error in a separate operation is determined by the tArg.bIgnoreError field.
To execute the example in C#, two extension procedures are used that enable the user to serialize and deserialize from XML.
public static class Extensions { /// Serialize object to XML public static System.Xml.XmlElement ObjectToXml(this object o) { var serializer = new System.Xml.Serialization.XmlSerializer(o.GetType()); var writer = new System.IO.StringWriter(); serializer.Serialize(writer, o); var doc = new System.Xml.XmlDocument(); doc.LoadXml(writer.ToString()); writer.Close(); var xml = doc.DocumentElement; return xml; } /// Deserialize object from XML public static Object XmlToObject(Type type, System.Xml.XmlElement xml) { var reader = new System.IO.StringReader(xml.OuterXml); var serializer = new System.Xml.Serialization.XmlSerializer(type); return serializer.Deserialize(reader); } }
The example of batch execution of two operations for extracting express report metadata. The request contains two operation execution patterns, the response contains two results of operation execution.
{ "BatchExec" : { "tArg" : { "its" : { "it" : [ { "GetEaxMd" : { "tEax" : { "id" : "S2!M!S!E1" }, "tArg" : { "pattern" : { "obInst" : "true", "dataSources" : "Get" } } } }, { "GetEaxMd" : { "tEax" : { "id" : "S2!M!S!E1" }, "tArg" : { "pattern" : { "obInst" : "true", "sheets" : "Get" } } } } ] }, "bIgnoreError" : "true" } } }
{ "BatchExecResult" : { "its" : { "it" : [ { "GetEaxMdResult" : { "id" : { "id" : "S2!M!S!E1" }, "meta" : { "obInst" : { "obDesc" : { "@fullUrl" : "\/", "@isShortcut" : "0", "@isLink" : "0", "i" : "EXPRESS_1", "n" : "Express report", "k" : "189", "c" : "2561", "p" : "182", "h" : "0" }, "openArgs" : "" }, "dataSources" : { "its" : { "it" : [ { "k" : "1", "id" : "OBJ183", "n" : "Cube (elements)", "vis" : "1", "cube" : { "obDesc" : { "@fullUrl" : "\/", "@isShortcut" : "0", "@isLink" : "0", "i" : "OBJ183", "n" : "Cube (elements)", "k" : "186", "c" : "1287", "p" : "182", "h" : "0" }, "dest" : { "k" : "1", "id" : "OBJ183" } } } ] } }, "windowsPosition" : "Maximized", "hasPivot" : "1" } } }, { "GetEaxMdResult" : { "id" : { "id" : "S2!M!S!E1" }, "meta" : { "obInst" : { "obDesc" : { "@fullUrl" : "\/", "@isShortcut" : "0", "@isLink" : "0", "i" : "EXPRESS_1", "n" : "Express report", "k" : "189", "c" : "2561", "p" : "182", "h" : "0" }, "openArgs" : "" }, "sheets" : { "active" : "0", "its" : { "it" : [ { "k" : "189", "id" : "SHEET1", "n" : "Sheet1", "vis" : "1", "eax" : { "id" : "S2!M!S!E1" }, "isActive" : "1" } ] } }, "windowsPosition" : "Maximized", "hasPivot" : "1" } } } ] }, "bSucceeded" : "1" } },
public static BatchExecResult BatchExec(EaxId eax) { //Parameters of first operation execution var tGet1 = new GetEaxMd()
{ tArg = new GetEaxMdArg() { pattern = new EaxMdPattern() { dataSources = ListOperation.Get } }, tEax = eax };
//Parameters of second operation execution var tGet2 = new GetEaxMd() { tArg = new GetEaxMdArg() { pattern = new EaxMdPattern() { sheets = ListOperation.Get } },
tEax = eax }; //Serialization of parameters to XML var tGetXml1 = tGet1.ObjectToXml(); var tGetXml2 = tGet2.ObjectToXml(); //Batch operation execution mode var somClient = new SomPortTypeClient(); //Proxy object for operation execution //Operation execution parameters var tExec = new BatchExec() {
tArg = new BatchExecArg() { bIgnoreError = true, //Specify parameters of operations executed within one request its = new System.Xml.XmlElement[2] { tGetXml1, tGetXml2 } } }; //Execute method var result = somClient.BatchExec(tExec); return result; }
See also: