/// <summary> /// Stop the active connection, if available. Terminate the listening socket. /// </summary> public void Disconnect() { if (this._client != null) { this._client.Disconnect(false); } if (this._listener != null) { this._listener.Close(); } this._State = XdebugClientState.Uninitialized; }
/// <summary> /// Deal with the init-message xdebug sends us: /// - See if we seem to be compatible language wise /// - See if we're compatible protocol wise /// - Find the initial file and fire off a ConnectionInitialized "event" /// /// Returns true/false /// </summary> private bool handleInitMessage(XDebug.Response initMessage) { if (initMessage == null) { throw new Exception("Init message was empty."); } /* parse out the filename and check wether the version is * compatible with XdebugClient */ XmlElement d = initMessage.XmlMessage.DocumentElement; if (d.Attributes["protocol_version"] != null) { string remoteVersion = d.Attributes["protocol_version"].Value; if (remoteVersion != supportedProtocolVersion) { throw new Exception( String.Format( "Expected version '{0}' but got version '{1}' which is not supported.'", supportedProtocolVersion, remoteVersion ) ); } } if (d.Attributes["language"] != null) { string remoteLanguage = d.Attributes["language"].Value; if (remoteLanguage.ToLower() != supportedLanguage) { throw new Exception( String.Format( "Expected language '{0}' but got '{1}' which is not supported.", supportedLanguage, remoteLanguage ) ); } } if (d.Attributes["fileuri"] != null) { string absoluteFilename = this.getLocalFilename(d.Attributes["fileuri"].Value); XDebugEventArgs xea = new XDebugEventArgs(); xea.Filename = absoluteFilename; xea.EventType = XDebugEventType.ConnectionInitialized; if (this.EventCallback(xea)) { _State = XdebugClientState.Initialized; } else { return false; } } else { throw new Exception("Missing 'fileuri' attribute."); } return true; }
/// <summary> /// Send a run, step_over or step_in command. /// </summary> public void Run(string command) { XDebug.Command c = new Command(command, ""); XDebug.Response resp = this.SendCommand(c); string status = resp.XmlMessage.DocumentElement.Attributes["status"].Value; string reason = resp.XmlMessage.DocumentElement.Attributes["reason"].Value; this.StackDepth = 0; XDebugEventArgs e; if (reason == "exception") { XmlNode ErrorNode = resp.XmlMessage.DocumentElement.FirstChild; this._State = XdebugClientState.Stopped; e = new XDebugEventArgs(); e.EventType = XDebugEventType.ErrorOccured; e.ErrorMessage = ErrorNode.InnerText; switch ( ErrorNode.Attributes["exception"].Value ) { case Client.FatalErrorExceptionName: e.ErrorType = XDebugErrorType.FatalError; break; case Client.NoticeExceptionName: e.ErrorType = XDebugErrorType.Warning; break; default: throw new Exception("Unknown exception type"); } this.EventCallback(e); return; } else { switch (status) { case "break": /* execution stopped: breakpoint, step_over/step_in result, etc. */ this._State = XdebugClientState.Break; List<StackEntry> CallStack = this.GetCallStack(0); e = new XDebugEventArgs(); e.CurrentLocation = CallStack[0].Location; e.EventType = XDebugEventType.BreakpointHit; this.EventCallback(e); break; case "stopped": case "stopping": /* Script's done. */ this.Disconnect(); e = new XDebugEventArgs(); e.EventType = XDebugEventType.ScriptFinished; this.EventCallback(e); break; default: throw new Exception("Unknown status: " + status); } } }
/// <summary> /// Stop the active connection, if available. Terminate the listening socket. /// </summary> public void Disconnect() { if (this._client != null) this._client.Disconnect(false); if (this._listener != null) { this._listener.Close(); } this._State = XdebugClientState.Uninitialized; }
/// <summary> /// Deal with the init-message xdebug sends us: /// - See if we seem to be compatible language wise /// - See if we're compatible protocol wise /// - Find the initial file and fire off a ConnectionInitialized "event" /// /// Returns true/false /// </summary> private bool handleInitMessage(XDebug.Response initMessage) { if (initMessage == null) { throw new Exception("Init message was empty."); } /* parse out the filename and check wether the version is * compatible with XdebugClient */ XmlElement d = initMessage.XmlMessage.DocumentElement; if (d.Attributes["protocol_version"] != null) { string remoteVersion = d.Attributes["protocol_version"].Value; if (remoteVersion != supportedProtocolVersion) { throw new Exception( String.Format( "Expected version '{0}' but got version '{1}' which is not supported.'", supportedProtocolVersion, remoteVersion ) ); } } if (d.Attributes["language"] != null) { string remoteLanguage = d.Attributes["language"].Value; if (remoteLanguage.ToLower() != supportedLanguage) { throw new Exception( String.Format( "Expected language '{0}' but got '{1}' which is not supported.", supportedLanguage, remoteLanguage ) ); } } if (d.Attributes["fileuri"] != null) { string absoluteFilename = this.getLocalFilename(d.Attributes["fileuri"].Value); XDebugEventArgs xea = new XDebugEventArgs(); xea.Filename = absoluteFilename; xea.EventType = XDebugEventType.ConnectionInitialized; if (this.EventCallback(xea)) { _State = XdebugClientState.Initialized; } else { return(false); } } else { throw new Exception("Missing 'fileuri' attribute."); } return(true); }
/// <summary> /// Send a run, step_over or step_in command. /// </summary> public void Run(string command) { XDebug.Command c = new Command(command, ""); XDebug.Response resp = this.SendCommand(c); string status = resp.XmlMessage.DocumentElement.Attributes["status"].Value; string reason = resp.XmlMessage.DocumentElement.Attributes["reason"].Value; this.StackDepth = 0; XDebugEventArgs e; if (reason == "exception") { XmlNode ErrorNode = resp.XmlMessage.DocumentElement.FirstChild; this._State = XdebugClientState.Stopped; e = new XDebugEventArgs(); e.EventType = XDebugEventType.ErrorOccured; e.ErrorMessage = ErrorNode.InnerText; switch (ErrorNode.Attributes["exception"].Value) { case Client.FatalErrorExceptionName: e.ErrorType = XDebugErrorType.FatalError; break; case Client.NoticeExceptionName: e.ErrorType = XDebugErrorType.Warning; break; default: throw new Exception("Unknown exception type"); } this.EventCallback(e); return; } else { switch (status) { case "break": /* execution stopped: breakpoint, step_over/step_in result, etc. */ this._State = XdebugClientState.Break; List <StackEntry> CallStack = this.GetCallStack(0); e = new XDebugEventArgs(); e.CurrentLocation = CallStack[0].Location; e.EventType = XDebugEventType.BreakpointHit; this.EventCallback(e); break; case "stopped": case "stopping": /* Script's done. */ this.Disconnect(); e = new XDebugEventArgs(); e.EventType = XDebugEventType.ScriptFinished; this.EventCallback(e); break; default: throw new Exception("Unknown status: " + status); } } }