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!
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:
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
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.
Service
Here we only need to inject our implemented update logic into IServiceCollection.
Next, let's look at how to implement it in the controller.
running effect
download and install
project address:
Nuget Address:
- https://www.nuget.org/packages/GeneralUpdate.Common/
- https://www.nuget.org/packages/GeneralUpdate.ClientCore/
- https://www.nuget.org/packages/GeneralUpdate.AspNetCore/
- https://www.nuget.org/packages/GeneralUpdate.Zip/
- https://www.nuget.org/packages/GeneralUpdate.Single/
- https://www.nuget.org/packages/GeneralUpdate.Core/
Microsoft Most Valuable Professional (MVP)
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!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。