Esempio n. 1
0
        private static Tuple <List <Operation>, List <Field> > FakeSpec()
        {
            var operations = new List <Operation>();
            var fields     = new List <Field>();

            IReadOnlyDictionary <MacroOperationType, Type> types = MacroOpManager.FindAll();

            foreach (var t in types)
            {
                MacroOperationType id = t.Key;
                Type type             = t.Value;

                IEnumerable <PropertyInfo> props = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(prop => prop.GetCustomAttribute <NoSerializeAttribute>() == null);

                var opFields = new List <OperationField>();
                foreach (PropertyInfo prop in props)
                {
                    var fieldAttr = prop.GetCustomAttribute <MacroFieldAttribute>();
                    if (fieldAttr == null)
                    {
                        continue;
                    }


                    Tuple <string, bool> mappedType = TypeMappings.MapTypeFull(prop.PropertyType);
                    fields.Add(new Field(fieldAttr.Id, fieldAttr.Name, mappedType.Item1, mappedType.Item2, prop.PropertyType.GetCustomAttributes <FlagsAttribute>().Any() || prop.PropertyType.GetCustomAttributes <XmlAsStringAttribute>().Any()));

                    opFields.Add(new OperationField(fieldAttr.Id, fieldAttr.Name, prop.Name, prop.PropertyType.ToString()));
                }

                operations.Add(new Operation(id.ToString(), type.FullName, opFields, type.GetCustomAttributes <NoMacroFieldsAttribute>().Any()));
            }

            fields     = fields.Distinct().OrderBy(f => f.Id).ToList();
            operations = operations.OrderBy(o => o.Id).ToList();

            var res = new List <Field>();

            foreach (IGrouping <string, Field> grp in fields.GroupBy(f => f.Id))
            {
                FieldEntry[] newTypes = grp.SelectMany(g => g.Entries).ToArray();
                Field        f        = grp.First();
                res.Add(new Field(f.Id, newTypes, f.EnumAsString, f.IsEnum));
            }

            return(Tuple.Create(operations, res));
        }
Esempio n. 2
0
 static AtemConnection()
 {
     AutoSerializeBase.CompilePropertySpecForTypes(CommandManager.GetAllTypes().SelectMany(g => g.Value.Select(t => t.Item2)));
     AutoSerializeBase.CompilePropertySpecForTypes(MacroOpManager.FindAll().Select(m => m.Value.Item2));
 }
Esempio n. 3
0
 static AtemConnection()
 {
     AutoSerializeBase.CompilePropertySpecForTypes(CommandManager.GetAllTypes().Values);
     AutoSerializeBase.CompilePropertySpecForTypes(MacroOpManager.FindAll().Values);
 }
Esempio n. 4
0
        public static MacroSpec CompileData(DeviceProfile profile)
        {
            var res = new MacroSpec();

            foreach (var op in MacroOpManager.FindAll())
            {
                var xmlOp = new MacroOperationSpec()
                {
                    Id = op.Key.ToString()
                };
                res.Operations.Add(xmlOp);

                IEnumerable <PropertyInfo> props = op.Value.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                                                   .Where(prop => prop.GetCustomAttribute <NoSerializeAttribute>() == null)
                                                   .OrderBy(prop => prop.GetCustomAttribute <SerializeAttribute>()?.StartByte ?? 999);

                foreach (PropertyInfo prop in props)
                {
                    var fieldAttr = prop.GetCustomAttribute <MacroFieldAttribute>();
                    if (fieldAttr == null)
                    {
                        continue;
                    }

                    var xmlField = new MacroFieldSpec()
                    {
                        Id   = fieldAttr.Id,
                        Name = fieldAttr.Name,
                        IsId = prop.GetCustomAttribute <CommandIdAttribute>() != null
                    };
                    xmlOp.Fields.Add(xmlField);

                    if (prop.GetCustomAttribute <BoolAttribute>() != null)
                    {
                        xmlField.Type = MacroFieldType.Bool;
                    }
                    else if (prop.GetCustomAttribute <Enum8Attribute>() != null || prop.GetCustomAttribute <Enum16Attribute>() != null || prop.GetCustomAttribute <Enum32Attribute>() != null)
                    {
                        xmlField.Type = prop.PropertyType.GetCustomAttribute <FlagsAttribute>() != null ? MacroFieldType.Flags : MacroFieldType.Enum;

                        string mappedTypeName = TypeMappings.MapType(prop.PropertyType.FullName);
                        Type   mappedType     = prop.PropertyType;
                        if (mappedTypeName != mappedType.FullName && mappedTypeName.IndexOf("System.") != 0)
                        {
                            mappedType = GetType(mappedTypeName);
                        }


                        foreach (object val in Enum.GetValues(mappedType))
                        {
                            string id      = val.ToString();
                            var    xmlAttr = mappedType.GetMember(val.ToString())[0].GetCustomAttribute <XmlEnumAttribute>();
                            if (xmlAttr != null)
                            {
                                id = xmlAttr.Name;
                            }

                            if (!AvailabilityChecker.IsAvailable(profile, val))
                            {
                                continue;
                            }

                            // TODO check value is available for usage location
                            xmlField.Values.Add(new MacroFieldValueSpec()
                            {
                                Id   = id,
                                Name = val.ToString(),
                            });
                        }
                    }
                    else
                    {
                        SetNumericProps(profile, op.Key, xmlField, prop);
                    }
                }
            }

            return(res);
        }