• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Transport.TransportAsyncCallbackArgs类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.Azure.Amqp.Transport.TransportAsyncCallbackArgs的典型用法代码示例。如果您正苦于以下问题:C# TransportAsyncCallbackArgs类的具体用法?C# TransportAsyncCallbackArgs怎么用?C# TransportAsyncCallbackArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TransportAsyncCallbackArgs类属于Microsoft.Azure.Amqp.Transport命名空间,在下文中一共展示了TransportAsyncCallbackArgs类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: WriteAsync

        public sealed override bool WriteAsync(TransportAsyncCallbackArgs args)
        {
            Fx.Assert(args.Buffer != null || args.ByteBufferList != null, "must have a buffer or buffers to write");
            Fx.Assert(args.CompletedCallback != null, "must have a valid callback");
            Fx.Assert(args.BytesTransfered == 0, "args.BytesTransfered != 0");
            Fx.Assert(this.sendEventArgs.Args == null, "write is pending");

            this.sendEventArgs.PrepareWrite(args.Count);

            if (args.Buffer != null)
            {
                this.sendEventArgs.SetBuffer(args.Buffer, args.Offset, args.Count);
            }
            else
            {
                ArraySegment<byte>[] buffers = new ArraySegment<byte>[args.ByteBufferList.Count];
                for (int i = 0; i < buffers.Length; ++i)
                {
                    buffers[i] = new ArraySegment<byte>(args.ByteBufferList[i].Buffer, args.ByteBufferList[i].Offset, args.ByteBufferList[i].Length);
                }

                this.sendEventArgs.BufferList = buffers;
            }

            this.sendEventArgs.Args = args;
            if (!this.socket.SendAsync(this.sendEventArgs))
            {
                this.HandleWriteComplete(args, true);
                return false;
            }

            return true;
        }
开发者ID:Azure,项目名称:azure-amqp,代码行数:33,代码来源:TcpTransport.cs


示例2: ConnectAsync

        public override bool ConnectAsync(TimeSpan timeout, TransportAsyncCallbackArgs callbackArgs)
        {
            // TODO: set socket connect timeout to timeout
            this.callbackArgs = callbackArgs;
            DnsEndPoint dnsEndPoint = new DnsEndPoint(this.transportSettings.Host, this.transportSettings.Port);

            SocketAsyncEventArgs connectEventArgs = new SocketAsyncEventArgs();
            connectEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(OnConnectComplete);
            connectEventArgs.RemoteEndPoint = dnsEndPoint;
            connectEventArgs.UserToken = this;

#if MONOANDROID
            // Work around for Mono issue: https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/171
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            bool connectResult = socket.ConnectAsync(connectEventArgs);
#else
            // On Linux platform, socket connections are allowed to be initiated on the socket instance 
            // with hostname due to multiple IP address DNS resolution possibility.
            // They suggest either using static Connect API or IP address directly.
            bool connectResult = Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, connectEventArgs);
#endif
            if (connectResult)
            {
                return true;
            }
            else
            {
                this.Complete(connectEventArgs, true);
                return false;
            }
        }
开发者ID:Azure,项目名称:azure-amqp,代码行数:31,代码来源:TcpTransportInitiator.cs


示例3: HandleInnerTransportConnected

        void HandleInnerTransportConnected(TransportAsyncCallbackArgs innerArgs)
        {
            this.callbackArgs.CompletedSynchronously = innerArgs.CompletedSynchronously;
            if (innerArgs.Exception != null)
            {
                this.callbackArgs.Exception = innerArgs.Exception;
                this.Complete();
            }
            else
            {
                Fx.Assert(innerArgs.Transport != null, "must have a valid inner transport");
                // upgrade transport
                this.callbackArgs.Transport = new TlsTransport(innerArgs.Transport, this.transportSettings);
                try
                {
                    IAsyncResult result = this.callbackArgs.Transport.BeginOpen(this.timeoutHelper.RemainingTime(), onTransportOpened, this);
                    if (result.CompletedSynchronously)
                    {
                        this.HandleTransportOpened(result);
                        this.Complete();
                    }
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }

                    this.callbackArgs.Exception = exception;
                    this.Complete();
                }
            }
        }
