Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public PipeAwaitable(bool completed)
        {
            _cancellationToken             = default(CancellationToken);
            _cancellationTokenRegistration = default(CancellationTokenRegistration);

            _cancelledState = CancelledState.NotCancelled;
            _state          = completed ? _awaitableIsCompleted : _awaitableIsNotCompleted;
        }
Exemplo n.º 3
0
        public Action Cancel()
        {
            var action = Complete();

            _cancelledState = action == null ?
                              CancelledState.CancellationPreRequested :
                              CancelledState.CancellationRequested;
            return(action);
        }
Exemplo n.º 4
0
 private Policy()
 {
     _cancelledState = new CancelledState(this);
     _closedState    = new ClosedState(this);
     _openState      = new OpenState(this);
     _unwrittenState = new UnwrittenState(this);
     _voidState      = new VoidState(this);
     State           = _unwrittenState;
 }
Exemplo n.º 5
0
 public bool ObserveCancelation()
 {
     if (_cancelledState == CancelledState.CancellationRequested)
     {
         _cancelledState = CancelledState.CancellationObserved;
         return(true);
     }
     return(false);
 }
Exemplo n.º 6
0
        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;
            }
        }
Exemplo n.º 7
0
        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;
            }
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
0
 public PipeAwaitable(bool completed)
 {
     _cancelledState = CancelledState.NotCancelled;
     _state          = completed ? _awaitableIsCompleted : _awaitableIsNotCompleted;
 }
Exemplo n.º 10
0
 public Action Cancel()
 {
     _cancelledState = CancelledState.CancellationRequested;
     return(Complete());
 }