private ProbedPath ParseKnownPathProbedEvent(Func <string, object> getData, Func <string, string> getDataString) { var probedPath = new ProbedPath() { FilePath = getDataString("FilePath"), Source = (ProbedPath.PathSource)getData("Source"), Result = (int)getData("Result"), }; return(probedPath); }
protected override void OnEventWritten(EventWrittenEventArgs data) { if (data.EventSource.Name != "Microsoft-Windows-DotNETRuntime") { return; } object GetData(string name) { int index = data.PayloadNames.IndexOf(name); return(index >= 0 ? data.Payload[index] : null); }; string GetDataString(string name) => GetData(name) as string; switch (data.EventName) { case "AssemblyLoadStart": { BindOperation bindOperation = ParseAssemblyLoadStartEvent(data, GetDataString); lock (eventsLock) { Assert.IsTrue(!bindOperations.ContainsKey(data.ActivityId), "AssemblyLoadStart should not exist for same activity ID "); bindOperation.Nested = bindOperations.ContainsKey(data.RelatedActivityId); bindOperations.Add(data.ActivityId, bindOperation); if (bindOperation.Nested) { bindOperations[data.RelatedActivityId].NestedBinds.Add(bindOperation); } } break; } case "AssemblyLoadStop": { lock (eventsLock) { Assert.IsTrue(bindOperations.ContainsKey(data.ActivityId), $"{data.EventName} should have a matching AssemblyBindStart"); BindOperation bind = bindOperations[data.ActivityId]; bind.Success = (bool)GetData("Success"); string resultName = GetDataString("ResultAssemblyName"); if (!string.IsNullOrEmpty(resultName)) { bind.ResultAssemblyName = new AssemblyName(resultName); } bind.ResultAssemblyPath = GetDataString("ResultAssemblyPath"); bind.Cached = (bool)GetData("Cached"); bind.Completed = true; } break; } case "ResolutionAttempted": { ResolutionAttempt attempt = ParseResolutionAttemptedEvent(GetData, GetDataString); lock (eventsLock) { Assert.IsTrue(bindOperations.ContainsKey(data.ActivityId), $"{data.EventName} should have a matching AssemblyBindStart"); BindOperation bind = bindOperations[data.ActivityId]; bind.ResolutionAttempts.Add(attempt); } break; } case "AssemblyLoadContextResolvingHandlerInvoked": { HandlerInvocation handlerInvocation = ParseHandlerInvokedEvent(GetDataString); lock (eventsLock) { Assert.IsTrue(bindOperations.ContainsKey(data.ActivityId), $"{data.EventName} should have a matching AssemblyBindStart"); BindOperation bind = bindOperations[data.ActivityId]; bind.AssemblyLoadContextResolvingHandlers.Add(handlerInvocation); } break; } case "AppDomainAssemblyResolveHandlerInvoked": { HandlerInvocation handlerInvocation = ParseHandlerInvokedEvent(GetDataString); lock (eventsLock) { Assert.IsTrue(bindOperations.ContainsKey(data.ActivityId), $"{data.EventName} should have a matching AssemblyBindStart"); BindOperation bind = bindOperations[data.ActivityId]; bind.AppDomainAssemblyResolveHandlers.Add(handlerInvocation); } break; } case "AssemblyLoadFromResolveHandlerInvoked": { LoadFromHandlerInvocation loadFrom = ParseLoadFromHandlerInvokedEvent(GetData, GetDataString); lock (eventsLock) { Assert.IsTrue(bindOperations.ContainsKey(data.ActivityId), $"{data.EventName} should have a matching AssemblyBindStart"); BindOperation bind = bindOperations[data.ActivityId]; bind.AssemblyLoadFromHandler = loadFrom; } break; } case "KnownPathProbed": { ProbedPath probedPath = ParseKnownPathProbedEvent(GetData, GetDataString); lock (eventsLock) { Assert.IsTrue(bindOperations.ContainsKey(data.ActivityId), $"{data.EventName} should have a matching AssemblyBindStart"); BindOperation bind = bindOperations[data.ActivityId]; bind.ProbedPaths.Add(probedPath); } break; } } }
protected override void OnEventWritten(EventWrittenEventArgs data) { if (data.EventSource.Name != "Microsoft-Windows-DotNETRuntime") { return; } object GetData(string name) { int index = data.PayloadNames.IndexOf(name); return(index >= 0 ? data.Payload[index] : null); }; string GetDataString(string name) => GetData(name) as string; switch (data.EventName) { case "AssemblyLoadStart": { BindOperation bindOperation = ParseAssemblyLoadStartEvent(data, GetDataString); if (!IsLoadToTrack(bindOperation.AssemblyName.Name)) { return; } lock (eventsLock) { Assert.IsTrue(!bindOperations.ContainsKey(data.ActivityId), "AssemblyLoadStart should not exist for same activity ID "); bindOperation.Nested = bindOperations.ContainsKey(data.RelatedActivityId); bindOperations.Add(data.ActivityId, bindOperation); if (bindOperation.Nested) { bindOperations[data.RelatedActivityId].NestedBinds.Add(bindOperation); } } break; } case "AssemblyLoadStop": { string assemblyName = GetDataString("AssemblyName"); if (!IsLoadToTrack(new AssemblyName(assemblyName).Name)) { return; } bool success = (bool)GetData("Success"); string resultName = GetDataString("ResultAssemblyName"); lock (eventsLock) { if (!bindOperations.ContainsKey(data.ActivityId)) { Assert.Fail(GetMissingAssemblyBindStartMessage(data, $"Success={success}, Name={resultName}")); } BindOperation bind = bindOperations[data.ActivityId]; bind.Success = success; if (!string.IsNullOrEmpty(resultName)) { bind.ResultAssemblyName = new AssemblyName(resultName); } bind.ResultAssemblyPath = GetDataString("ResultAssemblyPath"); bind.Cached = (bool)GetData("Cached"); bind.Completed = true; } break; } case "ResolutionAttempted": { ResolutionAttempt attempt = ParseResolutionAttemptedEvent(GetData, GetDataString); if (!IsLoadToTrack(attempt.AssemblyName.Name)) { return; } lock (eventsLock) { if (!bindOperations.ContainsKey(data.ActivityId)) { Assert.Fail(GetMissingAssemblyBindStartMessage(data, attempt.ToString())); } BindOperation bind = bindOperations[data.ActivityId]; bind.ResolutionAttempts.Add(attempt); } break; } case "AssemblyLoadContextResolvingHandlerInvoked": { HandlerInvocation handlerInvocation = ParseHandlerInvokedEvent(GetDataString); if (!IsLoadToTrack(handlerInvocation.AssemblyName.Name)) { return; } lock (eventsLock) { if (!bindOperations.ContainsKey(data.ActivityId)) { Assert.Fail(GetMissingAssemblyBindStartMessage(data, handlerInvocation.ToString())); } BindOperation bind = bindOperations[data.ActivityId]; bind.AssemblyLoadContextResolvingHandlers.Add(handlerInvocation); } break; } case "AppDomainAssemblyResolveHandlerInvoked": { HandlerInvocation handlerInvocation = ParseHandlerInvokedEvent(GetDataString); if (!IsLoadToTrack(handlerInvocation.AssemblyName.Name)) { return; } lock (eventsLock) { if (!bindOperations.ContainsKey(data.ActivityId)) { Assert.Fail(GetMissingAssemblyBindStartMessage(data, handlerInvocation.ToString())); } BindOperation bind = bindOperations[data.ActivityId]; bind.AppDomainAssemblyResolveHandlers.Add(handlerInvocation); } break; } case "AssemblyLoadFromResolveHandlerInvoked": { LoadFromHandlerInvocation loadFrom = ParseLoadFromHandlerInvokedEvent(GetData, GetDataString); if (!IsLoadToTrack(loadFrom.AssemblyName.Name)) { return; } lock (eventsLock) { if (!bindOperations.ContainsKey(data.ActivityId)) { Assert.Fail(GetMissingAssemblyBindStartMessage(data, loadFrom.ToString())); } BindOperation bind = bindOperations[data.ActivityId]; bind.AssemblyLoadFromHandler = loadFrom; } break; } case "KnownPathProbed": { ProbedPath probedPath = ParseKnownPathProbedEvent(GetData, GetDataString); string name = System.IO.Path.GetFileNameWithoutExtension(probedPath.FilePath); if (!IsLoadToTrack(name.EndsWith(".ni") ? name.Remove(name.Length - 3) : name)) { return; } lock (eventsLock) { if (!bindOperations.ContainsKey(data.ActivityId)) { Assert.Fail(GetMissingAssemblyBindStartMessage(data, probedPath.ToString())); } BindOperation bind = bindOperations[data.ActivityId]; bind.ProbedPaths.Add(probedPath); } break; } } }