引言:
今天看了部落格園一位博友“菜菜灰”寫的博文:《關於軟體多版本升級的一些思考》,有感而發,雖然是做Web應用,線上升級版本的功能還是很必要。
上午花費了2個小時寫了一個“類比軟體線上升級的類”,希望對博友“菜菜灰”有點協助。
軟體類:
/// <summary>
/// 軟體類
/// </summary>
public class Soft
{
private string v = "1.0";
private IList<string> vl = new List<string>() { "1.0", "2.0", "3.0", "4.0" };
/// <summary>
/// 目前的版本
/// </summary>
public string Version
{
get
{
return this.v;
}
set
{
this.v = value;
}
}
/// <summary>
/// 版本列表
/// </summary>
public IList<string> VersionList
{
get
{
return this.vl;
}
set
{
this.vl = value;
}
}
}
軟體升級器:
/// <summary>
/// 軟體升級器
/// </summary>
public class SoftUpdater
{
public Soft soft = new Soft();
/// <summary>
/// 更新版本
/// </summary>
/// <returns></returns>
public bool Update()
{
// 目前的版本
string ver1 = soft.Version;
// 目標版本
string ver2 = (soft.VersionList.IndexOf(ver1) == soft.VersionList.Count - 1) ? ver1 : soft.VersionList[soft.VersionList.IndexOf(ver1) + 1];
return this.Update(ver1, ver2);
}
/// <summary>
/// 更新版本
/// </summary>
/// <param name="ver1">目前的版本</param>
/// <param name="ver2">目標版本</param>
/// <returns></returns>
public bool Update(string ver1, string ver2)
{
if (ver1.Equals(ver2))
{
HttpContext.Current.Response.Write("已經是最新版本");
HttpContext.Current.Response.Write("<br />");
}
else
{
HttpContext.Current.Response.Write(string.Format("{0} 升級到 {1}", ver1, ver2));
HttpContext.Current.Response.Write("<br />");
string ver3 = ver2;
string ver4 = (soft.VersionList.IndexOf(ver3) == soft.VersionList.Count - 1) ? ver3 : soft.VersionList[soft.VersionList.IndexOf(ver3) + 1];
return this.Update(ver3, ver4);
}
return true;
}
}
輸出結果:
安布雷拉 標籤: 線上升級