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); }
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); }
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; }
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; } }
private void ReleaseContext(ClientActionContext context) { if (_contexts.Count < _poolSize) { context.Reset(); _contexts.Enqueue(context); } }
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; } }
public async Task OpenAsync() { using (ClientActionContext ctxt = new ClientActionContext(this, Contract, BoltFramework.GetSessionDescriptor(Contract).InitSession, null)) { await Pipeline.Instance(ctxt); State = ProxyState.Open; } }
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); }
public async Task OpenAsync() { ClientActionContext ctxt = CreateContext(Contract.Session.InitSession, null); try { await Pipeline.Instance(ctxt).ConfigureAwait(false); State = ProxyState.Open; } finally { ReleaseContext(ctxt); } }
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); } }
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; }
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; }
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); }
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(); }
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; }