protected static void OnDebug(string from, string message) { DebugEventHandler?.Invoke(null, new DebugEventArgs() { From = from, Message = message }); }
public string[] Connect(string applicationName) { bool isNewApplication = false; // OperationContext.Current.Channel.Faulted += new EventHandler(OnFaulted); // OperationContext.Current.Channel.Closing += new EventHandler(OnClosing); if (string.IsNullOrEmpty(applicationName)) { throw new NullReferenceException("未填写参数信息: applicationName."); } debugEventHandler = new DebugEventHandler(MyEventHandler); lock (syncObject) { this.sessionId = OperationContext.Current.SessionId; this.applicationName = applicationName; if (!apps.ContainsKey(this.applicationName)) { apps.Add(this.sessionId, MyEventHandler); isNewApplication = true; } } if (isNewApplication) { callback = OperationContext.Current.GetCallbackChannel <IDebugServiceCallback>(); DebugEventArgs e = new DebugEventArgs(); e.ApplicationName = applicationName; e.Message = "连接到控制台.\r\n"; BroadcastMessage(e); DebugEvent += debugEventHandler; string[] list = new string[apps.Count]; lock (syncObject) { apps.Keys.CopyTo(list, 0); } return(list); } else { return(null); } }
private void BroadcastMessage(DebugEventArgs e) { DebugEventHandler temp = DebugEvent; if (temp != null) { foreach (DebugEventHandler handler in temp.GetInvocationList()) { handler.BeginInvoke(this, e, new AsyncCallback(BroadcastMessageCallback), null); } } }
private static void BroadcastMessageCallback(IAsyncResult result) { DebugEventHandler asyncDelegate = null; try { System.Runtime.Remoting.Messaging.AsyncResult asyncResult = (System.Runtime.Remoting.Messaging.AsyncResult)result; asyncDelegate = ((DebugEventHandler)asyncResult.AsyncDelegate); asyncDelegate.EndInvoke(result); } catch { DebugEvent -= asyncDelegate; } }
public static void WriteLine(string applicationName, string message) { DebugEventArgs e = new DebugEventArgs(); e.ApplicationName = applicationName; e.Message = message + Environment.NewLine; DebugEventHandler temp = DebugEvent; if (temp != null) { foreach (DebugEventHandler handler in temp.GetInvocationList()) { handler.BeginInvoke(null, e, new AsyncCallback(BroadcastMessageCallback), null); } } }
// Note that this method can be called from a thread other than the test main thread. public int HandleCallbackEvent(IDebugEngine2 pEngine, IDebugProcess2 pProcess, IDebugProgram2 pProgram, IDebugThread2 pThread, IDebugEvent2 pEvent) { if (pEvent is IDebugBreakpointEvent2 || pEvent is IDebugBreakEvent2 || pEvent is IDebugStepCompleteEvent2) { _queue.Push( _programStoppedJobFactory.Create(pEngine, pEvent, _debugSessionContext, pThread)); } else if (pEvent is IDebugProgramDestroyEvent2) { _queue.Push( _programTerminatedJobFactory.Create(pEngine, pEvent, _debugSessionContext)); } var pProgram3 = pProgram as IDebugProgram3; if (pProgram3 == null) { // TODO: Ensure program can be cast to IDebugProgram3 without // throwing across the COM/interop boundary. throw new NotSupportedException( "'pProgram' must be castable to type " + $"{nameof(IDebugProgram3)} but is of type {pProgram.GetType()}"); } _queue.Push(_broadcastDebugEventJobFactory.Create(() => { DebugEventHandler handler = DebugEvent; handler?.Invoke(new DebugEventArgs { DebugEngine = pEngine, Process = pProcess, Program = pProgram3, Thread = pThread, Event = pEvent }); }, pEvent)); return(VSConstants.S_OK); }
/// <summary> /// Constructor /// </summary> /// <param name="fileSecurityPassword">File security password for the buffered files sent</param> /// <param name="debugEvent">Debug event handler</param> public ActionCenter(string fileSecurityPassword, DebugEventHandler debugEvent) : this(fileSecurityPassword) { this.CaptureManagerModule.DebugEvent += new DebugEventHandler(debugEvent); }