Пример #1
0
        void IEventActivity.Subscribe(ActivityExecutionContext parentContext, IActivityEventListener <QueueEventArgs> parentEventHandler)
        {
            if (parentContext == null)
            {
                throw new ArgumentNullException("parentContext");
            }
            if (parentEventHandler == null)
            {
                throw new ArgumentNullException("parentEventHandler");
            }

            this.IsInEventActivityMode = true;

            base.RaiseEvent(DelayActivity.InitializeTimeoutDurationEvent, this, EventArgs.Empty);
            TimeSpan timeSpan = this.TimeoutDuration;
            DateTime timeOut  = DateTime.UtcNow + timeSpan;

            WorkflowQueuingService qService = parentContext.GetService <WorkflowQueuingService>();

            IComparable            queueName = ((IEventActivity)this).QueueName;
            TimerEventSubscription timerSub  = new TimerEventSubscription((Guid)queueName, this.WorkflowInstanceId, timeOut);
            WorkflowQueue          queue     = qService.CreateWorkflowQueue(queueName, false);

            queue.RegisterForQueueItemAvailable(parentEventHandler, this.QualifiedName);
            this.SubscriptionID = timerSub.SubscriptionId;

            Activity root = this;

            while (root.Parent != null)
            {
                root = root.Parent;
            }

            TimerEventSubscriptionCollection timers = (TimerEventSubscriptionCollection)root.GetValue(TimerEventSubscriptionCollection.TimerCollectionProperty);

            Debug.Assert(timers != null, "TimerEventSubscriptionCollection on root activity should never be null, but it was");
            timers.Add(timerSub);
        }