C # implements its own proactive upgrade (with source code)

Source: Internet
Author: User

For PC desktop applications, the ability to proactively upgrade is often indispensable.

The proactive upgrade can be developed as an independent C/s system, so that it can be reused in different desktop applications. This article will focus on the relevant background of Oaus, usage, as to the specific implementation details, we can directly download the source code research.

Suppose you understand the use of Oaus. The source code is very easy to understand.

If you need to deploy the system directly using your own initiative, you can download the executable program compression package at the end of the article.

I. Main functions of Oaus

At the moment the mainstream program proactively upgrades the strategy by downloading the latest installation package again, and then installing the entire client again.

Although simple and intuitive, the flaw is very obvious. For example, even if the entire client has 100M. This update only changes a 1k size DLL, which means downloading all of the 100M content again.

This is a huge waste of bandwidth, and it has extended the time to upgrade and, accordingly, has added to the customer's vacant waiting time.

? ??? In the above scenario, when you proactively upgrade, can we just update the modified 1k DLL? Of course, it's easy to do this by using Oaus to proactively upgrade your system. Oaus own initiative to upgrade the system can be distributed in the client program each file version number management, each upgrade of the base unit is no longer the entire client program, but a single file.

Updates for individual files, including three forms:

(1) The file has been altered.

(2) The file is deleted.

(3) Add a new file.

????? Oaus supports these three types of file updates. Each time you actively upgrade, you can change n files, delete m files, new add l files.

Two. The structure of the Oaus using 1.OAUS

????? Oaus provides a server-side program and client program that can be executed directly: AutoUpdaterSystem.Server.exe and AutoUpdater.exe.? The directory structure of the Oaus server is as seen below:

???????????

????? With TCP communication between the client and server of Oaus, the server can be configured in the AutoUpdaterSystem.Server.exe.config configuration file to provide its own proactive upgrade service through which TCPPort.

????? The Filefolder directory was initially empty. The latest version number of each file that is used to deploy the program being distributed.

Attention. The file structure under it must be fully consistent with the structure of the program being distributed properly-that is, the equivalent of deploying a distributed program in the Filefolder directory.

?????? The directory structure of the oausclient is as follows:??????

??????

?????? Be able to configure Oausserver IP, port and other information in the AutoUpdater.exe.config configuration file. The contents are as follows:

<Configuration>  <appSettings>    <!--ServerIP -    <AddKey= "ServerIP"value= "127.0.0.1"/>    <!--ServerPort -    <AddKey= "ServerPort"value= "4530"/>    <!--after the upgrade is complete. The name of the executable program that will be recalled -    <AddKey= "Callbackexename"value= "Demo.exe"/>    <!--title of the main window -    <AddKey= "Title"value= "File Update"/>  </appSettings></Configuration>

? ??? Note the configured Callbackexename, which indicates when the upgrade is complete. The name of the EXE that will be started by the dispatcher.

Why is this callbackexename configuration a name instead of a path? This is due to the requirement when using and deploying Oausclient:

(1) The executable EXE of the program being distributed must be located in the root directory of the deployment directory.

(2) The Oaus client (that is, the entire Autoupdater directory) must also be located in this root directory.

????? In this way, Autoupdater knows the exe of the distribution program relative to its own path, so it can determine the absolute path of the EXE of the distribution program, so you can start the target EXE after the upgrade is complete. In addition, according to the above two conventions, combined with the previous service side of the Filefolder directory structure Convention, when the server update a file, Autoupdater will be able to determine the file on the client machine absolute path.

2. Oaus your own initiative to upgrade the process?

???????? Below we will specifically talk about how to use Oaus to build their own initiative to upgrade the system, the approximate process such as the following.

(1) Execute the Oaus service side.?????

? ? ???????

(2) Place all the contents of the client program being distributed to the Filefolder directory on the Oaus server. Its structure should be completely consistent with the structure of the client program after normal deployment. Let's take the deployment Videochatsystem as an example.

???????

(3) Use the Oaus server to generate a default version number for each file of the client program being distributed and create a version number information profile Updateconfiguration.xml. This configuration file will also be used by the client.

???????? Clicking on the "File version number Management" button on the server interface will bring up the "file version number information" window for managing the individual file version numbers.???????

   

When the new version number of the file overwrite the old file, click on the " self-scan " button, the server will retrieve the Filefolder directory file name, size, last update time, and then the results of this update: changed several files, a few new files, Several files have been deleted. The self-active scan feature simplifies all previous manual operations.

