public bool ObserveCancelation() { if (_cancelledState == CancelledState.NotCancelled) { return(false); } bool isPrerequested = _cancelledState == CancelledState.CancellationPreRequested; if (_cancelledState >= CancelledState.CancellationPreRequested) { _cancelledState = CancelledState.CancellationObserved; // Do not reset awaitable if we were not awaiting in the first place if (!isPrerequested) { Reset(); } _cancellationToken.ThrowIfCancellationRequested(); return(true); } return(false); }
public PipeAwaitable(bool completed) { _cancellationToken = default(CancellationToken); _cancellationTokenRegistration = default(CancellationTokenRegistration); _cancelledState = CancelledState.NotCancelled; _state = completed ? _awaitableIsCompleted : _awaitableIsNotCompleted; }
public Action Cancel() { var action = Complete(); _cancelledState = action == null ? CancelledState.CancellationPreRequested : CancelledState.CancellationRequested; return(action); }
private Policy() { _cancelledState = new CancelledState(this); _closedState = new ClosedState(this); _openState = new OpenState(this); _unwrittenState = new UnwrittenState(this); _voidState = new VoidState(this); State = _unwrittenState; }
public bool ObserveCancelation() { if (_cancelledState == CancelledState.CancellationRequested) { _cancelledState = CancelledState.CancellationObserved; return(true); } return(false); }
public void Reset() { if (_state == _awaitableIsCompleted && _cancelledState != CancelledState.CancellationRequested) { _state = _awaitableIsNotCompleted; } // Change the state from observed -> not cancelled. We only want to reset the cancelled state if it was observed if (_cancelledState == CancelledState.CancellationObserved) { _cancelledState = CancelledState.NotCancelled; } }
public void Reset() { if (ReferenceEquals(_state, _awaitableIsCompleted) && _cancelledState < CancelledState.CancellationPreRequested) { _state = _awaitableIsNotCompleted; } // Change the state from observed -> not cancelled. // We only want to reset the cancelled state if it was observed if (_cancelledState == CancelledState.CancellationObserved) { _cancelledState = CancelledState.NotCancelled; } }
public void State_pattern_test() { string TEST_POLICY_NUMBER = "007"; var testPolicy = new Policy(TEST_POLICY_NUMBER); var testCancelledState = new CancelledState(testPolicy); var testClosedState = new ClosedState(testPolicy); var testOpenState = new OpenState(testPolicy); var testUnwrittenState = new UnwrittenState(testPolicy); var testVoidState = new VoidState(testPolicy); //closing open policy testOpenState.Close(DateTime.Now); Assert.IsInstanceOfType(testPolicy.State, typeof(ClosedState)); }
public PipeAwaitable(bool completed) { _cancelledState = CancelledState.NotCancelled; _state = completed ? _awaitableIsCompleted : _awaitableIsNotCompleted; }
public Action Cancel() { _cancelledState = CancelledState.CancellationRequested; return(Complete()); }