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); } }
public static byte[] GetWorkflowGraphic(Guid processId) { SqlTrackingWorkflowInstance sqlTrackingWorkflowInstance = null; SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(ConfigurationManager.ConnectionStrings[Constants.Database.TenantWorkflowStore].ConnectionString); if (sqlTrackingQuery.TryGetWorkflow(processId, out sqlTrackingWorkflowInstance)) { if ((null != sqlTrackingWorkflowInstance) && (null != sqlTrackingWorkflowInstance.WorkflowDefinition)) { Dictionary <string, ActivityStatusInfo> activityStatusListValue = new Dictionary <string, ActivityStatusInfo>(); for (int index = sqlTrackingWorkflowInstance.ActivityEvents.Count; index >= 1; index--) { ActivityTrackingRecord activityTrackingRecord = sqlTrackingWorkflowInstance.ActivityEvents[index - 1]; if (!activityStatusListValue.ContainsKey(activityTrackingRecord.QualifiedName)) { ActivityStatusInfo latestActivityStatus = new ActivityStatusInfo(activityTrackingRecord.QualifiedName, activityTrackingRecord.ExecutionStatus.ToString()); activityStatusListValue.Add(activityTrackingRecord.QualifiedName, latestActivityStatus); } } Activity workflowDefinition = sqlTrackingWorkflowInstance.WorkflowDefinition; return(Viewer.GetWorkflowImageBinary(workflowDefinition, activityStatusListValue)); } } return(null); }
private static ActivityTrackRecord BuildSerializableActivityTrackRecord(ActivityTrackingRecord record) { ActivityTrackRecord wtr = new ActivityTrackRecord(); //utc date conversion to local wtr.DateTime = ConvertToLocalTime(record.EventDateTime);//.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).Hours); wtr.WfHost = _wfHost; wtr.ThreadId = Thread.CurrentThread.ManagedThreadId; wtr.Order = record.EventOrder; wtr.WfStatus = record.ExecutionStatus; wtr.Name = record.QualifiedName; wtr.Type = record.ActivityType.Name; if (record.Body.Count > 0) { var dataItem = GetTrackingDataItemByFieldName(record.Body, "Task"); if (dataItem != null) { wtr.BaseActivityTask = dataItem.Data; } dataItem = GetTrackingDataItemByFieldName(record.Body, "RequestedTaskStatusInfo"); if (dataItem != null) { wtr.UpdateTaskStatusRequestedTaskStatusInfo = dataItem.Data; } } return(wtr); }
private static void WriteActivityTrackingRecord(ActivityTrackingRecord activityTrackingRecord) { WriteTitle("Activity Tracking Record"); Console.WriteLine("EventDateTime: " + activityTrackingRecord.EventDateTime.ToString()); Console.WriteLine("QualifiedName: " + activityTrackingRecord.QualifiedName.ToString()); Console.WriteLine("Type: " + activityTrackingRecord.ActivityType); Console.WriteLine("Status: " + activityTrackingRecord.ExecutionStatus.ToString()); }
private void WriteActivityTrackingRecord(ActivityTrackingRecord activityTrackingRecord) { WriteTitle("Activity Tracking Record"); Console.WriteLine(string.Format("{0}: {1} on {2}: ", activityTrackingRecord.ActivityType, activityTrackingRecord.QualifiedName, activityTrackingRecord.EventDateTime.ToString())); Console.WriteLine("Status: " + activityTrackingRecord.ExecutionStatus.ToString()); }
///<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); } }
/// <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); }
/// <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); } } }
static public ExportProcessDC GetExportProcessbyContractId(Guid contractId) { SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(ConfigurationManager.ConnectionStrings[Constants.Database.TenantWorkflowStore].ConnectionString); SqlTrackingQueryOptions options = new SqlTrackingQueryOptions(); //options.WorkflowStatus = WorkflowStatus.Running; options.TrackingDataItems.Add(new TrackingDataItemValue("ExportProcess", "ObjectId", contractId.ToString())); IList <SqlTrackingWorkflowInstance> workflows = sqlTrackingQuery.GetWorkflows(options); if (workflows.Count == 0) { return(null); } SqlTrackingWorkflowInstance workflow = workflows[workflows.Count - 1]; ExportProcessDC exportProcessDC = new ExportProcessDC(); exportProcessDC.ObjectId = contractId; exportProcessDC.ProcessId = workflow.WorkflowInstanceId; exportProcessDC.Status = ProcessHelper.ToProcessStatus(workflow.Status); int activityEventsCount = workflow.ActivityEvents.Count; if (activityEventsCount > 0) { ActivityTrackingRecord record = (ActivityTrackingRecord)workflow.ActivityEvents[activityEventsCount - 1]; foreach (TrackingDataItem dataItem in record.Body) { switch (dataItem.FieldName) { case "Number": exportProcessDC.Number = (string)dataItem.Data; break; case "Creator": exportProcessDC.Creator = (string)dataItem.Data; break; case "Amount": exportProcessDC.Amount = dataItem.Data == null ? default(decimal) : (decimal)dataItem.Data; break; } } } return(exportProcessDC); }
//Query the database via the databaseService and update the activities ListView and activityStatusList // based on the currently selected workflow instance private void UpdateActivities() { if (listViewWorkflows.SelectedItems.Count == 0) { listViewActivities.Items.Clear(); activityStatusListValue.Clear(); return; } ListViewItem currentWorkflow = listViewWorkflows.SelectedItems[0]; if (currentWorkflow != null) { Guid workflowInstanceId = workflowStatusList[(currentWorkflow.SubItems[0]).Text].InstanceId; SqlTrackingWorkflowInstance sqlTrackingWorkflowInstance = null; if (true == monitorDatabaseServiceValue.TryGetWorkflow(workflowInstanceId, out sqlTrackingWorkflowInstance)) { listViewActivities.Items.Clear(); activityStatusListValue.Clear(); //ActivityEvents list received contain all events for activities in orders in event order //Walking down-up on the ActivityEvents list and keeping the last entry for (int index = sqlTrackingWorkflowInstance.ActivityEvents.Count; index >= 1; index--) { ActivityTrackingRecord activityTrackingRecord = sqlTrackingWorkflowInstance.ActivityEvents[index - 1]; if (!activityStatusListValue.ContainsKey(activityTrackingRecord.QualifiedName)) { ActivityStatusInfo latestActivityStatus = new ActivityStatusInfo(activityTrackingRecord.QualifiedName, activityTrackingRecord.ExecutionStatus.ToString()); activityStatusListValue.Add(activityTrackingRecord.QualifiedName, latestActivityStatus); string[] activitiesListViewItems = new string[] { activityTrackingRecord.EventOrder.ToString(), activityTrackingRecord.QualifiedName, activityTrackingRecord.ExecutionStatus.ToString() }; ListViewItem li = new ListViewItem(activitiesListViewItems, -1); listViewActivities.Items.Add(li); } } workflowViewHost.Refresh(); } } }
static public ExportProcessDC[] GetExportProcessListByStatus(Guid tenantId, ProcessStatus status) { List <ExportProcessDC> processList = new List <ExportProcessDC>(); SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(ConfigurationManager.ConnectionStrings[Constants.Database.TenantWorkflowStore].ConnectionString); SqlTrackingQueryOptions options = new SqlTrackingQueryOptions(); options.WorkflowStatus = ProcessHelper.ToWorkflowStatus(status); options.TrackingDataItems.Add(new TrackingDataItemValue("ExportProcess", "TenantId", tenantId.ToString())); IList <SqlTrackingWorkflowInstance> workflows = sqlTrackingQuery.GetWorkflows(options); foreach (SqlTrackingWorkflowInstance workflow in workflows) { ExportProcessDC exportProcessDC = new ExportProcessDC(); exportProcessDC.ProcessId = workflow.WorkflowInstanceId; exportProcessDC.Status = ProcessHelper.ToProcessStatus(workflow.Status); int activityEventsCount = workflow.ActivityEvents.Count; if (activityEventsCount > 0) { ActivityTrackingRecord record = (ActivityTrackingRecord)workflow.ActivityEvents[activityEventsCount - 1]; foreach (TrackingDataItem dataItem in record.Body) { switch (dataItem.FieldName) { case "ObjectId": exportProcessDC.ObjectId = (Guid)dataItem.Data; break; case "Number": exportProcessDC.Number = (string)dataItem.Data; break; case "Creator": exportProcessDC.Creator = (string)dataItem.Data; break; case "Amount": exportProcessDC.Amount = dataItem.Data == null ? default(decimal) : (decimal)dataItem.Data; break; } } } processList.Add(exportProcessDC); } return(processList.ToArray()); }
public override void Track(TrackingRecord record, TimeSpan timeout) { Type recordType = record.GetType(); Writer.WriteLine("[" + record.RecordNumber + "] ({" + record.EventTime + "}) Instance: " + record.InstanceId); if (record.Annotations.Count > 0) { Writer.WriteLine("Annotations:"); foreach (string key in record.Annotations.Keys) { Writer.WriteLine("\t" + key + "\t" + record.Annotations[key]); } } if (recordType == typeof(WorkflowInstanceUnhandledExceptionRecord)) { WorkflowInstanceUnhandledExceptionRecord crecord = (WorkflowInstanceUnhandledExceptionRecord)record; RecordWriteLine(crecord, "-----------Exception"); RecordWriteLine(crecord, crecord.UnhandledException.ToString()); RecordWriteLine(crecord, "-----------End Exception"); } else if (recordType == typeof(WorkflowInstanceRecord)) { WorkflowInstanceRecord crecord = (WorkflowInstanceRecord)record; RecordWriteLine(crecord, "Workflow State: " + crecord.State); } else if (recordType == typeof(ActivityTrackingRecord)) { ActivityTrackingRecord crecord = (ActivityTrackingRecord)record; RecordWriteLine(crecord, "Activity, " + crecord.Name + ", entered state: " + crecord.State); if (crecord.Variables.Count > 0) { Writer.WriteLine("Variables:"); foreach (string key in crecord.Variables.Keys) { Writer.WriteLine("\t" + key + "\t" + crecord.Variables[key].ToString()); } } } }
internal void ActivityStatusChange(object sender, WorkflowExecutor.ActivityStatusChangeEventArgs e) { WorkflowTrace.Tracking.TraceInformation("TrackingListener::ActivityStatusChange - Received Activity Status Change Event for activity {0}", new object[] { e.Activity.QualifiedName }); if (sender == null) { throw new ArgumentNullException("sender"); } if (!typeof(WorkflowExecutor).IsInstanceOfType(sender)) { throw new ArgumentException("sender"); } if (e == null) { throw new ArgumentNullException("e"); } WorkflowExecutor exec = (WorkflowExecutor)sender; if ((this._channels == null) || (this._channels.Count <= 0)) { WorkflowTrace.Tracking.TraceEvent(TraceEventType.Error, 0, ExecutionStringManager.NoChannels); } else { Activity activity = e.Activity; if (this.SubscriptionRequired(activity, exec)) { Guid empty = Guid.Empty; Guid contextGuid = Guid.Empty; this.GetContext(activity, exec, out contextGuid, out empty); DateTime utcNow = DateTime.UtcNow; int nextEventOrderId = this._broker.GetNextEventOrderId(); foreach (TrackingChannelWrapper wrapper in this._channels) { ActivityTrackingRecord record = new ActivityTrackingRecord(activity.GetType(), activity.QualifiedName, contextGuid, empty, activity.ExecutionStatus, utcNow, nextEventOrderId, null); if (wrapper.GetTrackingProfile(exec).TryTrackActivityEvent(activity, activity.ExecutionStatus, exec, record)) { wrapper.TrackingChannel.Send(record); } } } } }
/// <summary> /// Write any annotations and body data to the Console /// </summary> /// <param name="record"></param> private void WriteBodyToConsole(ActivityTrackingRecord record) { //write annotations if (record.Annotations.Count > 0) { foreach (String annotation in record.Annotations) { Console.WriteLine(" {0}", annotation); } } //write extracted data if (record.Body.Count > 0) { foreach (TrackingDataItem data in record.Body) { Console.WriteLine(" {0}={1}", data.FieldName, data.Data); } } }
internal bool TryTrackActivityEvent(Activity activity, ActivityExecutionStatus status, IServiceProvider provider, ActivityTrackingRecord record) { List <ActivityTrackPointCacheItem> list; if (!this.TryGetCacheItems(activity, out list)) { return(false); } bool flag = false; foreach (ActivityTrackPointCacheItem item in list) { if ((!item.HasLocationConditions || item.Point.IsMatch(activity, status)) && item.Events.Contains(status)) { flag = true; item.Point.Track(activity, provider, record.Body); record.Annotations.AddRange(item.Point.Annotations); } } return(flag); }
/// <summary> /// Serialise a <see cref="ActivityTrackingRecord" /> ready for persistence. /// </summary> /// <param name="activityTrackingRecord"> /// The original <see cref="ActivityTrackingRecord" /> to serialise. /// </param> /// <returns> /// Modified copy of the <see cref="ActivityTrackingRecord" /> containing /// the serialised data. /// </returns> private static SerialisableActivityTrackingRecord buildSerialisableActivityTrackingRecord(ActivityTrackingRecord activityTrackingRecord) { SerialisableActivityTrackingRecord serialisableActivityTrackingRecord = new SerialisableActivityTrackingRecord(); serialisableActivityTrackingRecord.ActivityType = activityTrackingRecord.ActivityType; serialisableActivityTrackingRecord.Annotations.AddRange(activityTrackingRecord.Annotations); serialisableActivityTrackingRecord.ContextGuid = activityTrackingRecord.ContextGuid; serialisableActivityTrackingRecord.EventDateTime = activityTrackingRecord.EventDateTime; serialisableActivityTrackingRecord.EventOrder = activityTrackingRecord.EventOrder; serialisableActivityTrackingRecord.ExecutionStatus = activityTrackingRecord.ExecutionStatus; serialisableActivityTrackingRecord.ParentContextGuid = activityTrackingRecord.ParentContextGuid; serialisableActivityTrackingRecord.QualifiedName = activityTrackingRecord.QualifiedName; if (activityTrackingRecord.Body != null) { for (int i = 0; i < activityTrackingRecord.Body.Count; i++) { serialisableActivityTrackingRecord.Body.Add(buildSerialisableTrackingDataItem(activityTrackingRecord.Body[i])); } } if (activityTrackingRecord.EventArgs != null) { serialisableActivityTrackingRecord.EventArgs = buildSerialisableData(activityTrackingRecord.EventArgs); } return(serialisableActivityTrackingRecord); }
internal bool TryTrackActivityEvent(Activity activity, ActivityExecutionStatus status, IServiceProvider provider, ActivityTrackingRecord record) { List <ActivityTrackPointCacheItem> points; // // Check the match caches. if (TryGetCacheItems(activity, out points)) { bool ret = false; foreach (ActivityTrackPointCacheItem item in points) { if (item.HasLocationConditions) { if (!item.Point.IsMatch(activity, status)) { continue; } } if (item.Events.Contains(status)) { ret = true; item.Point.Track(activity, provider, record.Body); record.Annotations.AddRange(item.Point.Annotations); } } return(ret); } return(false); }
private void WriteActivityTrackingRecord(ActivityTrackingRecord activityTrackingRecord) { WriteToFile("Activity: " + activityTrackingRecord.QualifiedName.ToString() + " " + activityTrackingRecord.ExecutionStatus.ToString()); }