public void DeliverMessage(ExternalDataEventArgs eventArgs, IComparable queueName, object message, object workItem, IPendingWork workHandler)
        {
            if (eventArgs == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("eventArgs");
            }
            if (queueName == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("queueName");
            }

            using (ExternalDataExchangeClient desClient = new ExternalDataExchangeClient(WorkflowRuntimeEndpoint.netNamedPipeContextBinding,
                new EndpointAddress(this.baseUri)))
            {
                using (OperationContextScope scope = new OperationContextScope((IContextChannel)desClient.InnerChannel))
                {
                    IContextManager contextManager = desClient.InnerChannel.GetProperty<IContextManager>();
                    Fx.Assert(contextManager != null, "IContextManager must not be null.");
                    if (contextManager != null)
                    {
                        IDictionary<string, string> context = new Dictionary<string, string>();
                        context["instanceId"] = eventArgs.InstanceId.ToString();
                        contextManager.SetContext(context);
                    }

                    desClient.RaiseEvent(eventArgs, queueName, message);
                }
            }
  
        }
Example #2
0
 public ExternalDataEventArgs(Guid instanceId, IPendingWork workHandler, object workItem, bool waitForIdle)
 {
     this.instanceId       = instanceId;
     this.batchworkHandler = workHandler;
     this.batchworkItem    = workItem;
     this.waitForIdle      = waitForIdle;
 }
Example #3
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;
                     }
                 }
             }
         }
     }
 }
        public void EnqueueItemOnIdle(IComparable queueName, object item, IPendingWork pendingWork, object workItem)
        {
            using (new WorkflowTraceTransfer(this.InstanceId))
            {
                WorkflowExecutor executor;
Label_000C:
                executor = this._runtime.Load(this);
                if (!executor.IsInstanceValid)
                {
                    goto Label_000C;
                }
                try
                {
                    executor.EnqueueItemOnIdle(queueName, item, pendingWork, workItem);
                }
                catch (InvalidOperationException)
                {
                    if (executor.IsInstanceValid)
                    {
                        throw;
                    }
                    goto Label_000C;
                }
            }
        }
 public ExternalDataEventArgs(Guid instanceId, IPendingWork workHandler, object workItem, bool waitForIdle)
 {
     this.instanceId = instanceId;
     this.batchworkHandler = workHandler;
     this.batchworkItem = workItem;
     this.waitForIdle = waitForIdle;
 }
Example #6
0
 internal void Commit(Transaction transaction)
 {
     foreach (KeyValuePair <IPendingWork, SortedList <long, object> > pair in this.Items)
     {
         IPendingWork  key   = pair.Key;
         List <object> items = new List <object>(pair.Value.Values);
         key.Commit(transaction, items);
     }
 }
 //Commit All Pending Work
 internal void Commit(Transaction transaction)
 {
     //ignore items param
     foreach (KeyValuePair <IPendingWork, SortedList <long, object> > workItem in Items)
     {
         IPendingWork  work   = workItem.Key;
         List <object> values = new List <object>(workItem.Value.Values);
         work.Commit(transaction, values);
     }
 }
Example #8
0
 void IWorkBatch.Add(IPendingWork work, object workItem)
 {
     if (this._pendingWorkCollection == null)
     {
         throw new ObjectDisposedException("WorkBatch");
     }
     lock (this.mutex)
     {
         this._pendingWorkCollection.Add(work, this._collection.GetNextWorkItemOrderId(work), workItem);
     }
 }
Example #9
0
            internal void Add(IPendingWork work, long orderId, object workItem)
            {
                SortedList <long, object> list = null;

                if (!this.Items.TryGetValue(work, out list))
                {
                    list = new SortedList <long, object>();
                    this.Items.Add(work, list);
                }
                list.Add(orderId, workItem);
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "pending work hc {0} added workItem hc {1}", new object[] { work.GetHashCode(), workItem.GetHashCode() });
            }
