• OOS升级服务


    给我们的应用程序做个版本更新服务,展示一个安装程序如何实现自动更新.

      //服务组,添加需要的任何服务
        public enum ServerEnum
        {
            AutoupdateService,//自动升级
            AutoBack,//自动备份
            AutoLog//日志服务
            
    
        }
        //服务控制器
       public class ServerController
        {
           public void RunServer(ServerEnum ser)
           {
               switch (ser)
               {
                   case ServerEnum.AutoupdateService:
                       AutoupdateService auds = new AutoupdateService();
                       auds.Run();
                       break;
                   case ServerEnum.AutoBack:
                       break;
                   case ServerEnum.AutoLog:
                       break;
                   default:
                       break;
               }
           }
           
        }

    创建一个升级服务

       //升级服务
      public  class AutoupdateService
        {
          //建立多线程
          private System.Threading.Thread td;
          private System.Threading.ThreadStart ts;
    
    
          public void Run()
          { 
              ts = new System.Threading.ThreadStart(this.GetServerXml);
              td = new System.Threading.Thread(ts);
              td.Priority = System.Threading.ThreadPriority.Lowest;
              td.Name = "AutoupdateService";
              td.Start();
              Console.WriteLine("自动服务升级程序在运行");
            
          }
    
    
          //
          public void GetServerXml()
          {
              System.Net.WebClient wc = new System.Net.WebClient();
              //从远程地址下载版本信息
              wc.DownloadFile("http://files.cnblogs.com/BABLOVE/Appxml.xml", @"c:Appxml.xml");
              //解析xml文件,获取地址和版本
              System.Data.DataSet ds = new System.Data.DataSet();
              ds.ReadXml(@"c:Appxml.xml");
              System.Data.DataTable dt = ds.Tables[0];
              string ver = dt.Rows[0]["version"].ToString();
              string url = dt.Rows[0]["url"].ToString();
    
              //版本对比
              if (System.Windows.Forms.Application.ProductVersion != ver)
              {
                  Uri uri = new Uri(url);
                  wc.DownloadFile(new Uri(url), @"c:" + uri.Segments[uri.Segments.Length - 1].ToString());
                  System.Windows.Forms.DialogResult dr = System.Windows.Forms.MessageBox.Show("应用程序已经更新,是否进行安装?", "提示", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Information);
    
                  if (dr == System.Windows.Forms.DialogResult.Yes)
                  {
                      System.Diagnostics.Process.Start(@"c:" + uri.Segments[uri.Segments.Length - 1].ToString());
                      System.Windows.Forms.Application.DoEvents();
                      System.Threading.Thread.Sleep(10000);
                      System.Windows.Forms.Application.Exit();
                  }
              }
    
          }
        }

    然后是进行服务启动

      /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
    
                
                //启动服务组
                Service.ServerController sc = new Service.ServerController();
                sc.RunServer(Service.ServerEnum.AutoupdateService);
    
                //下面的服务没实现
                sc.RunServer(Service.ServerEnum.AutoBack);
                sc.RunServer(Service.ServerEnum.AutoLog);
    
    
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }

    我们可以添加我们想得任何服务,给我们的安装程序实现更新,我们也可以通过做一个漂亮的壳程序做为引导向,来完成整个过程的升级!

    demo:http://files.cnblogs.com/BABLOVE/OOS%E5%8D%87%E7%BA%A7%E6%9C%8D%E5%8A%A1.rar

  • 相关阅读:
    [考试反思]0511省选模拟93:平衡
    [考试反思]0509省选模拟92:警示
    [考试反思]0508省选模拟91:小雨
    [考试反思]0507省选模拟90:信任
    [考试反思]0506省选模拟89:无事
    [专题总结]2-sat及题目&题解(3/5 complete)
    [考试反思]0505省选模拟88:滑稽
    [考试反思]0504省选模拟87:开花
    [考试反思]0502省选模拟86:恐惧
    [考试反思]0501省选模拟85:低落
  • 原文地址:https://www.cnblogs.com/BABLOVE/p/3308312.html
Copyright © 2020-2023  润新知