public async Task <MessageResult> Route(Request request, EndPointMetaData endPoint, Services.Messaging.ExecutionContext parentContext, TimeSpan?timeout = null) { CancellationTokenSource source; if (timeout.HasValue || endPoint.Timeout.HasValue) { source = new CancellationTokenSource(timeout ?? endPoint.Timeout.Value); } else { source = new CancellationTokenSource(); } var context = new Services.Messaging.ExecutionContext(request, endPoint, source.Token, parentContext); try { var result = await _commands.Ask(context, source.Token); return(result as MessageResult); } catch (Exception exception) { context.SetException(exception); } return(new MessageResult(context)); }
/// <summary> /// Initializes a new instance of the <see cref="ExecutionContext" /> class. /// </summary> /// <param name="request">The request.</param> /// <param name="endPoint">The current endpoint.</param> /// <param name="cancellationToken">The cancellation.</param> /// <param name="parent">The parent.</param> public ExecutionContext(Request request, EndPointMetaData endPoint, CancellationToken cancellationToken, ExecutionContext parent = null) { this.Request = request; this.EndPoint = endPoint; this.Parent = parent; this.CancellationToken = cancellationToken; }
/// <inheritdoc /> public async Task <MessageResult> Dispatch(Request request, EndPointMetaData endPoint, ExecutionContext parentContext, TimeSpan?timeout = null) { CancellationTokenSource source; if (timeout.HasValue || endPoint.Timeout.HasValue) { source = new CancellationTokenSource(timeout ?? endPoint.Timeout.Value); } else { source = new CancellationTokenSource(); } var context = new ExecutionContext(request, endPoint, source.Token, parentContext); var handler = _components.Resolve(endPoint.ServiceType); var service = handler as IEndPoint; if (service != null) { service.Context = context; } await(Task) endPoint.Method.Invoke(handler, new object[] { request.Message.Body }); return(new MessageResult(context)); }
private IMessage GetMessage(string message, EndPointMetaData endPoint) { if (message == null) { return(new Message(JsonConvert.DeserializeObject("{}", endPoint.RequestType))); } return(new Message(JsonConvert.DeserializeObject(message, endPoint.RequestType))); }
/// <inheritdoc /> public Request Resolve(object message, EndPointMetaData endPoint, Request parent = null) { return(new Request { CorrelationId = this.GetCorrelationId(), SourceAddress = this.GetSourceIPAddress(), SessionId = this.GetSession(), User = this.GetUser(), Parent = parent, Path = endPoint.Path, Message = this.GetMessage(message, endPoint) }); }
private IMessage GetMessage(object message, EndPointMetaData endPoint) { if (message != null && message.GetType() == endPoint.RequestType) { return(new Message(message)); } if (message != null) { var content = JsonConvert.SerializeObject(message); return(new Message(JsonConvert.DeserializeObject(content, endPoint.RequestType))); } return(new Message(JsonConvert.DeserializeObject("{}", endPoint.RequestType))); }
public static void ShouldBeSecure(this EndPointMetaData endpoint) { endpoint.Rules.Should().Contain(e => e.RuleType == ValidationType.Security); }
/// <inheritdoc /> public bool CanDispatch(EndPointMetaData endPoint) { return(endPoint.RootPath == ServiceHost.LocalPath); }