开发者ID:Azure,项目名称:azure-amqp,代码行数:34,代码来源:TlsTransportInitiator.cs


示例4: OnAcceptInnerTransport

        void OnAcceptInnerTransport(TransportListener innerListener, TransportAsyncCallbackArgs innerArgs)
        {
            Fx.Assert(innerArgs.Exception == null, "Should not be called with an exception.");
            Fx.Assert(innerArgs.Transport != null, "Should be called with a transport.");
            AmqpTrace.Provider.AmqpLogOperationInformational(this, TraceOperation.Accept, innerArgs.Transport);

            try
            {
                // upgrade transport
                innerArgs.Transport = new TlsTransport(innerArgs.Transport, this.transportSettings);
                IAsyncResult result = innerArgs.Transport.BeginOpen(
                    innerArgs.Transport.DefaultOpenTimeout, 
                    this.onTransportOpened,
                    innerArgs);
                if (result.CompletedSynchronously)
                {
                    this.HandleTransportOpened(result);
                    return;
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }

                innerArgs.Transport.SafeClose(exception);
            }
        }
开发者ID:Azure,项目名称:azure-amqp,代码行数:30,代码来源:TlsTransportListener.cs


示例5: ClientWebSocketTransportWriteWithoutConnectTest

 public void ClientWebSocketTransportWriteWithoutConnectTest()
 {
     var websocket = new ClientWebSocket();
     var clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null);
     var args = new TransportAsyncCallbackArgs();
     args.SetBuffer(byteArray, 0, byteArray.Length);
     clientWebSocketTransport.WriteAsync(args);
 }
开发者ID:pierreca,项目名称:azure-iot-sdks,代码行数:8,代码来源:ClientWebSocketTransportTests.cs


示例6: ClientWebSocketTransportReadTest

 public void ClientWebSocketTransportReadTest()
 {
     var websocket = new ClientWebSocket();
     var clientWebSocketTransport = new ClientWebSocketTransport(websocket, IotHubName, null, null);
     TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs();
     byte[] byteArray = new byte[10];
     args.SetBuffer(byteArray, 0, 10);
     clientWebSocketTransport.ReadAsync(args);
 }
开发者ID:stefangordon,项目名称:azure-iot-sdks,代码行数:9,代码来源:ClientWebSocketTransportTests.cs


示例7: OnTransportAccepted

 protected void OnTransportAccepted(TransportAsyncCallbackArgs args)
 {
     if (args.CompletedSynchronously)
     {
         ActionItem.Schedule(this.notifyAccept, args);
     }
     else
     {
         this.NotifyAccept(args);
     }
 }
开发者ID:Azure,项目名称:azure-amqp,代码行数:11,代码来源:TransportListener.cs


