/// <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); }
public PolicyBroker(bool debug, string outputPath) { this.policyExecutor = new PolicyExecutor(debug, outputPath); }