Exemplo n.º 1
0
        public static WorkflowApplication createInstance(string xamlString, Dictionary<string, object> dictionary, TrackingParticipant tracking)
        {
            WorkflowApplication instance = null;

            DynamicActivity dynamicActivity = tool.activityByXaml(xamlString) as DynamicActivity;

            if (dictionary != null)
            {
                instance = new WorkflowApplication(dynamicActivity, dictionary);
            }
            else
            {
                instance = new WorkflowApplication(dynamicActivity);
            }

            instance.Aborted = aborted;
            instance.Completed = completed;
            instance.OnUnhandledException = onUnhandledException;
            instance.PersistableIdle = persistableIdle;
            instance.Unloaded = unloaded;

            if (tracking != null)
            {
                instance.Extensions.Add(tracking);
            }

            return instance;
        }
 public TrackAsyncResult(TrackingParticipant participant, TrackingRecord record, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.participant = participant;
     this.record = record;
     this.timeout = timeout;
     ActionItem.Schedule(asyncExecuteTrack, this);
 }
Exemplo n.º 3
0
            bool RunLoop()
            {
                if (this.provider.HasPendingRecords)
                {
                    while (this.currentParticipant < this.provider.trackingParticipants.Count)
                    {
                        TrackingParticipant    participant    = this.provider.trackingParticipants[this.currentParticipant];
                        RuntimeTrackingProfile runtimeProfile = this.provider.GetRuntimeTrackingProfile(participant);

                        if (this.provider.pendingTrackingRecords != null)
                        {
                            while (this.currentRecord < this.provider.pendingTrackingRecords.Count)
                            {
                                bool completedSynchronously = PostTrackingRecord(participant, runtimeProfile);
                                if (!completedSynchronously)
                                {
                                    return(false);
                                }
                            }
                        }

                        this.currentRecord = 0;
                        this.currentParticipant++;
                    }
                }

                // We've now tracked all of the records.
                this.provider.ClearPendingRecords();
                return(true);
            }
        private RuntimeTrackingProfile GetRuntimeTrackingProfile(TrackingParticipant participant)
        {
            RuntimeTrackingProfile runtimeTrackingProfile;

            if (!this.profileSubscriptions.TryGetValue(participant, out runtimeTrackingProfile))
            {
                TrackingProfile trackingProfile = participant.TrackingProfile;
                if (trackingProfile != null)
                {
                    runtimeTrackingProfile = RuntimeTrackingProfile.GetRuntimeTrackingProfile(trackingProfile, this.definition);
                    this.Merge(runtimeTrackingProfile.Filter);
                    IEnumerable <string> subscribedActivityNames = runtimeTrackingProfile.GetSubscribedActivityNames();
                    if (subscribedActivityNames != null)
                    {
                        if (this.activitySubscriptions == null)
                        {
                            this.activitySubscriptions = new Hashtable();
                        }
                        foreach (string str in subscribedActivityNames)
                        {
                            if (this.activitySubscriptions[str] == null)
                            {
                                this.activitySubscriptions[str] = str;
                            }
                        }
                    }
                }
                else
                {
                    this.Merge(new TrackingRecordPreFilter(true));
                }
                this.profileSubscriptions.Add(participant, runtimeTrackingProfile);
            }
            return(runtimeTrackingProfile);
        }
 public TrackAsyncResult(TrackingParticipant participant, TrackingRecord record, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.participant = participant;
     this.record      = record;
     this.timeout     = timeout;
     ActionItem.Schedule(asyncExecuteTrack, this);
 }
 private bool RunLoop()
 {
     if (this.provider.HasPendingRecords)
     {
         while (this.currentParticipant < this.provider.trackingParticipants.Count)
         {
             TrackingParticipant    participant            = this.provider.trackingParticipants[this.currentParticipant];
             RuntimeTrackingProfile runtimeTrackingProfile = this.provider.GetRuntimeTrackingProfile(participant);
             if (this.provider.pendingTrackingRecords != null)
             {
                 while (this.currentRecord < this.provider.pendingTrackingRecords.Count)
                 {
                     if (!this.PostTrackingRecord(participant, runtimeTrackingProfile))
                     {
                         return(false);
                     }
                 }
             }
             this.currentRecord = 0;
             this.currentParticipant++;
         }
     }
     this.provider.ClearPendingRecords();
     return(true);
 }
 public void AddParticipant(TrackingParticipant participant)
 {
     if (this.trackingParticipants == null)
     {
         this.trackingParticipants = new List <TrackingParticipant>();
         this.profileSubscriptions = new Dictionary <TrackingParticipant, RuntimeTrackingProfile>();
     }
     this.trackingParticipants.Add(participant);
 }
 public void AddParticipant(TrackingParticipant participant)
 {
     if (this.trackingParticipants == null)
     {
         this.trackingParticipants = new List<TrackingParticipant>();
         this.profileSubscriptions = new Dictionary<TrackingParticipant, RuntimeTrackingProfile>();
     }
     this.trackingParticipants.Add(participant);
 }
