Exemplo n.º 1
1
        public static Exception GetExceptionFromOutcome(Outcome outcome)
        {
            Exception retException = null;
            if (outcome == null)
            {
                retException = new IotHubException("Unknown error.");
                return retException;
            }

            if (outcome.DescriptorCode == Rejected.Code)
            {
                var rejected = (Rejected)outcome;
                retException = AmqpErrorMapper.ToIotHubClientContract(rejected.Error);
            }
            else if (outcome.DescriptorCode == Released.Code)
            {
                retException = new OperationCanceledException("AMQP link released.");
            }
            else
            {
                retException = new IotHubException("Unknown error.");
            }

            return retException;
        }
            public void OnFailure(ICall p0, IOException p1)
            {
                // https://github.com/alexrainman/ModernHttpClient/pull/65
                var host = p0?.Request()?.Url()?.Host();

                // Kind of a hack, but the simplest way to find out that server cert. validation failed
                //if (p1.Message.StartsWith("Hostname " + p0.Request().Url().Host() + " not verified", StringComparison.Ordinal))
                if (host != null && p1.Message != null && p1.Message.StartsWith("Hostname " + host + " not verified", StringComparison.Ordinal))
                {
                    // SIGABRT after UnknownHostException #229
                    //tcs.TrySetException(new WebException(p1.Message));
                    //tcs.TrySetException(new WebException(p1.LocalizedMessage, WebExceptionStatus.TrustFailure));
                    var ex = new System.OperationCanceledException(HostnameVerifier.PinningFailureMessage, p1);
                    HostnameVerifier.PinningFailureMessage = null;
                    tcs.TrySetException(ex);
                }
                //else if (p1.Message.StartsWith("Certificate pinning failure", StringComparison.Ordinal))
                else if (p1.Message != null && p1.Message.StartsWith("Certificate pinning failure", StringComparison.Ordinal))
                {
                    System.Diagnostics.Debug.WriteLine(p1.Message);
                    tcs.TrySetException(new System.OperationCanceledException(FailureMessages.PinMismatch, p1));
                }
                else
                {
                    tcs.TrySetException(p1);
                }
            }
Exemplo n.º 3
0
        private static void EnsureOperationCanceledExceptionThrown(Action action, CancellationToken token, string message)
        {
            InternalOCE operationCanceledEx =
                AssertExtensions.Throws <InternalOCE>(action);

            Assert.AreEqual(token, operationCanceledEx.CancellationToken);
        }
Exemplo n.º 4
0
 protected override void OnCreate(Bundle savedInstance)
 {
     base.OnCreate(savedInstance);
     SetContentView(R.Layouts.MainLayout);
     var x = new System.OperationCanceledException(new CancellationToken());
 }
Exemplo n.º 5
0
 public override void Write(byte[] buffer, int offset, int count)
 {
     if (BreakHow == BreakHowType.ThrowOnWrite)
     {
         ThrownException = new IOException();
         throw ThrownException;
     }
     else if (BreakHow == BreakHowType.CancelOnWrite)
     {
         ThrownException = new OperationCanceledException();
         throw ThrownException;
     }
 }
Exemplo n.º 6
0
        protected override void OnCreate(Bundle savedInstance)
        {
            base.OnCreate(savedInstance);
            SetContentView(R.Layout.MainLayout);
			var x = new System.OperationCanceledException(new CancellationToken());
        }
Exemplo n.º 7
0
			internal void SetCanceled()
			{
				Exception = new OperationCanceledException("Der Vorgang wurde abgebrochen.");
				State = States.Canceled;
			}
 protected static UserErrorModel Handle(OperationCanceledException ex, string action)
     => new CanceledUserError(action, innerException: ex);
Exemplo n.º 9
0
        internal static StorageException GenerateCancellationException(RequestResult res, Exception inner)
        {
            if (res != null)
            {
                res.HttpStatusCode = 306;
                res.HttpStatusMessage = "Unused";
            }

            OperationCanceledException cancelEx = new OperationCanceledException(SR.OperationCanceled, inner);
            return new StorageException(res, cancelEx.Message, inner) { IsRetryable = false };
        }
Exemplo n.º 10
0
 public CanceledUserError(string errorMessage, string errorCauseOrResolution = null,
     IEnumerable<RecoveryCommandModel> recoveryOptions = null, Dictionary<string, object> contextInfo = null,
     OperationCanceledException innerException = null)
     : base(errorMessage, errorCauseOrResolution, recoveryOptions, contextInfo, innerException) {}
Exemplo n.º 11
0
 public static TwitterApiException CreateFromException(OperationCanceledException ex)
     => new TwitterApiException("Timeout", ex);
 protected static UserError Handle(OperationCanceledException ex, string action) {
     return new CanceledUserError(action, innerException: ex);
 }