Example #10
0
		//public void ApplyWorkflowChanges (WorkflowChanges workflowChanges);

		public void EnqueueItem (IComparable queueName, object item, IPendingWork pendingWork, object workItem)
		{
			WorkflowQueue queue;

			// TODO: What to do with pendingWork and workItem?
			if (queuing_service.Exists (queueName)) {
				queue = queuing_service.GetWorkflowQueue (queueName);
			} else {
				queue = queuing_service.CreateWorkflowQueue (queueName, true);
			}

			queue.Enqueue (item);
		}
            internal void Add(IPendingWork work, long orderId, object workItem)
            {
                SortedList <long, object> workItems = null;

                if (!Items.TryGetValue(work, out workItems))
                {
                    workItems = new SortedList <long, object>();
                    Items.Add(work, workItems);
                }
                Debug.Assert(!workItems.ContainsKey(orderId), string.Format(System.Globalization.CultureInfo.InvariantCulture, "List already contains key {0}", orderId));
                workItems.Add(orderId, workItem);
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "pending work hc {0} added workItem hc {1}", work.GetHashCode(), workItem.GetHashCode());
            }
        /// <summary>
        /// Add Work to Batch
        /// </summary>
        /// <param name="work"></param>
        /// <param name="workItem"></param>
        void IWorkBatch.Add(IPendingWork work, object workItem)
        {
            if (_pendingWorkCollection == null)
            {
                throw new ObjectDisposedException("WorkBatch");
            }

            lock (this.mutex)
            {
                System.Diagnostics.Debug.Assert(this._state == WorkBatchState.Usable, "Trying to add to unusable batch.");

                _pendingWorkCollection.Add(work, _collection.GetNextWorkItemOrderId(work), workItem);
            }
        }
Example #13
0
        //public void ApplyWorkflowChanges (WorkflowChanges workflowChanges);

        public void EnqueueItem(IComparable queueName, object item, IPendingWork pendingWork, object workItem)
        {
            WorkflowQueue queue;

            // TODO: What to do with pendingWork and workItem?
            if (queuing_service.Exists(queueName))
            {
                queue = queuing_service.GetWorkflowQueue(queueName);
            }
            else
            {
                queue = queuing_service.CreateWorkflowQueue(queueName, true);
            }

            queue.Enqueue(item);
        }
Example #14
0
 internal void Complete(bool succeeded)
 {
     foreach (KeyValuePair <IPendingWork, SortedList <long, object> > pair in this.Items)
     {
         IPendingWork  key   = pair.Key;
         List <object> items = new List <object>(pair.Value.Values);
         try
         {
             key.Complete(succeeded, items);
         }
         catch (Exception exception)
         {
             if (WorkflowExecutor.IsIrrecoverableException(exception))
             {
                 throw;
             }
             WorkflowTrace.Runtime.TraceEvent(TraceEventType.Warning, 0, "Work Item {0} threw exception on complete notification", new object[] { pair.GetType() });
         }
     }
 }
 public void EnqueueItem(IComparable queueName, object item, IPendingWork pendingWork, object workItem)
 {
     using (new WorkflowTraceTransfer(this.InstanceId))
     {
         WorkflowExecutor executor;
     Label_000C:
         executor = this._runtime.Load(this);
         try
         {
             executor.EnqueueItem(queueName, item, pendingWork, workItem);
         }
         catch (InvalidOperationException)
         {
             if (executor.IsInstanceValid)
             {
                 throw;
             }
             goto Label_000C;
         }
     }
 }
 //Complete All Pending Work
 internal void Complete(bool succeeded)
 {
     foreach (KeyValuePair <IPendingWork, SortedList <long, object> > workItem in Items)
     {
         IPendingWork  work   = workItem.Key;
         List <object> values = new List <object>(workItem.Value.Values);
         try
         {
             work.Complete(succeeded, values);
         }
         catch (Exception e)
         {
             if (WorkflowExecutor.IsIrrecoverableException(e))
             {
                 throw;
             }
             else
             {
                 WorkflowTrace.Runtime.TraceEvent(TraceEventType.Warning, 0, "Work Item {0} threw exception on complete notification", workItem.GetType());
             }
         }
     }
 }
 public void DeliverMessage(ExternalDataEventArgs eventArgs, IComparable queueName, object message, object workItem, IPendingWork workHandler)
 {
     WorkflowInstance workflowInstance = this.eds.Runtime.GetWorkflow(eventArgs.InstanceId);
     if (eventArgs.WaitForIdle)
     {
         workflowInstance.EnqueueItemOnIdle(queueName, message, workHandler, workItem);
     }
     else
     {
         workflowInstance.EnqueueItem(queueName, message, workHandler, workItem);
     }
 }
		public ExternalDataEventArgs (Guid instanceId, IPendingWork workHandler, object workItem, bool waitForIdle)
		{

		}
