public WorkflowInstance GetWorkflowInstance(bool canCreateInstance)
        {
            if (this.workflowInstance == null)
            {
                lock (thisLock)
                {
                    if (shouldCreateNew)
                    {
                        if (canCreateInstance)
                        {
                            this.workflowInstance = this.workflowDefinition.CreateWorkflow(this.InstanceId);
                            shouldCreateNew       = false;

                            if (DiagnosticUtility.ShouldTraceInformation)
                            {
                                string traceText = SR.GetString(SR.TraceCodeWorkflowDurableInstanceActivated, InstanceId);
                                TraceUtility.TraceEvent(TraceEventType.Information,
                                                        TraceCode.WorkflowDurableInstanceActivated, traceText,
                                                        new StringTraceRecord("DurableInstanceDetail", traceText),
                                                        this, null);
                            }
                            using (new WorkflowDispatchContext(true, true))
                            {
                                this.workflowInstance.Start();
                            }
                        }
                        else
                        {
                            //Make sure we clean up this InstanceContext;
                            DurableErrorHandler.CleanUpInstanceContextAtOperationCompletion();
                            //Inform InstanceLifeTimeManager to clean up record for InstanceId;
                            if (this.instanceContextProvider.InstanceLifeTimeManager != null)
                            {
                                this.instanceContextProvider.InstanceLifeTimeManager.CleanUp(this.InstanceId);
                            }
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FaultException(new DurableDispatcherAddressingFault()));
                        }
                    }
                    else
                    {
                        this.workflowInstance = this.workflowDefinition.WorkflowRuntime.GetWorkflow(InstanceId);

                        if (DiagnosticUtility.ShouldTraceInformation)
                        {
                            string traceText = SR.GetString(SR.TraceCodeWorkflowDurableInstanceLoaded, InstanceId);
                            TraceUtility.TraceEvent(TraceEventType.Information,
                                                    TraceCode.WorkflowDurableInstanceLoaded, traceText,
                                                    new StringTraceRecord("DurableInstanceDetail", traceText),
                                                    this, null);
                        }
                    }
                }
            }
            return(workflowInstance);
        }
Esempio n. 2
0
        bool TryActivateInstance(bool canCreateInstance)
        {
            if (this.newServiceType != null && !this.existsInPersistence)
            {
                if (canCreateInstance)
                {
                    this.instance = Activator.CreateInstance(this.newServiceType);
                    return(true);
                }
                else
                {
                    DurableErrorHandler.CleanUpInstanceContextAtOperationCompletion();
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FaultException(new DurableDispatcherAddressingFault()));
                }
            }

            return(false);
        }