public AdminCommandsHelperViewModel()
        {
            CreateNewOrEditExistingCommandCommand = new CreateNewOrEditExistingCommandCommand(this);
            CancelAndClearCommandActionCommand    = new CancelAndClearCommandActionCommand(this);
            RemoveCommandCommand           = new RemoveCommandCommand(this);
            UpdateAvaliableCommandsCommand = new UpdateAvaliableCommandsCommand(this);
            LoadCommandForEditionCommand   = new LoadCommandForEditionCommand(this);

            Commands         = new ObservableCollection <CommandInfoModel>();
            DisplayedCommand = new CommandInfoModel();

            if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                #region Design Placeholders
                DisplayedCommand = new CommandInfoModel("sm_ban", "bans player", "<player> <time> <reason>");

                EditMode = true;
                Commands.Add(new CommandInfoModel("sm_ban", "bans player", "<player> <time> <reason>"));
                Commands.Add(new CommandInfoModel("sm_ban", "bans player", "<player> <time> <reason>"));
                Commands.Add(new CommandInfoModel("sm_ban", "bans player", "<player> <time> <reason>"));
                #endregion
            }
            else
            {
                UpdateCommands();
            }
        }
Beispiel #2
0
        public static IList <ModuleInfoModel> GetModules()
        {
            var result = new List <ModuleInfoModel>();

            foreach (var module in Modules)
            {
                var modProps = AllFields.Where(x => x.Name.StartsWith(module, System.StringComparison.OrdinalIgnoreCase));

                var modName = modProps.Where(x => x.Name.EndsWith("module", System.StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                var modId   = modProps.Where(x => x.Name.EndsWith("_id", System.StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                var mod = new ModuleInfoModel()
                {
                    Name     = GetText(modName?.GetValue("").ToString()) ?? "",
                    Id       = (ModuleEnum)modId?.GetValue(ModuleEnum.Help),
                    Commands = new List <CommandInfoModel>()
                };

                foreach (var command in modProps.Where(x => x.Name.EndsWith("command", System.StringComparison.OrdinalIgnoreCase)).ToList())
                {
                    var propName = command.Name.Split('_')[1];
                    var aliases  = new List <string>();

                    foreach (var alias in modProps.Where(x => x.Name.ToLowerInvariant().Contains(propName.ToLowerInvariant()) && x.Name.ToLowerInvariant().Contains("alias")).ToList())
                    {
                        aliases.Add(alias.GetValue("").ToString());
                    }

                    var commandName    = modProps.Where(x => x.Name.EndsWith($"{propName}_Name", System.StringComparison.OrdinalIgnoreCase)).FirstOrDefault()?.GetValue("").ToString() ?? "";
                    var commandSummary = modProps.Where(x => x.Name.EndsWith($"{propName}_Summary", System.StringComparison.OrdinalIgnoreCase)).FirstOrDefault()?.GetValue("").ToString() ?? "";
                    var examples       = modProps.Where(x => x.Name.ToLowerInvariant().Contains($"{propName.ToLowerInvariant()}_example")).Select(x => GetText(x.GetValue("").ToString())).ToList() ?? new List <string>();

                    var commandInfoModel = new CommandInfoModel
                    {
                        Name        = GetText(commandName),
                        Command     = propName,
                        Description = "",
                        Alias       = aliases,
                        Fields      = new List <FieldInfoModel>(),
                        Examples    = new List <string>()
                    };

                    commandInfoModel = ProcessDescription(commandInfoModel, GetText(commandSummary));

                    mod.Commands.Add(commandInfoModel);
                }

                result.Add(mod);
            }

            return(result);
        }
Beispiel #3
0
        public void Execute(object parameter)
        {
            var command = parameter as CommandInfoModel;

            if (command.Id == VM.DisplayedCommand.Id)
            {
                VM.DisplayedCommand.Clear();
                VM.EditMode = false;
            }

            CommandInfoModel.DeleteOne(command);
            VM.UpdateCommands();
        }
        public void UpdateCommands()
        {
            var commands = CommandInfoModel.GetAll();

            Commands.Clear();

            foreach (var command in commands)
            {
                if (!Commands.Contains(command))
                {
                    Commands.Add(command);
                }
            }
        }
        public bool CanExecute(object parameter)
        {
            if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                return(true);
            }

            if (parameter == null)
            {
                return(false);
            }

            var model = (parameter as CommandInfoModel);

            return(VM.EditMode ? true : !CommandInfoModel.CommandOrIdExists(VM.DisplayedCommand));
        }
        public void Execute(object parameter)
        {
            if (VM.EditMode)
            {
                CommandInfoModel.UpdateOne(VM.DisplayedCommand);
            }
            else
            {
                CommandInfoModel.InsertOne(VM.DisplayedCommand);
            }

            VM.EditMode = false;
            VM.UpdateCommands();
            VM.DisplayedCommand.Clear();

            Variables.CommandAddedOrUpdated = true;
        }
Beispiel #7
0
        public void LoadCommands()
        {
            var commands = CommandInfoModel.GetAll();

            Application.Current.Dispatcher.Invoke(delegate
            {
                AllCommands.Clear();
            });

            foreach (var command in commands)
            {
                Application.Current.Dispatcher.Invoke(delegate
                {
                    AllCommands.Add(command);
                });
            }
        }
Beispiel #8
0
        public static CommandInfoModel GetCommandInfo(string commandname)
        {
            var result = new CommandInfoModel()
            {
                Name        = "Not found",
                Description = "",
                Fields      = new List <FieldInfoModel>(),
                Examples    = new List <string>()
            };

            var command = AllFields.Where(x => x.FieldType == typeof(string) && x.GetValue("").ToString().Equals(commandname, System.StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (command != null)
            {
                var split          = command.Name.Split('_');
                var cmd            = split[1];
                var commandPrefix  = $"{split[0]}_{cmd}";
                var commandName    = AllFields.Where(x => x.Name.EndsWith($"{commandPrefix}_Name", System.StringComparison.OrdinalIgnoreCase)).FirstOrDefault()?.GetValue("").ToString() ?? "";
                var commandSummary = AllFields.Where(x => x.Name.EndsWith($"{commandPrefix}_Summary", System.StringComparison.OrdinalIgnoreCase)).FirstOrDefault()?.GetValue("").ToString() ?? "";
                var examples       = AllFields.Where(x => x.Name.ToLowerInvariant().Contains($"{commandPrefix.ToLowerInvariant()}_example")).Select(x => GetText(x.GetValue("").ToString())).ToList() ?? new List <string>();
                var aliases        = new List <string>();

                foreach (var alias in AllFields.Where(x => x.Name.ToLowerInvariant().Contains(commandPrefix.ToLowerInvariant()) && x.Name.ToLowerInvariant().Contains("alias")).ToList())
                {
                    aliases.Add(alias.GetValue("").ToString());
                }

                result.Name    = GetText(commandName);
                result.Command = cmd;
                result.Alias   = aliases;

                result = ProcessDescription(result, GetText(commandSummary));
            }

            return(result);
        }
Beispiel #9
0
        private static CommandInfoModel ProcessDescription(CommandInfoModel model, string summary)
        {
            var fields = GetSubstring(summary, "fields");
            var descr  = summary;

            if (string.IsNullOrWhiteSpace(summary))
            {
                return(model);
            }

            var indexOf = summary.IndexOf("{fields");

            if (indexOf <= 0)
            {
                indexOf = summary.IndexOf("{examples");
            }

            if (indexOf > 0)
            {
                descr = descr.Substring(0, indexOf);
            }

            if (!string.IsNullOrWhiteSpace(fields))
            {
                var maxFields = 0;
                while (fields.Length > 0 && maxFields < 100)
                {
                    var field = GetSubstring(fields, "field");
                    if (string.IsNullOrWhiteSpace(field))
                    {
                        break;
                    }

                    fields = fields.Replace($"{{field}}{field}{{/field}}", "");

                    var name  = GetSubstring(field, "name");
                    var value = GetSubstring(field, "value");

                    model.Fields.Add(new FieldInfoModel
                    {
                        Name  = name,
                        Value = value
                    });

                    maxFields++;
                }
            }

            var examples = GetSubstring(summary, "examples");

            if (!string.IsNullOrWhiteSpace(examples))
            {
                var maxExamples = 0;
                while (examples.Length > 0 && maxExamples < 100)
                {
                    var example = GetSubstring(examples, "example");
                    if (string.IsNullOrWhiteSpace(example))
                    {
                        break;
                    }

                    examples = examples.Replace($"{{example}}{example}{{/example}}", "");

                    model.Examples.Add(example);

                    maxExamples++;
                }
            }

            model.Description = descr;

            return(model);
        }