Example #19
0
 public ExternalDataEventArgs(Guid instanceId, IPendingWork workHandler, object workItem, bool waitForIdle)
 {
 }
            public object[] PrepareEventArgsArray(object sender, ExternalDataEventArgs eventArgs, out object workItem, out IPendingWork workHandler)
            {
                // remove the batch items from the event args, only the runtime needs this data
                // and it is not necessarily serializable.
                workItem = eventArgs.WorkItem;
                eventArgs.WorkItem = null;
                workHandler = eventArgs.WorkHandler;
                eventArgs.WorkHandler = null;

                return new object[] { sender, eventArgs };
            }
 internal void EnqueueItemOnIdle(IComparable queueName, object item, IPendingWork pendingWork, object workItem)
 {
     using (new ScheduleWork(this))
     {
         using (this._executorLock.Enter())
         {
             if (!this.IsInstanceValid)
             {
                 throw new InvalidOperationException(ExecutionStringManager.WorkflowNotValid);
             }
             using (InstanceLock.InstanceLockGuard guard = this.MessageDeliveryLock.Enter())
             {
                 using (new ServiceEnvironment(this.rootActivity))
                 {
                     if (this.IsInstanceValid)
                     {
                         goto Label_006C;
                     }
                     throw new InvalidOperationException(ExecutionStringManager.WorkflowNotValid);
                 Label_0052:
                     guard.Wait();
                     if (!this.IsInstanceValid)
                     {
                         throw new InvalidOperationException(ExecutionStringManager.WorkflowNotValid);
                     }
                 Label_006C:
                     if (!this.IsIdle)
                     {
                         goto Label_0052;
                     }
                     if ((this.WorkflowStatus == System.Workflow.Runtime.WorkflowStatus.Suspended) || !this.Scheduler.CanRun)
                     {
                         throw new InvalidOperationException(ExecutionStringManager.InvalidWaitForIdleOnSuspendedWorkflow);
                     }
                     try
                     {
                         if (pendingWork != null)
                         {
                             ((IWorkBatch) this.rootActivity.GetValue(TransientBatchProperty)).Add(pendingWork, workItem);
                         }
                         this.stateChangedSincePersistence = true;
                         this.qService.EnqueueEvent(queueName, item);
                     }
                     finally
                     {
                         if (this.IsIdle)
                         {
                             guard.Pulse();
                         }
                     }
                 }
             }
         }
     }
 }
Example #22
0
		public void EnqueueItemOnIdle (IComparable queueName, object item, IPendingWork pendingWork, object workItem)
		{

		}
Example #23
0
            public void DeliverMessage(ExternalDataEventArgs eventArgs, IComparable queueName, object message, object workItem, IPendingWork workHandler)
            {
                WorkflowInstance workflow = this.eds.Runtime.GetWorkflow(eventArgs.InstanceId);

                if (eventArgs.WaitForIdle)
                {
                    workflow.EnqueueItemOnIdle(queueName, message, workHandler, workItem);
                }
                else
                {
                    workflow.EnqueueItem(queueName, message, workHandler, workItem);
                }
            }
 public object[] PrepareEventArgsArray(object sender, ExternalDataEventArgs eventArgs, out object workItem, out IPendingWork workHandler)
 {
     workItem = null;
     workHandler = null;
     return new object[] { sender, eventArgs };
 }
