public ServiceOperationAsyncResult(IOperationInvoker innerInvoker, WorkflowServiceInstance durableInstance, object[] inputs, OperationContext operationContext, Transaction currentTransaction, IInvokeReceivedNotification notification, AsyncCallback callback, object state) : base(callback, state)
 {
     this.durableInstance    = durableInstance;
     this.operationContext   = operationContext;
     this.inputs             = inputs;
     this.innerInvoker       = innerInvoker;
     this.currentTransaction = currentTransaction;
     this.notification       = notification;
     if (innerInvoker == null)
     {
         throw Fx.AssertAndThrow("Cannot reach this path without innerInvoker");
     }
     if (this.innerInvoker.IsSynchronous)
     {
         TransactionScope scope = Fx.CreateTransactionScope(this.currentTransaction);
         try
         {
             using (new OperationContextScopeHelper(this.operationContext))
             {
                 IManualConcurrencyOperationInvoker invoker = this.innerInvoker as IManualConcurrencyOperationInvoker;
                 if (invoker != null)
                 {
                     this.returnValue = invoker.Invoke(this.durableInstance, this.inputs, this.notification, out this.outputs);
                 }
                 else
                 {
                     this.returnValue = this.innerInvoker.Invoke(this.durableInstance, this.inputs, out this.outputs);
                 }
             }
         }
         finally
         {
             Fx.CompleteTransactionScope(ref scope);
         }
         base.Complete(true);
     }
     else
     {
         IAsyncResult result;
         using (base.PrepareTransactionalCall(this.currentTransaction))
         {
             using (new OperationContextScopeHelper(this.operationContext))
             {
                 IManualConcurrencyOperationInvoker invoker2 = this.innerInvoker as IManualConcurrencyOperationInvoker;
                 if (invoker2 != null)
                 {
                     result = invoker2.InvokeBegin(this.durableInstance, this.inputs, this.notification, base.PrepareAsyncCompletion(handleEndInvoke), this);
                 }
                 else
                 {
                     result = this.innerInvoker.InvokeBegin(this.durableInstance, this.inputs, base.PrepareAsyncCompletion(handleEndInvoke), this);
                 }
             }
         }
         if (base.SyncContinue(result))
         {
             base.Complete(true);
         }
     }
 }
Example #2
0
        protected override void InitializeRuntime()
        {
            if (base.Description != null)
            {
                FixupEndpoints();
                this.SetScopeName();
                if (this.DurableInstancingOptions.ScopeName == null)
                {
                    this.DurableInstancingOptions.ScopeName = XNamespace.Get(this.Description.Namespace).GetName(this.Description.Name);
                }
            }

            base.InitializeRuntime();

            this.WorkflowServiceHostPerformanceCounters.InitializePerformanceCounters();

            this.ServiceName = XNamespace.Get(this.Description.Namespace).GetName(this.Description.Name);

            // add a host-wide SendChannelCache (with default settings) if one doesn't exist
            this.workflowExtensions.EnsureChannelCache();

            // add a host-wide (free-threaded) CorrelationExtension based on our ServiceName
            this.WorkflowExtensions.Add(new CorrelationExtension(this.DurableInstancingOptions.ScopeName));

            this.WorkflowExtensions.MakeReadOnly();

            // now calculate if IsLoadTransactionRequired
            this.IsLoadTransactionRequired = WorkflowServiceInstance.IsLoadTransactionRequired(this);

            if (this.serviceDefinition != null)
            {
                ValidateBufferedReceiveProperty();
                this.serviceDefinition.ResetServiceDescription();
            }
        }
Example #3
0
 public static IAsyncResult BeginProcessRequest(WorkflowServiceInstance workflowInstance, OperationContext operationContext, string operationName,
                                                object[] inputs, bool performanceCountersEnabled, bool propagateActivity, Transaction currentTransaction, IInvokeReceivedNotification notification,
                                                WorkflowOperationBehavior behavior, ServiceEndpoint endpoint, TimeSpan timeout, AsyncCallback callback, object state)
 {
     Fx.Assert(inputs != null, "Null inputs");
     return(new WorkflowOperationContext(inputs, operationContext, operationName, performanceCountersEnabled,
                                         propagateActivity, currentTransaction, workflowInstance, notification, behavior, endpoint, timeout, callback, state));
 }
            protected override IAsyncResult OnBeginServiceOperation(WorkflowServiceInstance workflowInstance, OperationContext operationContext,
                                                                    object[] inputs, Transaction currentTransaction, IInvokeReceivedNotification notification, TimeSpan timeout, AsyncCallback callback, object state)
            {
                Fx.Assert(workflowInstance != null, "caller must verify");
                Fx.Assert(inputs != null, "caller must verify");

                return(WorkflowOperationContext.BeginProcessRequest(workflowInstance, operationContext, this.OperationName, inputs,
                                                                    this.performanceCountersEnabled, this.propagateActivity, currentTransaction, notification, this.behavior, this.endpoint, timeout, callback, state));
            }