示例8: ClientWebSocketTransportReadWithoutConnectTest

        public async Task ClientWebSocketTransportReadWithoutConnectTest()
        {
            var websocket = new ClientWebSocket();
            var clientWebSocketTransport = new ClientWebSocketTransport(websocket, 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(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None);
        }
开发者ID:pierreca,项目名称:azure-iot-sdks,代码行数:17,代码来源:ClientWebSocketTransportTests.cs


示例9: WriteAsync

        public override bool WriteAsync(TransportAsyncCallbackArgs args)
        {
            this.ThrowIfNotOpen();

            Fx.AssertAndThrow(args.Buffer != null || args.ByteBufferList != null, "must have a buffer to write");
            Fx.AssertAndThrow(args.CompletedCallback != null, "must have a valid callback");
            args.Exception = null; // null out any exceptions

            Task taskResult = this.WriteAsyncCore(args);
            if (WriteTaskDone(taskResult, args))
            {
                return false;
            }

            taskResult.ToAsyncResult(onWriteComplete, args);
            return true;
        }
开发者ID:Fricsay,项目名称:azure-iot-sdks,代码行数:17,代码来源:ClientWebSocketTransport.cs


示例10: WriteAsync

        public override bool WriteAsync(TransportAsyncCallbackArgs args)
        {
            Fx.Assert(this.writeState.Args == null, "Cannot write when a write is still in progress");
            ArraySegment<byte> buffer;
            if (args.Buffer != null)
            {
                buffer = new ArraySegment<byte>(args.Buffer, args.Offset, args.Count);
                this.writeState.Args = args;
            }
            else
            {
                Fx.Assert(args.ByteBufferList != null, "Buffer list should not be null when buffer is null");
                if (args.ByteBufferList.Count == 1)
                {
                    ByteBuffer byteBuffer = args.ByteBufferList[0];
                    buffer = new ArraySegment<byte>(byteBuffer.Buffer, byteBuffer.Offset, byteBuffer.Length);
                    this.writeState.Args = args;
                }
                else
                {
                    // Copy all buffers into one big buffer to avoid SSL overhead
                    Fx.Assert(args.Count > 0, "args.Count should be set");
                    ByteBuffer temp = new ByteBuffer(args.Count, false, false);
                    for (int i = 0; i < args.ByteBufferList.Count; ++i)
                    {
                        ByteBuffer byteBuffer = args.ByteBufferList[i];
                        Buffer.BlockCopy(byteBuffer.Buffer, byteBuffer.Offset, temp.Buffer, temp.Length, byteBuffer.Length);
                        temp.Append(byteBuffer.Length);
                    }

                    buffer = new ArraySegment<byte>(temp.Buffer, 0, temp.Length);
                    this.writeState.Args = args;
                    this.writeState.Buffer = temp;
                }
            }

            IAsyncResult result = this.sslStream.BeginWrite(buffer.Array, buffer.Offset, buffer.Count, onWriteComplete, this);
            bool completedSynchronously = result.CompletedSynchronously;
            if (completedSynchronously)
            {
                this.HandleOperationComplete(result, true, true);
            }

            return !completedSynchronously;
        }
开发者ID:Azure,项目名称:azure-amqp,代码行数:45,代码来源:TlsTransport.cs


示例11: ConnectAsync

        public override bool ConnectAsync(TimeSpan timeout, TransportAsyncCallbackArgs callbackArgs)
        {
            var streamSocket = new Windows.Networking.Sockets.StreamSocket();
            var addr = this.transportSettings.Host;

            this.callbackArgs = callbackArgs;

            var connectTask = streamSocket.ConnectAsync(new Windows.Networking.HostName(addr), this.transportSettings.Port.ToString(), Windows.Networking.Sockets.SocketProtectionLevel.PlainSocket).AsTask();
            connectTask.ContinueWith(_ =>
            {
                TransportBase transport = null;
                Exception exception = null;

                try
                {
                    transport = new TcpTransport(streamSocket, this.transportSettings);
                    transport.Open();
                }
                catch (Exception exp)
                {
                    if (Fx.IsFatal(exp))
                    {
                        throw;
                    }

                    exception = exp;
                    if (transport != null)
                    {
                        transport.SafeClose();
                    }
                    transport = null;
                }

                var completeSynchronously = false;
                this.callbackArgs.CompletedSynchronously = completeSynchronously;
                this.callbackArgs.Exception = exception;
                this.callbackArgs.Transport = transport;

                if (!completeSynchronously)
                {
                    this.callbackArgs.CompletedCallback(this.callbackArgs);
                }
            });
            return true;
        }
开发者ID:Azure,项目名称:azure-amqp,代码行数:45,代码来源:TcpTransportInitiator.UWP.cs


示例12: ReadWriteTest

        public void ReadWriteTest()
        {
            var websocket = new ClientWebSocket();
            // Set SubProtocol to AMQPWSB10
            websocket.Options.AddSubProtocol(WebSocketConstants.SubProtocols.Amqpwsb10);
            Uri uri = new Uri("ws://" + IotHubName + ":" + Port + WebSocketConstants.UriSuffix);
            websocket.ConnectAsync(uri, CancellationToken.None).Wait(CancellationToken.None);
            clientWebSocketTransport = new ClientWebSocketTransport(websocket, IotHubName, null, null);

            // Test Write API
            TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs();
            args.CompletedCallback = onWriteOperationComplete;
            args.SetBuffer(byteArray, 0, byteArray.Length);
            clientWebSocketTransport.WriteAsync(args);

            // Test Read API
            args.CompletedCallback = onReadOperationComplete;
            clientWebSocketTransport.ReadAsync(args);
        }
开发者ID:stefangordon,项目名称:azure-iot-sdks,代码行数:19,代码来源:ClientWebSocketTransportTests.cs


示例13: ConnectAsync

        public override bool ConnectAsync(TimeSpan timeout, TransportAsyncCallbackArgs callbackArgs)
        {
            AmqpTrace.Provider.AmqpLogOperationInformational(this, TraceOperation.Connect, this.transportSettings);
            TransportInitiator innerInitiator = this.transportSettings.CreateInitiator();
            TransportAsyncCallbackArgs args = new TransportAsyncCallbackArgs();
            args.CompletedCallback = this.OnConnectComplete;
            args.UserToken = callbackArgs;
            callbackArgs.CompletedSynchronously = false;
            this.timeoutHelper = new TimeoutHelper(timeout);
            if (innerInitiator.ConnectAsync(timeout, args))
            {
                return true;
            }

            int currentThread = CurrentThreadId;
            Interlocked.Exchange(ref this.completingThread, currentThread);
            this.OnConnectComplete(args);
            return Interlocked.Exchange(ref this.completingThread, -1) != 0;
        }
开发者ID:Azure,项目名称:azure-amqp,代码行数:19,代码来源:AmqpTransportInitiator.cs


示例14: ConnectAsync

        public override bool ConnectAsync(TimeSpan timeout, TransportAsyncCallbackArgs callbackArgs)
        {
            this.callbackArgs = callbackArgs;
            this.timeoutHelper = new TimeoutHelper(timeout);
            TransportInitiator innerInitiator = this.transportSettings.InnerTransportSettings.CreateInitiator();

            TransportAsyncCallbackArgs innerArgs = new TransportAsyncCallbackArgs();
            innerArgs.CompletedCallback = OnInnerTransportConnected;
            innerArgs.UserToken = this;
            if (innerInitiator.ConnectAsync(timeout, innerArgs))
            {
                // pending
                return true;
            }
            else
            {
                this.HandleInnerTransportConnected(innerArgs);
                return !this.callbackArgs.CompletedSynchronously;
            }
        }
开发者ID:Azure,项目名称:azure-amqp,代码行数:20,代码来源:TlsTransportInitiator.cs


示例15: WriteAsyncCore

        async Task WriteAsyncCore(TransportAsyncCallbackArgs args)
        {
            bool succeeded = false;
            try
            {
                if (args.Buffer != null)
                {
                    var arraySegment = new ArraySegment<byte>(args.Buffer, args.Offset, args.Count);
                    await this.webSocket.SendAsync(arraySegment, WebSocketMessageType.Binary, true, this.writeCancellationTokenSource.Token);
                }
                else
                {
                    foreach (ByteBuffer byteBuffer in args.ByteBufferList)
                    {
                        await this.webSocket.SendAsync(new ArraySegment<byte>(byteBuffer.Buffer, byteBuffer.Offset, byteBuffer.Length),
                            WebSocketMessageType.Binary, true, this.writeCancellationTokenSource.Token);
                    }
                }

                succeeded = true;
            }
            catch (WebSocketException webSocketException)
            {
                throw new IOException(webSocketException.Message, webSocketException);
            }
            catch (HttpListenerException httpListenerException)
            {
                throw new IOException(httpListenerException.Message, httpListenerException);
            }
            catch (TaskCanceledException taskCanceledException)
            {
                throw new TimeoutException(taskCanceledException.Message, taskCanceledException);
            }
            finally
            {
                if (!succeeded)
                {
                    this.Abort();
                }
            }
        }
开发者ID:Fricsay,项目名称:azure-iot-sdks,代码行数:41,代码来源:ClientWebSocketTransport.cs


示例16: WriteAsyncCore

        async Task WriteAsyncCore(TransportAsyncCallbackArgs args)
        {
            bool succeeded = false;
            try
            {
                if (args.Buffer != null)
                {
                    await this.webSocket.SendAsync(args.Buffer, args.Offset, args.Count, IotHubClientWebSocket.WebSocketMessageType.Binary, this.operationTimeout);
                }
                else
                {
                    foreach (ByteBuffer byteBuffer in args.ByteBufferList)
                    {
                        await this.webSocket.SendAsync(byteBuffer.Buffer, byteBuffer.Offset, byteBuffer.Length, IotHubClientWebSocket.WebSocketMessageType.Binary, this.operationTimeout);
                    }
                }

                succeeded = true;
            }
            catch (WebSocketException webSocketException)
            {
                throw new IOException(webSocketException.Message, webSocketException);
            }
            catch (HttpListenerException httpListenerException)
            {
                throw new IOException(httpListenerException.Message, httpListenerException);
            }
            catch (TaskCanceledException taskCanceledException)
            {
                throw new TimeoutException(taskCanceledException.Message, taskCanceledException);
            }
            finally
            {
                if (!succeeded)
                {
                    this.Abort();
                }
            }
        }
开发者ID:Fricsay,项目名称:azure-iot-sdks,代码行数:39,代码来源:LegacyClientWebSocketTransport.cs


示例17: ReadAsync

 public sealed override bool ReadAsync(TransportAsyncCallbackArgs args)
 {
     throw new NotImplementedException("Not supported in UWP");
 }
开发者ID:Azure,项目名称:azure-amqp,代码行数:4,代码来源:TcpTransport.UWP.cs


示例18: ReadWriteTest

        public async Task ReadWriteTest()
        {
            var websocket = new ClientWebSocket();
            // Set SubProtocol to AMQPWSB10
            websocket.Options.AddSubProtocol(WebSocketConstants.SubProtocols.Amqpwsb10);
            Uri uri = new Uri("ws://" + IotHubName + ":" + Port + WebSocketConstants.UriSuffix);
            await websocket.ConnectAsync(uri, CancellationToken.None);
            clientWebSocketTransport = new ClientWebSocketTransport(websocket, null, null);

            // Test Write API
            var args = new TransportAsyncCallbackArgs();
            args.CompletedCallback = onWriteOperationComplete;
            args.SetBuffer(byteArray, 0, byteArray.Length);
            clientWebSocketTransport.WriteAsync(args);

            // Test Read API
            args.CompletedCallback = onReadOperationComplete;
            if (clientWebSocketTransport.ReadAsync(args))
            {
                while (!readComplete)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            }

            // Once Read operation is complete, close websocket transport
            // Test Close API
            await clientWebSocketTransport.CloseAsync(TimeSpan.FromSeconds(30));
        }
开发者ID:pierreca,项目名称:azure-iot-sdks,代码行数:29,代码来源:ClientWebSocketTransportTests.cs


示例19: ReadAsyncCore

        async Task<int> ReadAsyncCore(TransportAsyncCallbackArgs args)
        {
            bool succeeded = false;
            try
            {
                WebSocketReceiveResult receiveResult = await this.webSocket.ReceiveAsync(
                    new ArraySegment<byte>(args.Buffer, args.Offset, args.Count), CancellationToken.None);

                succeeded = true;
                return receiveResult.Count;
            }
            catch (WebSocketException webSocketException)
            {
                throw new IOException(webSocketException.Message, webSocketException);
            }
            catch (HttpListenerException httpListenerException)
            {
                throw new IOException(httpListenerException.Message, httpListenerException);
            }
            catch (TaskCanceledException taskCanceledException)
            {
                throw new TimeoutException(taskCanceledException.Message, taskCanceledException);
            }
            finally
            {
                if (!succeeded)
                {
                    this.Abort();
                }
            }
        }
开发者ID:Fricsay,项目名称:azure-iot-sdks,代码行数:31,代码来源:ClientWebSocketTransport.cs


示例20: OnReadOperationComplete

        static void OnReadOperationComplete(TransportAsyncCallbackArgs args)
        {
            if (args.Exception != null)
            {
                throw args.Exception;
            }

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

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

            readComplete = true;
        }
开发者ID:pierreca,项目名称:azure-iot-sdks,代码行数:23,代码来源:ClientWebSocketTransportTests.cs



注:本文中的Microsoft.Azure.Amqp.Transport.TransportAsyncCallbackArgs类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Models.BatchClient类代码示例发布时间:2022-05-26
下一篇:
C# Azure.TokenCloudCredentials类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap