Ejemplo n.º 1
0
        public ActionDictionary GetActions()
        {
            ActionDictionary actionTypes = new ActionDictionary();

            actionTypes.Add("create", create);
            actionTypes.Add("call", call);
            actionTypes.Add("get", get);
            actionTypes.Add("set", set);
            return(actionTypes);
        }
Ejemplo n.º 2
0
 public AdminController()
     : base()
 {
     ActionDictionary.Add("DCIP", DisconnectIP);
     ActionDictionary.Add("DCSERVER", DisconnectServer);
     ActionDictionary.Add("CSERVER", ConnectServer);
     ActionDictionary.Add("ACSERVER", AddConnectNewServer);
     ActionDictionary.Add("ADDSERVER", AddNewServer);
     ActionDictionary.Add("DELSERVER", RemoveServer);
     ActionDictionary.Add("LISTSERVERS", ListServers);
     ActionDictionary.Add("DCL", DisableCommand);
     ActionDictionary.Add("CLS", ClearConsole);
     ActionDictionary.Add("EXIT", Exit);
     ActionDictionary.Add("HELP", Help);
     NLConsole.WriteLine(UIStrings.HelpPrompt, ConsoleColor.Red);
 }
 public DeploymentModule(
     IExceptionHandler exceptionHandler,
     IApplicationSettings applicationSettings,
     ISystemClock systemClock,
     IConsoleWrapper <DeploymentModule> consoleWrapper,
     ITargetService targetService,
     IDeploymentService deploymentService)
     : base(exceptionHandler)
 {
     ActionDictionary
     .Add(builder => builder.Add("add", AddDeployment)
          .Add("list", ListDeployments));
     DefaultAction            = GetDeployment;
     RequiresArguments        = true;
     WriteLineAsyncAction     = (format, args, logLevel) => consoleWrapper.WriteLineAsync(format, true, logLevel, args);
     this.applicationSettings = applicationSettings;
     this.systemClock         = systemClock;
     this.consoleWrapper      = consoleWrapper;
     this.targetService       = targetService;
     this.deploymentService   = deploymentService;
 }
 public TargetModule(
     ISystemClock systemClock,
     IExceptionHandler exceptionHandler,
     IConsoleWrapper <TargetModule> consoleWrapper,
     ICacheState <DateTimeOffset> cacheState,
     ITargetTypeService targetTypeService,
     ITargetService targetService,
     IDeploymentCache deploymentCache)
     : base(exceptionHandler)
 {
     ActionDictionary.Add(builder => builder
                          .Add("add", AddTarget)
                          .Add("list", ListTargets));
     WriteLineAsyncAction   = (format, args, logLevel) => consoleWrapper.WriteLineAsync(format, true, logLevel, args);
     DefaultAction          = GetTarget;
     RequiresArguments      = true;
     this.systemClock       = systemClock;
     this.consoleWrapper    = consoleWrapper;
     this.cacheState        = cacheState;
     this.targetTypeService = targetTypeService;
     this.targetService     = targetService;
     this.deploymentCache   = deploymentCache;
 }
Ejemplo n.º 5
0
 public QueryController() : base()
 {
     ActionDictionary.Add("HASH", CheckHashAction);
     RemoteActionDictionary.Add("HASH", CheckHashAction);
 }
