Use Web Services to implement software automatic upgrade

zhaozj2021-02-16  47

File Update.xml:

1.2 Voice Program official version release .com ,item name = "SIZE =">

Public class updatesVS: system.web.services.webservice {// automatically generated code slightly ......

[WebMethod (Description = "Software latest version information")] Public string getver () {xmlDocument doc = new xmldocument (); doc.load (server.mappath ("update.xml"); xmlelement root = doc.documentelement ;

Return root.selectsinglenode ("version"). innerText;}

[WebMethod (Description = "Online Update Software")] Public system.xml.xmldocument getUpdatedata () {// get updated XML template content xmlDocument doc = new xmldocument (); doc.load (server.mAppath ("Update.xml ")); Xmlelement root = doc.documentelement; // Take a look at how to update XMLNode Updatenode = root.selectsinglenode (" FileList "); string path = Updatenode.attributes [" sourcepath "]. Value; int count = INT.PARS (Updatenode.attributes ["count"]. Value); // Replace the value in XML Replace for for (int i = 0; i

Client main program code:

Namespace WindowsApplication2 {// Automatically generated code slightly ... public class form1: system.windows.forms.form {// To add a web reference http://10.16.80.22/websvs/websvs.asmx, naming For zwt_svs private static zwt_svs.UpdatesVs UPD; // The process function of the main program ...

Void update () {system.xml.xmldocument doc = new system.xml.xmldocument ();

System.xml.xmlNode TmpNode = Upd.getUpdatedata ();

doc.AppendChild (doc.ImportNode (tmpNode, true)); doc.Save (Application.StartupPath @ "/ update.xml"); System.Diagnostics.Process.Start (Application.StartupPath @ "/ update.exe" ); Close (); application.exit ();

Private void form1_load (object sender, system.eventargs e) {this.text = Application.ProductVersion.tostring (); try {upd = new zwt_svs.UpdatesVS (); string nver = upd.getver (); // software version No. in AssemblyInfo.cs (Application.ProductVersion.Compareto (NVER) <0) Update ();} catch (exception ex) {messagebox.show ("Anomaly:" ex. amount); Close (); Application.exit ();}}

}

Update Update.cs Code:

Namespace update {public class updateform: system.windows.Forms.form {// Automatically generated code slightly ... thread Tid;

PRIVATE VOID DOUPDATE () {process [] myprocesses;

Try {myprocesses = process.getProcessesbyName ("WindowsApplication2");

IF (MyProcesses.Length> 0) {foreach (process myprocess in myprocess) {myprocess.kill ();}}

XMLDocument Doc = New XmLDocument (); Doc.Load (Application.Startuppath @ "/ update.xml");

Xmlelement root = doc.documentelement; XMLNode Updatenode = root.selectsinglenode ("filelist");

String path = updatenode.attributes ["sourcepath"]. Value; int count = int.parse (INT "]. Value); for (int i = 0; i

System.Diagnostics.Process.start ("WindowsApplication2.exe"; Close ();

Application.exit (); Catch (Exception EX) {MessageBox.show ("Caught Exception ....:" ex. loading); close (); Application.exit ();}}

Private void form1_load (Object sender, system.eventargs e) {// new trip program update TID = New Thread (New Threadstart (this.doupdate)); TID.Start ();}

Private void button1_click (object sender, system.eventargs e) {tid.abort (); close (); Application.exit ();}}}

转载请注明原文地址:https://www.9cbs.com/read-20867.html

New Post(0)