예제 #1
0
            public void Execute()
            {
                var token = CancellationToken.None;

                if (done)
                {
                    Console.WriteLine("Execute called more than once");
                    throw new InvalidOperationException();
                }

                for (var i = 0; i < numIterations; i++)
                {
                    try
                    {
                        if (!transport.IsOpen)
                        {
                            transport.OpenAsync(token).GetAwaiter().GetResult();
                        }
                    }
                    catch (TTransportException ex)
                    {
                        Console.WriteLine("*** FAILED ***");
                        Console.WriteLine("Connect failed: " + ex.Message);
                        ReturnCode |= ErrorUnknown;
                        Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
                        continue;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("*** FAILED ***");
                        Console.WriteLine("Connect failed: " + ex.Message);
                        ReturnCode |= ErrorUnknown;
                        Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
                        continue;
                    }

                    try
                    {
                        ReturnCode |= ExecuteClientTestAsync(client).GetAwaiter().GetResult();;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("*** FAILED ***");
                        Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
                        ReturnCode |= ErrorUnknown;
                    }
                }
                try
                {
                    transport.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error while closing transport");
                    Console.WriteLine(ex.Message + " ST: " + ex.StackTrace);
                }
                done = true;
            }
예제 #2
0
            public async Task Execute()
            {
                if (done)
                {
                    Console.WriteLine("Execute called more than once");
                    throw new InvalidOperationException();
                }

                for (var i = 0; i < numIterations; i++)
                {
                    try
                    {
                        if (!transport.IsOpen)
                        {
                            await transport.OpenAsync(MakeTimeoutToken());
                        }
                    }
                    catch (TTransportException ex)
                    {
                        Console.WriteLine("*** FAILED ***");
                        Console.WriteLine("Connect failed: " + ex.Message);
                        ReturnCode |= ErrorUnknown;
                        Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
                        continue;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("*** FAILED ***");
                        Console.WriteLine("Connect failed: " + ex.Message);
                        ReturnCode |= ErrorUnknown;
                        Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
                        continue;
                    }

                    try
                    {
                        ReturnCode |= await ExecuteClientTest(client);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("*** FAILED ***");
                        Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
                        ReturnCode |= ErrorUnknown;
                    }
                }
                try
                {
                    transport.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error while closing transport");
                    Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
                }
                done = true;
            }
예제 #3
0
        private Task <TProtocol> GenericProtocolFactory <T>(bool forWrite)
            where T : TProtocol
        {
            var oldTrans = Transport;

            try
            {
                // read happens after write here, so let's take over the written bytes
                if (forWrite)
                {
                    MemBuffer = new TMemoryBufferTransport(Configuration);
                }
                else
                {
                    MemBuffer = new TMemoryBufferTransport(MemBuffer.GetBuffer(), Configuration);
                }

                //  layered transports anyone?
                switch (Layered)
                {
                case LayeredChoice.None:
                    Transport = MemBuffer;
                    break;

                case LayeredChoice.Framed:
                    Transport = new TFramedTransport(MemBuffer);
                    break;

                case LayeredChoice.Buffered:
                    Transport = new TBufferedTransport(MemBuffer);
                    break;

                default:
                    Debug.Assert(false);
                    break;
                }

                if (!Transport.IsOpen)
                {
                    Transport.OpenAsync().Wait();
                }

                var instance = (T)Activator.CreateInstance(typeof(T), Transport);
                return(Task.FromResult <TProtocol>(instance));
            }
            finally
            {
                if (oldTrans is IDisposable)
                {
                    (oldTrans as IDisposable).Dispose();
                }
            }
        }
예제 #4
0
        public override async Task OpenAsync(CancellationToken cancellationToken)
        {
            CheckNotDisposed();

            await _transport.OpenAsync(cancellationToken);
        }