Example #25
0
        internal void EnqueueItemOnIdle(IComparable queueName, object item, IPendingWork pendingWork, Object workItem)
        {
            using (ScheduleWork work = new ScheduleWork(this))
            {
                // prevent other control operations from outside
                using (this._executorLock.Enter())
                {
                    if (!this.IsInstanceValid)
                        throw new InvalidOperationException(ExecutionStringManager.WorkflowNotValid);

                    // take the msg delivery lock to make sure the instance
                    // doesn't persist while the message is being delivered.
                    using (InstanceLock.InstanceLockGuard messageDeliveryLockGuard = this.MessageDeliveryLock.Enter())
                    {
                        using (new ServiceEnvironment(this.rootActivity))
                        {

                            if (!this.IsInstanceValid)
                                throw new InvalidOperationException(ExecutionStringManager.WorkflowNotValid);

                            // Wait until the Scheduler is idle.
                            while (!this.IsIdle)
                            {
                                messageDeliveryLockGuard.Wait();
                                if (!this.IsInstanceValid)
                                    throw new InvalidOperationException(ExecutionStringManager.WorkflowNotValid);
                            }

                            // At this point the scheduler is not running and it is 
                            // EnqueueItemOnIdle is not valid for suspended workflows
                            if ((this.WorkflowStatus == WorkflowStatus.Suspended) || (!this.Scheduler.CanRun))
                                throw new InvalidOperationException(ExecutionStringManager.InvalidWaitForIdleOnSuspendedWorkflow);

                            try
                            {
                                // add work items to the current batch if exists
                                if (pendingWork != null)
                                {
                                    IWorkBatch batch = (IWorkBatch)this.rootActivity.GetValue(WorkflowExecutor.TransientBatchProperty);
                                    batch.Add(pendingWork, workItem);
                                }

                                stateChangedSincePersistence = true;
                                qService.EnqueueEvent(queueName, item);
                            }
                            finally
                            {
                                if (this.IsIdle)
                                    messageDeliveryLockGuard.Pulse();
                            }
                        }
                    }
                }
            }
        }
 internal void Add(IPendingWork work, long orderId, object workItem)
 {
     SortedList<long, object> list = null;
     if (!this.Items.TryGetValue(work, out list))
     {
         list = new SortedList<long, object>();
         this.Items.Add(work, list);
     }
     list.Add(orderId, workItem);
     WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "pending work hc {0} added workItem hc {1}", new object[] { work.GetHashCode(), workItem.GetHashCode() });
 }
Example #27
0
        internal void EnqueueItem(IComparable queueName, object item, IPendingWork pendingWork, Object workItem)
        {
            using (ScheduleWork work = new ScheduleWork(this))
            {
                bool lockedScheduler = false;
                if (!ServiceEnvironment.IsInServiceThread(InstanceId))
                    lockedScheduler = _schedulerLock.TryEnter();
                try
                {
                    // take the msg delivery lock to make sure the instance
                    // doesn't persist while the message is being delivered.
                    using (this.MessageDeliveryLock.Enter())
                    {
                        if (!this.IsInstanceValid)
                            throw new InvalidOperationException(ExecutionStringManager.WorkflowNotValid);

                        if (lockedScheduler || ServiceEnvironment.IsInServiceThread(InstanceId))
                        {
                            using (new ServiceEnvironment(this.RootActivity))
                            {
                                qService.EnqueueEvent(queueName, item);
                            }
                        }
                        else
                        {
                            if (qService.SafeEnqueueEvent(queueName, item))
                            {
                                ScheduleWork.NeedsService = true;
                            }
                        }

                        // add work items to the current batch if exists
                        if (pendingWork != null)
                        {
                            IWorkBatch batch = _resourceManager.BatchCollection.GetBatch(this.rootActivity);
                            batch.Add(pendingWork, workItem);
                        }

                        stateChangedSincePersistence = true;
                    }
                }
                finally
                {
                    if (lockedScheduler)
                        _schedulerLock.Exit();
                }
            }
        }
            public object[] PrepareEventArgsArray(object sender, ExternalDataEventArgs eventArgs, out object workItem, out IPendingWork workHandler)
            {
                // remove the batch items from the event args, only the runtime needs this data
                // and it is not necessarily serializable.
                workItem              = eventArgs.WorkItem;
                eventArgs.WorkItem    = null;
                workHandler           = eventArgs.WorkHandler;
                eventArgs.WorkHandler = null;

                return(new object[] { sender, eventArgs });
            }
Example #29
0
 public ExternalDataEventArgs(Guid instanceId, IPendingWork workHandler, object workItem)
     : this(instanceId, workHandler, workItem, false)
 {
 }
