Example #1
0
        public async Task HandleUpdates(UpdatePromptingModes confirmationMode, IReadOnlyList <UpdatePackageData> packagesToInstall, UpdatePackageData updaterUpdate)
        {
            try
            {
                if (packagesToInstall != null && packagesToInstall.Any())
                {
                    var shouldInstallNow = await this.DownloadUpdatesIfNeeded(confirmationMode, packagesToInstall, updaterUpdate).ConfigureAwait(false);

                    if (!shouldInstallNow.Item1)
                    {
                        return;
                    }

                    FileInfo instructionsFile = UpdateInstructionCreator.CreateInstructionsFile(packagesToInstall, this.programInfo.Program, this.programInfo.Program.Name);
                    foreach (UpdatePackageData item in packagesToInstall)
                    {
                        this.telemetryModule.Event(BuiltInEventKeys.UpdateInstallation, properties: new Dictionary <string, string>()
                        {
                            { "PackageVersion", item.Version },
                            { "FromVersionAssembly", this.programInfo.Program.PrimaryAssembly.VersionData.AssemblyVersion },
                            { "FromVersionFile", this.programInfo.Program.PrimaryAssembly.VersionData.FileVersion },
                        });
                    }
                    this.telemetryModule.SendAllDataNow();
                    this.updateInstaller.InstallUpdates(instructionsFile, shouldInstallNow.Item2);
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException($"An error occured while handling updates", ex);
            }
        }
Example #2
0
        private async Task <Tuple <bool, FileInfo> > DownloadUpdatesIfNeeded(UpdatePromptingModes confirmationMode, IReadOnlyList <UpdatePackageData> packagesToInstall
                                                                             , UpdatePackageData updaterUpdate)
        {
            string maxVersion = packagesToInstall.GetMaxVersion();

            bool     installUpdatesNow;
            FileInfo updaterFile = null;

            switch (confirmationMode)
            {
            case UpdatePromptingModes.PromptAfterDownload:
                updaterFile = await this.InstallUpdater(updaterUpdate).ConfigureAwait(false);

                await this.DownloadUpdatePackages(packagesToInstall).ConfigureAwait(false);

                installUpdatesNow = this.inputReceiver.ShowInstallUpdatesNowQuestion(maxVersion, packagesToInstall.Sum(x => x.FileSizeBytes), this.programInfo);
                return(new Tuple <bool, FileInfo>(installUpdatesNow, updaterFile));

            case UpdatePromptingModes.PromptBeforeDownload:
                installUpdatesNow = this.inputReceiver.ShowDownloadAndInstallUpdatesQuestion(maxVersion, packagesToInstall.Sum(x => x.FileSizeBytes), this.programInfo);
                break;

            case UpdatePromptingModes.DontPrompt:
                installUpdatesNow = true;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(confirmationMode), confirmationMode, null);
            }

            if (installUpdatesNow)
            {
                updaterFile = await this.InstallUpdater(updaterUpdate).ConfigureAwait(false);

                await this.DownloadUpdatePackages(packagesToInstall).ConfigureAwait(false);
            }

            return(new Tuple <bool, FileInfo>(installUpdatesNow, updaterFile));
        }
Example #3
0
        public async Task HandleUpdates(UpdatePromptingModes confirmationMode, IReadOnlyList <UpdatePackageData> packagesToInstall, UpdatePackageData updaterUpdate)
        {
            try
            {
                if (packagesToInstall != null && packagesToInstall.Any())
                {
                    var shouldInstallNow = await this.DownloadUpdatesIfNeeded(confirmationMode, packagesToInstall, updaterUpdate).ConfigureAwait(false);

                    if (!shouldInstallNow.Item1)
                    {
                        return;
                    }

                    FileInfo instructionsFile = UpdateInstructionCreator.CreateInstructionsFile(packagesToInstall, this.programInfo.Program, this.programInfo.Program.Name);

                    this.updateInstaller.InstallUpdates(instructionsFile, shouldInstallNow.Item2);
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException($"An error occured while handling updates", ex);
            }
        }