예제 #1
0
        protected override void Send(TrackingRecord record)
        {
            //Process.GetCurrentProcess().MachineName
            //System.Threading.Thread.CurrentThread.ManagedThreadId

            ActivityTrackingRecord activityTrackingRecord = record as ActivityTrackingRecord;

            if (activityTrackingRecord != null)
            {
                WorkflowEnvironment.WorkBatch.Add(this,
                                                  BuildSerializableActivityTrackRecord(activityTrackingRecord));
                return;
            }
            WorkflowTrackingRecord workflowTrackingRecord = record as WorkflowTrackingRecord;

            if (workflowTrackingRecord != null)
            {
                WorkflowEnvironment.WorkBatch.Add(this,
                                                  BuildSerializableWorkFlowTrackRecord(workflowTrackingRecord));
                return;
            }


            UserTrackingRecord userTrackingRecord = record as UserTrackingRecord;

            //TrackingRecord userTrackingRecord = record as UserTrackingRecord;
            if (record is UserTrackingRecord)
            {
                WorkflowEnvironment.WorkBatch.Add(this, record);

                //Debug.WriteLine(((UserTrackingRecord)record).UserData);
            }
        }
            /// <summary>
            /// Receives tracking events.  Instance terminated events are written to the event log.
            /// </summary>
            protected override void Send(TrackingRecord record)
            {
                WorkflowTrackingRecord instanceTrackingRecord = record as WorkflowTrackingRecord;

                if ((null == instanceTrackingRecord) || (TrackingWorkflowEvent.Terminated != instanceTrackingRecord.TrackingWorkflowEvent))
                {
                    return;
                }

                // Create an EventLog instance and assign its source.
                EventLog log = new EventLog();

                log.Source = sourceValue;

                // Write an informational entry to the event log.
                TrackingWorkflowTerminatedEventArgs terminatedEventArgs = instanceTrackingRecord.EventArgs as TrackingWorkflowTerminatedEventArgs;

                StringBuilder message = new StringBuilder(512);

                message.AppendLine(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Workflow instance {0} has been terminated.", parametersValue.InstanceId.ToString()));
                message.AppendLine();

                if (null != terminatedEventArgs.Exception)
                {
                    message.AppendLine(terminatedEventArgs.Exception.ToString());
                }

                log.WriteEntry(message.ToString(), EventLogEntryType.Warning);
            }
예제 #3
0
        internal void DynamicUpdateCommit(object sender, WorkflowExecutor.DynamicUpdateEventArgs e)
        {
            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }
            if (!typeof(WorkflowExecutor).IsInstanceOfType(sender))
            {
                throw new ArgumentException("sender");
            }
            WorkflowExecutor skedExec = (WorkflowExecutor)sender;
            DateTime         utcNow   = DateTime.UtcNow;

            foreach (TrackingChannelWrapper wrapper in this._channels)
            {
                wrapper.GetTrackingProfile(skedExec).WorkflowChangeCommit();
            }
            int nextEventOrderId = this._broker.GetNextEventOrderId();

            foreach (TrackingChannelWrapper wrapper2 in this._channels)
            {
                WorkflowTrackingRecord record = new WorkflowTrackingRecord(TrackingWorkflowEvent.Changed, utcNow, nextEventOrderId, new TrackingWorkflowChangedEventArgs(e.ChangeActions, skedExec.WorkflowDefinition));
                if (wrapper2.GetTrackingProfile(skedExec).TryTrackInstanceEvent(TrackingWorkflowEvent.Changed, record))
                {
                    wrapper2.TrackingChannel.Send(record);
                }
            }
        }
예제 #4
0
        ///<summary>
        ///When implemented in a derived class, sends a <see cref="T:System.Workflow.Runtime.Tracking.TrackingRecord"></see> on the <see cref="T:System.Workflow.Runtime.Tracking.TrackingChannel"></see>.
        ///</summary>
        ///
        ///<param name="record">The <see cref="T:System.Workflow.Runtime.Tracking.TrackingRecord"></see> to send.</param>
        protected override void Send(TrackingRecord record)
        {
            TraceHelper.Trace();

            try
            {
                // build a serialisable representation of the tracking record
                // and batch it up ready for persistence during commit
                ActivityTrackingRecord activityTrackingRecord = record as ActivityTrackingRecord;
                if (activityTrackingRecord != null)
                {
                    WorkflowEnvironment.WorkBatch.Add(this,
                                                      buildSerialisableActivityTrackingRecord(
                                                          activityTrackingRecord));

                    return;
                }

                UserTrackingRecord userTrackingRecord = record as UserTrackingRecord;
                if (userTrackingRecord != null)
                {
                    WorkflowEnvironment.WorkBatch.Add(this,
                                                      buildSerialisableUserTrackingRecord(
                                                          userTrackingRecord));

                    return;
                }

                WorkflowTrackingRecord workflowTrackingRecord = record as WorkflowTrackingRecord;
                if (workflowTrackingRecord != null)
                {
                    if (workflowTrackingRecord.TrackingWorkflowEvent == TrackingWorkflowEvent.Changed)
                    {
                        WorkflowEnvironment.WorkBatch.Add(this,
                                                          buildSerialisableWorkflowChangeTrackingRecord(
                                                              workflowTrackingRecord));
                    }
                    else
                    {
                        WorkflowEnvironment.WorkBatch.Add(this,
                                                          buildSerialisableWorkflowTrackingRecord(
                                                              workflowTrackingRecord));
                    }

                    return;
                }
            }
            catch (Exception e)
            {
                string errorMessage = RM.Get_Error_TrackingChannelException(e.ToString());

                TraceHelper.Trace(errorMessage);

                throw new TrackingException(errorMessage, e);
            }
        }
        internal bool TryTrackInstanceEvent(TrackingWorkflowEvent status, WorkflowTrackingRecord record)
        {
            bool track = false;

            foreach (WorkflowTrackPoint point in _profile.WorkflowTrackPoints)
            {
                if (point.IsMatch(status))
                {
                    record.Annotations.AddRange(point.Annotations);
                    track = true;
                }
            }
            return(track);
        }
예제 #6
0
        /// <summary>
        /// Write tracking data for a single instance to the Console
        /// </summary>
        /// <param name="instanceId"></param>
        /// <param name="records"></param>
        private void WriteSingleInstanceToConsole(
            Guid instanceId, SortedList <Int32, TrackingRecord> records)
        {
            Console.WriteLine("Tracking data for workflow instance {0}",
                              instanceId);

            foreach (TrackingRecord record in records.Values)
            {
                if (record is WorkflowTrackingRecord)
                {
                    WorkflowTrackingRecord wfRecord
                        = record as WorkflowTrackingRecord;
                    Console.WriteLine("{0:HH:mm:ss.fff} Workflow {1}",
                                      wfRecord.EventDateTime,
                                      wfRecord.TrackingWorkflowEvent);
                }
                else if (record is ActivityTrackingRecord)
                {
                    ActivityTrackingRecord actRecord
                        = record as ActivityTrackingRecord;
                    Console.WriteLine("{0:HH:mm:ss.fff} {1} {2}, Type={3}",
                                      actRecord.EventDateTime,
                                      actRecord.ExecutionStatus,
                                      actRecord.QualifiedName,
                                      actRecord.ActivityType.Name);
                    WriteBodyToConsole(actRecord);
                }
                else if (record is UserTrackingRecord)
                {
                    UserTrackingRecord userRecord
                        = record as UserTrackingRecord;
                    if (userRecord.UserData is RuleActionTrackingEvent)
                    {
                        WriteRuleData(userRecord);
                    }
                    else
                    {
                        Console.WriteLine(
                            "{0:HH:mm:ss.fff} UserData from {1} {2}:{3}",
                            userRecord.EventDateTime,
                            userRecord.QualifiedName,
                            userRecord.UserDataKey,
                            userRecord.UserData);
                    }
                }
            }

            Console.WriteLine("End of tracking data for {0}\n\r",
                              instanceId);
        }
예제 #7
0
        private static WorkFlowTrackRecord BuildSerializableWorkFlowTrackRecord(WorkflowTrackingRecord record)
        {
            WorkFlowTrackRecord wtr = new WorkFlowTrackRecord();

            //utc date conversion to local
            wtr.DateTime = ConvertToLocalTime(record.EventDateTime); //record.EventDateTime.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours);

            wtr.WfHost   = _wfHost;
            wtr.ThreadId = Thread.CurrentThread.ManagedThreadId;

            wtr.Order    = record.EventOrder;
            wtr.WfStatus = record.TrackingWorkflowEvent;

            return(wtr);
        }
