private void BuildService_ServiceEvent(object sender, BuildEventArgs e)
 {
     switch (e.Code)
     {
         case BuildEventCode.ServiceStart:
             SetLight(AvailableColours[Colors.Purple]);
             break;
         case BuildEventCode.BuildInformationRetrievalStart:
             SetLight(AvailableColours[Colors.White]);
             break;
         case BuildEventCode.Error:
             SetLight(AvailableColours[Colors.Red]);
             break;
         case BuildEventCode.NoBuildInformationAvailable:
         case BuildEventCode.NoBuildsFound:
             SetLight(AvailableColours[Colors.Purple]);
             break;
         case BuildEventCode.BuildInformationRetrievalEnd:
             ShowCombinedBuildStatus();
             break;
         case BuildEventCode.ServiceEnd:
             SetLight(AvailableColours[Colors.Black]);
             break;
     }
 }
 private void BuildService_BuildEvent(object sender, BuildEventArgs e)
 {
     switch (e.Code)
     {
         case BuildEventCode.Error:
             SetLight(AvailableColours[Colors.Red]);
             break;
     }
 }
        protected async override void OnServiceEvent(object sender, BuildEventArgs e)
        {
            base.OnServiceEvent(sender, e);

            if (e.Code == BuildEventCode.SkippedBuild)
            {
                await PerformUICode(() =>
                {
                    var build = Builds.FirstOrDefault(b => b.Definition.Name.Equals(e.Name));
                    if (build != null)
                    {
                        Builds.Remove(build);
                    }
                });
            }

        }
        private async Task AddBuildEventToLogsAsync(BuildEventArgs e)
        {
            await PerformUICode(() =>
            {
                LogEntries.Add(new LogEntry()
                {
                    Timestamp = e.Timestamp,
                    BuildName = e.BuildDetails?.Definition.Name,
                    Code = e.Code.ToString(),
                    Text = e.ToString(),
                    Description = e.Exception?.StackTrace
                });

                while (LogEntries.Count > 1000)
                {
                    LogEntries.RemoveAt(0);
                }
            });
        }
        protected async override void OnBuildEvent(object sender, BuildEventArgs e)
        {
            base.OnBuildEvent(sender, e);

            var definition = e.BuildDetails?.Definition;

            if ((definition != null) || !string.IsNullOrWhiteSpace(e.Name))
            {
                var build = Builds.FirstOrDefault(b => b.Definition == definition || b.Definition.Name.Equals(e.Name));

                if (e.Code == BuildEventCode.BuildInstanceRetrievalStart)
                {
                    if (build != null)
                    {
                        await PerformUICode(() => build.IsBusy = true);
                    }
                }
                else if (e.Code == BuildEventCode.BuildInstanceRetrievalEnd)
                {
                    if (build != null)
                    {
                        await PerformUICode(() => build.IsBusy = false);
                    }
                }
                else if (e.Code == BuildEventCode.StatusUpdate)
                {
                    if (build == null)
                    {
                        await PerformUICode(() => Builds.Add(e.BuildDetails));
                    }
                    else if (((build.CurrentBuild == null) && (e.BuildDetails.CurrentBuild != null)) || build.CurrentBuild.HasStatusChanged(e.BuildDetails.CurrentBuild))
                    {
                        await PerformUICode(() =>
                        {
                            Builds.Remove(build);
                            Builds.Insert(0, e.BuildDetails);
                        });
                    }
                }
            }
        }
Exemple #6
0
 void OnBuildEvent(BuildEventArgs eventArgs)
 {
     AddMessage("The " + eventArgs.name + " will be warped in " + eventArgs.turns + " turn(s).");
     //Debug.Log("Received Build Event");
 }
 public void RaiseEvent(object sender, BuildEventArgs args) => AnyEventRaised?.Invoke(sender, args);
Exemple #8
0
        /// <summary>
        /// Add the error/warning to the error list and potentially to the output window.
        /// </summary>
        private void AddToErrorList(
            BuildEventArgs errorEvent,
            string subcategory,
            string errorCode,
            string file,
            int startLine,
            int startColumn,
            int endLine,
            int endColumn)
        {
            if (file == null)
            {
                file = String.Empty;
            }

            bool isWarning = errorEvent is BuildWarningEventArgs;

            Shell.TaskPriority priority = isWarning ? Shell.TaskPriority.Normal : Shell.TaskPriority.High;

            TextSpan span;

            span.iStartLine  = startLine;
            span.iStartIndex = startColumn;
            span.iEndLine    = endLine < startLine ? span.iStartLine : endLine;
            span.iEndIndex   = (endColumn < startColumn) && (span.iStartLine == span.iEndLine) ? span.iStartIndex : endColumn;

            if (OutputWindowPane != null &&
                (this.Verbosity != LoggerVerbosity.Quiet || errorEvent is BuildErrorEventArgs))
            {
                // Format error and output it to the output window
                string message         = this.FormatMessage(errorEvent.Message);
                DefaultCompilerError e = new DefaultCompilerError(file,
                                                                  span.iStartLine,
                                                                  span.iStartIndex,
                                                                  span.iEndLine,
                                                                  span.iEndIndex,
                                                                  errorCode,
                                                                  message);
                e.IsWarning = isWarning;

                Output(GetFormattedErrorMessage(e));
            }

            UIThread.Run(delegate()
            {
                IVsUIShellOpenDocument openDoc = serviceProvider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
                if (openDoc == null)
                {
                    return;
                }

                IVsWindowFrame frame;
                IOleServiceProvider sp;
                IVsUIHierarchy hier;
                uint itemid;
                Guid logicalView = VSConstants.LOGVIEWID_Code;

                IVsTextLines buffer = null;
                // JAF
                // Notes about acquiring the buffer:
                // If the file physically exists then this will open the document in the current project. It doesn't matter if the file is a member of the project.
                // Also, it doesn't matter if this is an F# file. For example, an error in Microsoft.Common.targets will cause a file to be opened here.
                // However, opening the document does not mean it will be shown in VS.
                if (!Microsoft.VisualStudio.ErrorHandler.Failed(openDoc.OpenDocumentViaProject(file, ref logicalView, out sp, out hier, out itemid, out frame)) && frame != null)
                {
                    object docData;
                    frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData);

                    // Get the text lines
                    buffer = docData as IVsTextLines;

                    if (buffer == null)
                    {
                        IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider;
                        if (bufferProvider != null)
                        {
                            bufferProvider.GetTextBuffer(out buffer);
                        }
                    }
                }

                // Need to adjust line and column indexing for the task window, which assumes zero-based values
                if (span.iStartLine > 0 && span.iStartIndex > 0)
                {
                    span.iStartLine  -= 1;
                    span.iEndLine    -= 1;
                    span.iStartIndex -= 1;
                    span.iEndIndex   -= 1;
                }

                // Add error to task list
                var taskText = Microsoft.FSharp.Compiler.ErrorLogger.NewlineifyErrorString(errorEvent.Message);

                if (errorReporter != null)
                {
                    errorReporter.ReportError2(taskText, errorCode, (VSTASKPRIORITY)priority, span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex, file);
                }
            });
        }
Exemple #9
0
 /// <summary>
 /// Handle a events raised from the any event source. This source will
 /// raise all events no matter the type.
 /// </summary>
 /// <param name="sender">Who sent the event</param>
 /// <param name="e">Event raised on the event source</param>
 private void Source_AnyEventRaised(object sender, BuildEventArgs e)
 {
     _enteredAnyEventHandler = true;
     _raisedAnyEvent         = e;
 }
Exemple #10
0
 void eventSource_AnyEventRaised(object sender, BuildEventArgs e)
 {
 }
Exemple #11
0
 private void OnAnyEventRaised(object sender, BuildEventArgs e)
 {
     Add(e);
 }
Exemple #12
0
 private void EventSource_AnyEventRaised(object sender, BuildEventArgs e)
 {
     this.LoggedEvents.Add(e);
 }
Exemple #13
0
 private void Build_Finished(object sender, BuildEventArgs e)
 {
     FinishBuild();
 }
        /// <summary>
        /// Reads the next log record from the binary reader. If there are no more records, returns null.
        /// </summary>
        public BuildEventArgs Read()
        {
            BinaryLogRecordKind recordKind = (BinaryLogRecordKind)ReadInt32();

            while (IsBlob(recordKind))
            {
                ReadBlob(recordKind);

                recordKind = (BinaryLogRecordKind)ReadInt32();
            }

            BuildEventArgs result = null;

            switch (recordKind)
            {
            case BinaryLogRecordKind.EndOfFile:
                break;

            case BinaryLogRecordKind.BuildStarted:
                result = ReadBuildStartedEventArgs();
                break;

            case BinaryLogRecordKind.BuildFinished:
                result = ReadBuildFinishedEventArgs();
                break;

            case BinaryLogRecordKind.ProjectStarted:
                result = ReadProjectStartedEventArgs();
                break;

            case BinaryLogRecordKind.ProjectFinished:
                result = ReadProjectFinishedEventArgs();
                break;

            case BinaryLogRecordKind.TargetStarted:
                result = ReadTargetStartedEventArgs();
                break;

            case BinaryLogRecordKind.TargetFinished:
                result = ReadTargetFinishedEventArgs();
                break;

            case BinaryLogRecordKind.TaskStarted:
                result = ReadTaskStartedEventArgs();
                break;

            case BinaryLogRecordKind.TaskFinished:
                result = ReadTaskFinishedEventArgs();
                break;

            case BinaryLogRecordKind.Error:
                result = ReadBuildErrorEventArgs();
                break;

            case BinaryLogRecordKind.Warning:
                result = ReadBuildWarningEventArgs();
                break;

            case BinaryLogRecordKind.Message:
                result = ReadBuildMessageEventArgs();
                break;

            case BinaryLogRecordKind.CriticalBuildMessage:
                result = ReadCriticalBuildMessageEventArgs();
                break;

            case BinaryLogRecordKind.TaskCommandLine:
                result = ReadTaskCommandLineEventArgs();
                break;

            case BinaryLogRecordKind.ProjectEvaluationStarted:
                result = ReadProjectEvaluationStartedEventArgs();
                break;

            case BinaryLogRecordKind.ProjectEvaluationFinished:
                result = ReadProjectEvaluationFinishedEventArgs();
                break;

            case BinaryLogRecordKind.ProjectImported:
                result = ReadProjectImportedEventArgs();
                break;

            case BinaryLogRecordKind.TargetSkipped:
                result = ReadTargetSkippedEventArgs();
                break;

            case BinaryLogRecordKind.EnvironmentVariableRead:
                result = ReadEnvironmentVariableReadEventArgs();
                break;

            case BinaryLogRecordKind.PropertyReassignment:
                result = ReadPropertyReassignmentEventArgs();
                break;

            case BinaryLogRecordKind.UninitializedPropertyRead:
                result = ReadUninitializedPropertyReadEventArgs();
                break;

            case BinaryLogRecordKind.PropertyInitialValueSet:
                result = ReadPropertyInitialValueSetEventArgs();
                break;

            default:
                break;
            }

            return(result);
        }
Exemple #15
0
 protected virtual void ForwardToCentralLogger(BuildEventArgs e)
 {
     _buildEventRedirector.ForwardEvent(e);
 }
Exemple #16
0
 private void CollectImports(BuildEventArgs e)
 {
     if (e is ProjectImportedEventArgs importArgs && importArgs.ImportedProjectFile != null)
     {
         projectImportsCollector.AddFile(importArgs.ImportedProjectFile);
     }
Exemple #17
0
 private void EventSource_AnyEventRaised(object sender, BuildEventArgs e)
 {
     Write(e);
 }
 private void EventSource_AnyEventRaised(object sender, BuildEventArgs e)
 {
     //1>D:\Source\Projects\reactorui-xamarin\src\XamarinReactorUI.HotReloadVsExtension\OutputPaneLogger.cs(71,9,71,15): error CS0106: The modifier 'public' is not valid for this item
     outputPane.OutputStringThreadSafe($"{e.Message}{Environment.NewLine}");
 }
        /// <summary>
        /// Add the error/warning to the error list and potentially to the output window.
        /// </summary>
        private void AddToErrorList(
            BuildEventArgs errorEvent,
            string subcategory,
            string errorCode,
            string file,
            int startLine,
            int startColumn,
            int endLine,
            int endColumn)
        {
            if (String.IsNullOrEmpty(file))
            {
                return;
            }

            bool         isWarning = errorEvent is BuildWarningEventArgs;
            TaskPriority priority  = isWarning ? TaskPriority.Normal : TaskPriority.High;

            TextSpan span;

            span.iStartLine  = startLine;
            span.iStartIndex = startColumn;
            span.iEndLine    = endLine < startLine ? span.iStartLine : endLine;
            span.iEndIndex   = (endColumn < startColumn) && (span.iStartLine == span.iEndLine) ? span.iStartIndex : endColumn;

            if (OutputWindowPane != null &&
                (this.Verbosity != LoggerVerbosity.Quiet || errorEvent is BuildErrorEventArgs))
            {
                // Format error and output it to the output window
                string message         = this.FormatMessage(errorEvent.Message);
                DefaultCompilerError e = new DefaultCompilerError(file,
                                                                  span.iStartLine,
                                                                  span.iStartIndex,
                                                                  span.iEndLine,
                                                                  span.iEndIndex,
                                                                  errorCode,
                                                                  message);
                e.IsWarning = isWarning;

                Output(GetFormattedErrorMessage(e));
            }

            UIThread.Run(delegate()
            {
                IVsUIShellOpenDocument openDoc = serviceProvider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
                if (openDoc == null)
                {
                    return;
                }

                IVsWindowFrame frame;
                IOleServiceProvider sp;
                IVsUIHierarchy hier;
                uint itemid;
                Guid logicalView = VSConstants.LOGVIEWID_Code;

                IVsTextLines buffer = null;
                // JAF
                // Notes about acquiring the buffer:
                // If the file physically exists then this will open the document in the current project. It doesn't matter if the file is a member of the project.
                // Also, it doesn't matter if this is an F# file. For example, an error in Microsoft.Common.targets will cause a file to be opened here.
                // However, opening the document does not mean it will be shown in VS.
                if (!Microsoft.VisualStudio.ErrorHandler.Failed(openDoc.OpenDocumentViaProject(file, ref logicalView, out sp, out hier, out itemid, out frame)) && frame != null)
                {
                    object docData;
                    frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData);

                    // Get the text lines
                    buffer = docData as IVsTextLines;

                    if (buffer == null)
                    {
                        IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider;
                        if (bufferProvider != null)
                        {
                            bufferProvider.GetTextBuffer(out buffer);
                        }
                    }
                }

                // Need to adjust line and column indexing for the task window, which assumes zero-based values
                if (span.iStartLine > 0 && span.iStartIndex > 0)
                {
                    span.iStartLine  -= 1;
                    span.iEndLine    -= 1;
                    span.iStartIndex -= 1;
                    span.iEndIndex   -= 1;
                }

                // Add new document task to task list
                DocumentTask task = new DocumentTask(serviceProvider,
                                                     buffer, // May be null
                                                             // This seems weird. Why would warning status make this a 'compile error'?
                                                             // The “code sense” errors produce red squiggles, whereas the “compile” errors produce blue squiggles.  (This is in line with C#’s pre-VS2008-SP1 behavior.)  Swapping these two gives us a look consistent with that of the language service.
                                                     isWarning ? MARKERTYPE.MARKER_COMPILE_ERROR : MARKERTYPE.MARKER_CODESENSE_ERROR,
                                                     span,
                                                     file,
                                                     subcategory);

                // Add error to task list
                task.Text          = Microsoft.FSharp.Compiler.ErrorLogger.NewlineifyErrorString(errorEvent.Message);
                task.Priority      = priority;
                task.ErrorCategory = isWarning ? TaskErrorCategory.Warning : TaskErrorCategory.Error;
                task.Category      = TaskCategory.BuildCompile;
                task.HierarchyItem = hierarchy;
                task.Navigate     += new EventHandler(NavigateTo);

                if (null != this.TaskReporter)
                {
                    this.taskReporter.AddTask(task);
                }
                else
                {
                    this.taskProvider.Tasks.Add(task);
                }
            });
        }
Exemple #20
0
 public void RaiseEvent(BuildEventArgs e)
 {
     eventSource.RaiseEvent(e);
 }
Exemple #21
0
        /*
         * Method:  LoggerEventHandler
         *
         * Receives build events and logs them the way we like.
         *
         */
        internal void LoggerEventHandler(object sender, BuildEventArgs eventArgs)
        {
            if (eventArgs is BuildWarningEventArgs)
            {
                BuildWarningEventArgs w = (BuildWarningEventArgs)eventArgs;

                // hack: disregard the MTA warning.
                // need the second condition to pass on ploc builds
                if (w.Code != "MSB4056" && !w.Message.Contains("MSB4056"))
                {
                    fullLog.AppendFormat("{0}({1},{2}): {3} warning {4}: {5}\r\n",
                                         w.File,
                                         w.LineNumber,
                                         w.ColumnNumber,
                                         w.Subcategory,
                                         w.Code,
                                         w.Message);

                    ++warningCount;
                    this.warnings.Add(w);
                }
            }
            else if (eventArgs is BuildErrorEventArgs)
            {
                BuildErrorEventArgs e = (BuildErrorEventArgs)eventArgs;

                fullLog.AppendFormat("{0}({1},{2}): {3} error {4}: {5}\r\n",
                                     e.File,
                                     e.LineNumber,
                                     e.ColumnNumber,
                                     e.Subcategory,
                                     e.Code,
                                     e.Message);

                ++errorCount;
                this.errors.Add(e);
            }
            else
            {
                // Log the message unless we are a build finished event and logBuildFinished is set to false.
                bool logMessage = !(eventArgs is BuildFinishedEventArgs) || (eventArgs is BuildFinishedEventArgs && logBuildFinishedEvent);
                if (logMessage)
                {
                    fullLog.Append(eventArgs.Message);
                    fullLog.Append("\r\n");
                }
            }

            if (eventArgs is ExternalProjectStartedEventArgs)
            {
                this.ExternalProjectStartedEvents.Add((ExternalProjectStartedEventArgs)eventArgs);
            }
            else if (eventArgs is ExternalProjectFinishedEventArgs)
            {
                this.ExternalProjectFinishedEvents.Add((ExternalProjectFinishedEventArgs)eventArgs);
            }

            if (eventArgs is BuildFinishedEventArgs)
            {
                buildFinishedEvents.Add((BuildFinishedEventArgs)eventArgs);
                // We should not have any task crashes. Sometimes a test will validate that their expected error
                // code appeared, but not realize it then crashed.
                AssertLogDoesntContain("MSB4018");

                // We should not have any Engine crashes.
                AssertLogDoesntContain("MSB0001");

                // Console.Write in the context of a unit test is very expensive.  A hundred
                // calls to Console.Write can easily take two seconds on a fast machine.  Therefore, only
                // do the Console.Write once at the end of the build.
                Console.Write(FullLog);
            }
        }
