LogMessage() public static method

public static LogMessage ( string message ) : void
message string
return void
Exemplo n.º 1
0
        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
            });
        }
Exemplo n.º 2
0
        private static PackagingResult ExecuteCurrentPhase(Manifest manifest, ExecutionContext executionContext)
        {
            if (executionContext.CurrentPhase == 0)
            {
                SaveInitialPackage(manifest);
            }

            var steps = manifest.GetPhase(executionContext.CurrentPhase);

            var stopper = Stopwatch.StartNew();

            Logger.LogMessage("Executing steps");

            Exception phaseException = null;
            var       successful     = false;

            try
            {
                var maxStepId = steps.Count();
                foreach (var step in steps)
                {
                    var stepStopper = Stopwatch.StartNew();
                    Logger.LogStep(step, maxStepId);
                    step.Execute(executionContext);
                    stepStopper.Stop();
                    Logger.LogMessage("-------------------------------------------------------------");
                    Logger.LogMessage("Time: " + stepStopper.Elapsed);
                }
                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;
            }

            if (successful && (executionContext.CurrentPhase < manifest.CountOfPhases - 1))
            {
                return new PackagingResult {
                           NeedRestart = true, Successful = true, Errors = Logger.Errors
                }
            }
            ;

            try
            {
                if (Logger.Level <= LogLevel.Default)
                {
                    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)
            {
                throw new ApplicationException(String.Format(SR.Errors.PhaseFinishedWithError_1, phaseException.Message), phaseException);
            }

            return(new PackagingResult {
                NeedRestart = false, Successful = true, Errors = Logger.Errors
            });
        }
Exemplo n.º 3
0
        private void CheckPrerequisits(PackageParameter[] packageParameters, bool forcedReinstall, bool log, bool editConnectionString)
        {
            if (log)
            {
                Logger.LogMessage("ComponentId: {0}", this.ComponentId);
                Logger.LogMessage("PackageType:   " + this.PackageType);
                Logger.LogMessage("Package version: " + this.Version);
                if (SystemInstall)
                {
                    Logger.LogMessage(forcedReinstall ? "FORCED REINSTALL" : "SYSTEM INSTALL");
                }
            }

            if (SystemInstall && editConnectionString)
            {
                //UNDONE:CNSTR: Get ConnectionStringOptions from ServiceProvider or another general location.
                var connectionStrings = new ConnectionStringOptions();
                throw new SnNotSupportedException();
                EditConnectionString(connectionStrings, this.Parameters, packageParameters);
                RepositoryVersionInfo.Reset();
            }

            var versionInfo           = RepositoryVersionInfo.Instance;
            var existingComponentInfo = versionInfo.Components.FirstOrDefault(a => a.ComponentId == ComponentId);

            if (PackageType == PackageType.Install)
            {
                if (!(forcedReinstall && SystemInstall) && existingComponentInfo != null)
                {
                    // Install packages can be executed multiple times only if it is
                    // allowed in the package AND the version in the manifest is the
                    // same as in the db.
                    if (!this.MultipleExecutionAllowed || existingComponentInfo.Version != this.Version)
                    {
                        throw new PackagePreconditionException(
                                  string.Format(SR.Errors.Precondition.CannotInstallExistingComponent1, this.ComponentId),
                                  PackagingExceptionType.CannotInstallExistingComponent);
                    }
                }
            }
            else if (PackageType != PackageType.Tool)
            {
                if (existingComponentInfo == null)
                {
                    throw new PackagePreconditionException(string.Format(SR.Errors.Precondition.CannotUpdateMissingComponent1, this.ComponentId),
                                                           PackagingExceptionType.CannotUpdateMissingComponent);
                }
                if (existingComponentInfo.Version >= this.Version)
                {
                    throw new PackagePreconditionException(string.Format(SR.Errors.Precondition.TargetVersionTooSmall2, this.Version, existingComponentInfo.Version),
                                                           PackagingExceptionType.TargetVersionTooSmall);
                }
            }

            if (log && this.Dependencies.Any())
            {
                Logger.LogMessage("Dependencies:");
            }
            foreach (var dependency in this.Dependencies)
            {
                CheckDependency(dependency, versionInfo, log);
            }
        }
Exemplo n.º 4
0
        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
                });
            }
        }