Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Account a = new Account();

            a.AccountName     = "";
            a.AccountPassword = "";
            Server s = new Server();

            s.Acc = new List <Account>();
            s.Acc.Add(a);
            s.ServerName = textBox1.Text;

            Models.Datadisk d = new Models.Datadisk();
            d.datadiskName = comboBox1.Text;
            d.servers      = new List <Server>();
            //d.servers.Add(s);

            int isinDB = 0;

            foreach (Models.Datadisk dad in AppData.Database)
            {
                if (dad.datadiskName == d.datadiskName)
                {
                    dad.servers.Add(s);
                    isinDB = 1;
                    break;
                }
            }

            if (isinDB == 0)
            {
                AppData.Database.Add(d);
            }


            this.Close();
        }
Exemplo n.º 2
0
Arquivo: XML.cs Projeto: xkolm036/RLMS
        /// <summary>
        /// Read Xml database
        /// </summary>
        /// <returns>List of datadisk</returns>
        public static List <Models.Datadisk> ReadXMlFile()
        {
            List <Models.Datadisk> database = new List <Models.Datadisk>();

            Models.Datadisk d  = new Models.Datadisk();
            Server          s  = new Server();
            List <Account>  a  = new List <Account>();
            List <Server>   LS = new List <Server>();


            using (XmlReader xr = XmlReader.Create(@"Database.xml"))
            {
                while (xr.Read())
                {
                    if (xr.NodeType == XmlNodeType.Element)
                    {
                        if (xr.Depth == 1)
                        {
                            d = new Models.Datadisk();
                            d.datadiskName = xr.Name;
                            d.datadiskName = xr.GetAttribute("DatadiskName");
                            //     d.patchVersion = xr.GetAttribute("patchVersion");
                            d.iconPath = xr.GetAttribute("iconPath");
                        }
                        if (xr.Depth == 2)
                        {
                            s              = new Server();
                            s.ServerName   = xr.GetAttribute("ServerName");
                            s.ConfigPath   = xr.GetAttribute("ConfigPath");
                            s.RealmList    = xr.GetAttribute("RealmList");
                            s.ExePath      = xr.GetAttribute("ExePath");
                            s.Website      = xr.GetAttribute("Website");
                            s.patchVersion = xr.GetAttribute("patchVersion");
                        }

                        if (xr.Depth == 3)
                        {
                            Account acc = new Account();
                            acc.AccountName     = xr.GetAttribute("AccountName");
                            acc.AccountPassword = xr.GetAttribute("AccountPassword");
                            acc.CharacterInfo   = xr.GetAttribute("CharacterInfo");
                            a.Add(acc);
                        }
                    }

                    if (xr.NodeType == XmlNodeType.EndElement)
                    {
                        if (xr.Depth == 2)
                        {
                            s.Acc = new List <Account>();
                            foreach (Account ak in a)
                            {
                                s.Acc.Add(ak);
                            }

                            LS.Add(s);
                            a.Clear();
                        }

                        if (xr.Depth == 1)
                        {
                            d.servers = new List <Server>();
                            foreach (Server sr in LS)
                            {
                                d.servers.Add(sr);
                            }


                            database.Add(d);
                            LS.Clear();
                        }
                    }
                }
            }

            return(database);
        }