Esempio n. 1
0
        public ConfModule()
        {
            this.RequiresAuthentication();

            Post["/cfg/addvalue"] = x => {
                var tag   = (string)Request.Form.Tag;
                var key   = (string)Request.Form.Key;
                var value = (string)Request.Form.Value;
                if (key.Length > 0)
                {
                    ConfigManagement.AddValuesBundle(tag, key, value);
                }
                else
                {
                    ConfigManagement.AddValuesBundle(tag, value);
                }
                return(Response.AsRedirect("/"));
            };

            Post["/cfg/delvalue"] = x => {
                var tag   = (string)Request.Form.Tag;
                var key   = (string)Request.Form.Key;
                var value = (string)Request.Form.Value;
                ConfigManagement.DeleteValuesBundle(tag, key, value);
                return(Response.AsRedirect("/"));
            };

            Get["/cfg/tags"] = x => {
                var data = ConfigManagement.GetTagsBundleValue();
                var map  = SelectizerMapModel.MapRawTagOfValueBundle(data);
                return(Response.AsJson(map));
            };

            Post["/cfg/addcommand"] = x => {
                var command = (string)Request.Form.Command;
                if (command.Length > 0)
                {
                    ConfigManagement.AddCommandsBundle(command);
                }
                return(Response.AsRedirect("/"));
            };

            Post["/cfg/delcommand"] = x => {
                var guid = (string)Request.Form.Guid;
                ConfigManagement.DeleteCommandsBundle(guid);
                return(Response.AsRedirect("/"));
            };

            Post["/cfg/enablecommand"] = x => {
                var guid = (string)Request.Form.Guid;
                ConfigManagement.EnableCommand(guid);
                return(Response.AsJson(true));
            };

            Post["/cfg/disablecommand"] = x => {
                var guid = (string)Request.Form.Guid;
                ConfigManagement.DisableCommand(guid);
                return(Response.AsJson(true));
            };

            Post["/cfg/launchcommand"] = x => {
                var guid = (string)Request.Form.Guid;
                ConfigManagement.LaunchCommand(guid);
                return(Response.AsRedirect("/"));
            };

            Post["/cfg/reindex"] = x => {
                var guid    = (string)Request.Form.Guid;
                var index   = (string)Request.Form.Index;
                var guids   = guid.Split(',');
                var indexes = index.Split(',');
                for (var i = 0; i < guids.Length; i++)
                {
                    ConfigManagement.AssignIndexToCommandsBundle(guids[i], indexes[i]);
                }
                return(Response.AsRedirect("/"));
            };

            Get["/cfg/getenabled"] = x => {
                var data = ConfigManagement.GetCommandsBundle().Where(_ => _.IsEnabled);
                return(Response.AsJson(data));
            };

            Get["/cfg/layouts"] = x => {
                var data = ConfigManagement.GetCommandsBundleLayout();
                var map  = SelectizerMapModel.MapRawCommandBundleLayout(data);
                return(Response.AsJson(map));
            };

            Post["/cfg/export"] = x => {
                ConfigManagement.Export.ExportConfigurationToFile();
                return(Response.AsJson(true));
            };
        }