求大神指点在线升级应该怎么做?
找人外包做了个程序,做到一半人跑了,给了个半成品的demo的源码,升级部分也没完成,下面是升级的部分,求大神帮忙看下我服务端的XML应该怎么写呢,当前现有的程序能否完成升级呢

using demo.Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Windows.Forms;
namespace demo.Controller
{
public class UpdateChecker
{
private const string UpdateURL = "http://www.domain.com/update.xml";
public string LatestVersionNumber;
public string LatestVersionURL;
public event EventHandler NewVersionFound;
public const string Name = "demo";
public const string Copyright = "Copyright demo NetWork 2017.";
public const string Version = "4.6.1";
#if !_DOTNET_4_0
public const string NetVer = "2.0";
#elif !_CONSOLE
public const string NetVer = "4.0";
#else
public const string NetVer = "";
#endif
public const string FullVersion = Version +
#if DEBUG
" Debug";
#else
/*
" Alpha";
/*/
"";
//*/
#endif
private static bool UseProxy = true;
public void CheckUpdate(Configuration config)
{
try
{
WebClient http = new WebClient();
http.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.3319.102 Safari/537.36");
if (UseProxy)
{
WebProxy proxy = new WebProxy(IPAddress.Loopback.ToString(), config.localPort);
if (!string.IsNullOrEmpty(config.authPass))
{
proxy.Credentials = new NetworkCredential(config.authUser, config.authPass);
}
http.Proxy = proxy;
}
else
{
http.Proxy = null;
}
http.DownloadStringCompleted += http_DownloadStringCompleted;
http.DownloadStringAsync(new Uri(UpdateURL + "?rnd=" + Util.Utils.RandUInt32().ToString()));
}
catch (Exception e)
{
Logging.LogUsefulException(e);
}
}
public static int CompareVersion(string l, string r)
{
var ls = l.Split('.');
var rs = r.Split('.');
for (int i = 0; i < Math.Max(ls.Length, rs.Length); i++)
{
int lp = (i < ls.Length) ? int.Parse(ls[i]) : 0;
int rp = (i < rs.Length) ? int.Parse(rs[i]) : 0;
if (lp != rp)
{
return lp - rp;
}
}
return 0;
}
public class VersionComparer : IComparer<string>
{
public int Compare(string x, string y)
{
return CompareVersion(ParseVersionFromURL(x), ParseVersionFromURL(y));
}
}
private static string ParseVersionFromURL(string url)
{
Match match = Regex.Match(url, @".*" + Name + @"-win.*?-([\d\.]+)\.\w+", RegexOptions.IgnoreCase);
if (match.Success)
{
if (match.Groups.Count == 2)
{
return match.Groups[1].Value;
}
}
return null;
}
private void SortVersions(List<string> versions)
{
versions.Sort(new VersionComparer());
}
private bool IsNewVersion(string url)
{
if (url.IndexOf("prerelease") >= 0)
{
return false;
}
// check dotnet 4.0
AssemblyName[] references = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
Version dotNetVersion = Environment.Version;
foreach (AssemblyName reference in references)
{
if (reference.Name == "mscorlib")
{
dotNetVersion = reference.Version;
}
}
if (dotNetVersion.Major >= 4)
{
if (url.IndexOf("dotnet4.0") < 0)
{
return false;
}
}
else
{
if (url.IndexOf("dotnet4.0") >= 0)
{
return false;
}
}
string version = ParseVersionFromURL(url);
if (version == null)
{
return false;
}
string currentVersion = Version;
if (url.IndexOf("banned") > 0 && CompareVersion(version, currentVersion) == 0
|| url.IndexOf("deprecated") > 0 && CompareVersion(version, currentVersion) > 0)
{
Application.Exit();
return false;
}
return CompareVersion(version, currentVersion) > 0;
}
private void http_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
string response = e.Result;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(response);
XmlNodeList elements = xmlDoc.GetElementsByTagName("media:content");
List<string> versions = new List<string>();
foreach (XmlNode el in elements)
{
foreach (XmlAttribute attr in el.Attributes)
{
if (attr.Name == "url")
{
if (IsNewVersion(attr.Value))
{
versions.Add(attr.Value);
}
}
}
}
if (versions.Count == 0)
{
return;
}
// sort versions
SortVersions(versions);
LatestVersionURL = versions[versions.Count - 1];
LatestVersionNumber = ParseVersionFromURL(LatestVersionURL);
if (NewVersionFound != null)
{
NewVersionFound(this, new EventArgs());
}
}
catch (Exception ex)
{
if (e.Error != null)
{
Logging.Debug(e.Error.ToString());
}
Logging.Debug(ex.ToString());
if (NewVersionFound != null)
{
NewVersionFound(this, new EventArgs());
}
return;
}
}
}
}

using demo.Model;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Windows.Forms;
namespace demo.Controller
{
public class UpdateChecker
{
private const string UpdateURL = "http://www.domain.com/update.xml";
public string LatestVersionNumber;
public string LatestVersionURL;
public event EventHandler NewVersionFound;
public const string Name = "demo";
public const string Copyright = "Copyright demo NetWork 2017.";
public const string Version = "4.6.1";
#if !_DOTNET_4_0
public const string NetVer = "2.0";
#elif !_CONSOLE
public const string NetVer = "4.0";
#else
public const string NetVer = "";
#endif
public const string FullVersion = Version +
#if DEBUG
" Debug";
#else
/*
" Alpha";
/*/
"";
//*/
#endif
private static bool UseProxy = true;
public void CheckUpdate(Configuration config)
{
try
{
WebClient http = new WebClient();
http.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.3319.102 Safari/537.36");
if (UseProxy)
{
WebProxy proxy = new WebProxy(IPAddress.Loopback.ToString(), config.localPort);
if (!string.IsNullOrEmpty(config.authPass))
{
proxy.Credentials = new NetworkCredential(config.authUser, config.authPass);
}
http.Proxy = proxy;
}
else
{
http.Proxy = null;
}
http.DownloadStringCompleted += http_DownloadStringCompleted;
http.DownloadStringAsync(new Uri(UpdateURL + "?rnd=" + Util.Utils.RandUInt32().ToString()));
}
catch (Exception e)
{
Logging.LogUsefulException(e);
}
}
public static int CompareVersion(string l, string r)
{
var ls = l.Split('.');
var rs = r.Split('.');
for (int i = 0; i < Math.Max(ls.Length, rs.Length); i++)
{
int lp = (i < ls.Length) ? int.Parse(ls[i]) : 0;
int rp = (i < rs.Length) ? int.Parse(rs[i]) : 0;
if (lp != rp)
{
return lp - rp;
}
}
return 0;
}
public class VersionComparer : IComparer<string>
{
public int Compare(string x, string y)
{
return CompareVersion(ParseVersionFromURL(x), ParseVersionFromURL(y));
}
}
private static string ParseVersionFromURL(string url)
{
Match match = Regex.Match(url, @".*" + Name + @"-win.*?-([\d\.]+)\.\w+", RegexOptions.IgnoreCase);
if (match.Success)
{
if (match.Groups.Count == 2)
{
return match.Groups[1].Value;
}
}
return null;
}
private void SortVersions(List<string> versions)
{
versions.Sort(new VersionComparer());
}
private bool IsNewVersion(string url)
{
if (url.IndexOf("prerelease") >= 0)
{
return false;
}
// check dotnet 4.0
AssemblyName[] references = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
Version dotNetVersion = Environment.Version;
foreach (AssemblyName reference in references)
{
if (reference.Name == "mscorlib")
{
dotNetVersion = reference.Version;
}
}
if (dotNetVersion.Major >= 4)
{
if (url.IndexOf("dotnet4.0") < 0)
{
return false;
}
}
else
{
if (url.IndexOf("dotnet4.0") >= 0)
{
return false;
}
}
string version = ParseVersionFromURL(url);
if (version == null)
{
return false;
}
string currentVersion = Version;
if (url.IndexOf("banned") > 0 && CompareVersion(version, currentVersion) == 0
|| url.IndexOf("deprecated") > 0 && CompareVersion(version, currentVersion) > 0)
{
Application.Exit();
return false;
}
return CompareVersion(version, currentVersion) > 0;
}
private void http_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
string response = e.Result;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(response);
XmlNodeList elements = xmlDoc.GetElementsByTagName("media:content");
List<string> versions = new List<string>();
foreach (XmlNode el in elements)
{
foreach (XmlAttribute attr in el.Attributes)
{
if (attr.Name == "url")
{
if (IsNewVersion(attr.Value))
{
versions.Add(attr.Value);
}
}
}
}
if (versions.Count == 0)
{
return;
}
// sort versions
SortVersions(versions);
LatestVersionURL = versions[versions.Count - 1];
LatestVersionNumber = ParseVersionFromURL(LatestVersionURL);
if (NewVersionFound != null)
{
NewVersionFound(this, new EventArgs());
}
}
catch (Exception ex)
{
if (e.Error != null)
{
Logging.Debug(e.Error.ToString());
}
Logging.Debug(ex.ToString());
if (NewVersionFound != null)
{
NewVersionFound(this, new EventArgs());
}
return;
}
}
}
}
...全文
相关推荐
GD32F103 在线串口Ymodem协议升级IAP,很好的在线升级实例
GD32F103 在线串口Ymodem协议升级IAP,很好的在线升级实例
51单片机IAP在线升级
51单片机IAP在线升级 爱矽半导体E85F3325单片机IAP在线升级教程,此处可查看更新及demo下载 文章目录前言一、ROM资源二、KEIL有关知识1.BL51连接器:2.LX51连接器:三、Keil其他相关项说明:四、MCU启动文件说明:五、例程BOOTLOADER使用说明六、例程使用可更改说明:七、程序使用通信方式:XMODEM八、APP程序说明九、APP代码升级说明十、代码合并烧写 前言 扩展-IAP 主要用于产品出厂后应用程序的更新作用 ,类似于其他引导装载升级程序的方法,在系统中必须始终
28335在线升级bootloader
28335二阶bootloader,可以实现远程应用升级, 非常好用
DSP在线升级详细指导
源代码和指导文档,详细学习DSP在线下载过程。程序包含bootloader和上位机软件。
xilinx fpga在线升级
xilinx 远程升级,包括golden 工程和updata工程及对应约束; 工程中包括icape2源语模块和flash读写模块;


HTML/XML
