private static bool DispatchInvocation(Invocation invocation) { DebugView.TraceEvent(IndentLevel.Dispatch, () => String.Format("Intercepted profiler call: {0}", invocation.InputToString())); DebugView.PrintStackTrace(); var mockMixin = invocation.MockMixin; var repo = mockMixin != null ? mockMixin.Repository : MockingContext.ResolveRepository(UnresolvedContextBehavior.CreateNewContextual); if (repo == null) { repo = TryFindGlobalInterceptor(invocation.Method); } if (repo == null) { return(false); } lock (repo) { repo.DispatchInvocation(invocation); } if (invocation.CallOriginal) { DebugView.TraceEvent(IndentLevel.DispatchResult, () => "Calling original implementation"); } else if (invocation.IsReturnValueSet) { DebugView.TraceEvent(IndentLevel.DispatchResult, () => String.Format("Returning value '{0}'", invocation.ReturnValue)); } return(true); }
public void TraceEvent(string message) { #if !PORTABLE if ((this.TraceOptions & TraceOptions.RemoteTrace) != 0) { try { if (MockingContext.Plugins.Exists <IDebugWindowPlugin>()) { // traces triggered by profiler intercepted calls and repository retirement // could cause deadlocks and infinite loops in remote tracing, so skip them var testMethod = MockingContext.GetTestMethod(); var repo = MockingContext.ResolveRepository(UnresolvedContextBehavior.DoNotCreateNew); if (testMethod != null && repo != null && !repo.IsRetired) { var debugWindowPlugin = MockingContext.Plugins.Get <IDebugWindowPlugin>(); debugWindowPlugin.TraceMessage(message); } } } catch (Exception e) { System.Diagnostics.Trace.WriteLine("Exception thrown calling IDebugWindowPlugin plugin: " + e); } } #endif if ((this.TraceOptions & TraceOptions.InternalTrace) != 0) { Debug.WriteLine(message); lock (this.traceSync) { this.log.AppendLine(message); if (this.currentTraceRead) { this.currentTraceRead = false; this.currentTrace.Length = 0; } this.currentTrace.AppendLine(message); } } }