Esempio n. 1
0
        public void Abort()
        {
            using (new WorkflowTraceTransfer(this.InstanceId))
            {
                while (true)
                {
                    WorkflowExecutor executor = _runtime.Load(this);
                    if (executor.IsInstanceValid)
                    {
                        if (executor.WorkflowStatus == WorkflowStatus.Created)
                        {
                            throw new InvalidOperationException(ExecutionStringManager.CannotAbortBeforeStart);
                        }

                        try
                        {
                            executor.Abort();
                            break;
                        }
                        catch (InvalidOperationException)
                        {
                            if (executor.IsInstanceValid)
                            {
                                throw;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 public void EnqueueItemOnIdle(IComparable queueName, Object item, IPendingWork pendingWork, Object workItem)
 {
     using (new WorkflowTraceTransfer(this.InstanceId))
     {
         while (true)
         {
             WorkflowExecutor executor = _runtime.Load(this);
             if (executor.IsInstanceValid)
             {
                 try
                 {
                     executor.EnqueueItemOnIdle(queueName, item, pendingWork, workItem);
                     break;
                 }
                 catch (InvalidOperationException)
                 {
                     if (executor.IsInstanceValid)
                     {
                         throw;
                     }
                 }
             }
         }
     }
 }
Esempio n. 3
0
 public void ReloadTrackingProfiles()
 {
     using (new WorkflowTraceTransfer(this.InstanceId))
     {
         while (true)
         {
             WorkflowExecutor executor = _runtime.Load(this);
             if (executor.IsInstanceValid)
             {
                 try
                 {
                     _runtime.TrackingListenerFactory.ReloadProfiles(executor);
                     break;
                 }
                 catch (InvalidOperationException)
                 {
                     if (executor.IsInstanceValid)
                     {
                         throw;
                     }
                 }
             }
         }
     }
 }
Esempio n. 4
0
 public void Start()
 {
     using (new WorkflowTraceTransfer(this.InstanceId))
     {
         while (true)
         {
             WorkflowExecutor executor = _runtime.Load(this);
             if (executor.IsInstanceValid)
             {
                 try
                 {
                     executor.Start();
                     break;
                 }
                 catch (InvalidOperationException)
                 {
                     if (executor.IsInstanceValid)
                     {
                         throw;
                     }
                 }
             }
         }
     }
 }
        private static void FireEvents(List <SchedulerLockGuardInfo> eventList, WorkflowExecutor workflowExec)
        {
            if (!workflowExec.IsInstanceValid && ((workflowExec.WorkflowStatus == WorkflowStatus.Completed) || (workflowExec.WorkflowStatus == WorkflowStatus.Terminated)))
            {
                workflowExec.WorkflowInstance.DeadWorkflow = workflowExec;
            }
            for (int i = 0; i < eventList.Count; i++)
            {
                SchedulerLockGuardInfo info      = eventList[i];
                WorkflowEventInternal  eventType = info.EventType;
                if (eventType != WorkflowEventInternal.Suspended)
                {
                    if (eventType == WorkflowEventInternal.Terminated)
                    {
                        goto Label_0057;
                    }
                    goto Label_008A;
                }
                workflowExec.FireWorkflowSuspended((string)info.EventInfo);
                continue;
Label_0057:
                if (info.EventInfo is Exception)
                {
                    workflowExec.FireWorkflowTerminated((Exception)info.EventInfo);
                }
                else
                {
                    workflowExec.FireWorkflowTerminated((string)info.EventInfo);
                }
                continue;
Label_008A:
                workflowExec.FireWorkflowExecutionEvent(info.Sender, info.EventType);
            }
        }
Esempio n. 6
0
        internal void DynamicUpdateCommit(object sender, WorkflowExecutor.DynamicUpdateEventArgs e)
        {
            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }
            if (!typeof(WorkflowExecutor).IsInstanceOfType(sender))
            {
                throw new ArgumentException("sender");
            }
            WorkflowExecutor skedExec = (WorkflowExecutor)sender;
            DateTime         utcNow   = DateTime.UtcNow;

            foreach (TrackingChannelWrapper wrapper in this._channels)
            {
                wrapper.GetTrackingProfile(skedExec).WorkflowChangeCommit();
            }
            int nextEventOrderId = this._broker.GetNextEventOrderId();

            foreach (TrackingChannelWrapper wrapper2 in this._channels)
            {
                WorkflowTrackingRecord record = new WorkflowTrackingRecord(TrackingWorkflowEvent.Changed, utcNow, nextEventOrderId, new TrackingWorkflowChangedEventArgs(e.ChangeActions, skedExec.WorkflowDefinition));
                if (wrapper2.GetTrackingProfile(skedExec).TryTrackInstanceEvent(TrackingWorkflowEvent.Changed, record))
                {
                    wrapper2.TrackingChannel.Send(record);
                }
            }
        }
        private void LoadExistingInstance(WorkflowInstance instance, bool attaching)
        {
            WorkflowExecutor workflowResourceUNSAFE = instance.GetWorkflowResourceUNSAFE();

            if (workflowResourceUNSAFE.IsInstanceValid)
            {
                IWorkflowCoreRuntime workflowCoreRuntime = workflowResourceUNSAFE;
                Activity             rootActivity        = workflowCoreRuntime.RootActivity;
                Guid scheduleTypeId = this.GetScheduleTypeId(workflowCoreRuntime);
                if (attaching && workflowCoreRuntime.IsDynamicallyUpdated)
                {
                    this.LoadExistingScheduleType(scheduleTypeId, rootActivity.GetType(), true, rootActivity);
                }
                this.instanceTable.AddInstance(instance.InstanceId, rootActivity);
                this.controllerConduit.InstanceCreated(this.programId, instance.InstanceId, scheduleTypeId);
                lock (this.eventLock)
                {
                    workflowResourceUNSAFE.WorkflowExecutionEvent += new EventHandler <WorkflowExecutor.WorkflowExecutionEventArgs>(this.OnInstanceEvent);
                    foreach (Activity activity2 in WalkActivityTree(rootActivity))
                    {
                        this.UpdateActivityStatus(scheduleTypeId, instance.InstanceId, activity2);
                    }
                    ActivityExecutionContext rootContext = new ActivityExecutionContext(rootActivity);
                    foreach (ActivityExecutionContext context2 in WalkExecutionContextTree(rootContext))
                    {
                        foreach (Activity activity4 in WalkActivityTree(context2.Activity))
                        {
                            this.UpdateActivityStatus(scheduleTypeId, instance.InstanceId, activity4);
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        public ReadOnlyCollection <WorkflowQueueInfo> GetWorkflowQueueData()
        {
            if (_deadWorkflow != null)
            {
                return(_deadWorkflow.GetWorkflowQueueInfos());
            }

            while (true)
            {
                WorkflowExecutor executor = _runtime.Load(this);
                if (executor.IsInstanceValid)
                {
                    try
                    {
                        return(executor.GetWorkflowQueueInfos());
                    }
                    catch (InvalidOperationException)
                    {
                        if (executor.IsInstanceValid)
                        {
                            throw;
                        }
                    }
                }
            }
        }
 public bool TryUnload()
 {
     using (new WorkflowTraceTransfer(this.InstanceId))
     {
         WorkflowExecutor executor = this._runtime.Load(this);
         using (executor.ExecutorLock.Enter())
         {
             if (executor.IsInstanceValid)
             {
                 try
                 {
                     return(executor.TryUnload());
                 }
                 catch (InvalidOperationException)
                 {
                     if (executor.IsInstanceValid)
                     {
                         throw;
                     }
                 }
             }
         }
         return(false);
     }
 }
 internal void ReloadProfiles(WorkflowExecutor exec)
 {
     using (new ServiceEnvironment(exec.RootActivity))
     {
         using (exec.ExecutorLock.Enter())
         {
             if (!exec.IsInstanceValid)
             {
                 throw new InvalidOperationException(ExecutionStringManager.WorkflowNotValid);
             }
             bool flag = exec.Suspend(ExecutionStringManager.TrackingProfileUpdate);
             try
             {
                 this.GetListenerFromWRCache(exec.InstanceId).ReloadProfiles(exec, exec.InstanceId);
             }
             finally
             {
                 if (flag)
                 {
                     exec.Resume();
                 }
             }
         }
     }
 }
Esempio n. 11
0
            public void Run()
            {
                this.pause = false;

                while (!this.pause)
                {
                    SchedulableItem item;

                    // atomicActivityQueue has higher priority
                    if (this.atomicActivityQueue.Count > 0)
                    {
                        item = this.atomicActivityQueue.Dequeue();
                    }
                    // The execution of the items in the scheduler queue is deferred until the atomic activity completes.
                    else if (owner.CurrentAtomicActivity == null &&
                             this.schedulerQueue.Count > 0)
                    {
                        item = schedulerQueue.Dequeue();
                    }
                    else
                    {
                        break;
                    }

                    Activity itemActivity = owner.GetContextActivityForId(item.ContextId).GetActivityByName(item.ActivityId);
                    Activity atomicActivity;
                    TransactionalProperties transactionalProperties = null;

                    if (owner.IsActivityInAtomicContext(itemActivity, out atomicActivity))
                    {
                        transactionalProperties = (TransactionalProperties)atomicActivity.GetValue(WorkflowExecutor.TransactionalPropertiesProperty);

                        // If we've aborted for any reason stop now!
                        if (owner.CheckAndProcessTransactionAborted(transactionalProperties))
                        {
                            return;
                        }
                    }

                    try
                    {
                        item.Run(owner);
                    }
                    catch (Exception e)
                    {
                        if (WorkflowExecutor.IsIrrecoverableException(e))
                        {
                            throw;
                        }

                        if (transactionalProperties != null)
                        {
                            transactionalProperties.TransactionState = TransactionProcessState.AbortProcessed;
                            owner.lastExceptionThrown = e;
                        }

                        owner.RaiseException(e, itemActivity, null);
                    }
                }
            }
Esempio n. 12
0
 internal void ProcessTimers()
 {
     using (new WorkflowTraceTransfer(this.InstanceId))
     {
         while (true)
         {
             WorkflowExecutor executor = null;
             try
             {
                 executor = _runtime.Load(this);
             }
             catch (InvalidOperationException)
             {
                 break;
             }
             if (executor != null && executor.IsInstanceValid)
             {
                 try
                 {
                     executor.DeliverTimerSubscriptions();
                     break;
                 }
                 catch (InvalidOperationException)
                 {
                     if (executor.IsInstanceValid)
                     {
                         throw;
                     }
                 }
             }
         }
     }
 }
Esempio n. 13
0
 private void MakeProfilesPrivate(WorkflowExecutor exec)
 {
     foreach (TrackingChannelWrapper wrapper in this._channels)
     {
         wrapper.MakeProfilePrivate(exec);
         this._broker.MakeProfilePrivate(wrapper.TrackingServiceType);
     }
 }
 internal RTTrackingProfile GetTrackingProfile(WorkflowExecutor skedExec)
 {
     if (this._profile == null)
     {
         throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, ExecutionStringManager.NullProfileForChannel, new object[] { this._scheduleType.AssemblyQualifiedName }));
     }
     return(this._profile);
 }
 internal TrackingListener GetTrackingListener(Activity sked, WorkflowExecutor skedExec)
 {
     if (!this._initialized)
     {
         this.Initialize(skedExec.WorkflowRuntime);
     }
     return(this.GetListener(sked, skedExec, null));
 }
Esempio n. 16
0
 internal CreationContext(Type type, WorkflowExecutor invokerExec, string invokeActivityID, Dictionary <string, object> args)
 {
     Type             = type;
     InvokerExecutor  = invokerExec;
     InvokeActivityID = invokeActivityID;
     Args             = args;
     IsActivation     = true;
 }
 internal CreationContext(System.Type type, WorkflowExecutor invokerExec, string invokeActivityID, Dictionary <string, object> args)
 {
     this.Type             = type;
     this.InvokerExecutor  = invokerExec;
     this.InvokeActivityID = invokeActivityID;
     this.Args             = args;
     this.IsActivation     = true;
 }
Esempio n. 18
0
        internal static void Exit(InstanceLock il, WorkflowExecutor w)
        {
            List <SchedulerLockGuardInfo> eventList = new List <SchedulerLockGuardInfo>(w.EventsToFireList);

            w.EventsToFireList.Clear();
            il.Exit();
            FireEvents(eventList, w);
        }
 internal CreationContext(XmlReader xomlReader, XmlReader rulesReader, Dictionary <string, object> args)
 {
     this.XomlReader       = xomlReader;
     this.RulesReader      = rulesReader;
     this.InvokerExecutor  = null;
     this.InvokeActivityID = null;
     this.Args             = args;
     this.IsActivation     = true;
 }
        private void Notify(PerformanceCounterAction action, WorkflowExecutor executor)
        {
            List <PerformanceCounterStatement> list;

            if (this.m_actionStatements.TryGetValue(action, out list))
            {
                foreach (PerformanceCounterStatement statement in list)
                {
                    this.NotifyCounter(action, statement, executor);
                }
            }
        }
Esempio n. 21
0
 private void GetContext(Activity activity, WorkflowExecutor exec, out Guid contextGuid, out Guid parentContextGuid)
 {
     contextGuid = this._factory.GetContext(activity);
     if (activity.Parent != null)
     {
         parentContextGuid = this._factory.GetContext(activity.Parent);
     }
     else
     {
         parentContextGuid = contextGuid;
     }
 }
 private void Detach()
 {
     using (new DebuggerThreadMarker())
     {
         lock (this.syncRoot)
         {
             AppDomain.CurrentDomain.AssemblyLoad -= new AssemblyLoadEventHandler(this.OnAssemblyLoad);
             if (!this.isZombie && this.isAttached)
             {
                 this.isAttached = false;
                 this.programId  = Guid.Empty;
                 if (this.debugControllerThread != null)
                 {
                     this.debugControllerThread.StopThread();
                     this.debugControllerThread = null;
                 }
                 if (this.attachTimer != null)
                 {
                     this.attachTimer.Change(-1, -1);
                     this.attachTimer = null;
                 }
                 RemotingServices.Disconnect(this);
                 if (this.channel != null)
                 {
                     ChannelServices.UnregisterChannel(this.channel);
                     this.channel = null;
                 }
                 this.controllerConduit = null;
                 this.eventConduitAttached.Reset();
                 this.instanceTable  = null;
                 this.typeToGuid     = null;
                 this.xomlHashToGuid = null;
                 if (!this.serviceContainer.IsZombie)
                 {
                     foreach (WorkflowInstance instance in this.serviceContainer.GetLoadedWorkflows())
                     {
                         WorkflowExecutor workflowResourceUNSAFE = instance.GetWorkflowResourceUNSAFE();
                         using (workflowResourceUNSAFE.ExecutorLock.Enter())
                         {
                             if (workflowResourceUNSAFE.IsInstanceValid)
                             {
                                 workflowResourceUNSAFE.WorkflowExecutionEvent -= new EventHandler <WorkflowExecutor.WorkflowExecutionEventArgs>(this.OnInstanceEvent);
                             }
                         }
                     }
                     this.serviceContainer.WorkflowExecutorInitializing -= new EventHandler <WorkflowRuntime.WorkflowExecutorInitializingEventArgs>(this.InstanceInitializing);
                     this.serviceContainer.DefinitionDispenser.WorkflowDefinitionLoaded -= new EventHandler <WorkflowDefinitionEventArgs>(this.ScheduleTypeLoaded);
                 }
             }
         }
     }
 }
Esempio n. 23
0
        private bool SubscriptionRequired(Activity activity, WorkflowExecutor exec)
        {
            bool flag = false;

            foreach (TrackingChannelWrapper wrapper in this._channels)
            {
                if (wrapper.GetTrackingProfile(exec).ActivitySubscriptionNeeded(activity) && !flag)
                {
                    flag = true;
                }
            }
            return(flag);
        }
 internal TrackingListener GetTrackingListener(Activity sked, WorkflowExecutor skedExec, TrackingListenerBroker broker)
 {
     if (!this._initialized)
     {
         this.Initialize(skedExec.WorkflowRuntime);
     }
     if (broker == null)
     {
         WorkflowTrace.Tracking.TraceEvent(TraceEventType.Error, 0, ExecutionStringManager.NullTrackingBroker);
         return(null);
     }
     return(this.GetListener(sked, skedExec, broker));
 }
 public void Run()
 {
     this.pause = false;
     while (!this.pause)
     {
         SchedulableItem item;
         System.Workflow.ComponentModel.Activity activity2;
         if (this.atomicActivityQueue.Count > 0)
         {
             item = this.atomicActivityQueue.Dequeue();
         }
         else
         {
             if ((this.owner.CurrentAtomicActivity != null) || (this.schedulerQueue.Count <= 0))
             {
                 break;
             }
             item = this.schedulerQueue.Dequeue();
         }
         System.Workflow.ComponentModel.Activity activityByName = this.owner.GetContextActivityForId(item.ContextId).GetActivityByName(item.ActivityId);
         TransactionalProperties transactionalProperties        = null;
         if (this.owner.IsActivityInAtomicContext(activityByName, out activity2))
         {
             transactionalProperties = (TransactionalProperties)activity2.GetValue(WorkflowExecutor.TransactionalPropertiesProperty);
             if (this.owner.CheckAndProcessTransactionAborted(transactionalProperties))
             {
                 return;
             }
         }
         try
         {
             item.Run(this.owner);
             continue;
         }
         catch (Exception exception)
         {
             if (WorkflowExecutor.IsIrrecoverableException(exception))
             {
                 throw;
             }
             if (transactionalProperties != null)
             {
                 transactionalProperties.TransactionState = TransactionProcessState.AbortProcessed;
                 this.owner.lastExceptionThrown           = exception;
             }
             this.owner.RaiseException(exception, activityByName, null);
             continue;
         }
     }
 }
Esempio n. 26
0
        internal void RevertToCheckpointState()
        {
            Activity rootActivity = null;

            this.clonedInstanceStateStream.Position = 0L;
            using (new RuntimeEnvironment(this.workflowExecutor.WorkflowRuntime))
            {
                rootActivity = Activity.Load(this.clonedInstanceStateStream, this.workflowDefinition);
            }
            rootActivity.SetValue(WorkflowExecutor.TrackingListenerBrokerProperty, this.workflowExecutor.RootActivity.GetValue(WorkflowExecutor.TrackingListenerBrokerProperty));
            WorkflowExecutor newWorkflowExecutor = new WorkflowExecutor(Guid.Empty);

            newWorkflowExecutor.Initialize(rootActivity, this.workflowExecutor.WorkflowRuntime, this.workflowExecutor);
            Activity contextActivityForId = newWorkflowExecutor.GetContextActivityForId(this.activityContextId);
            Activity activityByName       = contextActivityForId.GetActivityByName(this.activityQualifiedName);

            using (new ServiceEnvironment(activityByName))
            {
                using (newWorkflowExecutor.SetCurrentActivity(activityByName))
                {
                    using (ActivityExecutionContext context = new ActivityExecutionContext(activityByName))
                    {
                        context.Invoke <EventArgs>(this.callbackHandler, this.callbackData);
                    }
                }
            }
            newWorkflowExecutor.BatchCollection.WorkItemOrderId = this.workflowExecutor.BatchCollection.WorkItemOrderId;
            foreach (KeyValuePair <object, WorkBatch> pair in this.workflowExecutor.BatchCollection)
            {
                pair.Value.SetWorkBatchCollection(newWorkflowExecutor.BatchCollection);
                Activity key = pair.Key as Activity;
                if (key != null)
                {
                    Activity activity5 = contextActivityForId.GetActivityByName(key.QualifiedName);
                    newWorkflowExecutor.BatchCollection.Add(activity5, pair.Value);
                }
            }
            this.workflowExecutor.BatchCollection.Clear();
            newWorkflowExecutor.CompletedContextActivities = this.completedContextActivities;
            this.workflowExecutor.WorkflowRuntime.ReplaceWorkflowExecutor(this.workflowExecutor.InstanceId, this.workflowExecutor, newWorkflowExecutor);
            if (!this.suspendOnRevert)
            {
                newWorkflowExecutor.Scheduler.Resume();
            }
            else
            {
                newWorkflowExecutor.SuspendOnIdle(this.suspendOnRevertInfo);
            }
            this.DisposeCheckpointState();
        }
Esempio n. 27
0
 internal TrackingListener(TrackingListenerFactory factory, Activity sked, WorkflowExecutor exec, List <TrackingChannelWrapper> channels, TrackingListenerBroker broker, bool load)
 {
     if ((sked == null) || (broker == null))
     {
         WorkflowTrace.Tracking.TraceEvent(TraceEventType.Error, 0, ExecutionStringManager.NullParameters);
     }
     else
     {
         this._factory  = factory;
         this._channels = channels;
         this._broker   = broker;
         this._broker.TrackingListener = this;
     }
 }
Esempio n. 28
0
        private void Notify(PerformanceCounterAction action, WorkflowExecutor executor)
        {
            System.Diagnostics.Debug.Assert(this.m_actionStatements != null);

            List <PerformanceCounterStatement> lStatements;

            if (this.m_actionStatements.TryGetValue(action, out lStatements))
            {
                foreach (PerformanceCounterStatement statement in lStatements)
                {
                    NotifyCounter(action, statement, executor);
                }
            }
        }
Esempio n. 29
0
 public void Invoke(WorkflowSchedulerService service)
 {
     try
     {
         WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "Running workflow {0}", new object[] { this.state });
         this.Callback(this.state);
     }
     catch (Exception exception)
     {
         if (WorkflowExecutor.IsIrrecoverableException(exception))
         {
             throw;
         }
         service.RaiseExceptionNotHandledEvent(exception, (Guid)this.state);
     }
 }
 internal void MakeProfilePrivate(WorkflowExecutor exec)
 {
     if (this._profile != null)
     {
         if (!this._profile.IsPrivate)
         {
             this._profile           = this._profile.Clone();
             this._profile.IsPrivate = true;
         }
     }
     else
     {
         this._profile           = this.GetTrackingProfile(exec).Clone();
         this._profile.IsPrivate = true;
     }
 }