コード例 #1
0
        private void SimulateUpgradeAvailable(
            ProductUpgrader.RingType remoteRing,
            string remoteVersion,
            ProductUpgrader.RingType localRing,
            bool expectedReturn,
            string expectedUpgradeVersion)
        {
            this.Upgrader.LocalRingConfig = localRing;
            this.Upgrader.PretendNewReleaseAvailableAtRemote(
                remoteVersion,
                remoteRing);

            Version newVersion;
            string  errorMessage;

            this.Upgrader.TryGetNewerVersion(out newVersion, out errorMessage).ShouldEqual(expectedReturn);

            if (string.IsNullOrEmpty(expectedUpgradeVersion))
            {
                newVersion.ShouldBeNull();
            }
            else
            {
                newVersion.ShouldNotBeNull();
                newVersion.ShouldEqual(new Version(expectedUpgradeVersion));
            }
        }
コード例 #2
0
        public void Execute()
        {
            string error = null;

            ProductUpgrader.RingType ring = ProductUpgrader.RingType.Invalid;
            string mountError             = null;

            if (!this.TryLoadUpgradeRing(out ring, out error))
            {
                this.output.WriteLine(GVFSConstants.UpgradeVerbMessages.InvalidRingConsoleAlert);
            }
            else if (ring == ProductUpgrader.RingType.None || ring == ProductUpgrader.RingType.NoConfig)
            {
                string message = ring == ProductUpgrader.RingType.None ?
                                 GVFSConstants.UpgradeVerbMessages.NoneRingConsoleAlert :
                                 GVFSConstants.UpgradeVerbMessages.NoRingConfigConsoleAlert;
                this.output.WriteLine(message);
                this.output.WriteLine(GVFSConstants.UpgradeVerbMessages.SetUpgradeRingCommand);
            }
            else
            {
                try
                {
                    Version newVersion = null;
                    if (!this.TryRunUpgrade(out newVersion, out error))
                    {
                        this.ExitCode = ReturnCode.GenericError;
                    }
                }
                finally
                {
                    if (!this.TryMountRepositories(out mountError))
                    {
                        mountError = Environment.NewLine + "WARNING: " + mountError;
                        this.output.WriteLine(mountError);
                    }

                    this.DeletedDownloadedAssets();
                }
            }

            if (this.ExitCode == ReturnCode.GenericError)
            {
                error = Environment.NewLine + "ERROR: " + error;
                this.output.WriteLine(error);
            }
            else
            {
                this.output.WriteLine($"{Environment.NewLine}Upgrade completed successfully{(string.IsNullOrEmpty(mountError) ? "." : ", but one or more repositories will need to be mounted manually.")}");
            }

            if (this.input == Console.In)
            {
                this.output.WriteLine("Press Enter to exit.");
                this.input.ReadLine();
            }

            Environment.ExitCode = (int)this.ExitCode;
        }
コード例 #3
0
ファイル: UpgradeVerb.cs プロジェクト: sanoursa/VFSForGit
        private bool TryLoadUpgradeRing(out ProductUpgrader.RingType ring, out string consoleError)
        {
            bool loaded = false;

            if (!this.upgrader.TryLoadRingConfig(out consoleError))
            {
                this.tracer.RelatedError($"{nameof(this.TryLoadUpgradeRing)} failed. {consoleError}");
            }
            else
            {
                consoleError = null;
                loaded       = true;
            }

            ring = this.upgrader.Ring;
            return(loaded);
        }
コード例 #4
0
        private bool TryLoadUpgradeRing(out ProductUpgrader.RingType ring, out string consoleError)
        {
            bool loaded = false;

            if (!this.upgrader.TryLoadRingConfig(out consoleError))
            {
                EventMetadata metadata = new EventMetadata();
                metadata.Add("Upgrade Step", nameof(this.TryLoadUpgradeRing));
                metadata.Add("Load Error", consoleError);
                this.tracer.RelatedError(metadata, $"{nameof(this.TryLoadUpgradeRing)} failed.");
                this.ExitCode = ReturnCode.GenericError;
            }
            else
            {
                consoleError = null;
                loaded       = true;
            }

            ring = this.upgrader.Ring;
            return(loaded);
        }
