示例#1
0
            private bool RunLoop()
            {
                if (_provider.HasPendingRecords)
                {
                    while (_currentParticipant < _provider._trackingParticipants.Count)
                    {
                        TrackingParticipant    participant    = _provider._trackingParticipants[_currentParticipant];
                        RuntimeTrackingProfile runtimeProfile = _provider.GetRuntimeTrackingProfile(participant);

                        if (_provider._pendingTrackingRecords != null)
                        {
                            while (_currentRecord < _provider._pendingTrackingRecords.Count)
                            {
                                bool completedSynchronously = PostTrackingRecord(participant, runtimeProfile);
                                if (!completedSynchronously)
                                {
                                    return(false);
                                }
                            }
                        }

                        _currentRecord = 0;
                        _currentParticipant++;
                    }
                }

                // We've now tracked all of the records.
                _provider.ClearPendingRecords();
                return(true);
            }
示例#2
0
 public TrackAsyncResult(TrackingParticipant participant, TrackingRecord record, TimeSpan timeout, AsyncCallback callback, object state)
     : base(callback, state)
 {
     _participant = participant;
     _record      = record;
     _timeout     = timeout;
     ActionItem.Schedule(s_asyncExecuteTrack, this);
 }
示例#3
0
 public void AddParticipant(TrackingParticipant participant)
 {
     if (_trackingParticipants == null)
     {
         _trackingParticipants = new List <TrackingParticipant>();
         _profileSubscriptions = new Dictionary <TrackingParticipant, RuntimeTrackingProfile>();
     }
     _trackingParticipants.Add(participant);
 }
示例#4
0
        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();
            }
        }
示例#5
0
            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);
            }
示例#6
0
        private RuntimeTrackingProfile GetRuntimeTrackingProfile(TrackingParticipant participant)
        {
            TrackingProfile        profile;
            RuntimeTrackingProfile runtimeProfile;

            if (!_profileSubscriptions.TryGetValue(participant, out runtimeProfile))
            {
                profile = participant.TrackingProfile;

                if (profile != null)
                {
                    runtimeProfile = RuntimeTrackingProfile.GetRuntimeTrackingProfile(profile, _definition);
                    Merge(runtimeProfile.Filter);

                    //Add the names to the list of activities that have subscriptions.  This provides a quick lookup
                    //for the runtime to check if a TrackingRecord has to be created.
                    IEnumerable <string> activityNames = runtimeProfile.GetSubscribedActivityNames();
                    if (activityNames != null)
                    {
                        if (_activitySubscriptions == null)
                        {
                            _activitySubscriptions = new Dictionary <string, string>();
                        }
                        foreach (string name in activityNames)
                        {
                            if (_activitySubscriptions.ContainsKey(name))
                            {
                                _activitySubscriptions.Add(name, name);
                            }
                            else
                            {
                                _activitySubscriptions[name] = name;
                            }
                        }
                    }
                }
                else
                {
                    //for null profiles, set all the filter flags.
                    Merge(new TrackingRecordPreFilter(true));
                }

                _profileSubscriptions.Add(participant, runtimeProfile);
            }
            return(runtimeProfile);
        }
示例#7
0
            private static bool OnTrackingComplete(IAsyncResult result)
            {
                Fx.Assert(!result.CompletedSynchronously, "TrackingAsyncResult.OnTrackingComplete should not get called with a result that is CompletedSynchronously");

                FlushPendingRecordsAsyncResult thisPtr     = (FlushPendingRecordsAsyncResult)result.AsyncState;
                TrackingParticipant            participant = thisPtr._provider._trackingParticipants[thisPtr._currentParticipant];
                bool isSuccessful = false;

                try
                {
                    participant.EndTrack(result);
                    isSuccessful = true;
                }
                finally
                {
                    if (!isSuccessful)
                    {
                        thisPtr._provider.ClearPendingRecords();
                    }
                }
                return(thisPtr.RunLoop());
            }