Пример #1
0
		///////////////////////////////////////////////////////////////

		private void OnHitsAdded (ResponseMessage r)
		{
			HitsAddedResponse response = (HitsAddedResponse) r;

			if (this.HitsAddedEvent != null)
				this.HitsAddedEvent (response);
		}
		private void OnIndexingStatus (ResponseMessage r)
		{
			IndexingStatusResponse response = (IndexingStatusResponse) r;

			if (this.IndexingStatusEvent != null)
				this.IndexingStatusEvent (response.Status);
		}
Пример #3
0
        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);
        }
Пример #4
0
 public ResponseWrapper(ResponseMessage response)
 {
     this.Message = response;
 }
Пример #5
0
		private void OnFinished (ResponseMessage r)
		{
			FinishedResponse response = (FinishedResponse) r;
	
			if (this.FinishedEvent != null)
				this.FinishedEvent (response);
		}
Пример #6
0
		private void OnSearchTerms (ResponseMessage r)
		{
			SearchTermResponse response = (SearchTermResponse) r;
			ProcessSearchTermResponse (response);
		}
Пример #7
0
		private void OnError (ResponseMessage r)
		{
			ErrorResponse response = (ErrorResponse) r;
			throw new ResponseMessageException (response);
		}
Пример #8
0
		public ResponseWrapper (ResponseMessage response)
		{
			this.Message = response;
		}
Пример #9
0
		protected void SendAsyncResponse (ResponseMessage response)
		{
			if (this.AsyncResponseEvent != null)
				this.AsyncResponseEvent (response);
		}
Пример #10
0
		private void OnAsyncResponse (ResponseMessage response)
		{
			AsyncResponseHandler async_response = (AsyncResponseHandler) this.handlers [response.GetType ()];

			if (async_response != null) {
				async_response (response);
			}
		}
Пример #11
0
		private void SnippetResponseReceived (ResponseMessage response)
		{
			// The returned snippet uses <font color="..."><b>blah</b></font>
			// to mark matches. The rest of the snippet might be HTML, or
			// it might be plain text, including unescaped '<'s and '&'s.
			// So we escape it, fix the match highlighting, and leave any
			// other tags escaped.

			// FIXME: Use the new snippeting framework
			
			snippet = GLib.Markup.EscapeText (((SnippetResponse)response).Snippet);
			snippet = Regex.Replace (snippet, "&lt;font color=&quot;.*?&quot;&gt;&lt;b&gt;(.*?)&lt;/b&gt;&lt;/font&gt;", "<b>$1</b>");
			if (snippet.Trim ().Length > 0)
				EmitGotSnippet ();
		}
Пример #12
0
			public EventThrowingClosure (Transport transport, ResponseMessage response)
			{
				this.transport = transport;
				this.response = response;
			}
Пример #13
0
		protected void InvokeAsyncResponseEvent (ResponseMessage response)
		{
			if (AsyncResponse != null)
				AsyncResponse (response);
		}