private void Write(TaskCommandLineEventArgs e) { Write(BinaryLogRecordKind.TaskCommandLine); WriteMessageFields(e); WriteOptionalString(e.CommandLine); WriteOptionalString(e.TaskName); }
/// <summary> /// Handler for a TaskCommandLine log event. Sets the command line arguments on the appropriate task. /// </summary> /// <param name="args">The <see cref="TaskCommandLineEventArgs"/> instance containing the event data.</param> public bool AddCommandLine(TaskCommandLineEventArgs args) { var buildEventContext = args.BuildEventContext; if (buildEventContext.ProjectContextId == BuildEventContext.InvalidProjectContextId || buildEventContext.TargetId == BuildEventContext.InvalidTargetId || buildEventContext.TaskId == BuildEventContext.InvalidTaskId) { return(false); } var project = construction.GetOrAddProject(args.BuildEventContext.ProjectContextId); var target = project.GetTargetById(args.BuildEventContext.TargetId); // task can be null as per https://github.com/KirillOsenkov/MSBuildStructuredLog/issues/136 var task = target.GetTaskById(args.BuildEventContext.TaskId); if (task != null) { task.CommandLineArguments = stringTable.Intern(args.CommandLine); return(true); } return(false); }
private void Write(TaskCommandLineEventArgs e) { Write(BinaryLogRecordKind.TaskCommandLine); WriteMessageFields(e, writeMessage: false, writeImportance: true); WriteDeduplicatedString(e.CommandLine); WriteDeduplicatedString(e.TaskName); }
public void VerifyEventType() { BuildFinishedEventArgs buildFinished = new BuildFinishedEventArgs("Message", "Keyword", true); BuildStartedEventArgs buildStarted = new BuildStartedEventArgs("Message", "Help"); BuildMessageEventArgs lowMessage = new BuildMessageEventArgs("Message", "help", "sender", MessageImportance.Low); TaskStartedEventArgs taskStarted = new TaskStartedEventArgs("message", "help", "projectFile", "taskFile", "taskName"); TaskFinishedEventArgs taskFinished = new TaskFinishedEventArgs("message", "help", "projectFile", "taskFile", "taskName", true); TaskCommandLineEventArgs commandLine = new TaskCommandLineEventArgs("commandLine", "taskName", MessageImportance.Low); BuildWarningEventArgs warning = new BuildWarningEventArgs("SubCategoryForSchemaValidationErrors", "MSB4000", "file", 1, 2, 3, 4, "message", "help", "sender"); BuildErrorEventArgs error = new BuildErrorEventArgs("SubCategoryForSchemaValidationErrors", "MSB4000", "file", 1, 2, 3, 4, "message", "help", "sender"); TargetStartedEventArgs targetStarted = new TargetStartedEventArgs("message", "help", "targetName", "ProjectFile", "targetFile"); TargetFinishedEventArgs targetFinished = new TargetFinishedEventArgs("message", "help", "targetName", "ProjectFile", "targetFile", true); ProjectStartedEventArgs projectStarted = new ProjectStartedEventArgs(-1, "message", "help", "ProjectFile", "targetNames", null, null, null); ProjectFinishedEventArgs projectFinished = new ProjectFinishedEventArgs("message", "help", "ProjectFile", true); ExternalProjectStartedEventArgs externalStartedEvent = new ExternalProjectStartedEventArgs("message", "help", "senderName", "projectFile", "targetNames"); VerifyLoggingPacket(buildFinished, LoggingEventType.BuildFinishedEvent); VerifyLoggingPacket(buildStarted, LoggingEventType.BuildStartedEvent); VerifyLoggingPacket(lowMessage, LoggingEventType.BuildMessageEvent); VerifyLoggingPacket(taskStarted, LoggingEventType.TaskStartedEvent); VerifyLoggingPacket(taskFinished, LoggingEventType.TaskFinishedEvent); VerifyLoggingPacket(commandLine, LoggingEventType.TaskCommandLineEvent); VerifyLoggingPacket(warning, LoggingEventType.BuildWarningEvent); VerifyLoggingPacket(error, LoggingEventType.BuildErrorEvent); VerifyLoggingPacket(targetStarted, LoggingEventType.TargetStartedEvent); VerifyLoggingPacket(targetFinished, LoggingEventType.TargetFinishedEvent); VerifyLoggingPacket(projectStarted, LoggingEventType.ProjectStartedEvent); VerifyLoggingPacket(projectFinished, LoggingEventType.ProjectFinishedEvent); VerifyLoggingPacket(externalStartedEvent, LoggingEventType.CustomEvent); }
/// <summary> /// Handler for a TaskCommandLine log event. Sets the command line arguments on the appropriate task. /// </summary> /// <param name="args">The <see cref="TaskCommandLineEventArgs"/> instance containing the event data.</param> public void AddCommandLine(TaskCommandLineEventArgs args) { var project = construction.GetOrAddProject(args.BuildEventContext.ProjectContextId); var target = project.GetTargetById(args.BuildEventContext.TargetId); var task = target.GetTaskById(args.BuildEventContext.TaskId); task.CommandLineArguments = stringTable.Intern(args.CommandLine); }
public void LogCommandLine(TaskCommandLineEventArgs eventArgs) { Console.WriteLine(eventArgs.Message); _log += eventArgs.Message; _log += "\n"; _upperLog = null; ++_commandLine; }
/// <summary> /// Handler for a TaskCommandLine log event. Sets the command line arguments on the appropriate task. /// </summary> /// <param name="taskCommandLineEventArgs">The <see cref="TaskCommandLineEventArgs"/> instance containing the event data.</param> public void AddCommandLine(TaskCommandLineEventArgs taskCommandLineEventArgs) { var project = GetOrAddProject(taskCommandLineEventArgs.BuildEventContext.ProjectContextId); var target = project.GetTargetById(taskCommandLineEventArgs.BuildEventContext.TargetId); var task = target.GetTaskById(taskCommandLineEventArgs.BuildEventContext.TaskId); task.CommandLineArguments = taskCommandLineEventArgs.CommandLine; }
void eventSource_MessageRaised(object sender, BuildMessageEventArgs e) { if (e.GetType() == typeof(TaskCommandLineEventArgs)) { TaskCommandLineEventArgs cl = (TaskCommandLineEventArgs)e; MFuVisionGenerator.EnqueueItem(cl.Message, Directory.GetCurrentDirectory(), this.ProjectBuildContext); } }
public void EventArgsCtors() { TaskCommandLineEventArgs taskCommandLineEvent = new TaskCommandLineEventArgs2(); taskCommandLineEvent = new TaskCommandLineEventArgs("Commandline", "taskName", MessageImportance.High); taskCommandLineEvent = new TaskCommandLineEventArgs("Commandline", "taskName", MessageImportance.High, DateTime.Now); taskCommandLineEvent = new TaskCommandLineEventArgs(null, null, MessageImportance.High); taskCommandLineEvent = new TaskCommandLineEventArgs(null, null, MessageImportance.High, DateTime.Now); }
public void LogCommandLine(MessageImportance importance, string commandLine) { ErrorUtilities.VerifyThrowArgumentNull(commandLine, "commandLine"); TaskCommandLineEventArgs e = new TaskCommandLineEventArgs(commandLine, this.TaskName, importance); if (this.BuildEngine == null) { ErrorUtilities.ThrowInvalidOperation("LoggingBeforeTaskInitialization", new object[] { e.Message }); } this.BuildEngine.LogMessageEvent(e); }
public void TestAssignment() { string commandLine = "commandLine"; string taskName = "taskName"; MessageImportance importance = MessageImportance.High; TaskCommandLineEventArgs tcle = new TaskCommandLineEventArgs(commandLine, taskName, importance); Assert.AreEqual(commandLine, tcle.CommandLine, "A1"); Assert.AreEqual(taskName, tcle.TaskName, "A2"); Assert.AreEqual(commandLine, tcle.Message, "A3"); }
/// <summary> /// Write Task Command Line log message into the translator /// </summary> private void WriteTaskCommandLineEventToStream(TaskCommandLineEventArgs taskCommandLineEventArgs, ITranslator translator) { MessageImportance importance = taskCommandLineEventArgs.Importance; translator.TranslateEnum(ref importance, (int)importance); string commandLine = taskCommandLineEventArgs.CommandLine; translator.Translate(ref commandLine); string taskName = taskCommandLineEventArgs.TaskName; translator.Translate(ref taskName); }
private BuildEventArgs ReadTaskCommandLineEventArgs() { var fields = ReadBuildEventArgsFields(); var importance = (MessageImportance)ReadInt32(); var commandLine = ReadOptionalString(); var taskName = ReadOptionalString(); var e = new TaskCommandLineEventArgs( commandLine, taskName, importance, fields.Timestamp); e.BuildEventContext = fields.BuildEventContext; e.ProjectFile = fields.ProjectFile; return(e); }
/// <summary> /// Read and reconstruct a TaskCommandLineEventArgs from the stream /// </summary> private TaskCommandLineEventArgs ReadTaskCommandLineEventFromStream(ITranslator translator, string message, string helpKeyword, string senderName) { MessageImportance importance = MessageImportance.Normal; translator.TranslateEnum(ref importance, (int)importance); string commandLine = null; translator.Translate(ref commandLine); string taskName = null; translator.Translate(ref taskName); TaskCommandLineEventArgs buildEvent = new TaskCommandLineEventArgs(commandLine, taskName, importance); return(buildEvent); }
public void RoundtripTaskCommandLineEventArgs() { var args = new TaskCommandLineEventArgs( "/bl /noconlog /v:diag", "Csc", MessageImportance.Low, DateTime.Parse("12/12/2015 06:11:56 PM")); Roundtrip(args, e => e.CommandLine, e => e.TaskName, e => e.Importance.ToString(), e => e.EndLineNumber.ToString(), e => e.File, e => e.LineNumber.ToString(), e => e.Message, e => e.ProjectFile, e => e.Subcategory); }
private BuildEventArgs ReadTaskCommandLineEventArgs() { BuildEventArgsFields fields = ReadBuildEventArgsFields(); MessageImportance importance = (MessageImportance)ReadInt32(); string commandLine = ReadOptionalString(); string taskName = ReadOptionalString(); TaskCommandLineEventArgs e = new TaskCommandLineEventArgs( commandLine, taskName, importance, fields.Timestamp) { BuildEventContext = fields.BuildEventContext, ProjectFile = fields.ProjectFile }; return(e); }
/// <summary> /// Handler for a TaskCommandLine log event. Sets the command line arguments on the appropriate task. /// </summary> /// <param name="args">The <see cref="TaskCommandLineEventArgs"/> instance containing the event data.</param> public bool AddCommandLine(TaskCommandLineEventArgs args) { var buildEventContext = args.BuildEventContext; if (buildEventContext.ProjectContextId == BuildEventContext.InvalidProjectContextId || buildEventContext.TargetId == BuildEventContext.InvalidTargetId || buildEventContext.TaskId == BuildEventContext.InvalidTaskId) { return(false); } // task can be null as per https://github.com/KirillOsenkov/MSBuildStructuredLog/issues/136 var task = GetTask(args); if (task != null) { task.CommandLineArguments = Intern(args.CommandLine); return(true); } return(false); }
/// <summary> /// Compares two LogMessagePacket objects for equivalence. /// </summary> private void CompareLogMessagePackets(LogMessagePacket left, LogMessagePacket right) { Assert.AreEqual(left.EventType, right.EventType); Assert.AreEqual(left.NodeBuildEvent.Value.Value.GetType(), right.NodeBuildEvent.Value.Value.GetType()); CompareNodeBuildEventArgs(left.NodeBuildEvent.Value, right.NodeBuildEvent.Value, left.EventType == LoggingEventType.CustomEvent /* expectInvalidBuildEventContext */); switch (left.EventType) { case LoggingEventType.BuildErrorEvent: BuildErrorEventArgs leftError = left.NodeBuildEvent.Value.Value as BuildErrorEventArgs; BuildErrorEventArgs rightError = right.NodeBuildEvent.Value.Value as BuildErrorEventArgs; Assert.IsNotNull(leftError); Assert.IsNotNull(rightError); Assert.AreEqual(leftError.Code, rightError.Code); Assert.AreEqual(leftError.ColumnNumber, rightError.ColumnNumber); Assert.AreEqual(leftError.EndColumnNumber, rightError.EndColumnNumber); Assert.AreEqual(leftError.EndLineNumber, rightError.EndLineNumber); Assert.AreEqual(leftError.File, rightError.File); Assert.AreEqual(leftError.LineNumber, rightError.LineNumber); Assert.AreEqual(leftError.Message, rightError.Message); Assert.AreEqual(leftError.Subcategory, rightError.Subcategory); break; case LoggingEventType.BuildFinishedEvent: BuildFinishedEventArgs leftFinished = left.NodeBuildEvent.Value.Value as BuildFinishedEventArgs; BuildFinishedEventArgs rightFinished = right.NodeBuildEvent.Value.Value as BuildFinishedEventArgs; Assert.IsNotNull(leftFinished); Assert.IsNotNull(rightFinished); Assert.AreEqual(leftFinished.Succeeded, rightFinished.Succeeded); break; case LoggingEventType.BuildMessageEvent: BuildMessageEventArgs leftMessage = left.NodeBuildEvent.Value.Value as BuildMessageEventArgs; BuildMessageEventArgs rightMessage = right.NodeBuildEvent.Value.Value as BuildMessageEventArgs; Assert.IsNotNull(leftMessage); Assert.IsNotNull(rightMessage); Assert.AreEqual(leftMessage.Importance, rightMessage.Importance); break; case LoggingEventType.BuildStartedEvent: BuildStartedEventArgs leftBuildStart = left.NodeBuildEvent.Value.Value as BuildStartedEventArgs; BuildStartedEventArgs rightBuildStart = right.NodeBuildEvent.Value.Value as BuildStartedEventArgs; Assert.IsNotNull(leftBuildStart); Assert.IsNotNull(rightBuildStart); break; case LoggingEventType.BuildWarningEvent: BuildWarningEventArgs leftBuildWarn = left.NodeBuildEvent.Value.Value as BuildWarningEventArgs; BuildWarningEventArgs rightBuildWarn = right.NodeBuildEvent.Value.Value as BuildWarningEventArgs; Assert.IsNotNull(leftBuildWarn); Assert.IsNotNull(rightBuildWarn); Assert.AreEqual(leftBuildWarn.Code, rightBuildWarn.Code); Assert.AreEqual(leftBuildWarn.ColumnNumber, rightBuildWarn.ColumnNumber); Assert.AreEqual(leftBuildWarn.EndColumnNumber, rightBuildWarn.EndColumnNumber); Assert.AreEqual(leftBuildWarn.EndLineNumber, rightBuildWarn.EndLineNumber); Assert.AreEqual(leftBuildWarn.File, rightBuildWarn.File); Assert.AreEqual(leftBuildWarn.LineNumber, rightBuildWarn.LineNumber); Assert.AreEqual(leftBuildWarn.Subcategory, rightBuildWarn.Subcategory); break; case LoggingEventType.CustomEvent: ExternalProjectStartedEventArgs leftCustom = left.NodeBuildEvent.Value.Value as ExternalProjectStartedEventArgs; ExternalProjectStartedEventArgs rightCustom = right.NodeBuildEvent.Value.Value as ExternalProjectStartedEventArgs; Assert.IsNotNull(leftCustom); Assert.IsNotNull(rightCustom); Assert.AreEqual(leftCustom.ProjectFile, rightCustom.ProjectFile); Assert.AreEqual(leftCustom.TargetNames, rightCustom.TargetNames); break; case LoggingEventType.ProjectFinishedEvent: ProjectFinishedEventArgs leftProjectFinished = left.NodeBuildEvent.Value.Value as ProjectFinishedEventArgs; ProjectFinishedEventArgs rightProjectFinished = right.NodeBuildEvent.Value.Value as ProjectFinishedEventArgs; Assert.IsNotNull(leftProjectFinished); Assert.IsNotNull(rightProjectFinished); Assert.AreEqual(leftProjectFinished.ProjectFile, rightProjectFinished.ProjectFile); Assert.AreEqual(leftProjectFinished.Succeeded, rightProjectFinished.Succeeded); break; case LoggingEventType.ProjectStartedEvent: ProjectStartedEventArgs leftProjectStarted = left.NodeBuildEvent.Value.Value as ProjectStartedEventArgs; ProjectStartedEventArgs rightProjectStarted = right.NodeBuildEvent.Value.Value as ProjectStartedEventArgs; Assert.IsNotNull(leftProjectStarted); Assert.IsNotNull(rightProjectStarted); Assert.AreEqual(leftProjectStarted.ParentProjectBuildEventContext, rightProjectStarted.ParentProjectBuildEventContext); Assert.AreEqual(leftProjectStarted.ProjectFile, rightProjectStarted.ProjectFile); Assert.AreEqual(leftProjectStarted.ProjectId, rightProjectStarted.ProjectId); Assert.AreEqual(leftProjectStarted.TargetNames, rightProjectStarted.TargetNames); // UNDONE: (Serialization.) We don't actually serialize the items at this time. // Assert.AreEqual(leftProjectStarted.Items, rightProjectStarted.Items); // UNDONE: (Serialization.) We don't actually serialize properties at this time. // Assert.AreEqual(leftProjectStarted.Properties, rightProjectStarted.Properties); break; case LoggingEventType.TargetFinishedEvent: TargetFinishedEventArgs leftTargetFinished = left.NodeBuildEvent.Value.Value as TargetFinishedEventArgs; TargetFinishedEventArgs rightTargetFinished = right.NodeBuildEvent.Value.Value as TargetFinishedEventArgs; Assert.IsNotNull(leftTargetFinished); Assert.IsNotNull(rightTargetFinished); Assert.AreEqual(leftTargetFinished.ProjectFile, rightTargetFinished.ProjectFile); Assert.AreEqual(leftTargetFinished.Succeeded, rightTargetFinished.Succeeded); Assert.AreEqual(leftTargetFinished.TargetFile, rightTargetFinished.TargetFile); Assert.AreEqual(leftTargetFinished.TargetName, rightTargetFinished.TargetName); break; case LoggingEventType.TargetStartedEvent: TargetStartedEventArgs leftTargetStarted = left.NodeBuildEvent.Value.Value as TargetStartedEventArgs; TargetStartedEventArgs rightTargetStarted = right.NodeBuildEvent.Value.Value as TargetStartedEventArgs; Assert.IsNotNull(leftTargetStarted); Assert.IsNotNull(rightTargetStarted); Assert.AreEqual(leftTargetStarted.ProjectFile, rightTargetStarted.ProjectFile); Assert.AreEqual(leftTargetStarted.TargetFile, rightTargetStarted.TargetFile); Assert.AreEqual(leftTargetStarted.TargetName, rightTargetStarted.TargetName); break; case LoggingEventType.TaskCommandLineEvent: TaskCommandLineEventArgs leftCommand = left.NodeBuildEvent.Value.Value as TaskCommandLineEventArgs; TaskCommandLineEventArgs rightCommand = right.NodeBuildEvent.Value.Value as TaskCommandLineEventArgs; Assert.IsNotNull(leftCommand); Assert.IsNotNull(rightCommand); Assert.AreEqual(leftCommand.CommandLine, rightCommand.CommandLine); Assert.AreEqual(leftCommand.Importance, rightCommand.Importance); Assert.AreEqual(leftCommand.TaskName, rightCommand.TaskName); break; case LoggingEventType.TaskFinishedEvent: TaskFinishedEventArgs leftTaskFinished = left.NodeBuildEvent.Value.Value as TaskFinishedEventArgs; TaskFinishedEventArgs rightTaskFinished = right.NodeBuildEvent.Value.Value as TaskFinishedEventArgs; Assert.IsNotNull(leftTaskFinished); Assert.IsNotNull(rightTaskFinished); Assert.AreEqual(leftTaskFinished.ProjectFile, rightTaskFinished.ProjectFile); Assert.AreEqual(leftTaskFinished.Succeeded, rightTaskFinished.Succeeded); Assert.AreEqual(leftTaskFinished.TaskFile, rightTaskFinished.TaskFile); Assert.AreEqual(leftTaskFinished.TaskName, rightTaskFinished.TaskName); break; case LoggingEventType.TaskStartedEvent: TaskStartedEventArgs leftTaskStarted = left.NodeBuildEvent.Value.Value as TaskStartedEventArgs; TaskStartedEventArgs rightTaskStarted = right.NodeBuildEvent.Value.Value as TaskStartedEventArgs; Assert.IsNotNull(leftTaskStarted); Assert.IsNotNull(rightTaskStarted); Assert.AreEqual(leftTaskStarted.ProjectFile, rightTaskStarted.ProjectFile); Assert.AreEqual(leftTaskStarted.TaskFile, rightTaskStarted.TaskFile); Assert.AreEqual(leftTaskStarted.TaskName, rightTaskStarted.TaskName); break; default: Assert.Fail("Unexpected logging event type {0}", left.EventType); break; } }
public void TestLoggingEventCustomerSerialization() { Hashtable loggingTypeCacheWrites = new Hashtable(); stream.Position = 0; BuildEventContext context = new BuildEventContext(1, 3, 5, 7); GenericBuildEventArg genericBuildEvent = new GenericBuildEventArg("Message", "Help", "Sender"); genericBuildEvent.BuildEventContext = context; NodeLoggingEvent genericBuildEventLoggingEvent = new NodeLoggingEvent(genericBuildEvent); genericBuildEventLoggingEvent.WriteToStream(writer, loggingTypeCacheWrites); GenericCustomBuildEventArg genericCustomEvent = new GenericCustomBuildEventArg("FooFighter"); genericCustomEvent.BuildEventContext = context; NodeLoggingEvent genericCustomEventLoggingEvent = new NodeLoggingEvent(genericCustomEvent); genericCustomEventLoggingEvent.WriteToStream(writer, loggingTypeCacheWrites); BuildErrorEventArgs errorEvent = new BuildErrorEventArgs("Subcategory", "Code", "File", 1, 2, 3, 4, "Message", "HelpKeyword", "SenderName"); errorEvent.BuildEventContext = context; NodeLoggingEvent errorEventLoggingEvent = new NodeLoggingEvent(errorEvent); errorEventLoggingEvent.WriteToStream(writer, loggingTypeCacheWrites); BuildMessageEventArgs messageEvent = new BuildMessageEventArgs("Message", "HelpKeyword", "SenderName", MessageImportance.High); messageEvent.BuildEventContext = context; NodeLoggingEvent messageEventLoggingEvent = new NodeLoggingEvent(messageEvent); messageEventLoggingEvent.WriteToStream(writer, loggingTypeCacheWrites); BuildWarningEventArgs warningEvent = new BuildWarningEventArgs("Subcategory", "Code", "File", 1, 2, 3, 4, "Message", "HelpKeyword", "SenderName"); warningEvent.BuildEventContext = context; NodeLoggingEvent warningEventLoggingEvent = new NodeLoggingEvent(warningEvent); warningEventLoggingEvent.WriteToStream(writer, loggingTypeCacheWrites); ProjectStartedEventArgs projectStartedEvent = new ProjectStartedEventArgs(8, "Message", "HelpKeyword", "ProjectFile", "TargetNames", null, null, new BuildEventContext(7, 8, 9, 10)); projectStartedEvent.BuildEventContext = context; NodeLoggingEvent projectStartedEventLoggingEvent = new NodeLoggingEvent(projectStartedEvent); projectStartedEventLoggingEvent.WriteToStream(writer, loggingTypeCacheWrites); ProjectFinishedEventArgs projectFinishedEvent = new ProjectFinishedEventArgs("Message", "HelpKeyword", "ProjectFile", true); projectFinishedEvent.BuildEventContext = context; NodeLoggingEvent projectFinishedEventLoggingEvent = new NodeLoggingEvent(projectFinishedEvent); projectFinishedEventLoggingEvent.WriteToStream(writer, loggingTypeCacheWrites); TargetStartedEventArgs targetStartedEvent = new TargetStartedEventArgs("Message", "HelpKeyword", "TargetName", "ProjectFile", "TargetFile"); targetStartedEvent.BuildEventContext = context; NodeLoggingEvent targetStartedEventLoggingEvent = new NodeLoggingEvent(targetStartedEvent); targetStartedEventLoggingEvent.WriteToStream(writer, loggingTypeCacheWrites); TargetFinishedEventArgs targetFinished = new TargetFinishedEventArgs("Message", "HelpKeyword", "TargetName", "ProjectFile", "TargetFile", true); targetFinished.BuildEventContext = context; NodeLoggingEvent targetFinishedEventLoggingEvent = new NodeLoggingEvent(targetFinished); targetFinishedEventLoggingEvent.WriteToStream(writer, loggingTypeCacheWrites); TaskStartedEventArgs taskStartedEvent = new TaskStartedEventArgs("Message", "HelpKeyword", "ProjectFile", "TaskFile", "TaskName"); taskStartedEvent.BuildEventContext = context; NodeLoggingEvent taskStartedEventLoggingEvent = new NodeLoggingEvent(taskStartedEvent); taskStartedEventLoggingEvent.WriteToStream(writer, loggingTypeCacheWrites); TaskFinishedEventArgs taskFinishedEvent = new TaskFinishedEventArgs("Message", "HelpKeyword", "ProjectFile", "TaskFile", "TaskName", true); taskFinishedEvent.BuildEventContext = context; NodeLoggingEvent taskFinishedEventLoggingEvent = new NodeLoggingEvent(taskFinishedEvent); taskFinishedEventLoggingEvent.WriteToStream(writer, loggingTypeCacheWrites); BuildFinishedEventArgs buildFinishedEvent = new BuildFinishedEventArgs("Message", "Help", true); buildFinishedEvent.BuildEventContext = context; NodeLoggingEvent buildFinishedEventEventLoggingEvent = new NodeLoggingEvent(buildFinishedEvent); buildFinishedEventEventLoggingEvent.WriteToStream(writer, loggingTypeCacheWrites); BuildStartedEventArgs buildStartedEvent = new BuildStartedEventArgs("Message", "Help"); buildStartedEvent.BuildEventContext = context; NodeLoggingEvent buildStartedEventLoggingEvent = new NodeLoggingEvent(buildStartedEvent); buildStartedEventLoggingEvent.WriteToStream(writer, loggingTypeCacheWrites); TaskCommandLineEventArgs commandlineEventArg = new TaskCommandLineEventArgs("CommandLine", "TaskName", MessageImportance.High); commandlineEventArg.BuildEventContext = context; NodeLoggingEvent commandlineEventArgLoggingEvent = new NodeLoggingEvent(commandlineEventArg); commandlineEventArgLoggingEvent.WriteToStream(writer, loggingTypeCacheWrites); Hashtable loggingTypeCacheReads = new Hashtable(); long streamWriteEndPosition = stream.Position; stream.Position = 0; NodeLoggingEvent nodeLoggingEvent = new NodeLoggingEvent(null); nodeLoggingEvent.CreateFromStream(reader, loggingTypeCacheReads); Assert.IsTrue(nodeLoggingEvent.BuildEvent.GetType() == typeof(GenericBuildEventArg)); nodeLoggingEvent = new NodeLoggingEvent(null); nodeLoggingEvent.CreateFromStream(reader, loggingTypeCacheReads); Assert.IsTrue(nodeLoggingEvent.BuildEvent.GetType() == typeof(GenericCustomBuildEventArg)); nodeLoggingEvent = new NodeLoggingEvent(null); nodeLoggingEvent.CreateFromStream(reader, loggingTypeCacheReads); Assert.IsTrue(nodeLoggingEvent.BuildEvent.GetType() == typeof(BuildErrorEventArgs)); nodeLoggingEvent = new NodeLoggingEvent(null); nodeLoggingEvent.CreateFromStream(reader, loggingTypeCacheReads); Assert.IsTrue(nodeLoggingEvent.BuildEvent.GetType() == typeof(BuildMessageEventArgs)); nodeLoggingEvent = new NodeLoggingEvent(null); nodeLoggingEvent.CreateFromStream(reader, loggingTypeCacheReads); Assert.IsTrue(nodeLoggingEvent.BuildEvent.GetType() == typeof(BuildWarningEventArgs)); nodeLoggingEvent = new NodeLoggingEvent(null); nodeLoggingEvent.CreateFromStream(reader, loggingTypeCacheReads); Assert.IsTrue(nodeLoggingEvent.BuildEvent.GetType() == typeof(ProjectStartedEventArgs)); nodeLoggingEvent = new NodeLoggingEvent(null); nodeLoggingEvent.CreateFromStream(reader, loggingTypeCacheReads); Assert.IsTrue(nodeLoggingEvent.BuildEvent.GetType() == typeof(ProjectFinishedEventArgs)); nodeLoggingEvent = new NodeLoggingEvent(null); nodeLoggingEvent.CreateFromStream(reader, loggingTypeCacheReads); Assert.IsTrue(nodeLoggingEvent.BuildEvent.GetType() == typeof(TargetStartedEventArgs)); nodeLoggingEvent = new NodeLoggingEvent(null); nodeLoggingEvent.CreateFromStream(reader, loggingTypeCacheReads); Assert.IsTrue(nodeLoggingEvent.BuildEvent.GetType() == typeof(TargetFinishedEventArgs)); nodeLoggingEvent = new NodeLoggingEvent(null); nodeLoggingEvent.CreateFromStream(reader, loggingTypeCacheReads); Assert.IsTrue(nodeLoggingEvent.BuildEvent.GetType() == typeof(TaskStartedEventArgs)); nodeLoggingEvent = new NodeLoggingEvent(null); nodeLoggingEvent.CreateFromStream(reader, loggingTypeCacheReads); Assert.IsTrue(nodeLoggingEvent.BuildEvent.GetType() == typeof(TaskFinishedEventArgs)); nodeLoggingEvent = new NodeLoggingEvent(null); nodeLoggingEvent.CreateFromStream(reader, loggingTypeCacheReads); Assert.IsTrue(nodeLoggingEvent.BuildEvent.GetType() == typeof(BuildFinishedEventArgs)); nodeLoggingEvent = new NodeLoggingEvent(null); nodeLoggingEvent.CreateFromStream(reader, loggingTypeCacheReads); Assert.IsTrue(nodeLoggingEvent.BuildEvent.GetType() == typeof(BuildStartedEventArgs)); nodeLoggingEvent = new NodeLoggingEvent(null); nodeLoggingEvent.CreateFromStream(reader, loggingTypeCacheReads); Assert.IsTrue(nodeLoggingEvent.BuildEvent.GetType() == typeof(TaskCommandLineEventArgs)); long streamReadEndPosition = stream.Position; Assert.AreEqual(streamWriteEndPosition, streamReadEndPosition, "Expected Read and Write Positions to match"); }
public void LogCommandLine(TaskCommandLineEventArgs eventArgs) { Console.WriteLine(eventArgs.Message); _log.AppendLine(eventArgs.Message); ++_commandLine; }
private void CompareLogMessagePackets(LogMessagePacket left, LogMessagePacket right) { Assert.Equal(left.EventType, right.EventType); Assert.Equal(left.NodeBuildEvent.Value.Value.GetType(), right.NodeBuildEvent.Value.Value.GetType()); CompareNodeBuildEventArgs(left.NodeBuildEvent.Value, right.NodeBuildEvent.Value, left.EventType == LoggingEventType.CustomEvent /* expectInvalidBuildEventContext */); switch (left.EventType) { case LoggingEventType.BuildErrorEvent: BuildErrorEventArgs leftError = left.NodeBuildEvent.Value.Value as BuildErrorEventArgs; BuildErrorEventArgs rightError = right.NodeBuildEvent.Value.Value as BuildErrorEventArgs; Assert.NotNull(leftError); Assert.NotNull(rightError); Assert.Equal(leftError.Code, rightError.Code); Assert.Equal(leftError.ColumnNumber, rightError.ColumnNumber); Assert.Equal(leftError.EndColumnNumber, rightError.EndColumnNumber); Assert.Equal(leftError.EndLineNumber, rightError.EndLineNumber); Assert.Equal(leftError.File, rightError.File); Assert.Equal(leftError.LineNumber, rightError.LineNumber); Assert.Equal(leftError.Message, rightError.Message); Assert.Equal(leftError.Subcategory, rightError.Subcategory); break; case LoggingEventType.BuildFinishedEvent: BuildFinishedEventArgs leftFinished = left.NodeBuildEvent.Value.Value as BuildFinishedEventArgs; BuildFinishedEventArgs rightFinished = right.NodeBuildEvent.Value.Value as BuildFinishedEventArgs; Assert.NotNull(leftFinished); Assert.NotNull(rightFinished); Assert.Equal(leftFinished.Succeeded, rightFinished.Succeeded); break; case LoggingEventType.BuildMessageEvent: BuildMessageEventArgs leftMessage = left.NodeBuildEvent.Value.Value as BuildMessageEventArgs; BuildMessageEventArgs rightMessage = right.NodeBuildEvent.Value.Value as BuildMessageEventArgs; Assert.NotNull(leftMessage); Assert.NotNull(rightMessage); Assert.Equal(leftMessage.Importance, rightMessage.Importance); break; case LoggingEventType.BuildStartedEvent: BuildStartedEventArgs leftBuildStart = left.NodeBuildEvent.Value.Value as BuildStartedEventArgs; BuildStartedEventArgs rightBuildStart = right.NodeBuildEvent.Value.Value as BuildStartedEventArgs; Assert.NotNull(leftBuildStart); Assert.NotNull(rightBuildStart); break; case LoggingEventType.BuildWarningEvent: BuildWarningEventArgs leftBuildWarn = left.NodeBuildEvent.Value.Value as BuildWarningEventArgs; BuildWarningEventArgs rightBuildWarn = right.NodeBuildEvent.Value.Value as BuildWarningEventArgs; Assert.NotNull(leftBuildWarn); Assert.NotNull(rightBuildWarn); Assert.Equal(leftBuildWarn.Code, rightBuildWarn.Code); Assert.Equal(leftBuildWarn.ColumnNumber, rightBuildWarn.ColumnNumber); Assert.Equal(leftBuildWarn.EndColumnNumber, rightBuildWarn.EndColumnNumber); Assert.Equal(leftBuildWarn.EndLineNumber, rightBuildWarn.EndLineNumber); Assert.Equal(leftBuildWarn.File, rightBuildWarn.File); Assert.Equal(leftBuildWarn.LineNumber, rightBuildWarn.LineNumber); Assert.Equal(leftBuildWarn.Subcategory, rightBuildWarn.Subcategory); break; case LoggingEventType.CustomEvent: ExternalProjectStartedEventArgs leftCustom = left.NodeBuildEvent.Value.Value as ExternalProjectStartedEventArgs; ExternalProjectStartedEventArgs rightCustom = right.NodeBuildEvent.Value.Value as ExternalProjectStartedEventArgs; Assert.NotNull(leftCustom); Assert.NotNull(rightCustom); Assert.Equal(leftCustom.ProjectFile, rightCustom.ProjectFile); Assert.Equal(leftCustom.TargetNames, rightCustom.TargetNames); break; case LoggingEventType.ProjectFinishedEvent: ProjectFinishedEventArgs leftProjectFinished = left.NodeBuildEvent.Value.Value as ProjectFinishedEventArgs; ProjectFinishedEventArgs rightProjectFinished = right.NodeBuildEvent.Value.Value as ProjectFinishedEventArgs; Assert.NotNull(leftProjectFinished); Assert.NotNull(rightProjectFinished); Assert.Equal(leftProjectFinished.ProjectFile, rightProjectFinished.ProjectFile); Assert.Equal(leftProjectFinished.Succeeded, rightProjectFinished.Succeeded); break; case LoggingEventType.ProjectStartedEvent: ProjectStartedEventArgs leftProjectStarted = left.NodeBuildEvent.Value.Value as ProjectStartedEventArgs; ProjectStartedEventArgs rightProjectStarted = right.NodeBuildEvent.Value.Value as ProjectStartedEventArgs; Assert.NotNull(leftProjectStarted); Assert.NotNull(rightProjectStarted); Assert.Equal(leftProjectStarted.ParentProjectBuildEventContext, rightProjectStarted.ParentProjectBuildEventContext); Assert.Equal(leftProjectStarted.ProjectFile, rightProjectStarted.ProjectFile); Assert.Equal(leftProjectStarted.ProjectId, rightProjectStarted.ProjectId); Assert.Equal(leftProjectStarted.TargetNames, rightProjectStarted.TargetNames); // UNDONE: (Serialization.) We don't actually serialize the items at this time. // Assert.AreEqual(leftProjectStarted.Items, rightProjectStarted.Items); // UNDONE: (Serialization.) We don't actually serialize properties at this time. // Assert.AreEqual(leftProjectStarted.Properties, rightProjectStarted.Properties); break; case LoggingEventType.ProjectEvaluationStartedEvent: ProjectEvaluationStartedEventArgs leftEvaluationStarted = left.NodeBuildEvent.Value.Value as ProjectEvaluationStartedEventArgs; ProjectEvaluationStartedEventArgs rightEvaluationStarted = right.NodeBuildEvent.Value.Value as ProjectEvaluationStartedEventArgs; Assert.NotNull(leftEvaluationStarted); Assert.NotNull(rightEvaluationStarted); Assert.Equal(leftEvaluationStarted.ProjectFile, rightEvaluationStarted.ProjectFile); break; case LoggingEventType.ProjectEvaluationFinishedEvent: ProjectEvaluationFinishedEventArgs leftEvaluationFinished = left.NodeBuildEvent.Value.Value as ProjectEvaluationFinishedEventArgs; ProjectEvaluationFinishedEventArgs rightEvaluationFinished = right.NodeBuildEvent.Value.Value as ProjectEvaluationFinishedEventArgs; Assert.NotNull(leftEvaluationFinished); Assert.NotNull(rightEvaluationFinished); Assert.Equal(leftEvaluationFinished.ProjectFile, rightEvaluationFinished.ProjectFile); Assert.Equal(leftEvaluationFinished.ProfilerResult, rightEvaluationFinished.ProfilerResult); Assert.Equal( TranslationHelpers.GetPropertiesString(leftEvaluationFinished.GlobalProperties), TranslationHelpers.GetPropertiesString(rightEvaluationFinished.GlobalProperties)); Assert.Equal( TranslationHelpers.GetPropertiesString(leftEvaluationFinished.Properties), TranslationHelpers.GetPropertiesString(rightEvaluationFinished.Properties)); Assert.Equal( TranslationHelpers.GetMultiItemsString(leftEvaluationFinished.Items), TranslationHelpers.GetMultiItemsString(rightEvaluationFinished.Items)); break; case LoggingEventType.TargetFinishedEvent: TargetFinishedEventArgs leftTargetFinished = left.NodeBuildEvent.Value.Value as TargetFinishedEventArgs; TargetFinishedEventArgs rightTargetFinished = right.NodeBuildEvent.Value.Value as TargetFinishedEventArgs; Assert.NotNull(leftTargetFinished); Assert.NotNull(rightTargetFinished); Assert.Equal(leftTargetFinished.ProjectFile, rightTargetFinished.ProjectFile); Assert.Equal(leftTargetFinished.Succeeded, rightTargetFinished.Succeeded); Assert.Equal(leftTargetFinished.TargetFile, rightTargetFinished.TargetFile); Assert.Equal(leftTargetFinished.TargetName, rightTargetFinished.TargetName); // TODO: target output translation is a special case and is done in TranslateTargetFinishedEvent // Assert.Equal(leftTargetFinished.TargetOutputs, rightTargetFinished.TargetOutputs); break; case LoggingEventType.TargetStartedEvent: TargetStartedEventArgs leftTargetStarted = left.NodeBuildEvent.Value.Value as TargetStartedEventArgs; TargetStartedEventArgs rightTargetStarted = right.NodeBuildEvent.Value.Value as TargetStartedEventArgs; Assert.NotNull(leftTargetStarted); Assert.NotNull(rightTargetStarted); Assert.Equal(leftTargetStarted.ProjectFile, rightTargetStarted.ProjectFile); Assert.Equal(leftTargetStarted.TargetFile, rightTargetStarted.TargetFile); Assert.Equal(leftTargetStarted.TargetName, rightTargetStarted.TargetName); break; case LoggingEventType.TargetSkipped: TargetSkippedEventArgs leftTargetSkipped = left.NodeBuildEvent.Value.Value as TargetSkippedEventArgs; TargetSkippedEventArgs rightTargetSkipped = right.NodeBuildEvent.Value.Value as TargetSkippedEventArgs; Assert.Equal(leftTargetSkipped.BuildReason, rightTargetSkipped.BuildReason); Assert.Equal(leftTargetSkipped.SkipReason, rightTargetSkipped.SkipReason); Assert.Equal(leftTargetSkipped.BuildEventContext, rightTargetSkipped.BuildEventContext); Assert.Equal(leftTargetSkipped.OriginalBuildEventContext, rightTargetSkipped.OriginalBuildEventContext); Assert.Equal(leftTargetSkipped.Condition, rightTargetSkipped.Condition); Assert.Equal(leftTargetSkipped.EvaluatedCondition, rightTargetSkipped.EvaluatedCondition); Assert.Equal(leftTargetSkipped.Importance, rightTargetSkipped.Importance); Assert.Equal(leftTargetSkipped.OriginallySucceeded, rightTargetSkipped.OriginallySucceeded); Assert.Equal(leftTargetSkipped.ProjectFile, rightTargetSkipped.ProjectFile); Assert.Equal(leftTargetSkipped.TargetFile, rightTargetSkipped.TargetFile); Assert.Equal(leftTargetSkipped.TargetName, rightTargetSkipped.TargetName); Assert.Equal(leftTargetSkipped.ParentTarget, rightTargetSkipped.ParentTarget); break; case LoggingEventType.TaskCommandLineEvent: TaskCommandLineEventArgs leftCommand = left.NodeBuildEvent.Value.Value as TaskCommandLineEventArgs; TaskCommandLineEventArgs rightCommand = right.NodeBuildEvent.Value.Value as TaskCommandLineEventArgs; Assert.NotNull(leftCommand); Assert.NotNull(rightCommand); Assert.Equal(leftCommand.CommandLine, rightCommand.CommandLine); Assert.Equal(leftCommand.Importance, rightCommand.Importance); Assert.Equal(leftCommand.TaskName, rightCommand.TaskName); break; case LoggingEventType.TaskParameterEvent: var leftTaskParameter = left.NodeBuildEvent.Value.Value as TaskParameterEventArgs; var rightTaskParameter = right.NodeBuildEvent.Value.Value as TaskParameterEventArgs; Assert.NotNull(leftTaskParameter); Assert.NotNull(rightTaskParameter); Assert.Equal(leftTaskParameter.Kind, rightTaskParameter.Kind); Assert.Equal(leftTaskParameter.ItemType, rightTaskParameter.ItemType); Assert.Equal(leftTaskParameter.Items.Count, rightTaskParameter.Items.Count); Assert.Equal(leftTaskParameter.Message, rightTaskParameter.Message); Assert.Equal(leftTaskParameter.BuildEventContext, rightTaskParameter.BuildEventContext); Assert.Equal(leftTaskParameter.Timestamp, rightTaskParameter.Timestamp); Assert.Equal(leftTaskParameter.LineNumber, rightTaskParameter.LineNumber); Assert.Equal(leftTaskParameter.ColumnNumber, rightTaskParameter.ColumnNumber); break; case LoggingEventType.TaskFinishedEvent: TaskFinishedEventArgs leftTaskFinished = left.NodeBuildEvent.Value.Value as TaskFinishedEventArgs; TaskFinishedEventArgs rightTaskFinished = right.NodeBuildEvent.Value.Value as TaskFinishedEventArgs; Assert.NotNull(leftTaskFinished); Assert.NotNull(rightTaskFinished); Assert.Equal(leftTaskFinished.ProjectFile, rightTaskFinished.ProjectFile); Assert.Equal(leftTaskFinished.Succeeded, rightTaskFinished.Succeeded); Assert.Equal(leftTaskFinished.TaskFile, rightTaskFinished.TaskFile); Assert.Equal(leftTaskFinished.TaskName, rightTaskFinished.TaskName); break; case LoggingEventType.TaskStartedEvent: TaskStartedEventArgs leftTaskStarted = left.NodeBuildEvent.Value.Value as TaskStartedEventArgs; TaskStartedEventArgs rightTaskStarted = right.NodeBuildEvent.Value.Value as TaskStartedEventArgs; Assert.NotNull(leftTaskStarted); Assert.NotNull(rightTaskStarted); Assert.Equal(leftTaskStarted.ProjectFile, rightTaskStarted.ProjectFile); Assert.Equal(leftTaskStarted.TaskFile, rightTaskStarted.TaskFile); Assert.Equal(leftTaskStarted.TaskName, rightTaskStarted.TaskName); Assert.Equal(leftTaskStarted.LineNumber, rightTaskStarted.LineNumber); Assert.Equal(leftTaskStarted.ColumnNumber, rightTaskStarted.ColumnNumber); break; default: Assert.True(false, string.Format("Unexpected logging event type {0}", left.EventType)); break; } }
private void OnTaskCommandLine(TaskCommandLineEventArgs taskCommandLineEventArgs) => FindTaskContext(taskCommandLineEventArgs).SetCommandLineArguments(Intern(taskCommandLineEventArgs.CommandLine));
public async void OnTaskCommandLine(SolutionItem solutionItem, TaskCommandLineEventArgs e) { await MessageSinks[0].AddMessage(e); }