http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/TTLSSocket.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/src/Transport/TTLSSocket.cs b/lib/csharp/src/Transport/TTLSSocket.cs index b87576d..9e1f9f2 100644 --- a/lib/csharp/src/Transport/TTLSSocket.cs +++ b/lib/csharp/src/Transport/TTLSSocket.cs @@ -25,276 +25,276 @@ using System.Security.Cryptography.X509Certificates; namespace Thrift.Transport { - /// <summary> - /// SSL Socket Wrapper class - /// </summary> - public class TTLSSocket : TStreamTransport - { - /// <summary> - /// Internal TCP Client - /// </summary> - private TcpClient client = null; - - /// <summary> - /// The host - /// </summary> - private string host = null; - - /// <summary> - /// The port - /// </summary> - private int port = 0; - - /// <summary> - /// The timeout for the connection - /// </summary> - private int timeout = 0; - - /// <summary> - /// Internal SSL Stream for IO - /// </summary> - private SslStream secureStream = null; - - /// <summary> - /// Defines wheter or not this socket is a server socket<br/> - /// This is used for the TLS-authentication - /// </summary> - private bool isServer = false; - - /// <summary> - /// The certificate - /// </summary> - private X509Certificate certificate = null; - - /// <summary> - /// User defined certificate validator. - /// </summary> - private RemoteCertificateValidationCallback certValidator = null; - - /// <summary> - /// Initializes a new instance of the <see cref="TTLSSocket"/> class. - /// </summary> - /// <param name="client">An already created TCP-client</param> - /// <param name="certificate">The certificate.</param> - /// <param name="isServer">if set to <c>true</c> [is server].</param> - public TTLSSocket(TcpClient client, X509Certificate certificate, bool isServer = false) - { - this.client = client; - this.certificate = certificate; - this.isServer = isServer; - - if (IsOpen) - { - base.inputStream = client.GetStream(); - base.outputStream = client.GetStream(); - } - } - - /// <summary> - /// Initializes a new instance of the <see cref="TTLSSocket"/> class. - /// </summary> - /// <param name="host">The host, where the socket should connect to.</param> - /// <param name="port">The port.</param> - /// <param name="certificatePath">The certificate path.</param> - /// <param name="certValidator">User defined cert validator.</param> - public TTLSSocket(string host, int port, string certificatePath, RemoteCertificateValidationCallback certValidator = null) - : this(host, port, 0, X509Certificate.CreateFromCertFile(certificatePath), certValidator) - { - } - - /// <summary> - /// Initializes a new instance of the <see cref="TTLSSocket"/> class. - /// </summary> - /// <param name="host">The host, where the socket should connect to.</param> - /// <param name="port">The port.</param> - /// <param name="certificate">The certificate.</param> - /// <param name="certValidator">User defined cert validator.</param> - public TTLSSocket(string host, int port, X509Certificate certificate, RemoteCertificateValidationCallback certValidator = null) - : this(host, port, 0, certificate, certValidator) - { - } - - /// <summary> - /// Initializes a new instance of the <see cref="TTLSSocket"/> class. - /// </summary> - /// <param name="host">The host, where the socket should connect to.</param> - /// <param name="port">The port.</param> - /// <param name="timeout">The timeout.</param> - /// <param name="certificate">The certificate.</param> - /// <param name="certValidator">User defined cert validator.</param> - public TTLSSocket(string host, int port, int timeout, X509Certificate certificate, RemoteCertificateValidationCallback certValidator = null) - { - this.host = host; - this.port = port; - this.timeout = timeout; - this.certificate = certificate; - this.certValidator = certValidator; - - InitSocket(); - } - - /// <summary> - /// Creates the TcpClient and sets the timeouts - /// </summary> - private void InitSocket() - { - this.client = new TcpClient(); - client.ReceiveTimeout = client.SendTimeout = timeout; - client.Client.NoDelay = true; - } - - /// <summary> - /// Sets Send / Recv Timeout for IO - /// </summary> - public int Timeout - { - set - { - this.client.ReceiveTimeout = this.client.SendTimeout = this.timeout = value; - } - } - - /// <summary> - /// Gets the TCP client. - /// </summary> - public TcpClient TcpClient - { - get - { - return client; - } - } - - /// <summary> - /// Gets the host. - /// </summary> - public string Host - { - get - { - return host; - } - } - - /// <summary> - /// Gets the port. - /// </summary> - public int Port - { - get - { - return port; - } - } - - /// <summary> - /// Gets a value indicating whether TCP Client is Cpen - /// </summary> - public override bool IsOpen - { - get - { - if (this.client == null) - { - return false; - } - - return this.client.Connected; - } - } - - /// <summary> - /// Validates the certificates!<br/> - /// </summary> - /// <param name="sender">The sender-object.</param> - /// <param name="certificate">The used certificate.</param> - /// <param name="chain">The certificate chain.</param> - /// <param name="sslPolicyErrors">An enum, which lists all the errors from the .NET certificate check.</param> - /// <returns></returns> - private bool CertificateValidator(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslValidationErrors) - { - return (sslValidationErrors == SslPolicyErrors.None); - } - - /// <summary> - /// Connects to the host and starts the routine, which sets up the TLS - /// </summary> - public override void Open() - { - if (IsOpen) - { - throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen, "Socket already connected"); - } - - if (String.IsNullOrEmpty(host)) - { - throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open null host"); - } - - if (port <= 0) - { - throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open without port"); - } - - if (client == null) - { - InitSocket(); - } - - client.Connect(host, port); - - setupTLS(); - } - - /// <summary> - /// Creates a TLS-stream and lays it over the existing socket - /// </summary> - public void setupTLS() - { - if (isServer) - { - // Server authentication - this.secureStream = new SslStream(this.client.GetStream(), false); - this.secureStream.AuthenticateAsServer(this.certificate, false, SslProtocols.Tls, true); - } - else - { - // Client authentication - X509CertificateCollection validCerts = new X509CertificateCollection(); - validCerts.Add(certificate); - - if (this.certValidator != null) - { - this.secureStream = new SslStream(this.client.GetStream(), false, new RemoteCertificateValidationCallback(this.certValidator)); - } - else - { - this.secureStream = new SslStream(this.client.GetStream(), false, new RemoteCertificateValidationCallback(CertificateValidator)); - } - this.secureStream.AuthenticateAsClient(host, validCerts, SslProtocols.Tls, true); - } - - inputStream = this.secureStream; - outputStream = this.secureStream; - } - - /// <summary> - /// Closes the SSL Socket - /// </summary> - public override void Close() - { - base.Close(); - if (this.client != null) - { - this.client.Close(); - this.client = null; - } - - if (this.secureStream != null) - { - this.secureStream.Close(); - this.secureStream = null; - } - } - } + /// <summary> + /// SSL Socket Wrapper class + /// </summary> + public class TTLSSocket : TStreamTransport + { + /// <summary> + /// Internal TCP Client + /// </summary> + private TcpClient client = null; + + /// <summary> + /// The host + /// </summary> + private string host = null; + + /// <summary> + /// The port + /// </summary> + private int port = 0; + + /// <summary> + /// The timeout for the connection + /// </summary> + private int timeout = 0; + + /// <summary> + /// Internal SSL Stream for IO + /// </summary> + private SslStream secureStream = null; + + /// <summary> + /// Defines wheter or not this socket is a server socket<br/> + /// This is used for the TLS-authentication + /// </summary> + private bool isServer = false; + + /// <summary> + /// The certificate + /// </summary> + private X509Certificate certificate = null; + + /// <summary> + /// User defined certificate validator. + /// </summary> + private RemoteCertificateValidationCallback certValidator = null; + + /// <summary> + /// Initializes a new instance of the <see cref="TTLSSocket"/> class. + /// </summary> + /// <param name="client">An already created TCP-client</param> + /// <param name="certificate">The certificate.</param> + /// <param name="isServer">if set to <c>true</c> [is server].</param> + public TTLSSocket(TcpClient client, X509Certificate certificate, bool isServer = false) + { + this.client = client; + this.certificate = certificate; + this.isServer = isServer; + + if (IsOpen) + { + base.inputStream = client.GetStream(); + base.outputStream = client.GetStream(); + } + } + + /// <summary> + /// Initializes a new instance of the <see cref="TTLSSocket"/> class. + /// </summary> + /// <param name="host">The host, where the socket should connect to.</param> + /// <param name="port">The port.</param> + /// <param name="certificatePath">The certificate path.</param> + /// <param name="certValidator">User defined cert validator.</param> + public TTLSSocket(string host, int port, string certificatePath, RemoteCertificateValidationCallback certValidator = null) + : this(host, port, 0, X509Certificate.CreateFromCertFile(certificatePath), certValidator) + { + } + + /// <summary> + /// Initializes a new instance of the <see cref="TTLSSocket"/> class. + /// </summary> + /// <param name="host">The host, where the socket should connect to.</param> + /// <param name="port">The port.</param> + /// <param name="certificate">The certificate.</param> + /// <param name="certValidator">User defined cert validator.</param> + public TTLSSocket(string host, int port, X509Certificate certificate, RemoteCertificateValidationCallback certValidator = null) + : this(host, port, 0, certificate, certValidator) + { + } + + /// <summary> + /// Initializes a new instance of the <see cref="TTLSSocket"/> class. + /// </summary> + /// <param name="host">The host, where the socket should connect to.</param> + /// <param name="port">The port.</param> + /// <param name="timeout">The timeout.</param> + /// <param name="certificate">The certificate.</param> + /// <param name="certValidator">User defined cert validator.</param> + public TTLSSocket(string host, int port, int timeout, X509Certificate certificate, RemoteCertificateValidationCallback certValidator = null) + { + this.host = host; + this.port = port; + this.timeout = timeout; + this.certificate = certificate; + this.certValidator = certValidator; + + InitSocket(); + } + + /// <summary> + /// Creates the TcpClient and sets the timeouts + /// </summary> + private void InitSocket() + { + this.client = new TcpClient(); + client.ReceiveTimeout = client.SendTimeout = timeout; + client.Client.NoDelay = true; + } + + /// <summary> + /// Sets Send / Recv Timeout for IO + /// </summary> + public int Timeout + { + set + { + this.client.ReceiveTimeout = this.client.SendTimeout = this.timeout = value; + } + } + + /// <summary> + /// Gets the TCP client. + /// </summary> + public TcpClient TcpClient + { + get + { + return client; + } + } + + /// <summary> + /// Gets the host. + /// </summary> + public string Host + { + get + { + return host; + } + } + + /// <summary> + /// Gets the port. + /// </summary> + public int Port + { + get + { + return port; + } + } + + /// <summary> + /// Gets a value indicating whether TCP Client is Cpen + /// </summary> + public override bool IsOpen + { + get + { + if (this.client == null) + { + return false; + } + + return this.client.Connected; + } + } + + /// <summary> + /// Validates the certificates!<br/> + /// </summary> + /// <param name="sender">The sender-object.</param> + /// <param name="certificate">The used certificate.</param> + /// <param name="chain">The certificate chain.</param> + /// <param name="sslPolicyErrors">An enum, which lists all the errors from the .NET certificate check.</param> + /// <returns></returns> + private bool CertificateValidator(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslValidationErrors) + { + return (sslValidationErrors == SslPolicyErrors.None); + } + + /// <summary> + /// Connects to the host and starts the routine, which sets up the TLS + /// </summary> + public override void Open() + { + if (IsOpen) + { + throw new TTransportException(TTransportException.ExceptionType.AlreadyOpen, "Socket already connected"); + } + + if (String.IsNullOrEmpty(host)) + { + throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open null host"); + } + + if (port <= 0) + { + throw new TTransportException(TTransportException.ExceptionType.NotOpen, "Cannot open without port"); + } + + if (client == null) + { + InitSocket(); + } + + client.Connect(host, port); + + setupTLS(); + } + + /// <summary> + /// Creates a TLS-stream and lays it over the existing socket + /// </summary> + public void setupTLS() + { + if (isServer) + { + // Server authentication + this.secureStream = new SslStream(this.client.GetStream(), false); + this.secureStream.AuthenticateAsServer(this.certificate, false, SslProtocols.Tls, true); + } + else + { + // Client authentication + X509CertificateCollection validCerts = new X509CertificateCollection(); + validCerts.Add(certificate); + + if (this.certValidator != null) + { + this.secureStream = new SslStream(this.client.GetStream(), false, new RemoteCertificateValidationCallback(this.certValidator)); + } + else + { + this.secureStream = new SslStream(this.client.GetStream(), false, new RemoteCertificateValidationCallback(CertificateValidator)); + } + this.secureStream.AuthenticateAsClient(host, validCerts, SslProtocols.Tls, true); + } + + inputStream = this.secureStream; + outputStream = this.secureStream; + } + + /// <summary> + /// Closes the SSL Socket + /// </summary> + public override void Close() + { + base.Close(); + if (this.client != null) + { + this.client.Close(); + this.client = null; + } + + if (this.secureStream != null) + { + this.secureStream.Close(); + this.secureStream = null; + } + } + } }
http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/TTransport.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/src/Transport/TTransport.cs b/lib/csharp/src/Transport/TTransport.cs index 5bb8f9e..13314ec 100644 --- a/lib/csharp/src/Transport/TTransport.cs +++ b/lib/csharp/src/Transport/TTransport.cs @@ -25,24 +25,24 @@ using System; namespace Thrift.Transport { - public abstract class TTransport : IDisposable - { - public abstract bool IsOpen - { - get; - } - - private byte[] _peekBuffer = new byte[1]; + public abstract class TTransport : IDisposable + { + public abstract bool IsOpen + { + get; + } + + private byte[] _peekBuffer = new byte[1]; private bool _hasPeekByte = false; public bool Peek() { //If we already have a byte read but not consumed, do nothing. - if (_hasPeekByte) + if (_hasPeekByte) return true; //If transport closed we can't peek. - if (!IsOpen) + if (!IsOpen) return false; //Try to read one byte. If succeeds we will need to store it for the next read. @@ -54,15 +54,15 @@ namespace Thrift.Transport return true; } - public abstract void Open(); + public abstract void Open(); - public abstract void Close(); + public abstract void Close(); - public abstract int Read(byte[] buf, int off, int len); + public abstract int Read(byte[] buf, int off, int len); - public int ReadAll(byte[] buf, int off, int len) - { - int got = 0; + public int ReadAll(byte[] buf, int off, int len) + { + int got = 0; //If we previously peeked a byte, we need to use that first. if (_hasPeekByte) @@ -83,19 +83,19 @@ namespace Thrift.Transport got += ret; } return got; - } + } + + public virtual void Write(byte[] buf) + { + Write (buf, 0, buf.Length); + } - public virtual void Write(byte[] buf) - { - Write (buf, 0, buf.Length); - } + public abstract void Write(byte[] buf, int off, int len); - public abstract void Write(byte[] buf, int off, int len); + public virtual void Flush() + { + } - public virtual void Flush() - { - } - public virtual IAsyncResult BeginFlush(AsyncCallback callback, object state) { throw new TTransportException( @@ -110,16 +110,16 @@ namespace Thrift.Transport "Asynchronous operations are not supported by this transport."); } - #region " IDisposable Support " - // IDisposable - protected abstract void Dispose(bool disposing); - - public void Dispose() - { - // Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. - Dispose(true); - GC.SuppressFinalize(this); - } - #endregion - } + #region " IDisposable Support " + // IDisposable + protected abstract void Dispose(bool disposing); + + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above. + Dispose(true); + GC.SuppressFinalize(this); + } + #endregion + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/TTransportException.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/src/Transport/TTransportException.cs b/lib/csharp/src/Transport/TTransportException.cs index fda0138..6dcd987 100644 --- a/lib/csharp/src/Transport/TTransportException.cs +++ b/lib/csharp/src/Transport/TTransportException.cs @@ -25,44 +25,44 @@ using System; namespace Thrift.Transport { - public class TTransportException : TException - { - protected ExceptionType type; + public class TTransportException : TException + { + protected ExceptionType type; - public TTransportException() - : base() - { - } + public TTransportException() + : base() + { + } - public TTransportException(ExceptionType type) - : this() - { - this.type = type; - } + public TTransportException(ExceptionType type) + : this() + { + this.type = type; + } - public TTransportException(ExceptionType type, string message) - : base(message) - { - this.type = type; - } + public TTransportException(ExceptionType type, string message) + : base(message) + { + this.type = type; + } - public TTransportException(string message) - : base(message) - { - } + public TTransportException(string message) + : base(message) + { + } - public ExceptionType Type - { - get { return type; } - } + public ExceptionType Type + { + get { return type; } + } - public enum ExceptionType - { - Unknown, - NotOpen, - AlreadyOpen, - TimedOut, - EndOfFile - } - } + public enum ExceptionType + { + Unknown, + NotOpen, + AlreadyOpen, + TimedOut, + EndOfFile + } + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/src/Transport/TTransportFactory.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/src/Transport/TTransportFactory.cs b/lib/csharp/src/Transport/TTransportFactory.cs index 8f4f15d..fa10033 100644 --- a/lib/csharp/src/Transport/TTransportFactory.cs +++ b/lib/csharp/src/Transport/TTransportFactory.cs @@ -25,18 +25,18 @@ using System; namespace Thrift.Transport { - /// <summary> - /// From Mark Slee & Aditya Agarwal of Facebook: - /// Factory class used to create wrapped instance of Transports. - /// This is used primarily in servers, which get Transports from - /// a ServerTransport and then may want to mutate them (i.e. create - /// a BufferedTransport from the underlying base transport) - /// </summary> - public class TTransportFactory - { - public virtual TTransport GetTransport(TTransport trans) - { - return trans; - } - } + /// <summary> + /// From Mark Slee & Aditya Agarwal of Facebook: + /// Factory class used to create wrapped instance of Transports. + /// This is used primarily in servers, which get Transports from + /// a ServerTransport and then may want to mutate them (i.e. create + /// a BufferedTransport from the underlying base transport) + /// </summary> + public class TTransportFactory + { + public virtual TTransport GetTransport(TTransport trans) + { + return trans; + } + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/test/JSON/JSONTest.csproj ---------------------------------------------------------------------- diff --git a/lib/csharp/test/JSON/JSONTest.csproj b/lib/csharp/test/JSON/JSONTest.csproj index 61e8e6c..f07d43e 100644 --- a/lib/csharp/test/JSON/JSONTest.csproj +++ b/lib/csharp/test/JSON/JSONTest.csproj @@ -75,7 +75,7 @@ </ProjectReference> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. <Target Name="BeforeBuild"> </Target> http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/test/JSON/Program.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/test/JSON/Program.cs b/lib/csharp/test/JSON/Program.cs index d66c78a..9823221 100644 --- a/lib/csharp/test/JSON/Program.cs +++ b/lib/csharp/test/JSON/Program.cs @@ -28,55 +28,55 @@ using Thrift.Transport; namespace JSONTest { - class Program - { - static void Main(string[] args) - { - TestThrift2365(); // JSON binary decodes too much data - TestThrift2336(); // hex encoding using \uXXXX where 0xXXXX > 0xFF - } + class Program + { + static void Main(string[] args) + { + TestThrift2365(); // JSON binary decodes too much data + TestThrift2336(); // hex encoding using \uXXXX where 0xXXXX > 0xFF + } - public static void TestThrift2365() - { - var rnd = new Random(); - for (var len = 0; len < 10; ++len) - { - byte[] dataWritten = new byte[len]; - rnd.NextBytes(dataWritten); + public static void TestThrift2365() + { + var rnd = new Random(); + for (var len = 0; len < 10; ++len) + { + byte[] dataWritten = new byte[len]; + rnd.NextBytes(dataWritten); - Stream stm = new MemoryStream(); - TTransport trans = new TStreamTransport(null, stm); - TProtocol prot = new TJSONProtocol(trans); - prot.WriteBinary(dataWritten); + Stream stm = new MemoryStream(); + TTransport trans = new TStreamTransport(null, stm); + TProtocol prot = new TJSONProtocol(trans); + prot.WriteBinary(dataWritten); - stm.Position = 0; - trans = new TStreamTransport(stm, null); - prot = new TJSONProtocol(trans); - byte[] dataRead = prot.ReadBinary(); + stm.Position = 0; + trans = new TStreamTransport(stm, null); + prot = new TJSONProtocol(trans); + byte[] dataRead = prot.ReadBinary(); - Debug.Assert(dataRead.Length == dataWritten.Length); - for (var i = 0; i < dataRead.Length; ++i) - Debug.Assert(dataRead[i] == dataWritten[i]); - } - } + Debug.Assert(dataRead.Length == dataWritten.Length); + for (var i = 0; i < dataRead.Length; ++i) + Debug.Assert(dataRead[i] == dataWritten[i]); + } + } - public static void TestThrift2336() - { - const string RUSSIAN_TEXT = "\u0420\u0443\u0441\u0441\u043a\u043e\u0435 \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435"; - const string RUSSIAN_JSON = "\"\\u0420\\u0443\\u0441\\u0441\\u043a\\u043e\\u0435 \\u041d\\u0430\\u0437\\u0432\\u0430\\u043d\\u0438\\u0435\""; - - // prepare buffer with JSON data - byte[] rawBytes = new byte[RUSSIAN_JSON.Length]; - for (var i = 0; i < RUSSIAN_JSON.Length; ++i) - rawBytes[i] = (byte)(RUSSIAN_JSON[i] & (char)0xFF); // only low bytes + public static void TestThrift2336() + { + const string RUSSIAN_TEXT = "\u0420\u0443\u0441\u0441\u043a\u043e\u0435 \u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435"; + const string RUSSIAN_JSON = "\"\\u0420\\u0443\\u0441\\u0441\\u043a\\u043e\\u0435 \\u041d\\u0430\\u0437\\u0432\\u0430\\u043d\\u0438\\u0435\""; - // parse and check - var stm = new MemoryStream(rawBytes); - var trans = new TStreamTransport(stm, null); - var prot = new TJSONProtocol(trans); - Debug.Assert(prot.ReadString() == RUSSIAN_TEXT, "reading JSON with hex-encoded chars > 8 bit"); - } - } + // prepare buffer with JSON data + byte[] rawBytes = new byte[RUSSIAN_JSON.Length]; + for (var i = 0; i < RUSSIAN_JSON.Length; ++i) + rawBytes[i] = (byte)(RUSSIAN_JSON[i] & (char)0xFF); // only low bytes + + // parse and check + var stm = new MemoryStream(rawBytes); + var trans = new TStreamTransport(stm, null); + var prot = new TJSONProtocol(trans); + Debug.Assert(prot.ReadString() == RUSSIAN_TEXT, "reading JSON with hex-encoded chars > 8 bit"); + } + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/test/JSON/Properties/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/test/JSON/Properties/AssemblyInfo.cs b/lib/csharp/test/JSON/Properties/AssemblyInfo.cs index 8629f6f..6788bc3 100644 --- a/lib/csharp/test/JSON/Properties/AssemblyInfo.cs +++ b/lib/csharp/test/JSON/Properties/AssemblyInfo.cs @@ -21,7 +21,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// Allgemeine Informationen über eine Assembly werden über die folgenden +// Allgemeine Informationen über eine Assembly werden über die folgenden // Attribute gesteuert. Ãndern Sie diese Attributwerte, um die Informationen zu ändern, // die mit einer Assembly verknüpft sind. [assembly: AssemblyTitle("JSONTest")] @@ -33,8 +33,8 @@ using System.Runtime.InteropServices; [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar -// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von +// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar +// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von // COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. [assembly: ComVisible(false)] @@ -44,11 +44,11 @@ using System.Runtime.InteropServices; // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: // // Hauptversion -// Nebenversion +// Nebenversion // Buildnummer // Revision // -// Sie können alle Werte angeben oder die standardmäÃigen Build- und Revisionsnummern +// Sie können alle Werte angeben oder die standardmäÃigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/test/JSON/app.config ---------------------------------------------------------------------- diff --git a/lib/csharp/test/JSON/app.config b/lib/csharp/test/JSON/app.config index bc39140..9c1919d 100644 --- a/lib/csharp/test/JSON/app.config +++ b/lib/csharp/test/JSON/app.config @@ -1,21 +1,21 @@ -<?xml version="1.0"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. ---> -<configuration> -<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration> +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<configuration> +<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration> http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/test/Multiplex/Client/Multiplex.Test.Client.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/test/Multiplex/Client/Multiplex.Test.Client.cs b/lib/csharp/test/Multiplex/Client/Multiplex.Test.Client.cs index 95ba5a4..ccfe21d 100644 --- a/lib/csharp/test/Multiplex/Client/Multiplex.Test.Client.cs +++ b/lib/csharp/test/Multiplex/Client/Multiplex.Test.Client.cs @@ -29,8 +29,8 @@ using Test.Multiplex; namespace Test.Multiplex.Client { - public class TestClient - { + public class TestClient + { private void Run() { try @@ -49,7 +49,7 @@ namespace Test.Multiplex.Client multiplex = new TMultiplexedProtocol( Protocol, Constants.NAME_AGGR); Aggr.Iface aggr = new Aggr.Client( multiplex); - + sbyte i; for( i = 1; 10 >= i; ++i) { http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/test/Multiplex/Multiplex.Test.Common.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/test/Multiplex/Multiplex.Test.Common.cs b/lib/csharp/test/Multiplex/Multiplex.Test.Common.cs index 5296b68..a687852 100644 --- a/lib/csharp/test/Multiplex/Multiplex.Test.Common.cs +++ b/lib/csharp/test/Multiplex/Multiplex.Test.Common.cs @@ -30,8 +30,8 @@ using Thrift.Server; namespace Test.Multiplex { - public class Constants - { + public class Constants + { public const string NAME_BENCHMARKSERVICE = "BenchmarkService"; public const string NAME_AGGR = "Aggr"; } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/test/Multiplex/Server/Multiplex.Test.Server.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/test/Multiplex/Server/Multiplex.Test.Server.cs b/lib/csharp/test/Multiplex/Server/Multiplex.Test.Server.cs index fbec1b7..61c2d7c 100644 --- a/lib/csharp/test/Multiplex/Server/Multiplex.Test.Server.cs +++ b/lib/csharp/test/Multiplex/Server/Multiplex.Test.Server.cs @@ -28,8 +28,8 @@ using Test.Multiplex; namespace Test.Multiplex.Server { - public class TestServer - { + public class TestServer + { public interface ITestHandler { void SetServer( TServer aServer); @@ -38,7 +38,7 @@ namespace Test.Multiplex.Server protected class TestHandlerImpl : ITestHandler { private TServer Server; - + public void SetServer( TServer aServer) { Server = aServer; @@ -53,7 +53,7 @@ namespace Test.Multiplex.Server int prev, next, result; prev = 0; result = 1; - while( n > 0) + while( n > 0) { next = result + prev; prev = result; @@ -110,7 +110,7 @@ namespace Test.Multiplex.Server (benchHandler as ITestHandler).SetServer(null); (aggrHandler as ITestHandler).SetServer(null); - } + } catch( Exception e) { Console.WriteLine( e.Message); @@ -118,7 +118,7 @@ namespace Test.Multiplex.Server Console.WriteLine( "done."); } - + static void Main(string[] args) { Execute(); http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/test/Multiplex/maketest.sh ---------------------------------------------------------------------- diff --git a/lib/csharp/test/Multiplex/maketest.sh b/lib/csharp/test/Multiplex/maketest.sh index a2bcde4..1f29ee2 100755 --- a/lib/csharp/test/Multiplex/maketest.sh +++ b/lib/csharp/test/Multiplex/maketest.sh @@ -22,13 +22,13 @@ ../../../../compiler/cpp/thrift --gen csharp ../../../../contrib/async-test/aggr.thrift ../../../../compiler/cpp/thrift --gen csharp ../../../rb/benchmark/Benchmark.thrift gmcs /t:library /out:./ThriftImpl.dll /recurse:./gen-csharp/* /reference:../../Thrift.dll Multiplex.Test.Common.cs -gmcs /out:MultiplexClient.exe /reference:../../Thrift.dll /reference:ThriftImpl.dll Client/Multiplex.Test.Client.cs -gmcs /out:MultiplexServer.exe /reference:../../Thrift.dll /reference:ThriftImpl.dll Server/Multiplex.Test.Server.cs +gmcs /out:MultiplexClient.exe /reference:../../Thrift.dll /reference:ThriftImpl.dll Client/Multiplex.Test.Client.cs +gmcs /out:MultiplexServer.exe /reference:../../Thrift.dll /reference:ThriftImpl.dll Server/Multiplex.Test.Server.cs export MONO_PATH=../../ -timeout 120 ./MultiplexServer.exe & +timeout 120 ./MultiplexServer.exe & sleep 3; ./MultiplexClient.exe http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/test/ThriftTest/Program.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/test/ThriftTest/Program.cs b/lib/csharp/test/ThriftTest/Program.cs index 4c63ca4..3bf6796 100644 --- a/lib/csharp/test/ThriftTest/Program.cs +++ b/lib/csharp/test/ThriftTest/Program.cs @@ -29,33 +29,33 @@ using Thrift.Test; //generated code namespace Test { - class Program - { - static void Main(string[] args) - { - if (args.Length == 0) - { - Console.WriteLine("must provide 'server' or 'client' arg"); - return; - } + class Program + { + static void Main(string[] args) + { + if (args.Length == 0) + { + Console.WriteLine("must provide 'server' or 'client' arg"); + return; + } - string[] subArgs = new string[args.Length - 1]; - for(int i = 1; i < args.Length; i++) - { - subArgs[i-1] = args[i]; - } - if (args[0] == "client") - { - TestClient.Execute(subArgs); - } - else if (args[0] == "server") - { - TestServer.Execute(subArgs); - } - else - { - Console.WriteLine("first argument must be 'server' or 'client'"); - } - } - } + string[] subArgs = new string[args.Length - 1]; + for(int i = 1; i < args.Length; i++) + { + subArgs[i-1] = args[i]; + } + if (args[0] == "client") + { + TestClient.Execute(subArgs); + } + else if (args[0] == "server") + { + TestServer.Execute(subArgs); + } + else + { + Console.WriteLine("first argument must be 'server' or 'client'"); + } + } + } } http://git-wip-us.apache.org/repos/asf/thrift/blob/d5436f5c/lib/csharp/test/ThriftTest/TestClient.cs ---------------------------------------------------------------------- diff --git a/lib/csharp/test/ThriftTest/TestClient.cs b/lib/csharp/test/ThriftTest/TestClient.cs index db0fe63..cb33473 100644 --- a/lib/csharp/test/ThriftTest/TestClient.cs +++ b/lib/csharp/test/ThriftTest/TestClient.cs @@ -27,453 +27,453 @@ using Thrift.Test; namespace Test { - public class TestClient - { - private static int numIterations = 1; - private static string protocol = ""; - - public static void Execute(string[] args) - { - try - { - string host = "localhost"; - int port = 9090; - string url = null, pipe = null; - int numThreads = 1; - bool buffered = false, framed = false, encrypted = false; - - try - { - for (int i = 0; i < args.Length; i++) - { - if (args[i] == "-u") - { - url = args[++i]; - } - else if (args[i] == "-n") - { - numIterations = Convert.ToInt32(args[++i]); - } - else if (args[i] == "-pipe") // -pipe <name> - { - pipe = args[++i]; - Console.WriteLine("Using named pipes transport"); - } - else if (args[i].Contains("--host=")) - { - host = args[i].Substring(args[i].IndexOf("=") + 1); - } - else if (args[i].Contains("--port=")) - { - port = int.Parse(args[i].Substring(args[i].IndexOf("=")+1)); - } - else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered") - { - buffered = true; - Console.WriteLine("Using buffered sockets"); - } - else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed") - { - framed = true; - Console.WriteLine("Using framed transport"); - } - else if (args[i] == "-t") - { - numThreads = Convert.ToInt32(args[++i]); - } - else if (args[i] == "--compact" || args[i] == "--protocol=compact") - { - protocol = "compact"; - Console.WriteLine("Using compact protocol"); - } - else if (args[i] == "--json" || args[i] == "--protocol=json") - { - protocol = "json"; - Console.WriteLine("Using JSON protocol"); - } - else if (args[i] == "--ssl") - { - encrypted = true; - Console.WriteLine("Using encrypted transport"); - } - } - } - catch (Exception e) - { - Console.WriteLine(e.StackTrace); - } - - //issue tests on separate threads simultaneously - Thread[] threads = new Thread[numThreads]; - DateTime start = DateTime.Now; - for (int test = 0; test < numThreads; test++) - { - Thread t = new Thread(new ParameterizedThreadStart(ClientThread)); - threads[test] = t; - if (url == null) - { - // endpoint transport - TTransport trans = null; - if (pipe != null) - trans = new TNamedPipeClientTransport(pipe); - else - { - if (encrypted) - trans = new TTLSSocket(host, port, "../../../../../keys/client.pem"); - else - trans = new TSocket(host, port); - } - - // layered transport - if (buffered) - trans = new TBufferedTransport(trans as TStreamTransport); - if (framed) - trans = new TFramedTransport(trans); - - //ensure proper open/close of transport - trans.Open(); - trans.Close(); - t.Start(trans); - } - else - { - THttpClient http = new THttpClient(new Uri(url)); - t.Start(http); - } - } - - for (int test = 0; test < numThreads; test++) - { - threads[test].Join(); - } - Console.Write("Total time: " + (DateTime.Now - start)); - } - catch (Exception outerEx) - { - Console.WriteLine(outerEx.Message + " ST: " + outerEx.StackTrace); - } - - Console.WriteLine(); - Console.WriteLine(); - } - - public static void ClientThread(object obj) - { - TTransport transport = (TTransport)obj; - for (int i = 0; i < numIterations; i++) - { - ClientTest(transport); - } - transport.Close(); - } - - public static void ClientTest(TTransport transport) - { - TProtocol proto; - if (protocol == "compact") - proto = new TCompactProtocol(transport); - else if (protocol == "json") - proto = new TJSONProtocol(transport); - else - proto = new TBinaryProtocol(transport); - - ThriftTest.Client client = new ThriftTest.Client(proto); - try - { - if (!transport.IsOpen) - { - transport.Open(); - } - } - catch (TTransportException ttx) - { - Console.WriteLine("Connect failed: " + ttx.Message); - return; - } - - long start = DateTime.Now.ToFileTime(); - - Console.Write("testVoid()"); - client.testVoid(); - Console.WriteLine(" = void"); - - Console.Write("testString(\"Test\")"); - string s = client.testString("Test"); - Console.WriteLine(" = \"" + s + "\""); - - Console.Write("testByte(1)"); - sbyte i8 = client.testByte((sbyte)1); - Console.WriteLine(" = " + i8); - - Console.Write("testI32(-1)"); - int i32 = client.testI32(-1); - Console.WriteLine(" = " + i32); - - Console.Write("testI64(-34359738368)"); - long i64 = client.testI64(-34359738368); - Console.WriteLine(" = " + i64); - - Console.Write("testDouble(5.325098235)"); - double dub = client.testDouble(5.325098235); - Console.WriteLine(" = " + dub); - - Console.Write("testStruct({\"Zero\", 1, -3, -5})"); - Xtruct o = new Xtruct(); - o.String_thing = "Zero"; - o.Byte_thing = (sbyte)1; - o.I32_thing = -3; - o.I64_thing = -5; - Xtruct i = client.testStruct(o); - Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}"); - - Console.Write("testNest({1, {\"Zero\", 1, -3, -5}, 5})"); - Xtruct2 o2 = new Xtruct2(); - o2.Byte_thing = (sbyte)1; - o2.Struct_thing = o; - o2.I32_thing = 5; - Xtruct2 i2 = client.testNest(o2); - i = i2.Struct_thing; - Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}"); - - Dictionary<int, int> mapout = new Dictionary<int, int>(); - for (int j = 0; j < 5; j++) - { - mapout[j] = j - 10; - } - Console.Write("testMap({"); - bool first = true; - foreach (int key in mapout.Keys) - { - if (first) - { - first = false; - } - else - { - Console.Write(", "); - } - Console.Write(key + " => " + mapout[key]); - } - Console.Write("})"); - - Dictionary<int, int> mapin = client.testMap(mapout); - - Console.Write(" = {"); - first = true; - foreach (int key in mapin.Keys) - { - if (first) - { - first = false; - } - else - { - Console.Write(", "); - } - Console.Write(key + " => " + mapin[key]); - } - Console.WriteLine("}"); - - List<int> listout = new List<int>(); - for (int j = -2; j < 3; j++) - { - listout.Add(j); - } - Console.Write("testList({"); - first = true; - foreach (int j in listout) - { - if (first) - { - first = false; - } - else - { - Console.Write(", "); - } - Console.Write(j); - } - Console.Write("})"); - - List<int> listin = client.testList(listout); - - Console.Write(" = {"); - first = true; - foreach (int j in listin) - { - if (first) - { - first = false; - } - else - { - Console.Write(", "); - } - Console.Write(j); - } - Console.WriteLine("}"); - - //set - THashSet<int> setout = new THashSet<int>(); - for (int j = -2; j < 3; j++) - { - setout.Add(j); - } - Console.Write("testSet({"); - first = true; - foreach (int j in setout) - { - if (first) - { - first = false; - } - else - { - Console.Write(", "); - } - Console.Write(j); - } - Console.Write("})"); - - THashSet<int> setin = client.testSet(setout); - - Console.Write(" = {"); - first = true; - foreach (int j in setin) - { - if (first) - { - first = false; - } - else - { - Console.Write(", "); - } - Console.Write(j); - } - Console.WriteLine("}"); - - - Console.Write("testEnum(ONE)"); - Numberz ret = client.testEnum(Numberz.ONE); - Console.WriteLine(" = " + ret); - - Console.Write("testEnum(TWO)"); - ret = client.testEnum(Numberz.TWO); - Console.WriteLine(" = " + ret); - - Console.Write("testEnum(THREE)"); - ret = client.testEnum(Numberz.THREE); - Console.WriteLine(" = " + ret); - - Console.Write("testEnum(FIVE)"); - ret = client.testEnum(Numberz.FIVE); - Console.WriteLine(" = " + ret); - - Console.Write("testEnum(EIGHT)"); - ret = client.testEnum(Numberz.EIGHT); - Console.WriteLine(" = " + ret); - - Console.Write("testTypedef(309858235082523)"); - long uid = client.testTypedef(309858235082523L); - Console.WriteLine(" = " + uid); - - Console.Write("testMapMap(1)"); - Dictionary<int, Dictionary<int, int>> mm = client.testMapMap(1); - Console.Write(" = {"); - foreach (int key in mm.Keys) - { - Console.Write(key + " => {"); - Dictionary<int, int> m2 = mm[key]; - foreach (int k2 in m2.Keys) - { - Console.Write(k2 + " => " + m2[k2] + ", "); - } - Console.Write("}, "); - } - Console.WriteLine("}"); - - Insanity insane = new Insanity(); - insane.UserMap = new Dictionary<Numberz, long>(); - insane.UserMap[Numberz.FIVE] = 5000L; - Xtruct truck = new Xtruct(); - truck.String_thing = "Truck"; - truck.Byte_thing = (sbyte)8; - truck.I32_thing = 8; - truck.I64_thing = 8; - insane.Xtructs = new List<Xtruct>(); - insane.Xtructs.Add(truck); - Console.Write("testInsanity()"); - Dictionary<long, Dictionary<Numberz, Insanity>> whoa = client.testInsanity(insane); - Console.Write(" = {"); - foreach (long key in whoa.Keys) - { - Dictionary<Numberz, Insanity> val = whoa[key]; - Console.Write(key + " => {"); - - foreach (Numberz k2 in val.Keys) - { - Insanity v2 = val[k2]; - - Console.Write(k2 + " => {"); - Dictionary<Numberz, long> userMap = v2.UserMap; - - Console.Write("{"); - if (userMap != null) - { - foreach (Numberz k3 in userMap.Keys) - { - Console.Write(k3 + " => " + userMap[k3] + ", "); - } - } - else - { - Console.Write("null"); - } - Console.Write("}, "); - - List<Xtruct> xtructs = v2.Xtructs; - - Console.Write("{"); - if (xtructs != null) - { - foreach (Xtruct x in xtructs) - { - Console.Write("{\"" + x.String_thing + "\", " + x.Byte_thing + ", " + x.I32_thing + ", " + x.I32_thing + "}, "); - } - } - else - { - Console.Write("null"); - } - Console.Write("}"); - - Console.Write("}, "); - } - Console.Write("}, "); - } - Console.WriteLine("}"); - - sbyte arg0 = 1; - int arg1 = 2; - long arg2 = long.MaxValue; - Dictionary<short, string> multiDict = new Dictionary<short, string>(); - multiDict[1] = "one"; - Numberz arg4 = Numberz.FIVE; - long arg5 = 5000000; - Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")"); - Xtruct multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5); - Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing - + ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n"); - - Console.WriteLine("Test Oneway(1)"); - client.testOneway(1); - - Console.Write("Test Calltime()"); - var startt = DateTime.UtcNow; - for ( int k=0; k<1000; ++k ) - client.testVoid(); - Console.WriteLine(" = " + (DateTime.UtcNow - startt).TotalSeconds.ToString() + " ms a testVoid() call" ); - } - } + public class TestClient + { + private static int numIterations = 1; + private static string protocol = ""; + + public static void Execute(string[] args) + { + try + { + string host = "localhost"; + int port = 9090; + string url = null, pipe = null; + int numThreads = 1; + bool buffered = false, framed = false, encrypted = false; + + try + { + for (int i = 0; i < args.Length; i++) + { + if (args[i] == "-u") + { + url = args[++i]; + } + else if (args[i] == "-n") + { + numIterations = Convert.ToInt32(args[++i]); + } + else if (args[i] == "-pipe") // -pipe <name> + { + pipe = args[++i]; + Console.WriteLine("Using named pipes transport"); + } + else if (args[i].Contains("--host=")) + { + host = args[i].Substring(args[i].IndexOf("=") + 1); + } + else if (args[i].Contains("--port=")) + { + port = int.Parse(args[i].Substring(args[i].IndexOf("=")+1)); + } + else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered") + { + buffered = true; + Console.WriteLine("Using buffered sockets"); + } + else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed") + { + framed = true; + Console.WriteLine("Using framed transport"); + } + else if (args[i] == "-t") + { + numThreads = Convert.ToInt32(args[++i]); + } + else if (args[i] == "--compact" || args[i] == "--protocol=compact") + { + protocol = "compact"; + Console.WriteLine("Using compact protocol"); + } + else if (args[i] == "--json" || args[i] == "--protocol=json") + { + protocol = "json"; + Console.WriteLine("Using JSON protocol"); + } + else if (args[i] == "--ssl") + { + encrypted = true; + Console.WriteLine("Using encrypted transport"); + } + } + } + catch (Exception e) + { + Console.WriteLine(e.StackTrace); + } + + //issue tests on separate threads simultaneously + Thread[] threads = new Thread[numThreads]; + DateTime start = DateTime.Now; + for (int test = 0; test < numThreads; test++) + { + Thread t = new Thread(new ParameterizedThreadStart(ClientThread)); + threads[test] = t; + if (url == null) + { + // endpoint transport + TTransport trans = null; + if (pipe != null) + trans = new TNamedPipeClientTransport(pipe); + else + { + if (encrypted) + trans = new TTLSSocket(host, port, "../../../../../keys/client.pem"); + else + trans = new TSocket(host, port); + } + + // layered transport + if (buffered) + trans = new TBufferedTransport(trans as TStreamTransport); + if (framed) + trans = new TFramedTransport(trans); + + //ensure proper open/close of transport + trans.Open(); + trans.Close(); + t.Start(trans); + } + else + { + THttpClient http = new THttpClient(new Uri(url)); + t.Start(http); + } + } + + for (int test = 0; test < numThreads; test++) + { + threads[test].Join(); + } + Console.Write("Total time: " + (DateTime.Now - start)); + } + catch (Exception outerEx) + { + Console.WriteLine(outerEx.Message + " ST: " + outerEx.StackTrace); + } + + Console.WriteLine(); + Console.WriteLine(); + } + + public static void ClientThread(object obj) + { + TTransport transport = (TTransport)obj; + for (int i = 0; i < numIterations; i++) + { + ClientTest(transport); + } + transport.Close(); + } + + public static void ClientTest(TTransport transport) + { + TProtocol proto; + if (protocol == "compact") + proto = new TCompactProtocol(transport); + else if (protocol == "json") + proto = new TJSONProtocol(transport); + else + proto = new TBinaryProtocol(transport); + + ThriftTest.Client client = new ThriftTest.Client(proto); + try + { + if (!transport.IsOpen) + { + transport.Open(); + } + } + catch (TTransportException ttx) + { + Console.WriteLine("Connect failed: " + ttx.Message); + return; + } + + long start = DateTime.Now.ToFileTime(); + + Console.Write("testVoid()"); + client.testVoid(); + Console.WriteLine(" = void"); + + Console.Write("testString(\"Test\")"); + string s = client.testString("Test"); + Console.WriteLine(" = \"" + s + "\""); + + Console.Write("testByte(1)"); + sbyte i8 = client.testByte((sbyte)1); + Console.WriteLine(" = " + i8); + + Console.Write("testI32(-1)"); + int i32 = client.testI32(-1); + Console.WriteLine(" = " + i32); + + Console.Write("testI64(-34359738368)"); + long i64 = client.testI64(-34359738368); + Console.WriteLine(" = " + i64); + + Console.Write("testDouble(5.325098235)"); + double dub = client.testDouble(5.325098235); + Console.WriteLine(" = " + dub); + + Console.Write("testStruct({\"Zero\", 1, -3, -5})"); + Xtruct o = new Xtruct(); + o.String_thing = "Zero"; + o.Byte_thing = (sbyte)1; + o.I32_thing = -3; + o.I64_thing = -5; + Xtruct i = client.testStruct(o); + Console.WriteLine(" = {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}"); + + Console.Write("testNest({1, {\"Zero\", 1, -3, -5}, 5})"); + Xtruct2 o2 = new Xtruct2(); + o2.Byte_thing = (sbyte)1; + o2.Struct_thing = o; + o2.I32_thing = 5; + Xtruct2 i2 = client.testNest(o2); + i = i2.Struct_thing; + Console.WriteLine(" = {" + i2.Byte_thing + ", {\"" + i.String_thing + "\", " + i.Byte_thing + ", " + i.I32_thing + ", " + i.I64_thing + "}, " + i2.I32_thing + "}"); + + Dictionary<int, int> mapout = new Dictionary<int, int>(); + for (int j = 0; j < 5; j++) + { + mapout[j] = j - 10; + } + Console.Write("testMap({"); + bool first = true; + foreach (int key in mapout.Keys) + { + if (first) + { + first = false; + } + else + { + Console.Write(", "); + } + Console.Write(key + " => " + mapout[key]); + } + Console.Write("})"); + + Dictionary<int, int> mapin = client.testMap(mapout); + + Console.Write(" = {"); + first = true; + foreach (int key in mapin.Keys) + { + if (first) + { + first = false; + } + else + { + Console.Write(", "); + } + Console.Write(key + " => " + mapin[key]); + } + Console.WriteLine("}"); + + List<int> listout = new List<int>(); + for (int j = -2; j < 3; j++) + { + listout.Add(j); + } + Console.Write("testList({"); + first = true; + foreach (int j in listout) + { + if (first) + { + first = false; + } + else + { + Console.Write(", "); + } + Console.Write(j); + } + Console.Write("})"); + + List<int> listin = client.testList(listout); + + Console.Write(" = {"); + first = true; + foreach (int j in listin) + { + if (first) + { + first = false; + } + else + { + Console.Write(", "); + } + Console.Write(j); + } + Console.WriteLine("}"); + + //set + THashSet<int> setout = new THashSet<int>(); + for (int j = -2; j < 3; j++) + { + setout.Add(j); + } + Console.Write("testSet({"); + first = true; + foreach (int j in setout) + { + if (first) + { + first = false; + } + else + { + Console.Write(", "); + } + Console.Write(j); + } + Console.Write("})"); + + THashSet<int> setin = client.testSet(setout); + + Console.Write(" = {"); + first = true; + foreach (int j in setin) + { + if (first) + { + first = false; + } + else + { + Console.Write(", "); + } + Console.Write(j); + } + Console.WriteLine("}"); + + + Console.Write("testEnum(ONE)"); + Numberz ret = client.testEnum(Numberz.ONE); + Console.WriteLine(" = " + ret); + + Console.Write("testEnum(TWO)"); + ret = client.testEnum(Numberz.TWO); + Console.WriteLine(" = " + ret); + + Console.Write("testEnum(THREE)"); + ret = client.testEnum(Numberz.THREE); + Console.WriteLine(" = " + ret); + + Console.Write("testEnum(FIVE)"); + ret = client.testEnum(Numberz.FIVE); + Console.WriteLine(" = " + ret); + + Console.Write("testEnum(EIGHT)"); + ret = client.testEnum(Numberz.EIGHT); + Console.WriteLine(" = " + ret); + + Console.Write("testTypedef(309858235082523)"); + long uid = client.testTypedef(309858235082523L); + Console.WriteLine(" = " + uid); + + Console.Write("testMapMap(1)"); + Dictionary<int, Dictionary<int, int>> mm = client.testMapMap(1); + Console.Write(" = {"); + foreach (int key in mm.Keys) + { + Console.Write(key + " => {"); + Dictionary<int, int> m2 = mm[key]; + foreach (int k2 in m2.Keys) + { + Console.Write(k2 + " => " + m2[k2] + ", "); + } + Console.Write("}, "); + } + Console.WriteLine("}"); + + Insanity insane = new Insanity(); + insane.UserMap = new Dictionary<Numberz, long>(); + insane.UserMap[Numberz.FIVE] = 5000L; + Xtruct truck = new Xtruct(); + truck.String_thing = "Truck"; + truck.Byte_thing = (sbyte)8; + truck.I32_thing = 8; + truck.I64_thing = 8; + insane.Xtructs = new List<Xtruct>(); + insane.Xtructs.Add(truck); + Console.Write("testInsanity()"); + Dictionary<long, Dictionary<Numberz, Insanity>> whoa = client.testInsanity(insane); + Console.Write(" = {"); + foreach (long key in whoa.Keys) + { + Dictionary<Numberz, Insanity> val = whoa[key]; + Console.Write(key + " => {"); + + foreach (Numberz k2 in val.Keys) + { + Insanity v2 = val[k2]; + + Console.Write(k2 + " => {"); + Dictionary<Numberz, long> userMap = v2.UserMap; + + Console.Write("{"); + if (userMap != null) + { + foreach (Numberz k3 in userMap.Keys) + { + Console.Write(k3 + " => " + userMap[k3] + ", "); + } + } + else + { + Console.Write("null"); + } + Console.Write("}, "); + + List<Xtruct> xtructs = v2.Xtructs; + + Console.Write("{"); + if (xtructs != null) + { + foreach (Xtruct x in xtructs) + { + Console.Write("{\"" + x.String_thing + "\", " + x.Byte_thing + ", " + x.I32_thing + ", " + x.I32_thing + "}, "); + } + } + else + { + Console.Write("null"); + } + Console.Write("}"); + + Console.Write("}, "); + } + Console.Write("}, "); + } + Console.WriteLine("}"); + + sbyte arg0 = 1; + int arg1 = 2; + long arg2 = long.MaxValue; + Dictionary<short, string> multiDict = new Dictionary<short, string>(); + multiDict[1] = "one"; + Numberz arg4 = Numberz.FIVE; + long arg5 = 5000000; + Console.Write("Test Multi(" + arg0 + "," + arg1 + "," + arg2 + "," + multiDict + "," + arg4 + "," + arg5 + ")"); + Xtruct multiResponse = client.testMulti(arg0, arg1, arg2, multiDict, arg4, arg5); + Console.Write(" = Xtruct(byte_thing:" + multiResponse.Byte_thing + ",String_thing:" + multiResponse.String_thing + + ",i32_thing:" + multiResponse.I32_thing + ",i64_thing:" + multiResponse.I64_thing + ")\n"); + + Console.WriteLine("Test Oneway(1)"); + client.testOneway(1); + + Console.Write("Test Calltime()"); + var startt = DateTime.UtcNow; + for ( int k=0; k<1000; ++k ) + client.testVoid(); + Console.WriteLine(" = " + (DateTime.UtcNow - startt).TotalSeconds.ToString() + " ms a testVoid() call" ); + } + } }
