public async Task <IMessagingBridge> Connect(IDeviceIdentity deviceidentity)
        {
            if (!(deviceidentity is ProtocolGatewayIdentity protocolGatewayIdentity))
            {
                throw new AuthenticationException("Invalid identity object received");
            }

            IDeviceListener deviceListener = await this.connectionProvider.GetDeviceListenerAsync(protocolGatewayIdentity.ClientCredentials.Identity);

            IMessagingServiceClient messagingServiceClient = new MessagingServiceClient(deviceListener, this.pgMessageConverter, this.byteBufferConverter);
            IMessagingBridge        messagingBridge        = new SingleClientMessagingBridge(deviceidentity, messagingServiceClient);

            return(messagingBridge);
        }
Beispiel #2
0
        static async Task <IClientCredentials> GetClientCredentials(string iotHubHostName, string deviceId, string userName, string token, bool isCertAuthAllowed = false, string productInfo = "", X509Certificate2 certificate = null, IList <X509Certificate2> chain = null)
        {
            var authenticator = Mock.Of <IAuthenticator>(a => a.AuthenticateAsync(It.IsAny <IClientCredentials>()) == Task.FromResult(true));
            var factory       = new ClientCredentialsFactory(new IdentityProvider(iotHubHostName), productInfo);
            var credentialIdentityProvider = new DeviceIdentityProvider(authenticator, factory, isCertAuthAllowed);

            if (certificate != null && chain != null)
            {
                credentialIdentityProvider.RegisterConnectionCertificate(certificate, chain);
            }

            IDeviceIdentity deviceIdentity = await credentialIdentityProvider.GetAsync(deviceId, userName, token, null);

            Assert.NotNull(deviceIdentity);
            IClientCredentials clientCredentials = (deviceIdentity as ProtocolGatewayIdentity)?.ClientCredentials;

            return(clientCredentials);
        }
Beispiel #3
0
 public virtual Task <ISessionState> GetAsync(IDeviceIdentity identity)
 {
     // This class does not store the session state, so return null to Protocol gateway
     return(Task.FromResult((ISessionState)null));
 }
Beispiel #4
0
 public virtual Task SetAsync(IDeviceIdentity identity, ISessionState sessionState) =>
 sessionState is SessionState registrationSessionState?
Beispiel #5
0
 public virtual Task SetAsync(IDeviceIdentity identity, ISessionState sessionState) =>
 sessionState is SessionState registrationSessionState?this.ProcessSessionSubscriptions(identity.Id, registrationSessionState) : Task.CompletedTask;