public AmqpIoTSession(AmqpConnection amqpConnection)
        {
            AmqpSessionSettings amqpSessionSettings = new AmqpSessionSettings()
            {
                Properties = new Fields()
            };

            AmqpSession = new AmqpSession(amqpConnection, amqpSessionSettings, AmqpIoTLinkFactory.GetInstance());
            amqpConnection.AddSession(AmqpSession, new ushort?());

            AmqpSession.Closed += _amqpSessionClosed;
        }
Example #2
0
        internal async Task <AmqpIoTSession> OpenSessionAsync(TimeSpan timeout)
        {
            if (_amqpConnection.IsClosing())
            {
                throw AmqpIoTExceptionAdapter.RESOUCE_DISCONNECTED_EXCEPTION;
            }

            AmqpSessionSettings amqpSessionSettings = new AmqpSessionSettings()
            {
                Properties = new Fields()
            };

            try
            {
                var amqpSession = new AmqpSession(_amqpConnection, amqpSessionSettings, AmqpIoTLinkFactory.GetInstance());
                _amqpConnection.AddSession(amqpSession, new ushort?());
                await amqpSession.OpenAsync(timeout).ConfigureAwait(false);

                return(new AmqpIoTSession(amqpSession));
            }
            catch (Exception e) when(!e.IsFatal())
            {
                Exception ex = AmqpIoTExceptionAdapter.ConvertToIoTHubException(e, _amqpConnection);

                if (ReferenceEquals(e, ex))
                {
                    throw;
                }
                else
                {
                    if (ex is AmqpIoTResourceException)
                    {
                        _amqpConnection.SafeClose();
                    }
                    throw new IotHubCommunicationException(ex.Message, ex);
                }
            }
        }