Example #30
0
 internal long GetNextWorkItemOrderId(IPendingWork pendingWork)
 {
     return(Interlocked.Increment(ref this._workItemOrderId));
 }
 public ExternalDataEventArgs(Guid instanceId, IPendingWork workHandler, object workItem)
     : this(instanceId, workHandler, workItem, false)
 {
 }
 void IWorkBatch.Add(IPendingWork work, object workItem)
 {
     if (this._pendingWorkCollection == null)
     {
         throw new ObjectDisposedException("WorkBatch");
     }
     lock (this.mutex)
     {
         this._pendingWorkCollection.Add(work, this._collection.GetNextWorkItemOrderId(work), workItem);
     }
 }
Example #33
0
 public object[] PrepareEventArgsArray(object sender, ExternalDataEventArgs eventArgs, out object workItem, out IPendingWork workHandler)
 {
     workItem              = eventArgs.WorkItem;
     eventArgs.WorkItem    = null;
     workHandler           = eventArgs.WorkHandler;
     eventArgs.WorkHandler = null;
     return(new object[] { sender, eventArgs });
 }
Example #34
0
        public void DeliverMessage(ExternalDataEventArgs eventArgs, IComparable queueName, object message, object workItem, IPendingWork workHandler)
        {
            if (eventArgs == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("eventArgs");
            }
            if (queueName == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("queueName");
            }

            using (ExternalDataExchangeClient desClient = new ExternalDataExchangeClient(WorkflowRuntimeEndpoint.netNamedPipeContextBinding,
                                                                                         new EndpointAddress(this.baseUri)))
            {
                using (OperationContextScope scope = new OperationContextScope((IContextChannel)desClient.InnerChannel))
                {
                    IContextManager contextManager = desClient.InnerChannel.GetProperty <IContextManager>();
                    Fx.Assert(contextManager != null, "IContextManager must not be null.");
                    if (contextManager != null)
                    {
                        IDictionary <string, string> context = new Dictionary <string, string>();
                        context["instanceId"] = eventArgs.InstanceId.ToString();
                        contextManager.SetContext(context);
                    }

                    desClient.RaiseEvent(eventArgs, queueName, message);
                }
            }
        }
 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;
                 }
             }
         }
     }
 }
 public void EnqueueItem(IComparable queueName, object item, IPendingWork pendingWork, object workItem)
 {
     this.WorkflowInstance.EnqueueItemOnIdle(queueName, item, pendingWork, workItem);
 }
 internal void EnqueueItem(IComparable queueName, object item, IPendingWork pendingWork, object workItem)
 {
     using (new ScheduleWork(this))
     {
         bool flag = false;
         if (!ServiceEnvironment.IsInServiceThread(this.InstanceId))
         {
             flag = this._schedulerLock.TryEnter();
         }
         try
         {
             using (this.MessageDeliveryLock.Enter())
             {
                 if (!this.IsInstanceValid)
                 {
                     throw new InvalidOperationException(ExecutionStringManager.WorkflowNotValid);
                 }
                 if (flag || ServiceEnvironment.IsInServiceThread(this.InstanceId))
                 {
                     using (new ServiceEnvironment(this.RootActivity))
                     {
                         this.qService.EnqueueEvent(queueName, item);
                         goto Label_008E;
                     }
                 }
                 if (this.qService.SafeEnqueueEvent(queueName, item))
                 {
                     ScheduleWork.NeedsService = true;
                 }
             Label_008E:
                 if (pendingWork != null)
                 {
                     this._resourceManager.BatchCollection.GetBatch(this.rootActivity).Add(pendingWork, workItem);
                 }
                 this.stateChangedSincePersistence = true;
             }
         }
         finally
         {
             if (flag)
             {
                 this._schedulerLock.Exit();
             }
         }
     }
 }
Example #38
0
 public void EnqueueItem(IComparable queueName, object item, IPendingWork pendingWork, object workItem)
 {
     this.WorkflowInstance.EnqueueItemOnIdle(queueName, item, pendingWork, workItem);
 }
Example #39
0
 public void EnqueueItemOnIdle(IComparable queueName, object item, IPendingWork pendingWork, object workItem)
 {
 }