예제 #1
0
        /// <summary>
        /// Loads the XML configuration.
        /// </summary>
        /// <param name="configFilePath">The config file path.</param>
        /// <returns></returns>
        public static ConfigFile Load(string configFilePath)
        {
            var xmlRoot = LoadXmlSettingsElement(configFilePath);

            return(new ConfigFile {
                TrayIconConfig = TrayIconConfig.FromXml(xmlRoot),
                HS110Config = HS110Config.FromXml(xmlRoot),
            });
        }
예제 #2
0
        /// <summary>
        /// Saves the current configuration to the configuration file.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        public void Save(string filePath)
        {
            var xmlRoot = LoadXmlSettingsElement(filePath);

            xmlRoot.AddOrReplaceElement(TrayIconConfig.ToXml());
            xmlRoot.AddOrReplaceElement(HS110Config.ToXml());

            using (var documentWriter = new StreamWriter(filePath, false, new UTF8Encoding(false)))
                new XDocument(FindTopRootElement(xmlRoot)).Save(documentWriter, SaveOptions.None);
        }
예제 #3
0
        /// <summary>
        /// Parses the configuration from XML.
        /// </summary>
        /// <param name="xmlRoot">The XML root.</param>
        /// <returns></returns>
        public static HS110Config FromXml(XElement xmlRoot)
        {
            var config = new HS110Config {
                IpAddress      = xmlRoot.OptionalElement(XmlStrings.RootElementName).OptionalElement(XmlStrings.IpAddressElementName).OptionalValue(""),
                Port           = xmlRoot.OptionalElement(XmlStrings.RootElementName).OptionalElement(XmlStrings.PortElementName).OptionalValue(9999),
                MonitorWattage = xmlRoot.OptionalElement(XmlStrings.RootElementName).OptionalElement(XmlStrings.MonitorWattageElementName).OptionalValue(true),
                MonitorVoltage = xmlRoot.OptionalElement(XmlStrings.RootElementName).OptionalElement(XmlStrings.MonitorVoltageElementName).OptionalValue(false),
                MonitorCurrent = xmlRoot.OptionalElement(XmlStrings.RootElementName).OptionalElement(XmlStrings.MonitorCurrentElementName).OptionalValue(false)
            };

            return(config);
        }