void IPolicy.Execute(params object[] facts) { using (var policy = new Microsoft.RuleEngine.Policy(_ruleSetInfo.Name, _ruleSetInfo.MajorRevision, _ruleSetInfo.MinorRevision)) { var interceptor = RuleSetTrackingLogger.Create(policy.RuleSetInfo); if (interceptor == null) { policy.Execute(facts); } else { policy.Execute(facts, interceptor); } } }
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; }