public AppCommands()
 {
     AllCommands.Add(new GammaCommand());
     AllCommands.Add(new AlphaCommand());
     AllCommands.Add(new BetaCommand());
     AllCommands.Add(new ThetaCommand());
 }
예제 #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);
            }
        }
예제 #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));
        }
예제 #5
0
 internal void ShowAllNotes()
 {
     DisplayCommands.Clear();
     foreach (var command in AllCommands.OrderByDescending(o => o.CreatedOn))
     {
         DisplayCommands.Add(command);
     }
 }
예제 #6
0
파일: Commands.cs 프로젝트: TETYYS/socon
        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 = "";
                }
            }
        }
예제 #7
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            var model = new AllCommands
            {
                Commands = _hardcodedCommands.Commands
            };

            return(View(model));
        }
예제 #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);
        }
예제 #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);
        }
예제 #10
0
        public Command GetCommand(string id)
        {
            var command = AllCommands.SingleOrDefault(c => c.Id == id);

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

            return(command);
        }
예제 #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);
        }
        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);
        }
        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);
        }
예제 #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;
 }
예제 #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);
                });
            }
        }
예제 #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);
        }
        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);
        }
예제 #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();
        }
        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);
        }
        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);
        }
예제 #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);
        }
예제 #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);
        }
        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();
            }
        }
예제 #24
0
 private void R6_Checked(object sender, RoutedEventArgs e)
 {
     SelectedCommand = AllCommands.HeaterOff;
     this.Close();
 }
예제 #25
0
 public ConfigureBtnView()
 {
     InitializeComponent();
     SelectedCommand = AllCommands.None;
 }
예제 #26
0
 private void R8_Checked(object sender, RoutedEventArgs e)
 {
     SelectedCommand = AllCommands.DoorClose;
     this.Close();
 }
예제 #27
0
 public void Update()
 {
     Addin = AddinManagerService.GetAddin(Addin.AddinFile);
     AllCommands.Clear();
     AllCommands.AddRange(Addin.Commands);
 }
예제 #28
0
 private void AddCommand(INoteCommand noteCommand, INoteViewModel note)
 {
     AllCommands.Insert(0, noteCommand);
     DisplayCommands.Insert(0, noteCommand);
     note.Commands.Insert(0, noteCommand);
 }
예제 #29
0
 private void R10_Checked(object sender, RoutedEventArgs e)
 {
     SelectedCommand = AllCommands.ACDown;
     this.Close();
 }
예제 #30
0
        public void Help()
        {
            AllCommands commands = new AllCommands();

            commands.Command();
        }