Пример #1
0
        /// <summary>
        /// Handles and executes a task.
        /// </summary>
        /// <param name="task"></param>
        private static void HandleTask(GuardianTask task)
        {
            if (task is ScheduledConfig config)
            {
                // This is obv not gerenic. Maybe if the settings are getting way more, we could be more generic here.
                switch (config.Name)
                {
                case "DIP_AutomaticBackupIntervall":
                    GuardianRequest?.Invoke(RequestTypes.Backup);
                    break;

                case "DI_AutomaticScans":
                    GuardianRequest?.Invoke(RequestTypes.Scan);
                    break;

                case "DI_AutomaticSaves":
                    GuardianRequest?.Invoke(RequestTypes.Save);
                    break;

                default:
                    throw new GuardianException($"{task.Name} could not be handled.");
                }
                // Task has been handled => Inform the View and delete this instance.
                _taskPool.Remove(config.Gtid, out var obsolete);
                _upcomingTasks.Remove(config.Gtid);
                GuardianHandledTask?.Invoke(config);
            }
        }
Пример #2
0
        /// <summary>
        /// Returns non-null parameters foudn in given request.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="parameterType"></param>
        /// <param name="routeConfiguration"></param>
        /// <returns></returns>
        private static object[] GetRequestParameters(GuardianRequest request, Type parameterType, RouteConfiguration routeConfiguration)
        {
            List <object> potentialParameters = new List <object>();

            potentialParameters.Add(GetDeserializedStream(request.Body, parameterType));
            potentialParameters.Add(GetTypedRouteParameter(request.Path, routeConfiguration.Path, parameterType));

            return(potentialParameters
                   .Where(p => p != null)
                   .ToArray());
        }
Пример #3
0
        /// <summary>
        /// Returns a Route Handler for the given request.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        internal static RouteHandler GetRouteHandler(GuardianRequest request)
        {
            RouteConfiguration matchingRouteConfiguration = GetConfiguredRoute(request);

            if (matchingRouteConfiguration == null)
            {
                return(null);
            }

            // Does the target method have an expected parameter? (Only one is allowed currently)
            Type parameterType = matchingRouteConfiguration.ControllerMethodInfo.GetParameters()
                                 .Select(mi => mi.ParameterType)
                                 .SingleOrDefault();

            if (parameterType == null)
            {
                return(new RouteHandler(matchingRouteConfiguration.ControllerMethodInfo));
            }

            return(new RouteHandler(matchingRouteConfiguration.ControllerMethodInfo, GetRequestParameters(request, parameterType, matchingRouteConfiguration)));
        }
Пример #4
0
 /// <summary>
 /// Returns a route configuration if the request matches a configured route.
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 internal static RouteConfiguration GetConfiguredRoute(GuardianRequest request)
 {
     return(_congifuredRoutes
            .Where(cr => cr.IsMatch(request.Path, request.Method))
            .FirstOrDefault());
 }