Exemplo n.º 1
0
        private void mephobiaButton3_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Trim().Length != 0 && textBox2.Text.Trim().Length != 0)
            {
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(Settings.Default["xml_filename"].ToString());

                    string usernamePath = "ServerInfo/Account[Username='******']";
                    string passwordPath = "ServerInfo/Account[Password='******']";

                    XmlNode _username = doc.SelectSingleNode(usernamePath);
                    XmlNode _password = _username.FirstChild.NextSibling;

                    if (textBox1.Text != _username.FirstChild.InnerText)
                    {
                        _username.FirstChild.InnerText = textBox1.Text;
                    }

                    if (textBox2.Text != _username.LastChild.InnerText)
                    {
                        _password.LastChild.InnerText = MyFunctions.base64Encode(textBox2.Text.ToString());
                    }

                    doc.Save(Settings.Default["xml_filename"].ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            this.Dispose();
            this.Close();
        }
Exemplo n.º 2
0
        private void mephobiaButton2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Trim().Length != 0 && textBox2.Text.Trim().Length != 0)
            {
                try
                {
                    XDocument doc   = XDocument.Load(Settings.Default["xml_filename"].ToString());
                    XElement  Realm = new XElement("Account", new XElement("Username", textBox1.Text),
                                                   new XElement("Password", MyFunctions.base64Encode(textBox2.Text.ToString())));
                    doc.Root.Add(Realm);
                    doc.Save(Settings.Default["xml_filename"].ToString());
                }
                catch
                {
                    // Exceptions: wrong xml structure, empty file
                    //- So we create a new xml configuration file
                    Form1 form1 = new Form1();
                    form1.CreateDefaultXMLConfFile();

                    //- We add new data which failed in this exception
                    XDocument doc   = XDocument.Load(Settings.Default["xml_filename"].ToString());
                    XElement  Realm = new XElement("Account", new XElement("Username", textBox1.Text),
                                                   new XElement("Password", MyFunctions.base64Encode(textBox2.Text.ToString())));
                    doc.Root.Add(Realm);

                    doc.Save(Settings.Default["xml_filename"].ToString());
                    MessageBox.Show("An error was ocurred while adding new data in configuration file, we recommend you to restart your application.");
                }
            }
            this.Dispose();
            this.Close();
        }