Exemple #1
0
        public void TestParseCustomObjectInstanceTooManyArgs()
        {
            //Arrange
            string line1 = "2. DOM X double Y double L_MIESZKAŃCÓW int";
            string line2 = "2. DOM 4 4 12 11 22";

            CustomObjectType        type  = Parser.ParseCustomObjectType(line1);
            List <CustomObjectType> types = new List <CustomObjectType>
            {
                type
            };

            //Act
            try
            {
                CustomObjectInstance result = Parser.ParseCustomObject(line2, types);
            }
            catch (ParseLineException e)
            {
                //Assert
                Assert.AreEqual("Too many arguments", e.Message);
                return;
            }
            Assert.Fail();
        }
Exemple #2
0
        public void TestParseCustomObjectInstanceWrongTypeOfArgs()
        {
            //Arrange
            string line1 = "2. DOM X double Y double L_MIESZKAŃCÓW int";
            string line2 = "2. DOM 4 marcin 13";

            CustomObjectType        type  = Parser.ParseCustomObjectType(line1);
            List <CustomObjectType> types = new List <CustomObjectType>
            {
                type
            };

            //Act
            try
            {
                CustomObjectInstance result = Parser.ParseCustomObject(line2, types);
            }
            catch (ParseLineException e)
            {
                //Assert
                Assert.AreEqual("2. argument is not double type", e.Message);
                return;
            }
            Assert.Fail();
        }
        protected override void OnShown(EventArgs e)
        {
            customObj = new CustomObjectType(this.values.Properties.ToDictionary(k => k.PropertyName, k => k.Value));
            customObj.Properties.AddRange(Target.GetType().GetProperties().Select(p => new CustomProperty
            {
                Description = p
                    .GetCustomAttributes(typeof(DescriptionAttribute), true)
                    .Select(a => ((DescriptionAttribute)a).Description)
                    .FirstOrDefault(),
                Category = p
                    .GetCustomAttributes(typeof(CategoryAttribute), true)
                    .Select(a => ((CategoryAttribute)a).Category)
                    .FirstOrDefault(),
                Name = p.Name,
                Type = p.PropertyType,
                Value = p.GetValue(Target)
            }));
            customObj.Properties.Add(new CustomProperty() {
                Description = "ObjectState",
                Name = "$ObjectState",
                Type = typeof(string),
                Value = null,
                Category = " Object State"
            });

            propertyGrid1.SelectedObject = customObj;

            base.OnShown(e);
        }
Exemple #4
0
        protected override void OnShown(EventArgs e)
        {
            customObj = new CustomObjectType(this.values.Properties.ToDictionary(k => k.PropertyName, k => k.Value));
            customObj.Properties.AddRange(Target.GetType().GetProperties().Select(p => new CustomProperty
            {
                Description = p
                              .GetCustomAttributes(typeof(DescriptionAttribute), true)
                              .Select(a => ((DescriptionAttribute)a).Description)
                              .FirstOrDefault(),
                Category = p
                           .GetCustomAttributes(typeof(CategoryAttribute), true)
                           .Select(a => ((CategoryAttribute)a).Category)
                           .FirstOrDefault(),
                Name  = p.Name,
                Type  = p.PropertyType,
                Value = p.GetValue(Target)
            }));
            customObj.Properties.Add(new CustomProperty()
            {
                Description = "ObjectState",
                Name        = "$ObjectState",
                Type        = typeof(string),
                Value       = null,
                Category    = " Object State"
            });

            propertyGrid1.SelectedObject = customObj;

            base.OnShown(e);
        }
Exemple #5
0
        public void TestParseCustomObjectInstanceWrongName()
        {
            //Arrange
            string line1 = "2. DOM X double Y double L_MIESZKAŃCÓW int";
            string line2 = "2. DYM 4 3 13";

            CustomObjectType        type  = Parser.ParseCustomObjectType(line1);
            List <CustomObjectType> types = new List <CustomObjectType>
            {
                type
            };

            //Act
            try
            {
                CustomObjectInstance result = Parser.ParseCustomObject(line2, types);
            }
            catch (ParseLineException e)
            {
                //Assert
                Assert.AreEqual("Unrecognised object type", e.Message);
                return;
            }
            Assert.Fail();
        }
