예제 #1
0
        public CommandResult ProcessCommand(string commands)
        {
            ICommandInput cmd = CommandBuilder.GetCommandInput(commands);

            if (cmd.CommandName == CommandNames.Add)
            {
                return(DomainRouter.AddCommand(cmd));
            }
            if (cmd.CommandName == CommandNames.Delete)
            {
                return(DomainRouter.DeleteCommand(cmd));
            }
            if (cmd.CommandName == CommandNames.View)
            {
                return(DomainRouter.GetCommand(cmd));
            }
            if (cmd.CommandName == CommandNames.Update)
            {
                return(DomainRouter.UpdateCommand(cmd));
            }
            if (cmd.CommandName == CommandNames.Help)
            {
                return(DomainRouter.HelpCommand(cmd));
            }
            else
            {
                return(ResultBuilder.Build(cmd, "Unable To Find Command", false, null));
            }
        }
        public ICommandResult Simulate(ICommandInput commandInput, Unit unit)
        {
            CommandInput_UseSkill input_UseSkill = commandInput as CommandInput_UseSkill;

            if (!SkillHelper.tempData.ContainsKey((unit, input_UseSkill.pipelineSignal)))
            {
                SkillHelper.tempData[(unit, input_UseSkill.pipelineSignal)] = new Dictionary <Type, IBufferValue>();
        public RemoteControlProgram(RepairDroid repairDroid, ICommandInput commandInput, IView consoleView)
        {
            _relativePosition = Coordinate.Origin;
            _lastPosition     = _relativePosition;

            _movementCommand            = (MovementCommand)(-1);
            commandInput.InputReceived += (_, v) => _movementCommand = (MovementCommand)v;

            repairDroid.OnReply += (_, msg) =>
            {
                switch (msg)
                {
                case RepairDroidStatusCode.HitWall:
                    consoleView.Write(GetNewLocation(_relativePosition), '#');

                    break;

                case RepairDroidStatusCode.Moved:
                    consoleView.Write(_relativePosition, '.');
                    Move();
                    consoleView.Write(_relativePosition, 'D');
                    break;

                case RepairDroidStatusCode.MovedAndFoundOxygenSystem:
                    Move();
                    FoundOxygenSystem?.Invoke(this, _relativePosition);
                    _run = false;
                    break;
                }
                ;
            };
            _repairDroid  = repairDroid;
            _commandInput = commandInput;
        }
        public void DispatchCommand(ICommandInput commandInput)
        {
            ICommand cmd;

            if ((cmd = CommandsCatalog.FindByName(commandInput.CommandName)) == null && DefaultCommand == null)
            {
                Console.WriteLine("'{0}' command not found", commandInput.CommandName);
                return;
            }

            if (cmd == null)
            {
                cmd          = DefaultCommand;
                commandInput = commandInput.ToDefaultCommand(DefaultCommand.Name);
            }

            if (DebugMode || Debugger.IsAttached)
            {
                DispatchCommandWithoutErrorHandling(commandInput, cmd);
            }
            else
            {
                DispatchCommandWithErrorHandling(commandInput, cmd);
            }
        }
예제 #5
0
        public override async Task OnExecute(ICommandInput input)
        {
            await Client.SendChatActionAsync(input.ChatId, ChatAction.Typing);

            await Task.Delay(1000);

            await Client.SendTextMessageAsync(input.ChatId, _messagesService.GetPhrase());
        }
예제 #6
0
        public override async Task OnExecute(ICommandInput input)
        {
            await Client.SendChatActionAsync(input.ChatId, ChatAction.Typing);

            var rate = await RateService.GetTodayUsdRate();

            var t = await Client.SendTextMessageAsync(input.ChatId, $"Rate: {rate.Rate}");
        }
예제 #7
0
 public AddDomainAProcessor(ICommandInput cmd)
 {
     this.CommandTransctionId = cmd.CommandTransctionId;
     this.CommandName         = cmd.CommandName;
     this.Command             = cmd.Command;
     this.Inputs = cmd.Inputs;
     // if We Have DI then it will be better Since at MediatR we can reduce Dependency Injection
     _Engine = new DomainAEngine();
 }
예제 #8
0
 public DeleteDomainAProcessor(ICommandInput cmd)
 {
     this.CommandTransctionId = cmd.CommandTransctionId;
     this.CommandName         = cmd.CommandName;
     this.Command             = cmd.Command;
     this.Inputs = cmd.Inputs;
     // if We Have DI then it will be better
     _Engine = new DomainAEngine();
 }
        public static ICommandInput ToDefaultCommand(this ICommandInput cmdInput, string name)
        {
            var parameters = new List <ParsedParameter>(cmdInput.InputParameters.Count + 1)
            {
                new ParsedParameter(0, null, cmdInput.CommandName)
            };

            parameters.AddRange(cmdInput.InputParameters.Select(p => new ParsedParameter(p.PositionIndex + 1, p.Name, p.Value)));
            return(new ParsedCommand(name, parameters));
        }
예제 #10
0
        private static void Recycle(ICommandInput commandInput)
        {
            Type type = commandInput.GetType();

            if (!commandInputs.ContainsKey(type))
            {
                commandInputs[type] = new Queue <ICommandInput>();
            }
            commandInputs[type].Enqueue(commandInput);
        }
 private void DispatchCommandWithErrorHandling(ICommandInput commandInput, ICommand cmd)
 {
     try
     {
         DispatchCommandWithoutErrorHandling(commandInput, cmd);
     }
     catch (Exception ex)
     {
         CommandErrorHandler(ex);
     }
 }
예제 #12
0
        public static void WriteCommandExecution(ICommandInput cmd)
        {
            Console.WriteLine("Executing command: {0}", cmd.CommandName);

            foreach (var arg in cmd.InputParameters)
            {
                Trace.Indent();
                Trace.WriteLine($"#{arg.PositionIndex} {arg.Name ?? "(anonymous)"}: {arg.Value}");
                Trace.Unindent();
            }
        }
예제 #13
0
        public override async Task OnExecute(ICommandInput input)
        {
            await Client.SendChatActionAsync(input.ChatId, ChatAction.Typing);

            var inputMessage = input.Text;
            var messageParts = inputMessage.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var city         = messageParts.Length == 1 ? "Minsk" : messageParts.Skip(1).First();
            var weather      = await WeatherService.GetWeatherForCityAsync(city);

            var t = await Client.SendTextMessageAsync(input.ChatId, $"In {city} {weather.Description} and the temperature is {weather.Temperature:+#;-#}°C");
        }
예제 #14
0
        public static CommandResult AddCommand(ICommandInput cmd)
        {
            switch (cmd.Inputs["message_1"])
            {
            case "DomainA":
                return(new AddDomainAProcessor(cmd).Process());

            default:
                return(ResultBuilder.Build(cmd, "Unable To Process Command", false, null));
            }
        }
예제 #15
0
 public static CommandResult Build(ICommandInput input, string message, bool isSuccess = true, Object objectResult = null)
 {
     return(new CommandResult()
     {
         Command = input.Command,
         CommandName = input.CommandName,
         CommandResultId = Guid.NewGuid(),
         CommandTransactionId = input.CommandTransctionId,
         IsContainException = false,
         IsSuccess = isSuccess,
         Message = message,
         Result = objectResult
     });
 }
예제 #16
0
        public Task <bool> Check(ICommandInput input)
        {
            if (input.MessageType != MessageType.TextMessage)
            {
                return(Task.FromResult(false));
            }

            if (string.IsNullOrEmpty(input.Text))
            {
                return(Task.FromResult(false));
            }

            return(Task.FromResult(input.Text.ToLowerInvariant().StartsWith("/weather")));
        }
예제 #17
0
        public void CollectCommandInput(ICommandInput input)
        {
            CharacterStateComponent property_CharacterState = GetParent <Unit>().GetComponent <CharacterStateComponent>();

            if (property_CharacterState.Get(SpecialStateType.CantDoAction) || property_CharacterState.Get(SpecialStateType.NotInControl))
            {
                return;
            }
            collectedNewInput = true;
            Command command = CommandGCHelper.GetCommand();

            command.commandInput          = input;
            currCommands[input.GetType()] = command;
        }
예제 #18
0
        public static CommandResult HelpCommand(ICommandInput cmd)
        {
            if (cmd.Inputs.Count == 0)
            {
                return(ResultBuilder.Build(cmd, "Unable To Process Help Command : Please include <domainname> that you would like to request help about", false, null));
            }
            switch (cmd.Inputs["message_1"])
            {
            case "DomainA":
                return(new HelpDomainAProcessor(cmd).Process());

            default:
                return(ResultBuilder.Build(cmd, "Unable To Process Command", false, null));
            }
        }
예제 #19
0
        public ICommandResult Simulate(ICommandInput commandInput, Unit unit)
        {
            CommandInput_Move input_Move        = commandInput as CommandInput_Move;
            UnitPathComponent unitPathComponent = unit.GetComponent <UnitPathComponent>();

            PathfindingComponent pathfindingComponent = Game.Scene.GetComponent <PathfindingComponent>();

            unitPathComponent.ABPath = ComponentFactory.Create <ABPathWrap, Vector3, Vector3>(unit.Position, input_Move.clickPos);
            pathfindingComponent.Search(unitPathComponent.ABPath);

            CommandResult_Move result_Move = CommandGCHelper.GetCommandResult <CommandResult_Move>();

            result_Move.Path = unitPathComponent.ABPath.Result;
            // result_Move.dir = input_Move.moveDir;// 暂时就以输入的方向作为角色的方向
            return(result_Move);
        }
예제 #20
0
        public async Task <bool> Execute(ICommandInput input)
        {
            Logger.Info($"I'm trying to execute {GetType()}");
            try
            {
                await OnExecute(input);

                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Something went wrong");
                return(false);
            }

            //Context.LastCommandId = Id;
        }
        private void DispatchCommandWithoutErrorHandling(ICommandInput commandInput, ICommand cmd)
        {
            if (EnableTrace)
            {
                Trace.Indent();
                Tracer.WriteCommandExecution(commandInput);
            }

            using (var context = _commandContextFactory.CreateContext(commandInput))
            {
                cmd.Execute(context);
            }

            if (EnableTrace)
            {
                Trace.Unindent();
            }
        }
예제 #22
0
 public async Task CommitAsync(ICommandInput commands, string commitMessage)
 {
     await Task.Run(async() => {
         if (Status != RepoStatus.RepoFoundWithChanges)
         {
             return;
         }
         Status        = RepoStatus.ProcessingCommit;
         string toRun  = $"commit -a -m \"{commitMessage}\"";
         string result = await commands.RunProcessAsync("git", toRun);
         if (result.Contains(commitMessage))
         {
             Status = RepoStatus.CommitSucceeded;
         }
         else
         {
             Status = RepoStatus.CommitFailed;
         }
     });
 }
예제 #23
0
        public async static Task <IRepoControl> GetRepoControllerAsync(ICommandInput commandInput)
        {
            IRepoControl controller = null;
            await Task.Run(() =>
            {
                controller = new Mercurial();
                if (controller.Exists(commandInput))
                {
                    return;
                }
                controller = new Git();
                if (controller.Exists(commandInput))
                {
                    return;
                }
                controller = null;
            });

            return(controller);
        }
예제 #24
0
        public RepairDroid(IntCodeStateMachine cpu, ICommandInput commandInput)
        {
            _cpu          = cpu;
            _commandInput = commandInput;
            _commandInput.InputReceived += (_, v) =>
            {
                var cmd = (MovementCommand)v;
                if (v < 1 || v > 4)
                {
                    throw new Exception("Wrong input value");
                }
                _cpu.SetInput((int)cmd);
            };

            _cpu.OnOutput += (_, o) =>
            {
                _lastOutput = (RepairDroidStatusCode)o;
                OnReply?.Invoke(this, _lastOutput);
                commandInput.AwaitInput();
            };
        }
예제 #25
0
 public async Task CommitAsync(ICommandInput commands, string commitMessage)
 {
     await Task.Run(async() => {
         if (Status != RepoStatus.RepoFoundWithChanges)
         {
             return;
         }
         Status       = RepoStatus.ProcessingCommit;
         string toRun = $"commit -m \"{commitMessage}\"";
         //Add new files to repo and remove deleted files from repo.
         await commands.RunProcessAsync("hg", "addremove");
         string result = await commands.RunProcessAsync("hg", toRun);
         if (String.IsNullOrWhiteSpace(result))
         {
             Status = RepoStatus.CommitSucceeded;
         }
         else
         {
             Status = RepoStatus.CommitFailed;
         }
     });
 }
예제 #26
0
        public bool Exists(ICommandInput commands)
        {
            Task <string> task = commands.RunProcessAsync("git", "status");

            task.Wait();
            string result = task.Result;

            task.Dispose();
            if (result.Contains(GitMessageNoRepo))
            {
                Status = RepoStatus.NoRepoFound;
                return(false);
            }
            else if (String.IsNullOrWhiteSpace(result))
            {
                Status = RepoStatus.RepoFoundNoChanges;
            }
            else
            {
                Status = RepoStatus.RepoFoundWithChanges;
            }
            return(true);
        }
 public ICommandContext CreateContext(ICommandInput commandInput)
 {
     return(new SimpleCommandContext(commandInput));
 }
예제 #28
0
        public static void GetInput(this UnitStateComponent unitStateComponent, int frame, ICommandInput commandInput)
        {
            try
            {
                //unitStateComponent.collectInput = true;
                //if (unitStateComponent.currGetInputFrame < frame)
                //    unitStateComponent.currGetInputFrame = frame;
                //UnitStateDelta unitStateDelta = new UnitStateDelta();
                //unitStateDelta.frame = frame;

                var result = Game.Scene.GetComponent <CommandSimulaterComponent>().commandSimulaters[commandInput.GetType()].Simulate(commandInput, unitStateComponent.unit);
                switch (result)
                {
                case CommandResult_Move result_Move:
                    unitStateComponent.unit.GetComponent <CharacterMoveComponent>().MoveAsync(result_Move.Path).Coroutine();

                    unitStateComponent.inputResult_Move.Frame    = frame;
                    unitStateComponent.inputResult_Move.Id       = unitStateComponent.unit.Id;
                    unitStateComponent.inputResult_Move.PathList = new Google.Protobuf.Collections.RepeatedField <Vector3Info>();
                    for (int i = 0; i < result_Move.Path.Count; i++)
                    {
                        unitStateComponent.inputResult_Move.PathList.Add(new Vector3Info()
                        {
                            X = result_Move.Path[i].x,
                            Y = result_Move.Path[i].y,
                            Z = result_Move.Path[i].z
                        });
                    }
                    MessageHelper.Broadcast(unitStateComponent.inputResult_Move);
                    break;

                case CommandResult_UseSkill result_UseSkill:

                    bool checkResult = unitStateComponent.unit.GetComponent <ActiveSkillComponent>().CheckCanUse(result_UseSkill.skillId);
                    if (checkResult)
                    {
                        unitStateComponent.unit.GetComponent <ActiveSkillComponent>().Execute(result_UseSkill.skillId).Coroutine();
                    }
                    switch ((commandInput as CommandInput_UseSkill).bufferValue)
                    {
                    case BufferValue_Dir bufferValue_Dir:
                        unitStateComponent.useSkill_Dir.SkillId        = result_UseSkill.skillId;
                        unitStateComponent.useSkill_Dir.Success        = checkResult;
                        unitStateComponent.useSkill_Dir.Id             = unitStateComponent.unit.Id;
                        unitStateComponent.useSkill_Dir.PipelineSignal = (commandInput as CommandInput_UseSkill).pipelineSignal;
                        unitStateComponent.useSkill_Dir.Dir            = bufferValue_Dir.dir.ToV3Info();
                        MessageHelper.Broadcast(unitStateComponent.useSkill_Dir);
                        break;
                    }
                    break;
                }
                //unitStateDelta.commandResults.Add(result.GetType(), result);
                //unitStateComponent.unitStatesDic[unitStateComponent.currGetInputFrame] = unitStateDelta;
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
        }
예제 #29
0
 public abstract Task OnExecute(ICommandInput input);
 public SimpleCommandContext(ICommandInput commandInput)
 {
     CommandInput = commandInput;
 }