/// <summary> /// 服务器配置保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button5_Click(object sender, EventArgs e) { Code.HostConfig hostconfig = new Code.HostConfig(); if (cb_WCF.Checked) { string server = "WcfHost"; hostconfig.HostServer.Add(server); } if (cb_Watch.Checked) { string server = "MonitorService"; hostconfig.HostServer.Add(server); } if (cb_DT.Checked) { string server = "DataTransferService"; hostconfig.HostServer.Add(server); } hostconfig.DBIP = txt_DBIP.Text.Trim(); hostconfig.DBName = txt_DBName.Text.Trim(); hostconfig.DBPW = txt_DBpw.Text.Trim(); hostconfig.DBUser = txt_DBUser.Text.Trim(); hostconfig.WCFString = txt_SeverWCFConnString.Text.Trim(); hostconfig.WeChatWCFString = txt_weixinendportwcf.Text.Trim(); hostconfig.MediaFilePath = txt_FilePath.Text.Trim(); hostconfig.SchoolNo = txt_ServerSchoolNo.Text.Trim(); hostconfig.LoopTime = txt_ServerLoopTime.Text.Trim(); hostconfig.UploadTime = txt_Uploadtime.Text.Trim(); if (Code.ReadSeatHostConfigV3.SaveConfig(hostconfig)) { MessageBox.Show("保存成功!"); if (gb_web.Enabled) { Code.WebConfigSetting webSetting = new Code.WebConfigSetting(); webSetting.IsChangePW = cb_web_pw_change.Checked; webSetting.ConnString = txt_SeverWCFConnString.Text.Trim(); webSetting.SchoolNo = txt_ServerSchoolNo.Text.Trim(); webSetting.SqlConn = "Data Source=" + hostconfig.DBIP + ";Initial Catalog=" + hostconfig.DBName + ";Persist Security Info=True" + ";User ID=" + hostconfig.DBUser + ";Password="******"管理网站设置保存失败!请手动修改!"); } } } else { MessageBox.Show("保存失败!"); } //修改预约记录 if (colbtnclickCount >= 5) { string connstr_new = string.Format("Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID={2};Password={3}", txt_DBIP.Text, txt_DBName.Text, txt_DBUser.Text, txt_DBpw.Text); Code.AddBookKey bk = new Code.AddBookKey(); bk.BookKeyon(connstr_new); } }
private void SeatManageConfigTool_Load(object sender, EventArgs e) { Code.HostConfig hostconfig = new Code.HostConfig(); Code.ClientBasicConfig clientconfig = new Code.ClientBasicConfig(); Code.CardReaderBasicConfig cardReaderConfig = new Code.CardReaderBasicConfig(); Code.WebConfigSetting webConfigSeeting = new Code.WebConfigSetting(); Code.LeaveClientBesicConfig leaveConfigSetting = new Code.LeaveClientBesicConfig(); Code.DeviceSettingConfig deviceSettingConfig = new Code.DeviceSettingConfig(); Code.ShutDownConfig shutDownConfig = new Code.ShutDownConfig(); if (Code.ReadSeatHostConfigV3.ReadConfig(ref hostconfig)) { foreach (string server in hostconfig.HostServer) { if (server == "WcfHost") { cb_WCF.Checked = true; } else if (server == "MonitorService") { cb_Watch.Checked = true; } else if (server == "DataTransferService") { cb_DT.Checked = true; } } txt_DBIP.Text = hostconfig.DBIP; txt_DBName.Text = hostconfig.DBName; txt_DBpw.Text = hostconfig.DBPW; txt_DBUser.Text = hostconfig.DBUser; txt_SeverWCFConnString.Text = hostconfig.WCFString; txt_weixinendportwcf.Text = hostconfig.WeChatWCFString; txt_FilePath.Text = hostconfig.MediaFilePath; txt_ServerSchoolNo.Text = hostconfig.SchoolNo; txt_ServerLoopTime.Text = hostconfig.LoopTime; txt_Uploadtime.Text = hostconfig.UploadTime; if (Code.WebConfig.ReadConfig(ref webConfigSeeting)) { cb_web_pw_change.Checked = webConfigSeeting.IsChangePW; } else { MessageBox.Show("无法自动获取管理网站配置文件,请确保和Host服务文件夹放置在同一目录,并且文件夹为“SeatManageWebV5”"); gb_web.Enabled = false; } foreach (Control c in tabControl1.TabPages[1].Controls) { c.Enabled = false; } foreach (Control c in tabControl1.TabPages[2].Controls) { c.Enabled = false; } foreach (Control c in tabControl1.TabPages[3].Controls) { c.Enabled = false; } } else if (Code.ReadSeatClientConfig.GetSeatClientBaseConfig(ref clientconfig) && Code.CardReaderConfig.GetCardReaderBaseConfig(ref cardReaderConfig, "Select")) { clientmode = "Select"; txt_clientwcfstring.Text = clientconfig.WCFConnString; txt_schoolno.Text = clientconfig.SchoolNo; txt_campusno.Text = clientconfig.CampusNo; txt_deviceno.Text = clientconfig.TerminalNum; txt_defualtmedia.Text = clientconfig.DefaultMedia; txt_adloop.Text = clientconfig.SCLoopTime; txt_sentloop.Text = clientconfig.SentStatusTime; txt_update.Text = clientconfig.UpdateTime; txt_mac.Text = GetMacAddress.GetLocalAddress()[0]; gb_xzx.Enabled = false; gb_mh.Enabled = false; gb_fk.Enabled = false; gb_gz.Enabled = false; gb_cut.Enabled = false; gb_dz.Enabled = false; switch (cardReaderConfig.CardReaderTye) { case 0: rb_mh.Checked = true; break; case 1: rb_xzx.Checked = true; break; case 2: rb_fk.Checked = true; break; case 3: rb_gz.Checked = true; break; case 4: rb_cut.Checked = true; break; case 5: rb_dz.Checked = true; break; } if (cardReaderConfig.CardID10Or16 == 10) { fk_10.Checked = true; rb_10.Checked = true; } else { fk_16.Checked = true; rb_16.Checked = true; } cb_Isbeep.Checked = cardReaderConfig.IsBeep; fk_port.Text = cardReaderConfig.FKport; txt_xzx_ip.Text = cardReaderConfig.XZX_ServerEndPort; txt_xzx_sys.Text = cardReaderConfig.XZX_SysCode; txt_xzx_tre.Text = cardReaderConfig.XZX_TerminalNo; xzx_addreader.Checked = cardReaderConfig.XZX_AddReader; xzx_off.Checked = cardReaderConfig.XZX_Offline; if (cardReaderConfig.Hook_isCardNo) { rb_gz_cardno.Checked = true; } else { rb_gz_cardid.Checked = true; } if (cardReaderConfig.XZX_IsOnelyReaderCardId) { rb_xzx_readcardid.Checked = true; } else { rb_xzx_readcardno.Checked = true; } cb_change.Checked = cardReaderConfig.CardIDIsChange; fk_change.Checked = cardReaderConfig.CardIDIsChange; cb_add0.Checked = cardReaderConfig.IsAdd0; fk_add0.Checked = cardReaderConfig.IsAdd0; if (Code.DeviceSetting.GetDeviceSetting(ref deviceSettingConfig)) { txt_d_IP.Text = deviceSettingConfig.IP; txt_d_dns.Text = deviceSettingConfig.DNS; txt_d_getway.Text = deviceSettingConfig.Gateway; txt_d_mask.Text = deviceSettingConfig.Mask; txt_pc_name.Text = deviceSettingConfig.PCName; cb_staticIP.Checked = deviceSettingConfig.IsStaticIP; } if (Code.DeviceSetting.GetShotDownSetting(ref shutDownConfig)) { cb_sd.Checked = shutDownConfig.IsUsed; txt_sd_h.Text = shutDownConfig.ShutDownHour; txt_sd_m.Text = shutDownConfig.ShutDownMin; txt_sd_s.Text = shutDownConfig.ShutDownWaitSec; } foreach (Control c in tabControl1.TabPages[0].Controls) { c.Enabled = false; } foreach (Control c in tabControl1.TabPages[2].Controls) { c.Enabled = false; } tabControl1.SelectedIndex = 1; } else if (Code.LeaveClientConfig.GetLeaveClientConfig(ref leaveConfigSetting) && Code.CardReaderConfig.GetCardReaderBaseConfig(ref cardReaderConfig, "Leave")) { clientmode = "Leave"; txt_leave_wcfconn.Text = leaveConfigSetting.WCFConnString; switch (leaveConfigSetting.LeaveMode) { case "0": rb_leave_s.Checked = true; break; case "1": rb_leave_sl.Checked = true; break; case "2": rb_leave_l.Checked = true; break; case "3": rb_leave_s.Checked = true; break; } if (leaveConfigSetting.SetUpMode == "1") { rb_win_max.Checked = true; } else { rb_win_min.Checked = true; } gb_xzx.Enabled = false; gb_mh.Enabled = false; gb_fk.Enabled = false; gb_gz.Enabled = false; gb_cut.Enabled = false; gb_dz.Enabled = false; switch (cardReaderConfig.CardReaderTye) { case 0: rb_mh.Checked = true; break; case 1: rb_xzx.Checked = true; break; case 2: rb_fk.Checked = true; break; case 3: rb_gz.Checked = true; break; case 4: rb_cut.Checked = true; break; case 5: rb_dz.Checked = true; break; } if (cardReaderConfig.CardID10Or16 == 10) { fk_10.Checked = true; rb_10.Checked = true; } else { fk_16.Checked = true; rb_16.Checked = true; } cb_Isbeep.Checked = cardReaderConfig.IsBeep; fk_port.Text = cardReaderConfig.FKport; txt_xzx_ip.Text = cardReaderConfig.XZX_ServerEndPort; txt_xzx_sys.Text = cardReaderConfig.XZX_SysCode; txt_xzx_tre.Text = cardReaderConfig.XZX_TerminalNo; xzx_addreader.Checked = cardReaderConfig.XZX_AddReader; xzx_off.Checked = cardReaderConfig.XZX_Offline; if (cardReaderConfig.Hook_isCardNo) { rb_gz_cardno.Checked = true; } else { rb_gz_cardid.Checked = true; } if (cardReaderConfig.XZX_IsOnelyReaderCardId) { rb_xzx_readcardid.Checked = true; } else { rb_xzx_readcardno.Checked = true; } cb_change.Checked = cardReaderConfig.CardIDIsChange; fk_change.Checked = cardReaderConfig.CardIDIsChange; cb_add0.Checked = cardReaderConfig.IsAdd0; fk_add0.Checked = cardReaderConfig.IsAdd0; foreach (Control c in tabControl1.TabPages[0].Controls) { c.Enabled = false; } foreach (Control c in tabControl1.TabPages[1].Controls) { c.Enabled = false; } tabControl1.SelectedIndex = 2; } else { MessageBox.Show("获取配置文件失败,请把配置工具拷贝到宿主服务或者终端的根目录下,再次尝试!"); foreach (Control c in tabControl1.TabPages[0].Controls) { c.Enabled = false; } foreach (Control c in tabControl1.TabPages[1].Controls) { c.Enabled = false; } foreach (Control c in tabControl1.TabPages[2].Controls) { c.Enabled = false; } foreach (Control c in tabControl1.TabPages[3].Controls) { c.Enabled = false; } btnBackupProgram.Enabled = false; tabControl1.SelectedIndex = 4; } }
public static bool ReadConfig(ref HostConfig hostconfig) { docMonitorService = new XmlDocument(); docTimerHost = new XmlDocument(); docWCFHost = new XmlDocument(); docWeChar = new XmlDocument(); docWeCharWcf = new XmlDocument(); string fileDircetoryPath = AppDomain.CurrentDomain.BaseDirectory; if (File.Exists(Path.GetDirectoryName(Application.StartupPath) + "\\MonitorService\\ServiceHostMonitorService.exe.config")) { docMonitorService.Load(Path.GetDirectoryName(Application.StartupPath) + "\\MonitorService\\ServiceHostMonitorService.exe.config"); if (File.Exists(fileDircetoryPath + "ServiceHostTimerHost.exe.config")) { docTimerHost.Load(fileDircetoryPath + "ServiceHostTimerHost.exe.config"); } else { return(false); } if (File.Exists(fileDircetoryPath + "ServiceHostWCFHost.exe.config")) { docWCFHost.Load(fileDircetoryPath + "ServiceHostWCFHost.exe.config"); } else { return(false); } if (File.Exists(fileDircetoryPath + "ServiceHostWeChar.exe.config")) { docWeChar.Load(fileDircetoryPath + "ServiceHostWeChar.exe.config"); } else { return(false); } if (File.Exists(fileDircetoryPath + "ServiceHostWeChatWCFHost.exe.config")) { docWeChar.Load(fileDircetoryPath + "ServiceHostWeChatWCFHost.exe.config"); } else { return(false); } string[] db = docWCFHost.SelectNodes("//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "ConnectionString").Attributes["connectionString"].Value.Split(';'); for (int i = 0; i < db.Length; i++) { switch (db[i].Split('=')[0]) { case "Data Source": hostconfig.DBIP = db[i].Split('=')[1]; break; case "Initial Catalog": hostconfig.DBName = db[i].Split('=')[1]; break; case "User ID": hostconfig.DBUser = db[i].Split('=')[1]; break; case "Password": hostconfig.DBPW = db[i].Split('=')[1]; break; } } XmlNode xmlNode = docTimerHost.SelectNodes("//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "EndpointAddress"); hostconfig.WCFString = AESAlgorithm.AESDecrypt(xmlNode.Attributes["connectionString"].Value); xmlNode = docMonitorService.SelectNodes("//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "WeChatEndpointAddress"); hostconfig.WeChatWCFString = AESAlgorithm.AESDecrypt(xmlNode.Attributes["connectionString"].Value); XmlNodeList nodes = docTimerHost.SelectNodes("//configuration/appSettings/add"); foreach (XmlNode node in nodes) { if (node.Attributes["key"].Value == "ServiceAssembly" && (node.Attributes["value"].Value == "SeatService.MonitorService.MonitorService,SeatService.MonitorService" || node.Attributes["value"].Value == "SeatManage.WCFService.WcfHost,SeatManage.WCFService" || node.Attributes["value"].Value == "AMS.DataTransfer.DataTransferService,AMS.DataTransfer")) { hostconfig.HostServer.Add(node.Attributes["value"].Value.Split(',')[0].Split('.')[2]); } else { switch (node.Attributes["key"].Value) { case "SaveFilePath": hostconfig.MediaFilePath = node.Attributes["value"].Value; break; case "LogUploadTime": hostconfig.UploadTime = node.Attributes["value"].Value; break; case "Interval": hostconfig.LoopTime = node.Attributes["value"].Value; break; case "SchoolNo": hostconfig.SchoolNo = node.Attributes["value"].Value; break; } } } return(true); } else { return(false); } }
public static bool SaveConfig(HostConfig hostconfig) { try { docMonitorService = new XmlDocument(); docTimerHost = new XmlDocument(); docWCFHost = new XmlDocument(); docWeChar = new XmlDocument(); docWeCharWcf = new XmlDocument(); string fileDircetoryPath = AppDomain.CurrentDomain.BaseDirectory; if (File.Exists(Path.GetDirectoryName(Application.StartupPath) + "\\MonitorService\\ServiceHostMonitorService.exe.config")) { docMonitorService.Load(Path.GetDirectoryName(Application.StartupPath) + "\\MonitorService\\ServiceHostMonitorService.exe.config"); } if (File.Exists(fileDircetoryPath + "ServiceHostTimerHost.exe.config")) { docTimerHost.Load(fileDircetoryPath + "ServiceHostTimerHost.exe.config"); } if (File.Exists(fileDircetoryPath + "ServiceHostWCFHost.exe.config")) { docWCFHost.Load(fileDircetoryPath + "ServiceHostWCFHost.exe.config"); } if (File.Exists(fileDircetoryPath + "ServiceHostWeChar.exe.config")) { docWeChar.Load(fileDircetoryPath + "ServiceHostWeChar.exe.config"); } if (File.Exists(fileDircetoryPath + "ServiceHostWeChatWCFHost.exe.config")) { docWeCharWcf.Load(fileDircetoryPath + "ServiceHostWeChatWCFHost.exe.config"); } docTimerHost.SelectNodes("//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "ConnectionString").Attributes["connectionString"].Value = "Data Source=" + hostconfig.DBIP + ";Initial Catalog=" + hostconfig.DBName + ";Persist Security Info=True" + ";User ID=" + hostconfig.DBUser + ";Password="******"//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "EndpointAddress").Attributes["connectionString"].Value = AESAlgorithm.AESEncrypt(hostconfig.WCFString); docTimerHost.SelectNodes("//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "AdvertServiceEndpointAddress").Attributes["connectionString"].Value = AESAlgorithm.AESEncrypt(hostconfig.AdrWcfString); docMonitorService.SelectNodes("//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "EndpointAddress").Attributes["connectionString"].Value = AESAlgorithm.AESEncrypt(hostconfig.WCFString); docMonitorService.SelectNodes("//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "WeChatEndpointAddress").Attributes["connectionString"].Value = AESAlgorithm.AESEncrypt(hostconfig.WeChatWCFString); docWCFHost.SelectNodes("//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "ConnectionString").Attributes["connectionString"].Value = "Data Source=" + hostconfig.DBIP + ";Initial Catalog=" + hostconfig.DBName + ";Persist Security Info=True" + ";User ID=" + hostconfig.DBUser + ";Password="******"//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "EndpointAddress").Attributes["connectionString"].Value = AESAlgorithm.AESEncrypt(hostconfig.WCFString); docWeChar.SelectNodes("//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "ConnectionString").Attributes["connectionString"].Value = "Data Source=" + hostconfig.DBIP + ";Initial Catalog=" + hostconfig.DBName + ";Persist Security Info=True" + ";User ID=" + hostconfig.DBUser + ";Password="******"//configuration/connectionStrings/add").Cast<XmlNode>().First(p => p.Attributes["name"].Value == "WeChatEndpointAddress").Attributes["connectionString"].Value = AESAlgorithm.AESEncrypt(hostconfig.WeChatWCFString); docWeCharWcf.SelectNodes("//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "ConnectionString").Attributes["connectionString"].Value = "Data Source=" + hostconfig.DBIP + ";Initial Catalog=" + hostconfig.DBName + ";Persist Security Info=True" + ";User ID=" + hostconfig.DBUser + ";Password="******"//configuration/connectionStrings/add").Cast <XmlNode>().First(p => p.Attributes["name"].Value == "EndpointAddress").Attributes["connectionString"].Value = AESAlgorithm.AESEncrypt(hostconfig.WCFString); XmlNodeList nodes = docWCFHost.SelectNodes("//configuration/system.serviceModel/services/service/host/baseAddresses/add"); foreach (XmlNode node in nodes) { string[] sp = node.Attributes["baseAddress"].Value.Split('/'); node.Attributes["baseAddress"].Value = hostconfig.WCFString + sp[sp.Length - 2] + "/"; } nodes = docWCFHost.SelectNodes("//configuration/appSettings/add"); foreach (XmlNode node in nodes) { if (node.Attributes["key"] == null) { continue; } if (node.Attributes["key"].Value == "SaveFilePath") { node.Attributes["value"].Value = hostconfig.MediaFilePath; } else if (node.Attributes["key"].Value == "LogUploadTime") { node.Attributes["value"].Value = hostconfig.UploadTime; } else if (node.Attributes["key"].Value == "Interval") { node.Attributes["value"].Value = hostconfig.LoopTime; } else if (node.Attributes["key"].Value == "SchoolNo") { node.Attributes["value"].Value = hostconfig.SchoolNo; } } docWCFHost.Save(fileDircetoryPath + "ServiceHostWCFHost.exe.config"); nodes = docWeCharWcf.SelectNodes("//configuration/system.serviceModel/services/service/host/baseAddresses/add"); foreach (XmlNode node in nodes) { string[] sp = node.Attributes["baseAddress"].Value.Split('/'); node.Attributes["baseAddress"].Value = hostconfig.WeChatWCFString + sp[sp.Length - 2] + "/"; } nodes = docWeCharWcf.SelectNodes("//configuration/appSettings/add"); foreach (XmlNode node in nodes) { if (node.Attributes["key"] == null) { continue; } if (node.Attributes["key"].Value == "SaveFilePath") { node.Attributes["value"].Value = hostconfig.MediaFilePath; } else if (node.Attributes["key"].Value == "LogUploadTime") { node.Attributes["value"].Value = hostconfig.UploadTime; } else if (node.Attributes["key"].Value == "Interval") { node.Attributes["value"].Value = hostconfig.LoopTime; } else if (node.Attributes["key"].Value == "SchoolNo") { node.Attributes["value"].Value = hostconfig.SchoolNo; } } docWeCharWcf.Save(fileDircetoryPath + "ServiceHostWeChatWCFHost.exe.config"); nodes = docTimerHost.SelectNodes("//configuration/appSettings/add"); foreach (XmlNode node in nodes) { if (node.Attributes["key"].Value == "ServiceAssembly" && (node.Attributes["value"].Value == "SeatService.MonitorService.MonitorService,SeatService.MonitorService" || node.Attributes["value"].Value == "SeatService.StatisticsService.StatisticsService,SeatService.StatisticsService" || node.Attributes["value"].Value == "SeatService.SyncService.SyncService,SeatService.SyncService" || node.Attributes["value"].Value == "SeatManage.WCFService.WcfHost,SeatManage.WCFService" || node.Attributes["value"].Value == "AMS.DataTransfer.DataTransferService,AMS.DataTransfer")) { XmlNode fnode = docTimerHost.SelectSingleNode("//configuration/appSettings"); fnode.RemoveChild(node); } } foreach (string server in hostconfig.HostServer) { switch (server) { case "MonitorService": { XmlNode node = docTimerHost.SelectSingleNode("//configuration/appSettings"); XmlElement element1 = docTimerHost.CreateElement("add"); element1.SetAttribute("key", "ServiceAssembly"); element1.SetAttribute("value", "SeatService.MonitorService.MonitorService,SeatService.MonitorService"); node.AppendChild(element1); node = docTimerHost.SelectSingleNode("//configuration/appSettings"); XmlElement element2 = docTimerHost.CreateElement("add"); element2.SetAttribute("key", "ServiceAssembly"); element2.SetAttribute("value", "SeatService.StatisticsService.StatisticsService,SeatService.StatisticsService"); node.AppendChild(element2); node = docTimerHost.SelectSingleNode("//configuration/appSettings"); XmlElement element3 = docTimerHost.CreateElement("add"); element3.SetAttribute("key", "ServiceAssembly"); element3.SetAttribute("value", "SeatService.SyncService.SyncService,SeatService.SyncService"); node.AppendChild(element3); } break; case "DataTransferService": { XmlNode node = docTimerHost.SelectSingleNode("//configuration/appSettings"); XmlElement element = docTimerHost.CreateElement("add"); element.SetAttribute("key", "ServiceAssembly"); element.SetAttribute("value", "AMS.DataTransfer.DataTransferService,AMS.DataTransfer"); node.AppendChild(element); } break; } } nodes = docTimerHost.SelectNodes("//configuration/appSettings/add"); foreach (XmlNode node in nodes) { if (node.Attributes["key"] == null) { continue; } if (node.Attributes["key"].Value == "SaveFilePath") { node.Attributes["value"].Value = hostconfig.MediaFilePath; } else if (node.Attributes["key"].Value == "LogUploadTime") { node.Attributes["value"].Value = hostconfig.UploadTime; } else if (node.Attributes["key"].Value == "Interval") { node.Attributes["value"].Value = hostconfig.LoopTime; } else if (node.Attributes["key"].Value == "SchoolNo") { node.Attributes["value"].Value = hostconfig.SchoolNo; } } docTimerHost.Save(fileDircetoryPath + "ServiceHostTimerHost.exe.config"); nodes = docWeChar.SelectNodes("//configuration/appSettings/add"); foreach (XmlNode node in nodes) { if (node.Attributes["key"] == null) { continue; } if (node.Attributes["key"].Value == "SaveFilePath") { node.Attributes["value"].Value = hostconfig.MediaFilePath; } else if (node.Attributes["key"].Value == "LogUploadTime") { node.Attributes["value"].Value = hostconfig.UploadTime; } else if (node.Attributes["key"].Value == "Interval") { node.Attributes["value"].Value = hostconfig.LoopTime; } else if (node.Attributes["key"].Value == "SchoolNo") { node.Attributes["value"].Value = hostconfig.SchoolNo; } } docWeChar.Save(fileDircetoryPath + "ServiceHostWeChar.exe.config"); docMonitorService.Save(Path.GetDirectoryName(Application.StartupPath) + "\\MonitorService\\ServiceHostMonitorService.exe.config"); XmlDocument docx = new XmlDocument(); XmlDeclaration dec = docx.CreateXmlDeclaration("1.0", "utf-8", null); docx.AppendChild(dec); XmlElement root = docx.CreateElement("configuration");//创建根节点 XmlElement elementx = docx.CreateElement("connectionStrings"); XmlElement addelement = docx.CreateElement("add"); addelement.SetAttribute("name", "EndpointAddress"); addelement.SetAttribute("connectionString", AESAlgorithm.AESEncrypt(hostconfig.WCFString)); elementx.AppendChild(addelement); root.AppendChild(elementx); XmlElement setelement = docx.CreateElement("startup"); XmlElement supelement = docx.CreateElement("supportedRuntime"); supelement.SetAttribute("version", "v4.0"); supelement.SetAttribute("sku", ".NETFramework,Version=v4.0"); setelement.AppendChild(supelement); root.AppendChild(setelement); docx.AppendChild(root); docx.Save(Process.GetCurrentProcess().MainModule.FileName + ".config"); return(true); } catch { return(false); } }