Exemplo n.º 1
0
        public static XMLConfig Deserialize()
        {
            XMLConfig config;

            if (!File.Exists("config.xml"))
            {
                return(new XMLConfig());
            }
            Type[]        contains = { typeof(xmlServer) };
            XmlSerializer x        = new XmlSerializer(typeof(XMLConfig), contains);

            using (StreamReader streamreader = System.IO.File.OpenText("config.xml"))
            {
                try
                {
                    config = (XMLConfig)x.Deserialize(streamreader);
                    config.VerifyValues();
                }
                catch (Exception)
                {
                    Console.WriteLine("Error deserializing XMLconfig from config.xml");
                    config = new XMLConfig();
                    throw;
                }
            }

            return(config);
        }
Exemplo n.º 2
0
        public ControlBox()
        {
            instance = this;
            InitializeComponent();
            formTitle = AssemblyTitle + " Configuration";
            //Add XML servers

            config = XmlHandler.Deserialize(); //not interfering with anything the server might use.

            for (int i = 0; i < config.ServerList.Count; i++)
            {
                // Read from config and fill in the provided info
                int outerHeight = GBServer.outerHeight; //20 + (GBServer.innerHeight * 4) + 40;

                int y = i * outerHeight;                //outer y offset

                GBServer server = new GBServer(i, config.ServerList[i].Name, config.ServerList[i].FilePath, config.ServerList[i].AllowInput);
                server.SetLocation(0, y);
                ListServerBox.Add(server);
                ServerBox.Controls.Add(server.gbServer);
            }
            UpdateScrollHeight();

            this.Text = MCDaemon.ControlBox.Instance.formTitle;


            toolTip1.SetToolTip(this.buttonAdd, "Add server");
            toolTip1.SetToolTip(this.buttonApply, "Save config");

            TbHost.Text   = config.Host;
            NumPort.Value = config.Port;

            TbHost.TextChanged   += GBServer.Config_Changed;
            NumPort.ValueChanged += GBServer.Config_Changed;
        }
Exemplo n.º 3
0
        private void MakeServerList()
        {
            XMLConfig con = XmlHandler.Deserialize();

            for (int i = 0; i < con.ServerList.Count; i++)
            {
                mcservers.Add(new MCServer(con.ServerList[i].Name, con.ServerList[i].FilePath, con.ServerList[i].AllowInput));
            }
            Host = con.Host;
            Port = con.Port;
        }
Exemplo n.º 4
0
        public static void Serialize(XMLConfig config)
        {
            Type[]        contains = { typeof(xmlServer) };
            XmlSerializer x        = new XmlSerializer(typeof(XMLConfig), contains);

            // TextWriter writer = new StreamWriter("config.xml");
            //x.Serialize(writer, config);
            using (StreamWriter streamWriter = System.IO.File.CreateText("config.xml"))
            {
                x.Serialize(streamWriter, config);
            }
        }
Exemplo n.º 5
0
        private void SaveXml()
        {
            List <xmlServer> xserver = new List <xmlServer>();

            for (int i = 0; i < ListServerBox.Count; i++)
            {
                xserver.Add(ListServerBox[i].ToXmlServer());
            }

            XMLConfig tmp = new XMLConfig(xserver, TbHost.Text, (ushort)NumPort.Value);

            XmlHandler.Serialize(tmp);
        }