Пример #1
0
 async Task CloseInternalAsync()
 {
     try
     {
         await webSocket.CloseAsync().ConfigureAwait(false);
     }
     catch (Exception e)
     {
         if (Fx.IsFatal(e))
         {
             throw;
         }
     }
 }
Пример #2
0
        public async Task LegacyClientWebSocketTransportReadWithoutConnectTest()
        {
            var websocket = new IotHubClientWebSocket(WebSocketConstants.SubProtocols.Amqpwsb10);
            var clientWebSocketTransport = new LegacyClientWebSocketTransport(websocket, TimeSpan.FromSeconds(60), null, null);
            var args      = new TransportAsyncCallbackArgs();
            var byteArray = new byte[10];

            args.SetBuffer(byteArray, 0, 10);
            if (clientWebSocketTransport.ReadAsync(args))
            {
                while (!readComplete)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            }

            await websocket.CloseAsync().ConfigureAwait(false);
        }
Пример #3
0
        public async Task LegacyClientWebSocketTransportReadWithoutConnectTest()
        {
            var  websocket = new IotHubClientWebSocket(WebSocketConstants.SubProtocols.Amqpwsb10);
            var  clientWebSocketTransport = new LegacyClientWebSocketTransport(websocket, s_oneMinute, null, null);
            var  args           = new TransportAsyncCallbackArgs();
            bool isReadComplete = false;

            args.CompletedCallback = (TransportAsyncCallbackArgs args) =>
            {
                if (args.Exception != null)
                {
                    throw args.Exception;
                }

                // Verify that data matches what was sent
                if (s_byteArray.Length != args.Count)
                {
                    throw new InvalidOperationException("Expected " + s_byteArray.Length + " bytes in response");
                }

                for (int i = 0; i < args.Count; i++)
                {
                    if (s_byteArray[i] != args.Buffer[i])
                    {
                        throw new InvalidOperationException("Response contents do not match what was sent");
                    }
                }

                isReadComplete = true;
            };
            var byteArray = new byte[10];

            args.SetBuffer(byteArray, 0, 10);
            if (clientWebSocketTransport.ReadAsync(args))
            {
                while (!isReadComplete)
                {
                    await Task.Delay(s_oneSecond);
                }
            }

            await websocket.CloseAsync().ConfigureAwait(false);
        }