C# 远程更新
来源:互联网 发布:淘宝羽绒服儿童 编辑:程序博客网 时间:2024/06/07 03:31
一段服务器端配置文件,一段客户端配置文件,一段下载代码。
RemoteXmlFile.xml
<?xml version="1.0" encoding="utf-8"?><configuration> <Item key="client" value="20121228" content="tlnews001,tlnews002,tlnews003" size="3" /> <Item key="renbao" value="20121228" content="a2.pdf,a1.pdf,a3.pdf,a4.pdf,a5.pdf,a6.pdf,a7.pdf,a8.pdf" size="4777360" /> <Item key="cenbao" value="20121228" content="a1.pdf,a2.pdf,a4.pdf,a6.pdf,a3.pdf,a5.pdf,a8.pdf,a7.pdf,a10.pdf,a9.pdf,a11.pdf" size="5542552" /> <Item key="button" value="20121124 10:59:52" content="" size="" /> <Item key="banner" value="20121124 10:55:40" content="" size="" /> <Item key="web" value="20121218 10:16:40" content="index.html" size="2116" /> <Item key="pb" value="20121124 10:56:21" content="" size="" /></configuration>
AnalysisXml.cs
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Xml;namespace comback{ class AnalysisXml { //更新本地配置文件节点值 public void UpdateLocalXml(string xmlPath, string updateKey, string updateValue, string updateContent, string updateSize) { XmlDocument xDoc = new XmlDocument(); try { xDoc.Load(xmlPath); foreach (XmlNode node in xDoc.DocumentElement.ChildNodes) { string key = node.Attributes["key"].Value; if (key == updateKey) { node.Attributes["value"].Value = updateValue; node.Attributes["content"].Value = updateContent; node.Attributes["size"].Value = updateSize; xDoc.Save(xmlPath); break; } } } catch (Exception ee) { System.Windows.Forms.MessageBox.Show("在AnalysisXml类中操作UpdateLocalXml时异常:" + ee.Message); } } }}
ClientXmlFile.xml
<?xml version="1.0" encoding="utf-8"?><configuration> <Item key="renbao" value="20121219" /> <Item key="cenbao" value="20121219" /> <Item key="button" value="20121124 10:59:52" /> <Item key="banner" value="20121124 10:55:40" /> <Item key="web" value="20121218 10:16:40" /> <Item key="pb" value="20121124 10:56:21" /></configuration>
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Xml;using System.Windows.Forms;namespace ClientIIS{ //解析xml配置文件 class AnalysisXml { //获取app.config值 public string GetValue(string appKey) { XmlDocument xDoc = new XmlDocument(); try { xDoc.Load(Application.StartupPath + "\\App.config"); XmlNode xNode; XmlElement xElem; xNode = xDoc.SelectSingleNode("//appSettings"); xElem = (XmlElement)xNode.SelectSingleNode("//add[@key='" + appKey + "']"); if (xElem != null) return xElem.GetAttribute("value"); else return ""; } catch (Exception ee) { LogManager.WriteLog(LogFile.XmlError, "", "在AnalysisXml类中操作GetValue时异常:" + ee.Message); } return ""; } //修改远程文件(.ini) public void UpdateRemoteFile(string xmlPath, string updateKey, string updateValue) { XmlDocument xDoc = new XmlDocument(); try { xDoc.Load(xmlPath); foreach (XmlNode node in xDoc.DocumentElement.ChildNodes) { string key = node.Attributes["key"].Value; if (key == updateKey) { node.Attributes["value"].Value = updateValue; xDoc.Save(xmlPath); MessageBox.Show("修改成功!"); break; } } } catch (Exception ee) { LogManager.WriteLog(LogFile.XmlError, "", "在AnalysisXml类中操作UpdateLocalXml时异常:" + ee.Message); } } List<ClientFileInfo> remoteList = new List<ClientFileInfo>(); //获取远程配置文件信息 public List<ClientFileInfo> GetRemoteXmlValue(string xmlPath) { XmlDocument xDoc = new XmlDocument(); try { xDoc.Load(xmlPath); foreach (XmlNode node in xDoc.DocumentElement.ChildNodes) { string key = node.Attributes["key"].Value; string value = node.Attributes["value"].Value; string content = node.Attributes["content"].Value; string size = node.Attributes["size"].Value; //我想到了一个温柔的你,可以用你来抚平创伤 if (string.IsNullOrEmpty(content) || string.IsNullOrEmpty(size)) { continue; } ClientFileInfo file = new ClientFileInfo(key, value, content, size); remoteList.Add(file); } } catch (Exception ee) { LogManager.WriteLog(LogFile.XmlError, "", "在AnalysisXml类中操作GetRemoteXmlValue时异常:" + ee.Message); } return remoteList; } //获取本地配置文件信息 List<ClientFileInfo> localList = new List<ClientFileInfo>(); public List<ClientFileInfo> GetLocalXmlValue(string xmlPath) { XmlDocument xDoc = new XmlDocument(); try { xDoc.Load(xmlPath); foreach (XmlNode node in xDoc.DocumentElement.ChildNodes) { string key = node.Attributes["key"].Value; string value = node.Attributes["value"].Value; ClientFileInfo file = new ClientFileInfo(key, value); localList.Add(file); } } catch (Exception ee) { LogManager.WriteLog(LogFile.XmlError, "", "在AnalysisXml类中操作GetLocalXmlValue时异常:" + ee.Message); } return localList; } //更新本地配置文件节点值 public void UpdateLocalXml(string xmlPath, string updateKey,string updateValue) { XmlDocument xDoc = new XmlDocument(); try { xDoc.Load(xmlPath); foreach (XmlNode node in xDoc.DocumentElement.ChildNodes) { string key = node.Attributes["key"].Value; if (key == updateKey) { node.Attributes["value"].Value = updateValue; xDoc.Save(xmlPath); break; } } } catch (Exception ee) { LogManager.WriteLog(LogFile.XmlError, "", "在AnalysisXml类中操作UpdateLocalXml时异常:" + ee.Message); } } }}
private void DownloadFile() { try { if (updateFileList != null && updateFileList.Count > 0) { for (int i = 0; i < updateFileList.Count; i++) { string downFile = this.updateFileList[i]; string saveFile = this.saveFileList[i]; clientDownload = new WebClient(); if (clientDownload.IsBusy) { clientDownload.CancelAsync(); } clientDownload.DownloadFileAsync(new Uri(downFile), saveFile, saveFile); clientDownload.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted); } } } catch(Exception ee) { LogManager.WriteLog(LogFile.OtherError, "", "在程序ClientIIS的ClientIISForm类中操作DownloadFile时异常:" + ee.Message); } }
- C# 远程更新
- 更新远程数据
- git从远程获取更新
- 手动更新nuxus远程索引
- 一种远程软件更新方法
- Git更新远程分支列表
- 辅助dns和远程更新
- C#实现远程控制
- c# 实现远程关机
- 远程dll注入 C#
- C#远程关机代码
- C# 远程开机函数
- C#远程抓取网页
- C#远程调用方法
- C#远程开机代码
- c# 映射远程网络
- c#实现远程连接
- vc,C#远程调试
- IInternetZoneManager安全设置
- 浮点数在计算机中存储方式
- C++ 编写和调用webservice解决方案
- 关于\r,\n,\r\n
- struts1工作原理
- C# 远程更新
- 面试2
- 关于书的写作方法
- YUV格式、RGB格式、JPEG格式、MJPEG格式之间的转换(C程序)之一
- ASP.NET C# List分页
- System Error Codes (0-499) (Windows)
- Runtime.getRunTime.exec(String command)的使用
- struts2.0的工作原理?
- Hadoop reduce阶段出现Failed to fetch错误及解决