C#?WinForm怎么實(shí)現(xiàn)自動(dòng)更新程序

這篇文章主要講解了“C# WinForm怎么實(shí)現(xiàn)自動(dòng)更新程序”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“C# WinForm怎么實(shí)現(xiàn)自動(dòng)更新程序”吧!

成都創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的巴楚網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

開發(fā)環(huán)境

.NET Core 3.1

開發(fā)工具

 Visual Studio 2019

實(shí)現(xiàn)代碼

//xml文件
<?xml version="1.0" encoding="utf-8" ?>
<updateList>
  <url>http://localhost:5000/api/Update/</url>
  <files>
    <file name="1.dll" version="1.0"></file>
    <file name="1.dll" version="1.1"></file>
    <file name="AutoUpdate.Test.exe" version="1.1"></file>
  </files>
</updateList>
 //Model
  public class UpdateModel {
        public string name { get; set; }
        public string version { get; set; }
    }

    public class UpdateModel_Out {
        public string url { get; set; }
        public List<UpdateModel> updateList { get; set; }
    }
//控制器
namespace AutoUpdate.WebApi.Controllers {
    [Route("api/[controller]/[Action]")]
    [ApiController]
    public class UpdateController : ControllerBase {

        [HttpGet]
        public JsonResult Index() {
            return new JsonResult(new { code = 10, msg = "success" });
        }

        [HttpPost]
        public JsonResult GetUpdateFiles([FromBody] List<UpdateModel> input) {
            string xmlPath = AppContext.BaseDirectory + "UpdateList.xml";

            XDocument xdoc = XDocument.Load(xmlPath);
            var files = from f in xdoc.Root.Element("files").Elements() select new { name = f.Attribute("name").Value, version = f.Attribute("version").Value };
            var url = xdoc.Root.Element("url").Value;

            List<UpdateModel> updateList = new List<UpdateModel>();
            foreach(var file in files) {

                UpdateModel model = input.Find(s => s.name == file.name);
                if(model == null || file.version.CompareTo(model.version) > 0) {
                    updateList.Add(new UpdateModel {
                        name = file.name,
                        version = file.version
                    });
                }
            }
            UpdateModel_Out output = new UpdateModel_Out {
                url = url,
                updateList = updateList
            };
            return new JsonResult(output);
        }

        [HttpPost]
        public FileStreamResult DownloadFile([FromBody] UpdateModel input) {
            string path = AppContext.BaseDirectory + "files\\" + input.name;
            FileStream fileStream = new FileStream(path, FileMode.Open);
            return new FileStreamResult(fileStream, "application/octet-stream");
        }

    }
}

實(shí)現(xiàn)效果

C#?WinForm怎么實(shí)現(xiàn)自動(dòng)更新程序

感謝各位的閱讀,以上就是“C# WinForm怎么實(shí)現(xiàn)自動(dòng)更新程序”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)C# WinForm怎么實(shí)現(xiàn)自動(dòng)更新程序這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

網(wǎng)頁(yè)題目:C#?WinForm怎么實(shí)現(xiàn)自動(dòng)更新程序
文章位置:http://bm7419.com/article0/jdgjio.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、全網(wǎng)營(yíng)銷推廣響應(yīng)式網(wǎng)站、服務(wù)器托管、網(wǎng)站建設(shè)、App設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名