コード例 #1
0
        public void JsonSerializationTest()
        {
            OperateStick os         = new OperateStick(StickID.RSTICK, StickAngle.MAX, StickAngle.NEUTRAL);
            string       obJson     = JsonConvert.SerializeObject(os);
            var          obFromJson = (OperateStick)JsonConvert.DeserializeObject <CommandBase>(obJson);

            Assert.AreEqual(os.TargetControlID, obFromJson.TargetControlID);
            Assert.AreEqual(os.TargetXAngle, obFromJson.TargetXAngle);
            Assert.AreEqual(os.TargetYAngle, obFromJson.TargetYAngle);
        }
コード例 #2
0
        public void OperateStickFromStringTest()
        {
            var orignalOS = new OperateStick(StickID.LSTICK, (byte)98, (byte)76);
            var cw        = new CommandWrapper(orignalOS.ToString());

            Assert.IsTrue(cw.Command is OperateStick);
            var osFromString = (OperateStick)cw.Command;

            Assert.AreEqual(orignalOS.StickID, osFromString.StickID);
            Assert.AreEqual(orignalOS.TargetXAngle, osFromString.TargetXAngle);
            Assert.AreEqual(orignalOS.TargetYAngle, osFromString.TargetYAngle);
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance by parsing a string, that is a return value of ICommand.ToString() method.
        /// If commandString is not parsable, throws ArgumentException.
        /// This constructor is for enabling copy / paste functionality on MacroDesigner.
        /// </summary>
        /// <param name="commandString">A return value of ICommand.ToString() method</param>
        public CommandWrapper(string commandString)
        {
            string CleanCommaAndParenthesis(string s) => s.Replace(",", "").Replace("(", "").Replace(")", "");

            ArgumentException ae = new ArgumentException("Failed to parse parameter.", "commandToString");
            CommandBase       command;

            try
            {
                string[] elements = commandString.Split(' ');
                string   head     = elements[0];
                if (head == "Wait")
                {
                    command = new Wait(int.Parse(elements[1]));
                }
                else if (head == "PRESS" || head == "RELEASE")
                {
                    command = new OperateButton(
                        (ButtonID)Enum.Parse(typeof(ButtonID), elements[1]),
                        head == "PRESS" ? ButtonState.PRESS : ButtonState.RELEASE);
                }
                else if (head == "LSTICK" || head == "RSTICK")
                {
                    command = new OperateStick(
                        head == "LSTICK" ? StickID.LSTICK : StickID.RSTICK,
                        byte.Parse(CleanCommaAndParenthesis(elements[1])),
                        byte.Parse(CleanCommaAndParenthesis(elements[2]))
                        );
                }
                else
                {
                    throw ae;
                }
            }
            catch (Exception)
            {
                throw ae;
            }

            this.Command = command;
        }
コード例 #4
0
        public void ToStringTest()
        {
            var os = new OperateStick(StickID.LSTICK, 90, 180);

            Assert.AreEqual("LSTICK (90, 180)", os.ToString());
        }