public static String MakeUpdateXml ( String UpdateApiUrl, String Action, String SoftwarePath, WebProxy Proxy, String[] SoftwareNameList, Int32 ProcessId, String AboutUsText, String AboutUsName, String AboutUsUrl ) { XmlTreeNode root = new XmlTreeNode("aaaSoft.Updater"); root.AddItem("UpdateApiUrl", UpdateApiUrl); root.AddItem("Action", Action); root.AddItem("Folder", SoftwarePath); root.AddItem("AboutUsText", AboutUsText); root.AddItem("AboutUsName", AboutUsName); root.AddItem("AboutUsUrl", AboutUsUrl); //代理 if (Proxy != null) { XmlTreeNode tnProxy = root.AddItem("ProxySetting"); tnProxy.AddItem("ProxyHost", Proxy.Address.Host); tnProxy.AddItem("ProxyPort", Proxy.Address.Port.ToString()); if (Proxy.Credentials != null) { NetworkCredential nc = (NetworkCredential)Proxy.Credentials; tnProxy.AddItem("ProxyUserName", nc.UserName); tnProxy.AddItem("ProxyPassword", nc.Password); tnProxy.AddItem("ProxyDomain", nc.Domain); } } XmlTreeNode tnSoftwareList = root.AddItem("SoftwareList"); foreach (var SoftwareName in SoftwareNameList) { var tnSoftware = tnSoftwareList.AddItem("Software"); tnSoftware.AddItem("Name", SoftwareName); } if (ProcessId > 0) { root.AddItem("ProcessId", ProcessId.ToString()); } return(XmlTreeNode.GenerateXml(root, Encoding.UTF8)); }
private void btnSaveConfig_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "xml文件(*.xml)|*.xml"; var dr = sfd.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.Cancel) { return; } XmlTreeNode rootNode = new XmlTreeNode("DatabaseBackupSetting"); rootNode.AddItem("host", txtHost.Text.Trim()); rootNode.AddItem("port", txtPort.Text.Trim()); rootNode.AddItem("userName", txtUserName.Text.Trim()); rootNode.AddItem("password", txtPassword.Text.Trim()); rootNode.AddItem("connectionString", txtConnectionString.Text.Trim()); File.WriteAllText(sfd.FileName, rootNode.ToXml(), Encoding.UTF8); MessageBox.Show("保存成功!"); }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { httpServer.Stop(); //保存配置文件 XmlTreeNode rootNode = new XmlTreeNode("root"); rootNode.AddItem("LastFolderPath", lastFolderPath); Encoding utf8Encoding = new UTF8Encoding(false); String xml = rootNode.ToXml(utf8Encoding); IoHelper.CreateMultiFolder(Path.GetDirectoryName(configFilePath)); File.WriteAllText(configFilePath, xml, Encoding.UTF8); Environment.Exit(0); }
void httpServer_BeforeWriteResponse(object sender, HttpServer.BeforeWriteResponseEventArgs e) { if (e.ContentType.StartsWith("text/html")) { if (e.Path.StartsWith("SHANZHAIF5_")) { if (e.Path == "SHANZHAIF5_LASTMODIFYTIME.html") { XmlTreeNode rootNode = new XmlTreeNode("root"); rootNode.AddItem("LastModifyTime", lastModifyTime.Ticks.ToString()); e.DataStream = getStream(rootNode.ToXml()); e.ContentType = "text/xml"; } } else { StreamReader reader = new StreamReader(e.DataStream, e.ContentEncoding); String html = reader.ReadToEnd(); reader.Close(); e.DataStream.Close(); StringBuilder sb = new StringBuilder(); sb.Append(html); sb.Append(String.Format("<script>var clientLastModifyTime = {0};</script>", lastModifyTime.Ticks)); sb.Append(@" <script> var SHANZHAIF5_XmlHttp = SHANZHAIF5_GetXmlHttpObject(); window.setInterval(SHANZHAIF5_CheckPageModifyTime,1000); function SHANZHAIF5_GetXmlHttpObject(){ var xmlHttp=null; try{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e){ // Internet Explorer try{ xmlHttp=new ActiveXObject('Msxml2.XMLHTTP'); }catch (e){ xmlHttp=new ActiveXObject('Microsoft.XMLHTTP'); } } return xmlHttp; } function SHANZHAIF5_CheckPageModifyTime(){ SHANZHAIF5_XmlHttp.onreadystatechange = function(){ if (SHANZHAIF5_XmlHttp.readyState == 4){ if (SHANZHAIF5_XmlHttp.status == 200){ var datas = SHANZHAIF5_XmlHttp.responseXML.getElementsByTagName('LastModifyTime'); var serverLastModifyTime = datas[0].childNodes[0].nodeValue; if(clientLastModifyTime != serverLastModifyTime){ location.reload(); } } } } SHANZHAIF5_XmlHttp.open('GET','/SHANZHAIF5_LASTMODIFYTIME.html',true); SHANZHAIF5_XmlHttp.setRequestHeader('If-Modified-Since','0'); SHANZHAIF5_XmlHttp.send(null); } </script>"); e.DataStream = getStream(sb.ToString(), e.ContentEncoding); } } }
//添加参数 public XmlTreeNode AddArgument(String key, String value) { return(rootPackage.AddItem(key, value)); }