示例#1
0
 /// <summary>
 /// Находит тип команды, которому соответствует строка cmdTypeText,
 /// и записывает его в cmdKind.
 /// </summary>
 /// <param name="cmdTypeText">Текстовое представление команды</param>
 /// <param name="cmdKind">Тип команды</param>
 /// <returns>Истину, если удалось рапарсить команду, и ложь в противном случае</returns>
 private bool _TryParseCommand(string cmdTypeText, out CommandKind cmdKind)
 {
     Debug.Assert(cmdTypeText == cmdTypeText.Trim(), "Command must be without spaces");
     cmdKind = CommandKind.UNDEFINED;
     switch (cmdTypeText)
     {
         case "dist": 
             cmdKind = CommandKind.DISTANCE;
             break;
         case "trngl.area": 
             cmdKind = CommandKind.TRIANGLE_AREA;
             break;
         case "trngl.perim": 
             cmdKind = CommandKind.TRIANGLE_PERIM;
             break;
         case "trngl.is-right": 
             cmdKind = CommandKind.TRIANGLE_IS_RIGHT;
             break;
         case "trngl.is-eq": 
             cmdKind = CommandKind.TRIANGLE_IS_EQUIL;
             break;
         default:
             return false;
     }
     return true;
 }
示例#2
0
 public CommandData(int id, CommandKind kind, int frameCount, object[] parameters)
 {
     this.id         = id;
     this.kind       = kind;
     this.frameCount = frameCount;
     this.parameters = parameters;
 }
示例#3
0
 public CommandFormat(CommandKind kind, int immediate, int length1 = 0, int length2 = 0)
 {
     this.Kind           = kind;
     this.ImmediateValue = immediate;
     this.Length1        = length1;
     this.Length2        = length2;
 }
示例#4
0
 public CommandFormat(CommandKind kind, int immediate, int length1 = 0, int length2 = 0)
 {
     Kind           = kind;
     ImmediateValue = immediate;
     Length1        = length1;
     Length2        = length2;
 }
示例#5
0
 public static byte[] CreateEofStringPayload(CommandKind command, string value)
 {
     var length = Encoding.UTF8.GetByteCount(value);
     var payload = new byte[length + 1];
     payload[0] = (byte) command;
     Encoding.UTF8.GetBytes(value, 0, value.Length, payload, 1);
     return payload;
 }
示例#6
0
 /// <summary>
 /// Instantiates a new instance of the Command class.
 /// </summary>
 /// <param name="kind">The kidn of command to consider.</param>
 /// <param name="name">The name of this instance.</param>
 /// <param name="items">The items to consider.</param>
 protected Command(
     CommandKind kind,
     string name = null,
     params IDataElement[] items)
     : base(name, items)
 {
     this.Kind = kind;
 }
        public static byte[] CreateEofStringPayload(CommandKind command, string value)
        {
            var length  = Encoding.UTF8.GetByteCount(value);
            var payload = new byte[length + 1];

            payload[0] = (byte)command;
            Encoding.UTF8.GetBytes(value, 0, value.Length, payload, 1);
            return(payload);
        }
        Task SendCommandData(CommandKind commandKind, object[] parameters)
        {
            var id        = Interlocked.Increment(ref currentId);
            var semaphore = new SemaphoreSlim(0, 1);

            semaphores.TryAdd(id, semaphore);
            gameSignalingClient.SendData(new HostReceiveSignalData(
                                             new CommandData(id, commandKind, 0, parameters)
                                             ));
            return(semaphore.WaitAsync());
        }
示例#9
0
        /// <summary>
        /// 显示确定取消菜单
        /// </summary>
        /// <param name="str">提示字段</param>
        /// <param name="mode">确定后运行的模式</param>
        private void ShowMessagePopupWindow(string str, CommandKind mode)
        {
            var msgPopup = new Resources.MessagePopupWindow(str);

            switch (mode)
            {
            case CommandKind.Insert:
                msgPopup.LeftClick += (s, e) => { StrongTypeViewModel.CommandInsertDialog.Execute(null); };
                break;
            }

            msgPopup.RightClick += (s, e) => { };
            msgPopup.ShowWIndow();
        }
