/// <summary> /// Sets the default values. /// </summary> protected override void SetToDefault() { ConnectionOptions = new OpcConnectionOptions(); EditingOptions = new EditingOptions(); Subscriptions = new List <SubscriptionConfig>(); Commands = new List <CommandConfig>(); }
/// <summary> /// Saves the configuration to the specified writer. /// </summary> protected override void Save(TextWriter writer) { XmlDocument xmlDoc = new XmlDocument(); XmlDeclaration xmlDecl = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); xmlDoc.AppendChild(xmlDecl); XmlElement rootElem = xmlDoc.CreateElement("OpcDeviceConfig"); xmlDoc.AppendChild(rootElem); ConnectionOptions.SaveToXml(rootElem.AppendElem("ConnectionOptions")); EditingOptions.SaveToXml(rootElem.AppendElem("EditingOptions")); XmlElement subscriptionsElem = rootElem.AppendElem("Subscriptions"); XmlElement commandsElem = rootElem.AppendElem("Commands"); foreach (SubscriptionConfig subscriptionConfig in Subscriptions) { subscriptionConfig.SaveToXml(subscriptionsElem.AppendElem("Subscription")); } foreach (CommandConfig commandConfig in Commands) { commandConfig.SaveToXml(commandsElem.AppendElem("Command")); } xmlDoc.Save(writer); }
/// <summary> /// Loads the configuration from the specified reader. /// </summary> protected override void Load(TextReader reader) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(reader); XmlElement rootElem = xmlDoc.DocumentElement; if (rootElem.SelectSingleNode("ConnectionOptions") is XmlNode connectionOptionsNode) { ConnectionOptions.LoadFromXml(connectionOptionsNode); } if (rootElem.SelectSingleNode("EditingOptions") is XmlNode editingOptionsNode) { EditingOptions.LoadFromXml(editingOptionsNode); } if (rootElem.SelectSingleNode("Subscriptions") is XmlNode subscriptionsNode) { foreach (XmlElement subscriptionElem in subscriptionsNode.SelectNodes("Subscription")) { SubscriptionConfig subscriptionConfig = new SubscriptionConfig(); subscriptionConfig.LoadFromXml(subscriptionElem); Subscriptions.Add(subscriptionConfig); } } if (rootElem.SelectSingleNode("Commands") is XmlNode commandsNode) { foreach (XmlElement commandElem in commandsNode.SelectNodes("Command")) { CommandConfig commandConfig = new CommandConfig(); commandConfig.LoadFromXml(commandElem); Commands.Add(commandConfig); } } }