public AppCommands()
 {
     AllCommands.Add(new GammaCommand());
     AllCommands.Add(new AlphaCommand());
     AllCommands.Add(new BetaCommand());
     AllCommands.Add(new ThetaCommand());
 }
Beispiel #2
0
        public static void PopulateCommands()
        {
            var FullNames = Assembly.GetExecutingAssembly().GetTypes().Where(x => x.IsClass && x.Namespace == "socon.Commands.CP").Select(x => x).Where(x => x.Attributes == TypeAttributes.BeforeFieldInit);

            Debug.Assert(!FullNames.Select(x => x.Name).Contains("Alias"));

            ConfigObject commandsList = null;

            if (!(Settings.Global?.Commands is null) && Settings.GlobalNonDynamic != null)
            {
                commandsList = ((ConfigObject)Settings.GlobalNonDynamic["Commands"]);
            }

            FullNames.ToList().ForEach(x => AllCommands.Add(new Command(x)));

            /*foreach (var c in FullNames) {
             *      Command toAdd = new Command(c);
             *      if (commandsList != null && commandsList.ContainsKey(c)) {
             *              dynamic properties = ((dynamic)commandsList[c]);
             *
             *              try {
             *                      if (!(properties.Regex as string is null))
             *                              toAdd.Regex = new Regex(properties.Regex, RegexOptions.Compiled);
             *              } catch (Exception ex) {
             *                      Debug.WriteLine("Failed to compile regex (1):\n" + ex);
             *              }
             *
             *              try {
             *                      if (!(properties.UsageTrigger as string is null))
             *                              toAdd.UsageTrigger = new Regex(properties.UsageTrigger, RegexOptions.Compiled);
             *              } catch (Exception ex) {
             *                      Debug.WriteLine("Failed to compile regex (2):\n" + ex);
             *              }
             *
             *              toAdd.Usage = properties.Usage as string ?? "";
             *      }
             *      AllCommands.Add(toAdd);
             * }*/

            string key = "";

            foreach (var kv in ((dynamic)commandsList)?.Alias)
            {
                if (key == "")
                {
                    key = kv;
                }
                else
                {
                    try {
                        Aliases.Add(new Regex(key, RegexOptions.Compiled), kv);
                    } catch (Exception ex) {
                        Debug.WriteLine("Failed to compile regex (3):\n" + ex);
                    }
                    key = "";
                }
            }
        }
Beispiel #3
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 #4
0
        private void InitializeCommands()
        {
            foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (!type.IsSubclassOf(typeof(CommandBase)) || type.IsAbstract)
                {
                    continue;
                }

                var instance = (CommandBase)Activator.CreateInstance(type, new object[] { this });

                if (instance.Command != "TEMPLATE")
                {
                    AllCommands.Add(instance);
                }
            }

            AllCommands = AllCommands.OrderBy(c => c.Command).ToList();
        }