Design and implementation of automatic upgrade system Oaus (continued) (with the latest source code)

Source: Internet
Author: User

I. Origins

 Since the design and implementation of the automatic upgrade system (source code) was released, received a lot of user feedback, the most requirement is that the Oaus server to increase the ability to automatically detect file changes, so that each deployment version upgrade, can save a lot of time, and can avoid manual modification caused by errors.

Now, let me briefly explain the implementation of this feature in the latest version of Oaus. in the previous release, we did this:

Each time there is a version update, we need to copy the updated files to the service side of the Filefolder folder to overwrite the old files, and then through the above operating interface, to manually modify the version number of each file. The process is tedious and error-prone. As a result, the new version increases the ability to scan automatically, and one-click can be done.

The new operating interface is as follows:

  

Click on the "Auto Scan" button, the server will retrieve the Filefolder folder file name, size, last update time, and then come to the results of this update: changed several files, several new files, deleted several files.

Two. Source Code implementation

The following is a brief description of the code implementation process.

The 1.FileUnit class adds FileSize and LastUpdateTime properties: These two properties are used as the most fundamental basis for changing the file.

2. The specific implementation code is as follows:

Private voidButton1_Click (Objectsender, EventArgs e) {        intChangedcount =0; intAddedcount =0; List <Fileunit> deleted =New List<FileUnit>(); List <string> Files = ESBasic.Helpers.FileHelper.GetOffspringFiles (AppDomain. Currentdomain.basedirectory +"filefolder\\"); //First round: Detection of changes and new files        foreach(stringFilerelativepathinchfiles) { FileInfo info=NewFileInfo (AppDomain.CurrentDomain.BaseDirectory +"filefolder\\"+Filerelativepath); fileunit Unit= This.            Getfileunit (Filerelativepath); if(Unit = =NULL)//the new file{Unit=New Fileunit(Filerelativepath,1, (int) info. Length, Info.                LastWriteTime);  This. FILECONFIG.FILELIST.ADD (unit); ++Addedcount; }            Else            {                //files that have changed                if(Unit. FileSize! = info. Length | | Unit. Lastupdatetime.tostring ()! =info. Lastwritetime.tostring ()) {unit. Version+=1; Unit. FileSize= (int) info.                    Length; Unit. LastUpdateTime=info.                    LastWriteTime; ++Changedcount; }            }        }        //second round: Detection of deleted Files        foreach(FileunitUnitinch  This. Fileconfig.filelist) {            BOOLFound =false; foreach(stringFilerelativepathinchfiles) {                if(Filerelativepath = =Unit. Filerelativepath) {found=true;  Break; }            }            if(!found) {deleted.            ADD (unit); }        }        foreach(FileunitUnitinchdeleted) {             This. FileConfig.FileList.Remove (unit); }         This. Fileconfig.save (); if(Changedcount >0|| Addedcount >0|| Deleted. Count >0)        {             This. changed =true;  This. Datagridview1.datasource =NULL;  This. Datagridview1.datasource = This. fileconfig.filelist; stringmsg =string. Format ("update: {0}, added: {1}, deleted: {2}", Changedcount, Addedcount, deleted.            Count); MessageBox.        Show (msg); }        Else{ MessageBox. Show ("no changes detected. "); }               }

(1) First, the first round detects changes or additions to the file.

(2) Then, the second round detects the deleted files.

(3) The version number of the maintenance is updated after each test is completed.

Finally, I retained the original manual update version number to prepare for a rainy date.

3. Instructions on how the client uses the upgrade mechanism

  In general, if the latest client program is compatible with older versions and does not have a significant impact, it can be left to the user to decide whether to upgrade, or if the latest client program is incompatible with the old version, or if there is a major update, a forced upgrade will be initiated. If the process is going to start the upgrade, just start the Autoupdater folder under AutoUpdater.exe. Note that after starting the AutoUpdater.exe process, to exit the current client process, some files may fail because they cannot be overwritten. The code is roughly as follows:

  if (versionhelper. Hasnewversion (Oausserverip,oausserverport))   {             AppDomain. Currentdomain.basedirectory + "autoupdater\\autoupdater.exe";          System.Diagnostics. Process myprocess = system.diagnostics. Process. Start (Updateexepath);            ...//exiting the current process    

After the client runs, the upgrade process is as follows:

three. Related Downloads

1. Automatic upgrade system Oaus-source code

2. Automatic Upgrade system Oaus (can be deployed directly)

  If you have any suggestions or questions, please leave a message to me.

Design and implementation of automatic upgrade system Oaus (continued) (with the latest source code)

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.