public object StartOperation(bool canCreateInstance) { using (StartOperationScope scope = new StartOperationScope(this)) { if (this.markedForCompletion) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new InstanceNotFoundException(this.InstanceId)); } if (this.instance == null) { if (!TryActivateInstance(canCreateInstance)) { using (PersistenceScope persistenceScope = new PersistenceScope( this.saveStateInOperationTransaction, this.clonedTransaction)) { if (this.lockingProvider != null) { this.instance = this.lockingProvider.Load(this.operationTimeout, true); } else { this.instance = this.provider.Load(this.operationTimeout); } if (DiagnosticUtility.ShouldTraceInformation) { string traceText = SR2.GetString(SR2.ServiceDurableInstanceLoadedDetails, this.InstanceId, (this.lockingProvider != null) ? "True" : "False"); TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.ServiceDurableInstanceLoaded, SR.GetString(SR.TraceCodeServiceDurableInstanceLoaded), new StringTraceRecord("DurableInstanceDetail", traceText), this, null); } } this.existsInPersistence = true; } } scope.Complete(); } Fx.Assert( this.instance != null, "Instance should definitely be non-null here or we should have thrown an exception."); return(this.instance); }
public StartOperationAsyncResult(ServiceDurableInstance durableInstance, bool canCreateInstance, AsyncCallback callback, object state) : base(callback, state) { this.durableInstance = durableInstance; bool completeSelf = false; IAsyncResult result = null; this.operationContext = OperationContext.Current; scope = new StartOperationScope(this.durableInstance); bool success = false; try { if (this.durableInstance.instance == null) { if (this.durableInstance.TryActivateInstance(canCreateInstance)) { completeSelf = true; } else { using (PersistenceScope persistenceScope = new PersistenceScope( this.durableInstance.saveStateInOperationTransaction, this.durableInstance.clonedTransaction)) { if (this.durableInstance.lockingProvider != null) { result = this.durableInstance.lockingProvider.BeginLoad(this.durableInstance.operationTimeout, true, loadCallback, this); } else { result = this.durableInstance.provider.BeginLoad(this.durableInstance.operationTimeout, loadCallback, this); } } this.durableInstance.existsInPersistence = true; if (result.CompletedSynchronously) { completeSelf = true; } } } else { completeSelf = true; } success = true; } finally { if (!success) { scope.Dispose(); } } if (completeSelf) { try { if (result != null) { this.durableInstance.instance = this.durableInstance.provider.EndLoad(result); } Fx.Assert(this.durableInstance.instance != null, "The instance should always be set here."); Complete(true); scope.Complete(); } finally { scope.Dispose(); } } }
public object StartOperation(bool canCreateInstance) { using (StartOperationScope scope = new StartOperationScope(this)) { if (this.markedForCompletion) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError( new InstanceNotFoundException(this.InstanceId)); } if (this.instance == null) { if (!TryActivateInstance(canCreateInstance)) { using (PersistenceScope persistenceScope = new PersistenceScope( this.saveStateInOperationTransaction, this.clonedTransaction)) { if (this.lockingProvider != null) { this.instance = this.lockingProvider.Load(this.operationTimeout, true); } else { this.instance = this.provider.Load(this.operationTimeout); } if (DiagnosticUtility.ShouldTraceInformation) { string traceText = SR2.GetString(SR2.ServiceDurableInstanceLoadedDetails, this.InstanceId, (this.lockingProvider != null) ? "True" : "False"); TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.ServiceDurableInstanceLoaded, SR.GetString(SR.TraceCodeServiceDurableInstanceLoaded), new StringTraceRecord("DurableInstanceDetail", traceText), this, null); } } this.existsInPersistence = true; } } scope.Complete(); } Fx.Assert( this.instance != null, "Instance should definitely be non-null here or we should have thrown an exception."); return this.instance; }
public StartOperationAsyncResult(ServiceDurableInstance durableInstance, bool canCreateInstance, AsyncCallback callback, object state) : base(callback, state) { this.durableInstance = durableInstance; bool completeSelf = false; IAsyncResult result = null; this.operationContext = OperationContext.Current; scope = new StartOperationScope(this.durableInstance); bool success = false; try { if (this.durableInstance.instance == null) { if (this.durableInstance.TryActivateInstance(canCreateInstance)) { completeSelf = true; } else { using (PersistenceScope persistenceScope = new PersistenceScope( this.durableInstance.saveStateInOperationTransaction, this.durableInstance.clonedTransaction)) { if (this.durableInstance.lockingProvider != null) { result = this.durableInstance.lockingProvider.BeginLoad(this.durableInstance.operationTimeout, true, loadCallback, this); } else { result = this.durableInstance.provider.BeginLoad(this.durableInstance.operationTimeout, loadCallback, this); } } this.durableInstance.existsInPersistence = true; if (result.CompletedSynchronously) { completeSelf = true; } } } else { completeSelf = true; } success = true; } finally { if (!success) { scope.Dispose(); } } if (completeSelf) { try { if (result != null) { this.durableInstance.instance = this.durableInstance.provider.EndLoad(result); } Fx.Assert(this.durableInstance.instance != null, "The instance should always be set here."); Complete(true); scope.Complete(); } finally { scope.Dispose(); } } }