乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      C# 程序自動(dòng)升級(jí)的代碼,C#代碼片段分享,

       悟靜 2014-04-26

      自動(dòng)更新的軟件的目的在于讓客戶不在為了尋找最新軟件花費(fèi)時(shí)間。也不用去到開發(fā)商的網(wǎng)站上查找。客戶端的軟件自動(dòng)會(huì)在程序啟動(dòng)前查找服務(wù)器上最新的版本。和自己當(dāng)前軟件的版本比較,如果服務(wù)器的是最新版本??蛻舳藙t進(jìn)行自動(dòng)下載、解壓、安裝。當(dāng)然了下載是要有網(wǎng)絡(luò)的,并且用戶可以根據(jù)提示去完成操作。再也不用為找不到最新版本的軟件而頭疼。
      轉(zhuǎn)自:http://blog.csdn.net/lybwwp/article/details/8426022

      下面是我的大體思路,已經(jīng)得到了實(shí)現(xiàn): 1、  寫一個(gè)webservice,提供一個(gè)獲取服務(wù)器xml中版本的數(shù)據(jù)的方法。|
      <?xml version="1.0" encoding="utf-8" ?>
      <Content>
        <Project id="程序名稱" Edition="1.0"> </Project>
      </Content>
      2、  在WinForm應(yīng)用程序啟動(dòng)的時(shí)候,首先訪問webservice獲取服務(wù)器的xml中的版本號(hào),然后獲取客戶端的xml中的版本號(hào)。將兩個(gè)版本號(hào)比較,若服務(wù)器中的版本號(hào)大,則提示提示可以在線更新應(yīng)用程序。

      3、  然后客戶端自動(dòng)下載網(wǎng)絡(luò)上的zip壓縮包到本機(jī)的指定位置,進(jìn)行自動(dòng)解壓縮到安裝的目錄進(jìn)行覆蓋。解壓縮完畢之后,用進(jìn)程打開所解壓過(guò)的exe文件進(jìn)行軟件安裝。同時(shí)關(guān)閉客戶端軟件所在的進(jìn)程。

      4、注意:升級(jí)程序和應(yīng)用程序都是單獨(dú)的,應(yīng)用程序在使用時(shí)不能對(duì)本身進(jìn)行升級(jí)(覆蓋會(huì)失?。?br>
      具體代碼如下:

      第一部分 應(yīng)用程序如口Program:
      using System;
      using System.Collections.Generic;
      using System.Windows.Forms;
      using Medicine_ERP;
      using DevExpress.XtraEditors;
      using System.Xml;
      using Anshield_AutoFutures.BaseClase;
       
      namespace Anshield_AutoFutures
      {
          static class Program
          {
              private static void LoadMath()
              {
                  //服務(wù)器上的版本號(hào)
                  string NewEdition = "1.0";
                  //應(yīng)用程序中的版本號(hào)
                  string OldEdition = "1.0";
       
                  try
                  {
                      //服務(wù)器上的版本號(hào)
                      NewEdition = webserverClase.getCopyRightCode();
       
                      //獲取系統(tǒng)中xml里面存儲(chǔ)的版本號(hào)              
                      String fileName = Application.StartupPath + "\\XMLEdition.xml";
                      XmlDocument xmlDoc = new XmlDocument();
                      xmlDoc.Load(fileName);
                      XmlNode xn = xmlDoc.SelectSingleNode("Content");
                      XmlNodeList xnl = xn.ChildNodes;
                      foreach (XmlNode xnf in xnl)
                      {
                          XmlElement xe = (XmlElement)xnf;
                          if (xe.GetAttribute("id") == "jigou_plz")
                          {
                              OldEdition = xe.GetAttribute("Edition");//動(dòng)態(tài)數(shù)組
                          }
                          break;
                      }
                      double newE = double.Parse(NewEdition);
                      double oldE = double.Parse(OldEdition);
                      //比較兩個(gè)版本號(hào),判斷應(yīng)用程序是否要更新
                      if (newE > oldE)
                      {
                          //更新程序¨
                          DialogResult dr = XtraMessageBox.Show("發(fā)現(xiàn)新的版本是否要更新該軟件", "平浪舟現(xiàn)貨程序化交易--更新提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                          if (dr == DialogResult.OK)
                          {
                              //打開下載窗口
                              // Application.Run(new DownUpdate());
       
                              //啟動(dòng)安裝程序                       
                              System.Diagnostics.Process.Start(Application.StartupPath + @"\Upgrade_Form.exe");
       
                              Application.Exit();
                          }
                          else
                          {
                              //若用戶取消,打開初始界面
                              anshield_Login login = new anshield_Login();
                              if (login.ShowDialog() == DialogResult.OK)
                              {
                                  Application.Run(new Main_AutoFutures());
                              }
                          }
                      }
                      else
                      {
                          //若服務(wù)器版本低于或相等客戶端,打開初始界面
                          anshield_Login login = new anshield_Login();
                          if (login.ShowDialog() == DialogResult.OK)
                          {
                              Application.Run(new Main_AutoFutures());
                          }
                      }
                  }
                  catch
                  {
                      XtraMessageBox.Show("網(wǎng)絡(luò)鏈接失??!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
       
                  }
              }
       
             
              /// <summary>
              /// 應(yīng)用程序的主入口點(diǎn)。
              /// </summary>
              [STAThread]
              static void Main()
              {
                   
                  //保證同時(shí)只有一個(gè)客戶端在運(yùn)行  
                  System.Threading.Mutex mutexMyapplication = new System.Threading.Mutex(false, "jigou_plz.exe");
                  if (!mutexMyapplication.WaitOne(100, false))
                  {
                      XtraMessageBox.Show("程序" + Application.ProductName + "已經(jīng)在運(yùn)行!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);             
                      return;
                  }
                  else
                  {
                      Application.EnableVisualStyles();
                      Application.SetCompatibleTextRenderingDefault(false);
                      //漢化
                      hugengyong hu = new hugengyong();              
                      DevExpress.UserSkins.OfficeSkins.Register();
                      DevExpress.Skins.SkinManager.EnableFormSkins();
                      DevExpress.UserSkins.BonusSkins.Register();
       
                      LoadMath();
                      }
              }
          }
      }
        
       
        
       
       
      //該代碼片段來(lái)自于: http://www./codes/csharp/6043
       第二部分:升級(jí)程序代碼如下:
        //debug目錄,用于存放壓縮文件
              string path = Application.StartupPath;
       
       private void btnDown_Click(object sender, EventArgs e)
              {
                  string zipFile = path + @"\jigou_plz.zip";
                  //關(guān)閉原有的應(yīng)用程序 
                  killProess();
                   
                  btnDown.Enabled = false;
                  button2.Enabled = false;
                  //自動(dòng)下載壓縮包,并且解壓,最后關(guān)閉當(dāng)前進(jìn)程,進(jìn)行安裝
                  try
                  {
                      //下載自動(dòng)更新
                      string downUrl = ConfigurationManager.ConnectionStrings["DownUrl"].ConnectionString.ToString().Trim();
                      if (!string.IsNullOrEmpty(downUrl))
                      {
                          DownloadFile(downUrl, zipFile, progressBar1, label1);
                      }
                      else
                      {
                          MessageBox.Show("Config中的下載路徑配置錯(cuò)誤!", "錯(cuò)誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                          return;
                      }
                  }
                  catch
                  {
                      MessageBox.Show("當(dāng)前沒有網(wǎng)絡(luò)或者文件地址不正確");
                      return;
                  }         
                  //解a壓1
                  try
                  {
                      //關(guān)閉原有的應(yīng)用程序 
                      killProess();
                      //unCompressRAR(path, path, "setup.rar", true);
                      BaseClase.Zip.UnZip(zipFile, path, "", true,true);
                      
                  }
                  catch (Exception ex)
                  {
                      MessageBox.Show(ex.Message);
                      return;
                  }
                  if (MessageBox.Show("升級(jí)完成!,請(qǐng)重新登陸!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                  {
                      FileInfo file = new FileInfo(path + @"\Anshield_AutoFutures.exe");//文件地址
                      if (file.Exists)
                      {
                          Process.Start(path + @"\Anshield_AutoFutures.exe");
                      }            
                      Application.Exit();
                  }
                  
              }
              /// <summary>       
              /// c#.net 下載文件       
              /// </summary>       
              /// <param name="URL">下載文件地址</param>      
              ///
              /// <param name="Filename">下載后的存放地址</param>       
              /// <param name="Prog">用于顯示的進(jìn)度條</param>       
              ///
              public void DownloadFile(string URL, string filename, System.Windows.Forms.ProgressBar prog, System.Windows.Forms.Label label1)
              {
                  float percent = 0;
                  try
                  {
                      System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
                      System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse();
                      long totalBytes = myrp.ContentLength;
                      if (prog != null)
                      {
                          prog.Maximum = (int)totalBytes;
                      }
                      System.IO.Stream st = myrp.GetResponseStream();
                      System.IO.Stream so = new System.IO.FileStream(filename, System.IO.FileMode.Create);
                      long totalDownloadedByte = 0;
                      byte[] by = new byte[1024];
                      int osize = st.Read(by, 0, (int)by.Length);
                      while (osize > 0)
                      {
                          totalDownloadedByte = osize + totalDownloadedByte;
                          System.Windows.Forms.Application.DoEvents();
                          so.Write(by, 0, osize);
                          if (prog != null)
                          {
                              prog.Value = (int)totalDownloadedByte;
                          }
                          osize = st.Read(by, 0, (int)by.Length);
       
                          percent = (float)totalDownloadedByte / (float)totalBytes * 100;
                          label1.Text = "下載進(jìn)度" + percent.ToString() + "%";
                          System.Windows.Forms.Application.DoEvents(); //必須加注這句代碼,否則label1將因?yàn)檠h(huán)執(zhí)行太快而來(lái)不及顯示信息
                      }
                      label1.Text = "下載完成。安裝中... ...";
                      so.Flush();//將緩沖區(qū)內(nèi)在寫入到基礎(chǔ)流中
                      st.Flush();//將緩沖區(qū)內(nèi)在寫入到基礎(chǔ)流中
                      so.Close();
                      st.Close();
                  }
                  catch (System.Exception)
                  {
                      throw;
                  }
              }
       
        
       
       /// <summary>
              /// 關(guān)閉原有的應(yīng)用程序
              /// </summary>
              private void killProess()
              {
                  this.label1.Text = "正在關(guān)閉程序....";
                  System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcessesByName("Anshield_AutoFutures");
                  //關(guān)閉原有應(yīng)用程序的所有進(jìn)程
                  foreach (System.Diagnostics.Process pro in proc)
                  {
                      pro.Kill();
                  }
              }
       
        
       
       
      //該代碼片段來(lái)自于: http://www./codes/csharp/6043
      zip壓縮文件解壓方法類
      using System;
      using System.Collections.Generic;
      using System.Text;
      using System.IO;
      using System.IO.Compression;
      using ICSharpCode.SharpZipLib.Zip;
       
      namespace Upgrade_Form.BaseClase
      {
          class Zip
          {
            
              /// <summary>
              /// 解壓縮一個(gè) zip 文件。
              /// </summary>
              /// <param name="zipedFile">zip文件路徑</param>
              /// <param name="strDirectory">解壓路徑</param>
              /// <param name="password">zip文件的密碼</param>
              /// <param name="overWrite">是否覆蓋已存在的文件。</param>
              /// <param name="delteFile">解壓后是否刪除文件</param>
              public static void UnZip(string zipedFile, string strDirectory, string password, bool overWrite,bool delteFile)
              {
                  //路徑不存在則創(chuàng)建
                  if (Directory.Exists(strDirectory) == false)
                  {
                      Directory.CreateDirectory(strDirectory);
                  }
                  if (strDirectory == "")
                      strDirectory = Directory.GetCurrentDirectory();
                  if (!strDirectory.EndsWith("\\"))
                      strDirectory = strDirectory + "\\";
       
                  using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipedFile)))
                  {
                      s.Password = password;
                      ZipEntry theEntry;
       
                      while ((theEntry = s.GetNextEntry()) != null)
                      {
                          string directoryName = "";
                          string pathToZip = "";
                          pathToZip = theEntry.Name;
       
                          if (pathToZip != "")
                              directoryName = Path.GetDirectoryName(pathToZip) + "\\";
       
                          string fileName = Path.GetFileName(pathToZip);
       
                          Directory.CreateDirectory(strDirectory + directoryName);
       
                          if (fileName != "")
                          {
                              if ((File.Exists(strDirectory + directoryName + fileName) && overWrite) || (!File.Exists(strDirectory + directoryName + fileName)))
                              {
                                  using (FileStream streamWriter = File.Create(strDirectory + directoryName + fileName))
                                  {
                                      int size = 2048;
                                      byte[] data = new byte[2048];
                                      while (true)
                                      {
                                          size = s.Read(data, 0, data.Length);
       
                                          if (size > 0)
                                              streamWriter.Write(data, 0, size);
                                          else
                                              break;
                                      }
                                      streamWriter.Close();
                                  }
                              }
                          }
                      }
       
                      s.Close();
                  }
                  if (delteFile == true)
                  {
                      File.Delete(zipedFile);
                  }
              }
       
          }
      }
      //該代碼片段來(lái)自于: http://www./codes/csharp/6043

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約