Exemple #6
0
        public void UpdateEntitySel(string classname, string name)
        {
            entityClassnameText.Text = classname;
            classNameText.Text       = name;

            List <CustomProperty> properties = new List <CustomProperty>();

            string str = NativeAPI.RadiantAPI_GetSelectedEntityAttributesManaged();

            string[] tokens = str.Split(';');
            for (int i = 0; i < tokens.Length - 1; i += 2)
            {
                string key   = tokens[i + 0];
                string value = tokens[i + 1];

                properties.Add(new CustomProperty {
                    Name = key, Desc = "", DefaultValue = value
                });
            }

            var obj = new CustomObjectType {
                props = properties
            };

            entityPropertyGrid.SelectedObject = obj;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RobotObjectConnectionStateEventArgs"/> class.
        /// </summary>
        /// <param name="e">The event.</param>
        internal RobotObjectConnectionStateEventArgs(ExternalInterface.Event e) : base(e)
        {
            var objectConnectionState = e.ObjectEvent.ObjectConnectionState;

            Connected        = objectConnectionState.Connected;
            FactoryId        = objectConnectionState.FactoryId;
            ObjectId         = (int)objectConnectionState.ObjectId;
            ObjectType       = objectConnectionState.ObjectType.ToSdkObjectType();
            CustomObjectType = objectConnectionState.ObjectType.ToSdkCustomObjectType();
        }
Exemple #8
0
        public void TestParseCustomObjectTypeValid()
        {
            //Arrange
            string line = "1. SZKOŁA Nazwa String X double Y double";
            //Act
            CustomObjectType result = Parser.ParseCustomObjectType(line);

            //Assert
            Assert.AreEqual("SZKOŁA", result.Name);
            Assert.AreEqual("Nazwa", result.VariableNames[0]);
            Assert.AreEqual("X", result.VariableNames[1]);
            Assert.AreEqual("Y", result.VariableNames[2]);
            Assert.AreEqual("String", result.VariableTypes[0]);
            Assert.AreEqual("double", result.VariableTypes[1]);
            Assert.AreEqual("double", result.VariableTypes[2]);
        }
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            var stdProps = base.GetProperties(context, value, attributes);
            CustomObjectType      obj         = value as CustomObjectType;
            List <CustomProperty> customProps = obj == null ? null : obj.Properties;

            PropertyDescriptor[] props = new PropertyDescriptor[stdProps.Count + (customProps == null ? 0 : customProps.Count)];
            stdProps.CopyTo(props, 0);
            if (customProps != null)
            {
                int index = stdProps.Count;
                foreach (CustomProperty prop in customProps)
                {
                    props[index++] = new CustomPropertyDescriptor(prop);
                }
            }
            return(new PropertyDescriptorCollection(props));
        }
Exemple #10
0
        public void TestParseCustomObjectTypeNoXCoord()
        {
            //Arrange
            string line = "1. SZKOŁA Nazwa String Y double";

            //Act
            try
            {
                CustomObjectType result = Parser.ParseCustomObjectType(line);
            }
            catch (ParseLineException e)
            {
                //Assert
                Assert.AreEqual("At least one coordinate is missing in object declaration", e.Message);
                return;
            }
            Assert.Fail();
        }
Exemple #11
0
        public void TestParseCustomObjectTypeNoVType()
        {
            //Arrange
            string line = "1. SZKOŁA Nazwa String X double Y";

            //Act
            try
            {
                CustomObjectType result = Parser.ParseCustomObjectType(line);
            }
            catch (ParseLineException e)
            {
                //Assert
                Assert.AreEqual("Incorrect number of arguments - variable does not have name or type", e.Message);
                return;
            }
            Assert.Fail();
        }
Exemple #12
0
        public void TestParseCustomObjectInstanceValid1()
        {
            //Arrange
            string line1 = "2. DOM X double Y double L_MIESZKAŃCÓW int";
            string line2 = "2. DOM 4 3 100";
            //Act
            CustomObjectType        type  = Parser.ParseCustomObjectType(line1);
            List <CustomObjectType> types = new List <CustomObjectType>
            {
                type
            };
            CustomObjectInstance result = Parser.ParseCustomObject(line2, types);
            double resultX       = (double)result.objectProperties[0];
            double resultY       = (double)result.objectProperties[1];
            int    resultLMieszk = (int)result.objectProperties[2];

            //Assert
            Assert.AreEqual(100, resultLMieszk);
            Assert.AreEqual(4, resultX);
            Assert.AreEqual(3, resultY);
        }