示例#10
0
 private bool _TryParseTriangle(CommandKind cmdKind, string[] argsText, out AbstractCommand cmd)
 {
     // здесь может некорректный формат команды
     cmd = new BadCommand(this.currCmdText);
     // команда работы с треугольником принимает лидо длины строн (3 аргумента), 
     // либо координаты вершин (6 аргументов)
     if (argsText.Length != 3 && argsText.Length != 6) 
         return false;
     TriangleCommand trnglCmd = null;
     // создаём конкретную команду
     switch (cmdKind)
     { 
         case CommandKind.TRIANGLE_AREA:
             trnglCmd = new TriangleAreaCommand();
             break;
         case CommandKind.TRIANGLE_PERIM:
             trnglCmd = new TrianglePerimCommand();
             break;
         case CommandKind.TRIANGLE_IS_RIGHT:
             trnglCmd = new TriangleIsRightCommand();
             break;
         case CommandKind.TRIANGLE_IS_EQUIL:
             trnglCmd = new TriangleIsRightCommand();
             break;
         default:
             Debug.Assert(false, "_TryParseTriangle must be called only for triangle commands");
             break;
     }
     // инициализируем данными треугольника
     if (argsText.Length == 3)
     {
         double[] sides;
         if (!_TryParseTriangleSides(argsText, out sides))
             return false;
         trnglCmd.Init(sides);
     }
     else
     {
         Debug.Assert(argsText.Length == 6, "This case only for 6 args-coordinates");
         Point[] vertices;
         if (!_TryParseTriangleVertices(argsText, out vertices))
             return false;
         trnglCmd.Init(vertices);
     }
     cmd = trnglCmd;
     return true;
 }
        public void SystemCommand(string input, CommandKind expectedKind)
        {
            using (var testDbInfo = SetupUtil.CreateTestDb())
            {
                Mock <ILog> mockLog = new Mock <ILog>();

                CommandInterpreter interpreter = new CommandInterpreter(SetupUtil.CreateMockRepositoryBag(testDbInfo.ConnectionString, mockLog.Object), BudgetCliCommands.BuildCommandLibrary());

                ICommandAction action;
                bool           success = interpreter.TryParseCommand(input, out action);

                Assert.True(success);
                Assert.NotNull(action);
                Assert.IsType(typeof(SystemCommand), action);
                Assert.Equal(expectedKind, ((SystemCommand)action).CommandKind);
            }
        }
 public static ICommand Create(CommandKind kind)
 {
     switch (kind)
     {
         case CommandKind.Pulse:
             return new PulseCommand();
         case CommandKind.Turn:
             return new TurnCommand();
         case CommandKind.TurnOn:
             return new TurnOnCommand();
         case CommandKind.TurnOff:
             return new TurnOffCommand();
         case CommandKind.BlinkLed:
             return new BlinkLedCommand();
         default:
             throw new Exception("Command kind is not valid");
     }
 }
示例#13
0
 public SystemCommand(string text, CommandKind commandKind)
 {
     RawText     = text;
     CommandKind = commandKind;
 }
示例#14
0
 public static Entity Encode(CommandKind Command, byte Parameter1, byte Parameter2, byte Value = 0x00)
 {
     return new Entity((byte)Command, Parameter1, Parameter2, Value);
 }
示例#15
0
 public CommandRule(CommandKind kind, DoxygenEntityKind entityKind, IEnumerable <ArgumentRule> args)
 {
     Kind       = kind;
     EntityKind = entityKind;
     Args       = args;
 }
示例#16
0
文件: Commands.cs 项目: Strongc/VSLua
 public Command(CommandKind command)
 {
     this.Kind = command;
 }
示例#17
0
 private void ExecuteCommand(CommandKind commandKind)
 {
     _command = commandKind;
     _commandEvent.Set();
 }
示例#18
0
 public Command(CommandKind command)
 {
     this.Kind = command;
 }
示例#19
0
 public SystemCommandResult(ICommandAction command, bool isSuccessful, CommandKind commandKind)
 {
     CommandAction = command;
     IsSuccessful  = isSuccessful;
     CommandKind   = commandKind;
 }
示例#20
0
 public CommandFormat(CommandKind kind, int immediate, int length1 = 0, int length2 = 0)
 {
     this.Kind = kind;
     this.ImmediateValue = immediate;
     this.Length1 = length1;
     this.Length2 = length2;
 }
示例#21
0
 public SimpleCommand(Action <Snippet> action, CommandKind kind)
 {
     _action = action;
     Kind    = kind;
 }
示例#22
0
 /// <summary>
 /// インスタンスを生成する
 /// </summary>
 /// <param name="kind"></param>
 /// <param name="args"></param>
 internal CommandArg(CommandKind kind, params object[] args)
 {
     this.Kind   = kind;
     this.Params = args;
 }