Saturday, January 8, 2011

Passing an Array of Facts into the Rules Engine (BizTalk )

I finally figured out how to pass an array of facts into the Rules Engine that comes with BizTalk 2004. (Since the XLangs syntax does not directly support arrays, see http://datacogs.com/datablogs/archive/2004/12/04/183.aspx )The trick is to use the ToArray method of the ArrayList class. Simple when you know how, but guaranteed to give hours of head-scratching if you don't. I will post a more “step-by-step“ article when I get some time.

Here is the code from the Expression shape that does all the work. (The variables are declared within an atomic scope shape in the orchestration)

//System.Collections.ArrayList List;
sCon = "Initial Catalog=Northwind;Data Source=(local);Integrated Security=SSPI;";
con = new System.Data.SqlClient.SqlConnection(sCon);
dcNorthwind = new Microsoft.RuleEngine.DataConnection("Northwind", "ShipperCountry", con);
List.Add(dcNorthwind);

xmlDocument = msgShippingRequest;
typedXmlDocument = new Microsoft.RuleEngine.TypedXmlDocument("RoleLinkSample.ShippingRequest",xmlDocument);
policy = new Microsoft.RuleEngine.Policy("ShippingPolicy");
List.Add(typedXmlDocument);

policy.Execute(List.ToArray());
msgOutgoingShippingRequest = typedXmlDocument.Document;
policy.Dispose();
typedXmlDocument = null;
dcNorthwind = null;

No comments:

Post a Comment