Exemple #13
0
        public void TestParseCustomObjectInstanceValid2()
        {
            //Arrange
            string line1 = "1. SZKOŁA Nazwa String X double Y double";
            string line2 = "1. SZKOŁA \"Szkoła robienia dużych pieniędzy\" 4 1";
            //Act
            CustomObjectType        type  = Parser.ParseCustomObjectType(line1);
            List <CustomObjectType> types = new List <CustomObjectType>
            {
                type
            };
            CustomObjectInstance result = Parser.ParseCustomObject(line2, types);
            double resultX     = (double)result.objectProperties[1];
            double resultY     = (double)result.objectProperties[2];
            string resultNazwa = (string)result.objectProperties[0];

            //Assert
            Assert.AreEqual("\"Szkoła robienia dużych pieniędzy\"", resultNazwa);
            Assert.AreEqual(4, resultX);
            Assert.AreEqual(1, resultY);
        }
    static void Main()
    {
        Application.EnableVisualStyles();
        var obj = new CustomObjectType
        {
            Name       = "Foo",
            Properties =
            {
                new CustomProperty {
                    Name = "Bar", Type = typeof(int), Desc = "I'm a bar"
                },
                new CustomProperty {
                    Name = "When", Type = typeof(DateTime), Desc = "When it happened"
                },
            }
        };

        Application.Run(new Form {
            Controls = { new PropertyGrid {
                             SelectedObject = obj, Dock = DockStyle.Fill
                         } }
        });
    }
Exemple #15
0
 public static CustomObjectType ParseCustomObjectType(string line)
 {
     string[] elements = line.Split();
     try
     {
         if (!int.TryParse(elements[0].Substring(0, elements[0].Length - 1), out int index))
         {
             throw new ParseLineException("Line index has to be an integer");
         }
         string           name = elements[1];
         CustomObjectType cot  = new CustomObjectType(name);
         for (int i = 2; i < elements.Length; i++)
         {
             string variableName = elements[i++];
             if (i < elements.Length)
             {
                 string variableType = elements[i];
                 try
                 {
                     cot.AddVariable(variableName, variableType);
                 }
                 catch (ObjectTypeDeclarationException e)
                 {
                     throw new ParseLineException(e.Message);
                 }
             }
             else
             {
                 throw new ParseLineException("Incorrect number of arguments - variable does not have name or type");
             }
         }
         bool isX = false, isY = false;
         for (int i = 0; i < cot.VariableNames.Count; i++)
         {
             if (cot.VariableNames[i] == "X")
             {
                 if (cot.VariableTypes[i] == "double")
                 {
                     isX = true;
                 }
                 else
                 {
                     throw new ParseLineException("X coordinate does not have double type");
                 }
             }
             if (cot.VariableNames[i] == "Y")
             {
                 if (cot.VariableTypes[i] == "double")
                 {
                     isY = true;
                 }
                 else
                 {
                     throw new ParseLineException("Y coordinate does not have double type");
                 }
             }
         }
         if (!(isX && isY))
         {
             throw new ParseLineException("At least one coordinate is missing in object declaration");
         }
         return(cot);
     }
     catch (IndexOutOfRangeException)
     {
         throw new ParseLineException("Too few arguments");
     }
 }
Exemple #16
0
 /// <summary>
 /// Converts to robot type.
 /// </summary>
 /// <param name="customObjectType">Type of the custom object.</param>
 /// <returns>Robot custom object type</returns>
 internal static CustomType ToRobotType(this CustomObjectType customObjectType)
 {
     return((CustomType)customObjectType);
 }
Exemple #17
0
                public override bool ShouldSerializeValue(object component)
                {
                    CustomObjectType obj = (CustomObjectType)component;

                    return(obj.Values.GetOrDefault(prop.Name, prop.Value) != prop.Value);
                }
