Ejemplo n.º 1
0
        public void AddRoute(string method, string path, IHandleRequest action)
        {
            var split = path.Split('/', StringSplitOptions.RemoveEmptyEntries);

            if (split.Length < 1)
            {
                throw new ArgumentException("Path cannot be empty");
            }
            var paths = new Stack <string>(split);

            method = method.ToUpper();

            RouteTreeNode <IHandleRequest> node;

            //always have an empty root node
            if (!_hostMethodRoutes.ContainsKey(method))
            {
                node = new RouteTreeNode <IHandleRequest>(null);
                _hostMethodRoutes.Add(method, node);
            }
            else
            {
                node = _hostMethodRoutes[method];
            }

            if (!node.TryAdd(paths, action))
            {
                throw new ArgumentException("Route already exists");
            }
        }
Ejemplo n.º 2
0
        public async Task <TResponse> ExecuteAsync <TRequest, TResponse>(
            IHandleRequest <TRequest, TResponse> handler,
            TRequest request,
            CancellationToken cancellationToken = default(CancellationToken))
            where TRequest : class, IRequest <TResponse>
        {
            var response = await handler.HandleAsync(request, cancellationToken);

            return(response);
        }
Ejemplo n.º 3
0
 public ServerCommunication(IHandleRequest handleRequest)
 {
     func = handleRequest;
 }