/// <summary>
        /// Method intended to be called at the start of an orchestration to create a BAM process tracking activity.
        /// </summary>
        /// <param name="activatingMessage">
        /// The message that activates the orchestration instance.
        /// </param>
        /// <param name="processName">The name that will be used to qualify the new tracked process instance.</param>
        /// <returns>
        /// The <see cref="TrackingContext"/> that contains the BAM tracking activities identifiers for the current process.
        /// Notice that <see cref="TrackingContext.MessagingStepActivityId"/> will be filled with the tracking activity
        /// identifier of <paramref name="activatingMessage"/> if it exists.
        /// </returns>
        public static TrackingContext Initiate(XLANGMessage activatingMessage, string processName)
        {
            if (activatingMessage == null)
            {
                throw new ArgumentNullException(nameof(activatingMessage));
            }
            if (processName.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(processName));
            }

            var process = Initiate(
                Service.RootService.InstanceId,
                processName,
                activatingMessage.GetProperty(TrackingProperties.Value1),
                activatingMessage.GetProperty(TrackingProperties.Value2),
                activatingMessage.GetProperty(TrackingProperties.Value3));

            // link inbound activating messaging step to its process
            // only an orchestration can link an activating messaging step to its process
            // as ProcessActivityId is initialized *by* the orchestration's first step
            var messagingStep = new MessagingStep(activatingMessage);

            process.AddStep(messagingStep);

            // set up orchestration's tracking context
            return(new TrackingContext {
                ProcessActivityId = process.ActivityId,
                MessagingStepActivityId = messagingStep.ActivityId
            });
        }
        internal void AddStep(MessagingStep messagingStep)
        {
            var tracking = new ProcessMessagingStep(Tracking.ActivityId.NewActivityId());

            tracking.BeginProcessMessagingStepActivity();
            tracking.MessagingStepActivityID = messagingStep.ActivityId;
            // don't bother to duplicate status other than failure
            tracking.MessagingStepStatus = messagingStep.Message.GetProperty(ErrorReportProperties.ErrorType);
            tracking.ProcessActivityID   = ActivityId;
            tracking.CommitProcessMessagingStepActivity();
            tracking.EndProcessMessagingStepActivity();
        }
        public static void TrackDirectReceive(TrackingContext trackingContext, XLANGMessage message, bool trackMessageBody, bool skipMessageContextTracking)
        {
            var messagingStepTracking = new MessagingStep(Tracking.ActivityId.NewActivityId(), message);

            messagingStepTracking.BeginMessagingStepActivity();
            if (trackMessageBody)
            {
                messagingStepTracking.TrackMessageBody();
            }
            if (!skipMessageContextTracking)
            {
                messagingStepTracking.TrackMessageContext();
            }
            messagingStepTracking.TrackStep(TrackingStatus.Received);
            messagingStepTracking.CommitMessagingStepActivity();
            messagingStepTracking.EndMessagingStepActivity();

            new Process(trackingContext.ProcessActivityId).AddStep(messagingStepTracking);
        }