C#實現(xiàn)軟件自動更新思路_第1頁
C#實現(xiàn)軟件自動更新思路_第2頁
C#實現(xiàn)軟件自動更新思路_第3頁
C#實現(xiàn)軟件自動更新思路_第4頁
C#實現(xiàn)軟件自動更新思路_第5頁
已閱讀5頁,還剩14頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、c#實現(xiàn)軟件自動更新思路prefacefor a long time, most programmers for what is the use of client/sem, or use the browser/server structure, in the midst of these arguments, the c/s structure of the program poor niaintainability, decorate difficulty, upgrade is not convenient, high maintenanee cost is an important

2、factor there are many enterprise users who give up using c/s for this reason. however, when an application has to use the c/s structure to do well, how do we solve client deployment and auto-escalation? it's easy to deploy, just click the installer, and the hard part is that every time a new rel

3、ease comes out, it will automatically update 3 now, our goal is simple, and we want to develop an automated upgrade system that is not relevant to specific applications below i provide a reusable set of automatic upgrade systems for c #the difficulty of automating software updatesfirst, in order to

4、find the remote server update, the application must have ways to query the network, the need to network programming, simple application and the server communication protocolthe seco nd is downloading. downloadi ng does n't seem to need to take into account the networking problem, but consider do

5、wnloading the file for the user's request and downloading large files without the user,s permission. the friendly automatic update application will download the updates with the remaining bandwidth. it sounds simple, but it is a technical problem, and fortunately there is a solution.the third co

6、nsideration is the process of replacing the original application with a new version of the application this question is interesting, because it requires the runtime code will be deleted from the system, and there are many ways to realize the function 5, this paper mainly through comparing the old an

7、d new versions of the program date, to achieve the function to replace the new version of the application.implement automatic online update of softwarewrite two programs, one is the main program; one is the upgrade program; all upgrade tasks are done by the upgrade program1. start the upgrade proces

8、s, upgrading program to connect to the web site, download the new main program (of course also includes support library files, xml configuration document, etc.) to a temporary folder.update the program to retrieve the update date or version number or file size of the new version of the server side x

9、ml configuration f訂eupdate the program to retrieve the latest update date or version number or file size of the original client application, both of which are compared; if you find that the update date is larger than the current date of the original program, the user will be prompted to upgrade ot t

10、o compare an existing version to the latest version, and find out if the latest one is an upgrade;others use other properties such as file size to compare, and find that the size of the file size of the upgrade program is larger than the older version of the program this article mainly uses the newe

11、r version update date number to prompt the user to upgradeif the user chooses to upgrade, get the list of downloaded files and start the batch downloadthe upgrade program detects if the old main program is active, and if the activity closes the old main programdelete the old master program and copy

12、the files in the temporary folder to the appropriate locationcheck the state of the main program, and start a new master program if the state is active.close the upgrade and upgrade to 4steps for online updatesuse c # to implement criticali mainly use date information here to check if you need to do

13、wnload the upgrade version.4.1 prepare an xml configuration filethe name is autoupding. xml,which is used as an upgradedtemplatetodisplay information thatneeds to be upgraded.the name is autoupding. xml, which is used as an upgradedtemplate to display information that needs to be upgraded.<? xml

14、version 二 l0? > / / xml version numberthe < autoupdater >< urladdres url 二 http:/192 168. 198.113 / vbroker/log/z,/ > / / upgrade the url on the server side of the serverthe < updateinfo >< updatetime date 二 2005-02-02 / > / / upgrade file update date< version num 二 1 0

15、. 0. 1 / > / / upgrade file version number< / updateinfo >< updatefilelist > / / upgrade file list< updatefile filename 二,zaa txt / > / / all three files need to be upgraded< updatefile filename 二 vb40rar" / >< updatefile filename 二 vb4t cab / >< / updatefile

16、list >the < restartapp >< restart allow 二 yes / > / / allow to restart the application< appname name 二 timsexe / > / / boot application name< / restartapp >< / autoupdater >/ / the xml version number/ / update the url on the server side of the file/ / update the date

17、 of the update file/ / upgrade the version number of the file/ / upgrade the list of files/ / there are three files that need to be upgraded/ / allow the application to be restarted/ / initiated application namelearn from above in the xml document can upgrade the document in the server address, date

18、 of update document update, need to upgrade the file list, there are three documents which need to upgrade: aa. txt, vb40. rar, vb4-1 the cab. and whether to allow the application and restart of the application name tobe restarted.get the latest update date for the client application and the server

