public AppCommands()
 {
     AllCommands.Add(new GammaCommand());
     AllCommands.Add(new AlphaCommand());
     AllCommands.Add(new BetaCommand());
     AllCommands.Add(new ThetaCommand());
 }
Ejemplo n.º 2
0
        internal void ReplayAllCommands()
        {
            // reverse
            var playBackCommands = new List <INoteCommand>();

            foreach (var command in AllCommands)
            {
                if (playBackCommands.Count == 0)
                {
                    playBackCommands.Add(command);
                }
                else
                {
                    playBackCommands.Insert(0, command);
                }
            }

            this.DisplayNotes.Clear();
            AllCommands.Clear();
            DisplayCommands.Clear();

            foreach (var command in playBackCommands)
            {
                Task.Delay(250).Wait();
                ReplayCommand(command);
            }
        }
Ejemplo n.º 3
0
 public CommandService(IBotService botService, IServiceProvider serviceProvider, UnknownCommand unknownCommand, AllCommands allCommands)
 {
     this.botService      = botService;
     this.serviceProvider = serviceProvider;
     this.unknownCommand  = unknownCommand;
     this.allCommands     = allCommands;
     commands             = serviceProvider.GetServices <ICommand>();
 }
        public async Task ThrowsIfcontextIsNull()
        {
            await Assert.ThrowsAsync <ArgumentException>(async() => await AllCommands.CreateAsync(null));

            await Assert.ThrowsAsync <ArgumentException>(async() => await AllCommands.DeleteAsync(null));

            await Assert.ThrowsAsync <ArgumentException>(async() => await AllCommands.UpdateAsync(null));
        }
Ejemplo n.º 5
0
 internal void ShowAllNotes()
 {
     DisplayCommands.Clear();
     foreach (var command in AllCommands.OrderByDescending(o => o.CreatedOn))
     {
         DisplayCommands.Add(command);
     }
 }
Ejemplo n.º 6
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 = "";
                }
            }
        }
Ejemplo n.º 7
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            var model = new AllCommands
            {
                Commands = _hardcodedCommands.Commands
            };

            return(View(model));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Runs the command with the given name using the given arguments.
        /// </summary>
        /// <param name="commandName">Name of the command.</param>
        /// <param name="arguments">Arguments of the command.</param>
        /// <param name="reportErrorsToConsole">True to print exceptions in the console.  False to throw the exception.</param>
        public async Task RunCommand(string commandName, IEnumerable <string> arguments, bool reportErrorsToConsole = false, IFileSystem FileSystem = null)
        {
            var command = AllCommands.Where(c => String.Compare(c.Key, commandName, StringComparison.CurrentCultureIgnoreCase) == 0).Select(c => c.Value).SingleOrDefault();

            if (FileSystem != null && CurrentPluginManager.CanCreateInstance(command.GetType()))
            {
                command = CurrentPluginManager.CreateNewInstance(command, FileSystem) as ConsoleCommand;
            }
            await RunCommand(command, arguments, reportErrorsToConsole);
        }
Ejemplo n.º 9
0
        private bool ProcessGroup(string command)
        {
            var commandGroupStrings = Enum.GetNames(typeof(CommandGroup)).ToList().Select(g => g.ToLower());

            if (!commandGroupStrings.Contains(command.ToLower()))
            {
                return(false);
            }

            List <CommandBase> toExecute;
            List <CommandBase> toExclude = new List <CommandBase>();

            foreach (var remainingCommand in Commands)
            {
                if (remainingCommand.StartsWith("-"))
                {
                    var foundCommand = AllCommands.FirstOrDefault(c => c.Command.Equals(remainingCommand.Substring(1), StringComparison.InvariantCultureIgnoreCase));
                    if (foundCommand != null)
                    {
                        toExclude.Add(foundCommand);
                    }
                }
            }

            switch (command.ToLower())
            {
            case "all":
                toExecute = AllCommands.ToList();
                break;

            default:
                CommandGroup commandGroup;
                try
                {
                    var groupName = Enum.GetNames(typeof(CommandGroup)).FirstOrDefault(c => c.ToLower() == command.ToLower());
                    commandGroup = (CommandGroup)Enum.Parse(typeof(CommandGroup), groupName);
                }
                catch (ArgumentException)
                {
                    return(false);
                }

                toExecute = AllCommands.Where(g => g.Group.Contains(commandGroup)).ToList();
                break;
            }

            var commandsFiltered = toExecute.Where(c => !toExclude.Contains(c)).ToList();

            commandsFiltered.ForEach(c =>
            {
                ExecuteCommand(c, new string[] { });
            });

            return(true);
        }
