/// <summary> /// Executes a pipeline component to process the input message and returns the result message. /// </summary> /// <param name="pContext">A reference to <see cref="Microsoft.BizTalk.Component.Interop.IPipelineContext"/> object that contains the current pipeline context.</param> /// <param name="pInMsg">A reference to <see cref="Microsoft.BizTalk.Message.Interop.IBaseMessage"/> object that contains the message to process.</param> /// <returns>A reference to the returned <see cref="Microsoft.BizTalk.Message.Interop.IBaseMessage"/> object which will contain the output message.</returns> public override IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg) { if (pContext != null && pInMsg != null) { PolicyExecutionInfo policyExecInfo = !String.IsNullOrEmpty(PolicyVersion) ? new PolicyExecutionInfo(PolicyName, System.Version.Parse(PolicyVersion)) : new PolicyExecutionInfo(PolicyName); string ctxPropName, ctxPropNamespace; for (int i = 0; i < pInMsg.Context.CountProperties; i++) { ctxPropName = null; ctxPropNamespace = null; object ctxPropValue = pInMsg.Context.ReadAt(i, out ctxPropName, out ctxPropNamespace); policyExecInfo.AddParameter(String.Format("{0}{1}{2}", ctxPropNamespace, BizTalkUtility.ContextPropertyNameSeparator, ctxPropName), ctxPropValue); #if DEBUG TraceManager.PipelineComponent.TraceDetails("DETAIL: Context property added: {0}{1}{2} = {3}", ctxPropNamespace, BizTalkUtility.ContextPropertyNameSeparator, ctxPropName, ctxPropValue); #endif } using (RuntimeTaskExecutionContext taskExecContext = new RuntimeTaskExecutionContext(pContext, pInMsg)) { IList <IMessagingRuntimeExtenderTask> registeredTasks = RuntimeTaskFactory.GetRegisteredTasks(taskExecContext); try { PolicyExecutionResult policyExecResult = PolicyHelper.Execute(policyExecInfo, registeredTasks); if (policyExecResult.Success) { foreach (IMessagingRuntimeExtenderTask task in taskExecContext.Extensions.FindAll <IMessagingRuntimeExtenderTask>()) { if (task.CanRun) { task.Run(taskExecContext); } } return(taskExecContext.Message); } } finally { policyExecInfo.ClearParameters(); registeredTasks.Clear(); registeredTasks = null; } } } return(pInMsg); }
public void ValidateHandleGetConfigurationSectionRequestPolicy() { PolicyExecutionInfo policyExecInfo = new PolicyExecutionInfo("Contoso.Cloud.Integration.GenericCloudRequestHandling"); policyExecInfo.AddParameter("http://schemas.microsoft.com/BizTalk/2003/soap-properties#MethodName", "Contoso.Cloud.Integration.ServiceContracts/IOnPremiseConfigurationService/GetConfigurationSection"); IList <IMessagingRuntimeExtenderTask> registeredTasks = RuntimeTaskFactory.GetRegisteredTasks(); PolicyExecutionResult policyExecResult = PolicyHelper.Execute(policyExecInfo, registeredTasks); IEnumerable <ExternalComponentInvokeTask> execTasks = registeredTasks.OfType <ExternalComponentInvokeTask>(); Assert.IsTrue(policyExecResult.Success, "Policy execution was not successful"); Assert.IsFalse(execTasks.Count() == 0, "No ExternalComponentInvokeTask was found in task collection"); ExternalComponentInvokeTask execTask = execTasks.ElementAt <ExternalComponentInvokeTask>(0); Assert.IsNotNull(execTask, "execTask instance has not been found"); Assert.IsFalse(String.IsNullOrEmpty(execTask.AssemblyName), "AssemblyName is null or empty"); Assert.IsFalse(String.IsNullOrEmpty(execTask.TypeName), "TypeName is null or empty"); }