Exemplo n.º 1
0
            public static async Task <TestModule> Create(string deviceId, string moduleId, string outputEndpointId, List <string> inputEndpointIds, IEdgeHub edgeHub, IConnectionManager connectionManager)
            {
                IClientCredentials moduleCredentials = SetupModuleCredentials(moduleId, deviceId);
                Try <ICloudProxy>  cloudProxy        = await connectionManager.CreateCloudConnectionAsync(moduleCredentials);

                Assert.True(cloudProxy.Success);
                var deviceListener   = new DeviceMessageHandler(moduleCredentials.Identity, edgeHub, connectionManager);
                var receivedMessages = new List <IMessage>();
                var deviceProxy      = new Mock <IDeviceProxy>();

                deviceProxy.Setup(d => d.SendMessageAsync(It.IsAny <IMessage>(), It.Is <string>(e => inputEndpointIds.Contains(e))))
                .Callback <IMessage, string>((m, e) =>
                {
                    receivedMessages.Add(m);
                    deviceListener.ProcessMessageFeedbackAsync(m.SystemProperties[SystemProperties.LockToken], FeedbackStatus.Complete).Wait();
                })
                .Returns(Task.CompletedTask);
                deviceProxy.SetupGet(d => d.IsActive).Returns(true);
                await connectionManager.AddDeviceConnection(moduleCredentials);

                deviceListener.BindDeviceProxy(deviceProxy.Object);
                await deviceListener.AddSubscription(DeviceSubscription.ModuleMessages);

                return(new TestModule(moduleCredentials.Identity as IModuleIdentity, outputEndpointId, deviceListener, receivedMessages));
            }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
            public static async Task <TestDevice> Create(string deviceId, IEdgeHub edgeHub, IConnectionManager connectionManager)
            {
                IClientCredentials deviceCredentials = SetupDeviceIdentity(deviceId);
                Try <ICloudProxy>  cloudProxy        = await connectionManager.CreateCloudConnectionAsync(deviceCredentials);

                Assert.True(cloudProxy.Success);
                var deviceProxy = Mock.Of <IDeviceProxy>();
                await connectionManager.AddDeviceConnection(deviceCredentials);

                var deviceListener = new DeviceMessageHandler(deviceCredentials.Identity, edgeHub, connectionManager);

                deviceListener.BindDeviceProxy(deviceProxy);
                return(new TestDevice(deviceCredentials.Identity as IDeviceIdentity, deviceListener));
            }
Exemplo n.º 4
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);
        }