Exemplo n.º 1
0
        public bool Save(ServerSettings ss)
        {
            bool ret = false;

            XmlDocument doc = new XmlDocument();

            doc.Load(this.settings_path);

            if (Check(ss, doc.DocumentElement))
            {
                throw new SettingsException(SettingsException.ExceptionTypes.DUPLICATE_ENTRY);
            }

            #region xml fragment settings
            string xmlfrag = @"
    <server dummy='{10}'>
        <uid>{0}</uid>
	    <servername>{1}</servername>
	    <server>{2}</server>
	    <username>{3}</username>
	    <password>{4}</password>
	    <description>{5}</description>
	    <colordepth>{6}</colordepth>
	    <desktopwidth>{7}</desktopwidth>
	    <desktopheight>{8}</desktopheight>
	    <fullscreen>{9}</fullscreen>
        <port>{11}</port>
        <gid>{12}</gid>
    </server>
";
            xmlfrag = string.Format(xmlfrag,
                                    ss.UID,
                                    ss.ServerName,
                                    ss.Server,
                                    ss.Username,
                                    (ss.Password == string.Empty ? string.Empty : RijndaelSettings.Encrypt(ss.Password)),
                                    ss.Description,
                                    ss.ColorDepth,
                                    ss.DesktopWidth,
                                    ss.DesktopHeight,
                                    ss.Fullscreen,
                                    ss.UID,
                                    ss.Port
                                    );
            #endregion

            XmlDocumentFragment docFrag = doc.CreateDocumentFragment();
            docFrag.InnerXml = xmlfrag;

            XmlNode curNode = doc.DocumentElement;
            curNode.InsertAfter(docFrag, curNode.LastChild);

            doc.Save(this.settings_path);

            ret = true;

            return(ret);
        }
Exemplo n.º 2
0
            private void GetDatas()
            {
                if (nav.SelectSingleNode("./uid") != null)
                {
                    this._uid = nav.SelectSingleNode("./uid").Value;
                }

                if (nav.SelectSingleNode("./servername") != null)
                {
                    this._serverName = nav.SelectSingleNode("./servername").Value;
                }

                if (nav.SelectSingleNode("./server") != null)
                {
                    this._server = nav.SelectSingleNode("./server").Value;
                }

                if (nav.SelectSingleNode("./port") != null)
                {
                    string val = nav.SelectSingleNode("./port").Value;
                    this._port = int.Parse(val == string.Empty ? "0" : val);
                }

                if (nav.SelectSingleNode("./username") != null)
                {
                    this._username = nav.SelectSingleNode("./username").Value;
                }

                if (nav.SelectSingleNode("./password") != null)
                {
                    string password = nav.SelectSingleNode("./password").Value;

                    if (password != string.Empty)
                    {
                        this._password = RijndaelSettings.Decrypt(password);
                    }
                }

                if (nav.SelectSingleNode("./description") != null)
                {
                    this._description = nav.SelectSingleNode("./description").Value;
                }

                if (nav.SelectSingleNode("./colordepth") != null)
                {
                    this._colorDepth = int.Parse(nav.SelectSingleNode("./colordepth").Value);
                }

                if (nav.SelectSingleNode("./desktopwidth") != null)
                {
                    this._desktopWidth = int.Parse(nav.SelectSingleNode("./desktopwidth").Value);
                }

                if (nav.SelectSingleNode("./desktopheight") != null)
                {
                    this._desktopHeight = int.Parse(nav.SelectSingleNode("./desktopheight").Value);
                }

                if (nav.SelectSingleNode("./fullscreen") != null)
                {
                    this._fullScreen = bool.Parse(nav.SelectSingleNode("./fullscreen").Value);
                }

                if (nav.SelectSingleNode("./gid") != null)
                {
                    this._groupID = int.Parse(nav.SelectSingleNode("./gid").Value);
                }
            }
Exemplo n.º 3
0
        public bool Update(ServerSettings ss, ServerSettings oldSS)
        {
            bool ret = false;

            XmlDocument doc = new XmlDocument();

            doc.Load(this.settings_path);

            // check if the user made some changes on Server Name and Server address
            if ((ss.ServerName != oldSS.ServerName) || (ss.Server != oldSS.Server))
            {
                // if so, then check if both of these settings has a duplicate on our db
                if (Check(ss, doc.DocumentElement))
                {
                    throw new SettingsException(SettingsException.ExceptionTypes.DUPLICATE_ENTRY);
                }
            }

            #region xml fragment settings
            string xmlfrag = @"
        <uid>{0}</uid>
	    <servername>{1}</servername>
	    <server>{2}</server>
	    <username>{3}</username>
	    <password>{4}</password>
	    <description>{5}</description>
	    <colordepth>{6}</colordepth>
	    <desktopwidth>{7}</desktopwidth>
	    <desktopheight>{8}</desktopheight>
	    <fullscreen>{9}</fullscreen>
        <port>{10}</port>
        <gid>{11}</gid>
";
            xmlfrag = string.Format(xmlfrag,
                                    oldSS.UID,
                                    ss.ServerName,
                                    ss.Server,
                                    ss.Username,
                                    RijndaelSettings.Encrypt(ss.Password),
                                    ss.Description,
                                    ss.ColorDepth,
                                    ss.DesktopWidth,
                                    ss.DesktopHeight,
                                    ss.Fullscreen,
                                    //ss.ServerName, ss.Server,
                                    ss.Port
                                    );
            #endregion

            XmlElement curNode = doc.DocumentElement;
            XmlNode    oldNode = curNode.SelectSingleNode("/serverlists/server[@dummy=\"" + oldSS.UID + "\"]");

            XmlElement newNode = doc.CreateElement("server");

            newNode.SetAttribute("dummy", oldSS.UID);
            newNode.InnerXml = xmlfrag;

            curNode.ReplaceChild(newNode, oldNode);

            doc.Save(this.settings_path);

            ret = true;

            return(ret);
        }