public virtual BoltServerException TryReadServerError(ClientActionContext context)
        {
            ServerErrorCode?result = TryReadBoltError(context);

            if (result != null)
            {
                return(new BoltServerException(result.Value, context.Action.Name, context.Request.RequestUri.ToString()));
            }

            int?code = TryReadErrorCode(context);

            if (code != null)
            {
                return(new BoltServerException(code.Value, context.Action.Name, context.Request.RequestUri.ToString()));
            }

            if (context.Response?.StatusCode == HttpStatusCode.NotFound)
            {
                return(new BoltServerException(
                           ServerErrorCode.BoltUnavailable,
                           context.Action.Name,
                           context.Request.RequestUri.ToString()));
            }

            return(null);
        }
Beispiel #2
0
        public virtual ErrorHandlingResult Handle(ClientActionContext context, Exception e)
        {
            if (context.Proxy.State == ProxyState.Closed)
            {
                return(ErrorHandlingResult.Close);
            }

            if (e is NoServersAvailableException)
            {
                return(ErrorHandlingResult.Recover);
            }

            if ((e as BoltServerException)?.ServerError == ServerErrorCode.ContractNotFound)
            {
                return(ErrorHandlingResult.Close);
            }

            if ((e as BoltServerException)?.ServerError == ServerErrorCode.SessionNotFound)
            {
                return(ErrorHandlingResult.Recover);
            }

            if (e is HttpRequestException)
            {
                return(ErrorHandlingResult.Recover);
            }

            if (e is ProxyClosedException)
            {
                return(ErrorHandlingResult.Close);
            }

            return(ErrorHandlingResult.Rethrow);
        }
Beispiel #3
0
        public ErrorHandlingResult Handle(ClientActionContext context, Exception e)
        {
            if (e is NoServersAvailableException)
            {
                return ErrorHandlingResult.Recover;
            }

            if ((e as BoltServerException)?.Error == ServerErrorCode.ContractNotFound)
            {
                return ErrorHandlingResult.Close;
            }

            if ((e as BoltServerException)?.Error == ServerErrorCode.SessionNotFound)
            {
                return ErrorHandlingResult.Recover; 
            }

            if (e is HttpRequestException)
            {
                return ErrorHandlingResult.Recover; 
            }

            if (e is ProxyClosedException)
            {
                return ErrorHandlingResult.Close;
            }

            return ErrorHandlingResult.Rethrow;
        }
Beispiel #4
0
 public async Task<object> SendAsync(MethodInfo action, params object[] parameters)
 {
     using (ClientActionContext ctxt = new ClientActionContext(this, Contract, action, parameters))
     {
         await Pipeline.Instance(ctxt);
         return ctxt.ActionResult;
     }
 }
Beispiel #5
0
 private void ReleaseContext(ClientActionContext context)
 {
     if (_contexts.Count < _poolSize)
     {
         context.Reset();
         _contexts.Enqueue(context);
     }
 }
Beispiel #6
0
 public async Task OpenAsync()
 {
     using (ClientActionContext ctxt = new ClientActionContext(this, Contract, BoltFramework.SessionMetadata.Resolve(Contract).InitSession.Action, null))
     {
         await Pipeline.Instance(ctxt);
         State = ProxyState.Open;
     }
 }
Beispiel #7
0
 public async Task OpenAsync()
 {
     using (ClientActionContext ctxt = new ClientActionContext(this, Contract, BoltFramework.GetSessionDescriptor(Contract).InitSession, null))
     {
         await Pipeline.Instance(ctxt);
         State = ProxyState.Open;
     }
 }
Beispiel #8
0
        private ClientActionContext CreateContext(ActionMetadata action, params object[] parameters)
        {
            ClientActionContext context;

            if (!_contexts.TryDequeue(out context))
            {
                context = new ClientActionContext();
            }

            context.Init(this, Contract, action, parameters);
            return(context);
        }
Beispiel #9
0
        public async Task OpenAsync()
        {
            ClientActionContext ctxt = CreateContext(Contract.Session.InitSession, null);

            try
            {
                await Pipeline.Instance(ctxt).ConfigureAwait(false);

                State = ProxyState.Open;
            }
            finally
            {
                ReleaseContext(ctxt);
            }
        }
Beispiel #10
0
        public async Task <object> SendAsync(MethodInfo action, params object[] parameters)
        {
            ClientActionContext ctxt = CreateContext(Contract.GetAction(action), parameters);

            try
            {
                await Pipeline.Instance(ctxt).ConfigureAwait(false);

                return(ctxt.ActionResult);
            }
            finally
            {
                ReleaseContext(ctxt);
            }
        }
Beispiel #11
0
        protected virtual ServerErrorCode? TryReadBoltError(ClientActionContext context)
        {
            string value = context.Response.Headers.GetHeaderValue(_errorCodeHeader);
            if (string.IsNullOrEmpty(value))
            {
                return null;
            }

            ServerErrorCode code;
            if (Enum.TryParse(value, true, out code))
            {
                return code;
            }

            return null;
        }
Beispiel #12
0
        protected virtual int? TryReadErrorCode(ClientActionContext context)
        {
            string value = context.Response.Headers.GetHeaderValue(_errorCodeHeader);
            if (string.IsNullOrEmpty(value))
            {
                return null;
            }

            int code;
            if (int.TryParse(value, out code))
            {
                return code;
            }

            return null;
        }
Beispiel #13
0
        public async Task CloseAsync()
        {
            if (State == ProxyState.Open)
            {
                using (ClientActionContext ctxt = new ClientActionContext(this, Contract, BoltFramework.SessionMetadata.Resolve(Contract).DestroySession.Action, null))
                {
                    await Pipeline.Instance(ctxt);
                    State = ProxyState.Closed;
                }
            }
            else
            {
                State = ProxyState.Closed;
            }

            Dispose();
        }
        protected virtual int?TryReadErrorCode(ClientActionContext context)
        {
            string value = context.Response.Headers.GetHeaderValue(_errorCodeHeader);

            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }

            int code;

            if (int.TryParse(value, out code))
            {
                return(code);
            }

            return(null);
        }
        protected virtual ServerErrorCode?TryReadBoltError(ClientActionContext context)
        {
            string value = context.Response.Headers.GetHeaderValue(_errorCodeHeader);

            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }

            ServerErrorCode code;

            if (Enum.TryParse(value, true, out code))
            {
                return(code);
            }

            return(null);
        }
Beispiel #16
0
        public async Task CloseAsync()
        {
            if (State == ProxyState.Open)
            {
                ClientActionContext ctxt = CreateContext(Contract.Session.DestroySession, null);
                try
                {
                    await Pipeline.Instance(ctxt).ConfigureAwait(false);

                    State = ProxyState.Closed;
                }
                finally
                {
                    ReleaseContext(ctxt);
                }
            }
            else
            {
                State = ProxyState.Closed;
            }

            Dispose();
        }
Beispiel #17
0
        public virtual BoltServerException TryReadServerError(ClientActionContext context)
        {
            ServerErrorCode? result = TryReadBoltError(context);
            if (result != null)
            {
                return new BoltServerException(result.Value, context.Action, context.Request.RequestUri.ToString());
            }

            int? code = TryReadErrorCode(context);
            if (code != null)
            {
                return new BoltServerException(code.Value, context.Action, context.Request.RequestUri.ToString());
            }

            if (context.Response?.StatusCode == HttpStatusCode.NotFound)
            {
                return new BoltServerException(
                    ServerErrorCode.BoltUnavailable,
                    context.Action,
                    context.Request.RequestUri.ToString());
            }

            return null;
        }