private void OnIndexingStatus (ResponseMessage r) { IndexingStatusResponse response = (IndexingStatusResponse) r; if (this.IndexingStatusEvent != null) this.IndexingStatusEvent (response.Status); }
/////////////////////////////////////////////////////////////// private void OnHitsAdded (ResponseMessage r) { HitsAddedResponse response = (HitsAddedResponse) r; if (this.HitsAddedEvent != null) this.HitsAddedEvent (response); }
public override ResponseMessage Send(RequestMessage request) { if (request.Keepalive) { throw new Exception("A blocking connection on a keepalive request is not allowed"); } Exception throw_me = null; try { SendRequest(request); } catch (IOException e) { throw_me = e; } catch (SocketException e) { throw_me = e; } if (throw_me != null) { throw new ResponseMessageException(throw_me); } NetworkStream stream = this.client.GetStream(); int bytes_read, end_index = -1; do { bytes_read = stream.Read(this.network_data, 0, 4096); //Logger.Log.Debug ("Read {0} bytes", bytes_read); if (bytes_read > 0) { // 0xff signifies end of message end_index = Array.IndexOf <byte> (this.network_data, (byte)0xff); this.BufferStream.Write(this.network_data, 0, end_index == -1 ? bytes_read : end_index); } } while (bytes_read > 0 && end_index == -1); // It's possible that the server side shut down the // connection before we had a chance to read any data. // If this is the case, throw a rather descriptive // exception. if (this.BufferStream.Length == 0) { this.BufferStream.Close(); throw new ResponseMessageException("Socket was closed before any data could be read"); } this.BufferStream.Seek(0, SeekOrigin.Begin); #if ENABLE_XML_DUMP StreamReader dump_reader = new StreamReader(this.BufferStream); Logger.Log.Debug("Received response:\n{0}\n", dump_reader.ReadToEnd()); this.BufferStream.Seek(0, SeekOrigin.Begin); #endif ResponseMessage resp = null; try { ResponseWrapper wrapper = (ResponseWrapper)resp_serializer.Deserialize(this.BufferStream); resp = wrapper.Message; } catch (Exception e) { this.BufferStream.Seek(0, SeekOrigin.Begin); StreamReader r = new StreamReader(this.BufferStream); throw_me = new ResponseMessageException(e, "Exception while deserializing response", String.Format("Message contents: '{0}'", r.ReadToEnd())); this.BufferStream.Seek(0, SeekOrigin.Begin); } this.BufferStream.Close(); if (throw_me != null) { throw throw_me; } return(resp); }
public ResponseWrapper (ResponseMessage response) { this.Message = response; }
protected void SendAsyncResponse (ResponseMessage response) { if (this.AsyncResponseEvent != null) this.AsyncResponseEvent (response); }
private void OnAsyncResponse (ResponseMessage response) { AsyncResponseHandler async_response = (AsyncResponseHandler) this.handlers [response.GetType ()]; if (async_response != null) { async_response (response); } }
public EventThrowingClosure (Transport transport, ResponseMessage response) { this.transport = transport; this.response = response; }
protected void InvokeAsyncResponseEvent (ResponseMessage response) { if (AsyncResponse != null) AsyncResponse (response); }
private void OnFinished (ResponseMessage r) { FinishedResponse response = (FinishedResponse) r; if (this.FinishedEvent != null) this.FinishedEvent (response); }
private void OnSearchTerms (ResponseMessage r) { SearchTermResponse response = (SearchTermResponse) r; ProcessSearchTermResponse (response); }
private void OnError (ResponseMessage r) { ErrorResponse response = (ErrorResponse) r; throw new ResponseMessageException (response); }