Beispiel #1
0
        public static bool LoadFromFile(string fileName, DeviceCollection devices)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }
            if (devices == null)
            {
                throw new ArgumentNullException(nameof(devices));
            }

            // Read data only once

            string xml = File.ReadAllText(fileName);

            // Try JuisCheck2 file format

            try {
                JC2Data.LoadFromString(xml, devices);
                return(false);
            }
            catch (InvalidOperationException) {
            }

            // Try JuisCheck1 file format

            JC1Data.LoadFromString(xml, devices);
            return(true);
        }
Beispiel #2
0
        public static void SaveToFile(string fileName, DeviceCollection devices)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }
            if (devices == null)
            {
                throw new ArgumentNullException(nameof(devices));
            }

            JC2Data.SaveToFile(fileName, devices);
        }
Beispiel #3
0
        public static void SaveToFile(string fileName, DeviceCollection devices)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }
            if (devices == null)
            {
                throw new ArgumentNullException(nameof(devices));
            }

            using (XmlWriter xmlWriter = XmlWriter.Create(fileName, new XmlWriterSettings {
                Indent = true
            })) {
                JC2Data jc2data = new JC2Data();

                foreach (Device device in devices)
                {
                    if (device is DectDevice dectDevice)
                    {
                        jc2data.DectDevices.Add(new JC2DectDevice(dectDevice));
                    }
                    if (device is JuisDevice juisDevice)
                    {
                        jc2data.JuisDevices.Add(new JC2JuisDevice(juisDevice));
                    }
                }

                foreach (KeyValuePair <string, string> setting in devices.Settings.GetDictionary())
                {
                    jc2data.Settings.Add(new JC2Setting(setting.Key, setting.Value));
                }

                XmlSerializer xmlSerializer = new XmlSerializer(typeof(JC2Data));
                xmlSerializer.Serialize(xmlWriter, jc2data);
            }
        }
Beispiel #4
0
        public static void LoadFromString(string xml, DeviceCollection devices)
        {
            if (xml == null)
            {
                throw new ArgumentNullException(nameof(xml));
            }
            if (devices == null)
            {
                throw new ArgumentNullException(nameof(devices));
            }

            XmlReaderSettings xmlReaderSettings = new XmlReaderSettings()
            {
                IgnoreComments = true, IgnoreWhitespace = true
            };
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(JC2Data));

            using (XmlReader xmlReader = XmlReader.Create(new StringReader(xml), xmlReaderSettings)) {
                JC2Data jc2data = (JC2Data)xmlSerializer.Deserialize(xmlReader);

                devices.Clear();
                foreach (JC2DectDevice jc2dectDevice in jc2data.DectDevices)
                {
                    devices.Add(new DectDevice(jc2dectDevice));
                }
                foreach (JC2JuisDevice jc2juisDevice in jc2data.JuisDevices)
                {
                    devices.Add(new JuisDevice(jc2juisDevice));
                }

                devices.Settings.Reset();
                foreach (JC2Setting setting in jc2data.Settings)
                {
                    devices.Settings.Add(setting.Name, setting.Value);
                }
            }
        }