Exemplo n.º 1
0
 public void Execute(ref Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg, Microsoft.BizTalk.Component.Interop.IPipelineContext pc)
 {
     if (xmlFactsApplicationStage == XMLFactsApplicationStageEnum.Explicit)
     {
         TypedXMLDocumentWrapper.ApplyTypedXMLDocument(document, inmsg, pc, callToken);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Implements IComponent.Execute method.
        /// </summary>
        /// <param name="pc">Pipeline context</param>
        /// <param name="inmsg">Input message</param>
        /// <returns>Original input message</returns>
        /// <remarks>
        /// IComponent.Execute method is used to initiate
        /// the processing of the message in this pipeline component.
        /// </remarks>
        public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(Microsoft.BizTalk.Component.Interop.IPipelineContext pc, Microsoft.BizTalk.Message.Interop.IBaseMessage inmsg)
        {
            long ticks = TraceIn();

            if (_Enabled)
            {
                // Setup the BREPipelineMetaInstructionCollection by copying over the body and context from the input message
                SetupBREPipelineMetaInstructionCollection(pc, inmsg);

                // Instantiate a TypedXMLDocumentWrapper class pointing to the body part's stream, a SQLDataConnectionCollection, and a MessageUtility object, passing in the 
                // body part's stream, and if available the message type context property value as well
                InstantiateInstructionLoaderPolicyFacts(pc);

                // Set ApplicationContext to String.Empty if it has a null value since that would cause the rules engine to crash
                if (applicationContext == null)
                {
                    applicationContext = string.Empty;
                }

                try
                {
                    // Execute the InstructionLoaderPolicy
                    if (!string.IsNullOrEmpty(instructionLoaderPolicy))
                    {
                        object[] instructionLoaderFacts = { applicationContext, _BREPipelineMetaInstructionCollection, documentWrapper, sqlConnectionCollection, utility };
                        ExecutePolicy(instructionLoaderPolicy, instructionLoaderFacts, instructionLoaderPolicyVersion);
                    }

                    // If the InstructionLoaderPolicy returned a handled error then throw that now
                    if (_BREPipelineMetaInstructionCollection.BREException != null)
                    {
                        throw _BREPipelineMetaInstructionCollection.BREException;
                    }

                    // Override the default ExecutionPolicy name and version, ApplicationContext, and XMLFactsApplicationStage if an override instruction was set by the InstructionLoaderPolicy
                    ApplyOverrides();

                    // Add out of the box MetaInstructions and custom MetaInstructions set on the pipeline component parameters
                    // to the collection so they can be used in any ExecutionPolicy
                    AddOutOfTheBoxMetaInstructions();
                    AddMetaInstructionsFromPipelineComponentParameters();

                    // Execute the ExecutionPolicy using the instantiated MetaInstructions as facts and passing in the TypedXMLDocument from within the wrapper if properly setup
                    // as well as any DataConnections that were setup in the InstructionLoaderPolicy
                    if (!string.IsNullOrEmpty(executionPolicy))
                    {
                        object[] pipelineMetaInstructionFacts = SetupExecutionPolicyFacts();

                        // Execute the Execution policy in question, utilizing the DebugTrackingInspector if a TrackingFolder has been specified
                        ExecutePolicy(executionPolicy, pipelineMetaInstructionFacts, executionPolicyVersion);

                        // If any of the MetaInstructions have returned exceptions then throw them now.
                        _BREPipelineMetaInstructionCollection.ThrowExceptions();

                        try
                        {
                            // If a TypedXMLDocument had been setup and xmlFactsApplicationStage is set to BeforeInstructionExecution then fetch 
                            // the potentially updated body from the asserted fact and replace the message body stream with this
                            if (_XMLFactsApplicationStage == XMLFactsApplicationStageEnum.BeforeInstructionExecution && documentWrapper.DocumentCount == 1)
                            {
                                TypedXMLDocumentWrapper.ApplyTypedXMLDocument((TypedXmlDocument)pipelineMetaInstructionFacts[2], _BREPipelineMetaInstructionCollection.InMsg, pc, callToken);
                            }

                            // Execute all the instructions that have been loaded into the MetaInstructions by the ExecutionPolicy
                            _BREPipelineMetaInstructionCollection.Execute();

                            // If a TypedXMLDocument had been setup and xmlFactsApplicationStage is set to AfterInstructionExecution then fetch 
                            // the potentially updated body from the asserted fact and replace the message body stream with this.  First check to see if the 
                            // message and/or body part are null and if so create them with context copied from the original message
                            if (_XMLFactsApplicationStage == XMLFactsApplicationStageEnum.AfterInstructionExecution && documentWrapper.DocumentCount == 1)
                            {
                                RecreateBizTalkMessageAndBodyPartIfNecessary(pc, inmsg);
                                TypedXMLDocumentWrapper.ApplyTypedXMLDocument((TypedXmlDocument)pipelineMetaInstructionFacts[2], _BREPipelineMetaInstructionCollection.InMsg, pc, callToken);
                            }
                        }
                        catch (Exception)
                        {
                            // Call compensation methods on all MetaInstructions before throwing the error
                            _BREPipelineMetaInstructionCollection.Compensate();
                            throw;
                        }
                    }
                }
                catch (Exception e)
                {
                    TraceManager.PipelineComponent.TraceError(e, true, Guid.Parse(callToken));
                    
                    // Handle any exception in a recoverable fashion if RIP has been setup, otherwise throw the exception
                    if (recoverableInterchangeProcessingEnabled)
                    {
                        HandleRIPException(inmsg, e);
                    }
                    else
                    {
                        _BREPipelineMetaInstructionCollection.InMsg.BodyPart.Data.Position = 0;

                        TraceManager.PipelineComponent.TraceEndScope(callToken, ticks);
                        TraceManager.PipelineComponent.TraceOut(callToken);
                        throw;
                    }
                }
                finally
                {
                    //Close all SQLConnections in the collection
                    if (sqlConnectionCollection.SQLConnectionCount > 0)
                    {
                        sqlConnectionCollection.CloseSQLConnections();
                    }
                }

                // If RIP has been setup then apply the appropriate context properties to ensure that routing failures are handled in a recoverable fashion
                if (recoverableInterchangeProcessingEnabled)
                {
                    _BREPipelineMetaInstructionCollection.InMsg.Context.Write(BizTalkGlobalPropertySchemaEnum.SuspendMessageOnRoutingFailure.ToString(), ContextPropertyNamespaces._BTSPropertyNamespace,
                            true);
                }

                TraceManager.PipelineComponent.TraceEndScope(callToken, ticks);
                TraceManager.PipelineComponent.TraceOut(callToken);

                // Return the updated message
                return _BREPipelineMetaInstructionCollection.InMsg;
            }

            TraceManager.PipelineComponent.TraceEndScope(callToken, ticks);
            TraceManager.PipelineComponent.TraceInfo("{0} - BRE Pipeline Framework pipeline component was disabled so acting like a pass through pipeline component.",callToken);
            TraceManager.PipelineComponent.TraceOut(callToken);

            // Return the original message, treating this pipeline component as if it were a pass through pipeline component if the Enabled property is set to false
            return inmsg;
        }