?

??????? If you need to do this manually, you can:

???????? Double-click a random line in the list to change the value of the version number of the corresponding file (the value of type int).

Note that the version number information in this list is not related to the real version number attribute of the file (for example, the DLL's version number attribute x.x.x.x), and the value of the version number in the list is only used to mark whether the file has been altered. Therefore, each time the file is changed, the corresponding version number in the list should be increased.

?????? When the file version number Information window is closed. There is only one file version number to change. Then the value of the last composite version number (int type) is incremented by 1. By comparing the value of the "final composite version number" Saved by the Oaus client with the latest "final comprehensive version" value of the Oaus server, it is possible to quickly identify whether the client is already the latest version number.

?????? In addition, the first time you open this window, you will be on the Oaus server directory, you actively generate a version number information configuration file Updateconfiguration.xml. And. Whenever a new version number of a file is set through this window, Updateconfiguration.xml automatically synchronizes the update itself.

(4) Add Updateconfiguration.xml to the Oaus client program (the Autoupdater directory above).

(5) When you create the Setup program for the client that is being distributed. The Oaus client (that is, the Autoupdater directory) is also packaged and, as previously stated, deployed directly under the execution directory (basedirectory) (the same directory as the distributed EXE).

???????? In this case, the preparation is complete, after the client has installed the Videochatsystem through the installation package. Its directory structure resembles the following:?

???????

(6) When we have a new version number to be published. For example, to update a file (because the file was altered), you can do so:

? A. Copy the modified file to the correct location (or overwrite the old file) under the Filefolder directory on the Oaus server.

? B. Open the "file version number Information" window on the Oaus server and double-click the row corresponding to the changed file. In the popup window, change the version number of the corresponding file and add the number of the version number. (Assuming that you delete old files or add new files, you can do the same here)

(7) This way, when the client restarts AutoUpdater.exe, it will actively upgrade itself. Update those files that have changed. The following is the implementation of AutoUpdater.exe.

??????

(8) When the upgrade is complete, the callback exe configured in the oausclient configuration file described above will be launched. (In this case, VideoChatSystem.exe)

(9) Oausclient will be in the log file UpdateLog.txt (located in the Autoupdater directory. The file is generated on its own initiative when Oausclient first executes). Record each time you proactively upgrade yourself.

(10) Assume the process of upgrading. If the connection to the server is interrupted, it will proactively reconnect itself. After the re-connection succeeds, the breakpoint is started to resume.

?????

???????

3. When do you start your own initiative to upgrade the client?

??????? If a system is downloaded as a client, how will the client know if there is a new version number? And then when is it time to start AutoUpdater.exe?

?????? Our experience is this: after the client login succeeds, get the value of the "last composite version number" from the server. Then, compared to the local "final composite version" value, assuming that the local value is small, the client needs to be updated. This process can do this:

(1) When a new file is placed in the Filefolder directory on the Oaus server. The version number is updated correctly by the file version number Information window, and when the file version number Information window is closed, the value of the final composite version number is actively added by 1.

(2) The system client can call Oaus.core. The static method of the Versionhelper class hasnewversion () to infer whether there is a new version number.

(3) Assuming that the Hasnewversion method returns True, there are usually two modes: the user chooses whether to upgrade. Or a forced upgrade.

????? In general, it is assumed that the latest client program is compatible with the old version number and does not have a small impact, and can be left to the user to decide whether to upgrade. If the latest client program is incompatible with the old version number, or if there is a significant update, a forced upgrade will be initiated. Assuming the process is going into a start-up upgrade, just start the Autoupdater directory and AutoUpdater.exe will be able to do so. Note that after you start the AutoUpdater.exe process. To exit the current client process, some files may fail to update because they cannot be overwritten. The code generally looks like the following:?

if(Versionhelper. Hasnewversion (Oausserverip,oausserverport))   {             stringUpdateexepath = AppDomain.CurrentDomain. BaseDirectory +"Autoupdater\\autoupdater.exe"; System.Diagnostics. Process myprocess=System.Diagnostics. Process.            Start (Updateexepath); ......//exiting the current process}
Three. Related Downloads

1. Proactively upgrade your system Oaus-source code

2. Proactively upgrade your system Oaus (can be deployed directly)?



C # implements its own proactive upgrade (with source code)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.