static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            #region check and download new version program
            bool bHasError = false;
            IAutoUpdater autoUpdater = new AutoUpdater();
            try
            {
                autoUpdater.Update();
            }
            catch (WebException exp)
            {
                MessageBox.Show(String.Format("无法找到指定资源\n\n{0}", exp.Message), "自动升级", MessageBoxButtons.OK, MessageBoxIcon.Error);
                bHasError = true;
            }
            catch (XmlException exp)
            {
                bHasError = true;
                MessageBox.Show(String.Format("下载的升级文件有错误\n\n{0}", exp.Message), "自动升级", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (NotSupportedException exp)
            {
                bHasError = true;
                MessageBox.Show(String.Format("升级地址配置错误\n\n{0}", exp.Message), "自动升级", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (ArgumentException exp)
            {
                bHasError = true;
                MessageBox.Show(String.Format("下载的升级文件有错误\n\n{0}", exp.Message), "自动升级", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception exp)
            {
                bHasError = true;
                MessageBox.Show(String.Format("升级过程中发生错误\n\n{0}", exp.Message), "自动升级", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (bHasError == true)
                {
                    try
                    {
                        autoUpdater.RollBack();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("异常:"+ex.Message);
                        //Log the message to your file or database
                    }
                }
            }
            #endregion

            OperProcess op = new OperProcess();
            //启动进程
            op.StartProcess();
            
        }
Пример #2
0
 void InitCheckUpdate()
 {
     #region check and download new version program
     bool         bHasError   = false;
     IAutoUpdater autoUpdater = new KnightsWarriorAutoupdater.AutoUpdater();
     try
     {
         autoUpdater.Update();
     }
     catch (WebException exp)
     {
         MessageBox.Show("服务器连接失败");
         bHasError = true;
     }
     catch (XmlException exp)
     {
         bHasError = true;
         MessageBox.Show("下载更新文件错误");
     }
     catch (NotSupportedException exp)
     {
         bHasError = true;
         MessageBox.Show("升级文件配置错误");
     }
     catch (ArgumentException exp)
     {
         bHasError = true;
         MessageBox.Show("下载升级文件错误");
     }
     catch (Exception exp)
     {
         bHasError = true;
         MessageBox.Show("更新过程中出现错误");
     }
     finally
     {
         if (bHasError == true)
         {
             try
             {
                 autoUpdater.RollBack();
             }
             catch (Exception)
             {
                 //Log the message to your file or database
             }
         }
         OperProcess op = new OperProcess();
         //启动进程
         op.StartProcess();
         //  this.Close();
     }
     #endregion
 }
 public static void AutoUpdater()
 {
     #region check and download new version program
     bool bHasError = false;
     IAutoUpdater autoUpdater = new AutoUpdater();
     try
     {
         autoUpdater.Update();
     }
     catch (WebException exp)
     {
         MessageBox.Show("Can not find the specified resource");
         bHasError = true;
     }
     catch (XmlException exp)
     {
         bHasError = true;
         MessageBox.Show("Download the upgrade file error");
     }
     catch (NotSupportedException exp)
     {
         bHasError = true;
         MessageBox.Show("Upgrade address configuration error");
     }
     catch (ArgumentException exp)
     {
         bHasError = true;
         MessageBox.Show("Download the upgrade file error");
     }
     catch (Exception exp)
     {
         bHasError = true;
         MessageBox.Show("An error occurred during the upgrade process");
     }
     finally
     {
         if (bHasError == true)
         {
             try
             {
                 autoUpdater.RollBack();
             }
             catch (Exception)
             {
                 //Log the message to your file or database
             }
         }
     }
     #endregion
 }
Пример #4
0
 public void StartUpdate()
 {
     #region check and download new version program
     bool         bHasError   = false;
     IAutoUpdater autoUpdater = new KnightsWarriorAutoupdater.AutoUpdater();
     try
     {
         autoUpdater.CheckUpdates(
             (UpdateInfo info) =>
         {
             if (info.hasUpdate)
             {
                 if (MessageBox.Show("Найдены обновления:\r\n\r\n" + info.updateInfo + "\r\nОбновить? \r\nЗамененные файлы Информатора будут скопированы в папку AppBackup", "Система обновления Информатора СИ", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                 {
                     DownloadingInfo di = new DownloadingInfo();
                     autoUpdater        = new KnightsWarriorAutoupdater.AutoUpdater();// обнулим все внутренние объекты
                     autoUpdater.Update(di);
                 }
             }
         }
             );
     }
     catch (WebException exp)
     {
         MessageBox.Show("Can not find the specified resource");
         bHasError = true;
     }
     catch (XmlException exp)
     {
         bHasError = true;
         MessageBox.Show("Download the upgrade file error");
     }
     catch (NotSupportedException exp)
     {
         bHasError = true;
         MessageBox.Show("Upgrade address configuration error");
     }
     catch (ArgumentException exp)
     {
         bHasError = true;
         MessageBox.Show("Download the upgrade file error");
     }
     catch (Exception exp)
     {
         bHasError = true;
         MessageBox.Show("An error occurred during the upgrade process");
     }
     finally
     {
         if (bHasError == true)
         {
             try
             {
                 autoUpdater.RollBack();
             }
             catch (Exception)
             {
                 //Log the message to your file or database
             }
         }
     }
     #endregion
 }
Пример #5
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Process[] pary = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
            if (pary.Length > 1)
            {
                
                MessageBox.Show("已经有相同的程序在运行,请关闭已经打开的程序!");
                Application.Exit();
                return;
            }


            #region check and download new version program
            bool bHasError = false;
            IAutoUpdater autoUpdater = new AutoUpdater();
            try
            {
                autoUpdater.Update();
            }
            catch (WebException exp)
            {
                MessageBox.Show("Can not find the specified resource");
                bHasError = true;
            }
            catch (XmlException exp)
            {
                bHasError = true;
                MessageBox.Show("Download the upgrade file error");
            }
            catch (NotSupportedException exp)
            {
                bHasError = true;
                MessageBox.Show("Upgrade address configuration error");
            }
            catch (ArgumentException exp)
            {
                bHasError = true;
                MessageBox.Show("Download the upgrade file error");
            }
            catch (Exception exp)
            {
                bHasError = true;
                MessageBox.Show("An error occurred during the upgrade process");
            }
            finally
            {
                if (bHasError == true)
                {
                    try
                    {
                        autoUpdater.RollBack();
                    }
                    catch (Exception)
                    {
                        //Log the message to your file or database
                    }
                }
            }
            #endregion

            bool isNewVersion = true ;
            if (isNewVersion)
            {

                frmLogin fLogin = new frmLogin();
                fLogin.ShowDialog();
                if (fLogin.DialogResult != DialogResult.OK)
                    return;


                frmMain frmMain = new ChinaUnion_Agent.frmMain();
                frmMain.isNewVersion = isNewVersion;
                frmMain.menuTable = fLogin.menuTable;
                frmMain.loginUser = fLogin.loginUser;
                Application.Run(frmMain);
            }
            else
            {
                Application.Run(new frmMain());
            }
        }