Esempio n. 1
0
		public ResponseMessageException (ErrorResponse response)
			: base (response.ErrorMessage)
		{ 
			this.details = response.Details;
		}
Esempio n. 2
0
		public override void SendAsyncBlocking (RequestMessage request)
		{
			Exception ex = null;

			try {
				SendRequest (request);
			} catch (IOException e) {
				ex = e;
			} catch (SocketException e) {
				ex = e;
			}

			if (ex != null) {
				ResponseMessage resp = new ErrorResponse (ex);				
				InvokeAsyncResponseEvent (resp);
				return;
			}
			
			NetworkStream stream = this.client.GetStream ();
			MemoryStream deserialize_stream = new MemoryStream ();

			// This buffer is annoyingly small on purpose, to avoid
			// having to deal with the case of multiple messages
			// in a single block.
			byte [] buffer = new byte [32];

			while (!this.IsClosed) {

				Array.Clear (buffer, 0, buffer.Length);

				int bytes_read;
				bytes_read = stream.Read (buffer, 0, buffer.Length);
				if (bytes_read == 0)
					break;

				int end_index;
				end_index = Array.IndexOf<byte> (buffer, (byte) 0xff);

				if (end_index == -1) {
					deserialize_stream.Write (buffer, 0, bytes_read);
				} else {
					deserialize_stream.Write (buffer, 0, end_index);
					deserialize_stream.Seek (0, SeekOrigin.Begin);

#if ENABLE_XML_DUMP
					StreamReader r = new StreamReader (deserialize_stream);
					Logger.Log.Debug ("Received response:\n{0}\n", r.ReadToEnd ());
					deserialize_stream.Seek (0, SeekOrigin.Begin);
#endif

					ResponseMessage resp;
					try {
						ResponseWrapper wrapper;
						wrapper = (ResponseWrapper) resp_serializer.Deserialize (deserialize_stream);
						
						resp = wrapper.Message;
					} catch (Exception e) {
						resp = new ErrorResponse (e);
					}

					InvokeAsyncResponseEvent (resp);

					deserialize_stream.Close ();
					deserialize_stream = new MemoryStream ();
					if (bytes_read - end_index - 1 > 0)
						deserialize_stream.Write (buffer, end_index + 1, bytes_read - end_index - 1);
				}
			}
		}
Esempio n. 3
0
		public void SendAsync (RequestMessage request)
		{
			Exception exception = null;

			try {
				SendRequest (request);
			} catch (IOException e) {
				exception = e;
			} catch (SocketException e) {
				exception = e;
			}

			if (exception == null) {
				BeginRead ();
				return;
			}

			ResponseMessage response = new ErrorResponse (exception);
			
			if (AsyncResponse != null)
				AsyncResponse (response);
		}