Exemplo n.º 1
0
            /// <summary>
            /// 解析命令
            /// </summary>
            /// <param name="cmd"></param>
            /// <param name="msg"></param>
            /// <returns></returns>
            public ICommand TryParse(string cmd, out string msg)
            {
                msg = "";
                WaitCommand command = new WaitCommand();
                String      cmdName = command.findNames(cmd);

                if (cmdName == null || cmdName == "")
                {
                    return(null);
                }
                String cmdParam = cmd.Substring(cmdName.Length);

                int[] numberpos = new int[2];
                int   number    = TextUtils.FeatchNumber(cmdParam, numberpos);

                if (numberpos[0] == -1)
                {
                    msg = "无法解析命令WaitCommand的参数:缺少时间项" + cmdParam;
                    return(null);
                }
                String timeUnitStr = cmdParam.Substring(numberpos[1] + 1);

                TimeUnit timeUnit = new TimeUnit();

                try
                {
                    timeUnit = TimeUnitUtils.Parse(timeUnitStr);
                }
                catch (Exception e)
                {
                    msg = "无法解析命令WaitCommand的参数:时间单位无效" + e.Message + ":" + cmdParam;
                    return(null);
                }

                command.timeUnit = timeUnit;
                command.time     = number;



                if (number < 0)
                {
                    msg = "无法解析命令WaitCommand的参数:时间值错误:" + number + ":" + cmdParam;
                    return(null);
                }


                return(command);
            }
Exemplo n.º 2
0
        public override void Execute(CommandContext context)
        {
            int ms = TimeUnitUtils.Transfer((int)time, timeUnit, TimeUnit.millsecond);

            System.Threading.Thread.Sleep(ms);
        }