コード例 #1
0
        public MainWizard()
        {
            InitializeComponent();


            // Load existing xml settings if present
            try
            {
                //Retrieve and store the imported xml data
                InstallImporter importer = new InstallImporter();
                string          fileName = "config.xml";
                baseSettings = importer.Deserialize(fileName);
            }
            catch (Exception x)
            {
                baseSettings = new FullInstallSettings();
            }

            //Auto populate the network fields.
            txtCallsign.Text = baseSettings.CallSign;

            //Split the pulled data on the dot and populate the ip textboxes
            try
            {
                string[] ipArray = baseSettings.IpAddress.Split('.');
                ipMi1.Text = ipArray[0];
                ipMi2.Text = ipArray[1];
                ipMi3.Text = ipArray[2];
                ipMi4.Text = ipArray[3];

                string[] subnetArray = baseSettings.SubnetMask.Split('.');
                subnetMi1.Text = subnetArray[0];
                subnetMi2.Text = subnetArray[1];
                subnetMi3.Text = subnetArray[2];
                subnetMi4.Text = subnetArray[3];

                string[] gatewayArray = baseSettings.DefaultGateway.Split('.');
                gatewayMi1.Text = gatewayArray[0];
                gatewayMi2.Text = gatewayArray[1];
                gatewayMi3.Text = gatewayArray[2];
                gatewayMi4.Text = gatewayArray[3];

                string[] prefDns = baseSettings.PreferredDns.Split('.');
                prefDnsMi1.Text = prefDns[0];
                prefDnsMi2.Text = prefDns[1];
                prefDnsMi3.Text = prefDns[2];
                prefDnsMi4.Text = prefDns[3];

                string[] altArray = baseSettings.AlternateDns.Split('.');
                altDnsMi1.Text = altArray[0];
                altDnsMi2.Text = altArray[1];
                altDnsMi3.Text = altArray[2];
                altDnsMi4.Text = altArray[3];
            }
            catch (Exception)
            {
            }


            rdbManualIP.Checked = (baseSettings.Dhcp.Equals("false")) ? true : false;
        }
コード例 #2
0
        private void wizardControl1_Finished(object sender, EventArgs e)
        {
            // Collect all input settings and prepare for xml serialization
            finalSettings          = new FullInstallSettings();
            finalSettings.CallSign = txtCallsign.Text;
            finalSettings.Dhcp     = (rdbAutoIP.Checked == true) ? "true" : "false";
            finalSettings.Updated  = DateTime.Now.ToString("yyyyMMddHHmm");

            string          xmlResult = "";
            InstallImporter importer  = null;

            if (rdbAutoIP.Checked) //Discard any old imported network settings
            {
            }
            else // Use new settings
            {
                // Concat all the boxes for each field together and then remove all whitespace just as a safety measure
                finalSettings.IpAddress = ipMi1.Text + "." + ipMi2.Text + "." + ipMi3.Text + "." + ipMi4.Text;
                finalSettings.IpAddress.Replace(" ", string.Empty);
                finalSettings.SubnetMask = subnetMi1.Text + "." + subnetMi2.Text + "." + subnetMi3.Text + "." + subnetMi4.Text;
                finalSettings.SubnetMask.Replace(" ", string.Empty);
                finalSettings.DefaultGateway = gatewayMi1.Text + "." + gatewayMi2.Text + "." + gatewayMi3.Text + "." + gatewayMi4.Text;
                finalSettings.DefaultGateway.Replace(" ", string.Empty);
                finalSettings.PreferredDns = prefDnsMi1.Text + "." + prefDnsMi2.Text + "." + prefDnsMi3.Text + "." + prefDnsMi4.Text;
                finalSettings.PreferredDns.Replace(" ", string.Empty);
                string altdns = altDnsMi1.Text + "." + altDnsMi2.Text + "." + altDnsMi3.Text + "." + altDnsMi4.Text;

                //If alternate dns is only 3 characters ("..."), save it as an empty string, else, use the inputed altDns
                if (altdns.Length == 3)
                {
                    finalSettings.AlternateDns = "";
                }
                else
                {
                    finalSettings.AlternateDns = altdns;
                    finalSettings.AlternateDns.Replace(" ", string.Empty);
                }
            }

            try
            {
                importer = new InstallImporter();
                //Serialize the object to xml
                xmlResult = importer.Serialize(finalSettings);
            }
            catch (Exception)
            {
            }


            //Write the xml to the file
            try
            {
                importer.WriteXmlToCurrentDirectory(xmlResult);
                MessageBox.Show("Safely remove the thumb drive and insert into the Syncbox. It should stay in the Syncbox while it's in use.", "Configuration Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception)
            {
                MessageBox.Show("Drive removed. Reinsert the syncbak drive and try again. Application now closing", "Drive removed!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }