Exemple #1
0
        /// <summary>
        /// Method that gets called everytime a message should be printed.
        /// The said message will be printed to the console and is some kind of verbose boot process.
        /// </summary>
        /// <param name="message">The message you want to send to the console.</param>
        /// <param name="infoImportance">Sets the importance of the informaition to filter it with different filteroptions.</param>
        public static void Info(string message, InfoImportance infoImportance)
        {
            if (infoImportance == InfoImportance.None)
            {
                return;
            }

            if ((infoImportance & InfoLogImportance) != infoImportance)
            {
                return;
            }


            var    numberChunk = $"[{_messageNumber.ToString("X8")}]";
            string messageChunk;

            if (message == null ||
                message.Length <= 0)
            {
                var stackframe       = new StackFrame(1);
                var callerMethod     = stackframe.GetMethod();
                var callerMethodName = callerMethod.Name;

                messageChunk = $"{callerMethodName}";
            }
            else
            {
                messageChunk = $"{message}";
            }


            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.DarkGray;
            Console.Write(numberChunk);

            if (infoImportance == InfoImportance.VeryImportant)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write(" - ### - ");
            }

            else if (infoImportance == InfoImportance.Important)
            {
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.Write(" - ... - ");
            }

            else if (infoImportance == InfoImportance.NotImportant)
            {
                Console.Write(" -     - ");
            }

            Console.ForegroundColor = ConsoleColor.White;
            Console.Write(messageChunk);

            Console.Write('\n');

            _messageNumber += 1;
        }
        /// <summary>
        /// Method that gets called everytime a message should be printed.
        /// The said message will be printed to the console and is some kind of verbose boot process. 
        /// </summary>
        /// <param name="message">The message you want to send to the console.</param>
        /// <param name="infoImportance">Sets the importance of the informaition to filter it with different filteroptions.</param>
        public static void Info(string message, InfoImportance infoImportance)
        {
            if (infoImportance == InfoImportance.None)
                return;

            if ((infoImportance & InfoLogImportance) != infoImportance)
                return;

            var numberChunk = $"[{_messageNumber.ToString("X8")}]";
            string messageChunk;

            if (message == null ||
                message.Length <= 0)
            {
                var stackframe = new StackFrame(1);
                var callerMethod = stackframe.GetMethod();
                var callerMethodName = callerMethod.Name;

                messageChunk = $"{callerMethodName}";
            }
            else
            {
                messageChunk = $"{message}";
            }

            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.DarkGray;
            Console.Write(numberChunk);

            if (infoImportance == InfoImportance.VeryImportant)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write(" - ### - ");
            }

            else if (infoImportance == InfoImportance.Important)
            {
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.Write(" - ... - ");
            }

            else if (infoImportance == InfoImportance.NotImportant)
            {
                Console.Write(" -     - ");
            }

            Console.ForegroundColor = ConsoleColor.White;
            Console.Write(messageChunk);

            Console.Write('\n');

            _messageNumber += 1;
        }
Exemple #3
0
        /// <summary>
        /// Executes the custom MsBuild task. Called by the MsBuild tool.
        /// </summary>
        /// <returns>
        /// True if there was no error and no exception.
        /// </returns>
        public override bool Execute()
        {
            if (_logger == null)
            {
                // This must not be moved to the ctor because BuildEngine is not yet initialized at construction time.
                _logger = new MsBuildLoggerGateway(BuildEngine);
            }

            try
            {
                var runWasSuccessful = true;

                _logger.LogTraceMessage(GetInputParameterDiagnosticMessages());

                var defaultInfoImportance = EnumHelper.ParseNullable <Importance>(InfoImportance.GetValue());
                var analyzerFactory       = new DependencyAnalyzerFactory(_logger.LogTraceMessage).SetDefaultInfoImportance(defaultInfoImportance);
                var analyzer         = analyzerFactory.CreateOutOfProcess(ProjectFolder, ServiceAddressProvider.ServiceAddress);
                var analyzerMessages = analyzer.AnalyzeProject(SourceFilePaths, ReferencedAssemblyPaths);

                _logger.InfoImportance = analyzer.InfoImportance.ToMessageImportance();

                foreach (var analyzerMessage in analyzerMessages)
                {
                    switch (analyzerMessage)
                    {
                    case InfoMessageBase infoMessage:
                        _logger.LogInfo(infoMessage);
                        break;

                    case IssueMessageBase issueMessage:
                        _logger.LogIssue(issueMessage);
                        runWasSuccessful = runWasSuccessful && issueMessage.IssueKind != IssueKind.Error;
                        break;

                    default:
                        throw new Exception($"Unexpected analyzer message type: {analyzerMessage?.GetType().Name}");
                    }
                }

                return(runWasSuccessful);
            }
            catch (Exception e)
            {
                _logger.LogError($"Exception during NsDepCopTask execution: {e}");
                return(false);
            }
        }
Exemple #4
0
        /// <summary>
        /// Executes the custom MsBuild task. Called by the MsBuild tool.
        /// </summary>
        /// <returns>
        /// True if there was no error and no exception.
        /// </returns>
        public override bool Execute()
        {
            if (_logger == null)
            {
                // This must not be moved to the ctor because BuildEngine is not yet inicialized at construction time.
                _logger = new MsBuildLoggerGateway(BuildEngine);
            }

            try
            {
                var runWasSuccessful = true;

                _logger.LogTraceMessage(GetInputParameterDiagnosticMessages());

                var defaultInfoImportance = EnumHelper.ParseNullable <Importance>(InfoImportance.GetValue());
                var analyzerFactory       = new DependencyAnalyzerFactory(_logger.LogTraceMessage).SetDefaultInfoImportance(defaultInfoImportance);
                var analyzer         = analyzerFactory.CreateOutOfProcess(ProjectFolder, ServiceAddressProvider.ServiceAddress);
                var analyzerMessages = analyzer.AnalyzeProject(SourceFilePaths, ReferencedAssemblyPaths);

                _logger.InfoImportance = analyzer.InfoImportance.ToMessageImportance();

                foreach (var analyzerMessage in analyzerMessages)
                {
                    switch (analyzerMessage)
                    {
                    case IllegalDependencyMessage illegalDependencyMessage:
                        _logger.LogIssue(
                            IssueDefinitions.IllegalDependencyIssue,
                            illegalDependencyMessage.IllegalDependency,
                            illegalDependencyMessage.IssueKind,
                            illegalDependencyMessage.IllegalDependency.SourceSegment);
                        break;

                    case ConfigErrorMessage configErrorMessage:
                        _logger.LogIssue(IssueDefinitions.ConfigExceptionIssue, configErrorMessage.Exception);
                        break;

                    case TooManyIssuesMessage tooManyIssuesMessage:
                        _logger.LogIssue(IssueDefinitions.TooManyIssuesIssue, tooManyIssuesMessage.IssueKind);
                        break;

                    case NoConfigFileMessage _:
                        _logger.LogIssue(IssueDefinitions.NoConfigFileIssue);
                        break;

                    case ConfigDisabledMessage _:
                        _logger.LogIssue(IssueDefinitions.ConfigDisabledIssue);
                        break;

                    case AnalysisStartedMessage analysisStartedMessage:
                        _logger.LogIssue(IssueDefinitions.AnalysisStartedIssue, analysisStartedMessage.ProjectLocation);
                        break;

                    case AnalysisFinishedMessage analysisFinishedMessage:
                        _logger.LogIssue(IssueDefinitions.AnalysisFinishedIssue, analysisFinishedMessage.AnalysisDuration);
                        break;

                    default:
                        throw new Exception($"Unexpected analyzer message type: {analyzerMessage?.GetType().Name}");
                    }

                    if (analyzerMessage is IssueMessageBase issueMessage)
                    {
                        runWasSuccessful = runWasSuccessful && issueMessage.IssueKind != IssueKind.Error;
                    }
                }

                return(runWasSuccessful);
            }
            catch (Exception e)
            {
                _logger.LogIssue(TaskExceptionIssue, e);
                return(false);
            }
        }