Ejemplo n.º 10
0
        public Command GetCommand(string id)
        {
            var command = AllCommands.SingleOrDefault(c => c.Id == id);

            if (command == null)
            {
                throw new CommandNotRegisteredException(id);
            }

            return(command);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Run the interpreter
        /// </summary>
        public GraphicGroup Run(StreamReader scriptStream, int postscriptVersion)
        {
            PrepareStandardDictionaries(postscriptVersion);
            AllCommands.Register(this);
            InitGraphic();

            FileReader = new EpsStreamReader(scriptStream);
            parser     = new Parser(FileReader);

            Run();

            return(ReturnGraphicGroup);
        }
Ejemplo n.º 12
0
        public async Task CreateAsyncHappyPath()
        {
            var request = new ConfigChangeRequest {
                Name = "name", Value = "value"
            };
            var context = new CommandContext(CommandTypes.Create, request, model);

            model.StoreEntityAsync(Arg.Any <ConfigEntity>()).Returns(true);
            var result = await AllCommands.CreateAsync(context);

            Assert.True(result.IsSuccess);
            Assert.Equal("name", result.Result.Name);
            Assert.Equal("value", result.Result.Value);
        }
Ejemplo n.º 13
0
        public async Task CreateAsyncStorageFailsReturnsStorageFailedOperationResult()
        {
            var request = new ConfigChangeRequest {
                Name = "name", Value = "value"
            };
            var context = new CommandContext(CommandTypes.Create, request, model);

            model.StoreEntityAsync(Arg.Any <ConfigEntity>()).Returns(false);
            var result = await AllCommands.CreateAsync(context);

            Assert.False(result.IsSuccess);
            Assert.Null(result.Result);
            Assert.Equal(ResultType.Forbidden, result.ResultType);
        }
Ejemplo n.º 14
0
 public AuthorizationCommand(
     IAuthorizationService authorizationService,
     IChatRepository chatRepository,
     IBotService botService,
     IAuthRepository authRepository,
     AllCommands allCommands,
     IBotWebApiService botWebApiService) : base(botService)
 {
     this.authorizationService = authorizationService;
     this.chatRepository       = chatRepository;
     this.authRepository       = authRepository;
     this.allCommands          = allCommands;
     this.botWebApiService     = botWebApiService;
 }
Ejemplo n.º 15
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);
                });
            }
        }
Ejemplo n.º 16
0
        /// <inheritdoc/>
        protected override bool ExecuteParent(ArraySegment <string> arguments, ICommandSender sender, out string response)
        {
            Player player = Player.Get((sender as PlayerCommandSender).ReferenceHub);

            string message = "\nPlease enter a valid subcommand:\n";

            foreach (var command in AllCommands.ToList())
            {
                if (player.CheckPermission($"sh.{command.Command}"))
                {
                    message += $"- {command.Command} ({command.Aliases[0]})\n";
                }
            }

            response = message;
            return(false);
        }
Ejemplo n.º 17
0
        public async Task DeleteAsyncConfigEntityNotFound()
        {
            var request = new ConfigChangeRequest {
                Name = "name", Value = "value"
            };
            var context  = new CommandContext(CommandTypes.Delete, request, model);
            var expected = new ConfigEntity {
                Name = "name", Value = "old"
            };

            model.GetEntityByNameAsync("name").Returns((ConfigEntity)null);

            var result = await AllCommands.DeleteAsync(context);

            Assert.False(result.IsSuccess);
            Assert.Null(result.Result);
            Assert.Equal(ResultType.NotFound, result.ResultType);
        }
Ejemplo n.º 18
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();
        }
Ejemplo n.º 19
0
        public async Task UpdateAsyncConfigEntityNotStored()
        {
            var request = new ConfigChangeRequest {
                Name = "name", Value = "value"
            };
            var context  = new CommandContext(CommandTypes.UpdateValue, request, model);
            var expected = new ConfigEntity {
                Name = "name", Value = "old"
            };

            model.GetEntityByNameAsync("name").Returns(expected);
            model.StoreEntityAsync(Arg.Any <ConfigEntity>()).Returns(false);

            var result = await AllCommands.UpdateAsync(context);

            Assert.False(result.IsSuccess);
            Assert.Null(result.Result);
            Assert.Equal(ResultType.Forbidden, result.ResultType);
        }
