예제 #1
0
        void IGXSettingsPage.Apply()
        {
            GuruxAmiSettings addresses = new GuruxAmiSettings();
            List <string>    items     = new List <string>();

            if (EnabledCb.Checked && ServerAddress.Text == "")
            {
                throw new Exception("Invalid Gurux.DLMS.AMI address.");
            }
            Properties.Settings.Default.ServerAddress = ServerAddress.Text;
            Properties.Settings.Default.Save();
            if (!string.IsNullOrEmpty(ServerAddress.Text))
            {
                items.Add(ServerAddress.Text);
            }
            foreach (string it in ServerAddress.Items)
            {
                if (!items.Contains(it))
                {
                    items.Add(it);
                }
            }
            addresses.Servers = items.ToArray();
            string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "GXDLMSDirector");

            path = Path.Combine(path, "gurux.dlms.ami.settings");
            using (Stream stream = File.Open(path, FileMode.Create))
            {
                XmlSerializer x = new XmlSerializer(typeof(GuruxAmiSettings));
                x.Serialize(stream, addresses);
                stream.Flush();
            }
        }
예제 #2
0
        public static string[] GetServerAddress()
        {
            string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "GXDLMSDirector");

            path = Path.Combine(path, "gurux.dlms.ami.settings");
            if (File.Exists(path) && new FileInfo(path).Length != 0)
            {
                using (XmlReader reader = XmlReader.Create(path))
                {
                    XmlSerializer    x         = new XmlSerializer(typeof(GuruxAmiSettings));
                    GuruxAmiSettings addresses = (GuruxAmiSettings)x.Deserialize(reader);
                    return(addresses.Servers);
                }
            }
            return(new string[0]);
        }