コード例 #1
0
        public void IgnoreExceptionOnDispatcherWhenRemoving()
        {
            factoryMock.ExpectAndReturn("CreateApplicationWatcherMonitor", watcher);
            factoryMock.ExpectAndReturn("CreateApplicationWatcherMonitor", watcher);
            watcherMock.Expect("StartWatching");
            watcherMock.Expect("StopWatching");
            watcherMock.Expect("Dispose");
            watcherMock.Expect("StartWatching");
            watcherMock.Expect("StopWatching");
            watcherMock.Expect("Dispose");
            ISync canContinue = new Semaphore(0);
            ISync started     = new Semaphore(0);

            AddApplication();
            AddApplication(sampleDir2);
            IDeployEventDispatcher dispatcher = new ExceptionDispatcher(started, canContinue);

            location = new FileSystemDeployLocation(dispatcher, factory, deployPath, true);
            Assert.AreEqual(2, location.Applications.Count);
            Directory.Delete(sampleDir, true);
            started.Acquire();
            canContinue.Release();
            Assert.AreEqual(1, location.Applications.Count);
            Directory.Delete(sampleDir2, true);
            started.Acquire();
            canContinue.Release();
            Assert.AreEqual(0, location.Applications.Count);
        }
コード例 #2
0
        public void OnNext(OperationStatusChange change)
        {
            var onProgress = OnProgressChanged;

            switch (change.State.Status)
            {
            case OperationStatus.InProgress:
                if (onProgress != null && change.State.Progress != null)
                {
                    onProgress(change.State.Progress);
                }
                break;

            case OperationStatus.Completed:
                StopProcessing();
                _result.TrySetResult(change.State.Result);
                break;

            case OperationStatus.Faulted:
                StopProcessing();
                var exceptionResult = (OperationExceptionResult)change.State.Result;
                Debug.Assert(exceptionResult != null);
                _result.TrySetException(ExceptionDispatcher.Get(exceptionResult.Message, exceptionResult.Error, exceptionResult.Type, exceptionResult.StatusCode));
                break;

            case OperationStatus.Canceled:
                StopProcessing();
                _result.TrySetCanceled();
                break;
            }
        }
コード例 #3
0
        public void OnNext(OperationStatusChange change)
        {
            _lock.Wait();

            try
            {
                var onProgress = OnProgressChanged;

                switch (change.State.Status)
                {
                case OperationStatus.InProgress:
                    if (onProgress != null && change.State.Progress != null)
                    {
                        onProgress(change.State.Progress);
                    }

                    break;

                case OperationStatus.Completed:
                    StopProcessing();
                    _result.TrySetResult(change.State.Result);
                    break;

                case OperationStatus.Faulted:
                    StopProcessing();
                    if (_additionalTask.IsFaulted)
                    {
                        _result.TrySetException(_additionalTask.Exception);
                        break;
                    }

                    var exceptionResult = (OperationExceptionResult)change.State.Result;
                    Debug.Assert(exceptionResult != null);
                    var ex = new ExceptionDispatcher.ExceptionSchema
                    {
                        Error   = exceptionResult.Error,
                        Message = exceptionResult.Message,
                        Type    = exceptionResult.Type,
                        Url     = _requestExecutor.Url
                    };
                    _result.TrySetException(ExceptionDispatcher.Get(ex, exceptionResult.StatusCode));
                    break;

                case OperationStatus.Canceled:
                    StopProcessing();
                    _result.TrySetCanceled();
                    break;
                }
            }
            finally
            {
                _lock.Release();
            }
        }
コード例 #4
0
        public static void EndAsyncResult(IAsyncResult asyncResult)
        {
            Task task = asyncResult as Task;

            if (task == null)
            {
                throw Fx.Exception.AsError(new ArgumentException(Resources.InvalidAsyncResult), null);
            }
            try
            {
                task.Wait();
            }
            catch (AggregateException aggregateException)
            {
                ExceptionDispatcher.Throw(aggregateException.GetBaseException());
            }
        }
コード例 #5
0
        public static TResult EndAsyncResult <TResult>(IAsyncResult asyncResult)
        {
            TResult        result;
            Task <TResult> task = asyncResult as Task <TResult>;

            if (task == null)
            {
                throw Fx.Exception.AsError(new ArgumentException(Resources.InvalidAsyncResult), null);
            }
            try
            {
                result = task.Result;
            }
            catch (AggregateException aggregateException1)
            {
                AggregateException aggregateException = aggregateException1;
                ExceptionDispatcher.Throw(aggregateException.GetBaseException());
                throw aggregateException.GetBaseException();
            }
            return(result);
        }
コード例 #6
0
 public void IgnoreExceptionOnDispatcherWhenRemoving ()
 {
     factoryMock.ExpectAndReturn("CreateApplicationWatcherMonitor", watcher);
     factoryMock.ExpectAndReturn("CreateApplicationWatcherMonitor", watcher);
     watcherMock.Expect("StartWatching");
     watcherMock.Expect("StopWatching");
     watcherMock.Expect("Dispose");
     watcherMock.Expect("StartWatching");
     watcherMock.Expect("StopWatching");
     watcherMock.Expect("Dispose");
     ISync canContinue = new Semaphore(0);
     ISync started = new Semaphore(0);
     AddApplication();
     AddApplication(sampleDir2);
     IDeployEventDispatcher dispatcher = new ExceptionDispatcher(started, canContinue);
     location = new FileSystemDeployLocation (dispatcher, factory, deployPath, true);
     Assert.AreEqual(2, location.Applications.Count);
     Directory.Delete(sampleDir, true);
     started.Acquire();
     canContinue.Release();
     Assert.AreEqual(1, location.Applications.Count);
     Directory.Delete(sampleDir2, true);
     started.Acquire();
     canContinue.Release();
     Assert.AreEqual(0, location.Applications.Count);
 }