CAutoupdater general automatic upgrade component source code

CAutoupdater Universal Automatic Update Component

 

1. Introduction of CAutoupdater general automatic upgrade components

1.1 、Component introduction

The characteristic of the C/S structure is that it can give full play to the processing capability of the client. Many jobs can be processed by the client and then submitted to the server. The corresponding advantage is that the client has a fast response speed. The client has its powerful functions and rich expressiveness. It is favored by a considerable number of users, but the cost of client deployment, maintenance and upgrade is very high.

The C/S client needs to install special client software and operating environment. First of all, it involves the workload of installation, and secondly, any computer problems, such as viruses and hardware damage, need to be installed or maintained. Especially when there are many branches or specialty stores, it is not the workload but the distance. Also, when the system software is upgraded, each client needs to be reinstalled, and the maintenance and upgrade costs are very high.

The CAutoupdater component exists to solve the problem of C/S maintenance and upgrade. This component can quickly build an upgrade and deployment application, fully control the entire upgrade and deployment process, full-featured, fast, and easy to use . Set up and publish your client application .

This component provides the client with online deployment and automatic upgrade functions in the simplest mode, and completely solves the worries of upgrade and deployment. The interface provided in the component provides full control over the upgrade process in the simplest way possible. The CAutoupdater component integrates stable / efficient automatic upgrade functions for your software , which is the purpose of this upgrade component.

The CAutoupdater component completes the upgrade in four steps: check the new version, download to the temporary directory, check the local file, and copy to the working directory.

No need for a special server, traditional Web services, such as IIS , etc. The server deploys the latest version of the software files (the file list is stored in an XML file), the CAutoupdater component compares and analyzes the XML configuration files of the server and the client , and updates if they are different.

The CAutoupdater component is written in C# language and can be applied to software developed in most popular languages. It does not depend on any class library, and is stable and efficient.

2.2 , CAutoupdater component upgrade principle and process.

2.2.1 The working principle of the CAutoupdater component.

Figure 2.1.1.1 Do n't care about the version currently in use

 

Figure 2.1.1.2 Comparative analysis of the software versions used by the server and the client

2.2.2 . Server deployment.

To use the CAutoupdater component, the server must be deployed. The deployment of the server is very simple. Here we choose traditional IIS for deployment. Suppose the relevant files we upgrade are placed in the CAutoupdater folder of the D drive on the server, open IIS , create a new website, and point its physical path to: D:\CAutoupdater. For the specific IIS configuration, please refer to the relevant articles, which will not be introduced here. Here we focus on the server-side AutoupdateService.xml file.

Figure 2.2.1 AutoupdateService.xml file

You can see from the AutoupdateService.xml file that we have added a new file to be updated, RDIFramework.NET.exe , whose version number is provided by the lastver configuration item, the file size is provided by the size configuration item, and there is a configuration item needRestart , whether The application needs to be restarted, which means whether the main program needs to be restarted after updating this file. The url configuration item is the actual server address of the file to be updated, and the client downloads the file through this address.

客户端是如何判断当前是否需要更新呢?这儿主要是通过lastver(最新的版本号)与size(文件大小)来判断,两者只要取其一即可,在CAutoupdater组件中是两者同时取,只要客户端对应文件与服务端对应文件的最新版本号或文件大小不一样,则更新。下面我们来看一下如何自动生成服务端的配置文件(AutoupdateService.xml),如下图所示:

2.2.2.1CAutoupdater服务端配置

在图2.2.2.1中,配置文件的名称默认不允许修改,服务端地址就是我们配置IIS时的URL地址,在我的这个实例中是:http://localhost:8010/,服务端目录就是IIS对应URL地址所在的物理地址,在我的实例中是:D:\CAutoupdater,在界面下方的文件列表中,我们可以添加需要更新的文件,对于选择错误的文件,也可以对其选中后移除,可以看到文件列表的第一列为“重启?”,如果选中,则表示客户端升级后,需要重启客户端主程序,以完成更新,这需要根据实际的项目要求做相应的设置,没有定论。单击“生成”按钮,即可自动生成服务端的配置文件AutoupdateService.xml,同时把文件列表中的文件拷贝到指定的“服务端目录”中去。这样,就完成了服务端的配置。

同时需要说明的时,同时要修改CAutoUpdater项目文件中的“Autoupdater.config”文件,此文件实例设置如下:

<?xml version="1.0" encoding="utf-8"?>
<Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Enabled>true</Enabled>
 <ServerUrl>http://localhost:8010/AutoupdateService.xml</ServerUrl>
</Config>

其中的:http://localhost:8010/AutoupdateService.xml就是升级服务器上升级配置文件的URL地址。在客户端中也要包含这个文件,以让客户可以通过这个文件中配置的升级服务器的地址,找到待升级的文件。

2.3、客户端部署。

客户端的配置非常简单,只需引用“AutoUpdater.dll”文件,然后在需要的位置(一般是在程序启动时检查更新,也可让用户手动检查更新),我一般都是在程序启动时(在Program.cs文件的Main函数中)检查待更新的文件,参考代码为:

          #region check and download new version program
            bool bHasError = false;
            IAutoUpdater autoUpdater = new AutoUpdater();
            try
            {
                 autoUpdater.Update();
            }
            catch (WebException ex)
            {
                LogHelper.WriteException(ex);
                MessageBoxHelper.ShowErrorMsg("连接自动升级服务器出错,请检查网络连接或联系软件提供商。");
                bHasError = true;
            }
            catch (XmlException ex)
            {
                LogHelper.WriteException(ex);
                bHasError = true;
                MessageBoxHelper.ShowErrorMsg("AutoUpdate Error:Download the upgrade file error");
            }
            catch (NotSupportedException ex)
            {
                LogHelper.WriteException(ex);
                bHasError = true;
                MessageBoxHelper.ShowErrorMsg("AutoUpdate Error:Upgrade address configuration error");
            }
            catch (ArgumentException ex)
            {
                LogHelper.WriteException(ex);
                bHasError = true;
                MessageBoxHelper.ShowErrorMsg("AutoUpdate Error:Download the upgrade file error");
            }
            catch (Exception ex)
            {
                LogHelper.WriteException(ex);
                bHasError = true;
                MessageBoxHelper.ShowErrorMsg("AutoUpdate Error:An error occurred during the upgrade process");
            }
            finally
            {
                if (bHasError == true)
                {
                    try
                    {
                        autoUpdater.RollBack();
                    }
                    catch (Exception ex)
                    {
                        LogHelper.WriteException(ex);                     
                    }
                }
            }
            #endregion

客户端启动时,检查若有升级,就会弹出下面的窗口。

 

作者: EricHu
出处: http://blog.csdn.net/chinahuyong
微博: 腾讯
Email: [email protected]406590790@qq.com
QQ 交流:406590790 
平台博客: 【CSDN】http://blog.csdn.net/chinahuyong
         【CNBLOGS】http://www.cnblogs.com/huyong
关于作者:高级工程师、信息系统项目管理师、DBA。专注于微软平台项目架构、管理和企业解决方案,多年项目开发与管理经验,曾多次组织并开发多个大型项目,精通DotNet,DB(SqlServer、Oracle等)技术。熟悉Java、Delhpi及Linux操作系统,有扎实的网络知识。在面向对象、面向服务以及数据库领域有一定的造诣。现从事DB管理与开发、WinForm、WCF、WebService、网页数据抓取以及ASP.NET等项目管理、开发、架构等工作。
如有问题或建议,请多多赐教!
本文版权归作者和CNBLOGS博客共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过邮箱或QQ 联系我,非常感谢。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327046371&siteId=291194637