private void btnAdvanced_Click(object sender, System.EventArgs e) { Uri assemblyUri = new Uri(Assembly.GetExecutingAssembly().CodeBase); FileInfo assemblyInfo = new FileInfo(assemblyUri.LocalPath); string configFile = assemblyInfo.DirectoryName + Path.DirectorySeparatorChar + "FileTransfer.xml"; string strXmlConfig = "<FileTransferCapability><Configuration><Fec enabled='" + fileTransferCapability.FecEnabled + "' value='" + fileTransferCapability.FecChecksum + "' /><MaxBandwidth value='" + fileTransferCapability.MaximumBandwidthLimiter + "' /></Configuration></FileTransferCapability>"; AdvancedDialog advDlg = new AdvancedDialog(); XmlDocument xmlDocSettings = new XmlDocument(); try { xmlDocSettings.Load(configFile); if (xmlDocSettings.DocumentElement.Name != "FileTransferCapability") { throw new Exception(Strings.ConfigurationFileCorrupt); } } catch { xmlDocSettings.LoadXml(strXmlConfig); } XmlElement xmlConfiguration = xmlDocSettings.DocumentElement["Configuration"]; System.Diagnostics.Debug.Assert(xmlConfiguration != null, "The configuration file is corrupt"); advDlg.MaxBandwidth = int.Parse(xmlConfiguration["MaxBandwidth"].GetAttribute("value"), CultureInfo.InvariantCulture); advDlg.EnableFEC = bool.Parse(xmlConfiguration["Fec"].GetAttribute("enabled")); advDlg.FECAmount = int.Parse(xmlConfiguration["Fec"].GetAttribute("value"), CultureInfo.InvariantCulture); if (advDlg.ShowDialog() != DialogResult.OK) { return; } strXmlConfig = "<FileTransferCapability><Configuration><Fec enabled='" + advDlg.EnableFEC + "' value='" + advDlg.FECAmount + "' /><MaxBandwidth value='" + advDlg.MaxBandwidth + "' /></Configuration></FileTransferCapability>"; xmlDocSettings.LoadXml(strXmlConfig); XmlTextWriter xtw = new XmlTextWriter(configFile, System.Text.Encoding.UTF8); xtw.Formatting = Formatting.Indented; xmlDocSettings.Save(xtw); xtw.Flush(); xtw.Close(); }
private void btnAdvanced_Click(object sender, System.EventArgs e) { Uri assemblyUri = new Uri(Assembly.GetExecutingAssembly().CodeBase); FileInfo assemblyInfo = new FileInfo(assemblyUri.LocalPath); string configFile = assemblyInfo.DirectoryName + Path.DirectorySeparatorChar + "FileTransfer.xml"; string strXmlConfig = "<FileTransferCapability><Configuration><Fec enabled='" + fileTransferCapability.FecEnabled + "' value='" + fileTransferCapability.FecChecksum + "' /><MaxBandwidth value='" + fileTransferCapability.MaximumBandwidthLimiter + "' /></Configuration></FileTransferCapability>"; AdvancedDialog advDlg = new AdvancedDialog(); XmlDocument xmlDocSettings = new XmlDocument(); try { xmlDocSettings.Load(configFile); if (xmlDocSettings.DocumentElement.Name != "FileTransferCapability") throw new Exception("The configuration file is corrupt"); } catch { xmlDocSettings.LoadXml(strXmlConfig); } XmlElement xmlConfiguration = xmlDocSettings.DocumentElement["Configuration"]; System.Diagnostics.Debug.Assert(xmlConfiguration != null, "The configuration file is corrupt"); advDlg.MaxBandwidth = int.Parse(xmlConfiguration["MaxBandwidth"].GetAttribute("value")); advDlg.EnableFEC = bool.Parse(xmlConfiguration["Fec"].GetAttribute("enabled")); advDlg.FECAmount = int.Parse(xmlConfiguration["Fec"].GetAttribute("value")); if (advDlg.ShowDialog() != DialogResult.OK) return; strXmlConfig = "<FileTransferCapability><Configuration><Fec enabled='" + advDlg.EnableFEC + "' value='" + advDlg.FECAmount + "' /><MaxBandwidth value='" + advDlg.MaxBandwidth + "' /></Configuration></FileTransferCapability>"; xmlDocSettings.LoadXml(strXmlConfig); XmlTextWriter xtw = new XmlTextWriter(configFile, System.Text.Encoding.UTF8); xtw.Formatting = Formatting.Indented; xmlDocSettings.Save(xtw); xtw.Flush(); xtw.Close(); }