예제 #8
0
 /// <summary>
 /// Invoked by the runtime to send tracking data
 /// to the service
 /// </summary>
 /// <param name="record"></param>
 protected override void Send(TrackingRecord record)
 {
     if (record is WorkflowTrackingRecord)
     {
         WorkflowTrackingRecord wfRecord
             = record as WorkflowTrackingRecord;
         Console.WriteLine("{0:HH:mm:ss.fff} Workflow {1}",
                           wfRecord.EventDateTime,
                           wfRecord.TrackingWorkflowEvent);
     }
     else if (record is ActivityTrackingRecord)
     {
         ActivityTrackingRecord actRecord
             = record as ActivityTrackingRecord;
         Console.WriteLine("{0:HH:mm:ss.fff} {1} {2}, Type={3}",
                           actRecord.EventDateTime,
                           actRecord.ExecutionStatus,
                           actRecord.QualifiedName,
                           actRecord.ActivityType.Name);
         WriteBodyToConsole(actRecord);
     }
     else if (record is UserTrackingRecord)
     {
         UserTrackingRecord userRecord
             = record as UserTrackingRecord;
         if (userRecord.UserData is RuleActionTrackingEvent)
         {
             RuleActionTrackingEvent ruleAction
                 = userRecord.UserData as RuleActionTrackingEvent;
             Console.WriteLine(
                 "{0:HH:mm:ss.fff} RuleAction from {1} Rule:{2} Result:{3}",
                 userRecord.EventDateTime,
                 userRecord.QualifiedName,
                 ruleAction.RuleName,
                 ruleAction.ConditionResult);
         }
         else
         {
             Console.WriteLine(
                 "{0:HH:mm:ss.fff} UserData from {1} {2}:{3}",
                 userRecord.EventDateTime,
                 userRecord.QualifiedName,
                 userRecord.UserDataKey,
                 userRecord.UserData);
         }
     }
 }
예제 #9
0
        private void NotifyChannels(TrackingWorkflowEvent evt, WorkflowExecutor.WorkflowExecutionEventArgs e, WorkflowExecutor exec)
        {
            DateTime utcNow           = DateTime.UtcNow;
            int      nextEventOrderId = this._broker.GetNextEventOrderId();

            foreach (TrackingChannelWrapper wrapper in this._channels)
            {
                WorkflowExecutor.WorkflowExecutionTerminatingEventArgs args2;
                WorkflowTrackingRecord record;
                EventArgs eventArgs = null;
                switch (evt)
                {
                case TrackingWorkflowEvent.Exception:
                {
                    WorkflowExecutor.WorkflowExecutionExceptionEventArgs args3 = (WorkflowExecutor.WorkflowExecutionExceptionEventArgs)e;
                    eventArgs = new TrackingWorkflowExceptionEventArgs(args3.Exception, args3.CurrentPath, args3.OriginalPath, args3.ContextGuid, args3.ParentContextGuid);
                    goto Label_00BC;
                }

                case TrackingWorkflowEvent.Terminated:
                    args2 = (WorkflowExecutor.WorkflowExecutionTerminatingEventArgs)e;
                    if (args2.Exception == null)
                    {
                        break;
                    }
                    eventArgs = new TrackingWorkflowTerminatedEventArgs(args2.Exception);
                    goto Label_00BC;

                case TrackingWorkflowEvent.Suspended:
                    eventArgs = new TrackingWorkflowSuspendedEventArgs(((WorkflowExecutor.WorkflowExecutionSuspendingEventArgs)e).Error);
                    goto Label_00BC;

                default:
                    goto Label_00BC;
                }
                eventArgs = new TrackingWorkflowTerminatedEventArgs(args2.Error);
Label_00BC:
                record = new WorkflowTrackingRecord(evt, utcNow, nextEventOrderId, eventArgs);
                if (wrapper.GetTrackingProfile(exec).TryTrackInstanceEvent(evt, record))
                {
                    wrapper.TrackingChannel.Send(record);
                }
            }
        }
 private void WriteWorkflowTrackingRecord(WorkflowTrackingRecord workflowTrackingRecord)
 {
     WriteTitle("Workflow Tracking Record");
     Console.WriteLine("EventDateTime: " + workflowTrackingRecord.EventDateTime.ToString());
     Console.WriteLine("Status: " + workflowTrackingRecord.TrackingWorkflowEvent.ToString());
 }
