Ejemplo n.º 1
0
        static void ExecutePolicy()
        {
            // wait one minute for the deploy to propogate
            Console.WriteLine("Sleeping for 60 seconds (so that the deployed ruleset becomes effective) ...");
            Thread.Sleep(60000);

            // go get the policy
            Console.WriteLine("Grabbing the policy ...");
            Policy policy = new Policy("SampleRuleset");

            //create an instance of the XML object
            XmlDocument xd1 = new XmlDocument();

            xd1.Load(@"..\..\SampleDocumentInstance.xml");
            TypedXmlDocument doc1 = new TypedXmlDocument("SampleSchema", xd1);

            // create the array of short-term facts
            object[] shortTermFacts = new object[4];
            shortTermFacts[0] = doc1;
            shortTermFacts[1] = new Microsoft.Samples.BizTalk.BusinessRulesHelloWorld2.HelloWorld2Library.HelloWorld2LibraryObject(1);
            shortTermFacts[2] = new Microsoft.Samples.BizTalk.BusinessRulesHelloWorld2.HelloWorld2Library.HelloWorld2LibraryObject(2);
            shortTermFacts[3] = new Microsoft.Samples.BizTalk.BusinessRulesHelloWorld2.HelloWorld2Library.HelloWorld2LibraryObject(3);

            // now execute to see what happens
            Console.WriteLine("Executing the policy...");
            policy.Execute(shortTermFacts);
            Console.WriteLine("The major version of the policy was: " + policy.MajorRevision);
            Console.WriteLine("The minor version of the policy was: " + policy.MinorRevision);
            Console.WriteLine("Press the ENTER to continue after updating the policy...");
            Console.Read();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method uses a BRE Policy to lookup and return information about another BRE Policy. (Broker Pattern)
        /// </summary>
        /// <param name="message">Xml Message for use of the policy lookup process</param>
        /// <param name="resolution">An instance of the resolution class for use in the policy lookup process</param>
        /// <param name="PolicyName">The Name of the BRE Policy for looking up which policy information to return</param>
        /// <param name="itineraryInfo">Instance of an Itinerary class which contains the attached itinerary for use in the policy lookup process</param>
        /// <param name="factRetreiver">Instance of MessageContextFactRetriever which contains BizTalk Message Promoted and Distinguished properties for use in the policy lookup process</param>
        /// <param name="major">Major version of the business rule to execute for determining which policyinfo to return</param>
        /// <param name="minor">Minor version of the business rule to execute for determining which policyinfo to return</param>
        /// <returns>PolicyBrokerInfo class containing information about the name, version, document type, and namespace of a Policy to execute</returns>
        public PolicyBrokerInfoCollection  GetPolicies(XmlDocument message, Resolution resolution, string PolicyName, ItineraryFact itineraryInfo, MessageContextFactRetriever factRetreiver, int major, int minor)
        {
            EventLogger.Write("Executing PolicyBroker!");

            string documentType = "Microsoft.Practices.ESB.ResolveProviderMessage";


            string docNameSpace = resolution.Namespace();
            string docName      = resolution.MessageName();

            EventLogger.Write("Document Namespace is: " + docNameSpace);
            EventLogger.Write("Document Name is: " + docName);

            PolicyBrokerInfo _info = new PolicyBrokerInfo()
            {
                DocNamespace = docNameSpace, DocName = docName
            };
            PolicyBrokerInfoCollection infos = new PolicyBrokerInfoCollection();

            infos.AddPolicyInfo(docName, docNameSpace, string.Format("{0}#{1}", docNameSpace, docName), "");

            object[]         facts    = new object[5];
            TypedXmlDocument document = new TypedXmlDocument(documentType, message);

            facts[0] = resolution;
            facts[1] = document;
            facts[2] = infos;
            facts[3] = itineraryInfo;
            facts[4] = factRetreiver;


            EventLogger.Write("Document Content is: " + message.InnerXml);

            bool useVersioning = (major > 0 || minor > 0);

            if (useVersioning)
            {
                this.policyExecutor.ExecutePolicy(PolicyName, facts, major, minor);
            }
            else
            {
                this.policyExecutor.ExecutePolicy(PolicyName, facts);
            }

            foreach (var policyInfo in infos.PolicyInfos)
            {
                var info = policyInfo.Value;
                if (string.IsNullOrEmpty(info.PolicyName))
                {
                    EventLogger.Write(string.Format(
                                          "Policy Broker could not found policy in Policy {0} for message name {1} with namespace {2}!",
                                          info.PolicyName,
                                          info.DocName,
                                          info.DocNamespace));
                }
                EventLogger.Write("Found Policy " + info.PolicyName + "\nVersion: " + info.Version);
            }
            return(infos);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Use a DocumentType and the documentStream setup in the constructor to create a TypedXmlDocument property
        /// </summary>
        /// <param name="DocumentType"></param>
        public void CreateTypedXmlDocument(string DocumentType)
        {
            XmlTextReader reader = new XmlTextReader(documentStream);

            document = new TypedXmlDocument(DocumentType, reader);
            documentStream.Position = 0;
            pc.ResourceTracker.AddResource(reader);

            hasBeenSet = true;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// ITestStep.Execute() implementation
        /// </summary>
        /// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
        /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
        public void Execute(System.Xml.XmlNode testConfig, Context context)
        {
            // Using Policy Tester

            // Retrieve Rule-Set from Policy file
            string RuleStoreName             = context.ReadConfigAsString(testConfig, "RuleStoreName");
            string RuleSetInfoCollectionName = context.ReadConfigAsString(testConfig, "RuleSetInfoCollectionName");
            string DebugTracking             = context.ReadConfigAsString(testConfig, "DebugTracking");
            string SampleXML  = context.ReadConfigAsString(testConfig, "SampleXML");
            string XSD        = context.ReadConfigAsString(testConfig, "XSD");
            string ResultFile = context.ReadConfigAsString(testConfig, "ResultFile");

            RuleStore             ruleStore = new FileRuleStore(RuleStoreName);
            RuleSetInfoCollection rsInfo    = ruleStore.GetRuleSets(RuleSetInfoCollectionName, RuleStore.Filter.Latest);

            if (rsInfo.Count != 1)
            {
                // oops ... error
                throw new ApplicationException();
            }

            RuleSet ruleset = ruleStore.GetRuleSet(rsInfo[0]);

            // Create an instance of the DebugTrackingInterceptor
            DebugTrackingInterceptor dti = new DebugTrackingInterceptor(DebugTracking);

            // Create an instance of the Policy Tester class
            PolicyTester policyTester = new PolicyTester(ruleset);

            XmlDocument xd1 = new XmlDocument();

            xd1.Load(SampleXML);

            TypedXmlDocument doc1 = new TypedXmlDocument(XSD, xd1);

            // Execute Policy Tester
            try
            {
                policyTester.Execute(doc1, dti);
            }
            catch (Exception e)
            {
                context.LogException(e);
                throw;
            }

            FileInfo     f = new FileInfo(ResultFile);
            StreamWriter w = f.CreateText();

            w.Write(doc1.Document.OuterXml);
            w.Close();
        }
        public void ExecutePolicy()
        {
            // Retrieve Rule-Set from the filestore

            RuleStore ruleStore = new FileRuleStore("MedicalInsurancePolicy.xml");

            //Grab the latest version of the rule-set

            RuleSetInfoCollection rsInfo = ruleStore.GetRuleSets("MedicalInsurancePolicy", RuleStore.Filter.Latest);

            if (rsInfo.Count != 1)
            {
                // oops ... error
                throw new ApplicationException();
            }

            RuleSet ruleset = ruleStore.GetRuleSet(rsInfo[0]);

            // Create an instance of the DebugTrackingInterceptor to provide an output trace
            DebugTrackingInterceptor dti = new DebugTrackingInterceptor("outputtrace.txt");

            //Create an instance of the Policy Tester class
            PolicyTester policyTester = new PolicyTester(ruleset);

            //Create the set of short term facts

            //XML facts

            XmlDocument xd1 = new XmlDocument();

            xd1.Load(@"..\..\sampleClaim.xml");

            TypedXmlDocument doc1 = new TypedXmlDocument("MedicalClaims", xd1);

            // .NET facts
            Microsoft.Samples.BizTalk.MedicalClaimsProcessingandTestingPolicies.Claims.ClaimResults results = new Microsoft.Samples.BizTalk.MedicalClaimsProcessingandTestingPolicies.Claims.ClaimResults();

            object[] shortTermFacts = new object[] { doc1, results, new TimeStamp(DateTime.Now) };

            //Execute Policy Tester
            try
            {
                policyTester.Execute(shortTermFacts, dti);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }
            System.Console.WriteLine("Status: " + results.Status);
            System.Console.WriteLine("Reason: " + results.Reason);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Static method to apply a TypedXMLDocument to a BizTalk message body
        /// </summary>
        /// <param name="document"></param>
        /// <param name="inmsg"></param>
        /// <param name="pc"></param>
        /// <param name="callToken"></param>
        public static void ApplyTypedXMLDocument(TypedXmlDocument document, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg, Microsoft.BizTalk.Component.Interop.IPipelineContext pc, string callToken)
        {
            TraceManager.PipelineComponent.TraceInfo("{0} - Applying typed XML document (overwriting current message body)", callToken);

            XmlDocument   doc = (XmlDocument)document.Document;
            VirtualStream ms  = new VirtualStream();

            doc.Save(ms);
            ms.Position         = 0;
            inmsg.BodyPart.Data = ms;

            // Add the new message body part's stream to the Pipeline Context's resource tracker so that it will be disposed off correctly
            pc.ResourceTracker.AddResource(ms);
        }
        public XmlDocument RunHardCodePolicy(XmlDocument request)
        {
            //load request into typed document
            TypedXmlDocument txd = new TypedXmlDocument("AdaptivIntegration.BizTalkSample.SampleSchema", request);

            //load BRE policy from the BTS Rules Engine DB
            Policy policy = new Policy("AdaptivIntegration.BizTalkSample.Policy");

            //Execute the policy
            policy.Execute(txd);

            //load up modified document as response
            XmlDocument response = new XmlDocument();
            response.LoadXml(txd.Document.OuterXml);

            return response;
        }
Ejemplo n.º 8
0
        }         // End of Cleanup()

        public void Execute()
        {
            //Using Policy Tester

            // Retrieve Rule-Set from Policy file
            RuleStore             ruleStore = new FileRuleStore("LoanProcessing.xml");
            RuleSetInfoCollection rsInfo    = ruleStore.GetRuleSets("LoanProcessing", RuleStore.Filter.Latest);

            if (rsInfo.Count != 1)
            {
                // oops ... error
                throw new ApplicationException();
            }

            RuleSet ruleset = ruleStore.GetRuleSet(rsInfo[0]);

            // Create an instance of the DebugTrackingInterceptor
            DebugTrackingInterceptor dti = new DebugTrackingInterceptor("outputtraceforLoanPocessing.txt");

            //Create an instance of the Policy Tester class
            PolicyTester policyTester = new PolicyTester(ruleset);

            XmlDocument xd1 = new XmlDocument();

            xd1.Load("sampleLoan.xml");

            TypedXmlDocument doc1 = new TypedXmlDocument("Microsoft.Samples.BizTalk.LoansProcessor.Case", xd1);

            //Execute Policy Tester
            try
            {
                policyTester.Execute(doc1, dti);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }

            FileInfo     f = new FileInfo("LoanPocessingResults.xml");
            StreamWriter w = f.CreateText();

            w.Write(doc1.Document.OuterXml);
            w.Close();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// TestStepBase.Execute() implementation
        /// </summary>
        /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
        public override void Execute(Context context)
        {
            var fi = new System.IO.FileInfo(RuleStoreName);

            if (!fi.Exists)
            {
                throw new FileNotFoundException("RuleStoreName", RuleStoreName);
            }

            var ruleStore = new FileRuleStore(fi.FullName);
            var rsInfo = ruleStore.GetRuleSets(RuleSetInfoCollectionName, RuleStore.Filter.Latest);
            if (rsInfo.Count != 1)
            {
                // oops ... error
                throw new ApplicationException(String.Format("RuleStore {0} did not contain RuleSet {1}", RuleStoreName, RuleSetInfoCollectionName));
            }

            var ruleset = ruleStore.GetRuleSet(rsInfo[0]);

            // Create an instance of the DebugTrackingInterceptor
            var dti = new DebugTrackingInterceptor(DebugTracking);

            // Create an instance of the Policy Tester class
            var policyTester = new PolicyTester(ruleset);

            // load the facts into array
            var facts = new object[_factsList.Count]; 
            var i = 0;

            foreach (var currentFact in _factsList)
            {
                switch (currentFact.GetFactType)
                {
                    case "ObjectFact":
                        {
                            var fact = currentFact as ObjectFact;

                            object[] objectArgs = null;
                            if (null != fact.Args)
                            {
                                objectArgs = fact.Args.Split(new char[] { ',' });
                            }

                            System.Reflection.Assembly asm;
                            Type type;
                            if (fact.AssemblyPath.Length > 0)
                            {
                                asm = System.Reflection.Assembly.LoadWithPartialName(fact.AssemblyPath);
                                if (asm == null)
                                {
                                    // fail
                                    throw (new Exception("failed to create type " + fact.Type));
                                }
                                type = asm.GetType(fact.Type, true, false);
                            }
                            else
                            {
                                // must be in path
                                type = Type.GetType(fact.Type);
                            }

                            facts[i] = Activator.CreateInstance(type, objectArgs);
                            break;
                        }
                    case "DocumentFact":
                        {
                            var fact = currentFact as DocumentFact;
                            var xd1 = new XmlDocument();
                            xd1.Load(fact.InstanceDocument);
                            var txd = new TypedXmlDocument(fact.SchemaType, xd1);
                            facts[i] = txd; 
                            break;
                        }
                    case "DataConnectionFact":
                        {
                            var fact = currentFact as DataConnectionFact;
                            var conn = new SqlConnection(fact.ConnectionString);
                            conn.Open();
                            var dc = new DataConnection(fact.Dataset, fact.TableName, conn);
                            facts[i] = dc;
                            break;
                        }
                    case "dataTable":
                    case "dataRow":
                        {
                            var fact = currentFact as DataTableFact;

                            var dAdapt = new SqlDataAdapter();
                            dAdapt.TableMappings.Add("Table", fact.TableName);
                            var conn = new SqlConnection(fact.ConnectionString);
                            conn.Open();
                            var myCommand = new SqlCommand(fact.Command, conn) {CommandType = CommandType.Text};
                            dAdapt.SelectCommand = myCommand;
                            var ds = new DataSet(fact.Dataset);
                            dAdapt.Fill(ds);
                            var tdt = new TypedDataTable(ds.Tables[fact.TableName]);
                            if (fact.Type == "dataRow")
                            {
                                var tdr = new TypedDataRow(ds.Tables[fact.TableName].Rows[0], tdt);
                                facts[i] = tdr;
                            }
                            else
                            {
                                facts[i] = tdt;
                            }
                            break;
                        }
                }
                i++;
            }

            // Execute Policy Tester
            try
            {
                policyTester.Execute(facts, dti);
            }
            catch (Exception e)
            {
                context.LogException(e);
                throw;
            }
            finally
            {
                dti.CloseTraceFile();
            }

            // write out all document instances passed in
            foreach (object fact in facts)
            {
                switch (fact.GetType().Name)
                {
                    case "TypedXmlDocument":
                        {
                            var txd = (TypedXmlDocument)fact;

                            context.LogData("TypedXmlDocument result: ", txd.Document.OuterXml);
                            Stream data = StreamHelper.LoadMemoryStream(txd.Document.OuterXml);

                            // Validate if configured...
                            // HACK: We need to prevent ExecuteValidator for /each/ TypedXmlDocument
                            if (txd.DocumentType == "UBS.CLAS.PoC.Schemas.INSERTS")
                            {
                                foreach (var subStep in SubSteps)
                                {
                                    data = subStep.Execute(data, context);
                                }

                            }

                            break;
                        }
                    case "DataConnection":
                        {
                            var dc = (DataConnection)fact;
                            dc.Update(); // persist any changes
                            break;
                        }
                    case "TypedDataTable":
                        {
                            var tdt = (TypedDataTable)fact;
                            tdt.DataTable.AcceptChanges();
                            break;
                        }
                    case "TypedDataRow":
                        {
                            var tdr = (TypedDataRow)fact;
                            tdr.DataRow.AcceptChanges();
                            break;
                        }
                }
            }
        }
        /// <summary>
        /// Method which executes the BRE Policy which is configured using the config and resolver connection string
        /// </summary>
        /// <param name="config">string containing name, value property values</param>
        /// <param name="resolver">Resolver connection string</param>
        /// <param name="message">Xml document containing the message to pass to the BRE policies if configured properly</param>
        /// <param name="resolution">Resolution object</param>
        /// <param name="bre">BRE Descriptor object</param>
        /// <param name="ctxtValues">Dictionary collection of BizTalk Message Context property value pairs</param>
        /// <param name="pCtxt">BizTalk Pipeline Context</param>
        /// <param name="baseMsg">BizTalk BaseMessage</param>
        /// <returns>Resolver Dictionary Collection containing resolved entries, such as itinerary name, map name, and endpoint address resolution values</returns>
        private static Dictionary <string, string> ResolveRules(string config, string resolver, XmlDocument message, Resolution resolution, BRE bre, Dictionary <string, string> ctxtValues, IPipelineContext pCtxt, ref IBaseMessage baseMsg)
        {
            Dictionary <string, string> dictionary3;
            int    num    = 0;
            int    num2   = 0;
            Policy policy = null;
            Dictionary <string, string> dictionary = null;

            string[]         strArray      = null;
            object[]         objArray      = null;
            TypedXmlDocument document      = null;
            ItineraryFact    itineraryInfo = new ItineraryFact();

            string documentSpecNameField = "Microsoft.Practices.ESB.ResolveProviderMessage";
            Dictionary <string, string> resolverDictionary = new Dictionary <string, string>();

            if (!resolver.Contains(@":\"))
            {
                resolver = resolver + @":\";
            }
            try
            {
                EventLogger.Write("Resolution strong name is {0}.", new object[] { resolution.DocumentSpecNameField });
                if (!string.IsNullOrEmpty(resolution.DocumentSpecNameField) && bre.recognizeMessageFormat)
                {
                    int index = resolution.DocumentSpecNameField.IndexOf(",", StringComparison.CurrentCultureIgnoreCase);
                    if ((index > 0) && (index < resolution.DocumentSpecNameField.Length))
                    {
                        documentSpecNameField = resolution.DocumentSpecNameField.Substring(0, index);
                    }
                    else
                    {
                        documentSpecNameField = resolution.DocumentSpecNameField;
                    }
                }


                // add root node as non promoted value for purpose of using with Orchestrations if needed
                if (ctxtValues == null)
                {
                    ctxtValues = new Dictionary <string, string>();
                }
                ctxtValues.Add("Microsoft.Practices.ESB.ResolveProviderMessage#RootNode", message.DocumentElement.LocalName.ToUpperInvariant());

                MessageContextFactRetriever customFactRetriever = new MessageContextFactRetriever(ctxtValues);

                EventLogger.Write("DocType for typed xml document is {0}.", new object[] { documentSpecNameField });
                if (!string.IsNullOrEmpty(bre.version))
                {
                    strArray = bre.version.Split(".".ToCharArray());
                    if (strArray != null)
                    {
                        num  = Convert.ToInt16(strArray[0], NumberFormatInfo.CurrentInfo);
                        num2 = Convert.ToInt16(strArray[1], NumberFormatInfo.CurrentInfo);
                    }
                }
                if (bre.useMsg)
                {
                    EventLogger.Write("Xml document Content is {0}.", message.OuterXml);
                    objArray = new object[4];
                    document = new TypedXmlDocument(documentSpecNameField, message);

                    objArray[0] = resolution;
                    objArray[1] = document;
                    objArray[2] = itineraryInfo;
                    objArray[3] = customFactRetriever;
                }
                else
                {
                    objArray = new object[] { resolution, itineraryInfo, customFactRetriever };
                }

                bool   useDebugInterceptor = false;
                string outputPath          = string.Empty;
                if (bre.useDebugInterceptorSpecified)
                {
                    useDebugInterceptor = bre.useDebugInterceptor;
                    outputPath          = bre.debugOutputPath;
                    policyExecutor      = new PolicyExecutor(useDebugInterceptor, outputPath);
                }
                else
                {
                    policyExecutor = new PolicyExecutor(false, string.Empty);
                }

                // Check to see if we need to use the Policy Broker
                if (bre.usePolicyBrokerSpecified)
                {
                    if (bre.usePolicyBroker)
                    {
                        PolicyBroker broker = new PolicyBroker(useDebugInterceptor, outputPath);
                        PolicyBrokerInfoCollection _policyInfos = broker.GetPolicies(message, resolution, bre.policy, itineraryInfo, customFactRetriever, num, num2);
                        foreach (var policyBrokerInfo in _policyInfos.PolicyInfos)
                        {
                            var policyInfo       = policyBrokerInfo.Value;
                            int foundPolicyMajor = 0;
                            int foundPolicyMinor = 0;
                            strArray = policyInfo.Version.Split(".".ToCharArray());
                            if (strArray != null)
                            {
                                foundPolicyMajor = Convert.ToInt16(strArray[0], NumberFormatInfo.CurrentInfo);
                                foundPolicyMinor = Convert.ToInt16(strArray[1], NumberFormatInfo.CurrentInfo);
                            }
                            policyExecutor.ExecutePolicy(policyInfo.PolicyName, objArray, foundPolicyMajor, foundPolicyMinor);
                        }
                    }
                    else
                    {
                        // don't use policy broker
                        policyExecutor.ExecutePolicy(bre.policy, objArray, num, num2);
                    }
                }
                else
                {
                    // don't use policy broker
                    policyExecutor.ExecutePolicy(bre.policy, objArray, num, num2);
                }

                if (objArray[0] == null)
                {
                    throw new ResolveException("Resolution is not configured correctly after applying BRE Custom Resolver;\nPlease check the Business Rule Policy");
                }

                // Check for Itinerary fact values
                SetAllResolutionDictionaryEntries(objArray, resolverDictionary, bre);
                dictionary3 = resolverDictionary;

                if (bre.useMsg)
                {
                    TypedXmlDocument doc = (TypedXmlDocument)objArray[1];
                    dictionary3.Add("message", doc.Document.OuterXml);

                    if (bre.useMsgCtxt)
                    {
                        MessageContextFactRetriever customRetriever = (MessageContextFactRetriever)objArray[3];
                        dictionary3.Add("contextValues", GetContextValuesString(customRetriever.GetDictionaryCollection()));

                        // Update the context properties
                        UpdateContextProperties(customRetriever, bre, pCtxt, ref baseMsg);
                    }

                    // Modify the Current Message in pipeline context
                    UpdateMessage(doc.Document.OuterXml, pCtxt, ref baseMsg);
                }
                else
                {
                    if (bre.useMsgCtxt)
                    {
                        MessageContextFactRetriever customRetriever = (MessageContextFactRetriever)objArray[2];
                        dictionary3.Add("contextValues", GetContextValuesString(customRetriever.GetDictionaryCollection()));

                        // Update the context properties
                        UpdateContextProperties(customRetriever, bre, pCtxt, ref baseMsg);
                    }
                }
            }
            catch (Exception exception)
            {
                EventLogger.Write(MethodBase.GetCurrentMethod(), exception);
                throw;
            }
            finally
            {
                if (objArray != null)
                {
                    objArray = null;
                }
                if (document != null)
                {
                    document = null;
                }
                if (resolution != null)
                {
                    resolution = null;
                }
                if (bre != null)
                {
                    bre = null;
                }
                if (strArray != null)
                {
                    strArray = null;
                }
                if (policy != null)
                {
                    policy.Dispose();
                    policy = null;
                }
                if (dictionary != null)
                {
                    dictionary.Clear();
                    dictionary = null;
                }
                if (resolverDictionary != null)
                {
                    resolverDictionary = null;
                }
                if (ctxtValues != null)
                {
                    ctxtValues = null;
                }
            }
            return(dictionary3);
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     TestStepBase.Execute() implementation
        /// </summary>
        /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
        public override void Execute(Context context)
        {
            var fi = new FileInfo(RuleStoreName);

            if (!fi.Exists)
            {
                throw new FileNotFoundException("RuleStoreName", RuleStoreName);
            }

            var ruleStore = new FileRuleStore(fi.FullName);
            var rsInfo    = ruleStore.GetRuleSets(RuleSetInfoCollectionName, RuleStore.Filter.Latest);

            if (rsInfo.Count != 1)
            {
                // oops ... error
                throw new InvalidOperationException(string.Format("RuleStore {0} did not contain RuleSet {1}",
                                                                  RuleStoreName, RuleSetInfoCollectionName));
            }

            var ruleset = ruleStore.GetRuleSet(rsInfo[0]);


            // load the facts into array
            var facts = new List <object>(FactsList.Count);

            // Create an instance of the Policy Tester class
            using (var policyTester = new PolicyTester(ruleset))
            {
                foreach (var currentFact in FactsList)
                {
                    switch (currentFact.GetType().ToString())
                    {
                    case "ObjectFact":
                    {
                        var fact = currentFact as ObjectFact;

                        object[] objectArgs = null;
                        if (null != fact.Args)
                        {
                            objectArgs = fact.Args.Split(',').Cast <object>().ToArray();
                        }

                        Type type;
                        if (fact.AssemblyPath.Length > 0)
                        {
                            var asm = Assembly.Load(fact.AssemblyPath);
                            if (asm == null)
                            {
                                // fail
                                throw (new InvalidOperationException("failed to create type " + fact.Type));
                            }
                            type = asm.GetType(fact.Type, true, false);
                        }
                        else
                        {
                            // must be in path
                            type = Type.GetType(fact.Type);
                        }

                        facts.Add(Activator.CreateInstance(type, objectArgs));
                        break;
                    }

                    case "DocumentFact":
                    {
                        var fact = currentFact as DocumentFact;
                        var xd1  = new XmlDocument();
                        xd1.Load(fact.InstanceDocument);
                        var txd = new TypedXmlDocument(fact.SchemaType, xd1);
                        facts.Add(txd);
                        break;
                    }

                    case "DataConnectionFact":
                    {
                        var fact = currentFact as DataConnectionFact;
                        var conn = new SqlConnection(fact.ConnectionString);
                        conn.Open();
                        var dc = new DataConnection(fact.Dataset, fact.TableName, conn);
                        facts.Add(dc);
                        break;
                    }

                    case "dataTable":
                    case "dataRow":
                    {
                        var fact = currentFact as DataTableFact;

                        var conn = new SqlConnection(fact.ConnectionString);
                        conn.Open();
                        var myCommand = new SqlCommand(fact.Command, conn)
                        {
                            CommandType = CommandType.Text
                        };
                        var dAdapt = new SqlDataAdapter();
                        dAdapt.TableMappings.Add("Table", fact.TableName);
                        dAdapt.SelectCommand = myCommand;
                        var ds = new DataSet(fact.Dataset);
                        dAdapt.Fill(ds);
                        var tdt = new TypedDataTable(ds.Tables[fact.TableName]);
                        if (fact.Type == "dataRow")
                        {
                            var tdr = new TypedDataRow(ds.Tables[fact.TableName].Rows[0], tdt);
                            facts.Add(tdr);
                        }
                        else
                        {
                            facts.Add(tdt);
                        }
                        break;
                    }
                    }
                }

                // Create an instance of the DebugTrackingInterceptor
                using (var dti = new DebugTrackingInterceptor(DebugTracking))
                {
                    // Execute Policy Tester
                    try
                    {
                        policyTester.Execute(facts.ToArray(), dti);
                    }
                    catch (Exception e)
                    {
                        context.LogException(e);
                        throw;
                    }
                }
            }

            // write out all document instances passed in
            foreach (var fact in facts)
            {
                switch (fact.GetType().Name)
                {
                case "TypedXmlDocument":
                {
                    var txd = (TypedXmlDocument)fact;

                    context.LogData("TypedXmlDocument result: ", txd.Document.OuterXml);
                    using (var data = StreamHelper.LoadMemoryStream(txd.Document.OuterXml))
                    {
                        if (txd.DocumentType == "UBS.CLAS.PoC.Schemas.INSERTS")
                        {
                            SubSteps.Aggregate(data, (current, subStep) => subStep.Execute(current, context));
                        }
                    }

                    break;
                }

                case "DataConnection":
                {
                    var dc = (DataConnection)fact;
                    dc.Update();     // persist any changes
                    break;
                }

                case "TypedDataTable":
                {
                    var tdt = (TypedDataTable)fact;
                    tdt.DataTable.AcceptChanges();
                    break;
                }

                case "TypedDataRow":
                {
                    var tdr = (TypedDataRow)fact;
                    tdr.DataRow.AcceptChanges();
                    break;
                }
                }
            }
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            // create a ruleset
            Console.WriteLine("Creating a new ruleset ...");
            RuleSet rs = CreateRuleset("SampleRuleset");

            // save it to a file
            Console.WriteLine("Saving ruleset to " + RuleStoreFilename + " ...");
            SaveToFile(RuleStoreFilename, rs);

            // load the same ruleset from the file
            Console.WriteLine("Loading ruleset ...");
            RuleSet newRS = LoadFromFile(RuleStoreFilename, "SampleRuleset");

            // create an engine for the ruleset
            Microsoft.RuleEngine.RuleEngine engine = new Microsoft.RuleEngine.RuleEngine((newRS), false);

            //create an instance of the XML object
            XmlDocument xd1 = new XmlDocument();

            xd1.Load(@"..\..\SampleDocumentInstance.xml");
            TypedXmlDocument doc1 = new TypedXmlDocument("SampleSchema", xd1);

            // create the array of short-term facts
            object[] shortTermFacts = new object[4];
            shortTermFacts[0] = doc1;
            shortTermFacts[1] = new Microsoft.Samples.BizTalk.BusinessRulesHelloWorld1.MySampleLibrary.MySampleBusinessObject(1);
            shortTermFacts[2] = new Microsoft.Samples.BizTalk.BusinessRulesHelloWorld1.MySampleLibrary.MySampleBusinessObject(2);
            shortTermFacts[3] = new Microsoft.Samples.BizTalk.BusinessRulesHelloWorld1.MySampleLibrary.MySampleBusinessObject(3);

            try
            {
                // assert several objects
                Console.WriteLine("Asserting objects ...");
                engine.Assert(shortTermFacts);

                // now execute to see what happens
                Console.WriteLine("Executing ...");

                engine.Execute();
            }


            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Press any key to finish ...");
            System.Console.Read();

            // Clean up SampleRuleStore.xml
            CleanUp();

            // there should be 2 lines output:
            //   MySampleBusinessObject -- MySampleMethod executed for object 1 with parameter 5
            //   MySampleBusinessObject -- MySampleMethod executed for object 3 with parameter 5

            //This is because:

            /*
             * The rule created programmatically within the CreateRuleset() method says:
             *
             * IF
             *
             * MySampleBusinessObject.MyValue is not equal to the value of the ID element in the XML document.
             * THEN
             *
             * Execute MySampleBusinessObject.MySampleMethod(int) with a hardcoded integer constant 5 ".
             *
             * In our case we assert 3 .NET objects with "MyValue" = 1,2, and 3 along with an XML document with ID = 1, as fact instances.
             *
             * Hence the rule fires twice for the 2 .NET property values that are != 1
             *
             */
        }
        /// <summary>
        /// TestStepBase.Execute() implementation
        /// </summary>
        /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
        public override void Execute(Context context)
        {
            var fi = new System.IO.FileInfo(RuleStoreName);

            if (!fi.Exists)
            {
                throw new FileNotFoundException("RuleStoreName", RuleStoreName);
            }

            var ruleStore = new FileRuleStore(fi.FullName);
            var rsInfo    = ruleStore.GetRuleSets(RuleSetInfoCollectionName, RuleStore.Filter.Latest);

            if (rsInfo.Count != 1)
            {
                // oops ... error
                throw new ApplicationException(String.Format("RuleStore {0} did not contain RuleSet {1}", RuleStoreName, RuleSetInfoCollectionName));
            }

            var ruleset = ruleStore.GetRuleSet(rsInfo[0]);

            // Create an instance of the DebugTrackingInterceptor
            var dti = new DebugTrackingInterceptor(DebugTracking);

            // Create an instance of the Policy Tester class
            var policyTester = new PolicyTester(ruleset);

            // load the facts into array
            var facts = new object[_factsList.Count];
            var i     = 0;

            foreach (var currentFact in _factsList)
            {
                switch (currentFact.GetType().ToString())
                {
                case "ObjectFact":
                {
                    var fact = currentFact as ObjectFact;

                    object[] objectArgs = null;
                    if (null != fact.Args)
                    {
                        objectArgs = fact.Args.Split(new char[] { ',' });
                    }

                    System.Reflection.Assembly asm;
                    Type type;
                    if (fact.AssemblyPath.Length > 0)
                    {
                        asm = System.Reflection.Assembly.LoadWithPartialName(fact.AssemblyPath);
                        if (asm == null)
                        {
                            // fail
                            throw (new Exception("failed to create type " + fact.Type));
                        }
                        type = asm.GetType(fact.Type, true, false);
                    }
                    else
                    {
                        // must be in path
                        type = Type.GetType(fact.Type);
                    }

                    facts[i] = Activator.CreateInstance(type, objectArgs);
                    break;
                }

                case "DocumentFact":
                {
                    var fact = currentFact as DocumentFact;
                    var xd1  = new XmlDocument();
                    xd1.Load(fact.InstanceDocument);
                    var txd = new TypedXmlDocument(fact.SchemaType, xd1);
                    facts[i] = txd;
                    break;
                }

                case "DataConnectionFact":
                {
                    var fact = currentFact as DataConnectionFact;
                    var conn = new SqlConnection(fact.ConnectionString);
                    conn.Open();
                    var dc = new DataConnection(fact.Dataset, fact.TableName, conn);
                    facts[i] = dc;
                    break;
                }

                case "dataTable":
                case "dataRow":
                {
                    var fact = currentFact as DataTableFact;

                    var dAdapt = new SqlDataAdapter();
                    dAdapt.TableMappings.Add("Table", fact.TableName);
                    var conn = new SqlConnection(fact.ConnectionString);
                    conn.Open();
                    var myCommand = new SqlCommand(fact.Command, conn)
                    {
                        CommandType = CommandType.Text
                    };
                    dAdapt.SelectCommand = myCommand;
                    var ds = new DataSet(fact.Dataset);
                    dAdapt.Fill(ds);
                    var tdt = new TypedDataTable(ds.Tables[fact.TableName]);
                    if (fact.Type == "dataRow")
                    {
                        var tdr = new TypedDataRow(ds.Tables[fact.TableName].Rows[0], tdt);
                        facts[i] = tdr;
                    }
                    else
                    {
                        facts[i] = tdt;
                    }
                    break;
                }
                }
                i++;
            }

            // Execute Policy Tester
            try
            {
                policyTester.Execute(facts, dti);
            }
            catch (Exception e)
            {
                context.LogException(e);
                throw;
            }
            finally
            {
                dti.CloseTraceFile();
            }

            // write out all document instances passed in
            foreach (object fact in facts)
            {
                switch (fact.GetType().Name)
                {
                case "TypedXmlDocument":
                {
                    var txd = (TypedXmlDocument)fact;

                    context.LogData("TypedXmlDocument result: ", txd.Document.OuterXml);
                    Stream data = StreamHelper.LoadMemoryStream(txd.Document.OuterXml);

                    // Validate if configured...
                    // HACK: We need to prevent ExecuteValidator for /each/ TypedXmlDocument
                    if (txd.DocumentType == "UBS.CLAS.PoC.Schemas.INSERTS")
                    {
                        foreach (var subStep in SubSteps)
                        {
                            data = subStep.Execute(data, context);
                        }
                    }

                    break;
                }

                case "DataConnection":
                {
                    var dc = (DataConnection)fact;
                    dc.Update();         // persist any changes
                    break;
                }

                case "TypedDataTable":
                {
                    var tdt = (TypedDataTable)fact;
                    tdt.DataTable.AcceptChanges();
                    break;
                }

                case "TypedDataRow":
                {
                    var tdr = (TypedDataRow)fact;
                    tdr.DataRow.AcceptChanges();
                    break;
                }
                }
            }
        }
Ejemplo n.º 14
0
 public ApplyTypedXMLDocumentInstruction(TypedXmlDocument document, XMLFactsApplicationStageEnum xmlFactsApplicationStage, string callToken)
 {
     this.document = document;
     this.xmlFactsApplicationStage = xmlFactsApplicationStage;
     this.callToken = callToken;
 }
        private void FireRule(XmlDocument xd, string fileName)
        {
            string           destDirectory  = outboundTxtBx.Text.Trim();
            string           traceDirectory = traceTxtBx.Text.Trim();
            TypedXmlDocument doc1           = new TypedXmlDocument("TrackSource.BizTalk.Schemas.InboundToRules", xd);

            string [] policies = new string[14] {
                "Data Preparation",
                "Pre-Processing Group 1",
                "Pre-Processing Group 2",
                "Pre-Processing Group 3",
                "Pre-Processing Group 4",
                "Pre-Processing Group 5",
                "Pre-Processing Group 6",
                "Lender Specific",
                "Insurance Servicing",
                "Post Processing Group 1",
                "Post Processing Group 2",
                "Black Hole",
                "Fidelity Hold",
                "Procedure Set"
            };

            ProcessingTxtBx.Text = ProcessingTxtBx.Text + "Processing Started " + DateTime.Now + "\r\n";
            string traceFileName = fileName + "_RuleTrace";

            traceFileName = traceDirectory + traceFileName + ".txt";
            if (File.Exists(traceFileName))
            {
                File.Delete(traceFileName);
            }
            DebugTrackingInterceptor dti = new DebugTrackingInterceptor(traceFileName);

            try
            {
                for (int i = 0; i < policies.Length; i++)
                {
                    string PolicyName = policies[i].Trim();
                    lblProcessing.Text   = PolicyName;
                    ProcessingTxtBx.Text = ProcessingTxtBx.Text + "Processing ... " + policies[i] + " " + DateTime.Now + "\r\n";
                    Application.DoEvents();
                    Microsoft.RuleEngine.Policy tstPolicy = new Microsoft.RuleEngine.Policy(PolicyName);
                    ArrayList shortTermFacts = new ArrayList();
                    shortTermFacts = GetFacts(PolicyName);
                    shortTermFacts.Add(doc1);
                    tstPolicy.Execute(shortTermFacts.ToArray(), dti);
                    tstPolicy = null;
                }
            }
            catch (Exception ex)
            {
                ProcessingTxtBx.Text = ProcessingTxtBx.Text + "Exception Caught Check _Excepion Text File";
                string exceptionFileName = fileName + "_Exception";
                exceptionFileName = traceDirectory + exceptionFileName + ".txt";
                if (File.Exists(exceptionFileName))
                {
                    File.Delete(exceptionFileName);
                }
                StreamWriter sw2 = new StreamWriter(exceptionFileName);
                ProcessingTxtBx.Text = ProcessingTxtBx.Text + ex.Message;
                sw2.Write(ex.Message.ToString());
                sw2.Close();
            }
            finally
            {
                ProcessingTxtBx.Text = ProcessingTxtBx.Text + "Processing Done " + DateTime.Now + "\r\n";
                lblProcessing.Text   = "Writing output File";
                string processedDoc = fileName + "_Outbound";
                processedDoc = destDirectory + processedDoc + ".xml";
                if (File.Exists(processedDoc))
                {
                    File.Delete(processedDoc);
                }
                StreamWriter sw = new StreamWriter(processedDoc);
                dti.CloseTraceFile();
                sw.Write(doc1.Document.InnerXml.ToString());
                sw.Close();
                xd   = null;
                doc1 = null;
                lblProcessing.Text = "Processing Completed for " + fileName;
            }
            //return xd;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Synchronously executes the task using the specified <see cref="RuntimeTaskExecutionContext"/> execution context object.
        /// </summary>
        /// <param name="context">The execution context.</param>
        public override void Run(RuntimeTaskExecutionContext context)
        {
            Guard.ArgumentNotNull(context, "context");
            Guard.ArgumentNotNull(context.Message, "context.Message");

            var callToken = TraceManager.PipelineComponent.TraceIn();

            Stream messageDataStream = null;
            IEnumerable <object> facts = null;
            string             policyName = PolicyName, ctxPropName = null, ctxPropNamespace = null;
            Version            policyVersion = PolicyVersion;
            RulesEngineRequest request       = null;
            bool responseRequired            = true;

            try
            {
                XmlReaderSettings readerSettings = new XmlReaderSettings()
                {
                    CloseInput = false, CheckCharacters = false, IgnoreComments = true, IgnoreProcessingInstructions = true, IgnoreWhitespace = true, ValidationType = ValidationType.None
                };

                if (context.Message.BodyPart != null)
                {
                    messageDataStream = BizTalkUtility.EnsureSeekableStream(context.Message, context.PipelineContext);

                    if (messageDataStream != null)
                    {
                        using (XmlReader messageDataReader = XmlReader.Create(messageDataStream, readerSettings))
                        {
                            // Navigate through the XML reader until we find an element with the expected name and namespace.
                            while (!messageDataReader.EOF && messageDataReader.Name != WellKnownContractMember.MessageParameters.Request && messageDataReader.NamespaceURI != WellKnownNamespace.DataContracts.General)
                            {
                                messageDataReader.Read();
                            }

                            // Element was found, let's perform de-serialization from XML into a RulesEngineRequest object.
                            if (!messageDataReader.EOF)
                            {
                                DataContractSerializer serializer = new DataContractSerializer(typeof(RulesEngineRequest));
                                request = serializer.ReadObject(messageDataReader, false) as RulesEngineRequest;

                                if (request != null)
                                {
                                    policyName    = request.PolicyName;
                                    policyVersion = request.PolicyVersion;
                                    facts         = request.Facts;
                                }
                            }
                        }
                    }
                }

                // Check if the policy name was supplied when this component was instantiated or retrieved from a request message.
                if (!String.IsNullOrEmpty(policyName))
                {
                    // If policy version is not specified, use the latest deployed version.
                    PolicyExecutionInfo policyExecInfo = policyVersion != null ? new PolicyExecutionInfo(policyName, policyVersion) : new PolicyExecutionInfo(policyName);

                    // Use all context properties as parameters when invoking a policy.
                    for (int i = 0; i < context.Message.Context.CountProperties; i++)
                    {
                        ctxPropName      = null;
                        ctxPropNamespace = null;

                        object ctxPropValue = context.Message.Context.ReadAt(i, out ctxPropName, out ctxPropNamespace);
                        policyExecInfo.AddParameter(String.Format("{0}#{1}", ctxPropNamespace, ctxPropName), ctxPropValue);
                    }

                    // If we still haven't determined what facts should be passed to the policy, let's use the request message as a single fact.
                    if (null == facts)
                    {
                        if (messageDataStream != null)
                        {
                            // Unwind the data stream back to the beginning.
                            messageDataStream.Seek(0, SeekOrigin.Begin);

                            // Read the entire message into a BRE-compliant type XML document.
                            using (XmlReader messageDataReader = XmlReader.Create(messageDataStream, readerSettings))
                            {
                                facts            = new object[] { new TypedXmlDocument(Resources.DefaultTypedXmlDocumentTypeName, messageDataReader) };
                                responseRequired = false;
                            }
                        }
                    }

                    // Execute a BRE policy.
                    PolicyExecutionResult policyExecResult = PolicyHelper.Execute(policyExecInfo, facts);

                    // CHeck if we need to return a response. We don't need to reply back if we are not handling ExecutePolicy request message.
                    if (responseRequired)
                    {
                        // Construct a response message.
                        RulesEngineResponse response = new RulesEngineResponse(policyExecResult.PolicyName, policyExecResult.PolicyVersion, policyExecResult.Success);

                        // Add all facts that were being used when invoking the policy.
                        response.AddFacts(facts);

                        // Create a response message.
                        IBaseMessagePart  responsePart = BizTalkUtility.CreateResponsePart(context.PipelineContext.GetMessageFactory(), context.Message);
                        XmlWriterSettings settings     = new XmlWriterSettings();

                        // Initialize a new stream that will hold the response message payload.
                        MemoryStream dataStream = new MemoryStream();
                        context.PipelineContext.ResourceTracker.AddResource(dataStream);

                        settings.CloseOutput       = false;
                        settings.CheckCharacters   = false;
                        settings.ConformanceLevel  = ConformanceLevel.Fragment;
                        settings.NamespaceHandling = NamespaceHandling.OmitDuplicates;

                        using (XmlWriter responseWriter = XmlWriter.Create(dataStream, settings))
                        {
                            responseWriter.WriteResponseStartElement("r", WellKnownContractMember.MethodNames.ExecutePolicy, WellKnownNamespace.ServiceContracts.General);

                            DataContractSerializer dcSerializer = new DataContractSerializer(typeof(RulesEngineResponse), String.Concat(WellKnownContractMember.MethodNames.ExecutePolicy, WellKnownContractMember.ResultMethodSuffix), WellKnownNamespace.ServiceContracts.General);
                            dcSerializer.WriteObject(responseWriter, response);

                            responseWriter.WriteEndElement();
                            responseWriter.Flush();
                        }

                        dataStream.Seek(0, SeekOrigin.Begin);
                        responsePart.Data = dataStream;
                    }
                    else
                    {
                        if (facts != null)
                        {
                            TypedXmlDocument xmlDoc = facts.Where((item) => { return(item.GetType() == typeof(TypedXmlDocument)); }).FirstOrDefault() as TypedXmlDocument;

                            if (xmlDoc != null)
                            {
                                // Initialize a new stream that will hold the response message payload.
                                MemoryStream dataStream = new MemoryStream();
                                context.PipelineContext.ResourceTracker.AddResource(dataStream);

                                XmlWriterSettings settings = new XmlWriterSettings
                                {
                                    CloseOutput       = false,
                                    CheckCharacters   = false,
                                    ConformanceLevel  = ConformanceLevel.Fragment,
                                    NamespaceHandling = NamespaceHandling.OmitDuplicates
                                };

                                using (XmlWriter dataWriter = XmlWriter.Create(dataStream, settings))
                                {
                                    xmlDoc.Document.WriteContentTo(dataWriter);
                                    dataWriter.Flush();
                                }

                                dataStream.Seek(0, SeekOrigin.Begin);
                                context.Message.BodyPart.Data = dataStream;
                            }
                        }
                    }
                }
                else
                {
                    throw new ApplicationException(String.Format(CultureInfo.InvariantCulture, ExceptionMessages.PolicyNameNotSpecified));
                }
            }
            finally
            {
                if (messageDataStream != null && messageDataStream.CanSeek && messageDataStream.Position > 0)
                {
                    messageDataStream.Seek(0, SeekOrigin.Begin);
                }

                TraceManager.PipelineComponent.TraceOut(callToken);
            }
        }
Ejemplo n.º 17
0
		/// <summary>
		/// ITestStep.Execute() implementation
		/// </summary>
		/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
		/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
		public void Execute(System.Xml.XmlNode testConfig , Context context)
		{
			// Using Policy Tester
			 
			// Retrieve Rule-Set from Policy file
			string RuleStoreName = context.ReadConfigAsString(testConfig, "RuleStoreName");
			string RuleSetInfoCollectionName =context.ReadConfigAsString(testConfig, "RuleSetInfoCollectionName");
			string DebugTracking = context.ReadConfigAsString(testConfig, "DebugTracking");
			string SampleXML = context.ReadConfigAsString(testConfig, "SampleXML");
			string XSD = context.ReadConfigAsString(testConfig, "XSD");
			string ResultFile = context.ReadConfigAsString(testConfig, "ResultFile");

			RuleStore ruleStore = new FileRuleStore(RuleStoreName);
			RuleSetInfoCollection rsInfo = ruleStore.GetRuleSets(RuleSetInfoCollectionName, RuleStore.Filter.Latest);
			if (rsInfo.Count != 1)
			{
				// oops ... error
				throw new ApplicationException();
			}
			
			RuleSet ruleset = ruleStore.GetRuleSet(rsInfo[0]);
			
			// Create an instance of the DebugTrackingInterceptor
			DebugTrackingInterceptor dti = new DebugTrackingInterceptor(DebugTracking);

			// Create an instance of the Policy Tester class
			PolicyTester policyTester = new PolicyTester(ruleset);

			XmlDocument xd1 = new XmlDocument();
			xd1.Load(SampleXML);
								
			TypedXmlDocument doc1 = new TypedXmlDocument(XSD, xd1);

			// Execute Policy Tester
			try
			{
				policyTester.Execute(doc1, dti);
			}
			catch (Exception e) 
			{
				context.LogException(e);
				throw;
			}
			
			FileInfo f = new FileInfo(ResultFile);
			StreamWriter w = f.CreateText();
			w.Write(doc1.Document.OuterXml);
			w.Close();
		}
Ejemplo n.º 18
0
 public TypedXMLDocumentMetaInstructions(TypedXmlDocument doc, XMLFactsApplicationStageEnum xmlFactsApplicationStage)
 {
     this.doc = doc;
     this.xmlFactsApplicationStage = xmlFactsApplicationStage;
 }
Ejemplo n.º 19
0
 public void AddNodeWithNamespaceIfNotThere(TypedXmlDocument document, string xpath, string nodeName, string nodeNamespace)
 {
     XmlHelper.AddNodeIfNotThere(document, xpath, nodeName, nodeNamespace);
 }
Ejemplo n.º 20
0
 public void AddNode(TypedXmlDocument document, string xpath, string nodeName)
 {
     XmlHelper.AddNode(document, xpath, nodeName);
 }
Ejemplo n.º 21
0
 public void AddAttribute(TypedXmlDocument document, string xpath, string attributeName, object attributeValue)
 {
     XmlHelper.AddAttribute(document, xpath, attributeName, attributeValue);
 }
Ejemplo n.º 22
0
 public void AddNodeWithNamespaceAndValue(TypedXmlDocument document, string xpath, string nodeName, string nodeNamespace, string value)
 {
     XmlHelper.AddNodeWithValue(document, xpath, nodeName, nodeNamespace, value);
 }