示例#1
0
        private void TransferData(int bytesRead, TransportAsyncCallbackArgs args)
        {
            if (bytesRead <= args.Count)
            {
                Buffer.BlockCopy(this.asyncReadBuffer, this.asyncReadBufferOffset, args.Buffer, args.Offset, bytesRead);
                this.asyncReadBufferOffset = 0;
                this.remainingBytes        = 0;
                args.BytesTransfered       = bytesRead;
                return;
            }
            Buffer.BlockCopy(this.asyncReadBuffer, this.asyncReadBufferOffset, args.Buffer, args.Offset, args.Count);
            ClientWebSocketTransport count = this;

            count.asyncReadBufferOffset = count.asyncReadBufferOffset + args.Count;
            this.remainingBytes         = bytesRead - args.Count;
            args.BytesTransfered        = args.Count;
        }
        private void Complete(IAsyncResult connectAsyncResult, bool completeSynchronously)
        {
            EventTraceActivity eventTraceActivity       = new EventTraceActivity();
            TransportBase      clientWebSocketTransport = null;

            try
            {
                try
                {
                    ServiceBusClientWebSocket clientWebSocket = AsyncResult <WebSocketConnectAsyncResult> .End(connectAsyncResult).ClientWebSocket;

                    clientWebSocketTransport = new ClientWebSocketTransport(clientWebSocket, this.uri, this.webSocketTransportSettings, eventTraceActivity);
                    clientWebSocketTransport.Open();
                    MessagingClientEtwProvider.Provider.WebSocketTransportEstablished(eventTraceActivity, this.uri.AbsoluteUri);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    this.callbackArgs.Exception = exception;
                    if (clientWebSocketTransport != null)
                    {
                        clientWebSocketTransport.SafeClose(exception);
                    }
                    clientWebSocketTransport = null;
                }
            }
            finally
            {
                this.callbackArgs.Transport = clientWebSocketTransport;
                this.callbackArgs.CompletedSynchronously = completeSynchronously;
                if (!completeSynchronously)
                {
                    this.callbackArgs.CompletedCallback(this.callbackArgs);
                }
            }
        }