예제 #11
0
        /// <summary>
        /// Serialise a <see cref="WorkflowTrackingRecord" /> ready for persistence.
        /// </summary>
        /// <param name="workflowTrackingRecord">
        /// The original <see cref="WorkflowTrackingRecord" /> to serialise.
        /// </param>
        /// <returns>
        /// A <see cref="SerialisableWorkflowTrackingRecord" /> containing a serialised
        /// copy of the <see cref="WorkflowTrackingRecord" />.
        /// </returns>
        private static SerialisableWorkflowTrackingRecord buildSerialisableWorkflowTrackingRecord(WorkflowTrackingRecord workflowTrackingRecord)
        {
            SerialisableWorkflowTrackingRecord serialisableWorkflowTrackingRecord = new SerialisableWorkflowTrackingRecord();

            serialisableWorkflowTrackingRecord.Annotations.AddRange(workflowTrackingRecord.Annotations);
            serialisableWorkflowTrackingRecord.EventDateTime         = workflowTrackingRecord.EventDateTime;
            serialisableWorkflowTrackingRecord.EventOrder            = workflowTrackingRecord.EventOrder;
            serialisableWorkflowTrackingRecord.TrackingWorkflowEvent = workflowTrackingRecord.TrackingWorkflowEvent;

            if (workflowTrackingRecord.EventArgs != null)
            {
                serialisableWorkflowTrackingRecord.EventArgs = buildSerialisableData(workflowTrackingRecord.EventArgs);
                if (serialisableWorkflowTrackingRecord.EventArgs.NonSerialisable)
                {
                    // if this is a termination or other exception event then
                    // we need to get the exception details to trace what happened...
                    Exception workflowException = null;
                    switch (workflowTrackingRecord.TrackingWorkflowEvent)
                    {
                    case TrackingWorkflowEvent.Terminated:
                        workflowException = ((TrackingWorkflowTerminatedEventArgs)
                                             workflowTrackingRecord.EventArgs).Exception;

                        break;

                    case TrackingWorkflowEvent.Exception:
                        workflowException = ((TrackingWorkflowExceptionEventArgs)
                                             workflowTrackingRecord.EventArgs).Exception;

                        break;
                    }

                    if (workflowException != null)
                    {
                        serialisableWorkflowTrackingRecord.EventArgs =
                            buildSerialisableData(workflowException.ToString());
                    }
                }
            }

            return(serialisableWorkflowTrackingRecord);
        }
예제 #12
0
        /// <summary>
        /// Serialise a <see cref="WorkflowTrackingRecord" /> ready for persistence. This
        /// method deals with WorkflowTrackingRecords that contain workflow change
        /// details.
        /// </summary>
        /// <param name="workflowTrackingRecord">
        /// The original <see cref="WorkflowTrackingRecord" /> to serialise.
        /// </param>
        /// <returns>
        /// Modified copy of the <see cref="WorkflowTrackingRecord" /> containing
        /// serialised data.
        /// </returns>
        private static SerialisableWorkflowChangeRecord buildSerialisableWorkflowChangeTrackingRecord(WorkflowTrackingRecord workflowTrackingRecord)
        {
            SerialisableWorkflowChangeRecord serialisableWorkflowChangeRecord = new SerialisableWorkflowChangeRecord();

            serialisableWorkflowChangeRecord.Annotations.AddRange(workflowTrackingRecord.Annotations);
            serialisableWorkflowChangeRecord.EventDateTime         = workflowTrackingRecord.EventDateTime;
            serialisableWorkflowChangeRecord.EventOrder            = workflowTrackingRecord.EventOrder;
            serialisableWorkflowChangeRecord.TrackingWorkflowEvent = workflowTrackingRecord.TrackingWorkflowEvent;

            if (workflowTrackingRecord.EventArgs != null && workflowTrackingRecord.EventArgs is TrackingWorkflowChangedEventArgs)
            {
                TrackingWorkflowChangedEventArgs eventArgs = (TrackingWorkflowChangedEventArgs)workflowTrackingRecord.EventArgs;

                serialisableWorkflowChangeRecord.EventArgs =
                    buildSerialisableTrackingWorkflowChangedEventArgs(eventArgs);
            }

            return(serialisableWorkflowChangeRecord);
        }
예제 #13
0
 private void WriteWorkflowTrackingRecord(WorkflowTrackingRecord workflowTrackingRecord)
 {
     WriteToFile("Workflow: " + workflowTrackingRecord.TrackingWorkflowEvent.ToString());
 }