做爰高潮a片〈毛片〉,尤物av天堂一区二区在线观看,一本久久A久久精品VR综合,添女人荫蒂全部过程av

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

asp.net(c#)程序版本升級更新的實現代碼

來源:懂視網 責編:小采 時間:2020-11-27 22:43:18
文檔

asp.net(c#)程序版本升級更新的實現代碼

asp.net(c#)程序版本升級更新的實現代碼:直接上代碼: 代碼如下:using System; using System.Collections.Generic; using System.Text; using System.Reflection; using System.IO; using System.Net; using System.Xml; namespace Update
推薦度:
導讀asp.net(c#)程序版本升級更新的實現代碼:直接上代碼: 代碼如下:using System; using System.Collections.Generic; using System.Text; using System.Reflection; using System.IO; using System.Net; using System.Xml; namespace Update

直接上代碼:
代碼如下:

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.IO;
using System.Net;
using System.Xml;
namespace Update
{
    /// <summary>
    /// 更新完成觸發的事件
    /// </summary>
    public delegate void UpdateState();
    /// <summary>
    /// 程序更新
    /// </summary>
    public class SoftUpdate
    {
        private string download;
private const string updateUrl = "http://www.gxlcms.com/update.xml";//升級配置的XML文件地址
        #region 構造函數
        public SoftUpdate() { }
        /// <summary>
        /// 程序更新
        /// </summary>
        /// <param name="file">要更新的文件</param>
        public SoftUpdate(string file,string softName) {
            this.LoadFile = file;
this.SoftName = softName;
        }
        #endregion
        #region 屬性
        private string loadFile;
        private string newVerson;
private string softName;
        private bool isUpdate;
        /// <summary>
        /// 或取是否需要更新
        /// </summary>
        public bool IsUpdate
        {
            get
            {
                checkUpdate();
                return isUpdate;
            }
        }
        /// <summary>
        /// 要檢查更新的文件
        /// </summary>
        public string LoadFile
        {
            get { return loadFile; }
            set { loadFile = value; }
        }
        /// <summary>
        /// 程序集新版本
        /// </summary>
        public string NewVerson
        {
            get { return newVerson; }
        }
/// <summary>
/// 升級的名稱
/// </summary>
public string SoftName
{
get { return softName; }
set { softName = value; }
}
        #endregion
        /// <summary>
        /// 更新完成時觸發的事件
        /// </summary>
        public event UpdateState UpdateFinish;
        private void isFinish() {
            if(UpdateFinish != null)
                UpdateFinish();
        }
        /// <summary>
        /// 下載更新
        /// </summary>
        public void Update()
        {
try
{
if (!isUpdate)
return;
WebClient wc = new WebClient();
string filename = "";
string exten = download.Substring(download.LastIndexOf("."));
if (loadFile.IndexOf(@"\") == -1)
filename = "Update_" + Path.GetFileNameWithoutExtension(loadFile) + exten;
else
filename = Path.GetDirectoryName(loadFile) + "\\Update_" + Path.GetFileNameWithoutExtension(loadFile) + exten;
wc.DownloadFile(download, filename);
wc.Dispose();
isFinish();
}
catch
{
throw new Exception("更新出現錯誤,網絡連接失敗!");
}
        }
        /// <summary>
        /// 檢查是否需要更新
        /// </summary>
        public void checkUpdate()
        {
            try {
                WebClient wc = new WebClient();
                Stream stream = wc.OpenRead(updateUrl);
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(stream);
                XmlNode list = xmlDoc.SelectSingleNode("Update");
                foreach(XmlNode node in list) {
                    if(node.Name == "Soft" && node.Attributes["Name"].Value.ToLower() == SoftName.ToLower()) {
                        foreach(XmlNode xml in node) {
                            if(xml.Name == "Verson")
                                newVerson = xml.InnerText;
                            else
                                download = xml.InnerText;
                        }
                    }
                }
                Version ver = new Version(newVerson);
                Version verson = Assembly.LoadFrom(loadFile).GetName().Version;
                int tm = verson.CompareTo(ver);
                if(tm >= 0)
                    isUpdate = false;
                else
                    isUpdate = true;
            }
            catch(Exception ex) {
throw new Exception("更新出現錯誤,請確認網絡連接無誤后重試!");
            }
        }
        /// <summary>
        /// 獲取要更新的文件
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return this.loadFile;
        }
    }
}

把代碼編譯為一個類庫文件,通過程序引用就OK啦。
傳入的參數已經有注釋了。
下面是更新的XML文件類容,傳到空間上面就可以了,得到XML文件的地址。
代碼如下:

<?xml version="1.0" encoding="utf-8" ?>
<Update>
<Soft Name="BlogWriter">
<Verson>1.0.1.2</Verson>
<DownLoad>//www.gxlcms.com/BlogWrite.rar</DownLoad>
</Soft>
</Update>

程序更新調用方法:
1、先引用上面的DLL。
2、調用方法代碼 如下:
代碼如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Net;
using System.Xml;
using Update;
namespace UpdateTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            checkUpdate();
        }
        public void checkUpdate()
        {
SoftUpdate app = new SoftUpdate(Application.ExecutablePath, "BlogWriter");
            app.UpdateFinish += new UpdateState(app_UpdateFinish);
try
{
if (app.IsUpdate && MessageBox.Show("檢查到新版本,是否更新?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Thread update = new Thread(new ThreadStart(app.Update));
update.Start();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
        }
        void app_UpdateFinish() {
                MessageBox.Show("更新完成,請重新啟動程序!", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}

好了,整個程序到此結束。如覺得有哪里不正確或者有疑問的請給我留言。

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

asp.net(c#)程序版本升級更新的實現代碼

asp.net(c#)程序版本升級更新的實現代碼:直接上代碼: 代碼如下:using System; using System.Collections.Generic; using System.Text; using System.Reflection; using System.IO; using System.Net; using System.Xml; namespace Update
推薦度:
標簽: 升級 更新 版本
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 龙海市| 城口县| 闸北区| 哈尔滨市| 西华县| 阿巴嘎旗| 南华县| 大庆市| 齐齐哈尔市| 沧源| 梁河县| 安西县| 舟山市| 万州区| 西贡区| 济源市| 华蓥市| 伊宁市| 客服| 榕江县| 铜川市| 屯门区| 黎平县| 吴川市| 安化县| 中方县| 浏阳市| 济源市| 呼伦贝尔市| 西丰县| 满洲里市| 奈曼旗| 望都县| 哈巴河县| 黄大仙区| 醴陵市| 阜平县| 濮阳县| 淄博市| 青浦区| 屏山县|