Exemple #22
0
 private void WriteCore(BuildEventArgs e)
 {
     // the cases are ordered by most used first for performance
     if (e is BuildMessageEventArgs)
     {
         Write((BuildMessageEventArgs)e);
     }
     else if (e is TaskStartedEventArgs)
     {
         Write((TaskStartedEventArgs)e);
     }
     else if (e is TaskFinishedEventArgs)
     {
         Write((TaskFinishedEventArgs)e);
     }
     else if (e is TargetStartedEventArgs)
     {
         Write((TargetStartedEventArgs)e);
     }
     else if (e is TargetFinishedEventArgs)
     {
         Write((TargetFinishedEventArgs)e);
     }
     else if (e is BuildErrorEventArgs)
     {
         Write((BuildErrorEventArgs)e);
     }
     else if (e is BuildWarningEventArgs)
     {
         Write((BuildWarningEventArgs)e);
     }
     else if (e is ProjectStartedEventArgs)
     {
         Write((ProjectStartedEventArgs)e);
     }
     else if (e is ProjectFinishedEventArgs)
     {
         Write((ProjectFinishedEventArgs)e);
     }
     else if (e is BuildStartedEventArgs)
     {
         Write((BuildStartedEventArgs)e);
     }
     else if (e is BuildFinishedEventArgs)
     {
         Write((BuildFinishedEventArgs)e);
     }
     else if (e is ProjectEvaluationStartedEventArgs)
     {
         Write((ProjectEvaluationStartedEventArgs)e);
     }
     else if (e is ProjectEvaluationFinishedEventArgs)
     {
         Write((ProjectEvaluationFinishedEventArgs)e);
     }
     else
     {
         // convert all unrecognized objects to message
         // and just preserve the message
         var buildMessageEventArgs = new BuildMessageEventArgs(
             e.Message,
             e.HelpKeyword,
             e.SenderName,
             MessageImportance.Normal,
             e.Timestamp);
         buildMessageEventArgs.BuildEventContext = e.BuildEventContext ?? BuildEventContext.Invalid;
         Write(buildMessageEventArgs);
     }
 }
        /*
         * Method:  LoggerEventHandler
         *
         * Receives build events and logs them the way we like.
         *
         */
        internal void LoggerEventHandler(object sender, BuildEventArgs eventArgs)
        {
            lock (_lockObj)
            {
                AllBuildEvents.Add(eventArgs);

                foreach (var handler in AdditionalHandlers)
                {
                    handler(sender, eventArgs);
                }

                if (eventArgs is BuildWarningEventArgs w)
                {
                    // hack: disregard the MTA warning.
                    // need the second condition to pass on ploc builds
                    if (w.Code != "MSB4056" && !w.Message.Contains("MSB4056"))
                    {
                        string logMessage = string.Format(
                            "{0}({1},{2}): {3} warning {4}: {5}",
                            w.File,
                            w.LineNumber,
                            w.ColumnNumber,
                            w.Subcategory,
                            w.Code,
                            w.Message);

                        _fullLog.AppendLine(logMessage);
                        _testOutputHelper?.WriteLine(logMessage);

                        ++WarningCount;
                        Warnings.Add(w);
                    }
                }
                else if (eventArgs is BuildErrorEventArgs)
                {
                    var e = (BuildErrorEventArgs)eventArgs;

                    string logMessage = string.Format(
                        "{0}({1},{2}): {3} error {4}: {5}",
                        e.File,
                        e.LineNumber,
                        e.ColumnNumber,
                        e.Subcategory,
                        e.Code,
                        e.Message);
                    _fullLog.AppendLine(logMessage);
                    _testOutputHelper?.WriteLine(logMessage);

                    ++ErrorCount;
                    Errors.Add(e);
                }
                else
                {
                    // Log the message unless we are a build finished event and logBuildFinished is set to false.
                    bool logMessage = !(eventArgs is BuildFinishedEventArgs) || LogBuildFinished;
                    if (logMessage)
                    {
                        _fullLog.AppendLine(eventArgs.Message);
                        _testOutputHelper?.WriteLine(eventArgs.Message);
                    }
                }

                if (eventArgs is ExternalProjectStartedEventArgs args)
                {
                    ExternalProjectStartedEvents.Add(args);
                }
                else if (eventArgs is ExternalProjectFinishedEventArgs)
                {
                    ExternalProjectFinishedEvents.Add((ExternalProjectFinishedEventArgs)eventArgs);
                }

                if (eventArgs is ProjectStartedEventArgs startedEventArgs)
                {
                    ProjectStartedEvents.Add(startedEventArgs);
                }
                else if (eventArgs is ProjectFinishedEventArgs)
                {
                    ProjectFinishedEvents.Add((ProjectFinishedEventArgs)eventArgs);
                }
                else if (eventArgs is TargetStartedEventArgs)
                {
                    TargetStartedEvents.Add((TargetStartedEventArgs)eventArgs);
                }
                else if (eventArgs is TargetFinishedEventArgs)
                {
                    TargetFinishedEvents.Add((TargetFinishedEventArgs)eventArgs);
                }
                else if (eventArgs is TaskStartedEventArgs)
                {
                    TaskStartedEvents.Add((TaskStartedEventArgs)eventArgs);
                }
                else if (eventArgs is TaskFinishedEventArgs)
                {
                    TaskFinishedEvents.Add((TaskFinishedEventArgs)eventArgs);
                }
                else if (eventArgs is BuildMessageEventArgs)
                {
                    BuildMessageEvents.Add((BuildMessageEventArgs)eventArgs);
                }
                else if (eventArgs is BuildStartedEventArgs)
                {
                    BuildStartedEvents.Add((BuildStartedEventArgs)eventArgs);
                }
                else if (eventArgs is BuildFinishedEventArgs)
                {
                    BuildFinishedEvents.Add((BuildFinishedEventArgs)eventArgs);

                    if (!AllowTaskCrashes)
                    {
                        // We should not have any task crashes. Sometimes a test will validate that their expected error
                        // code appeared, but not realize it then crashed.
                        AssertLogDoesntContain("MSB4018");
                    }

                    // We should not have any Engine crashes.
                    AssertLogDoesntContain("MSB0001");

                    // Console.Write in the context of a unit test is very expensive.  A hundred
                    // calls to Console.Write can easily take two seconds on a fast machine.  Therefore, only
                    // do the Console.Write once at the end of the build.
                    Console.Write(FullLog);
                }
            }
        }
