.NET客户端应用程序:.NET应用程序更新组件(3)

类别:.NET开发 点击:0 评论:0 推荐:

作者:Jamie Cool

Microsoft Corporation

3/4/02 

翻译:李嘉
      北京.东方瑞道
      2004-6-3

(接上篇)

Checking for Updates

为更新做检查

The first thing an application needs to be able to do in order to update itself is figure out when a new update is available.  In order to do this an application needs to know three things 1) where to check for updates, 2) when to check for updates and 3) how to check for updates.  The application update component uses HTTP for all network communication.  This allows it to update applications over the intranet or extranet.  Thus the ‘where’ to check for updates is simply a URL to a well known Web server.  

 

为了更新自身,应用程序首先需要做的就是弄清楚可使用的更新放在什么地方。为做到这一点,应用程序需要知道三件事情:1)到什么地方为更新做检查;2)什么时候进行更新检查;3)如何进行更新检查。应用程序更新组件使用HTTP进行所有的网络通讯。这就允许通过企业网或外网来更新应用程序。这样的话进行更新检查所需要的地址就成了已知的Web服务器的一个URL地址。

 

To address the ‘when’ to check for updates, the .NET Application Updater component creates a thread on component creation which is responsible for checking for updates.  This thread will sleep for most of the time, but will wake up at the configured interval to perform an update check.   How often the application checks for new updates is dependent on the individual application, but common values range from one hour to one day between update checks.  This polling based approach is not appropriate for all applications, for example Microsoft Money only checks for updates when the user tells them to.  In this case, the update poller thread can be disabled and update checks performed on-demand by calling the CheckForUpdate() method on the updater component. 

要获取何时做更新检查,.NET应用程序更新组件在组件生成的基础上产生一个线程,该线程负责进行更新检查。该线程在大多数时间处于休眠状态,但会在设置好的间隔苏醒并实现一次更新检查。应用程序为新的更新所做的检查的频率依赖于各应用自身。但是进行更新检查的间隔常用值的范围一般是从一个小时到几天。对于所有的应用程序,这种轮询的基本方法并不都合适。比如Microsoft Money只是在用户让它去进行更新检查时它才去检查。在这种情况下,更新轮询线程可被禁用,通过用命令调用更新组件的CheckForUpdate()方法来实现更新检查。

 

There are several ways to go about the ‘how’ to check for updates:  

关于如何进行更新检查的方法有如下几种:

Method #1:  Direct File Check – The simplest way to check for updates is to use HTTP to compare the last modified date/time stamp of the application files on the server with that on the client.  If the server has newer files, the client knows it’s time to update itself.  This is the same way a Web browser knows if it needs to re-download an html page or image or whether it can just re-use the one previously downloaded.   This is certainly the simplest to administrate.  When a new version of the app is available, the administrator simply copies the newer version over the older version on the Web server.  The problem with this is that the update is not atomic and thus there are potential windows of failure.  For example, if an administrator updates the version of the app on the Web server while a client was in the middle of downloading the previous update, that client may be left with some files from the previous update and some files from new update.  For this reason, using a direct file check is not recommended for any non-trivial applications.  

方法一.直接文件检查----通过检查来更新最简单的方法是使用HTTP来比较服务器和客户端的应用程序的最后的修改日期/时间戳是否一致。如果服务器上有更新的文件,客户端就知道是时间更新自己了。对于Web浏览器来讲,也是同样的道理,它知道是否需要重新下载一个html页面或图片还是是否可以重复使用先前已下载的。 对于管理员来说这当然是最简单的。当应用程序有一个新的版本可用时,管理员简单的拷贝一个更新的版本来覆盖Web服务器上的旧版本。这种方法的问题在于更新不是自动进行,由此会出现潜在的失败窗体。比如,如果管理员在更新Web服务器上的应用程序版本,同时有个客户在下载更新之前的版本,那么这个客户的计算机上就会既存在更新之前的一些文件,也存在更新之后新版本的一些文件。基于上述原因,对于重要的应用程序不提倡使用直接文件检查来更新。

 

(未完待续)

本文地址:http://com.8s8s.com/it/it44708.htm