Beispiel #1
0
        static Task InitEdgeHub(EdgeHubConnection edgeHubConnection, IConnectionManager connectionManager, IIdentity edgeHubIdentity, IEdgeHub edgeHub)
        {
            IDeviceProxy deviceProxy             = new EdgeHubDeviceProxy(edgeHubConnection);
            Task         addDeviceConnectionTask = connectionManager.AddDeviceConnection(edgeHubIdentity, deviceProxy);
            Task         desiredPropertyUpdatesSubscriptionTask = edgeHub.AddSubscription(edgeHubIdentity.Id, DeviceSubscription.DesiredPropertyUpdates);
            Task         methodsSubscriptionTask           = edgeHub.AddSubscription(edgeHubIdentity.Id, DeviceSubscription.Methods);
            Task         clearDeviceConnectionStatusesTask = edgeHubConnection.ClearDeviceConnectionStatuses();

            return(Task.WhenAll(addDeviceConnectionTask, desiredPropertyUpdatesSubscriptionTask, methodsSubscriptionTask, clearDeviceConnectionStatusesTask));
        }
Beispiel #2
0
        public static async Task <EdgeHubConnection> Create(
            IClientCredentials edgeHubCredentials,
            IEdgeHub edgeHub,
            ITwinManager twinManager,
            IConnectionManager connectionManager,
            ICloudProxy cloudProxy,
            RouteFactory routeFactory,
            IMessageConverter <TwinCollection> twinCollectionMessageConverter,
            IMessageConverter <Twin> twinMessageConverter,
            VersionInfo versionInfo,
            IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache
            )
        {
            Preconditions.CheckNotNull(edgeHubCredentials, nameof(edgeHubCredentials));
            Preconditions.CheckNotNull(edgeHub, nameof(edgeHub));
            Preconditions.CheckNotNull(connectionManager, nameof(connectionManager));
            Preconditions.CheckNotNull(cloudProxy, nameof(cloudProxy));
            Preconditions.CheckNotNull(twinCollectionMessageConverter, nameof(twinCollectionMessageConverter));
            Preconditions.CheckNotNull(twinMessageConverter, nameof(twinMessageConverter));
            Preconditions.CheckNotNull(routeFactory, nameof(routeFactory));
            Preconditions.CheckNotNull(deviceScopeIdentitiesCache, nameof(deviceScopeIdentitiesCache));

            var edgeHubConnection = new EdgeHubConnection(
                edgeHubCredentials.Identity as IModuleIdentity, twinManager, routeFactory,
                twinCollectionMessageConverter, twinMessageConverter,
                versionInfo ?? VersionInfo.Empty,
                deviceScopeIdentitiesCache
                );

            IDeviceProxy deviceProxy = new EdgeHubDeviceProxy(edgeHubConnection);
            await connectionManager.AddDeviceConnection(edgeHubCredentials);

            connectionManager.BindDeviceProxy(edgeHubCredentials.Identity, deviceProxy);

            await edgeHub.AddSubscription(edgeHubCredentials.Identity.Id, DeviceSubscription.DesiredPropertyUpdates);

            await edgeHub.AddSubscription(edgeHubCredentials.Identity.Id, DeviceSubscription.Methods);

            // Clear out all the reported devices.
            await edgeHubConnection.ClearDeviceConnectionStatuses();

            connectionManager.DeviceConnected    += edgeHubConnection.DeviceConnected;
            connectionManager.DeviceDisconnected += edgeHubConnection.DeviceDisconnected;
            Events.Initialized(edgeHubCredentials.Identity);
            return(edgeHubConnection);
        }
Beispiel #3
0
        public async Task RemoveSubscriptionTimesOutTest()
        {
            // Arrange
            string deviceId   = "d1";
            var    cloudProxy = new Mock <ICloudProxy>();

            cloudProxy.Setup(c => c.SetupCallMethodAsync())
            .ThrowsAsync(new TimeoutException());

            var connectionManager = new Mock <IConnectionManager>();

            connectionManager.Setup(c => c.AddSubscription(deviceId, DeviceSubscription.Methods));
            connectionManager.Setup(c => c.GetCloudConnection(deviceId)).Returns(Option.Some(cloudProxy.Object));
            IEdgeHub edgeHub = await GetTestEdgeHub(connectionManager.Object);

            // Act
            await edgeHub.AddSubscription(deviceId, DeviceSubscription.Methods);

            // Assert
            cloudProxy.VerifyAll();
            connectionManager.VerifyAll();
        }
        public async Task AddSubscriptionTest()
        {
            // Arrange
            string deviceId   = "d1";
            var    cloudProxy = new Mock <ICloudProxy>();

            cloudProxy.Setup(c => c.SetupCallMethodAsync())
            .Returns(Task.CompletedTask);

            var connectionManager = new Mock <IConnectionManager>();

            connectionManager.Setup(c => c.AddSubscription(deviceId, DeviceSubscription.Methods));
            connectionManager.Setup(c => c.GetCloudConnection(deviceId)).Returns(Task.FromResult(Option.Some(cloudProxy.Object)));
            IEdgeHub edgeHub = await GetTestEdgeHub(connectionManager.Object);

            // Act
            await edgeHub.AddSubscription(deviceId, DeviceSubscription.Methods);

            // Assert
            cloudProxy.VerifyAll();
            connectionManager.VerifyAll();
        }
Beispiel #5
0
        public async Task RemoveSubscriptionThrowsTest()
        {
            // Arrange
            string deviceId   = "d1";
            var    cloudProxy = new Mock <ICloudProxy>();

            cloudProxy.Setup(c => c.SetupCallMethodAsync())
            .ThrowsAsync(new InvalidOperationException());

            var connectionManager = new Mock <IConnectionManager>();

            connectionManager.Setup(c => c.AddSubscription(deviceId, DeviceSubscription.Methods));
            connectionManager.Setup(c => c.GetCloudConnection(deviceId)).Returns(Task.FromResult(Option.Some(cloudProxy.Object)));
            IEdgeHub edgeHub = await GetTestEdgeHub(connectionManager.Object);

            // Act
            await Assert.ThrowsAsync <InvalidOperationException>(() => edgeHub.AddSubscription(deviceId, DeviceSubscription.Methods));

            // Assert
            cloudProxy.VerifyAll();
            connectionManager.VerifyAll();
        }