private void SetViewControlsForDownload(ApplicationUpdateModel model)
 {
     downloadProgressLabel.Text  = $"Downloading {model.SelectedUpdateFile.Name}...";
     downloadButton.Enabled      = false;
     updateFilesComboBox.Visible = false;
     downloadProgressBar.Visible = true;
 }
        public async Task ApplicationUpdatePresenter_DownloadClicked_ShowsMessageBoxWhenDownloadFails()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var updateFile = new ApplicationUpdateFile {
                    Description = "Foo", Name = "Foo.zip", HttpAddress = @"C:\DoesNotExist\Foo.zip"
                };
                var update = new ApplicationUpdate
                {
                    UpdateFiles = new List <ApplicationUpdateFile> {
                        updateFile
                    }
                };
                var model = new ApplicationUpdateModel(update);
                model.SelectedUpdateFile = update.UpdateFiles.First();

                var messageBox = new MockMessageBoxPresenter();
                using (var presenter = new MockDialogApplicationUpdatePresenter(model, messageBox))
                {
                    presenter.ShowDialog(null);
                    Assert.IsTrue(presenter.MockDialog.Shown);
                    // Act
                    var saveFile = new MockFileDialogPresenterReturnsFileName(_ => DialogResult.OK, artifacts.GetRandomFilePath());
                    await presenter.DownloadClick(saveFile);

                    // Assert
                    Assert.AreEqual(1, messageBox.Invocations.Count);
                    Assert.IsTrue(presenter.MockDialog.Shown);
                    Assert.AreEqual(1, saveFile.Invocations.Count);
                }
            }
        }
        private void LoadData(ApplicationUpdateModel model)
        {
            captionLabel.Text     = $"A new version of {Core.Application.Name} is available for download.";
            thisVersionLabel.Text = $"This version: {Core.Application.FullVersion}";
            newVersionLabel.Text  = $"New version: {model.Update.Version}";

            model.PropertyChanged += ModelPropertyChanged;

            updateFilesComboBox.DataSource    = model.UpdateFilesList;
            updateFilesComboBox.DisplayMember = nameof(ListItem.DisplayMember);
            updateFilesComboBox.ValueMember   = nameof(ListItem.ValueMember);
            updateFilesComboBox.DataBindings.Add(SelectedValuePropertyName, model, nameof(ApplicationUpdateModel.SelectedUpdateFile), false, DataSourceUpdateMode.OnPropertyChanged);
        }
        void CheckForApplicationUpdate()
        {
            try
            {
                var uri       = new Uri(@"http://exvision.co.jp/egs/zkoo/ZkooSetupInformation_" + ApplicationCommonSettings.DefaultCultureInfoName + @".json");
                var appUpdate = new ApplicationUpdateModel(uri);
                if (appUpdate.CheckInformationFile() == false)
                {
                    return;
                }
                var installerOnWebVersion    = new Version(appUpdate.LatestInstallerInformation.Version);
                var isLatestVersionInstalled = installerOnWebVersion <= new Version(ApplicationCommonSettings.HostAppCoreDllAssemblyVersionMajorMinorBuildRevisionString);
#if DEBUG
                // MUSTDO: When you debug the application update, enable the next line.
                isLatestVersionInstalled = false;
#endif
                if (isLatestVersionInstalled)
                {
                    // NOTE: The latest version is installed.
                    var msg = string.Format(System.Globalization.CultureInfo.InvariantCulture, Resources.CommonStrings_Application0IsLatest, ApplicationCommonSettings.HostApplicationName);
                    MessageBox.Show(msg, ApplicationCommonSettings.HostApplicationName, MessageBoxButton.OK);
                }
                else
                {
                    // NOTE: A newer version exists.
                    var t = IsStartingHostApplicationUpdate; if (t != null)
                    {
                        t(this, EventArgs.Empty);
                    }
                    var msg = string.Format(System.Globalization.CultureInfo.InvariantCulture, Resources.CommonStrings_CanDownloadNewApplication0, ApplicationCommonSettings.HostApplicationName);
                    if (MessageBox.Show(msg, ApplicationCommonSettings.HostApplicationName, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                    {
                        var appUpdateProgressWindow = new ApplicationUpdateProgressWindow();
                        appUpdateProgressWindow.DataContext = appUpdate;
                        appUpdateProgressWindow.Closing    += (sender, e) => { appUpdate.DownloadWebClient.CancelAsync(); };
                        appUpdate.DownloadInstaller();
                        appUpdateProgressWindow.ShowDialog();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ApplicationCommonSettings.IsDebugging)
                {
                    Debugger.Break();
                }
                Console.WriteLine(ex.Message);
            }
        }
예제 #5
0
        public void UpdateApplication(ApplicationUpdateModel updateModel)
        {
            if (updateModel == null)
            {
                throw new ArgumentNullException(nameof(updateModel));
            }

            _dbContext.Applications.Update(
                _ => new Application
            {
                ParentId    = updateModel.ParentId,
                Name        = updateModel.Name,
                Description = updateModel.Description,
                Path        = updateModel.Path,
                Arguments   = updateModel.Arguments
            },
                x => x.Id == updateModel.Id);
        }
예제 #6
0
 private void CheckForAndFireUpdateProcess(ApplicationUpdateModel update)
 {
     if (update != null && update.SelectedUpdateFileIsReadyToBeExecuted)
     {
         string path = update.SelectedUpdateFileLocalFilePath;
         Logger.Info($"Firing update file '{path}'...");
         try
         {
             Process.Start(path);
         }
         catch (Exception ex)
         {
             Logger.Error(ex.Message, ex);
             string message = String.Format(CultureInfo.CurrentCulture,
                                            "Update process failed to start with the following error:{0}{0}{1}", Environment.NewLine, ex.Message);
             MessageBox.ShowError(Form, message, Core.Application.NameAndVersion);
         }
     }
 }
예제 #7
0
        private bool?CheckForUpdateInternal(IApplicationUpdateService service, ApplicationUpdatePresenterFactory presenterFactory)
        {
            if (!Monitor.TryEnter(_checkForUpdateLock))
            {
                return(null);
            }
            try
            {
                var uri    = new Uri(Properties.Settings.Default.UpdateUrl);
                var update = service.GetApplicationUpdate(uri);

                if (update is null)
                {
                    return(false);
                }
                if (!update.VersionIsGreaterThan(Core.Application.VersionNumber))
                {
                    return(false);
                }

                _applicationUpdateModel = new ApplicationUpdateModel(update);
                using (var presenter = presenterFactory.Create(_applicationUpdateModel))
                {
                    if (presenter.ShowDialog(Form) == DialogResult.OK)
                    {
                        if (_applicationUpdateModel.SelectedUpdateFileIsReadyToBeExecuted)
                        {
                            string text = String.Format(CultureInfo.CurrentCulture,
                                                        "{0} will install the new version when you exit the application.", Core.Application.Name);
                            MessageBox.ShowInformation(Form, text, Core.Application.NameAndVersion);
                        }
                    }
                }
                return(true);
            }
            finally
            {
                Monitor.Exit(_checkForUpdateLock);
            }
        }
예제 #8
0
 public virtual ApplicationUpdatePresenter Create(ApplicationUpdateModel model) => new ApplicationUpdatePresenter(model, Logger, Preferences, MessageBox);
 public MockDialogApplicationUpdatePresenter(ApplicationUpdateModel model, MessageBoxPresenter messageBox) : base(model, null, null, messageBox)
 {
 }
 public MockDialogApplicationUpdatePresenter(ApplicationUpdateModel model) : base(model, null, null, null)
 {
 }