private void ProcessActivityStateRecord(ActivityStateRecord record) { object str; IDictionary<string, object> variables = record.Variables; StringBuilder stringBuilder = new StringBuilder(); if (variables.Count > 0) { stringBuilder.AppendLine("\n\tVariables:"); foreach (KeyValuePair<string, object> variable in variables) { object[] key = new object[2]; key[0] = variable.Key; key[1] = variable.Value; stringBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "\t\tName: {0} Value: {1}", key)); } } PowerShellTraceSource tracer = this.Tracer; CultureInfo invariantCulture = CultureInfo.InvariantCulture; string str1 = " :Activity DisplayName: {0} :ActivityInstanceState: {1} {2}"; object[] name = new object[3]; name[0] = record.Activity.Name; name[1] = record.State; object[] objArray = name; int num = 2; if (variables.Count > 0) { str = stringBuilder.ToString(); } else { str = string.Empty; } objArray[num] = str; tracer.WriteMessage(string.Format(invariantCulture, str1, name)); }
ActivityStateRecord(ActivityStateRecord record) : base(record) { this.Activity = record.Activity; this.State = record.State; if (record.variables != null) { if (record.variables == ActivityUtilities.EmptyParameters) { this.variables = ActivityUtilities.EmptyParameters; } else { this.variables = new Dictionary<string, object>(record.variables); } } if (record.arguments != null) { if (record.arguments == ActivityUtilities.EmptyParameters) { this.arguments = ActivityUtilities.EmptyParameters; } else { this.arguments = new Dictionary<string, object>(record.arguments); } } }
protected override void OnActivityState(ActivityStateRecord record, TimeSpan timeout) { StringBuilder arguments = new StringBuilder(); foreach (var key in record.Arguments.Keys) { arguments.AppendFormat("\"{0}\"={{{1}}}, ", key, record.Variables[key]); } StringBuilder variables = new StringBuilder(); foreach (var key in record.Variables.Keys) { variables.AppendFormat("\"{0}\"={{{1}}}, ", key, record.Variables[key]); } Log.InfoWrite("Tracking::ActivityState - InstanceId:{0}, Activity:{1}, EventTime:{2}, Record#:{3}, Level:{4}, State:{5}, Arguments: [{6}], Variables: [{7}]", record.InstanceId, record.Activity.Name, record.EventTime, record.RecordNumber, record.Level, record.State, arguments.ToString(), variables.ToString()); }
private static ActivityStateQuery MatchActivityState(ActivityStateRecord activityRecord, ReadOnlyCollection <ActivityStateQuery> subscriptions) { ActivityStateQuery genericMatch = null; for (var i = 0; i < subscriptions.Count; i++) { if (subscriptions[i].States.Contains(activityRecord.State)) { return(subscriptions[i]); } else if (subscriptions[i].States.Contains("*")) { if (genericMatch == null) { genericMatch = subscriptions[i]; } } } return(genericMatch); }
private ActivityStateQuery Match(ActivityStateRecord activityStateRecord) { ActivityStateQuery query = null; if (this.activitySubscriptions != null) { HybridCollection <ActivityStateQuery> hybrids; if (this.activitySubscriptions.TryGetValue(activityStateRecord.Activity.Name, out hybrids)) { query = MatchActivityState(activityStateRecord, hybrids.AsReadOnly()); } if ((query == null) && this.activitySubscriptions.TryGetValue("*", out hybrids)) { query = MatchActivityState(activityStateRecord, hybrids.AsReadOnly()); if (((query != null) && (this.associatedProfile.ImplementationVisibility == ImplementationVisibility.RootScope)) && !this.ShouldTrackActivity(activityStateRecord.Activity, "*")) { return(null); } } } return(query); }
void TrackActivityRecord(ActivityStateRecord record) { if (EtwTrackingParticipantTrackRecords.ActivityStateRecordIsEnabled(this.diagnosticTrace)) { if (!EtwTrackingParticipantTrackRecords.ActivityStateRecord(this.diagnosticTrace, record.EventTraceActivity, record.InstanceId, record.RecordNumber, record.EventTime.ToFileTime(), record.State, record.Activity.Name, record.Activity.Id, record.Activity.InstanceId, record.Activity.TypeName, record.Arguments.Count > 0 ? PrepareDictionary(record.Arguments) : emptyItemsTag, record.Variables.Count > 0 ? PrepareDictionary(record.Variables) : emptyItemsTag, record.HasAnnotations ? PrepareAnnotations(record.Annotations) : emptyItemsTag, this.TrackingProfile == null ? string.Empty : this.TrackingProfile.Name, this.ApplicationReference)) { if (EtwTrackingParticipantTrackRecords.ActivityStateRecord(this.diagnosticTrace, record.EventTraceActivity, record.InstanceId, record.RecordNumber, record.EventTime.ToFileTime(), record.State, record.Activity.Name, record.Activity.Id, record.Activity.InstanceId, record.Activity.TypeName, truncatedItemsTag, truncatedItemsTag, truncatedItemsTag, this.TrackingProfile == null ? string.Empty : this.TrackingProfile.Name, this.ApplicationReference)) { TraceTrackingRecordTruncated(record.RecordNumber); } else { TraceTrackingRecordDropped(record.RecordNumber); } } } }
private static ActivityStateQuery MatchActivityState(ActivityStateRecord activityRecord, ReadOnlyCollection<ActivityStateQuery> subscriptions) { ActivityStateQuery query = null; for (int i = 0; i < subscriptions.Count; i++) { if (subscriptions[i].States.Contains(activityRecord.State)) { return subscriptions[i]; } if (subscriptions[i].States.Contains("*") && (query == null)) { query = subscriptions[i]; } } return query; }
private ActivityStateQuery Match(ActivityStateRecord activityStateRecord) { ActivityStateQuery query = null; if (this.activitySubscriptions != null) { HybridCollection<ActivityStateQuery> hybrids; if (this.activitySubscriptions.TryGetValue(activityStateRecord.Activity.Name, out hybrids)) { query = MatchActivityState(activityStateRecord, hybrids.AsReadOnly()); } if ((query == null) && this.activitySubscriptions.TryGetValue("*", out hybrids)) { query = MatchActivityState(activityStateRecord, hybrids.AsReadOnly()); if (((query != null) && (this.associatedProfile.ImplementationVisibility == ImplementationVisibility.RootScope)) && !this.ShouldTrackActivity(activityStateRecord.Activity, "*")) { return null; } } } return query; }
private static void ExtractVariables(ActivityStateRecord activityStateRecord, ActivityStateQuery activityStateQuery) { if (activityStateQuery.HasVariables) { activityStateRecord.Variables = activityStateRecord.GetVariables(activityStateQuery.Variables); } else { activityStateRecord.Variables = ActivityUtilities.EmptyParameters; } }
private static void ExtractArguments(ActivityStateRecord activityStateRecord, ActivityStateQuery activityStateQuery) { if (activityStateQuery.HasArguments) { activityStateRecord.Arguments = activityStateRecord.GetArguments(activityStateQuery.Arguments); } else { activityStateRecord.Arguments = ActivityUtilities.EmptyParameters; } }
/// <summary> /// The get key. /// </summary> /// <param name="record"> /// The record. /// </param> /// <returns> /// The System.String. /// </returns> private static string GetKey(ActivityStateRecord record) { return record.InstanceId + record.Activity.Name; }
protected virtual void OnActivityState(ActivityStateRecord record, TimeSpan timeout) { }
/// <summary> /// Updates the state info based on the record /// </summary> /// <param name="record"> /// The activity state record /// </param> internal void UpdateState(ActivityStateRecord record) { this.InstanceState = record.GetInstanceState(); switch (this.InstanceState) { case ActivityInstanceState.Executing: break; case ActivityInstanceState.Closed: this.CurrentState = null; this.possibleTransitions = null; break; case ActivityInstanceState.Canceled: this.CurrentState = null; this.possibleTransitions = null; break; case ActivityInstanceState.Faulted: this.CurrentState = null; this.possibleTransitions = null; break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// process the activity state record. /// </summary> /// <param name="record">Record representing activity state record.</param> private void ProcessActivityStateRecord(ActivityStateRecord record) { IDictionary<String, object> variables = record.Variables; StringBuilder vars = new StringBuilder(); if (variables.Count > 0) { vars.AppendLine("\n\tVariables:"); foreach (KeyValuePair<string, object> variable in variables) { vars.AppendLine(String.Format(CultureInfo.InvariantCulture, "\t\tName: {0} Value: {1}", variable.Key, variable.Value)); } } Tracer.WriteMessage(String.Format(CultureInfo.InvariantCulture, " :Activity DisplayName: {0} :ActivityInstanceState: {1} {2}", record.Activity.Name, record.State, ((variables.Count > 0) ? vars.ToString() : String.Empty))); }
static ActivityStateQuery MatchActivityState(ActivityStateRecord activityRecord, ReadOnlyCollection<ActivityStateQuery> subscriptions) { ActivityStateQuery genericMatch = null; for (int i = 0; i < subscriptions.Count; i++) { if (subscriptions[i].States.Contains(activityRecord.State)) { return subscriptions[i]; } else if (subscriptions[i].States.Contains("*")) { if (genericMatch == null) { genericMatch = subscriptions[i]; } } } return genericMatch; }
ActivityStateQuery Match(ActivityStateRecord activityStateRecord) { ActivityStateQuery query = null; if (this.activitySubscriptions != null) { HybridCollection<ActivityStateQuery> eventSubscriptions; //first look for a specific match, if not found, look for a generic match. if (this.activitySubscriptions.TryGetValue(activityStateRecord.Activity.Name, out eventSubscriptions)) { query = MatchActivityState(activityStateRecord, eventSubscriptions.AsReadOnly()); } if (query == null && this.activitySubscriptions.TryGetValue("*", out eventSubscriptions)) { query = MatchActivityState(activityStateRecord, eventSubscriptions.AsReadOnly()); if ((query != null) && (this.associatedProfile.ImplementationVisibility == ImplementationVisibility.RootScope)) { if (!ShouldTrackActivity(activityStateRecord.Activity, "*")) { return null; } } } } return query; }
/// <summary> /// The update instance state. /// </summary> /// <param name="record"> /// The record. /// </param> private void UpdateInstanceState(ActivityStateRecord record) { var stateMachineInfo = this.stateMachines[GetKey(record)]; stateMachineInfo.UpdateState(record); }
/// <summary> /// The add state machine. /// </summary> /// <param name="record"> /// The record. /// </param> private void AddOrUpdateStateMachine(ActivityStateRecord record) { var history = this.maxHistory; this.currentStateMachine = this.stateMachines.AddOrUpdate( GetKey(record), s => new StateMachineInfo(history) { Name = record.Activity.Name, InstanceState = record.GetInstanceState(), InstanceId = record.InstanceId }, (s, info) => { info.InstanceState = record.GetInstanceState(); return info; }); }
/// <summary> /// The track. /// </summary> /// <param name="record"> /// The record. /// </param> /// <param name="timeout"> /// The timeout. /// </param> protected override void Track(ActivityStateRecord record, TimeSpan timeout) { this.records.Add(record); }
private void TrackActivityRecord(ActivityStateRecord record) { if (EtwTrackingParticipantTrackRecords.ActivityStateRecordIsEnabled(this.diagnosticTrace) && !EtwTrackingParticipantTrackRecords.ActivityStateRecord(this.diagnosticTrace, record.InstanceId, record.RecordNumber, record.EventTime.ToFileTime(), record.State, record.Activity.Name, record.Activity.Id, record.Activity.InstanceId, record.Activity.TypeName, (record.Arguments.Count > 0) ? this.PrepareDictionary(record.Arguments) : "<items />", (record.Variables.Count > 0) ? this.PrepareDictionary(record.Variables) : "<items />", record.HasAnnotations ? PrepareAnnotations(record.Annotations) : "<items />", (this.TrackingProfile == null) ? string.Empty : this.TrackingProfile.Name, this.ApplicationReference)) { if (EtwTrackingParticipantTrackRecords.ActivityStateRecord(this.diagnosticTrace, record.InstanceId, record.RecordNumber, record.EventTime.ToFileTime(), record.State, record.Activity.Name, record.Activity.Id, record.Activity.InstanceId, record.Activity.TypeName, "<items>...</items>", "<items>...</items>", "<items>...</items>", (this.TrackingProfile == null) ? string.Empty : this.TrackingProfile.Name, this.ApplicationReference)) { this.TraceTrackingRecordTruncated(record.RecordNumber); } else { this.TraceTrackingRecordDropped(record.RecordNumber); } } }
public ActivityStateTrackedEventArgs(ActivityStateRecord state) { this.ActivityStateRecord = state; }
/// <summary> /// When implemented in a derived class, used to synchronously process the tracking record. /// </summary> /// <param name="record"> /// The generated tracking record. /// </param> /// <param name="timeout"> /// The time period after which the provider aborts the attempt. /// </param> protected virtual void Track(ActivityStateRecord record, TimeSpan timeout) { // Do nothing }
/// <summary> /// The track. /// </summary> /// <param name="record"> /// The record. /// </param> /// <param name="timeout"> /// The timeout. /// </param> /// <exception cref="ArgumentOutOfRangeException"> /// An unknown ActivityInstanceState was encountered /// </exception> protected override void Track(ActivityStateRecord record, TimeSpan timeout) { // If the record is a state machine if (record.Activity.TypeName == typeof(StateMachine).FullName) { this.AddOrUpdateStateMachine(record); } }