Ejemplo n.º 20
0
        public async Task UpdateAsyncHappyPath()
        {
            var request = new ConfigChangeRequest {
                Name = "name", Value = "value"
            };
            var context  = new CommandContext(CommandTypes.UpdateValue, request, model);
            var expected = new ConfigEntity {
                Name = "name", Value = "old"
            };

            model.GetEntityByNameAsync("name").Returns(expected);
            model.StoreEntityAsync(Arg.Any <ConfigEntity>()).Returns(true);
            var result = await AllCommands.UpdateAsync(context);

            await model.Received().StoreEntityAsync(Arg.Any <ConfigEntity>());

            Assert.True(result.IsSuccess);
            Assert.Equal("name", result.Result.Name);
            Assert.Equal("value", result.Result.Value);
        }
Ejemplo n.º 21
0
        private bool ProcessGroup(string command)
        {
            var commandGroupStrings = Enum.GetNames(typeof(CommandGroup)).ToList().Select(g => g.ToLower());

            if (!commandGroupStrings.Contains(command.ToLower()))
            {
                return(false);
            }

            List <CommandBase> toExecute;

            switch (command.ToLower())
            {
            case "all":
                toExecute = AllCommands;
                break;

            default:
                CommandGroup commandGroup;
                try
                {
                    var groupName = Enum.GetNames(typeof(CommandGroup)).FirstOrDefault(c => c.ToLower() == command.ToLower());
                    commandGroup = (CommandGroup)Enum.Parse(typeof(CommandGroup), groupName);
                }
                catch (ArgumentException)
                {
                    return(false);
                }

                toExecute = AllCommands.Where(g => g.Group.Contains(commandGroup)).ToList();
                break;
            }

            toExecute.ForEach(c =>
            {
                ExecuteCommand(c, new string[] { });
            });

            return(true);
        }
Ejemplo n.º 22
0
        private bool ProcessCommand(string commandLine)
        {
            var args = Shell32.CommandLineToArgs(commandLine);

            var commandName = args[0];
            var command     = AllCommands.FirstOrDefault(c => c.Command.Equals(commandName, StringComparison.InvariantCultureIgnoreCase));

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

            var commandArgs = new string[] { };

            if (args.Length > 1)
            {
                commandArgs = args.SubArray(1, args.Length - 1);
            }

            ExecuteCommand(command, commandArgs);

            return(true);
        }
Ejemplo n.º 23
0
        public async Task ThrowsOnWrongArgumentType(CommandTypes expected, CommandTypes incoming)
        {
            var context = new CommandContext(incoming, new ConfigChangeRequest()
            {
                Name = "name", Value = "value"
            }, model);

            if (expected == CommandTypes.Create)
            {
                await Assert.ThrowsAsync <ArgumentException>(async() => await AllCommands.CreateAsync(context));
            }
            else if (expected == CommandTypes.Delete)
            {
                await Assert.ThrowsAsync <ArgumentException>(async() => await AllCommands.DeleteAsync(context));
            }
            else if (expected == CommandTypes.UpdateValue)
            {
                await Assert.ThrowsAsync <ArgumentException>(async() => await AllCommands.UpdateAsync(context));
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 24
0
 private void R6_Checked(object sender, RoutedEventArgs e)
 {
     SelectedCommand = AllCommands.HeaterOff;
     this.Close();
 }
Ejemplo n.º 25
0
 public ConfigureBtnView()
 {
     InitializeComponent();
     SelectedCommand = AllCommands.None;
 }
Ejemplo n.º 26
0
 private void R8_Checked(object sender, RoutedEventArgs e)
 {
     SelectedCommand = AllCommands.DoorClose;
     this.Close();
 }
Ejemplo n.º 27
0
 public void Update()
 {
     Addin = AddinManagerService.GetAddin(Addin.AddinFile);
     AllCommands.Clear();
     AllCommands.AddRange(Addin.Commands);
 }
Ejemplo n.º 28
0
 private void AddCommand(INoteCommand noteCommand, INoteViewModel note)
 {
     AllCommands.Insert(0, noteCommand);
     DisplayCommands.Insert(0, noteCommand);
     note.Commands.Insert(0, noteCommand);
 }
Ejemplo n.º 29
0
 private void R10_Checked(object sender, RoutedEventArgs e)
 {
     SelectedCommand = AllCommands.ACDown;
     this.Close();
 }
Ejemplo n.º 30
0
        public void Help()
        {
            AllCommands commands = new AllCommands();

            commands.Command();
        }