internal static PackagingResult ExecuteCurrentPhase(Manifest manifest, ExecutionContext executionContext) { var sysInstall = manifest.SystemInstall; var currentPhase = executionContext.CurrentPhase; if (0 == currentPhase - (sysInstall ? 1 : 0)) { SaveInitialPackage(manifest); } var stepElements = manifest.GetPhase(executionContext.CurrentPhase); var stopper = Stopwatch.StartNew(); Logger.LogMessage("Executing steps"); Exception phaseException = null; var successful = false; try { var maxStepId = stepElements.Count; for (int i = 0; i < maxStepId; i++) { var stepElement = stepElements[i]; var step = Step.Parse(stepElement, i, executionContext); var stepStopper = Stopwatch.StartNew(); Logger.LogStep(step, maxStepId); step.Execute(executionContext); stepStopper.Stop(); Logger.LogMessage("-------------------------------------------------------------"); Logger.LogMessage("Time: " + stepStopper.Elapsed); if (executionContext.Terminated) { LogTermination(executionContext); break; } } stopper.Stop(); Logger.LogMessage("============================================================="); Logger.LogMessage("All steps were executed."); Logger.LogMessage("Aggregated time: " + stopper.Elapsed); Logger.LogMessage("Errors: " + Logger.Errors); successful = true; } catch (Exception e) { phaseException = e; } var finished = executionContext.Terminated || (executionContext.CurrentPhase == manifest.CountOfPhases - 1); if (successful && !finished) { return new PackagingResult { NeedRestart = true, Successful = true, Errors = Logger.Errors } } ; if (executionContext.Terminated && executionContext.TerminationReason == TerminationReason.Warning) { successful = false; phaseException = new PackageTerminatedException(executionContext.TerminationMessage); } try { SavePackage(manifest, executionContext, successful, phaseException); } catch (Exception e) { if (phaseException != null) { Logger.LogException(phaseException); } throw new PackagingException("Cannot save the package.", e); } finally { RepositoryVersionInfo.Reset(); // we need to shut down messaging, because the line above uses it if (!executionContext.Test) { DistributedApplication.ClusterChannel.ShutDown(); } else { Diagnostics.SnTrace.Test.Write("DistributedApplication.ClusterChannel.ShutDown SKIPPED because it is a test context."); } } if (!successful && !executionContext.Terminated) { throw new ApplicationException(String.Format(SR.Errors.PhaseFinishedWithError_1, phaseException.Message), phaseException); } return(new PackagingResult { NeedRestart = false, Successful = successful, Terminated = executionContext.Terminated && !successful, Errors = Logger.Errors }); }
private static PackagingResult ExecuteCurrentPhase(Manifest manifest, ExecutionContext executionContext) { if (manifest.Type == PackageType.Product && manifest.Level == PackageLevel.Install) { // In case of product install create initial entry at the beginning of the // second phase, after the new db was created in the first phase. if (executionContext.CurrentPhase == 1) { SaveInitialPackage(manifest); } } else { if (executionContext.CurrentPhase == 0) { SaveInitialPackage(manifest); } } var stepElements = manifest.GetPhase(executionContext.CurrentPhase); var stopper = Stopwatch.StartNew(); Logger.LogMessage("Executing steps"); Exception phaseException = null; var successful = false; try { var maxStepId = stepElements.Count(); for (int i = 0; i < maxStepId; i++) { var stepElement = stepElements[i]; var step = Step.Parse(stepElement, i); executionContext.SubstituteParameters(step); var stepStopper = Stopwatch.StartNew(); Logger.LogStep(step, maxStepId); step.Execute(executionContext); stepStopper.Stop(); Logger.LogMessage("-------------------------------------------------------------"); Logger.LogMessage("Time: " + stepStopper.Elapsed); if (executionContext.Terminated) { LogTermination(executionContext); break; } } stopper.Stop(); Logger.LogMessage("============================================================="); Logger.LogMessage("All steps were executed."); Logger.LogMessage("Aggregated time: " + stopper.Elapsed); Logger.LogMessage("Errors: " + Logger.Errors); successful = true; } catch (Exception e) { phaseException = e; } var finished = executionContext.Terminated || (executionContext.CurrentPhase == manifest.CountOfPhases - 1); if (successful && !finished) { return new PackagingResult { NeedRestart = true, Successful = true, Errors = Logger.Errors } } ; if (executionContext.Terminated && executionContext.TerminationReason == TerminationReason.Warning) { successful = false; phaseException = new PackageTerminatedException(executionContext.TerminationMessage); } try { SavePackage(manifest, executionContext, successful, phaseException); } finally { RepositoryVersionInfo.Reset(); //we need to shut down messaging, because the line above uses it DistributedApplication.ClusterChannel.ShutDown(); } if (!successful && !executionContext.Terminated) { throw new ApplicationException(String.Format(SR.Errors.PhaseFinishedWithError_1, phaseException.Message), phaseException); } return(new PackagingResult { NeedRestart = false, Successful = successful, Terminated = executionContext.Terminated && !successful, Errors = Logger.Errors }); }