Пример #1
0
        static void ThreadWorks(UpdaterFlags flags)
        {
            string checkVersion = String.Empty, checkResult = String.Empty;
            bool   showAnyway     = FlagsHelper.IsSet(flags, UpdaterFlags.ShowAnyway);
            bool   updateRequired = FlagsHelper.IsSet(flags, UpdaterFlags.UpdateRequired);
            bool   isMainThread   = !FlagsHelper.IsSet(flags, UpdaterFlags.StartInThread);
            Uri    address        = new Uri("http://saas.qsolution.ru:2048/Updater");

            try {
                logger.Info("Получаем данные от сервера");
                string parameters = String.Format("product.{0};edition.{1};serial.{2};major.{3};minor.{4};build.{5};revision.{6}",
                                                  MainSupport.ProjectVerion.Product,
                                                  MainSupport.ProjectVerion.Edition,
                                                  MainSupport.BaseParameters.SerialNumber,
                                                  MainSupport.ProjectVerion.Version.Major,
                                                  MainSupport.ProjectVerion.Version.Minor,
                                                  MainSupport.ProjectVerion.Version.Build,
                                                  MainSupport.ProjectVerion.Version.Revision);
                IUpdateService service = new WebChannelFactory <IUpdateService> (new WebHttpBinding {
                    AllowCookies = true
                }, address)
                                         .CreateChannel();
                updateResult = service.checkForUpdate(parameters);
                if (MachineConfig.ConfigSource.Configs ["Updater"] != null)
                {
                    checkVersion = MachineConfig.ConfigSource.Configs ["Updater"].Get("NewVersion", String.Empty);
                    checkResult  = MachineConfig.ConfigSource.Configs ["Updater"].Get("Check", String.Empty);
                }
                if (showAnyway || (updateResult.HasUpdate &&
                                   (checkResult == "True" || checkResult == String.Empty || checkVersion != updateResult.NewVersion)))
                {
                    if (isMainThread)
                    {
                        ShowDialog(updateRequired);
                    }
                    else
                    {
                        Application.Invoke(delegate {
                            ShowDialog(updateRequired);
                        });
                    }
                }
            } catch (Exception ex) {
                logger.Error(ex, "Ошибка доступа к серверу обновления.");
                if (showAnyway)
                {
                    ShowErrorDialog("Не удалось подключиться к серверу обновлений.\nПожалуйста, повторите попытку позже.");
                }
                if (updateRequired)
                {
                    Environment.Exit(1);
                }
            }
        }
Пример #2
0
 static public void StartCheckUpdateThread(UpdaterFlags flags)
 {
     if (FlagsHelper.IsSet(flags, UpdaterFlags.StartInThread))
     {
         Thread loadThread = new Thread(() => ThreadWorks(flags));
         loadThread.Start();
         if (FlagsHelper.IsSet(flags, UpdaterFlags.UpdateRequired))
         {
             loadThread.Join();
         }
     }
     else
     {
         ThreadWorks(flags);
     }
 }