示例#1
0
        async Task <SendingAmqpLink> CreateTwinSendingLinkAsync(TimeSpan timeout, CancellationToken cancellationToken)
        {
            string path = string.Format(CultureInfo.InvariantCulture, CommonConstants.DeviceTwinPathTemplate, System.Net.WebUtility.UrlEncode(this.deviceId));

            SendingAmqpLink twinSendingLink = await this.IotHubConnection.CreateSendingLinkAsync(path, this.iotHubConnectionString, this.twinConnectionCorrelationId, IotHubConnection.SendingLinkType.Twin, timeout, cancellationToken);

            MyStringCopy(twinSendingLink.Name, out twinSendingLinkName);
            this.SafeAddClosedTwinSendingLinkHandler = this.linkClosedListener;
            twinSendingLink.SafeAddClosed(async(o, ea) =>
                                          await Task.Run(async() =>
            {
                await this.SafeAddClosedTwinSendingLinkHandler(
                    o,
                    new ConnectionEventArgs
                {
                    ConnectionType               = ConnectionType.AmqpTwinSending,
                    ConnectionStatus             = ConnectionStatus.Disconnected_Retrying,
                    ConnectionStatusChangeReason = ConnectionStatusChangeReason.No_Network
                });
                foreach (var entry in twinResponseCompletions)
                {
                    TaskCompletionSource <AmqpMessage> task;
                    if (this.twinResponseCompletions.TryRemove(entry.Key, out task))
                    {
                        task.SetCanceled();
                    }
                }
            }
                                                         ));

            return(twinSendingLink);
        }
        private async Task EnableSendingLinkAsync(CancellationToken cancellationToken)
        {
            SendingAmqpLink methodSendingLink = await this.GetMethodSendingLinkAsync(cancellationToken);

            this.SafeAddClosedSendingLinkHandler = this.linkClosedListener;
            methodSendingLink.SafeAddClosed((o, ea) => this.SafeAddClosedSendingLinkHandler(o, ea));
        }
示例#3
0
        async Task <SendingAmqpLink> CreateTwinSendingLinkAsync(TimeSpan timeout, CancellationToken cancellationToken)
        {
            string path = this.BuildPath(CommonConstants.DeviceTwinPathTemplate, CommonConstants.ModuleTwinPathTemplate);

            SendingAmqpLink twinSendingLink = await this.IotHubConnection.CreateSendingLinkAsync(path, this.iotHubConnectionString, this.twinConnectionCorrelationId, IotHubConnection.SendingLinkType.Twin, timeout, this.productInfo, cancellationToken).ConfigureAwait(false);

            MyStringCopy(twinSendingLink.Name, out twinSendingLinkName);
            twinSendingLink.SafeAddClosed(async(o, ea) =>
                                          await Task.Run(async() =>
            {
                foreach (var entry in twinResponseCompletions)
                {
                    TaskCompletionSource <AmqpMessage> task;
                    if (this.twinResponseCompletions.TryRemove(entry.Key, out task))
                    {
                        task.SetCanceled();
                    }

                    OnAmqpConnectionClose(o, ea);
                }
            }
                                                         ).ConfigureAwait(false));

            return(twinSendingLink);
        }
        private async Task EnableTwinSendingLinkAsync(CancellationToken cancellationToken)
        {
            SendingAmqpLink twinSendingLink = await this.GetTwinSendingLinkAsync(cancellationToken);

            this.SafeAddClosedTwinSendingLinkHandler = this.linkClosedListener;
            twinSendingLink.SafeAddClosed((o, ea) => this.SafeAddClosedTwinSendingLinkHandler(o, new ConnectionEventArgs {
                ConnectionKey = ConnectionKeys.AmqpTwinSending, ConnectionStatus = ConnectionStatus.Disconnected_Retrying, ConnectionStatusChangeReason = ConnectionStatusChangeReason.No_Network
            }));
        }
示例#5
0
        private async Task EnableMethodSendingLinkAsync(CancellationToken cancellationToken)
        {
            SendingAmqpLink methodSendingLink = await this.GetMethodSendingLinkAsync(cancellationToken);

            this.SafeAddClosedMethodSendingLinkHandler = this.linkClosedListener;
            methodSendingLink.SafeAddClosed((o, ea) => this.SafeAddClosedMethodSendingLinkHandler(o, new ConnectionEventArgs {
                ConnectionKey = ConnectionKeys.AmqpMessaging, ConnectionStatus = ConnectionStatus.Disconnected_Retrying
            }));
        }
示例#6
0
        async Task <SendingAmqpLink> CreateMethodSendingLinkAsync(TimeSpan timeout, CancellationToken cancellationToken)
        {
            string path = this.BuildPath(CommonConstants.DeviceMethodPathTemplate, CommonConstants.ModuleMethodPathTemplate);

            SendingAmqpLink methodSendingLink = await this.IotHubConnection.CreateSendingLinkAsync(path, this.iotHubConnectionString, this.methodConnectionCorrelationId, IotHubConnection.SendingLinkType.Methods, timeout, this.productInfo, cancellationToken).ConfigureAwait(false);

            MyStringCopy(methodSendingLink.Name, out methodSendingLinkName);

            methodSendingLink.SafeAddClosed(OnAmqpConnectionClose);
            return(methodSendingLink);
        }
示例#7
0
        async Task <SendingAmqpLink> CreateTwinSendingLinkAsync(TimeSpan timeout, CancellationToken cancellationToken)
        {
            string path = string.Format(CultureInfo.InvariantCulture, CommonConstants.DeviceTwinPathTemplate, System.Net.WebUtility.UrlEncode(this.deviceId));

            SendingAmqpLink twinSendingLink = await this.IotHubConnection.CreateSendingLinkAsync(path, this.iotHubConnectionString, this.deviceId, IotHubConnection.SendingLinkType.Twin, timeout, cancellationToken);

            this.SafeAddClosedTwinSendingLinkHandler = this.linkClosedListener;
            twinSendingLink.SafeAddClosed((o, ea) => this.SafeAddClosedTwinSendingLinkHandler(o, new ConnectionEventArgs {
                ConnectionType = ConnectionType.AmqpTwinSending, ConnectionStatus = ConnectionStatus.Disconnected_Retrying, ConnectionStatusChangeReason = ConnectionStatusChangeReason.No_Network
            }));

            return(twinSendingLink);
        }
示例#8
0
        async Task <SendingAmqpLink> CreateMethodSendingLinkAsync(TimeSpan timeout, CancellationToken cancellationToken)
        {
            string path = string.Format(CultureInfo.InvariantCulture, CommonConstants.DeviceMethodPathTemplate, System.Net.WebUtility.UrlEncode(this.deviceId));

            SendingAmqpLink methodSendingLink = await this.IotHubConnection.CreateSendingLinkAsync(path, this.iotHubConnectionString, this.methodConnectionCorrelationId, IotHubConnection.SendingLinkType.Methods, timeout, cancellationToken);

            MyStringCopy(methodSendingLink.Name, out methodSendingLinkName);
            this.SafeAddClosedMethodSendingLinkHandler = this.linkClosedListener;
            methodSendingLink.SafeAddClosed(async(o, ea) =>
                                            await Task.Run(async() =>
            {
                await this.SafeAddClosedMethodSendingLinkHandler(
                    o,
                    new ConnectionEventArgs
                {
                    ConnectionType               = ConnectionType.AmqpMethodSending,
                    ConnectionStatus             = ConnectionStatus.Disconnected_Retrying,
                    ConnectionStatusChangeReason = ConnectionStatusChangeReason.No_Network
                });
            }
                                                           ));
            return(methodSendingLink);
        }