19、side upgradethe getthelastupdatetime () function is implemented.private string getthelastupdatetime (string dir)string lastupdatetime 二 ;string autoupdaterfi1ename 二 dir + " autoupder-xml"if (! file exists (autoupdaterfilename)return lastupdatetime;/ / open the xml filefilestream myfile 二

20、new filestream (filemode.open);/ / xml file readerxmltextreader xml 二 new xmltextreader (myfile);while (xml. the read ()if ( = = updatetime)/ / get the last updated date for the upgrade documentlastupdatetime 二 xml. getattribute (“ date “);break;xml. the close ();myfile close ();return lastu

21、pdatetime;open the xml document with the xmltextreader, read the update time to get the value of date, the latest update time for the server side upgrade filefunction call implementation:/ / get the latest update time for the application under the client specified pathstring lhepreupdatedate 二 getth

22、elastupdatetime (application.application, startuppath is the path that the die ntapplication is in./ / get the latest update date from the server side to download the documentstring thelastsupdatedate 二 getthelastupdatetime (thefolder)thefolder fullname refers to the path of the temporary folder whe

23、re the document is downloaded to the client4. 3the latest update date for the client application is compared with the latest update date from the server side upgrade/ / get the latest update date for the downloaded documentstring thelastsupdatedate 二 getthelastupdatetime (thefolder)if (thepreupdated

24、ate!二“)/ / if the update date for an updated application is greater than the update date of the server side upgrade applicationthepreupdatedate > = convert, todatetime (thelastsupdatedate)messagebox show (“ the current software is new, no need to update! “), "system prompt", messageboxb

25、uttons ok, messageboxicon.enclosing the close ();this labdownfile .text 二down load the update file"this labfilename refresh ();this.thisprogressbar .position 二 0;thisprogressbartota1. position 二 0this progressbartota1. refresh ();this the progressbar refresh ();/ / retrieve the list of download

26、ed files from the dynamic arraythe arraylist list 二 getdownfilelist (gettheupdateurl (),the. fuliname);string urls 二 new string list.count;copyto (urls, 0);compare the date of the application with the client upgrade to the application date downloaded from the server side, if the former is greater th

27、an the latter, and is not updated; if the former is less than the latter, you can download the list of the downloaded files from the dynamic array and start downloading the fileget the latest update date for the client application and the server side upgradethe getthelastupdatetime () function is im

28、plemented.private string getthelastupdatetime (string dir)string lastupdatetime 二 ;string autoupdaterfi 1 ename 二 dir + " autoupder-xml,z;if (! file exists (autoupdaterfilename)return lastupdatetime;filestream myfile 二 new filestream (filemode.open);/ / xml file readerxmltextreader xml 二 new xm

29、ltextreader (myfile);wh訂 e (xml. the read ()if ( 二 二,updatetime,/)/ / get the last updated date for the upgrade documentlastupdatetime 二 xml. getattribute (“ date “);break;xml. the close ();myfile close ();return lastupdatetime;open the xml document with the xmltextreader, read the update ti

30、me to get the value of date, the latest update time for the server side upgrade filefunction call implementation:/ / get the latest update time for the application under the client specified pathstring thepreupdatedate 二 getthelastupdatetime (application.application. startuppath is the path that the

31、 client application is in./ / get the latest update date from the server side to download the documentstring thelastsupdatedate 二 getthelastupdatetime (thefolder)thefolder fuhname refers to the path of the temporary folder where the document is downloaded to the client4. 3the latest update date for

32、the client application is compared with the latest update date from the server side upgradestring thelastslpdatedate = getthelastupdatetime (thefolder)if (thepreupdatedate!二“)/ / if the update date for an updated application is greater than the update date of the server side upgrade application(conv

33、ert todatetime)messagebox show (“ the current software is new, no need to update! “, "system prompt", messageboxbuttons ok, messageboxicon.information);enclosing the close ();this. labdownfile .text 二,z down load the update file"this labfilename refresh ();this.tgressbar.positi

34、on 二 0;tgressbattota1. position 二 0this progressbartota1. refresh ();this the progressbar refresh ();/ / retrieve the list of downloaded files from the dynamic arraythe arraylist list 二 getdownfilelist (gettheupdateurl (), the.fullname);string urls 二 new string list.count;copyto (urls, 0);com

35、pare the date of the application with the client upgrade to the application date downloaded from the server side, if the former is greater than the latter, and is not updated; if the former is less than the latter, you can download the list of the downloaded files from the dynamic array and start do

36、wnloading the filethis is achieved through the batchdownload () function the upgrade program detects if the old main program is active and if the activity closes the old main program; delete the old master program and copy the files in the temporary folder to the appropriate location; check the stat

37、e of the main program, if the state is active, start a new master programprivate void batchdownload (object data)this is the most important thing in the world.the trydownloadinstructions 二(downloadinstructions) data;/ / batch downloadusing (batchdownloader bdl 二 new batchdownloader ()currentprogresschanged + 二 new downloadprogresshandler.statechanged + 二 new downloadprogresshandlerfilechanged + 二 new downloadprogresshandler (bdlf i1echanged);totalprogresschanged + 二 new downloadprogresshandler (bdl_totalprogresschanged

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論