头图

Hello everyone, I am the laboratory researcher of this issue-Zhu Zhen. Today I will introduce to you how to create a client application that can be automatically upgraded based on the open source project GeneralUpdate through experiments and a complete operation process. Next, let us go to the laboratory to find out!

image.png

project introduction

developed based on the .net standard (c/s application). This component extracts the core part of the update and is convenient to apply to a variety of projects. It is currently suitable for wpf, console applications, and winfrom. The functions of the six components currently encapsulated are as follows:

  • GeneralUpdate.Core: Resumable uploading, version-by-version update, download timeout period
  • GeneralUpdate.ClientCore: Resumable uploading, version-by-version update, self-update of update component, convenient start of update component
  • GeneralUpdate.AspNetCore: The server supports the update package download address, version information, etc.
  • GeneralUpdate.Zip: unzip the update package, unzip progress notification
  • GeneralUpdate.Single: application singleton operation
  • GeneralUpdate.Common: component public classes and methods
  • And the database structure script that generates version information.

coding realizes

Before I talk about the coding implementation, you may be unfamiliar with the automatic update process. Here I have compiled an update flow chart to explain it for you:

289e178077dac9c8f4ec90ef4a1e4bc6.png

Please remember a few nouns . MainApp is the company's product project, UpdateApp is an independent process upgrade program, and Service is a server.

(1) Mainapp will request the UpdateApp update program package from the server (this step is for self-update UpdateApp)

(2) If UpdateApp needs to be updated, download the update package (for MD5 encryption verification)

(3) No need to update or after the update is completed, UpdateApp will be opened through process communication

(4) After UpdateApp is started, it starts to request the update package of Mainapp from the server (for MD5 encryption verification)

(5) If yes, download the update package, and unzip the file in the Mainapp update package and overwrite it locally to implement the update

(6) After the UpdateApp update is complete, start Mainapp and close itself

After roughly knowing the update process, let's take a look at the applications of MainApp, UpdateApp, and Service respectively.

MainApp

9707b41749e3dfda797bdd52a43aabb7.png

You can see that after referencing the nuget package of GeneralUpdate.ClientCore, it is very convenient to directly use the above syntax directly. Basically, some of the information you care about is encapsulated in these events. Let's take a look at the encapsulated content.

MutiDownloadProgressChanged This event can provide information for single or multiple update packages:

  • Current download package size
  • Download progress
  • Percentage of progress
  • Downloaded version information
  • The operation currently being performed (checking the version information, downloading the current version, update completed, update failed)
  • Downloaded size

MutiDownloadStatistics This event can provide information:

  • Remaining download time
  • download speed

OnMutiDownloadCompleted This event can provide information:

  • Is the currently downloaded update package downloaded?

OnMutiAllDownloadCompleted This event can provide information:

  • This time, if there are multiple versions that need to be updated, it will be notified after all version update files are downloaded.

OnMutiDownloadError This event can provide information:

  • Abnormal information in the process of downloading the version file

Exception:

  • Any abnormalities in the process of downloading, installing and starting the program will be returned through this event

Config:

  • What needs to be passed between processes

Strategy<>:

  • It is an entrance open to developers to extend. If there are new changes in the update process, you can inherit the DefaultStrategy class that comes with the component default for custom extensions

LaunchTaskAsync:

  • Start the update boot class

UpdateApp

Here is almost the same function as the previous component. Here is a brief look at how the code is applied.

a933ce6e9d0345971bf3ac1043f88313.png

Service

Here we only need to inject our implemented update logic into IServiceCollection.

9aadc7caba64d5f682189ca235e7233b.png

Next, let's look at how to implement it in the controller.

988f9e48385446eafac08a1055372bf9.png

running effect

895a751cbce7c7b9e9923b84f8a0a64d.png

download and install

project address:

Nuget Address:

Microsoft Most Valuable Professional (MVP)

bc93fde364ea9dd3d9106b58e805b770.png

Microsoft's Most Valuable Expert is a global award granted by Microsoft to third-party technology professionals. For 28 years, technology community leaders around the world have won this award for sharing their expertise and experience in online and offline technology communities.

MVP is a team of experts who have been carefully selected. They represent the most skilled and intelligent people, and they are experts who have great enthusiasm for the community and are willing to help others. MVP is committed to helping others through speeches, forum questions and answers, creating websites, writing blogs, sharing videos, open source projects, organizing conferences, etc., and to help users in the Microsoft technology community use Microsoft technology to the greatest extent.
For more details, please visit the official website:
https://mvp.microsoft.com/zh-cn


Welcome to follow the Microsoft China MSDN subscription account for more latest releases!
image.png


微软技术栈
423 声望996 粉丝

微软技术生态官方平台。予力众生,成就不凡!微软致力于用技术改变世界,助力企业实现数字化转型。


引用和评论

0 条评论