public static InstancePersistenceContext End(IAsyncResult result) { AcquireContextAsyncResult pThis = AsyncResult.End <AcquireContextAsyncResult>(result); Fx.Assert(pThis.executionContext != null, "Somehow the execution context didn't get set."); return(pThis.executionContext); }
static void OnHostTransaction(object state, TimeoutException timeoutException) { AcquireContextAsyncResult pThis = (AcquireContextAsyncResult)state; Exception exception = timeoutException; bool completeSelf = exception != null; if (!completeSelf) { try { if (pThis.DoAfterTransaction()) { completeSelf = true; } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } exception = e; completeSelf = true; } } if (completeSelf) { if (exception != null) { pThis.handle.FinishOperation(); } pThis.Complete(false, exception); } }
void OnRollBack(AcquireContextAsyncResult rollingBack) { bool rollbackNeeded = false; lock (ThisLock) { TooLateToEnlist = true; if (OperationPending && AcquirePending == null) { Fx.Assert(CurrentExecutionContext != null, "Should either be acquiring or executing in RollBack."); this.pendingRollback = rollingBack; // Don't prepare and roll back. this.pendingPreparingEnlistment = null; } else { rollbackNeeded = true; } } if (rollbackNeeded) { rollingBack.RollBack(); } }
void FinishOperation() { List <InstanceHandleReference> handlesPendingResolution = null; try { bool needNotification; PreparingEnlistment preparingEnlistment; AcquireContextAsyncResult pendingRollback; lock (ThisLock) { OperationPending = false; AcquirePending = null; CurrentExecutionContext = null; // This means we could have bound the handle, but didn't - clear the state here. if (this.inProgressBind != null && (Version == -1 || !IsValid)) { Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution); } else if (Version != -1 && !IsValid) { // This means the handle was successfully bound in the past. Need to remove it from the table of handles. Owner.Unbind(this); } needNotification = this.needFreedNotification; this.needFreedNotification = false; preparingEnlistment = this.pendingPreparingEnlistment; this.pendingPreparingEnlistment = null; pendingRollback = this.pendingRollback; this.pendingRollback = null; } try { if (needNotification) { Store.FreeInstanceHandle(this, ProviderObject); } } finally { if (pendingRollback != null) { Fx.Assert(preparingEnlistment == null, "Should not have both."); pendingRollback.RollBack(); } else if (preparingEnlistment != null) { preparingEnlistment.Prepared(); } } } finally { InstanceOwner.ResolveHandles(handlesPendingResolution); } }
private void FinishOperation() { List <InstanceHandleReference> handlesPendingResolution = null; try { bool needFreedNotification; PreparingEnlistment pendingPreparingEnlistment; AcquireContextAsyncResult pendingRollback; lock (this.ThisLock) { this.OperationPending = false; this.AcquirePending = null; this.CurrentExecutionContext = null; if ((this.inProgressBind != null) && ((this.Version == -1L) || !this.IsValid)) { this.Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution); } else if ((this.Version != -1L) && !this.IsValid) { this.Owner.Unbind(this); } needFreedNotification = this.needFreedNotification; this.needFreedNotification = false; pendingPreparingEnlistment = this.pendingPreparingEnlistment; this.pendingPreparingEnlistment = null; pendingRollback = this.pendingRollback; this.pendingRollback = null; } try { if (needFreedNotification) { this.Store.FreeInstanceHandle(this, this.ProviderObject); } } finally { if (pendingRollback != null) { pendingRollback.RollBack(); } else if (pendingPreparingEnlistment != null) { pendingPreparingEnlistment.Prepared(); } } } finally { InstanceOwner.ResolveHandles(handlesPendingResolution); } }
internal IAsyncResult BeginAcquireExecutionContext(Transaction hostTransaction, TimeSpan timeout, AsyncCallback callback, object state) { bool setOperationPending = false; IAsyncResult result = null; try { result = new AcquireContextAsyncResult(this, hostTransaction, timeout, out setOperationPending, callback, state); return(result); } finally { if (result == null && setOperationPending) { FinishOperation(); } } }
internal IAsyncResult BeginAcquireExecutionContext(Transaction hostTransaction, TimeSpan timeout, AsyncCallback callback, object state) { IAsyncResult result2; bool setOperationPending = false; IAsyncResult result = null; try { result = new AcquireContextAsyncResult(this, hostTransaction, timeout, out setOperationPending, callback, state); result2 = result; } finally { if ((result == null) && setOperationPending) { this.FinishOperation(); } } return result2; }
internal InstancePersistenceContext AcquireExecutionContext(Transaction hostTransaction, TimeSpan timeout) { bool setOperationPending = false; InstancePersistenceContext result = null; try { result = AcquireContextAsyncResult.End(new AcquireContextAsyncResult(this, hostTransaction, timeout, out setOperationPending)); Fx.AssertAndThrow(result != null, "Null result returned from AcquireContextAsyncResult (synchronous)."); return(result); } finally { if (result == null && setOperationPending) { FinishOperation(); } } }
bool DoAfterTransaction() { AcquireContextAsyncResult setWaitTo = null; try { lock (this.handle.ThisLock) { if (!this.handle.IsValid) { throw Fx.Exception.AsError(new OperationCanceledException(SRCore.HandleFreed)); } if (HostTransaction == null) { this.executionContext = new InstancePersistenceContext(this.handle, this.timeoutHelper.RemainingTime()); } else { this.executionContext = new InstancePersistenceContext(this.handle, HostTransaction); } this.handle.AcquirePending = null; this.handle.CurrentExecutionContext = this.executionContext; this.handle.TooLateToEnlist = false; } if (HostTransaction != null) { WaitForHostTransaction = new AsyncWaitHandle(EventResetMode.ManualReset); HostTransaction.EnlistVolatile(this, EnlistmentOptions.None); setWaitTo = this; } } finally { this.handle.CurrentTransactionalAsyncResult = setWaitTo; } return(true); }
private void OnRollBack(AcquireContextAsyncResult rollingBack) { bool flag = false; lock (this.ThisLock) { this.TooLateToEnlist = true; if (this.OperationPending && (this.AcquirePending == null)) { this.pendingRollback = rollingBack; this.pendingPreparingEnlistment = null; } else { flag = true; } } if (flag) { rollingBack.RollBack(); } }
private void OnRollBack(AcquireContextAsyncResult rollingBack) { bool flag = false; lock (this.ThisLock) { this.TooLateToEnlist = true; if (this.OperationPending && (this.AcquirePending == null)) { this.pendingRollback = rollingBack; this.pendingPreparingEnlistment = null; } else { flag = true; } } if (flag) { rollingBack.RollBack(); } }
private void FinishOperation() { List<InstanceHandleReference> handlesPendingResolution = null; try { bool needFreedNotification; PreparingEnlistment pendingPreparingEnlistment; AcquireContextAsyncResult pendingRollback; lock (this.ThisLock) { this.OperationPending = false; this.AcquirePending = null; this.CurrentExecutionContext = null; if ((this.inProgressBind != null) && ((this.Version == -1L) || !this.IsValid)) { this.Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution); } else if ((this.Version != -1L) && !this.IsValid) { this.Owner.Unbind(this); } needFreedNotification = this.needFreedNotification; this.needFreedNotification = false; pendingPreparingEnlistment = this.pendingPreparingEnlistment; this.pendingPreparingEnlistment = null; pendingRollback = this.pendingRollback; this.pendingRollback = null; } try { if (needFreedNotification) { this.Store.FreeInstanceHandle(this, this.ProviderObject); } } finally { if (pendingRollback != null) { pendingRollback.RollBack(); } else if (pendingPreparingEnlistment != null) { pendingPreparingEnlistment.Prepared(); } } } finally { InstanceOwner.ResolveHandles(handlesPendingResolution); } }
internal InstancePersistenceContext EndAcquireExecutionContext(IAsyncResult result) { return(AcquireContextAsyncResult.End(result)); }
void FinishOperation() { List<InstanceHandleReference> handlesPendingResolution = null; try { bool needNotification; PreparingEnlistment preparingEnlistment; AcquireContextAsyncResult pendingRollback; lock (ThisLock) { OperationPending = false; AcquirePending = null; CurrentExecutionContext = null; // This means we could have bound the handle, but didn't - clear the state here. if (this.inProgressBind != null && (Version == -1 || !IsValid)) { Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution); } else if (Version != -1 && !IsValid) { // This means the handle was successfully bound in the past. Need to remove it from the table of handles. Owner.Unbind(this); } needNotification = this.needFreedNotification; this.needFreedNotification = false; preparingEnlistment = this.pendingPreparingEnlistment; this.pendingPreparingEnlistment = null; pendingRollback = this.pendingRollback; this.pendingRollback = null; } try { if (needNotification) { Store.FreeInstanceHandle(this, ProviderObject); } } finally { if (pendingRollback != null) { Fx.Assert(preparingEnlistment == null, "Should not have both."); pendingRollback.RollBack(); } else if (preparingEnlistment != null) { preparingEnlistment.Prepared(); } } } finally { InstanceOwner.ResolveHandles(handlesPendingResolution); } }
void OnRollBack(AcquireContextAsyncResult rollingBack) { bool rollbackNeeded = false; lock (ThisLock) { TooLateToEnlist = true; if (OperationPending && AcquirePending == null) { Fx.Assert(CurrentExecutionContext != null, "Should either be acquiring or executing in RollBack."); this.pendingRollback = rollingBack; // Don't prepare and roll back. this.pendingPreparingEnlistment = null; } else { rollbackNeeded = true; } } if (rollbackNeeded) { rollingBack.RollBack(); } }