Esempio n. 1
0
        /// <summary>
        /// Adds a new route to the table.
        /// </summary>
        public void AddRoute(Func <string, Destination, bool> destinationFilter, string destinationFilterDescription, string gateway, string iface)
        {
            var entry = new RouteTableEntry(destinationFilter, destinationFilterDescription, gateway, iface);

            entries.Add(entry);

            logger.Debug($"Adding route {entry}.");
        }
        static void RegisterMessageRoute(Type mappedType, string address, Dictionary <Type, RouteTableEntry> routeTableEntries, IEnumerable <Type> baseTypes)
        {
            var route = UnicastRoute.CreateFromPhysicalAddress(address);

            foreach (var baseType in baseTypes)
            {
                routeTableEntries[baseType] = new RouteTableEntry(baseType, route);
            }
            routeTableEntries[mappedType] = new RouteTableEntry(mappedType, route);
        }
Esempio n. 3
0
        public RestfulDispatcher(Action <string> traceMessage, object controller)
        {
            this.traceMessage = traceMessage;
            this.controller   = controller;

            this.routeTable = controller.GetType()
                              .GetMethods()
                              .Where(methodInfo => methodInfo.ReturnType == typeof(Task <TResponseModel>))
                              .Select(methodInfo => RouteTableEntry.Create(methodInfo))
                              .Where(entry => entry != null)
                              .ToArray();
        }
Esempio n. 4
0
        public async Task <TResponseModel> DispatchAsync(
            string httpMethod,
            string path,
            string content,
            IReadOnlyDictionary <string, IEnumerable <string> > headers,
            IEnumerable <KeyValuePair <string, string> > query)
        {
            RouteTableEntry             selectedEntry = null;
            Dictionary <string, string> pathVariables = null;

            foreach (var entry in this.routeTable)
            {
                pathVariables = entry.GetPathVariables(httpMethod, path);
                if (pathVariables != null)
                {
                    selectedEntry = entry;
                    break;
                }
            }

            if (selectedEntry == null)
            {
#if DEBUG
                throw new ResourceNotFoundException($"Invalid path '{path}' for resource provider {this.controller.GetType().Name}");
#else
                throw new ResourceNotFoundException($"Invalid path '{path}'");
#endif
            }

            var method = this.controller.GetType().GetMethod(selectedEntry.Action, selectedEntry.ParameterTypes);

            var parameters = method.GetParameters()
                             .Select(parameterInfo => CastParameter(
                                         parameterInfo,
                                         content,
                                         pathVariables,
                                         headers,
                                         query))
                             .ToArray();

            var task = method.Invoke(this.controller, parameters.ToArray()) as Task <TResponseModel>;
            return(await task);
        }
 static void RegisterMessageRoute(Type mappedType, string address, Dictionary<Type, RouteTableEntry> routeTableEntries, IEnumerable<Type> baseTypes)
 {
     var route = UnicastRoute.CreateFromPhysicalAddress(address);
     foreach (var baseType in baseTypes)
     {
         routeTableEntries[baseType] = new RouteTableEntry(baseType, route);
     }
     routeTableEntries[mappedType] = new RouteTableEntry(mappedType, route);
 }
Esempio n. 6
0
 public RouteState(UnicastRoute routeToRouter, Type messageType, string endpointName)
 {
     this.routeToRouter = new RouteTableEntry(messageType, routeToRouter);
     directRoute        = new RouteTableEntry(messageType, UnicastRoute.CreateFromEndpointName(endpointName));
     useDirectRoute     = true;
 }