public IEnumerable <string> DeserializeInterface(HeliosInterfaceCollection destination, XmlReader xmlReader) { string interfaceType = xmlReader.GetAttribute("TypeIdentifier"); ComponentUnsupportedSeverity unsupportedSeverity = ReadUnsupportedSeverity(xmlReader); HeliosInterface heliosInterface = (HeliosInterface)CreateNewObject("Interface", interfaceType, unsupportedSeverity); if (heliosInterface != null) { string name = xmlReader.GetAttribute("Name"); if (xmlReader.IsEmptyElement) { // don't read from empty XML element xmlReader.Read(); } else { xmlReader.ReadStartElement("Interface"); heliosInterface.ReadXml(xmlReader); xmlReader.ReadEndElement(); } heliosInterface.Name = name; heliosInterface.UnsupportedSeverity = unsupportedSeverity; destination.Add(heliosInterface); yield return($"loaded {heliosInterface.TypeIdentifier} {heliosInterface.Name}"); } else { xmlReader.Skip(); yield return("failed to load interface"); } }
protected object CreateNewObject(string type, string typeId, ComponentUnsupportedSeverity ifUnsupported = ComponentUnsupportedSeverity.Error) { switch (type) { case "Monitor": return(new Monitor()); case "Visual": HeliosVisual visual = ConfigManager.ModuleManager.CreateControl(typeId); if (visual == null) { Logger.Error("Ignoring control not supported by this version of Helios: " + typeId); return(null); } return(visual); case "Interface": HeliosInterfaceDescriptor descriptor = ConfigManager.ModuleManager.InterfaceDescriptors[typeId]; if (descriptor == null) { switch (ifUnsupported) { case ComponentUnsupportedSeverity.Error: Logger.Error("Ignoring interface not supported by this version of Helios: {TypeId}; bindings to this interface will fail", typeId); return(null); case ComponentUnsupportedSeverity.Warning: Logger.Warn("Ignoring interface not supported by this version of Helios: {TypeId}; bindings to this interface will fail", typeId); return(null); case ComponentUnsupportedSeverity.Ignore: Logger.Info("Ignoring interface not supported by this version of Helios: {TypeId}; bindings to this interface will be silently ignored", typeId); // create a dummy interface that preserves the XML and ignores but allows writing of all bindings UnsupportedInterface dummy = new UnsupportedInterface(); dummy.RepresentedTypeIdentifier = typeId; // record interface type alias, but don't install it yet because we may read more instances of this interface // alias will allow resolution of the unsupported class to our dummy for use in places where we try to instantiate the editor HeliosInterfaceDescriptor dummyDescriptor = ConfigManager.ModuleManager.InterfaceDescriptors[UnsupportedInterface.TYPE_IDENTIFIER]; if (DiscoveredAliases != null) { DiscoveredAliases[typeId] = dummyDescriptor; } return(dummy); default: throw new ArgumentOutOfRangeException(nameof(ifUnsupported), ifUnsupported, null); } } return(descriptor.CreateInstance()); case "Binding": return(new HeliosBinding()); } return(null); }