Exemple #18
0
        public static CustomObjectInstance ParseCustomObject(string line, List <CustomObjectType> customObjectTypes)
        {
            string[] elements = line.Split();
            try
            {
                if (!int.TryParse(elements[0].Substring(0, elements[0].Length - 1), out int index))
                {
                    throw new ParseLineException("Line index has to be an integer");
                }
                string           name = elements[1];
                CustomObjectType cot  = null;
                for (int i = 0; i < customObjectTypes.Count; i++)
                {
                    if (customObjectTypes[i].Name == name)
                    {
                        cot = customObjectTypes[i];
                        break;
                    }
                }
                if (cot == null)
                {
                    throw new ParseLineException("Unrecognised object type");
                }
                object[] objectProperties = new object[cot.VariableNames.Count];
                double   x = 0, y = 0;
                bool     isStringLoading = false;
                string   loadingString   = "";
                for (int i = 2, variableCounter = 0; i < elements.Length; i++)
                {
                    switch (cot.VariableTypes[variableCounter])
                    {
                    case "int":
                        if (!int.TryParse(elements[i], out int argI))
                        {
                            throw new ParseLineException((i - 1) + ". argument is not integer type");
                        }
                        objectProperties[variableCounter] = argI;
                        variableCounter++;
                        break;

                    case "double":
                        if (!double.TryParse(elements[i], out double argD))
                        {
                            throw new ParseLineException((i - 1) + ". argument is not double type");
                        }
                        if (cot.VariableNames[variableCounter] == "X")
                        {
                            x = argD;
                            if (x < 0 || x > 600)
                            {
                                throw new ParseLineException("X coordinate out of range");
                            }
                        }
                        else if (cot.VariableNames[variableCounter] == "Y")
                        {
                            y = argD;
                            if (y < 0 || y > 600)
                            {
                                throw new ParseLineException("Y coordinate out of range");
                            }
                        }
                        objectProperties[variableCounter] = argD;
                        variableCounter++;
                        break;

                    case "float":
                        if (!float.TryParse(elements[i], out float argF))
                        {
                            throw new ParseLineException((i - 1) + ". argument is not float type");
                        }
                        objectProperties[variableCounter] = argF;
                        variableCounter++;
                        break;

                    case "string":
                    case "String":
                        if (!isStringLoading && elements[i][0] != '\"')
                        {
                            throw new ParseLineException((i - 1) + ". argument does not start with \" symbol when string expected");
                        }
                        else if (!isStringLoading && elements[i][0] == '\"' && elements[i][elements[i].Length - 1] != '\"')
                        {
                            isStringLoading = true;
                            loadingString   = loadingString + elements[i];
                        }
                        else if (isStringLoading && elements[i][elements[i].Length - 1] != '\"')
                        {
                            loadingString = loadingString + " " + elements[i];
                        }
                        else if (isStringLoading && elements[i][elements[i].Length - 1] == '\"')
                        {
                            loadingString   = loadingString + " " + elements[i];
                            isStringLoading = false;
                            objectProperties[variableCounter] = loadingString;
                            loadingString = "";
                            variableCounter++;
                        }
                        else
                        {
                            objectProperties[variableCounter] = elements[i];
                            variableCounter++;
                        }
                        break;

                    case "bool":
                        if (!bool.TryParse(elements[i], out bool argB))
                        {
                            throw new ParseLineException((i - 1) + ". argument is not boolean type");
                        }
                        objectProperties[variableCounter] = argB;
                        variableCounter++;
                        break;

                    case "long":
                        if (!long.TryParse(elements[i], out long argL))
                        {
                            throw new ParseLineException((i - 1) + ". argument is not integer type");
                        }
                        objectProperties[variableCounter] = argL;
                        variableCounter++;
                        break;
                    }
                }
                if (objectProperties[objectProperties.Length - 1] == null)
                {
                    throw new ParseLineException("Too few arguments");
                }
                return(new CustomObjectInstance(x, y, cot, objectProperties));
            }
            catch (IndexOutOfRangeException)
            {
                throw new ParseLineException("Too few arguments");
            }
            catch (ArgumentOutOfRangeException)
            {
                throw new ParseLineException("Too many arguments");
            }
        }