コード例 #1
0
ファイル: JCData.cs プロジェクト: kingfisher63/avm_juischeck
        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);
        }
コード例 #2
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(JC1Data));

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

                devices.Clear();
                foreach (JC1Device jc1device in jc1data.Devices)
                {
                    if (jc1device.DeviceKind == JC1DeviceKind.DECT)
                    {
                        devices.Add(new DectDevice(jc1device));
                    }
                    if (jc1device.DeviceKind == JC1DeviceKind.JUIS)
                    {
                        devices.Add(new JuisDevice(jc1device));
                    }
                }

                devices.Settings.Reset();
            }
        }