asp.net Automatic Update component sharing

Source: Internet
Author: User
Tags date end file size ftp iis net version versions
I. Summary
Two days ago on the blog published an English Automatic Update component article release a Autoupdater tool, then in this article, we also have some simple explanation of its function, this component is very simple, so you can download some improvements. As we all know, for the general Software development, at the beginning there will be a technology selection stage, the largest selection is to determine the first choice of Client/server mode or Browser/server mode. Synthesis and discussion: both have advantages and disadvantages, in many ways can not be replaced by each other, such as in the application of the Internet, maintenance workload, b/s than c/s stronger than the more than the, but in the speed of operation, data security, human-computer interaction, B/S is far less powerful than So to sum up, all C/s strengths, is b/s weakness, and vice versa. Because today's discussion is the automatic Update component, so next we go to this aspect, since the C/S mode in the running speed, data security, man-machine interaction has so many advantages, especially the increasingly development of client technology today, how to solve the client deployment and automatic upgrade is a very important issue.

Two. Outline of this article

· 1. The SUMMARY

· 2. Outline of this article

· 3. Why not use ClickOnce

· 4. Brief introduction

· 5. How to use the project

· 6. Specific effects

· 7. Maintenance and download

· 8. Summary
three. Why not use ClickOnce
In the previous summary we briefly introduced the importance of the Automatic Updates feature, and in this section we talk about why we don't use the Automatic Updates component ClickOnce that Microsoft has given us, and we all know that ClickOnce offers us a lot of functionality: Simply put, ClickOnce The application is any Windows forms or console application that is published using ClickOnce technology. You can publish a ClickOnce application in three different ways: from a Web page, from a network file share, or from a media (such as a CD-ROM). A ClickOnce application can be installed on the end user's computer and run locally (even when the computer is offline), or it can be run in online mode only, without permanently installing anything on the end user's computer. ClickOnce applications can update themselves, and these applications can check for newer versions when newer versions become available, and automatically replace all updated files. Developers can specify update behavior, and network administrators can control update policies, such as marking updates as mandatory. The end user or administrator can also rollback the update to restore the application to an earlier version.

As you can see from the above, ClickOnce is undoubtedly the best solution for Microsoft's deployment of Client/server mode, but it is very powerful and easy to use, so it is particularly tight on the packaging of the product, and basically exposes some simple operating interfaces, This will be invisible to some of the customization of the operation of the door, such as:

1, the user cannot specify the installation path himself.

2, the automatic update process can not do customized operations.

3, the automatic updating of the UI can not be customized design.

Because of these reasons, many enterprises will do some customization of components to implement the automatic Update function, based on this, we also implemented a very simple automatic Update component.

Four. Brief introduction

In fact, the principle of automatic Updates is very simple, analysis is simply a few steps, of course, the implementation of the same way, here we choose a simpler way:

1. Start the main program, the main program to call the upgrade program, upgrade the program to connect to IIS or FTP.
2. The upgrade program gets the updated date or version number or file size of the new version of the server-side XML configuration file.
3. The upgrade program obtains the most recent update date or version number or file size of the original client application, then compares the two, and prompts the user for an upgrade if the new version date > The current date of the original program, or if the new version number > The version number of the original program, prompts the , or if the new version file size > The file size of the original program, prompts the user for an upgrade. This article mainly uses the general practice, is by the version number to carry on the contrast.
4. If the user chooses to upgrade, obtain the download file list;
5. Establish a temporary directory with remote IIS or FTP locally and download it to this temporary directory file;
6. Delete the old main program, copy the files in the temporary folder to the appropriate location;
8. End the upgrade process and restart the main program.
Based on the previous process, we can simply design the following items:

Figure 1

Specific class Introduction:
IAutoUpdater.cs provides an interface for external calls
AutoUpdater.cs the main action class for this component
Autoupdater.config Local configuration file
DownloadConfirm.cs Prompt for Update page
DownloadProgress.cs Download Progress page
CommonUnitity.cs some common functions
Config.cs you need to update config after the update is complete, you need a config class that provides serialization
ConstFile.cs Some constant files
DownloadFileInfo.cs file entity classes that need to be downloaded
LocalFile.cs Local File entity class
RemoteFile.cs Remote File entity class
UpdateFileList.cs a local collection of entity classes
The code is very simple, can be downloaded for viewing, so there is no too much elaboration.
Five. How to use the project
The first step: host-Updated version to server
If you need to get the latest version of the client, first we need developers to compile the source code and generate files, and then copy to the FTP or IIS directory, run an automatic generation of XML files, all the files are automatically generated to an XML file, detailed see the following figure:
                                Figure 2

Step Two: Configure the local config

After the first step, this step is to configure the local config to monitor and download remote IIS or files that need to be updated under FTP, as shown in the following illustration:

Figure 3

Step Three: Modify the main program
First of all, Autoupdater this DLL into our main project, and then add the following code to the main project, of course, you can write according to your own needs, this DLL provides two external interfaces, an interface to determine whether there are updates and downloads, Another interface is a rollback operation for an update error, as follows:
Copy CodeThe code is as follows:
#region Check and download new version program
BOOL Bhaserror = false;
Iautoupdater autoupdater = new Autoupdater ();
Try
{
Autoupdater.update ();
}
catch (WebException exp)
{
MessageBox.Show ("Can not find the specified resource");
Bhaserror = true;
}
catch (XmlException exp)
{
Bhaserror = true;
MessageBox.Show ("Download The upgrade file error");
}
catch (NotSupportedException exp)
{
Bhaserror = true;
MessageBox.Show ("Upgrade address configuration Error");
}
catch (ArgumentException exp)
{
Bhaserror = true;
MessageBox.Show ("Download The upgrade file error");
}
catch (Exception exp)
{
Bhaserror = true;
MessageBox.Show ("An error occurred during the upgrade process");
}
Finally
{
if (Bhaserror = = True)
{
Try
{
Autoupdater.rollback ();
}
catch (Exception)
{
Log the message to your file or database
}
}
}
#endregion使用就是这么简单, more detailed operation, you can download the source code, but also because it is simple, so you can modify it to meet the needs of specific projects.

Six. Specific effects

When we run the main program (WinForm or WPF), if the server has the latest version, it will pop up the following page to prompt and let the user choose whether to update.

Figure 4

When the user does not need to update, you can choose the Skip button to skip and continue the main program flow, and vice versa, go to the following page.

Figure 5

During the download process, the user can choose Cancel to stop downloading and return to the main process.

Seven. Maintenance and download

This component has been hosted to CodePlex, so you can download its source code, specific address: http://autoupdater.codeplex.com/

Figure 6

Eight. Summary

Our article simply explained a simple automatic Update component, because it is relatively simple and functional, so it does not cost a lot of space for discussion, interested readers can download its source code. Later I will be the development of their own set of MVVM framework also hosted up, because the current support for Silverlight is not very good, so is continuing to do related improvements, which draw on some of the other excellent framework of ideas and into a number of practical application scenarios, so when we also hope that we can give more advice!
The Knights Templar
Source: http://www.cnblogs.com/KnightsWarrior/



Related Article

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.