|
3 | 3 | using System.Linq;
|
4 | 4 | using System.Reflection;
|
5 | 5 | using System.Xml.Serialization;
|
| 6 | +using LibAtem; |
6 | 7 | using LibAtem.Commands;
|
7 | 8 | using LibAtem.Common;
|
8 | 9 | using LibAtem.DeviceProfile;
|
@@ -41,6 +42,8 @@ public CommandSpec()
|
41 | 42 | public string FullName { get; set; }
|
42 | 43 | public string Name { get; set; }
|
43 | 44 |
|
| 45 | + public ProtocolVersion InitialVersion { get; set; } |
| 46 | + |
44 | 47 | public bool IsValid { get; set; }
|
45 | 48 |
|
46 | 49 | public List<CommandProperty> Properties { get; set; }
|
@@ -77,75 +80,84 @@ public static CommandsSpec CompileData(DeviceProfile profile)
|
77 | 80 | {
|
78 | 81 | var res = new CommandsSpec();
|
79 | 82 |
|
80 |
| - foreach (var cmd in CommandManager.GetAllTypes()) |
| 83 | + foreach (var cmdSet in CommandManager.GetAllTypes()) |
81 | 84 | {
|
82 |
| - var spec = res.Commands[cmd.Value.FullName] = new CommandSpec |
83 |
| - { |
84 |
| - FullName = cmd.Value.FullName, |
85 |
| - Name = cmd.Value.Name |
86 |
| - }; |
87 |
| - |
88 |
| - if (typeof(SerializableCommandBase).GetTypeInfo().IsAssignableFrom(cmd.Value)) |
| 85 | + foreach (var cmd in cmdSet.Value) |
89 | 86 | {
|
90 |
| - spec.IsValid = true; |
| 87 | + var spec = res.Commands[cmd.Item2.FullName] = new CommandSpec |
| 88 | + { |
| 89 | + FullName = cmd.Item2.FullName, |
| 90 | + Name = cmd.Item2.Name, |
| 91 | + InitialVersion = cmd.Item1 |
| 92 | + }; |
91 | 93 |
|
92 |
| - foreach (PropertyInfo prop in cmd.Value.GetProperties( |
93 |
| - BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) |
| 94 | + if (typeof(SerializableCommandBase).GetTypeInfo().IsAssignableFrom(cmd.Item2)) |
94 | 95 | {
|
95 |
| - // If prop cannot be deserialized, then ignore |
96 |
| - if (!prop.CanWrite || prop.GetSetMethod() == null) |
97 |
| - continue; |
| 96 | + spec.IsValid = true; |
98 | 97 |
|
99 |
| - if (prop.GetCustomAttribute<NoSerializeAttribute>() != null) |
100 |
| - continue; |
101 |
| - |
102 |
| - //TODO |
103 |
| - var resProp = new CommandProperty |
104 |
| - { |
105 |
| - Name = prop.Name, |
106 |
| - IsId = prop.GetCustomAttributes<CommandIdAttribute>().Any() |
107 |
| - }; |
108 |
| - |
109 |
| - if (prop.GetCustomAttribute<BoolAttribute>() != null) |
110 |
| - { |
111 |
| - resProp.Type = CommandPropertyType.Bool; |
112 |
| - } |
113 |
| - else if (prop.GetCustomAttribute<Enum8Attribute>() != null || prop.GetCustomAttribute<Enum16Attribute>() != null || prop.GetCustomAttribute<Enum32Attribute>() != null) |
| 98 | + foreach (PropertyInfo prop in cmd.Item2.GetProperties( |
| 99 | + BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) |
114 | 100 | {
|
115 |
| - resProp.Type = prop.PropertyType.GetCustomAttribute<FlagsAttribute>() != null ? CommandPropertyType.Flags : CommandPropertyType.Enum; |
| 101 | + // If prop cannot be deserialized, then ignore |
| 102 | + if (!prop.CanWrite || prop.GetSetMethod() == null) |
| 103 | + continue; |
116 | 104 |
|
117 |
| - /* string mappedTypeName = TypeMappings.MapType(prop.PropertyType.FullName); |
118 |
| - Type mappedType = prop.PropertyType; |
119 |
| - if (mappedTypeName != mappedType.FullName && mappedTypeName.IndexOf("System.") != 0) |
120 |
| - mappedType = GetType(mappedTypeName); |
| 105 | + if (prop.GetCustomAttribute<NoSerializeAttribute>() != null) |
| 106 | + continue; |
121 | 107 |
|
| 108 | + //TODO |
| 109 | + var resProp = new CommandProperty |
| 110 | + { |
| 111 | + Name = prop.Name, |
| 112 | + IsId = prop.GetCustomAttributes<CommandIdAttribute>().Any() |
| 113 | + }; |
122 | 114 |
|
123 |
| - foreach (object val in Enum.GetValues(mappedType)) |
| 115 | + if (prop.GetCustomAttribute<BoolAttribute>() != null) |
| 116 | + { |
| 117 | + resProp.Type = CommandPropertyType.Bool; |
| 118 | + } |
| 119 | + else if (prop.GetCustomAttribute<Enum8Attribute>() != null || |
| 120 | + prop.GetCustomAttribute<Enum16Attribute>() != null || |
| 121 | + prop.GetCustomAttribute<Enum32Attribute>() != null) |
124 | 122 | {
|
125 |
| - string id = val.ToString(); |
126 |
| - var xmlAttr = mappedType.GetMember(val.ToString())[0].GetCustomAttribute<XmlEnumAttribute>(); |
127 |
| - if (xmlAttr != null) |
128 |
| - id = xmlAttr.Name; |
| 123 | + resProp.Type = prop.PropertyType.GetCustomAttribute<FlagsAttribute>() != null |
| 124 | + ? CommandPropertyType.Flags |
| 125 | + : CommandPropertyType.Enum; |
129 | 126 |
|
130 |
| - if (!AvailabilityChecker.IsAvailable(profile, val)) |
131 |
| - continue; |
| 127 | + /* string mappedTypeName = TypeMappings.MapType(prop.PropertyType.FullName); |
| 128 | + Type mappedType = prop.PropertyType; |
| 129 | + if (mappedTypeName != mappedType.FullName && mappedTypeName.IndexOf("System.") != 0) |
| 130 | + mappedType = GetType(mappedTypeName); |
| 131 | + |
| 132 | + |
| 133 | + foreach (object val in Enum.GetValues(mappedType)) |
| 134 | + { |
| 135 | + string id = val.ToString(); |
| 136 | + var xmlAttr = mappedType.GetMember(val.ToString())[0].GetCustomAttribute<XmlEnumAttribute>(); |
| 137 | + if (xmlAttr != null) |
| 138 | + id = xmlAttr.Name; |
| 139 | + |
| 140 | + if (!AvailabilityChecker.IsAvailable(profile, val)) |
| 141 | + continue; |
| 142 | + |
| 143 | + // TODO check value is available for usage location |
| 144 | + xmlField.Values.Add(new MacroFieldValueSpec() |
| 145 | + { |
| 146 | + Id = id, |
| 147 | + Name = val.ToString(), |
| 148 | + }); |
| 149 | + }*/ |
| 150 | + } |
| 151 | + else |
| 152 | + { |
| 153 | + SetNumericProps(profile, cmd.Item2, resProp, prop); |
| 154 | + } |
132 | 155 |
|
133 |
| - // TODO check value is available for usage location |
134 |
| - xmlField.Values.Add(new MacroFieldValueSpec() |
135 |
| - { |
136 |
| - Id = id, |
137 |
| - Name = val.ToString(), |
138 |
| - }); |
139 |
| - }*/ |
140 |
| - } |
141 |
| - else |
142 |
| - { |
143 |
| - SetNumericProps(profile, cmd.Value, resProp, prop); |
| 156 | + spec.Properties.Add(resProp); |
144 | 157 | }
|
145 |
| - |
146 |
| - spec.Properties.Add(resProp); |
147 | 158 | }
|
148 | 159 | }
|
| 160 | + |
149 | 161 | /*
|
150 | 162 | var xmlOp = new MacroOperationSpec() {Id = op.Key.ToString()};
|
151 | 163 | res.Operations.Add(xmlOp);
|
@@ -279,7 +291,7 @@ private static void SetNumericProps(DeviceProfile profile, Type cmdType, Command
|
279 | 291 |
|
280 | 292 | private static T GetDefaultForField<T>(DeviceProfile profile, Type cmdType, CommandProperty field)
|
281 | 293 | {
|
282 |
| - return (T) AvailabilityChecker.GetMaxForCommandProperty(profile, string.Format("{0}.{1}", cmdType.Name, field.Name)); |
| 294 | + return (T) AvailabilityChecker.GetMaxForCommandProperty(profile, $"{cmdType.Name}.{field.Name}"); |
283 | 295 | }
|
284 | 296 | }
|
285 | 297 | }
|
0 commit comments