예제 #1
0
        public void Terminate(Guid id, string reason)
        {
            EnsureOpen();
            WorkflowApplicationState workflowApplicationState = null;

            lock (this.instanceStatesLock)
            {
                this.instanceStates.TryGetValue(id, out workflowApplicationState);
            }

            if (workflowApplicationState == null)
            {
                InstanceNoLongerPresent(id);
                return;
            }

            workflowApplicationState.CanResumeBookmarks = false;

            try
            {
                workflowApplicationState.WorkflowApplication.BeginTerminate(reason, new AsyncCallback(OnEndTerminate), workflowApplicationState.WorkflowApplication);
            }
            catch (WorkflowApplicationException workflowApplicationException)
            {
                RemoveInstanceWithException(workflowApplicationState.WorkflowApplication.Id, "An error occured during Termination", workflowApplicationException);
            }
        }
예제 #2
0
        void AddInstance(WorkflowApplicationState workflowApplicationState)
        {
            List <WorkflowApplicationInfo> instanceInfos = null;

            lock (instanceStatesLock)
            {
                this.instanceStates.Add(workflowApplicationState.WorkflowApplication.Id, workflowApplicationState);
                instanceInfos = BuildInstanceInfoList();
            }

            this.hostView.UpdateInstances(instanceInfos);
        }
예제 #3
0
        public void Abort(Guid id, string reason)
        {
            EnsureOpen();
            WorkflowApplicationState workflowApplicationState = null;

            lock (this.instanceStatesLock)
            {
                this.instanceStates.TryGetValue(id, out workflowApplicationState);
            }

            if (workflowApplicationState == null)
            {
                //it is possible this instance has been removed by some other event in the workflow
                //nothing to do
                return;
            }

            workflowApplicationState.WorkflowApplication.Abort(reason);
        }
예제 #4
0
        public void ResumeBookmark(Guid id, string bookmarkName, string value)
        {
            EnsureOpen();

            WorkflowApplicationState workflowApplicationState = null;

            lock (this.instanceStatesLock)
            {
                this.instanceStates.TryGetValue(id, out workflowApplicationState);
            }

            if (workflowApplicationState == null)
            {
                InstanceNoLongerPresent(id);
                return;
            }

            workflowApplicationState.CanResumeBookmarks = false;

            workflowApplicationState.WorkflowApplication.BeginResumeBookmark(bookmarkName, value, new AsyncCallback(OnEndResumeBookmark), new object[] { workflowApplicationState.WorkflowApplication, bookmarkName });
        }
예제 #5
0
        void UpdateInstanceState(Guid id)
        {
            WorkflowApplicationState workflowApplicationState = null;

            lock (this.instanceStatesLock)
            {
                this.instanceStates.TryGetValue(id, out workflowApplicationState);
            }

            if (workflowApplicationState == null)
            {
                //any event that would result in the removal of the instance will have output the reason to the hostView
                return;
            }

            List <WorkflowApplicationInfo> instanceInfos = null;

            lock (this.instanceStatesLock)
            {
                instanceInfos = BuildInstanceInfoList();
            }

            this.hostView.UpdateInstances(instanceInfos);
        }
        void AddInstance(WorkflowApplicationState workflowApplicationState)
        {
            List<WorkflowApplicationInfo> instanceInfos = null;

            lock (instanceStatesLock)
            {
                this.instanceStates.Add(workflowApplicationState.WorkflowApplication.Id, workflowApplicationState);
                instanceInfos = BuildInstanceInfoList();
            }

            this.hostView.UpdateInstances(instanceInfos);
        }
예제 #7
0
        public void Close()
        {
            lock (managerStateLock)
            {
                if (this.state == ManagerState.Closed)
                {
                    return;
                }
                else
                {
                    this.state = ManagerState.Closed;
                }
            }

            List <WorkflowApplication> instances;

            lock (instanceStatesLock)
            {
                instances = new List <WorkflowApplication>();
                Guid[] keys = this.instanceStates.Keys.ToArray();
                for (int index = 0; index < keys.Length; index++)
                {
                    WorkflowApplicationState instanceState = this.instanceStates[keys[index]];
                    if (instanceState.IsLoaded)
                    {
                        instances.Add(instanceState.WorkflowApplication);
                    }
                    instanceState.Close();
                    this.instanceStates.Remove(keys[index]);
                }
            }

            Collection <IAsyncResult> unloadCalls = new Collection <IAsyncResult>();

            foreach (WorkflowApplication instance in instances)
            {
                if (this.hostView.UsePersistence)
                {
                    try
                    {
                        IAsyncResult result = instance.BeginUnload(null, instance);
                        unloadCalls.Add(result);
                    }
                    //swallow any exception - this is a best effort Close
                    catch (WorkflowApplicationException) { }
                    catch (InstancePersistenceException) { }
                }
                else
                {
                    instance.Abort();
                }
            }

            //can't wait on multiple handles under an STA thread
            foreach (IAsyncResult result in unloadCalls)
            {
                result.AsyncWaitHandle.WaitOne();
                WorkflowApplication instance = result.AsyncState as WorkflowApplication;
                try
                {
                    instance.EndUnload(result);
                }
                //swallow any exception - this is a best effort Close
                catch (WorkflowApplicationException) { }
                catch (InstancePersistenceException) { }
            }
        }