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; }
/// <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; }
/// <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; }
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); } } }
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); } } }
private void LoadWorkflowEventsFromReader(SqlDataReader reader, object parameter) { if (null == reader) { throw new ArgumentNullException("reader"); } // // There should always be 2 recordsets in this reader! // DateTime tmpMin = SqlDateTime.MinValue.Value; Dictionary <long, WorkflowTrackingRecord> inst = new Dictionary <long, WorkflowTrackingRecord>(); while (reader.Read()) { TrackingWorkflowEvent evt = (TrackingWorkflowEvent)reader[0]; DateTime dt = reader.GetDateTime(1); int order = reader.GetInt32(2); object tmp = null; EventArgs args = null; if (!reader.IsDBNull(3)) { BinaryFormatter formatter = new BinaryFormatter(); tmp = formatter.Deserialize(new MemoryStream((Byte[])reader[3])); if (tmp is EventArgs) { args = (EventArgs)tmp; } } long eventId = reader.GetInt64(4); DateTime dbDt = reader.GetDateTime(5); inst.Add(eventId, new WorkflowTrackingRecord(evt, dt, order, args)); if (dbDt > tmpMin) { tmpMin = dbDt; } } if (!reader.NextResult()) { throw new ArgumentException(ExecutionStringManager.InvalidWorkflowInstanceEventReader); } // // Add any annotations while (reader.Read()) { long eventId = reader.GetInt64(0); string annotation = null; if (!reader.IsDBNull(1)) { annotation = reader.GetString(1); } WorkflowTrackingRecord rec = null; if (inst.TryGetValue(eventId, out rec)) { if (null != rec) { rec.Annotations.Add(annotation); } } } if (!reader.IsClosed) { reader.Close(); } // // Check if we have any WorkflowChange events in this list // If so pull back the change actions and reconstruct the args property foreach (KeyValuePair <long, WorkflowTrackingRecord> kvp in inst) { WorkflowTrackingRecord rec = kvp.Value; if (TrackingWorkflowEvent.Changed != rec.TrackingWorkflowEvent) { continue; } SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "[dbo].[GetWorkflowChangeEventArgs]"; cmd.Parameters.Add(new SqlParameter("@WorkflowInstanceInternalId", _internalId)); cmd.Parameters.Add(new SqlParameter("@BeginDateTime", SqlDateTime.MinValue.Value)); cmd.Parameters.Add(new SqlParameter("@WorkflowInstanceEventId", kvp.Key)); ExecuteRetried(cmd, LoadWorkflowChangeEventArgsFromReader, rec); } _workflowEvents.AddRange(inst.Values); // // set the min for the next query to the most recent event from this query // Don't overwrite the previous min if nothing came back for this query if (tmpMin > SqlDateTime.MinValue.Value) { _instMinDT = tmpMin; } }
private void LoadWorkflowChangeEventArgsFromReader(SqlDataReader reader, object parameter) { if (null == reader) { throw new ArgumentNullException("reader"); } if (null == parameter) { throw new ArgumentNullException("parameter"); } WorkflowTrackingRecord record = parameter as WorkflowTrackingRecord; if (null == record) { throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsParameter, "parameter"); } if (!reader.Read()) { throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsReader); } StringReader sr = new StringReader(reader.GetString(0)); //Deserialize the xoml and set the root activity Activity def = null; WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); DesignerSerializationManager serializationManager = new DesignerSerializationManager(); IList errors = null; try { using (serializationManager.CreateSession()) { using (XmlReader xmlReader = XmlReader.Create(sr)) { def = serializer.Deserialize(serializationManager, xmlReader) as Activity; errors = serializationManager.Errors; } } } finally { sr.Close(); } if ((null == def) || ((null != errors) && (errors.Count > 0))) { throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError); } if (!reader.NextResult()) { throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsReader); } // // There is a result set that we don't care about for this scenario, skip it if (!reader.NextResult()) { throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsReader); } List <WorkflowChangeAction> actions = new List <WorkflowChangeAction>(); DateTime currDT = DateTime.MinValue; int currEventOrder = -1; int currOrder = -1; while (reader.Read()) { DateTime dt = reader.GetDateTime(1); int eventOrder = reader.GetInt32(2); int order = reader.GetInt32(3); // // Build temp lists as we read the results but // only save the last set of change actions if (dt > currDT && eventOrder > currEventOrder) { currEventOrder = eventOrder; currOrder = order; currDT = dt; actions = new List <WorkflowChangeAction>(); } using (sr = new StringReader(reader.GetString(0))) { using (serializationManager.CreateSession()) { using (XmlReader xmlReader = XmlReader.Create(sr)) { ActivityChangeAction aAction = serializer.Deserialize(serializationManager, xmlReader) as ActivityChangeAction; errors = serializationManager.Errors; if (null == aAction) { throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError); } actions.Add(aAction); aAction.ApplyTo(def); } } } } record.EventArgs = new TrackingWorkflowChangedEventArgs(actions, def); }
private void LoadWorkflowEventsFromReader(SqlDataReader reader, object parameter) { if (reader == null) { throw new ArgumentNullException("reader"); } DateTime time = SqlDateTime.MinValue.Value; Dictionary <long, WorkflowTrackingRecord> dictionary = new Dictionary <long, WorkflowTrackingRecord>(); while (reader.Read()) { TrackingWorkflowEvent trackingWorkflowEvent = (TrackingWorkflowEvent)reader[0]; DateTime dateTime = reader.GetDateTime(1); int eventOrder = reader.GetInt32(2); object obj2 = null; EventArgs eventArgs = null; if (!reader.IsDBNull(3)) { obj2 = new BinaryFormatter().Deserialize(new MemoryStream((byte[])reader[3])); if (obj2 is EventArgs) { eventArgs = (EventArgs)obj2; } } long key = reader.GetInt64(4); DateTime time3 = reader.GetDateTime(5); dictionary.Add(key, new WorkflowTrackingRecord(trackingWorkflowEvent, dateTime, eventOrder, eventArgs)); if (time3 > time) { time = time3; } } if (!reader.NextResult()) { throw new ArgumentException(ExecutionStringManager.InvalidWorkflowInstanceEventReader); } while (reader.Read()) { long num3 = reader.GetInt64(0); string item = null; if (!reader.IsDBNull(1)) { item = reader.GetString(1); } WorkflowTrackingRecord record = null; if (dictionary.TryGetValue(num3, out record) && (record != null)) { record.Annotations.Add(item); } } if (!reader.IsClosed) { reader.Close(); } foreach (KeyValuePair <long, WorkflowTrackingRecord> pair in dictionary) { WorkflowTrackingRecord loadFromReaderParam = pair.Value; if (TrackingWorkflowEvent.Changed == loadFromReaderParam.TrackingWorkflowEvent) { SqlCommand cmd = new SqlCommand { CommandType = CommandType.StoredProcedure, CommandText = "[dbo].[GetWorkflowChangeEventArgs]" }; cmd.Parameters.Add(new SqlParameter("@WorkflowInstanceInternalId", this._internalId)); cmd.Parameters.Add(new SqlParameter("@BeginDateTime", SqlDateTime.MinValue.Value)); cmd.Parameters.Add(new SqlParameter("@WorkflowInstanceEventId", pair.Key)); this.ExecuteRetried(cmd, new LoadFromReader(this.LoadWorkflowChangeEventArgsFromReader), loadFromReaderParam); } } this._workflowEvents.AddRange(dictionary.Values); if (time > SqlDateTime.MinValue.Value) { this._instMinDT = time; } }
private void LoadWorkflowChangeEventArgsFromReader(SqlDataReader reader, object parameter) { if (reader == null) { throw new ArgumentNullException("reader"); } if (parameter == null) { throw new ArgumentNullException("parameter"); } WorkflowTrackingRecord record = parameter as WorkflowTrackingRecord; if (record == null) { throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsParameter, "parameter"); } if (!reader.Read()) { throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsReader); } StringReader input = new StringReader(reader.GetString(0)); Activity rootActivity = null; WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); DesignerSerializationManager serializationManager = new DesignerSerializationManager(); IList errors = null; try { using (serializationManager.CreateSession()) { using (XmlReader reader3 = XmlReader.Create(input)) { rootActivity = serializer.Deserialize(serializationManager, reader3) as Activity; errors = serializationManager.Errors; } } } finally { input.Close(); } if ((rootActivity == null) || ((errors != null) && (errors.Count > 0))) { throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError); } if (!reader.NextResult()) { throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsReader); } if (!reader.NextResult()) { throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsReader); } List <WorkflowChangeAction> changes = new List <WorkflowChangeAction>(); DateTime minValue = DateTime.MinValue; int num = -1; while (reader.Read()) { DateTime dateTime = reader.GetDateTime(1); int num2 = reader.GetInt32(2); int num3 = reader.GetInt32(3); if ((dateTime > minValue) && (num2 > num)) { num = num2; minValue = dateTime; changes = new List <WorkflowChangeAction>(); } using (input = new StringReader(reader.GetString(0))) { using (serializationManager.CreateSession()) { using (XmlReader reader4 = XmlReader.Create(input)) { ActivityChangeAction item = serializer.Deserialize(serializationManager, reader4) as ActivityChangeAction; errors = serializationManager.Errors; if (item == null) { throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError); } changes.Add(item); item.ApplyTo(rootActivity); } } continue; } } record.EventArgs = new TrackingWorkflowChangedEventArgs(changes, rootActivity); }
private static void WriteWorkflowTrackingRecord(WorkflowTrackingRecord workflowTrackingRecord) { WriteTitle("Workflow Tracking Record"); Console.WriteLine("EventDateTime: " + workflowTrackingRecord.EventDateTime.ToString()); Console.WriteLine("Status: " + workflowTrackingRecord.TrackingWorkflowEvent.ToString()); }
private void WriteWorkflowTrackingRecord(WorkflowTrackingRecord workflowTrackingRecord) { var message = GetTitle("Workflow Tracking Record"); message += string.Format("EventDateTime: {0}\r\n" , workflowTrackingRecord.EventDateTime); message += string.Format("Status: {0}\r\n" , workflowTrackingRecord.TrackingWorkflowEvent); m_Logger.Debug(message); }
private void WriteWorkflowTrackingRecord(WorkflowTrackingRecord workflowTrackingRecord) { WriteToFile("Workflow: " + workflowTrackingRecord.TrackingWorkflowEvent.ToString()); }