Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Proposal]: Add overload for EventSource primitives #83751

Merged
merged 15 commits into from
Jun 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
agocke committed Mar 30, 2023
commit b9d9e26d4b8729a9832a0d5efc41d0e3ca684f5c
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,45 @@ public void LogData(TestData data)
}
}

[EventSource(Name = EventSourceName)]
private class PrimitiveOnlyEventSource : EventSource
{
public const string EventSourceName = "PrimitiveOnly";
public readonly static PrimitiveOnlyEventSource Log = new PrimitiveOnlyEventSource();

[Event(1)]
public void LogBoolInt(bool b1, int i1)
{
WriteEvent(1, b1, i1);
}

[Event(2)]
public void LogStringIntStringInt(string s1, int i1, string s2, int i2)
{
WriteEvent(2, s1, i1, s2, i2);
}
}

private class TestEventListener : EventListener
{
public ReadOnlyCollection<object> LogDataPayload { get; set; }

protected override void OnEventSourceCreated(EventSource eventSource)
{
if (eventSource.Name == TestEventSource.EventSourceName)
switch (eventSource.Name)
{
EnableEvents(eventSource, EventLevel.Verbose);
case TestEventSource.EventSourceName:
case PrimitiveOnlyEventSource.EventSourceName:
EnableEvents(eventSource, EventLevel.Verbose);
break;
}

base.OnEventSourceCreated(eventSource);
}

protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
if (eventData.EventName == "LogData")
{
LogDataPayload = eventData.Payload;
}

LogDataPayload = eventData.Payload;
base.OnEventWritten(eventData);
}
}
Expand All @@ -79,14 +97,23 @@ public static int Main()
};
TestEventSource.Log.LogData(testData);

if (listener.LogDataPayload?.Count == 2 &&
(int)listener.LogDataPayload[0] == testData.TestInt &&
(int)((IDictionary<string, object>)listener.LogDataPayload[1])["SubInt"] == testData.SubData.SubInt)
if (listener.LogDataPayload?.Count != 2 ||
(int)listener.LogDataPayload[0] != testData.TestInt ||
(int)((IDictionary<string, object>)listener.LogDataPayload[1])["SubInt"] != testData.SubData.SubInt)
{
return 100;
return -1;
}

return -1;
PrimitiveOnlyEventSource.Log.LogStringIntStringInt("a", 1, "b", 2);
if (listener.LogDataPayload?.Count != 4 ||
(string)listener.LogDataPayload[0] != "a" ||
(int)listener.LogDataPayload[1] != 1 ||
(string)listener.LogDataPayload[2] != "b" ||
(int)listener.LogDataPayload[3] != 2)
{
return -2;
}
}
return 100;
}
}