private Command.Command FilterForStart(Command.Command command)
        {
            string lastArg = command.Arguments.Last().GetAsText();

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

            if (lastArg != "(")
            {
                return(command);
            }

            // Start of function block
            // Remove start function block syntax
            command.Arguments.RemoveAt(command.Arguments.Count - 1);

            // Add start function block argument
            var argument = new Argument(new OpenFunctionBlockToken());

            command.Arguments.Add(argument);

            return(command);
        }
        public Command.Command Filter(Command.Command command)
        {
            command = FilterForStart(command);
            command = FilterForEnd(command);

            return(command);
        }
示例#3
0
文件: Parser.cs 项目: crybx/mud
        public ICommand Parse(string text)
        {
            List <string> words = parserRegex.Matches(text)
                                  .Cast <Match>()
                                  .Select(m => m.Value)
                                  .ToList();

            for (int i = 0; i < words.Count; i++)
            {
                words[i] = words[i].Replace("\"", "");
            }

            ICommand command = new Command.Command();

            if (words.Count > 0)
            {
                command.CommandName = words[0].ToUpper();
            }

            for (int i = 1; i < words.Count; i++)
            {
                command.Parameters.Add(new Parameter(words[i]));
            }

            return(command);
        }
        private Command.Command FilterForEnd(Command.Command command)
        {
            // Requires exactly one argument (the closing bracket)
            if (command.Arguments.Count != 1)
            {
                return(command);
            }

            string firstArg = command.Arguments.First().GetAsText();

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

            if (firstArg != ")")
            {
                return(command);
            }

            // Closing of function block
            // Remove close function block syntax argument
            command.Arguments.RemoveAt(0);

            // Add close function block argument
            command.Arguments.Add(new Argument(new CloseFunctionBlockToken()));

            return(command);
        }
示例#5
0
        public void HandleDevice(Object obj)
        {
            TcpClient client = (TcpClient)obj;

            stream = client.GetStream();
            Packet packet         = new Packet(); //pachetul primit de la client
            Packet responsePacket = new Packet(); //pachetul pe care il vom trimite in urma cerererii clientului

            try
            {
                while (Running())
                {
                    packet = SerializeControl.ReadObject(stream, _client.Client.RemoteEndPoint.ToString());   //citesc pachetul primit de la client folosind serializare TCP
                    _log.WriteLog(Thread.CurrentThread.ManagedThreadId + ": Received: " + packet._data + "\n");

                    Command.Command command = new Command.Command(dataController, packet);
                    responsePacket = command.Execute();  // am pregatit raspunsul

                    _log.WriteLog(Thread.CurrentThread.ManagedThreadId + ": Sent: " + responsePacket._data + "\n");
                    SerializeControl.WriteObject(stream, responsePacket, _client.Client.RemoteEndPoint.ToString());   //trimit raspunsul clientului folosind serializare TCP
                }
            }
            catch (Exception e)
            {
                _log.WriteLog("Exception: " + e.ToString());
                client.Close();
            }
        }
示例#6
0
        public Command.Command Filter(Command.Command command)
        {
            if (command.GetCommandName() != "define" || command.Arguments.Count < 3)
            {
                return(command);
            }

            string constName = command.Arguments[1].GetAsText();

            // Constant value
            var argument = new Argument();

            for (var i = 2; i < command.Arguments.Count; i++)
            {
                foreach (var token in command.Arguments[i].Tokens)
                {
                    argument.Tokens.Add(token);
                }
                argument.Tokens.Add(new TextToken(" "));
            }

            var defineConstToken = new DefineConstantToken(constName, argument);

            return(new Command.Command(new List <Argument> {
                new Argument(defineConstToken)
            }));
        }
示例#7
0
        private void MainProcess(IAsyncResult ar)
        {
            HttpListener        socket  = null;
            HttpListenerContext context = null;

            try
            {
                Server.BeginGetContext(new AsyncCallback(MainProcess), Server);
                socket  = ar.AsyncState as HttpListener;
                context = socket.EndGetContext(ar);
            }
            catch (Exception e)
            {
                Log.Print("执行方法[MainProcess]:" + e.Message);
            }

            try
            {
                Command.Command command = new Command.Command();
                command.RunRoule(context, Roule, interceptor_);
            }
            catch (Exception e)
            {
                Log.Print("执行方法[command.RunRoule]:" + e.Message);
            }
        }
示例#8
0
文件: Boss.cs 项目: spiri91/ToyRobot
        private bool ValidPlace(Command.Command cmd)
        {
            var _cmd      = cmd as PlaceCommand;
            var validMove = _robot.IsThisMoveValid(_cmd.XPosition, _cmd.YPosition);

            return(validMove);
        }
示例#9
0
文件: Boss.cs 项目: spiri91/ToyRobot
        private Command.Command CheckIfValidOrder(Command.Command command)
        {
            if (command.YouValid())
            {
                return(command);
            }

            _logger.Log(Messages.BadCommand);

            return(new ChillOutCommand());
        }
示例#10
0
文件: Boss.cs 项目: spiri91/ToyRobot
 private void NeedsRefresh(Command.Command cmd)
 {
     (cmd.MovingStuff() && _robot.DidIMoved())
     .IfTrue(LawAndOrder)
     .Else(() =>
     {
         _logger.EmptyLine();
         _logger.Log(Messages.WaitingInstructions);
         _logger.EmptyLine();
         _logger.Log(Messages.Arrow);
     });
 }
