Exemplo n.º 1
0
 public WindowsUpgradeOrchestrator(
     ProductUpgrader upgrader,
     ITracer tracer,
     PhysicalFileSystem fileSystem,
     InstallerPreRunChecker preRunChecker,
     TextReader input,
     TextWriter output)
     : base(upgrader, tracer, fileSystem, preRunChecker, input, output)
 {
 }
        public UpgradeOrchestrator()
        {
            // CommandLine's Parser will create multiple instances of UpgradeOrchestrator, and we don't want
            // multiple log files to get created.  Defer tracer (and preRunChecker) creation until Execute()
            this.tracer        = null;
            this.preRunChecker = null;

            this.fileSystem     = new PhysicalFileSystem();
            this.output         = Console.Out;
            this.input          = Console.In;
            this.mount          = false;
            this.ExitCode       = ReturnCode.Success;
            this.installationId = DateTime.Now.ToString("yyyyMMdd_HHmmss");
        }
 public UpgradeOrchestrator(
     ProductUpgrader upgrader,
     ITracer tracer,
     PhysicalFileSystem fileSystem,
     InstallerPreRunChecker preRunChecker,
     TextReader input,
     TextWriter output)
 {
     this.upgrader       = upgrader;
     this.tracer         = tracer;
     this.fileSystem     = fileSystem;
     this.preRunChecker  = preRunChecker;
     this.output         = output;
     this.input          = input;
     this.mount          = false;
     this.ExitCode       = ReturnCode.Success;
     this.installationId = DateTime.Now.ToString("yyyyMMdd_HHmmss");
 }
        public void Execute()
        {
            string  error      = null;
            string  mountError = null;
            Version newVersion = null;

            if (this.tracer == null)
            {
                this.tracer = this.CreateTracer();
            }

            if (this.preRunChecker == null)
            {
                this.preRunChecker = new InstallerPreRunChecker(this.tracer, GSDConstants.UpgradeVerbMessages.GSDUpgradeConfirm);
            }

            try
            {
                if (this.TryInitialize(out error))
                {
                    try
                    {
                        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();
                    }
                }
                else
                {
                    this.ExitCode = ReturnCode.GenericError;
                }

                if (this.ExitCode == ReturnCode.GenericError)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine();
                    sb.Append("ERROR: " + error);

                    sb.AppendLine();
                    sb.AppendLine();

                    sb.AppendLine($"Upgrade logs can be found at: {this.logDirectory} with file names that end with the installation ID: {this.installationId}.");

                    this.output.WriteLine(sb.ToString());
                }
                else
                {
                    if (newVersion != null)
                    {
                        this.output.WriteLine($"{Environment.NewLine}Upgrade completed successfully{(string.IsNullOrEmpty(mountError) ? "." : ", but one or more repositories will need to be mounted manually.")}");
                    }
                }
            }
            finally
            {
                this.upgrader?.Dispose();
            }

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

            Environment.ExitCode = (int)this.ExitCode;
        }