コード例 #1
0
 protected Process(IPipelineContext pipelineContext, IBaseMessage message)
     : this(Tracking.ActivityId.NewActivityId(), pipelineContext.GetEventStream())
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     _message = message;
 }
コード例 #2
0
 // internal because cannot prevent NullReferenceException should pipelineContext be null when calling .GetEventStream()
 internal MessagingStep(IPipelineContext pipelineContext, IBaseMessage message)
     : this(Tracking.ActivityId.NewActivityId(), pipelineContext.GetEventStream())
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     _message = message;
     BeginMessagingStepActivity();
     _message.SetProperty(TrackingProperties.MessagingStepActivityId, _activityId);
 }
コード例 #3
0
 // internal because cannot prevent NullReferenceException should pipelineContext be null when calling .GetEventStream()
 internal Process(IPipelineContext pipelineContext, IBaseMessage message, string name)
     : this(Tracking.ActivityId.NewActivityId(), pipelineContext.GetEventStream())
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     if (name.IsNullOrEmpty())
     {
         throw new ArgumentException("Process name is null or empty.", "name");
     }
     _message = message;
     BeginProcessActivity();
     message.SetProperty(TrackingProperties.ProcessActivityId, _activityId);
     ProcessName = name;
 }
コード例 #4
0
        /// <summary>
        /// Returns an instance of the <see cref="IActivityTrackingEventStream"/> object instantiated for a given messaging event stream taken from the specified pipeline context.
        /// </summary>
        /// <param name="pContext">A reference to <see cref="Microsoft.BizTalk.Component.Interop.IPipelineContext"/> object that contains a references to the messaging event stream.</param>
        /// <returns>The <see cref="IActivityTrackingEventStream"/> object instance.</returns>
        public static IActivityTrackingEventStream CreateEventStream(IPipelineContext pContext)
        {
            Guard.ArgumentNotNull(pContext, "pContext");

            return(new ActivityTrackingEventStream(pContext.GetEventStream()));
        }
コード例 #5
0
        /// <summary>
        /// Performs the BAM activity tracking using the current message context and instance.
        /// </summary>
        /// <param name="pipelineContext">Pipeline context</param>
        /// <param name="inputMessage">Input message</param>
        /// <returns>Original input message</returns>
        protected override IBaseMessage Execute(IPipelineContext pipelineContext, IBaseMessage inputMessage)
        {
            // Note: this component, as a general rule, first attemps to read a property from the context and if
            // it cannot be found there, it uses the design property value
            string activityName = inputMessage.Context.Read <string>(BAMTrackerProperties.ActivityName.Name, BAMTrackerProperties.ActivityName.Namespace, this.ActivityName);
            List <BAMEventSource> eventSources = inputMessage.Context.Read <List <BAMEventSource> >(BAMTrackerProperties.EnableContinuation.Name, BAMTrackerProperties.EnableContinuation.Namespace, this.EventSources);

            if (eventSources != null && eventSources.Count > 0)
            {
                TraceProvider.Logger.TraceInfo("Retrieving Messaging Event Stream from pipeline context...");
                // get a messaging BAM event stream instance that participates in the pipeline transaction context
                EventStream eventStream = pipelineContext.GetEventStream();
                if (eventStream != null)
                {
                    // set default BAM activity ID
                    string activityID = Guid.NewGuid().ToString();

                    // read message InterchangeID to use it as the continuation token
                    TraceProvider.Logger.TraceInfo("Attempting to read InterchangeID from context...");
                    // attempt to read the activity ID from the context
                    string interchangeID = inputMessage.Context.Read <string>(BtsProperties.InterchangeID.Name, BtsProperties.InterchangeID.Namespace, null);
                    if (String.IsNullOrEmpty(interchangeID) == true)
                    {
                        throw new InvalidOperationException("InterchangeID not found in context.");
                    }

                    // if using continuation, open activity with the continuation ID
                    bool useContinuation = inputMessage.Context.Read <bool>(BAMTrackerProperties.UseContinuation.Name, BAMTrackerProperties.UseContinuation.Namespace, this.UseContinuation);
                    if (useContinuation == true)
                    {
                        activityID = CONTINUATION_PREFIX + interchangeID;
                    }

                    // open activity
                    TraceProvider.Logger.TraceInfo("Opening activity {0} with ID: {1}...", activityName, activityID);
                    eventStream.BeginActivity(activityName, activityID);

                    // check if we need to enable continuation
                    bool enableContinuation = inputMessage.Context.Read <bool>(BAMTrackerProperties.EnableContinuation.Name, BAMTrackerProperties.EnableContinuation.Namespace, this.EnableContinuation);
                    if (this.EnableContinuation == true)
                    {
                        string continuationToken = CONTINUATION_PREFIX + interchangeID;
                        TraceProvider.Logger.TraceInfo("Enabling continuation on activity {0} with ID: {1} using continuation token: {2}...", activityName, activityID, continuationToken);
                        eventStream.EnableContinuation(activityName, activityID, continuationToken);
                    }

                    TraceProvider.Logger.TraceInfo("Writing event data to activity {0} with ID: {1}...", activityName, activityID);
                    // write BAM data
                    List <object> eventData = new List <object>();
                    foreach (BAMEventSource eventSource in eventSources)
                    {
                        // add activity item key (this the BAM activity item name in the BAM definition)
                        eventData.Add(eventSource.ActivityItem);
                        // read from the context the corresponding value
                        object itemValue = inputMessage.Context.Read(eventSource.ContextPropertyName, eventSource.ContextPropertyNamespace);
                        eventData.Add(itemValue);
                    }

                    // update activity
                    eventStream.UpdateActivity(activityName, activityID, eventData.ToArray());
                    // end updates to activity
                    eventStream.EndActivity(activityName, activityID);
                    TraceProvider.Logger.TraceInfo("Finished writing to activity {0} with ID: {1}...", activityName, activityID);
                }
            }

            return(inputMessage);
        }