示例#11
0
 protected AbstractCommandWrapper(Action executeAction, Func <bool> cantExectueFunc)
 {
     if (executeAction == null)
     {
         throw new ArgumentNullException(nameof(executeAction));
     }
     if (cantExectueFunc == null)
     {
         throw new ArgumentNullException(nameof(cantExectueFunc));
     }
     WrappedCommand = new Command.Command(executeAction, cantExectueFunc);
 }
示例#12
0
文件: Parser.cs 项目: mitchfizz05/mcc
        public McFunction Parse(string id, string code = null)
        {
            if (code == null)
            {
                // Load file from path in build environment
                string path = Environment.GetPath(id, "mcfunction");
                code = File.ReadAllText(path);
            }

            McFunction = new McFunction(id);

            // Iterate over lines in file
            foreach (string line in code.Split('\n'))
            {
                // Break command up into arguments
                var parts = CommandParser.Parse(line);

                if (parts == null)
                {
                    continue;
                }

                // Parse command into arguments
                var cmd = new Command.Command();
                foreach (string part in parts)
                {
                    Argument argument = new Argument();
                    argument.Tokens.Add(new TextToken(part));

                    // Run argument through filters
                    foreach (IParseFilter filter in ParseFilters)
                    {
                        argument = filter.FilterArgument(argument);
                    }

                    if (argument != null)
                    {
                        cmd.Arguments.Add(argument);
                    }
                }

                // Run command through filters
                foreach (IParseFilter filter in ParseFilters)
                {
                    cmd = filter.Filter(cmd);
                }

                McFunction.Commands.Add(cmd);
            }

            return(McFunction);
        }
示例#13
0
        public ActionResult KiemTraDangNhap(string tenDangNhap, string matKhau)
        {
            string a        = new Command.Command().MaHoaChuoi(matKhau);
            var    taiKhoan = new TaiKhoanDangNhapModel(tenDangNhap, new Command.Command().MaHoaChuoi(matKhau)).DangNhap();

            if (taiKhoan.Count > 0)
            {
                Contains.TAIKHOANDANGNHAP            = taiKhoan[0];
                Session[Contains.SESSIONKEYDANGNHAP] = taiKhoan[0];
                return(RedirectToAction("Index", "XinChao", new { area = "Admin" }));
            }
            else
            {
                ViewData["LoiDangNhap"] = "Đăng nhập thất bại.";
                return(View("index"));
            }
        }
示例#14
0
文件: Boss.cs 项目: spiri91/ToyRobot
        private Command.Command CheckFirstCommand(Command.Command cmd)
        {
            if (false == _isFirstCommand)
            {
                return(cmd);
            }

            if (cmd is PlaceCommand && ValidPlace(cmd))
            {
                _isFirstCommand = false;

                return(cmd);
            }

            _logger.Log(Messages.FirstCommand);
            _logger.EmptyLine();

            return(new ChillOutCommand());
        }
示例#15
0
        public Command.Command Filter(Command.Command command)
        {
            if (command.GetCommandName() != "if")
            {
                return(command);
            }

            // Remove the command name to make working with the arguments easier
            command.Arguments.RemoveAt(0);

            // Split if statement into individual conditions by seperating them at "&&"
            List <List <Argument> > ifConditionArguments = new List <List <Argument> > {
                new List <Argument>()
            };
            int pieceIndex = 0;

            foreach (Argument argument in command.Arguments)
            {
                string argText = argument.GetAsText();

                if (argText == "&&")
                {
                    ifConditionArguments.Add(new List <Argument>());
                    pieceIndex++;
                }
                else
                {
                    ifConditionArguments[pieceIndex].Add(new Argument(argText));
                }
            }

            List <Condition> conditions = new List <Condition>();

            foreach (var arguments in ifConditionArguments)
            {
                // Matches condition
                Condition condition = MatchesCondition.Parse(arguments);

                // Operation condition
                if (condition == null)
                {
                    condition = OperationCondition.Parse(arguments);
                }

                if (condition == null)
                {
                    throw new Exception("Invalid if statement condition");
                }
                else
                {
                    conditions.Add(condition);
                }
            }

            // Get all the left over arguments; these will make up the command that will be ran if the conditions are met
            int             startIndex = conditions.Last().LastIndex + 1;
            List <Argument> leftOver   = new List <Argument>(command.Arguments.GetRange(startIndex, command.Arguments.Count - startIndex));

            Command.Command successCommand = new Command.Command(leftOver);

            // Replace existing command with an if token
            command.Arguments.Clear();
            command.Arguments.Add(new Argument(new IfToken(conditions)));
            command.Arguments.AddRange(successCommand.Arguments);

            return(command);
        }
示例#16
0
 public ActionResult <string> GetTest()
 {
     Command.Command cs = new Command.Command();
     cs.testfun(6900f, 69f);
     return($"[CommandService] I am alive");
 }
 // ReSharper disable once MemberCanBeMadeStatic.Local
 private void Invoke(CommandPacket cmdPacket)
 {
     Command.Command cmd = SandboxMain.CmdHandler.GetCommand(cmdPacket.CmdKey);
     cmd?.InvokeServer(cmdPacket.Contents);
 }
示例#18
0
 public Command.Command Filter(Command.Command command)
 {
     return(command);
 }
示例#19
0
 // 为功能键注入命令
 public void SetCommand(Command.Command command)
 {
     this.command = command;
 }
 public CreateRealFolderViewModel(string path)
 {
     _path = path;
     AddFolderCmd = new Command.Command(OnCreateFolder, FolderName != string.Empty);
 }
示例#21
0
文件: Boss.cs 项目: spiri91/ToyRobot
        public Command.Command GiveOrder(Command.Command command)
        {
            command.OrderRobot(_robot);

            return(command);
        }