コード例 #5
0
ファイル: UpgradeVerb.cs プロジェクト: sanoursa/VFSForGit
        private bool TryRunProductUpgrade()
        {
            string  errorOutputFormat   = Environment.NewLine + "ERROR: {0}";
            string  error               = null;
            string  cannotInstallReason = null;
            Version newestVersion       = null;

            ProductUpgrader.RingType ring = ProductUpgrader.RingType.Invalid;

            bool isInstallable = this.TryCheckUpgradeInstallable(out cannotInstallReason);

            if (this.Confirmed && !isInstallable)
            {
                this.ReportInfoToConsole($"Cannot upgrade GVFS on this machine.");
                this.Output.WriteLine(errorOutputFormat, cannotInstallReason);
                this.tracer.RelatedError($"{nameof(this.TryRunProductUpgrade)}: Upgrade is not installable. {cannotInstallReason}");
                return(false);
            }

            if (!this.TryLoadUpgradeRing(out ring, out error))
            {
                this.tracer.RelatedError($"{nameof(this.TryRunProductUpgrade)}: Could not load upgrade ring. {error}");
                this.ReportInfoToConsole(GVFSConstants.UpgradeVerbMessages.InvalidRingConsoleAlert);
                this.Output.WriteLine(errorOutputFormat, error);
                return(false);
            }

            if (ring == ProductUpgrader.RingType.None || ring == ProductUpgrader.RingType.NoConfig)
            {
                this.tracer.RelatedInfo($"{nameof(this.TryRunProductUpgrade)}: {GVFSConstants.UpgradeVerbMessages.NoneRingConsoleAlert}");
                this.ReportInfoToConsole(ring == ProductUpgrader.RingType.None ? GVFSConstants.UpgradeVerbMessages.NoneRingConsoleAlert : GVFSConstants.UpgradeVerbMessages.NoRingConfigConsoleAlert);
                this.ReportInfoToConsole(GVFSConstants.UpgradeVerbMessages.SetUpgradeRingCommand);
                return(true);
            }

            if (!this.TryRunUpgradeChecks(out newestVersion, out error))
            {
                this.Output.WriteLine(errorOutputFormat, error);
                this.tracer.RelatedError($"{nameof(this.TryRunProductUpgrade)}: Upgrade checks failed. {error}");
                return(false);
            }

            if (newestVersion == null)
            {
                this.ReportInfoToConsole($"Great news, you're all caught up on upgrades in the {this.upgrader.Ring} ring!");
                return(true);
            }

            string upgradeAvailableMessage = $"New GVFS version {newestVersion.ToString()} available in ring {ring}";

            if (this.Confirmed)
            {
                this.ReportInfoToConsole(upgradeAvailableMessage);

                if (!isInstallable)
                {
                    this.tracer.RelatedError($"{nameof(this.TryRunProductUpgrade)}: {error}");
                    this.Output.WriteLine(errorOutputFormat, error);
                    return(false);
                }

                if (!this.TryRunInstaller(out error))
                {
                    this.tracer.RelatedError($"{nameof(this.TryRunProductUpgrade)}: Could not launch upgrade tool. {error}");
                    this.Output.WriteLine(errorOutputFormat, "Could not launch upgrade tool. " + error);
                    return(false);
                }
            }
            else
            {
                string message = string.Join(
                    Environment.NewLine,
                    GVFSConstants.UpgradeVerbMessages.UnmountRepoWarning,
                    GVFSConstants.UpgradeVerbMessages.UpgradeInstallAdvice);
                this.ReportInfoToConsole(upgradeAvailableMessage + Environment.NewLine + Environment.NewLine + message + Environment.NewLine);
            }

            return(true);
        }