Example #5
0
        public TransactionContext(WorkflowServiceInstance durableInstance, Transaction currentTransaction)
        {
            Fx.Assert(durableInstance != null, "Null DurableInstance passed to TransactionContext.");
            Fx.Assert(currentTransaction != null, "Null Transaction passed to TransactionContext.");

            this.currentTransaction = currentTransaction.Clone();
            this.durableInstance    = durableInstance;
            this.currentTransaction.EnlistVolatile(this, EnlistmentOptions.EnlistDuringPrepareRequired);
        }
            protected override object OnEndServiceOperation(WorkflowServiceInstance durableInstance, out object[] outputs, IAsyncResult result)
            {
                // InternalSendMessage always redirects the replyMessage into the returnValue
                object returnValue = WorkflowOperationContext.EndProcessRequest(result, out outputs);

                //we will just assert that outputs is always an empty array
                Fx.Assert(this.isHostingEndpoint || outputs == null || outputs.Length == 0, "Workflow returned a non-empty out-arg");

                return(returnValue);
            }
        private WorkflowOperationContext(object[] inputs, System.ServiceModel.OperationContext operationContext, string operationName, bool performanceCountersEnabled, bool propagateActivity, Transaction currentTransaction, WorkflowServiceInstance workflowInstance, IInvokeReceivedNotification notification, WorkflowOperationBehavior behavior, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
        {
            this.inputs                     = inputs;
            this.operationName              = operationName;
            this.OperationContext           = operationContext;
            this.CurrentTransaction         = currentTransaction;
            this.performanceCountersEnabled = performanceCountersEnabled;
            this.propagateActivity          = propagateActivity;
            this.timeoutHelper              = new TimeoutHelper(timeout);
            this.workflowInstance           = workflowInstance;
            this.thisLock                   = new object();
            this.notification               = notification;
            base.OnCompleting               = onCompleting;
            this.bookmark                   = behavior.OnResolveBookmark(this, out this.bookmarkScope, out this.bookmarkValue);
            bool flag = false;

            try
            {
                if (TraceUtility.MessageFlowTracingOnly)
                {
                    this.e2eActivityId         = TraceUtility.GetReceivedActivityId(this.OperationContext);
                    DiagnosticTrace.ActivityId = this.e2eActivityId;
                }
                if (this.workflowInstance.BufferedReceiveManager != null)
                {
                    ReceiveContext.TryGet(this.OperationContext.IncomingMessageProperties, out this.receiveContext);
                    this.OperationContext.IncomingMessageProperties.Remove(ReceiveContext.Name);
                }
                flag = this.ProcessRequest();
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                base.OnCompleting(this, exception);
                throw;
            }
            if (flag)
            {
                base.Complete(true);
            }
        }
 internal PersistenceContext(PersistenceProviderDirectory directory, InstanceStore store, InstanceHandle handle, Guid instanceId, IEnumerable <InstanceKey> associatedKeys, bool newInstance, bool locked, InstanceView view) : this(directory, instanceId, null, associatedKeys)
 {
     this.store         = store;
     this.handle        = handle;
     this.IsInitialized = !newInstance;
     this.IsLocked      = locked;
     if (view != null)
     {
         this.ReadSuspendedInfo(view);
     }
     if (this.IsInitialized || this.IsLocked)
     {
         this.RationalizeSavedKeys(false);
     }
     if (this.IsInitialized)
     {
         this.workflowInstance = this.directory.InitializeInstance(this.InstanceId, this, view.InstanceData, null);
     }
 }
 public WorkflowServiceInstance GetInstance(WorkflowGetInstanceContext parameters)
 {
     if ((this.workflowInstance == null) && (parameters != null))
     {
         lock (base.ThisLock)
         {
             base.ThrowIfDisposedOrNotOpen();
             if (this.workflowInstance == null)
             {
                 try
                 {
                     WorkflowServiceInstance instance;
                     if (parameters.WorkflowHostingEndpoint != null)
                     {
                         WorkflowHostingResponseContext responseContext = new WorkflowHostingResponseContext();
                         WorkflowCreationContext        creationContext = parameters.WorkflowHostingEndpoint.OnGetCreationContext(parameters.Inputs, parameters.OperationContext, this.InstanceId, responseContext);
                         if (creationContext == null)
                         {
                             throw System.ServiceModel.Activities.FxTrace.Exception.AsError(WorkflowHostingEndpoint.CreateDispatchFaultException());
                         }
                         instance = this.directory.InitializeInstance(this.InstanceId, this, null, creationContext);
                         parameters.WorkflowCreationContext        = creationContext;
                         parameters.WorkflowHostingResponseContext = responseContext;
                     }
                     else
                     {
                         instance = this.directory.InitializeInstance(this.InstanceId, this, null, null);
                     }
                     this.workflowInstance = instance;
                 }
                 finally
                 {
                     if (this.workflowInstance == null)
                     {
                         base.Fault();
                     }
                 }
             }
         }
     }
     return(this.workflowInstance);
 }
Example #10
0
 protected override void InitializeRuntime()
 {
     if (base.Description != null)
     {
         this.FixupEndpoints();
         if (this.DurableInstancingOptions.ScopeName == null)
         {
             this.DurableInstancingOptions.ScopeName = XNamespace.Get(base.Description.Namespace).GetName(base.Description.Name);
         }
     }
     base.InitializeRuntime();
     this.ServiceName = XNamespace.Get(base.Description.Namespace).GetName(base.Description.Name);
     this.workflowExtensions.EnsureChannelCache();
     this.WorkflowExtensions.Add(new CorrelationExtension(this.DurableInstancingOptions.ScopeName));
     this.WorkflowExtensions.MakeReadOnly();
     this.IsLoadTransactionRequired = WorkflowServiceInstance.IsLoadTransactionRequired(this);
     if (this.serviceDefinition != null)
     {
         this.ValidateBufferedReceiveProperty();
         this.serviceDefinition.ResetServiceDescription();
     }
 }
 protected virtual object OnEndServiceOperation(WorkflowServiceInstance durableInstance, out object[] outputs, IAsyncResult result)
 {
     return(ServiceOperationAsyncResult.End(out outputs, result));
 }
 protected virtual IAsyncResult OnBeginServiceOperation(WorkflowServiceInstance durableInstance, OperationContext operationContext, object[] inputs, Transaction currentTransaction, IInvokeReceivedNotification notification, TimeSpan timeout, AsyncCallback callback, object state)
 {
     return(new ServiceOperationAsyncResult(this.innerInvoker, durableInstance, inputs, operationContext, currentTransaction, notification, callback, state));
 }
Example #13
0
 public TransactionContext(WorkflowServiceInstance durableInstance, Transaction currentTransaction)
 {
     this.currentTransaction = currentTransaction.Clone();
     this.durableInstance    = durableInstance;
     this.currentTransaction.EnlistVolatile(this, EnlistmentOptions.EnlistDuringPrepareRequired);
 }
Example #14
0
        WorkflowOperationContext(object[] inputs, OperationContext operationContext, string operationName,
                                 bool performanceCountersEnabled, bool propagateActivity, Transaction currentTransaction,
                                 WorkflowServiceInstance workflowInstance, IInvokeReceivedNotification notification, WorkflowOperationBehavior behavior, ServiceEndpoint endpoint,
                                 TimeSpan timeout, AsyncCallback callback, object state)
            : base(callback, state)
        {
            this.inputs                     = inputs;
            this.operationName              = operationName;
            this.OperationContext           = operationContext;
            this.ServiceEndpoint            = endpoint;
            this.CurrentTransaction         = currentTransaction;
            this.performanceCountersEnabled = performanceCountersEnabled;
            this.propagateActivity          = propagateActivity;
            this.timeoutHelper              = new TimeoutHelper(timeout);
            this.workflowInstance           = workflowInstance;
            this.thisLock                   = new object();
            this.notification               = notification;
            this.OnCompleting               = onCompleting;

            // Resolve bookmark
            Fx.Assert(behavior != null, "behavior must not be null!");
            this.bookmark = behavior.OnResolveBookmark(this, out this.bookmarkScope, out this.bookmarkValue);
            Fx.Assert(this.bookmark != null, "bookmark must not be null!");

            bool completeSelf = false;

            try
            {
                // set activity ID on the executing thread (
                if (TraceUtility.MessageFlowTracingOnly)
                {
                    this.e2eActivityId             = TraceUtility.GetReceivedActivityId(this.OperationContext);
                    DiagnosticTraceBase.ActivityId = this.e2eActivityId;
                }

                if (Fx.Trace.IsEtwProviderEnabled)
                {
                    this.eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(this.OperationContext.IncomingMessage);
                }

                // Take ownership of the ReceiveContext when buffering is enabled by removing the property
                if (this.workflowInstance.BufferedReceiveManager != null)
                {
                    if (!ReceiveContext.TryGet(this.OperationContext.IncomingMessageProperties, out this.receiveContext))
                    {
                        Fx.Assert("ReceiveContext expected when BufferedReceives are enabled");
                    }

                    this.OperationContext.IncomingMessageProperties.Remove(ReceiveContext.Name);
                }

                completeSelf = ProcessRequest();
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                // Failing synchronously is one case where AsyncResult won't handle calling OnCompleting
                OnCompleting(this, e);
                throw;
            }

            if (completeSelf)
            {
                base.Complete(true);
            }
        }
 public WorkflowServiceInstance InitializeInstance(Guid instanceId, PersistenceContext context, IDictionary <XName, InstanceValue> instance, WorkflowCreationContext creationContext)
 {
     return(WorkflowServiceInstance.InitializeInstance(context, instanceId, this.workflowDefinition, instance, creationContext, WorkflowSynchronizationContext.Instance, this.serviceHost));
 }
Example #16
0
 protected override object OnEndServiceOperation(WorkflowServiceInstance durableInstance, out object[] outputs, IAsyncResult result)
 {
     return(WorkflowOperationContext.EndProcessRequest(result, out outputs));
 }