THRIFT-25. csharp: Various compiler and library improvements

Compiler:
- Thrift structures are serializable.
- The member fields of thrift structures are now private and only accessible
  through Properties, which keep the appropriate __isset up to date.

Library
- Addition of TBufferedTransport, which can be used to wrap other Transports.
- Addition of TThreadedServer, which manually manages threads instead of
  relying on .NET ThreadPool.
- Servers use a log delegate that defaults to System.Console but allows
  servers to use log4net without introducing the dependency.

ThriftTest Visual Studio Project
- Test client and server that use ThriftTest.thrift. The project references
  thrift.exe and Thrift.dll from the subversion tree and automatically builds
  generated code. This makes it very easy to test changes in both the compiler
  and library.


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@732079 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/csharp/src/Transport/TBufferedTransport.cs b/lib/csharp/src/Transport/TBufferedTransport.cs
new file mode 100644
index 0000000..96a0741
--- /dev/null
+++ b/lib/csharp/src/Transport/TBufferedTransport.cs
@@ -0,0 +1,92 @@
+//
+//  TBufferedTransport.cs
+//
+//  Begin:  May 22, 2008
+//  Authors:
+//		Will Palmeri <wpalmeri@imeem.com>
+//
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.IO;
+
+namespace Thrift.Transport
+{
+	public class TBufferedTransport : TTransport
+	{
+		private BufferedStream inputBuffer;
+		private BufferedStream outputBuffer;
+		private int bufSize;
+		private TStreamTransport transport;
+
+		public TBufferedTransport(TStreamTransport transport)
+			:this(transport, 1024)
+		{
+
+		}
+
+		public TBufferedTransport(TStreamTransport transport, int bufSize)
+		{
+			this.bufSize = bufSize;
+			this.transport = transport;
+			InitBuffers();
+		}
+
+		private void InitBuffers()
+		{
+			if (transport.InputStream != null)
+			{
+				inputBuffer = new BufferedStream(transport.InputStream, bufSize);
+			}
+			if (transport.OutputStream != null)
+			{
+				outputBuffer = new BufferedStream(transport.OutputStream, bufSize);
+			}
+		}
+
+		public TTransport UnderlyingTransport
+		{
+			get { return transport; }
+		}
+
+		public override bool IsOpen
+		{
+			get { return transport.IsOpen; }
+		}
+
+		public override void Open()
+		{
+			transport.Open();
+			InitBuffers();
+		}
+
+		public override void Close()
+		{
+			if (inputBuffer != null && inputBuffer.CanRead)
+			{
+				inputBuffer.Close();
+			}
+			if (outputBuffer != null && outputBuffer.CanWrite)
+			{
+				outputBuffer.Close();
+			}
+		}
+
+		public override int Read(byte[] buf, int off, int len)
+		{
+			return inputBuffer.Read(buf, off, len);
+		}
+
+		public override void Write(byte[] buf, int off, int len)
+		{
+			outputBuffer.Write(buf, off, len);
+		}
+
+		public override void Flush()
+		{
+			outputBuffer.Flush();
+		}
+	}
+}
diff --git a/lib/csharp/src/Transport/TServerSocket.cs b/lib/csharp/src/Transport/TServerSocket.cs
index 33ada7b..a6caf90 100644
--- a/lib/csharp/src/Transport/TServerSocket.cs
+++ b/lib/csharp/src/Transport/TServerSocket.cs
@@ -34,6 +34,11 @@
 		private int clientTimeout = 0;
 
 		/**
+		 * Whether or not to wrap new TSocket connections in buffers
+		 */
+		private bool useBufferedSockets = false;
+
+		/**
 		 * Creates a server socket from underlying socket object
 		 */
 		public TServerSocket(TcpListener listener)
@@ -62,9 +67,15 @@
 		 * Creates just a port listening server socket
 		 */
 		public TServerSocket(int port, int clientTimeout)
+			:this(port, clientTimeout, false)
+		{
+		}
+
+		public TServerSocket(int port, int clientTimeout, bool useBufferedSockets)
 		{
 			this.port = port;
 			this.clientTimeout = clientTimeout;
+			this.useBufferedSockets = useBufferedSockets;
 			try
 			{
 				// Make server socket
@@ -88,7 +99,7 @@
 				}
 				catch (SocketException sx)
 				{
-					Console.Error.WriteLine(sx);
+					throw new TTransportException("Could not accept on listening socket: " + sx.Message);
 				}
 			}
 		}
@@ -104,7 +115,15 @@
 				TcpClient result = server.AcceptTcpClient();
 				TSocket result2 = new TSocket(result);
 				result2.Timeout = clientTimeout;
-				return result2;
+				if (useBufferedSockets)
+				{
+					TBufferedTransport result3 = new TBufferedTransport(result2);
+					return result3;
+				}
+				else
+				{
+					return result2;
+				}
 			}
 			catch (Exception ex)
 			{
@@ -122,7 +141,7 @@
 				}
 				catch (Exception ex)
 				{
-					Console.Error.WriteLine("WARNING: Could not close server socket: " + ex);
+					throw new TTransportException("WARNING: Could not close server socket: " + ex);
 				}
 				server = null;
 			}
diff --git a/lib/csharp/src/Transport/TSocket.cs b/lib/csharp/src/Transport/TSocket.cs
index a3f3623..c790fce 100644
--- a/lib/csharp/src/Transport/TSocket.cs
+++ b/lib/csharp/src/Transport/TSocket.cs
@@ -69,6 +69,22 @@
 			}
 		}
 
+		public string Host
+		{
+			get
+			{
+				return host;
+			}
+		}
+
+		public int Port
+		{
+			get
+			{
+				return port;
+			}
+		}
+
 		public override bool IsOpen
 		{
 			get
diff --git a/lib/csharp/src/Transport/TStreamTransport.cs b/lib/csharp/src/Transport/TStreamTransport.cs
index dbbec19..ca14ecf 100644
--- a/lib/csharp/src/Transport/TStreamTransport.cs
+++ b/lib/csharp/src/Transport/TStreamTransport.cs
@@ -31,6 +31,16 @@
 			this.outputStream = outputStream;
 		}
 
+		public Stream OutputStream
+		{
+			get { return outputStream; }
+		}
+
+		public Stream InputStream
+		{
+			get { return inputStream; }
+		}
+
 		public override bool IsOpen
 		{
 			get { return true; }