Ejemplo n.º 1
0
        public void TestNullableEnum()
        {
            CommandReflection.AddMappedType(typeof(EnumClass));
            var c1 = (EnumClass)CommandMapping.Parse("M999 Y1");

            Assert.IsTrue(c1.Y == EnumObject.A);
            Assert.IsTrue(c1.ToGCode() == "M999 X0 Y1");
            var c2 = (EnumClass)CommandMapping.Parse("M999 Y2");

            Assert.IsTrue(c2.Y == EnumObject.B);
            Assert.IsTrue(c2.ToGCode() == "M999 X0 Y2");
            var c3 = (EnumClass)CommandMapping.Parse("M999 Y5");

            Assert.IsTrue(c3.Y == (EnumObject)5);
            Assert.IsTrue(c3.ToGCode() == "M999 X0 Y5");
            var c4 = (EnumClass)CommandMapping.Parse("M999 Y");

            Assert.IsTrue(c4.Y == null);
            Assert.IsTrue(c4.ToGCode() == "M999 X0");
            var c5 = (EnumClass)CommandMapping.Parse("M999");

            Assert.IsTrue(c5.Y == null);
            Assert.IsTrue(c5.ToGCode() == "M999 X0");
            var c6 = (EnumClass)CommandMapping.Parse("M999 Y-1.1");

            Assert.IsTrue(c6.Y == (EnumObject)(-1));
            Assert.IsTrue(c6.ToGCode() == "M999 X0 Y-1");
        }
Ejemplo n.º 2
0
        public void CLIFlow_Run_ShouldRunOnlyProperCommandHandler_WhenMultipleCommandHandlersAreMapped()
        {
            //Arrange
            var args = new string[]
            {
                "command1",
                "--boolOption", "true",
                "--stringOption", "stringOptionValue",
                "--intOption", "1"
            };

            var mockCommand1Handler = new MockCommand1Handler();
            var mockCommand2Handler = new MockCommand2Handler();
            var mapping             = new CommandMapping().Map <Command1>(mockCommand1Handler)
                                      .Map <Command2>(mockCommand2Handler);

            //Act
            var result = CLIFlow.Create().UseMapping(mapping).Run(args);

            //Assert
            Assert.AreEqual(0, result, "RunCLI method indicted error in returned exit code");

            Assert.IsNull(mockCommand2Handler.LastRunParameters);
            Assert.IsNotNull(mockCommand1Handler.LastRunParameters);
        }
Ejemplo n.º 3
0
        public void TestEnum()
        {
            CommandReflection.AddMappedType(typeof(EnumClass));
            var c1 = (EnumClass)CommandMapping.Parse("M999 X1");

            Assert.IsTrue(c1.X == EnumObject.A);
            Assert.IsTrue(c1.ToGCode() == "M999 X1");
            var c2 = (EnumClass)CommandMapping.Parse("M999 X2");

            Assert.IsTrue(c2.X == EnumObject.B);
            Assert.IsTrue(c2.ToGCode() == "M999 X2");
            var c3 = (EnumClass)CommandMapping.Parse("M999 X5");

            Assert.IsTrue(c3.X == (EnumObject)5);
            Assert.IsTrue(c3.ToGCode() == "M999 X5");
            var c4 = (EnumClass)CommandMapping.Parse("M999 X");

            Assert.IsTrue(c4.X == (EnumObject)0);
            Assert.IsTrue(c4.ToGCode() == "M999 X0");
            var c5 = (EnumClass)CommandMapping.Parse("M999");

            Assert.IsTrue(c5.X == (EnumObject)0);
            Assert.IsTrue(c5.ToGCode() == "M999 X0");
            var c6 = (EnumClass)CommandMapping.Parse("M999 X-1.1");

            Assert.IsTrue(c6.X == (EnumObject)(-1));
            Assert.IsTrue(c6.ToGCode() == "M999 X-1");
        }
