private void Initiate(IActivityFactory activityFactory, IBaseMessage message, string processName)
        {
            var previousTrackingContext = message.GetTrackingContext();

            // an outbound message without an ongoing process --i.e. that has no process affiliation-- denotes a
            // publish/subscribe, or messaging-only process and the whole process needs to be tracked; that means the
            // initiating messaging step, whose MessagingStepActivityId is still conveyed by the ambient
            // previousTrackingContext, as well as the currently ongoing messaging step, which completes the process.
            var isMessagingProcess = message.Direction().IsOutbound() &&
                                     !previousTrackingContext.HasProcessAffiliation() &&
                                     !previousTrackingContext.MessagingStepActivityId.IsNullOrEmpty();

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug($"Initiating tracking of a messaging {(isMessagingProcess ? "process" : "step")}.");
            }

            _process = isMessagingProcess
                                ? activityFactory.CreateProcess(message, processName)
                                : previousTrackingContext.HasProcessAffiliation()
                                        ? activityFactory.FindProcess(previousTrackingContext)
                                        : null;

            _previousMessagingStep = isMessagingProcess
                                ? activityFactory.FindMessagingStep(previousTrackingContext)
                                : null;

            _messagingStep = activityFactory.CreateMessagingStep(message);
        }
        /// <summary>
        /// Returns the <see cref="TrackingContext"/> associated to the <paramref name="message"/>.
        /// </summary>
        /// <param name="message">
        /// Message whose associated <see cref="TrackingContext"/> will be returned.
        /// </param>
        /// <param name="throwOnEmpty">
        /// <c>true</c> to throw an <see cref="InvalidOperationException"/> if none of the discrete activity Ids of the <see
        /// cref="TrackingContext"/> are set in the <paramref name="message"/>'s context.
        /// </param>
        /// <returns>
        /// The <see cref="TrackingContext"/> associated to the <paramref name="message"/>.
        /// </returns>
        public static TrackingContext GetTrackingContext(this IBaseMessage message, bool throwOnEmpty)
        {
            var trackingContext = message.GetTrackingContext();

            if (throwOnEmpty && trackingContext.IsEmpty())
            {
                throw new InvalidOperationException("Invalid TrackingContext: None of its discrete activity Ids are set.");
            }
            return(trackingContext);
        }
Example #3
0
 protected void CacheTrackingContext(IBaseMessage message, int duration)
 {
     // if propagation of TrackingContext is not disabled, cache the current TrackingContext
     if (duration > -1)
     {
         _logger.DebugFormat("Caching current tracking context for {0} seconds", duration);
         TrackingContextCache.Instance.Set(
             message.GetProperty(BtsProperties.TransmitWorkId),
             message.GetTrackingContext(),
             duration + 1);
     }
 }