private static InstallResult DoIt(string fsPath, StepVisitor visitor, bool withBinaries) { InstallResult result = new InstallResult { Successful = true, NeedRestart = false }; try { int warn; int err; int warnings = 0; int errors = 0; AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(AssemblyHandler.CurrentDomain_ReflectionOnlyAssemblyResolve); var unpacker = CreateUnpacker(fsPath); var manifests = unpacker.Unpack(fsPath); var dbScripts = GetDbScripts(manifests); InstallResult dbScriptResult; dbScriptResult = ExecuteDbScripts(PositionInSequence.BeforePackageValidating, dbScripts, visitor); if (!dbScriptResult.Successful) { return(dbScriptResult); } result.Combine(dbScriptResult); var validateResult = ValidatePackage(manifests, visitor, withBinaries, out warn); warnings += warn; if (!validateResult.Successful) { return(validateResult); } result.Combine(validateResult); dbScriptResult = ExecuteDbScripts(PositionInSequence.AfterPackageValidating, dbScripts, visitor); if (!dbScriptResult.Successful) { return(dbScriptResult); } result.Combine(dbScriptResult); //------------------------------------------------------------ if (withBinaries) { dbScriptResult = ExecuteDbScripts(PositionInSequence.BeforeCheckRequirements, dbScripts, visitor); if (!dbScriptResult.Successful) { return(dbScriptResult); } result.Combine(dbScriptResult); Logger.LogMessage(""); Logger.LogMessage("------------------------------ Prerequisits ---------------------------------"); Logger.LogMessage(""); result.Combine(ExecutePrerequisits(manifests, visitor, out warn, out err)); warnings += warn; if (!result.Successful) { return(result); } dbScriptResult = ExecuteDbScripts(PositionInSequence.AfterCheckRequirements, dbScripts, visitor); if (!dbScriptResult.Successful) { return(dbScriptResult); } result.Combine(dbScriptResult); dbScriptResult = ExecuteDbScripts(PositionInSequence.BeforeExecutables, dbScripts, visitor); if (!dbScriptResult.Successful) { return(dbScriptResult); } result.Combine(dbScriptResult); Logger.LogMessage(""); Logger.LogMessage("------------------------------ Executables ----------------------------------"); Logger.LogMessage(""); result.Combine(ExecuteExecutables(manifests, visitor, out warn, out err)); warnings += warn; dbScriptResult = ExecuteDbScripts(PositionInSequence.AfterExecutables, dbScripts, visitor); if (!dbScriptResult.Successful) { return(dbScriptResult); } result.Combine(dbScriptResult); if (!result.Successful || result.NeedRestart) { if (warnings > 0) { Logger.LogMessage(String.Concat(warnings, " warnings")); } if (errors > 0) { Logger.LogMessage(String.Concat(errors, " errors")); } return(result); } } dbScriptResult = ExecuteDbScripts(PositionInSequence.BeforeContentTypes, dbScripts, visitor); if (!dbScriptResult.Successful) { return(dbScriptResult); } result.Combine(dbScriptResult); Logger.LogMessage(""); Logger.LogMessage("------------------------------ ContentTypes ---------------------------------"); Logger.LogMessage(""); result.Combine(ExecuteContentTypes(manifests, visitor, out warn, out err)); warnings += warn; if (!result.Successful) { return(result); } dbScriptResult = ExecuteDbScripts(PositionInSequence.AfterContentTypes, dbScripts, visitor); if (!dbScriptResult.Successful) { return(dbScriptResult); } result.Combine(dbScriptResult); dbScriptResult = ExecuteDbScripts(PositionInSequence.BeforeContents, dbScripts, visitor); if (!dbScriptResult.Successful) { return(dbScriptResult); } result.Combine(dbScriptResult); Logger.LogMessage(""); Logger.LogMessage("-------------------------------- Contents -----------------------------------"); Logger.LogMessage(""); result.Combine(ExecuteContents(manifests, visitor, out warn, out err)); warnings += warn; if (!result.Successful) { return(result); } dbScriptResult = ExecuteDbScripts(PositionInSequence.AfterContents, dbScripts, visitor); if (!dbScriptResult.Successful) { return(dbScriptResult); } result.Combine(dbScriptResult); if (warnings > 0) { Logger.LogMessage(String.Concat(warnings, " warnings")); } if (errors > 0) { Logger.LogMessage(String.Concat(errors, " errors")); } return(result); } catch (Exception e) { Logger.LogException(e); return(new InstallResult { Successful = false }); } }
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.ShutDownAsync(CancellationToken.None).GetAwaiter().GetResult(); } 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 InstallResult ExecuteContents(IEnumerable <IManifest> manifests, StepVisitor visitor, out int warnings, out int errors) { warnings = 0; int warn; errors = 0; if (!CustomInstallStep.Invoke(GetMethod <CustomInstallStep>(x => x.OnBeforeInstallContents(default(bool))), visitor.IsProbing, out warn)) { return(ReturnWithErrorResult()); } warnings += warn; var contentSteps = new List <ContentInstallStep>(); foreach (var manifest in manifests) { contentSteps.AddRange(GetContentSteps(manifest)); } //---- Initialize contents try { foreach (var step in contentSteps) { step.Initialize(); } } catch (Exception e) { Logger.LogException(e, "INITIALIZING ERROR"); return(ReturnWithErrorResult()); } //---- Install contents contentSteps.Sort(); var postponedContents = new List <ContentInstallStep>(); foreach (var step in contentSteps) { try { StepResult result = visitor.DoIt(step); if (result.Kind == StepResultKind.Warning) { warnings++; } if (result.Kind == StepResultKind.Error) { return(ReturnWithErrorResult()); } if (result.NeedSetReferencePhase) { postponedContents.Add(step); } } catch (Exception e) { Logger.LogException(e); return(ReturnWithErrorResult()); } } foreach (var step in postponedContents) { try { StepResult result = step.SetReferences(); if (result.Kind == StepResultKind.Warning) { warnings++; } if (result.Kind == StepResultKind.Error) { errors++; } } catch (Exception e) { Logger.LogException(e); return(ReturnWithErrorResult()); } } if (!CustomInstallStep.Invoke(GetMethod <CustomInstallStep>(x => x.OnAfterInstallContents(default(bool))), visitor.IsProbing, out warn)) { return(ReturnWithErrorResult()); } warnings += warn; return(new InstallResult { Successful = true, NeedRestart = false }); }