Ejemplo n.º 6
0
        public static RouteCollection MapRoutes(this RouteCollection routes, Assembly assembly, ActionDictionary actions)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }

            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            assembly.GetTypes()
                // Find all non abstract classes of type Controller and whose names end with "Controller"
                .Where(x => x.IsClass && !x.IsAbstract && x.IsSubclassOf(typeof(Controller)) && x.Name.EndsWith("Controller"))

                // Find all public methods from those controller classes
                .SelectMany(x => x.GetMethods(), (x, y) => new { Controller = x.Name, Method = y, Namespace = x.Namespace })

                // Find all route attributes from those methods
                .SelectMany(x => x.Method.GetCustomAttributes(typeof(RouteAttribute), false),
                            (x, y) => new { Controller = x.Controller.Substring(0, x.Controller.Length - 10), Action = x.Method.Name, Method = x.Method, Namespace = x.Namespace, Route = (RouteAttribute)y })

                // Order selected entires by rank number and iterate through each of them
                .OrderBy(x => x.Route.Order == -1).ThenBy(x => x.Route.Order).ToList().ForEach(x =>
                {
                    // Set Defautls
                    var defaults = ParseRouteValues(x.Route.Defaults);
                    defaults.Add("controller", x.Controller);
                    defaults.Add("action", x.Action);

                    // Set Optional Parameters and remove '?' mark from the url
                    Match m;

                    while ((m = Regex.Match(x.Route.Url, @"\{([^\}]+?)\?\}")) != null && m.Success)
                    {
                        var p = m.Groups[1].Value;
                        defaults.Add(p, UrlParameter.Optional);
                        x.Route.Url = x.Route.Url.Replace("{" + p + "?}", "{" + p + "}");
                    }

                    // Set Defautls
                    var constraints = ParseRouteValues(x.Route.Constraints);

                    // Set Data Tokens
                    var dataTokens = new RouteValueDictionary();
                    dataTokens.Add("Namespaces", new string[] { x.Namespace });

                    var route = new Route(x.Route.Url, new MvcRouteHandler())
                    {
                        Defaults = defaults,
                        Constraints = constraints,
                        DataTokens = dataTokens
                    };

                    //Setup Actions
                    var par = x.Method.GetParameters().FirstOrDefault();
                    if (par == null)
                        throw new Exception("No Parameter found for action - " + x.Method.DeclaringType + ", " + x.Method.Name);

                    if (actions.ContainsKey(par.ParameterType))
                    {
                        throw new Exception("Parameter type already exists on another action - " + x.Method.DeclaringType + ", " + x.Method.Name + ", " + par.ParameterType);
                    }

                    actions.Add(par.ParameterType, new ActionInfo()
                    {
                        ClassType = x.Method.DeclaringType,
                        HttpMethod = x.Method.GetAttribute<HttpPostAttribute>() != null ? "post" : "get",
                        Name = x.Method.Name,
                        Controller = x.Controller,
                        Action = x.Action
                    });

                    x.Route.Name = par.ParameterType.FullName;
                    routes.Add(x.Route.Name, route);
                });

            return routes;
        }
Ejemplo n.º 7
0
        public static RouteCollection MapRoutes(this RouteCollection routes, Assembly assembly, ActionDictionary actions)
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }

            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            assembly.GetTypes()
            // Find all non abstract classes of type Controller and whose names end with "Controller"
            .Where(x => x.IsClass && !x.IsAbstract && x.IsSubclassOf(typeof(Controller)) && x.Name.EndsWith("Controller"))

            // Find all public methods from those controller classes
            .SelectMany(x => x.GetMethods(), (x, y) => new { Controller = x.Name, Method = y, Namespace = x.Namespace })

            // Find all route attributes from those methods
            .SelectMany(x => x.Method.GetCustomAttributes(typeof(RouteAttribute), false),
                        (x, y) => new { Controller = x.Controller.Substring(0, x.Controller.Length - 10), Action = x.Method.Name, Method = x.Method, Namespace = x.Namespace, Route = (RouteAttribute)y })

            // Order selected entires by rank number and iterate through each of them
            .OrderBy(x => x.Route.Order == -1).ThenBy(x => x.Route.Order).ToList().ForEach(x =>
            {
                // Set Defautls
                var defaults = ParseRouteValues(x.Route.Defaults);
                defaults.Add("controller", x.Controller);
                defaults.Add("action", x.Action);

                // Set Optional Parameters and remove '?' mark from the url
                Match m;

                while ((m = Regex.Match(x.Route.Url, @"\{([^\}]+?)\?\}")) != null && m.Success)
                {
                    var p = m.Groups[1].Value;
                    defaults.Add(p, UrlParameter.Optional);
                    x.Route.Url = x.Route.Url.Replace("{" + p + "?}", "{" + p + "}");
                }

                // Set Defautls
                var constraints = ParseRouteValues(x.Route.Constraints);

                // Set Data Tokens
                var dataTokens = new RouteValueDictionary();
                dataTokens.Add("Namespaces", new string[] { x.Namespace });

                var route = new Route(x.Route.Url, new MvcRouteHandler())
                {
                    Defaults    = defaults,
                    Constraints = constraints,
                    DataTokens  = dataTokens
                };

                //Setup Actions
                var par = x.Method.GetParameters().FirstOrDefault();
                if (par == null)
                {
                    throw new Exception("No Parameter found for action - " + x.Method.DeclaringType + ", " + x.Method.Name);
                }

                if (actions.ContainsKey(par.ParameterType))
                {
                    throw new Exception("Parameter type already exists on another action - " + x.Method.DeclaringType + ", " + x.Method.Name + ", " + par.ParameterType);
                }

                actions.Add(par.ParameterType, new ActionInfo()
                {
                    ClassType  = x.Method.DeclaringType,
                    HttpMethod = x.Method.GetAttribute <HttpPostAttribute>() != null ? "post" : "get",
                    Name       = x.Method.Name,
                    Controller = x.Controller,
                    Action     = x.Action
                });

                x.Route.Name = par.ParameterType.FullName;
                routes.Add(x.Route.Name, route);
            });

            return(routes);
        }