Beispiel #1
0
 public DefaultMessageRouterHandler(IChromelyRouteProvider routeProvider, IChromelyRequestHandler requestHandler, IChromelyDataTransferOptions dataTransferOptions, IChromelyErrorHandler chromelyErrorHandler)
 {
     _routeProvider        = routeProvider;
     _requestHandler       = requestHandler;
     _dataTransferOptions  = dataTransferOptions;
     _chromelyErrorHandler = chromelyErrorHandler;
 }
Beispiel #2
0
    /// <summary>
    /// Initializes a new instance of <see cref="IChromelyRouteProvider"/>.
    /// </summary>
    /// <param name="routeParameterBinder">The <see cref="IChromelyModelBinder"/> instance.</param>
    /// <param name="dataTransferOptions">The <see cref="IChromelyDataTransferOptions"/> instance.</param>
    public DefaultRouteProvider(IChromelyModelBinder routeParameterBinder, IChromelyDataTransferOptions dataTransferOptions)
    {
        _routeParameterBinder = routeParameterBinder;
        _dataTransferOptions  = dataTransferOptions;

        RouteMap = new Dictionary <string, ControllerRoute>();
    }
 /// <summary>
 /// Initializes a new instance of <see cref="DefaultRequestSchemeHandlerFactory"/>.
 /// </summary>
 /// <param name="routeProvider">Instance of <see cref="IChromelyRouteProvider"/>.</param>
 /// <param name="requestSchemeProvider">Instance of <see cref="IChromelyRequestSchemeProvider"/>.</param>
 /// <param name="requestHandler">Instance of <see cref="IChromelyRequestHandler"/>.</param>
 /// <param name="dataTransferOptions">Instance of <see cref="IChromelyDataTransferOptions"/>.</param>
 /// <param name="chromelyErrorHandler">Instance of <see cref="IChromelyErrorHandler"/>.</param>
 public DefaultRequestSchemeHandlerFactory(IChromelyRouteProvider routeProvider,
                                           IChromelyRequestSchemeProvider requestSchemeProvider,
                                           IChromelyRequestHandler requestHandler,
                                           IChromelyDataTransferOptions dataTransferOptions,
                                           IChromelyErrorHandler chromelyErrorHandler)
 {
     _routeProvider         = routeProvider;
     _requestSchemeProvider = requestSchemeProvider;
     _requestHandler        = requestHandler;
     _dataTransferOptions   = dataTransferOptions;
     _chromelyErrorHandler  = chromelyErrorHandler;
 }
 public ControllerRoute(string name, dynamic del, IList <RouteArgument> argumentInfos, IChromelyModelBinder routeParameterBinder, IChromelyDataTransferOptions dataTransfers, bool isAsync, bool hasReturnValue)
 {
     Name                     = name;
     Delegate                 = del;
     RouteArguments           = argumentInfos;
     _routeParameterBinder    = routeParameterBinder;
     _dataTransfers           = dataTransfers;
     IsAsync                  = isAsync;
     HasReturnValue           = hasReturnValue;
     _routeArguments          = new object[argumentInfos.Count];
     _queryParameterArgs      = new Dictionary <string, object>();
     _propertyNameArgumentMap = new Dictionary <string, RouteArgument>();
 }
 public DefaultRequestSchemeHandler(IChromelyRouteProvider routeProvider,
                                    IChromelyRequestSchemeProvider requestSchemeProvider,
                                    IChromelyRequestHandler requestHandler,
                                    IChromelyDataTransferOptions dataTransferOptions,
                                    IChromelyErrorHandler chromelyErrorHandler)
 {
     _routeProvider         = routeProvider;
     _requestSchemeProvider = requestSchemeProvider;
     _requestHandler        = requestHandler;
     _dataTransferOptions   = dataTransferOptions;
     _chromelyErrorHandler  = chromelyErrorHandler;
     _chromelyResponse      = new ChromelyResponse();
     _mimeType = ResourceHandler.DefaultMimeType;
     _stream   = Stream.Null;
 }
 /// <summary>
 /// Initializes a new instance of <see cref="IChromelyModelBinder"/>.
 /// </summary>
 /// <param name="dataTransfers">The <see cref="IChromelyDataTransferOptions"/> instance.</param>
 public DefaultModelBinder(IChromelyDataTransferOptions dataTransfers)
 {
     _dataTransfers = dataTransfers;
 }
    public static void CreateAndRegisterRoutes(IChromelyRouteProvider routeProvider, ChromelyController controller, IChromelyModelBinder routeParameterBinder, IChromelyDataTransferOptions dataTransferOptions)
    {
        if (routeProvider is null || controller is null)
        {
            return;
        }

        var methodInfos = controller.GetType().GetMethods()
                          .Where(m => m.GetCustomAttributes(typeof(ChromelyRouteAttribute), false).Length > 0)
                          .ToArray();

        foreach (var methodInfo in methodInfos)
        {
            var attribute = methodInfo.GetCustomAttribute <ChromelyRouteAttribute>();
            var key       = RouteKeys.CreateActionKey(controller.RoutePath, attribute?.Path ?? string.Empty);
            if (!routeProvider.RouteExists(key))
            {
                routeProvider.RegisterRoute(key, ControllerRoutesFactory.CreateDelegate(controller, methodInfo, routeParameterBinder, dataTransferOptions));
            }
        }
    }
    private static ControllerRoute CreateDelegate(object instance, MethodInfo method, IChromelyModelBinder routeParameterBinder, IChromelyDataTransferOptions dataTransferOptions)
    {
        var args = method
                   .GetParameters();

        var arguments = new List <RouteArgument>();

        int lenght = args.Length;

        for (int i = 0; i < lenght; i++)
        {
            arguments.Add(new RouteArgument(args[i].Name, args[i].ParameterType, i));
        }

        var argTypes = args
                       .Select(p => p.ParameterType)
                       .Concat(new[] { method.ReturnType })
                       .ToArray();

        var newDelType = Expression.GetDelegateType(argTypes);
        var newDel     = Delegate.CreateDelegate(newDelType, instance, method);

        bool isAsync   = method.ReturnType.IsSubclassOf(typeof(Task));
        bool hasReturn = method.ReturnType != VoidType;

        // It is async method without return (void - System.Threading.Tasks.VoidTaskResult)
        if (method.ReturnType == typeof(Task))
        {
            isAsync   = true;
            hasReturn = false;
        }

        return(new ControllerRoute(method.Name, newDel, arguments, routeParameterBinder, dataTransferOptions, isAsync, hasReturn));
    }
 public ChromelyRequestSchemeHandlerFactory(IChromelyRouteProvider routeProvider, IChromelyRequestSchemeProvider requestSchemeProvider, IChromelyRequestHandler requestHandler, IChromelyDataTransferOptions dataTransferOptions, IChromelyErrorHandler chromelyErrorHandler)
     : base(routeProvider, requestSchemeProvider, requestHandler, dataTransferOptions, chromelyErrorHandler)
 {
 }
 public ChromelyMessageRouter(IChromelyRouteProvider routeProvider, IChromelyRequestHandler requestHandler, IChromelyDataTransferOptions dataTransferOptions, IChromelyErrorHandler chromelyErrorHandler)
     : base(routeProvider, requestHandler, dataTransferOptions, chromelyErrorHandler)
 {
 }