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));
        }
예제 #2
0
 /// <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;
 }
예제 #3
0
        /// <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));
        }
예제 #4
0
파일: Request.cs 프로젝트: kennyup/stacks
 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)));
 }
예제 #5
0
파일: Request.cs 프로젝트: kennyup/stacks
 /// <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)
     });
 }
예제 #6
0
파일: Request.cs 프로젝트: kennyup/stacks
 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)));
 }
예제 #7
0
 public static void ShouldBeSecure(this EndPointMetaData endpoint)
 {
     endpoint.Rules.Should().Contain(e => e.RuleType == ValidationType.Security);
 }
예제 #8
0
 /// <inheritdoc />
 public bool CanDispatch(EndPointMetaData endPoint)
 {
     return(endPoint.RootPath == ServiceHost.LocalPath);
 }