Exemplo n.º 1
0
        protected override async Task <int> ExecuteAsync(UpdateCliCommandArgs args, ChangeObservable observable)
        {
            string startMessage = string.IsNullOrEmpty(args.File)
                                      ? (args.Version != null
                                             ? $"Updating to version {args.Version}"
                                             : "Updating to newest version")
                                      : $"Updating using the file {args.File}";

            using (IProgressNotifier progressNotifier = progressVisualizer.Spawn(2, startMessage, "Completed update"))
            {
                VirtualFile      download;
                VirtualDirectory directory = fileSystem.GetTemporaryDirectory();
                observable.OnNext(new Change(() => {}, $"Create temporary folder {directory.FullName}"));
                if (string.IsNullOrEmpty(args.File))
                {
                    if (await cliUpdater.IsCurrentVersion(args.Version, args.Proxy).ConfigureAwait(false))
                    {
                        directory.Delete();
                        userInterface.WriteInformation("Version is up-to-date.");
                        return(0);
                    }

                    download = await cliUpdater.DownloadVersion(args.Version, directory, progressNotifier, args.Proxy).ConfigureAwait(false);
                }
                else
                {
                    progressNotifier.TickIncrement();
                    if (!fileSystem.FileExists(args.File))
                    {
                        throw new FormattableException($"The file {args.File} does not exist.");
                    }
                    download = fileSystem.GetFile(args.File);
                }

                await cliUpdater.InstallVersion(download, directory, progressNotifier).ConfigureAwait(false);
            }

            return(0);
        }
Exemplo n.º 2
0
        public async Task InstallSdk(VirtualFile packedSdk, VirtualDirectory destination, ChangeObservable observable,
                                     bool force)
        {
            using (IEditableSettings editableSettings = settingsProvider.StartSettingTransaction())
            {
                if (!force && destination.Files(searchRecursive: true).Any())
                {
                    throw new FileExistsException(destination.FullName);
                }

                if (force)
                {
                    destination.Clear();
                    observable.OnNext(new Change(destination.UnClear, "Cleared destination directory."));
                }

                using (IProgressNotifier progressNotifier = Console.IsInputRedirected || Console.IsOutputRedirected ? null : progressVisualizer.Spawn(1, "Install SDK.", null))
                {
                    await fileUnpackService.Unpack(packedSdk, destination, progressNotifier, observable).ConfigureAwait(false);
                }

                editableSettings.AddSetting(Constants.SdkPathsKey, $"{destination.FullName}");
            }
        }