Ejemplo n.º 4
0
        public bool TryToExecuteInstruction(Instructions currentInstruction)
        {
            Command command = null;

            if (!CommandMapping.TryGetValue(currentInstruction, out command))
            {
                ConsoleLogger.WriteError($"There is no matching command to instruction: {currentInstruction}");
                return(false);
            }

            var result = command.ExecuteCommand(_positionState, Tracker);

            if (result.Terminate)
            {
                return(false);
            }

            if (!result.IsSuccesful)
            {
                if (!_backOffStrategies.RunBackOffCommands())
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
        public void CLIFlow_Run_ShouldRunDefaultCommand_WhenNoCommandWasSpecified()
        {
            //Arrange
            var stringOptionValue = "sampleString";
            var intOptionValue    = 102;

            var args = new string[]
            {
                "--boolOption",
                "--stringOption", stringOptionValue,
                "--intOption", intOptionValue.ToString()
            };

            var mockCommandHandler = new MockCommand1Handler();
            var mapping            = new CommandMapping().MapDefault <Command1>(mockCommandHandler);

            //Act
            var result = CLIFlow.Create().UseMapping(mapping).Run(args);

            //Assert
            Assert.AreEqual(0, result, "RunCLI method indicted error in returned exit code");
            Assert.IsTrue(mockCommandHandler.LastRunParameters.BoolOption);
            Assert.IsNull(mockCommandHandler.LastRunParameters.NotOptionProperty);
            Assert.AreEqual(stringOptionValue, mockCommandHandler.LastRunParameters.StringOption);
            Assert.AreEqual(intOptionValue, mockCommandHandler.LastRunParameters.IntOption);
        }
Ejemplo n.º 6
0
        private void CAlias_Click(object sender, EventArgs e)
        {
            if (Commands.SelectedItem == null)
            {
                return;
            }
            CommandMapping original = _mem._rc.CommandMappings.Find(k => k.Name == Commands.SelectedItem.ToString());
            string         input    = Microsoft.VisualBasic.Interaction.InputBox("Please specify the permission to add.", "New Permission", "");

            if (input == "")
            {
                return;
            }
            var i = _mem._rc.CommandMappings.Find(k => k.Name == input);

            if (i != null)
            {
                MessageBox.Show("A command or alias \"" + input + "\" already exists! Please specify a different alias.");
            }
            else
            {
                CommandMapping newone = new CommandMapping(input, original.Class, original.Enabled, original.Priority);
                _mem._rc.CommandMappings.Add(newone);
                Commands.Items.Add(newone.Name);
                Commands.SelectedItem = newone.Name;
            }
        }
Ejemplo n.º 7
0
        public static IServiceCollection ConfigureCLIFlow(this IServiceCollection services, Action <CommandMapping> setup)
        {
            if (services == null)
            {
                throw new ArgumentNullException($"{nameof(services)} cannot be null.");
            }

            if (setup == null)
            {
                throw new ArgumentNullException($"{nameof(setup)} cannot be null.");
            }

            CommandMapping mapping = new CommandMapping();

            setup(mapping);
            services.AddSingleton(mapping);

            mapping.Entries.ToList().ForEach(it =>
            {
                if (it.HandlerInstance != null)
                {
                    services.AddSingleton(it.HandlerInstance);
                }
                else
                {
                    services.AddSingleton(it.HandlerType);
                }
            });

            return(services);
        }
Ejemplo n.º 8
0
        private void DispatchCommand(object sender, EventArgs e)
        {
            ButtonItemBase item = (ButtonItemBase)sender;
            CommandMapping cmd  = (CommandMapping)item.Tag;

            Editor.DispatchCommand(cmd);
        }
Ejemplo n.º 9
0
        static void MappedCommandFromGCode()
        {
            var cmd = CommandMapping.Parse("G1 X10 Y20") as RapidLinearMove;

            Console.WriteLine(cmd.CommandType);    //Output: "G"
            Console.WriteLine(cmd.CommandSubType); //Output: "1"
            Console.WriteLine(cmd.MoveX);          //Output: "10"
            Console.WriteLine(cmd.MoveY);          //Output: "20"
            Console.WriteLine(cmd.ToGCode());      //Output: "G1 X10 Y20 S0"
        }
Ejemplo n.º 10
0
        private void RemComm_Click(object sender, EventArgs e)
        {
            if (Commands.SelectedItem == null)
            {
                return;
            }
            CommandMapping target = _mem._rc.CommandMappings.Find(k => k.Name == Commands.SelectedItem.ToString());

            _mem._rc.CommandMappings.Remove(target);
            Commands.Items.Remove(target.Name);
            Commands.SelectedIndex = Commands.Items.Count > 0 ? 0 : -1;
        }
Ejemplo n.º 11
0
        public ICommand Register(ICommand command, Key key, ModifierKeys modifierKeys)
        {
            var mapping = new CommandMapping()
            {
                Command      = command,
                Key          = key,
                ModifierKeys = modifierKeys
            };

            _mappings.Add(mapping);
            return(command);
        }
Ejemplo n.º 12
0
        public void CLIFlow_Run_ShouldThrowInvalidCommmandException_ForEmptyArguments()
        {
            //Arrange
            var args = new string[] { };

            var mockCommand1Handler = new MockCommand1Handler();
            var mapping             = new CommandMapping().Map <Command1>(mockCommand1Handler);

            //Act
            var result = CLIFlow.Create().UseMapping(mapping).Run(args);

            //Assert
            Assert.AreEqual((int)ErrorCode.UnspecifiedCommand, result);
        }
Ejemplo n.º 13
0
 private void CNamespace_TextChanged(object sender, EventArgs e)
 {
     if (!_controlled)
     {
         if (Commands.SelectedItem == null)
         {
             return;
         }
         CommandMapping p     = _mem._rc.CommandMappings.Find(k => k.Name == Commands.SelectedItem.ToString());
         var            index = _mem._rc.CommandMappings.IndexOf(p);
         p.Class = CNamespace.Text;
         _mem._rc.CommandMappings[index] = p;
     }
 }
Ejemplo n.º 14
0
 private void CPriority_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (!_controlled)
     {
         if (Commands.SelectedItem == null)
         {
             return;
         }
         CommandMapping p     = _mem._rc.CommandMappings.Find(k => k.Name == Commands.SelectedItem.ToString());
         var            index = _mem._rc.CommandMappings.IndexOf(p);
         p.Priority = Enum.GetValues(typeof(CommandPriority)).Cast <CommandPriority>().ToList().Find(k => k.ToString() == CPriority.SelectedItem.ToString());
         _mem._rc.CommandMappings[index] = p;
     }
 }
Ejemplo n.º 15
0
 private void ECommand_CheckedChanged(object sender, EventArgs e)
 {
     if (!_controlled)
     {
         if (Commands.SelectedItem == null)
         {
             return;
         }
         CommandMapping p     = _mem._rc.CommandMappings.Find(k => k.Name == Commands.SelectedItem.ToString());
         var            index = _mem._rc.CommandMappings.IndexOf(p);
         p.Enabled = ECommand.Checked;
         _mem._rc.CommandMappings[index] = p;
     }
 }
Ejemplo n.º 16
0
        public bool RunBackOffCommands()
        {
            var hitOnObstacle            = false;
            var currentBackStageStrategy = instructions.First;

            while (currentBackStageStrategy != null)
            {
                var currentInstruction = currentBackStageStrategy.Value.First;
                while (currentInstruction != null && !hitOnObstacle)
                {
                    Command command = null;
                    if (!CommandMapping.TryGetValue(currentInstruction.Value, out command))
                    {
                        ConsoleLogger.WriteError($"There is no matching back off command to instruction: {currentInstruction.Value}");
                        return(false);
                    }

                    var result = command.ExecuteCommand(_positionState, Tracker);
                    if (result.Terminate)
                    {
                        return(false);
                    }

                    if (!result.IsSuccesful)
                    {
                        hitOnObstacle = true;
                    }

                    currentInstruction = currentInstruction.Next;
                }

                if (!hitOnObstacle)
                {
                    return(true);
                }

                hitOnObstacle            = false;
                currentBackStageStrategy = currentBackStageStrategy.Next;
            }

            return(false);
        }
Ejemplo n.º 17
0
        public void TestByte()
        {
            CommandReflection.AddMappedType(typeof(ByteClass));
            var c2 = (ByteClass)CommandMapping.Parse("M999 X1.1");

            Assert.IsTrue(c2.X == 1);
            Assert.IsTrue(c2.ToGCode() == "M999 X1");
            var c3 = (ByteClass)CommandMapping.Parse("M999 X1");

            Assert.IsTrue(c3.X == 1);
            Assert.IsTrue(c3.ToGCode() == "M999 X1");
            var c4 = (ByteClass)CommandMapping.Parse("M999 X");

            Assert.IsTrue(c4.X == 0);
            Assert.IsTrue(c4.ToGCode() == "M999 X0");
            var c5 = (ByteClass)CommandMapping.Parse("M999");

            Assert.IsTrue(c5.X == 0);
            Assert.IsTrue(c5.ToGCode() == "M999 X0");
        }
Ejemplo n.º 18
0
        public void TestNullableByte()
        {
            CommandReflection.AddMappedType(typeof(ByteClass));
            var c2 = (ByteClass)CommandMapping.Parse("M999 Y1.1");

            Assert.IsTrue(c2.Y == 1);
            Assert.IsTrue(c2.ToGCode() == "M999 X0 Y1");
            var c3 = (ByteClass)CommandMapping.Parse("M999 Y1");

            Assert.IsTrue(c3.Y == 1);
            Assert.IsTrue(c3.ToGCode() == "M999 X0 Y1");
            var c4 = (ByteClass)CommandMapping.Parse("M999 Y");

            Assert.IsTrue(c4.Y == null);
            Assert.IsTrue(c4.ToGCode() == "M999 X0");
            var c5 = (ByteClass)CommandMapping.Parse("M999");

            Assert.IsTrue(c5.Y == null);
            Assert.IsTrue(c5.ToGCode() == "M999 X0");
        }
Ejemplo n.º 19
0
        public void CLIFlow_Run_ShouldThrowInvalidCommmandException_ForNotMappedCommand()
        {
            var invalidCommandName = "invalidCommandName";

            //Arrange
            var args = new string[]
            {
                invalidCommandName,
                "--boolOption", "true",
            };

            var mockCommand1Handler = new MockCommand1Handler();
            var mapping             = new CommandMapping().Map <Command1>(mockCommand1Handler);

            //Act
            var result = CLIFlow.Create().UseMapping(mapping).Run(args);

            //Assert
            Assert.AreEqual((int)ErrorCode.UnrecognizedCommand, result);
        }
Ejemplo n.º 20
0
        public void CLIFlow_Run_ShouldThrowInvalidOptionException_ForInvalidOption()
        {
            //Arrange
            var args = new string[]
            {
                "command1",
                "--boolOption", "true",
                "--boolOptionXX", "true",
                "--stringOption", "stringOptionValue",
                "--intOption", "1"
            };

            var mockCommand1Handler = new MockCommand1Handler();
            var mapping             = new CommandMapping().Map <Command1>(mockCommand1Handler);

            //Act
            var result = CLIFlow.Create().UseMapping(mapping).Run(args);

            //Assert
            Assert.AreEqual((int)ErrorCode.UnrecognizedOption, result);
        }
Ejemplo n.º 21
0
        public void CLIFlow_Run_ShouldRunProperCommand_WhenCommandNameIncludeDash()
        {
            //Arrange
            var stringOptionValue = "sampleString";

            var args = new string[]
            {
                "command-sample",
                "--stringOption", stringOptionValue,
            };


            var mockCommandHandler = new MockCommand3Handler();
            var mapping            = new CommandMapping().MapDefault <Command3>(mockCommandHandler);

            //Act
            var result = CLIFlow.Create().UseMapping(mapping).Run(args);

            //Assert
            Assert.AreEqual(0, result, "RunCLI method indicted error in returned exit code");
            Assert.AreEqual(stringOptionValue, mockCommandHandler.LastRunParameters.StringOption);
        }
Ejemplo n.º 22
0
        private void RefreshCommandData()
        {
            if (Commands.SelectedItem == null)
            {
                CAlias.Enabled     = false;
                RemComm.Enabled    = false;
                ECommand.Enabled   = false;
                CPriority.Enabled  = false;
                CNamespace.Enabled = false;
                return;
            }
            CAlias.Enabled     = true;
            RemComm.Enabled    = true;
            ECommand.Enabled   = true;
            CPriority.Enabled  = true;
            CNamespace.Enabled = true;
            _controlled        = true;
            CommandMapping c = _mem._rc.CommandMappings.Find(k => k.Name == Commands.SelectedItem.ToString());

            ECommand.Checked        = c.Enabled;
            CPriority.SelectedIndex = CPriority.Items.IndexOf(c.Priority.ToString());
            CNamespace.Text         = c.Class;
            _controlled             = false;
        }
Ejemplo n.º 23
0
        public void TestDecimal()
        {
            CommandReflection.AddMappedType(typeof(DecimalClass));
            var c1 = (DecimalClass)CommandMapping.Parse("M999 X-1.1");

            Assert.IsTrue(c1.X == -1.1m);
            Assert.IsTrue(c1.ToGCode() == "M999 X-1.1");
            var c2 = (DecimalClass)CommandMapping.Parse("M999 X1.1");

            Assert.IsTrue(c2.X == 1.1m);
            Assert.IsTrue(c2.ToGCode() == "M999 X1.1");
            var c3 = (DecimalClass)CommandMapping.Parse("M999 X1");

            Assert.IsTrue(c3.X == 1);
            Assert.IsTrue(c3.ToGCode() == "M999 X1");
            var c4 = (DecimalClass)CommandMapping.Parse("M999 X");

            Assert.IsTrue(c4.X == 0);
            Assert.IsTrue(c4.ToGCode() == "M999 X0");
            var c5 = (DecimalClass)CommandMapping.Parse("M999");

            Assert.IsTrue(c5.X == 0);
            Assert.IsTrue(c5.ToGCode() == "M999 X0");
        }
Ejemplo n.º 24
0
        public void TestBool()
        {
            CommandReflection.AddMappedType(typeof(BoolClass));
            var c1 = (BoolClass)CommandMapping.Parse("M999 X-1.1");

            Assert.IsTrue(c1.X == true);
            Assert.IsTrue(c1.ToGCode() == "M999 X");
            var c2 = (BoolClass)CommandMapping.Parse("M999 X1.1");

            Assert.IsTrue(c2.X == true);
            Assert.IsTrue(c2.ToGCode() == "M999 X");
            var c3 = (BoolClass)CommandMapping.Parse("M999 X1");

            Assert.IsTrue(c3.X == true);
            Assert.IsTrue(c3.ToGCode() == "M999 X");
            var c4 = (BoolClass)CommandMapping.Parse("M999 X");

            Assert.IsTrue(c4.X == true);
            Assert.IsTrue(c4.ToGCode() == "M999 X");
            var c5 = (BoolClass)CommandMapping.Parse("M999");

            Assert.IsTrue(c5.X == false);
            Assert.IsTrue(c5.ToGCode() == "M999");
        }
 public void CustomCommandMappingException()
 {
     CommandReflection.ClearMappings();
     Assert.Catch(typeof(Exception), () => { var cmd = CommandMapping.Parse("M999 X"); });
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Instructs to explicitly use specified <see cref="CommandMapping"/>.
 /// </summary>
 /// <param name="mapping"></param>
 /// <returns></returns>
 public CLIFlow UseMapping(CommandMapping mapping)
 {
     _mapping = mapping ?? throw new ArgumentNullException(nameof(mapping));
     return(this);
 }
 public void CustomCommandAddType()
 {
     CommandReflection.ClearMappings();
     CommandReflection.AddMappedType(typeof(CustomCommand));
     var cmd = CommandMapping.Parse("M999 X");
 }
Ejemplo n.º 28
0
        public CommandChooser()
        {
            InitializeComponent();
            this.Icon = OutOfPhase.Properties.Resources.Icon2;

            DpiChangeHelper.ScaleFont(this, Program.Config.AdditionalUIZoom);

            listBoxCommands.ValueMember   = "Key";
            listBoxCommands.DisplayMember = "Value";
            foreach (NoteCommands command in CommandList)
            {
                if (command != NoteCommands.eCmd_End)
                {
                    KeyValuePair <NoteCommands, string> entry = new KeyValuePair <NoteCommands, string>(command, CommandMapping.GetCommandName(command));
                    listBoxCommands.Items.Add(entry);
                }
                else
                {
                    listBoxCommands.Items.Add(new KeyValuePair <NoteCommands, string>(NoteCommands.eCmd_End, String.Empty));
                }
            }
            if (lastSelectIndex >= 0)
            {
                listBoxCommands.SelectedIndex = lastSelectIndex;
            }
            listBoxCommands.DoubleClick += buttonOK_Click;
        }
 public void CustomCommandAddAssembly()
 {
     CommandReflection.ClearMappings();
     CommandReflection.AddMappedTypesFromAssembly(System.Reflection.Assembly.GetExecutingAssembly());
     var cmd = CommandMapping.Parse("M999 X");
 }
 public void AutoAddCustomCommand2()
 {
     CommandReflection.ClearMappings();
     var cmd = CommandMapping.Parse(typeof(CustomCommand), "M999 X");
     var g   = cmd.ToGCode();
 }
		public void before()
		{
			commandClass = typeof(NullCommand);
			mapping = new CommandMapping(commandClass);
		}