Exemplo n.º 9
0
        public void FlushPendingRecords(TimeSpan timeout)
        {
            try
            {
                if (this.HasPendingRecords)
                {
                    TimeoutHelper helper = new TimeoutHelper(timeout);
                    for (int i = 0; i < this.trackingParticipants.Count; i++)
                    {
                        TrackingParticipant    participant    = this.trackingParticipants[i];
                        RuntimeTrackingProfile runtimeProfile = GetRuntimeTrackingProfile(participant);

                        // HasPendingRecords can be true for the sole purpose of populating our initial profiles, so check again here
                        if (this.pendingTrackingRecords != null)
                        {
                            for (int j = 0; j < this.pendingTrackingRecords.Count; j++)
                            {
                                TrackingRecord currentRecord = this.pendingTrackingRecords[j];
                                Fx.Assert(currentRecord != null, "We should never come across a null context.");

                                TrackingRecord preparedRecord = null;
                                bool           shouldClone    = this.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();
            }
        }
Exemplo n.º 10
0
            bool PostTrackingRecord(TrackingParticipant participant, RuntimeTrackingProfile runtimeProfile)
            {
                TrackingRecord originalRecord = this.provider.pendingTrackingRecords[this.currentRecord];

                this.currentRecord++;
                bool isSuccessful = false;

                try
                {
                    TrackingRecord preparedRecord = null;
                    bool           shouldClone    = this.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, this.timeoutHelper.RemainingTime(), PrepareAsyncCompletion(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)
                    {
                        this.provider.ClearPendingRecords();
                    }
                }
                return(true);
            }
 public void FlushPendingRecords(TimeSpan timeout)
 {
     try
     {
         if (this.HasPendingRecords)
         {
             TimeoutHelper helper = new TimeoutHelper(timeout);
             for (int i = 0; i < this.trackingParticipants.Count; i++)
             {
                 TrackingParticipant    participant            = this.trackingParticipants[i];
                 RuntimeTrackingProfile runtimeTrackingProfile = this.GetRuntimeTrackingProfile(participant);
                 if (this.pendingTrackingRecords != null)
                 {
                     for (int j = 0; j < this.pendingTrackingRecords.Count; j++)
                     {
                         TrackingRecord record      = this.pendingTrackingRecords[j];
                         TrackingRecord record2     = null;
                         bool           shouldClone = this.trackingParticipants.Count > 1;
                         if (runtimeTrackingProfile == null)
                         {
                             record2 = shouldClone ? record.Clone() : record;
                         }
                         else
                         {
                             record2 = runtimeTrackingProfile.Match(record, shouldClone);
                         }
                         if (record2 != null)
                         {
                             participant.Track(record2, helper.RemainingTime());
                             if (TD.TrackingRecordRaisedIsEnabled())
                             {
                                 TD.TrackingRecordRaised(record2.ToString(), participant.GetType().ToString());
                             }
                         }
                     }
                 }
             }
         }
     }
     finally
     {
         this.ClearPendingRecords();
     }
 }
            private bool PostTrackingRecord(TrackingParticipant participant, RuntimeTrackingProfile runtimeProfile)
            {
                TrackingRecord record = this.provider.pendingTrackingRecords[this.currentRecord];

                this.currentRecord++;
                bool flag = false;

                try
                {
                    TrackingRecord record2     = null;
                    bool           shouldClone = this.provider.trackingParticipants.Count > 1;
                    if (runtimeProfile == null)
                    {
                        record2 = shouldClone ? record.Clone() : record;
                    }
                    else
                    {
                        record2 = runtimeProfile.Match(record, shouldClone);
                    }
                    if (record2 != null)
                    {
                        IAsyncResult result = participant.BeginTrack(record2, this.timeoutHelper.RemainingTime(), base.PrepareAsyncCompletion(trackingCompleteCallback), this);
                        if (TD.TrackingRecordRaisedIsEnabled())
                        {
                            TD.TrackingRecordRaised(record2.ToString(), participant.GetType().ToString());
                        }
                        if (!result.CompletedSynchronously)
                        {
                            flag = true;
                            return(false);
                        }
                        participant.EndTrack(result);
                    }
                    flag = true;
                }
                finally
                {
                    if (!flag)
                    {
                        this.provider.ClearPendingRecords();
                    }
                }
                return(true);
            }
Exemplo n.º 13
0
        RuntimeTrackingProfile GetRuntimeTrackingProfile(TrackingParticipant participant)
        {
            TrackingProfile        profile;
            RuntimeTrackingProfile runtimeProfile;

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

                if (profile != null)
                {
                    runtimeProfile = RuntimeTrackingProfile.GetRuntimeTrackingProfile(profile, this.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 (this.activitySubscriptions == null)
                        {
                            this.activitySubscriptions = new Hashtable();
                        }
                        foreach (string name in activityNames)
                        {
                            if (this.activitySubscriptions[name] == null)
                            {
                                this.activitySubscriptions[name] = name;
                            }
                        }
                    }
                }
                else
                {
                    //for null profiles, set all the filter flags.
                    Merge(new TrackingRecordPreFilter(true));
                }

                this.profileSubscriptions.Add(participant, runtimeProfile);
            }
            return(runtimeProfile);
        }
            private static bool OnTrackingComplete(IAsyncResult result)
            {
                TrackingProvider.FlushPendingRecordsAsyncResult asyncState = (TrackingProvider.FlushPendingRecordsAsyncResult)result.AsyncState;
                TrackingParticipant participant = asyncState.provider.trackingParticipants[asyncState.currentParticipant];
                bool flag = false;

                try
                {
                    participant.EndTrack(result);
                    flag = true;
                }
                finally
                {
                    if (!flag)
                    {
                        asyncState.provider.ClearPendingRecords();
                    }
                }
                return(asyncState.RunLoop());
            }
Exemplo n.º 15
0
            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());
            }
Exemplo n.º 16
0
            bool PostTrackingRecord(TrackingParticipant participant, RuntimeTrackingProfile runtimeProfile)
            {
                TrackingRecord originalRecord = this.provider.pendingTrackingRecords[this.currentRecord];
                this.currentRecord++;
                bool isSuccessful = false;

                try
                {
                    TrackingRecord preparedRecord = null;
                    bool shouldClone = this.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, this.timeoutHelper.RemainingTime(), PrepareAsyncCompletion(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)
                    {
                        this.provider.ClearPendingRecords();
                    }
                }
                return true;
            }
Exemplo n.º 17
0
        RuntimeTrackingProfile GetRuntimeTrackingProfile(TrackingParticipant participant)
        {
            TrackingProfile profile;
            RuntimeTrackingProfile runtimeProfile;

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

                if (profile != null)
                {
                    runtimeProfile = RuntimeTrackingProfile.GetRuntimeTrackingProfile(profile, this.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 (this.activitySubscriptions == null)
                        {
                            this.activitySubscriptions = new Hashtable();
                        }
                        foreach (string name in activityNames)
                        {
                            if (this.activitySubscriptions[name] == null)
                            {
                                this.activitySubscriptions[name] = name;
                            }
                        }
                    }
                }
                else
                {
                    //for null profiles, set all the filter flags. 
                    Merge(new TrackingRecordPreFilter(true));
                }

                this.profileSubscriptions.Add(participant, runtimeProfile);
            }
            return runtimeProfile;
        }
 private bool PostTrackingRecord(TrackingParticipant participant, RuntimeTrackingProfile runtimeProfile)
 {
     TrackingRecord record = this.provider.pendingTrackingRecords[this.currentRecord];
     this.currentRecord++;
     bool flag = false;
     try
     {
         TrackingRecord record2 = null;
         bool shouldClone = this.provider.trackingParticipants.Count > 1;
         if (runtimeProfile == null)
         {
             record2 = shouldClone ? record.Clone() : record;
         }
         else
         {
             record2 = runtimeProfile.Match(record, shouldClone);
         }
         if (record2 != null)
         {
             IAsyncResult result = participant.BeginTrack(record2, this.timeoutHelper.RemainingTime(), base.PrepareAsyncCompletion(trackingCompleteCallback), this);
             if (TD.TrackingRecordRaisedIsEnabled())
             {
                 TD.TrackingRecordRaised(record2.ToString(), participant.GetType().ToString());
             }
             if (!result.CompletedSynchronously)
             {
                 flag = true;
                 return false;
             }
             participant.EndTrack(result);
         }
         flag = true;
     }
     finally
     {
         if (!flag)
         {
             this.provider.ClearPendingRecords();
         }
     }
     return true;
 }
 private RuntimeTrackingProfile GetRuntimeTrackingProfile(TrackingParticipant participant)
 {
     RuntimeTrackingProfile runtimeTrackingProfile;
     if (!this.profileSubscriptions.TryGetValue(participant, out runtimeTrackingProfile))
     {
         TrackingProfile trackingProfile = participant.TrackingProfile;
         if (trackingProfile != null)
         {
             runtimeTrackingProfile = RuntimeTrackingProfile.GetRuntimeTrackingProfile(trackingProfile, this.definition);
             this.Merge(runtimeTrackingProfile.Filter);
             IEnumerable<string> subscribedActivityNames = runtimeTrackingProfile.GetSubscribedActivityNames();
             if (subscribedActivityNames != null)
             {
                 if (this.activitySubscriptions == null)
                 {
                     this.activitySubscriptions = new Hashtable();
                 }
                 foreach (string str in subscribedActivityNames)
                 {
                     if (this.activitySubscriptions[str] == null)
                     {
                         this.activitySubscriptions[str] = str;
                     }
                 }
             }
         }
         else
         {
             this.Merge(new TrackingRecordPreFilter(true));
         }
         this.profileSubscriptions.Add(participant, runtimeTrackingProfile);
     }
     return runtimeTrackingProfile;
 }