public void FlushPendingRecords(TimeSpan timeout) { try { if (this.HasPendingRecords) { TimeoutHelper helper = new TimeoutHelper(timeout); for (int i = 0; i < _trackingParticipants.Count; i++) { TrackingParticipant participant = _trackingParticipants[i]; RuntimeTrackingProfile runtimeProfile = GetRuntimeTrackingProfile(participant); // HasPendingRecords can be true for the sole purpose of populating our initial profiles, so check again here if (_pendingTrackingRecords != null) { for (int j = 0; j < _pendingTrackingRecords.Count; j++) { TrackingRecord currentRecord = _pendingTrackingRecords[j]; Fx.Assert(currentRecord != null, "We should never come across a null context."); TrackingRecord preparedRecord = null; bool shouldClone = _trackingParticipants.Count > 1; if (runtimeProfile == null) { preparedRecord = shouldClone ? currentRecord.Clone() : currentRecord; } else { preparedRecord = runtimeProfile.Match(currentRecord, shouldClone); } if (preparedRecord != null) { participant.Track(preparedRecord, helper.RemainingTime()); if (TD.TrackingRecordRaisedIsEnabled()) { TD.TrackingRecordRaised(preparedRecord.ToString(), participant.GetType().ToString()); } } } } } } } finally { // Note that if we fail to track yet the workflow manages to recover // we will attempt to track those records again. ClearPendingRecords(); } }
private bool PostTrackingRecord(TrackingParticipant participant, RuntimeTrackingProfile runtimeProfile) { TrackingRecord originalRecord = _provider._pendingTrackingRecords[_currentRecord]; _currentRecord++; bool isSuccessful = false; try { TrackingRecord preparedRecord = null; bool shouldClone = _provider._trackingParticipants.Count > 1; if (runtimeProfile == null) { preparedRecord = shouldClone ? originalRecord.Clone() : originalRecord; } else { preparedRecord = runtimeProfile.Match(originalRecord, shouldClone); } if (preparedRecord != null) { IAsyncResult result = participant.BeginTrack(preparedRecord, _timeoutHelper.RemainingTime(), PrepareAsyncCompletion(s_trackingCompleteCallback), this); if (TD.TrackingRecordRaisedIsEnabled()) { TD.TrackingRecordRaised(preparedRecord.ToString(), participant.GetType().ToString()); } if (result.CompletedSynchronously) { participant.EndTrack(result); } else { isSuccessful = true; return(false); } } isSuccessful = true; } finally { if (!isSuccessful) { _provider.ClearPendingRecords(); } } return(true); }
private static TrackingRecord PrepareRecord(TrackingRecord record, TrackingQuery query, bool shouldClone) { TrackingRecord preparedRecord = shouldClone ? record.Clone() : record; if (query.HasAnnotations) { preparedRecord.Annotations = new ReadOnlyDictionary <string, string>(query.QueryAnnotations); } if (query is ActivityStateQuery) { ExtractArguments((ActivityStateRecord)preparedRecord, (ActivityStateQuery)query); ExtractVariables((ActivityStateRecord)preparedRecord, (ActivityStateQuery)query); } return(preparedRecord); }