private void DeleteSubscription(ActivityExecutionContext context)
        {
            if (this.queueName == null)
            {
                return;
            }

            WorkflowQueuingService queueSvcs = context.GetService <WorkflowQueuingService>();

            if (queueCreator)
            {
                queueSvcs.DeleteWorkflowQueue(this.queueName);
            }

            if (this.eventHandler != null)
            {
                return;
            }

            WorkflowSubscriptionService subscriptionService = context.GetService <WorkflowSubscriptionService>();

            if (subscriptionService != null)
            {
                subscriptionService.DeleteSubscription(this.subscriptionId);
            }

            WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "CorrelationTokenInvalidatedHandler subscription deleted SubId {0} QueueId {1}", this.subscriptionId, this.queueName);
        }
        private void CreateSubscription(Guid instanceId, ActivityExecutionContext context, ICollection <CorrelationProperty> correlationValues)
        {
            WorkflowQueuingService queueSvcs = context.GetService <WorkflowQueuingService>();
            EventQueueName         queueId   = new EventQueueName(this.interfaceType, this.followerOperation, correlationValues);

            WorkflowQueue workflowQueue = null;

            if (!queueSvcs.Exists(queueId))
            {
                WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "CorrelationTokenInvalidatedHandler: creating q {0} ", queueId.GetHashCode());
                workflowQueue = queueSvcs.CreateWorkflowQueue(queueId, true);
                queueCreator  = true;
            }
            else
            {
                workflowQueue = queueSvcs.GetWorkflowQueue(queueId);
            }

            if (this.eventHandler != null)
            {
                workflowQueue.RegisterForQueueItemAvailable(this.eventHandler);
            }

            WorkflowSubscriptionService subscriptionService = (WorkflowSubscriptionService)context.GetService(typeof(WorkflowSubscriptionService));

            MessageEventSubscription subscription = new MessageEventSubscription(queueId, instanceId);

            this.queueName             = queueId;
            this.subscriptionId        = subscription.SubscriptionId;
            subscription.InterfaceType = this.interfaceType;
            subscription.MethodName    = this.followerOperation;

            this.interfaceType     = null;
            this.followerOperation = null;

            if (correlationValues != null)
            {
                foreach (CorrelationProperty property in correlationValues)
                {
                    subscription.CorrelationProperties.Add(property);
                }
            }

            if (this.eventHandler != null)
            {
                return;
            }

            if (subscriptionService == null)
            {
                return;
            }
            subscriptionService.CreateSubscription(subscription);
        }
 private void DeleteSubscription(ActivityExecutionContext context)
 {
     if (this.queueName != null)
     {
         WorkflowQueuingService service = context.GetService <WorkflowQueuingService>();
         if (this.queueCreator)
         {
             service.DeleteWorkflowQueue(this.queueName);
         }
         if (this.eventHandler == null)
         {
             WorkflowSubscriptionService service2 = context.GetService <WorkflowSubscriptionService>();
             if (service2 != null)
             {
                 service2.DeleteSubscription(this.subscriptionId);
             }
             WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "CorrelationTokenInvalidatedHandler subscription deleted SubId {0} QueueId {1}", new object[] { this.subscriptionId, this.queueName });
         }
     }
 }