Exemple #24
0
 private void AllMessagesHandler(object sender, BuildEventArgs args)
 {
     all_messages.Add(args);
 }
 protected void anyEventRaised(object sender, BuildEventArgs e)
 {
     Log.Info(e.Message);
 }
Exemple #26
0
 public void ForwardEvent(BuildEventArgs buildEvent)
 {
     _buildEvents.Add(buildEvent);
 }
Exemple #27
0
        /// <summary>
        /// Enumerate over all records in the file. For each record store the bytes,
        /// the start position in the stream, length in bytes and the deserialized object.
        /// </summary>
        /// <remarks>Useful for debugging and analyzing binary logs</remarks>
        public IEnumerable <Record> ReadRecords(string sourceFilePath)
        {
            using (var stream = new FileStream(sourceFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var gzipStream   = new GZipStream(stream, CompressionMode.Decompress, leaveOpen: true);
                var memoryStream = new MemoryStream();
                gzipStream.CopyTo(memoryStream);
                memoryStream.Position = 0;

                var binaryReader = new BinaryReader(memoryStream);
                var bytes        = memoryStream.ToArray();

                int fileFormatVersion = binaryReader.ReadInt32();

                // the log file is written using a newer version of file format
                // that we don't know how to read
                if (fileFormatVersion > BinaryLogger.FileFormatVersion)
                {
                    var text = $"Unsupported log file format. Latest supported version is {BinaryLogger.FileFormatVersion}, the log file has version {fileFormatVersion}.";
                    throw new NotSupportedException(text);
                }

                long index = memoryStream.Position;
                long lengthOfBlobsAddedLastTime = 0;

                List <Record> blobs = new List <Record>();

                var reader = new BuildEventArgsReader(binaryReader, fileFormatVersion);
                reader.OnBlobRead += (kind, blob) =>
                {
                    var record = new Record
                    {
                        Bytes  = blob,
                        Args   = null,
                        Start  = index,
                        Length = blob.Length
                    };

                    blobs.Add(record);
                    lengthOfBlobsAddedLastTime += blob.Length;
                };

                while (true)
                {
                    BuildEventArgs instance = null;

                    instance = reader.Read();
                    if (instance == null)
                    {
                        break;
                    }

                    var position = memoryStream.Position;
                    var length   = position - index - lengthOfBlobsAddedLastTime;

                    var chunk = new byte[length];
                    Array.Copy(bytes, (int)(index + lengthOfBlobsAddedLastTime), chunk, 0, (int)length);
                    var record = new Record
                    {
                        Bytes  = chunk,
                        Args   = instance,
                        Start  = index,
                        Length = length
                    };

                    yield return(record);

                    index = position;
                    lengthOfBlobsAddedLastTime = 0;
                }

                foreach (var blob in blobs)
                {
                    yield return(blob);
                }
            }
        }
        private void AnyEvent(object sender, BuildEventArgs args)
        {
            if (args.BuildEventContext == null || args.BuildEventContext.EvaluationId == BuildEventContext.InvalidEvaluationId)
            {
                return;
            }

            switch (args)
            {
            case ProjectEvaluationStartedEventArgs evaluationStarted:
            {
                if (!DataSource.IsLogging || evaluationStarted.ProjectFile == "(null)")
                {
                    return;
                }

                var logPath      = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.binlog");
                var binaryLogger = new BinaryLogger
                {
                    Parameters            = logPath,
                    Verbosity             = LoggerVerbosity.Diagnostic,
                    CollectProjectImports = BinaryLogger.ProjectImportsCollectionMode.None
                };
                var wrapper = new EventWrapper(binaryLogger);
                var build   = new Build(evaluationStarted.ProjectFile, Array.Empty <string>(), Array.Empty <string>(),
                                        BuildType.Evaluation, args.Timestamp);
                _evaluations[evaluationStarted.BuildEventContext.EvaluationId] = new Evaluation
                {
                    Wrapper = wrapper,
                    Build   = build,
                    LogPath = logPath
                };
                wrapper.RaiseEvent(sender, args);
                DataSource.AddEntry(build);
            }
            break;

            case ProjectEvaluationFinishedEventArgs _:
            {
                if (_evaluations.TryGetValue(args.BuildEventContext.EvaluationId, out var evaluation))
                {
                    evaluation.Build.Finish(true, args.Timestamp);
                    evaluation.Wrapper.RaiseEvent(sender, args);
                    evaluation.Wrapper.BinaryLogger.Shutdown();
                    evaluation.Build.SetLogPath(GetLogPath(evaluation.Build));
                    Copy(evaluation.LogPath, evaluation.Build.LogPath);
                    DataSource.NotifyChange();
                }
            }
            break;

            default:
            {
                if (_evaluations.TryGetValue(args.BuildEventContext.EvaluationId, out var evaluation))
                {
                    evaluation.Wrapper.RaiseEvent(sender, args);
                }
            }
            break;
            }
        }
 protected async override void OnServiceEvent(object sender, BuildEventArgs e)
 {
     base.OnServiceEvent(sender, e);
     await AddBuildEventToLogsAsync(e);
 }
 private void EventSource_AnyEventRaised(object sender, BuildEventArgs e)
 {
     this.LoggedEvents.Add(e);
 }
Exemple #31
0
 private static void source_AnyEventRaised(object sender, BuildEventArgs e)
 {
     Log("{0}: {1}: {2}", e.Timestamp, e.SenderName, e.Message);
 }
Exemple #32
0
        /// <summary>
        /// Reads the logging packet from the translator.
        /// </summary>
        internal void ReadFromStream(INodePacketTranslator translator)
        {
            if (LoggingEventType.CustomEvent != _eventType)
            {
                _buildEvent = GetBuildEventArgFromId();

                // The other side is telling us whether the event knows how to log itself, or whether we're going to have
                // to do it manually
                int packetVersion = s_defaultPacketVersion;
                translator.Translate(ref packetVersion);

                bool eventCanSerializeItself = true;
                translator.Translate(ref eventCanSerializeItself);

                if (eventCanSerializeItself)
                {
                    MethodInfo methodInfo = null;
                    lock (s_readMethodCache)
                    {
                        if (!s_readMethodCache.TryGetValue(_eventType, out methodInfo))
                        {
                            Type eventDerivedType = _buildEvent.GetType();
                            methodInfo = eventDerivedType.GetMethod("CreateFromStream", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod);
                            s_readMethodCache.Add(_eventType, methodInfo);
                        }
                    }

                    ArgsReaderDelegate readerMethod = (ArgsReaderDelegate)CreateDelegateRobust(typeof(ArgsReaderDelegate), _buildEvent, methodInfo);

                    readerMethod(translator.Reader, packetVersion);
                    if (_eventType == LoggingEventType.TargetFinishedEvent && _targetFinishedTranslator != null)
                    {
                        _targetFinishedTranslator(translator, (TargetFinishedEventArgs)_buildEvent);
                    }
                }
                else
                {
                    _buildEvent = ReadEventFromStream(_eventType, translator);
                }
            }
            else
            {
                string fileLocation = null;
                translator.Translate(ref fileLocation);

                bool resolveAssembly = false;
                lock (s_lockObject)
                {
                    if (!s_customEventsLoaded.Contains(fileLocation))
                    {
                        resolveAssembly = true;
                    }

                    // If we are to resolve the assembly add it to the list of assemblies resolved
                    if (resolveAssembly)
                    {
                        s_customEventsLoaded.Add(fileLocation);
                    }
                }

                if (resolveAssembly)
                {
                    s_resolver = new TaskEngineAssemblyResolver();
                    s_resolver.InstallHandler();
                    s_resolver.Initialize(fileLocation);
                }

                try
                {
                    translator.TranslateDotNet(ref _buildEvent);
                }
                finally
                {
                    if (resolveAssembly)
                    {
                        s_resolver.RemoveHandler();
                        s_resolver = null;
                    }
                }
            }

            _eventType = GetLoggingEventId(_buildEvent);
        }
 private static CompilerInvocation TryGetInvocationFromRecord(BuildEventArgs args, Dictionary <(int, int), CompilerInvocation> taskIdToInvocationMap)
Exemple #34
0
 /// <summary>
 /// Raises the given event to all registered loggers. This method up-cast the events
 /// extracted from the queue.
 /// </summary>
 /// <param name="buildEvent">BuildEventArgs</param>
 /// <param name="sinkId">Note this is not used in the eventsource sink</param>
 public void Consume(BuildEventArgs buildEvent, int sinkId)
 {
     Consume(buildEvent);
 }
 /// <summary>
 /// Will Log a build Event. Will also take into account OnlyLogCriticalEvents when determining if to drop the event or to log it.
 /// </summary>
 /// <param name="buildEvent">The event to log</param>
 internal void LogBuildEvent(BuildEventArgs buildEvent)
 {
     ErrorUtilities.VerifyThrow(IsValid, "must be valid");
     LoggingService.LogBuildEvent(buildEvent);
 }
Exemple #36
0
 /// <summary>
 /// Raises the given event to all registered loggers. This method up-cast the events
 /// extracted from the queue.
 /// </summary>
 public void Consume(BuildEventArgs buildEvent)
 {
     // FXCop may complain that there are unecessary casts here, and there are, but
     // using "as" and allocating another variable for each event is extremely costly
     // and is much slower then this approach even with the additional casts
     if (buildEvent is BuildMessageEventArgs)
     {
         this.RaiseMessageEvent(null, (BuildMessageEventArgs)buildEvent);
     }
     else if (buildEvent is TaskStartedEventArgs)
     {
         this.RaiseTaskStartedEvent(null, (TaskStartedEventArgs)buildEvent);
     }
     else if (buildEvent is TaskFinishedEventArgs)
     {
         this.RaiseTaskFinishedEvent(null, (TaskFinishedEventArgs)buildEvent);
     }
     else if (buildEvent is TargetStartedEventArgs)
     {
         this.RaiseTargetStartedEvent(null, (TargetStartedEventArgs)buildEvent);
     }
     else if (buildEvent is TargetFinishedEventArgs)
     {
         this.RaiseTargetFinishedEvent(null, (TargetFinishedEventArgs)buildEvent);
     }
     else if (buildEvent is ProjectStartedEventArgs)
     {
         this.RaiseProjectStartedEvent(null, (ProjectStartedEventArgs)buildEvent);
     }
     else if (buildEvent is ProjectFinishedEventArgs)
     {
         this.RaiseProjectFinishedEvent(null, (ProjectFinishedEventArgs)buildEvent);
     }
     else if (buildEvent is BuildStartedEventArgs)
     {
         HaveLoggedBuildStartedEvent = true;
         this.RaiseBuildStartedEvent(null, (BuildStartedEventArgs)buildEvent);
     }
     else if (buildEvent is BuildFinishedEventArgs)
     {
         HaveLoggedBuildFinishedEvent = true;
         this.RaiseBuildFinishedEvent(null, (BuildFinishedEventArgs)buildEvent);
     }
     else if (buildEvent is CustomBuildEventArgs)
     {
         this.RaiseCustomEvent(null, (CustomBuildEventArgs)buildEvent);
     }
     else if (buildEvent is BuildStatusEventArgs)
     {
         this.RaiseStatusEvent(null, (BuildStatusEventArgs)buildEvent);
     }
     else if (buildEvent is BuildWarningEventArgs)
     {
         this.RaiseWarningEvent(null, (BuildWarningEventArgs)buildEvent);
     }
     else if (buildEvent is BuildErrorEventArgs)
     {
         this.RaiseErrorEvent(null, (BuildErrorEventArgs)buildEvent);
     }
     else if (buildEvent is TelemetryEventArgs)
     {
         this.RaiseTelemetryEvent(null, (TelemetryEventArgs)buildEvent);
     }
     else
     {
         ErrorUtilities.VerifyThrow(false, "Unknown event args type.");
     }
 }
Exemple #37
0
 /// <summary>
 /// Create an instance of this class wrapping given BuildEventArgs
 /// </summary>
 internal NodeLoggingEvent(BuildEventArgs eventToLog)
 {
     this.e = eventToLog;
 }