Exemplo n.º 13
0
        private async Task DoReceive()
        {
            Exception error = null;

            try
            {
                var socketError = await ProcessReceives();

                var ex = new SocketException((int)socketError);
                if (ex.SocketErrorCode == SocketError.ConnectionReset)
                {
                    error = new ConnectionResetException(ex.Message, ex);
                    _trace.ConnectionReset(ConnectionId);
                }
                else if (ex.SocketErrorCode == SocketError.OperationAborted ||
                         ex.SocketErrorCode == SocketError.ConnectionAborted ||
                         ex.SocketErrorCode == SocketError.Interrupted ||
                         ex.SocketErrorCode == SocketError.InvalidArgument)
                {
                    if (!_aborted)
                    {
                        // Calling Dispose after ReceiveAsync can cause an "InvalidArgument" error on *nix.
                        error = new ConnectionAbortedException();
                        _trace.ConnectionError(ConnectionId, error);
                    }
                }
                else if (socketError != SocketError.Success)
                {
                    error = ex;
                    _trace.ConnectionError(ConnectionId, error);
                }
            }
            catch (SocketException ex) when(ex.SocketErrorCode == SocketError.ConnectionReset)
            {
                error = new ConnectionResetException(ex.Message, ex);
                _trace.ConnectionReset(ConnectionId);
            }
            catch (SocketException ex) when(ex.SocketErrorCode == SocketError.OperationAborted ||
                                            ex.SocketErrorCode == SocketError.ConnectionAborted ||
                                            ex.SocketErrorCode == SocketError.Interrupted ||
                                            ex.SocketErrorCode == SocketError.InvalidArgument)
            {
                if (!_aborted)
                {
                    // Calling Dispose after ReceiveAsync can cause an "InvalidArgument" error on *nix.
                    error = new ConnectionAbortedException();
                    _trace.ConnectionError(ConnectionId, error);
                }
            }
            catch (ObjectDisposedException)
            {
                if (!_aborted)
                {
                    error = new ConnectionAbortedException();
                    _trace.ConnectionError(ConnectionId, error);
                }
            }
            catch (IOException ex)
            {
                error = ex;
                _trace.ConnectionError(ConnectionId, error);
            }
            catch (Exception ex)
            {
                error = new IOException(ex.Message, ex);
                _trace.ConnectionError(ConnectionId, error);
            }
            finally
            {
                if (_aborted)
                {
                    error = error ?? new ConnectionAbortedException();
                }

                ReceiveError = error;
                Input.Complete();
            }
        }
        private void ContinueAsyncLogin(Uri loginUrl, Action<bool, Exception> continuation)
        {
            Log.To.Sync.I(Tag, "{0} scheduling app login callback block", this);
            var remoteUrl = RemoteUrl;
            var authBaseUrl = remoteUrl.AppendPath("_oidc_callback");
            _callbackContext.StartNew(() =>
            {
                try {
                    _loginCallback(loginUrl, authBaseUrl, (authUrl, error) =>
                    {
                        if(authUrl != null) {
                            Log.To.Sync.I(Tag, "{0} app login callback returned authUrl=<{1}>", this, authUrl.AbsolutePath);
                            // Verify that the authUrl matches the site:
                            var remoteUrlLeft = remoteUrl.GetLeftPart(UriPartial.Path).TrimEnd('/');
                            if(String.Compare(authUrl.Host, remoteUrl.Host, StringComparison.InvariantCultureIgnoreCase) != 0 || authUrl.Port != remoteUrl.Port || $"{remoteUrlLeft}/_oidc_callback" != authUrl.GetLeftPart(UriPartial.Path)) {
                                Log.To.Sync.W(Tag, "{0} app-provided authUrl <{1}> doesn't match server URL; ignoring it", this, authUrl.AbsolutePath);
                                authUrl = null;
                                error = new ArgumentException("authURL does not match server URL");
                            }
                        }

                        if(authUrl != null) {
                            _authUrl = authUrl;
                            continuation(true, null);
                        } else {
                            if(error == null) {
                                error = new OperationCanceledException();
                            }

                            Log.To.Sync.I(Tag, $"{this} app login callback returned error", error);
                            continuation(false, error);
                        }
                    });
                } catch(Exception e) {
                    Log.To.Sync.W(Tag, "Exception during login callback", e);
                    continuation(false, e);
                }
            });
        }
Exemplo n.º 15
0
        private async Task <Exception> DoReceive()
        {
            Exception error = null;

            try
            {
                var buffer    = new ArraySegment <byte>(new byte[MinAllocBufferSize]);
                var awaitable = _receiveAwaitable;
                awaitable.EventArgs.SetBuffer(buffer.Array, buffer.Offset, buffer.Count);
                while (true)
                {
                    if (!await _socket.ReceiveAsync(awaitable))
                    {
                        throw new SocketException((int)awaitable.EventArgs.SocketError);
                    }

                    var bytesReceived = awaitable.EventArgs.BytesTransferred;

                    if (bytesReceived == 0)
                    {
                        // FIN
                        _trace.ConnectionReadFin(ConnectionId);
                        break;
                    }

#if NETCOREAPP2_0
                    Received(buffer.Slice(buffer.Offset, bytesReceived));
#else
                    Received(new ArraySegment <byte>(buffer.Array, buffer.Offset, bytesReceived));
#endif
                }
            }
            catch (SocketException ex) when(ex.SocketErrorCode == SocketError.ConnectionReset)
            {
                error = new ConnectionResetException(ex.Message, ex);
                _trace.ConnectionReset(ConnectionId);
            }
            catch (SocketException ex) when(ex.SocketErrorCode == SocketError.OperationAborted ||
                                            ex.SocketErrorCode == SocketError.ConnectionAborted ||
                                            ex.SocketErrorCode == SocketError.Interrupted ||
                                            ex.SocketErrorCode == SocketError.InvalidArgument)
            {
                if (!_aborted)
                {
                    // Calling Dispose after ReceiveAsync can cause an "InvalidArgument" error on *nix.
                    error = new ConnectionAbortedException();
                    _trace.ConnectionError(ConnectionId, error);
                }
            }
            catch (ObjectDisposedException)
            {
                if (!_aborted)
                {
                    error = new ConnectionAbortedException();
                    _trace.ConnectionError(ConnectionId, error);
                }
            }
            catch (IOException ex)
            {
                error = ex;
                _trace.ConnectionError(ConnectionId, error);
            }
            catch (Exception ex)
            {
                error = new IOException(ex.Message, ex);
                _trace.ConnectionError(ConnectionId, error);
            }
            finally
            {
                if (_aborted)
                {
                    error = error ?? new ConnectionAbortedException();
                }
            }

            return(error);
        }