public async void GetDeploymentConfigTest2() { // Arrange var runtimeInfo = Mock.Of <IRuntimeInfo>(); var edgeHubModule = Mock.Of <IEdgeHubModule>(m => m.Name == "$edgeHub"); var edgeAgentModule = Mock.Of <IEdgeAgentModule>(m => m.Name == "$edgeAgent"); var systemModules = new SystemModules(edgeAgentModule, edgeHubModule); string customModule1Name = null; string customModule2Name = null; var customModule1 = Mock.Of <IModule>(); var customModule2 = Mock.Of <IModule>(); Mock.Get(customModule1).SetupSet(n => n.Name = It.IsAny <string>()).Callback <string>(n => customModule1Name = n); Mock.Get(customModule2).SetupSet(n => n.Name = It.IsAny <string>()).Callback <string>(n => customModule2Name = n); IDictionary <string, IModule> modules = new Dictionary <string, IModule> { ["module1"] = customModule1, ["module2"] = customModule2 }; var deploymentConfig = new DeploymentConfig("1.0", runtimeInfo, systemModules, modules); var deploymentConfigInfo = new DeploymentConfigInfo(5, deploymentConfig); var edgeAgentConnection = new Mock <IEdgeAgentConnection>(); edgeAgentConnection.Setup(e => e.GetDeploymentConfigInfoAsync()).ReturnsAsync(Option.Some(deploymentConfigInfo)); var configuration = Mock.Of <IConfiguration>(); var twinConfigSource = new TwinConfigSource(edgeAgentConnection.Object, configuration); // Act DeploymentConfigInfo receivedDeploymentConfigInfo = await twinConfigSource.GetDeploymentConfigInfoAsync(); // Assert Assert.NotNull(receivedDeploymentConfigInfo); Assert.NotNull(receivedDeploymentConfigInfo.DeploymentConfig); Assert.Equal(5, receivedDeploymentConfigInfo.Version); DeploymentConfig returnedDeploymentConfig = receivedDeploymentConfigInfo.DeploymentConfig; Assert.Equal(Option.Some(edgeAgentModule), returnedDeploymentConfig.SystemModules.EdgeAgent); Assert.Equal(Option.Some(edgeHubModule), returnedDeploymentConfig.SystemModules.EdgeHub); ModuleSet moduleSet = returnedDeploymentConfig.GetModuleSet(); Assert.Equal(4, returnedDeploymentConfig.GetModuleSet().Modules.Count); Assert.Equal(customModule1.Name, moduleSet.Modules["module1"].Name); Assert.Equal(customModule2.Name, moduleSet.Modules["module2"].Name); Assert.Equal(edgeHubModule.Name, moduleSet.Modules["$edgeHub"].Name); Assert.Equal(edgeAgentModule.Name, moduleSet.Modules["$edgeAgent"].Name); Assert.Equal("module1", customModule1Name); Assert.Equal("module2", customModule2Name); }
public async void GetDeploymentConfigTest1() { // Arrange var edgeAgentConnection = new Mock <IEdgeAgentConnection>(); edgeAgentConnection.Setup(e => e.GetDeploymentConfigInfoAsync()).ReturnsAsync(Option.None <DeploymentConfigInfo>()); var configuration = Mock.Of <IConfiguration>(); var twinConfigSource = new TwinConfigSource(edgeAgentConnection.Object, configuration); // Act DeploymentConfigInfo deploymentConfigInfo = await twinConfigSource.GetDeploymentConfigInfoAsync(); // Assert Assert.NotNull(deploymentConfigInfo); Assert.Equal(-1, deploymentConfigInfo.Version); Assert.Equal(DeploymentConfig.Empty, deploymentConfigInfo.DeploymentConfig); }
public void TestExtractHubTwinAndVerify(string type, string schemaVersion, string algo, string[] signercert, string[] intermediatecacert, string signature) { var desiredProperties = new { routes = new { route = "FROM /messages/* INTO $upstream" }, schemaVersion, storeAndForwardConfiguration = new { timeToLiveSecs = 7200 }, integrity = new { header = new { signercert, intermediatecacert, }, signature = new { bytes = signature, algorithm = algo } }, version = "10" }; TwinCollection twinDesiredProperties = new TwinCollection(JsonConvert.SerializeObject(desiredProperties)); if (type == "good") { Assert.True(TwinConfigSource.ExtractHubTwinAndVerify(twinDesiredProperties)); } else { Assert.False(TwinConfigSource.ExtractHubTwinAndVerify(twinDesiredProperties)); } }
protected override void Load(ContainerBuilder builder) { // IEdgeAgentConnection builder.Register( c => { var serde = c.Resolve <ISerde <DeploymentConfig> >(); var deviceClientprovider = c.Resolve <IModuleClientProvider>(); IEdgeAgentConnection edgeAgentConnection = new EdgeAgentConnection(deviceClientprovider, serde, this.configRefreshFrequency); return(edgeAgentConnection); }) .As <IEdgeAgentConnection>() .SingleInstance(); // Task<IConfigSource> builder.Register( async c => { var serde = c.Resolve <ISerde <DeploymentConfigInfo> >(); var edgeAgentConnection = c.Resolve <IEdgeAgentConnection>(); IEncryptionProvider encryptionProvider = await c.Resolve <Task <IEncryptionProvider> >(); var twinConfigSource = new TwinConfigSource(edgeAgentConnection, this.configuration); IConfigSource backupConfigSource = new FileBackupConfigSource(this.backupConfigFilePath, twinConfigSource, serde, encryptionProvider); return(backupConfigSource); }) .As <Task <IConfigSource> >() .SingleInstance(); // IReporter builder.Register( c => { var runtimeInfoDeserializerTypes = new Dictionary <string, Type> { [DockerType] = typeof(DockerReportedRuntimeInfo), [Constants.Unknown] = typeof(UnknownRuntimeInfo) }; var edgeAgentDeserializerTypes = new Dictionary <string, Type> { [DockerType] = typeof(EdgeAgentDockerRuntimeModule), [Constants.Unknown] = typeof(UnknownEdgeAgentModule) }; var edgeHubDeserializerTypes = new Dictionary <string, Type> { [DockerType] = typeof(EdgeHubDockerRuntimeModule), [Constants.Unknown] = typeof(UnknownEdgeHubModule) }; var moduleDeserializerTypes = new Dictionary <string, Type> { [DockerType] = typeof(DockerRuntimeModule) }; var deserializerTypesMap = new Dictionary <Type, IDictionary <string, Type> > { { typeof(IRuntimeInfo), runtimeInfoDeserializerTypes }, { typeof(IEdgeAgentModule), edgeAgentDeserializerTypes }, { typeof(IEdgeHubModule), edgeHubDeserializerTypes }, { typeof(IModule), moduleDeserializerTypes } }; return(new IoTHubReporter( c.Resolve <IEdgeAgentConnection>(), new TypeSpecificSerDe <AgentState>(deserializerTypesMap), this.versionInfo ) as IReporter); } ) .As <IReporter>() .SingleInstance(); base.Load(builder); }
public async Task TestEdgeHubConnection() { const string EdgeDeviceId = "testHubEdgeDevice1"; var twinMessageConverter = new TwinMessageConverter(); var twinCollectionMessageConverter = new TwinCollectionMessageConverter(); var messageConverterProvider = new MessageConverterProvider( new Dictionary <Type, IMessageConverter>() { { typeof(Message), new DeviceClientMessageConverter() }, { typeof(Twin), twinMessageConverter }, { typeof(TwinCollection), twinCollectionMessageConverter } }); string iotHubConnectionString = await SecretsHelper.GetSecretFromConfigKey("iotHubConnStrKey"); IotHubConnectionStringBuilder iotHubConnectionStringBuilder = IotHubConnectionStringBuilder.Create(iotHubConnectionString); RegistryManager registryManager = RegistryManager.CreateFromConnectionString(iotHubConnectionString); await registryManager.OpenAsync(); string iothubHostName = iotHubConnectionStringBuilder.HostName; var identityProvider = new IdentityProvider(iothubHostName); var identityFactory = new ClientCredentialsFactory(identityProvider); (string edgeDeviceId, string deviceConnStr) = await RegistryManagerHelper.CreateDevice(EdgeDeviceId, iotHubConnectionString, registryManager, true, false); string edgeHubConnectionString = $"{deviceConnStr};ModuleId={EdgeHubModuleId}"; IClientCredentials edgeHubCredentials = identityFactory.GetWithConnectionString(edgeHubConnectionString); string sasKey = ConnectionStringHelper.GetSharedAccessKey(deviceConnStr); var signatureProvider = new SharedAccessKeySignatureProvider(sasKey); var credentialsCache = Mock.Of <ICredentialsCache>(); var metadataStore = new Mock <IMetadataStore>(); metadataStore.Setup(m => m.GetMetadata(It.IsAny <string>())).ReturnsAsync(new ConnectionMetadata("dummyValue")); var cloudConnectionProvider = new CloudConnectionProvider( messageConverterProvider, 1, new ClientProvider(), Option.None <UpstreamProtocol>(), new ClientTokenProvider(signatureProvider, iothubHostName, edgeDeviceId, TimeSpan.FromMinutes(60)), Mock.Of <IDeviceScopeIdentitiesCache>(), credentialsCache, edgeHubCredentials.Identity, TimeSpan.FromMinutes(60), true, TimeSpan.FromSeconds(20), false, Option.None <IWebProxy>(), metadataStore.Object); var deviceConnectivityManager = Mock.Of <IDeviceConnectivityManager>(); var connectionManager = new ConnectionManager(cloudConnectionProvider, Mock.Of <ICredentialsCache>(), identityProvider, deviceConnectivityManager); try { Mock.Get(credentialsCache) .Setup(c => c.Get(edgeHubCredentials.Identity)) .ReturnsAsync(Option.Some(edgeHubCredentials)); Assert.NotNull(edgeHubCredentials); Assert.NotNull(edgeHubCredentials.Identity); // Set Edge hub desired properties await this.SetDesiredProperties(registryManager, edgeDeviceId); var endpointFactory = new EndpointFactory(connectionManager, new RoutingMessageConverter(), edgeDeviceId, 10, 10); var routeFactory = new EdgeRouteFactory(endpointFactory); var dbStoreProvider = new InMemoryDbStoreProvider(); IStoreProvider storeProvider = new StoreProvider(dbStoreProvider); IEntityStore <string, TwinInfo> twinStore = storeProvider.GetEntityStore <string, TwinInfo>("twins"); var twinManager = new TwinManager(connectionManager, twinCollectionMessageConverter, twinMessageConverter, Option.Some(twinStore)); var routerConfig = new RouterConfig(Enumerable.Empty <Route>()); TimeSpan defaultTimeout = TimeSpan.FromSeconds(60); var endpointExecutorFactory = new SyncEndpointExecutorFactory(new EndpointExecutorConfig(defaultTimeout, new FixedInterval(0, TimeSpan.FromSeconds(1)), defaultTimeout, true)); Router router = await Router.CreateAsync(Guid.NewGuid().ToString(), iothubHostName, routerConfig, endpointExecutorFactory); IInvokeMethodHandler invokeMethodHandler = new InvokeMethodHandler(connectionManager); var subscriptionProcessor = new SubscriptionProcessor(connectionManager, invokeMethodHandler, deviceConnectivityManager); IEdgeHub edgeHub = new RoutingEdgeHub(router, new RoutingMessageConverter(), connectionManager, twinManager, edgeDeviceId, invokeMethodHandler, subscriptionProcessor); cloudConnectionProvider.BindEdgeHub(edgeHub); var versionInfo = new VersionInfo("v1", "b1", "c1"); // Create Edge Hub connection EdgeHubConnection edgeHubConnection = await EdgeHubConnection.Create( edgeHubCredentials.Identity, edgeHub, twinManager, connectionManager, routeFactory, twinCollectionMessageConverter, versionInfo, new NullDeviceScopeIdentitiesCache()); await Task.Delay(TimeSpan.FromMinutes(1)); TwinConfigSource configSource = new TwinConfigSource(edgeHubConnection, edgeHubCredentials.Identity.Id, versionInfo, twinManager, twinMessageConverter, twinCollectionMessageConverter, routeFactory); // Get and Validate EdgeHubConfig Option <EdgeHubConfig> edgeHubConfigOption = await configSource.GetConfig(); Assert.True(edgeHubConfigOption.HasValue); EdgeHubConfig edgeHubConfig = edgeHubConfigOption.OrDefault(); Assert.Equal("1.0", edgeHubConfig.SchemaVersion); Assert.NotNull(edgeHubConfig.Routes); Assert.NotNull(edgeHubConfig.StoreAndForwardConfiguration); Assert.Equal(20, edgeHubConfig.StoreAndForwardConfiguration.TimeToLiveSecs); IReadOnlyDictionary <string, RouteConfig> routes = edgeHubConfig.Routes; Assert.Equal(4, routes.Count); RouteConfig route1 = routes["route1"]; Assert.True(route1.Route.Endpoint.GetType() == typeof(CloudEndpoint)); Assert.Equal("route1", route1.Name); Assert.Equal("from /* INTO $upstream", route1.Value); RouteConfig route2 = routes["route2"]; Endpoint endpoint = route2.Route.Endpoint; Assert.True(endpoint.GetType() == typeof(ModuleEndpoint)); Assert.Equal($"{edgeDeviceId}/module2/input1", endpoint.Id); Assert.Equal("route2", route2.Name); Assert.Equal("from /modules/module1 INTO BrokeredEndpoint(\"/modules/module2/inputs/input1\")", route2.Value); RouteConfig route3 = routes["route3"]; endpoint = route3.Route.Endpoint; Assert.True(endpoint.GetType() == typeof(ModuleEndpoint)); Assert.Equal($"{edgeDeviceId}/module3/input1", endpoint.Id); Assert.Equal("route3", route3.Name); Assert.Equal("from /modules/module2 INTO BrokeredEndpoint(\"/modules/module3/inputs/input1\")", route3.Value); RouteConfig route4 = routes["route4"]; endpoint = route4.Route.Endpoint; Assert.True(endpoint.GetType() == typeof(ModuleEndpoint)); Assert.Equal($"{edgeDeviceId}/module4/input1", endpoint.Id); Assert.Equal("route4", route4.Name); Assert.Equal("from /modules/module3 INTO BrokeredEndpoint(\"/modules/module4/inputs/input1\")", route4.Value); // Make sure reported properties were updated appropriately EdgeHubConnection.ReportedProperties reportedProperties = await this.GetReportedProperties(registryManager, edgeDeviceId); Assert.Equal(200, reportedProperties.LastDesiredStatus.Code); Assert.NotNull(reportedProperties.Clients); Assert.Equal(0, reportedProperties.Clients.Count); Assert.Equal("1.0", reportedProperties.SchemaVersion); Assert.Equal(versionInfo, reportedProperties.VersionInfo); // Simulate a module and a downstream device that connects to Edge Hub. string moduleId = "module1"; string sasToken = TokenHelper.CreateSasToken($"{iothubHostName}/devices/{edgeDeviceId}/modules/{moduleId}"); string moduleConnectionstring = $"HostName={iothubHostName};DeviceId={edgeDeviceId};ModuleId={moduleId};SharedAccessSignature={sasToken}"; IClientCredentials moduleClientCredentials = identityFactory.GetWithConnectionString(moduleConnectionstring); var moduleProxy = Mock.Of <IDeviceProxy>(d => d.IsActive); string downstreamDeviceId = "device1"; sasToken = TokenHelper.CreateSasToken($"{iothubHostName}/devices/{downstreamDeviceId}"); string downstreamDeviceConnectionstring = $"HostName={iothubHostName};DeviceId={downstreamDeviceId};SharedAccessSignature={sasToken}"; IClientCredentials downstreamDeviceCredentials = identityFactory.GetWithConnectionString(downstreamDeviceConnectionstring); var downstreamDeviceProxy = Mock.Of <IDeviceProxy>(d => d.IsActive); // Connect the module and downstream device and make sure the reported properties are updated as expected. await connectionManager.AddDeviceConnection(moduleClientCredentials.Identity, moduleProxy); await connectionManager.AddDeviceConnection(downstreamDeviceCredentials.Identity, downstreamDeviceProxy); string moduleIdKey = $"{edgeDeviceId}/{moduleId}"; await Task.Delay(TimeSpan.FromSeconds(10)); reportedProperties = await this.GetReportedProperties(registryManager, edgeDeviceId); Assert.Equal(2, reportedProperties.Clients.Count); Assert.Equal(ConnectionStatus.Connected, reportedProperties.Clients[moduleIdKey].Status); Assert.NotNull(reportedProperties.Clients[moduleIdKey].LastConnectedTimeUtc); Assert.Null(reportedProperties.Clients[moduleIdKey].LastDisconnectTimeUtc); Assert.Equal(ConnectionStatus.Connected, reportedProperties.Clients[downstreamDeviceId].Status); Assert.NotNull(reportedProperties.Clients[downstreamDeviceId].LastConnectedTimeUtc); Assert.Null(reportedProperties.Clients[downstreamDeviceId].LastDisconnectTimeUtc); Assert.Equal(200, reportedProperties.LastDesiredStatus.Code); Assert.Equal("1.0", reportedProperties.SchemaVersion); Assert.Equal(versionInfo, reportedProperties.VersionInfo); // Update desired propertied and make sure callback is called with valid values bool callbackCalled = false; Task ConfigUpdatedCallback(EdgeHubConfig updatedConfig) { Assert.NotNull(updatedConfig); Assert.NotNull(updatedConfig.StoreAndForwardConfiguration); Assert.NotNull(updatedConfig.Routes); routes = updatedConfig.Routes; Assert.Equal(4, routes.Count); route1 = routes["route1"]; Assert.True(route1.Route.Endpoint.GetType() == typeof(CloudEndpoint)); Assert.Equal("route1", route1.Name); Assert.Equal("from /* INTO $upstream", route1.Value); route2 = routes["route2"]; endpoint = route2.Route.Endpoint; Assert.True(endpoint.GetType() == typeof(ModuleEndpoint)); Assert.Equal($"{edgeDeviceId}/module2/input1", endpoint.Id); Assert.Equal("route2", route2.Name); Assert.Equal("from /modules/module1 INTO BrokeredEndpoint(\"/modules/module2/inputs/input1\")", route2.Value); route3 = routes["route4"]; endpoint = route3.Route.Endpoint; Assert.True(endpoint.GetType() == typeof(ModuleEndpoint)); Assert.Equal($"{edgeDeviceId}/module5/input1", endpoint.Id); Assert.Equal("route4", route3.Name); Assert.Equal("from /modules/module3 INTO BrokeredEndpoint(\"/modules/module5/inputs/input1\")", route3.Value); route4 = routes["route5"]; endpoint = route4.Route.Endpoint; Assert.True(endpoint.GetType() == typeof(ModuleEndpoint)); Assert.Equal($"{edgeDeviceId}/module6/input1", endpoint.Id); Assert.Equal("route5", route4.Name); Assert.Equal("from /modules/module5 INTO BrokeredEndpoint(\"/modules/module6/inputs/input1\")", route4.Value); callbackCalled = true; return(Task.CompletedTask); } configSource.SetConfigUpdatedCallback(ConfigUpdatedCallback); await this.UpdateDesiredProperties(registryManager, edgeDeviceId); await Task.Delay(TimeSpan.FromSeconds(5)); Assert.True(callbackCalled); reportedProperties = await this.GetReportedProperties(registryManager, edgeDeviceId); Assert.Equal(200, reportedProperties.LastDesiredStatus.Code); Assert.NotNull(reportedProperties.Clients); Assert.Equal(2, reportedProperties.Clients.Count); Assert.Equal("1.0", reportedProperties.SchemaVersion); Assert.Equal(versionInfo, reportedProperties.VersionInfo); // Disconnect the downstream device and make sure the reported properties are updated as expected. await connectionManager.RemoveDeviceConnection(moduleIdKey); await connectionManager.RemoveDeviceConnection(downstreamDeviceId); await Task.Delay(TimeSpan.FromSeconds(10)); reportedProperties = await this.GetReportedProperties(registryManager, edgeDeviceId); Assert.Equal(1, reportedProperties.Clients.Count); Assert.True(reportedProperties.Clients.ContainsKey(moduleIdKey)); Assert.False(reportedProperties.Clients.ContainsKey(downstreamDeviceId)); Assert.Equal(ConnectionStatus.Disconnected, reportedProperties.Clients[moduleIdKey].Status); Assert.NotNull(reportedProperties.Clients[moduleIdKey].LastConnectedTimeUtc); Assert.NotNull(reportedProperties.Clients[moduleIdKey].LastDisconnectTimeUtc); Assert.Equal(200, reportedProperties.LastDesiredStatus.Code); Assert.Equal("1.0", reportedProperties.SchemaVersion); Assert.Equal(versionInfo, reportedProperties.VersionInfo); // If the edge hub restarts, clear out the connected devices in the reported properties. await EdgeHubConnection.Create( edgeHubCredentials.Identity, edgeHub, twinManager, connectionManager, routeFactory, twinCollectionMessageConverter, versionInfo, new NullDeviceScopeIdentitiesCache()); await Task.Delay(TimeSpan.FromMinutes(1)); reportedProperties = await this.GetReportedProperties(registryManager, edgeDeviceId); Assert.Null(reportedProperties.Clients); Assert.Equal("1.0", reportedProperties.SchemaVersion); Assert.Equal(versionInfo, reportedProperties.VersionInfo); } finally { try { await RegistryManagerHelper.RemoveDevice(edgeDeviceId, registryManager); } catch (Exception) { // ignored } } }
public void TestExtractAgentTwinAndVerify(bool isExceptionExpected, bool expectedResult, TwinConfigSource twinConfigSource, TwinCollection twinDesiredProperties) { if (isExceptionExpected) { Assert.Throws <ManifestSigningIsNotEnabledProperly>(() => twinConfigSource.ExtractHubTwinAndVerify(twinDesiredProperties)); } else { Assert.Equal(expectedResult, twinConfigSource.ExtractHubTwinAndVerify(twinDesiredProperties)); } }
public void TestCheckIfManifestSigningIsEnabled(bool expectedResult, TwinConfigSource twinConfigSource, TwinCollection twinDesiredProperties) { Assert.Equal(expectedResult, twinConfigSource.CheckIfManifestSigningIsEnabled(twinDesiredProperties)); }
protected override void Load(ContainerBuilder builder) { // ILogsUploader builder.Register(c => new AzureBlobLogsUploader(this.iotHubHostName, this.deviceId)) .As <ILogsUploader>() .SingleInstance(); // Task<ILogsProvider> builder.Register( async c => { var logsProcessor = new LogsProcessor(new LogMessageParser(this.iotHubHostName, this.deviceId)); IRuntimeInfoProvider runtimeInfoProvider = await c.Resolve <Task <IRuntimeInfoProvider> >(); return(new LogsProvider(runtimeInfoProvider, logsProcessor) as ILogsProvider); }) .As <Task <ILogsProvider> >() .SingleInstance(); // IRequestManager builder.Register( c => { var requestHandlers = new List <IRequestHandler> { new PingRequestHandler(), new TaskStatusRequestHandler() }; return(new RequestManager(requestHandlers, this.requestTimeout) as IRequestManager); }) .As <IRequestManager>() .SingleInstance(); if (this.experimentalFeatures.EnableUploadLogs) { // Task<IRequestHandler> - LogsUploadRequestHandler builder.Register( async c => { var logsUploader = c.Resolve <ILogsUploader>(); var runtimeInfoProviderTask = c.Resolve <Task <IRuntimeInfoProvider> >(); var logsProviderTask = c.Resolve <Task <ILogsProvider> >(); IRuntimeInfoProvider runtimeInfoProvider = await runtimeInfoProviderTask; ILogsProvider logsProvider = await logsProviderTask; return(new LogsUploadRequestHandler(logsUploader, logsProvider, runtimeInfoProvider) as IRequestHandler); }) .As <Task <IRequestHandler> >() .SingleInstance(); } if (this.experimentalFeatures.EnableGetLogs) { // Task<IRequestHandler> - LogsRequestHandler builder.Register( async c => { var runtimeInfoProviderTask = c.Resolve <Task <IRuntimeInfoProvider> >(); var logsProviderTask = c.Resolve <Task <ILogsProvider> >(); IRuntimeInfoProvider runtimeInfoProvider = await runtimeInfoProviderTask; ILogsProvider logsProvider = await logsProviderTask; return(new LogsRequestHandler(logsProvider, runtimeInfoProvider) as IRequestHandler); }) .As <Task <IRequestHandler> >() .SingleInstance(); } // Task<IRequestHandler> - RestartRequestHandler builder.Register( async c => { var environmentProviderTask = c.Resolve <Task <IEnvironmentProvider> >(); var commandFactoryTask = c.Resolve <Task <ICommandFactory> >(); var configSourceTask = c.Resolve <Task <IConfigSource> >(); IEnvironmentProvider environmentProvider = await environmentProviderTask; ICommandFactory commandFactory = await commandFactoryTask; IConfigSource configSource = await configSourceTask; return(new RestartRequestHandler(environmentProvider, configSource, commandFactory) as IRequestHandler); }) .As <Task <IRequestHandler> >() .SingleInstance(); // ISdkModuleClientProvider builder.Register(c => new SdkModuleClientProvider()) .As <ISdkModuleClientProvider>() .SingleInstance(); // IEdgeAgentConnection builder.Register( c => { var serde = c.Resolve <ISerde <DeploymentConfig> >(); var deviceClientprovider = c.Resolve <IModuleClientProvider>(); var requestManager = c.Resolve <IRequestManager>(); var deviceManager = c.Resolve <IDeviceManager>(); bool enableSubscriptions = !this.experimentalFeatures.DisableCloudSubscriptions; IEdgeAgentConnection edgeAgentConnection = new EdgeAgentConnection(deviceClientprovider, serde, requestManager, deviceManager, enableSubscriptions, this.configRefreshFrequency); return(edgeAgentConnection); }) .As <IEdgeAgentConnection>() .SingleInstance(); // Task<IStreamRequestListener> builder.Register( async c => { if (this.enableStreams) { var runtimeInfoProviderTask = c.Resolve <Task <IRuntimeInfoProvider> >(); var logsProviderTask = c.Resolve <Task <ILogsProvider> >(); var edgeAgentConnection = c.Resolve <IEdgeAgentConnection>(); IRuntimeInfoProvider runtimeInfoProvider = await runtimeInfoProviderTask; ILogsProvider logsProvider = await logsProviderTask; var streamRequestHandlerProvider = new StreamRequestHandlerProvider(logsProvider, runtimeInfoProvider); return(new StreamRequestListener(streamRequestHandlerProvider, edgeAgentConnection) as IStreamRequestListener); } else { return(new NullStreamRequestListener() as IStreamRequestListener); } }) .As <Task <IStreamRequestListener> >() .SingleInstance(); // Task<IConfigSource> builder.Register( async c => { var edgeAgentConnection = c.Resolve <IEdgeAgentConnection>(); var twinConfigSource = new TwinConfigSource(edgeAgentConnection, this.configuration); var backupSourceTask = c.Resolve <Task <IDeploymentBackupSource> >(); IConfigSource backupConfigSource = new BackupConfigSource(await backupSourceTask, twinConfigSource); return(backupConfigSource); }) .As <Task <IConfigSource> >() .SingleInstance(); // IReporter builder.Register( c => { var runtimeInfoDeserializerTypes = new Dictionary <string, Type> { [DockerType] = typeof(DockerReportedRuntimeInfo), [Constants.Unknown] = typeof(UnknownRuntimeInfo) }; var edgeAgentDeserializerTypes = new Dictionary <string, Type> { [DockerType] = typeof(EdgeAgentDockerRuntimeModule), [Constants.Unknown] = typeof(UnknownEdgeAgentModule) }; var edgeHubDeserializerTypes = new Dictionary <string, Type> { [DockerType] = typeof(EdgeHubDockerRuntimeModule), [Constants.Unknown] = typeof(UnknownEdgeHubModule) }; var moduleDeserializerTypes = new Dictionary <string, Type> { [DockerType] = typeof(DockerRuntimeModule) }; var deserializerTypesMap = new Dictionary <Type, IDictionary <string, Type> > { { typeof(IRuntimeInfo), runtimeInfoDeserializerTypes }, { typeof(IEdgeAgentModule), edgeAgentDeserializerTypes }, { typeof(IEdgeHubModule), edgeHubDeserializerTypes }, { typeof(IModule), moduleDeserializerTypes } }; var edgeAgentConnection = c.Resolve <IEdgeAgentConnection>(); return(new IoTHubReporter( edgeAgentConnection, new TypeSpecificSerDe <AgentState>(deserializerTypesMap), this.versionInfo) as IReporter); }) .As <IReporter>() .SingleInstance(); base.Load(builder); }
protected override void Load(ContainerBuilder builder) { // ILogsUploader builder.Register(c => new AzureBlobLogsUploader(this.iotHubHostName, this.deviceId)) .As <ILogsUploader>() .SingleInstance(); // Task<ILogsProvider> builder.Register( async c => { var logsProcessor = new LogsProcessor(new LogMessageParser(this.iotHubHostName, this.deviceId)); IRuntimeInfoProvider runtimeInfoProvider = await c.Resolve <Task <IRuntimeInfoProvider> >(); return(new LogsProvider(runtimeInfoProvider, logsProcessor) as ILogsProvider); }) .As <Task <ILogsProvider> >() .SingleInstance(); // Task<IStreamRequestListener> builder.Register( async c => { if (this.enableStreams) { var runtimeInfoProviderTask = c.Resolve <Task <IRuntimeInfoProvider> >(); var logsProviderTask = c.Resolve <Task <ILogsProvider> >(); IRuntimeInfoProvider runtimeInfoProvider = await runtimeInfoProviderTask; ILogsProvider logsProvider = await logsProviderTask; var streamRequestHandlerProvider = new StreamRequestHandlerProvider(logsProvider, runtimeInfoProvider); return(new StreamRequestListener(streamRequestHandlerProvider) as IStreamRequestListener); } else { return(new NullStreamRequestListener() as IStreamRequestListener); } }) .As <Task <IStreamRequestListener> >() .SingleInstance(); // Task<IRequestManager> builder.Register( async c => { var logsUploader = c.Resolve <ILogsUploader>(); var runtimeInfoProviderTask = c.Resolve <Task <IRuntimeInfoProvider> >(); var logsProviderTask = c.Resolve <Task <ILogsProvider> >(); IRuntimeInfoProvider runtimeInfoProvider = await runtimeInfoProviderTask; ILogsProvider logsProvider = await logsProviderTask; var requestHandlers = new List <IRequestHandler> { new PingRequestHandler(), new LogsUploadRequestHandler(logsUploader, logsProvider, runtimeInfoProvider) }; return(new RequestManager(requestHandlers, this.requestTimeout) as IRequestManager); }) .As <Task <IRequestManager> >() .SingleInstance(); // Task<IEdgeAgentConnection> builder.Register( async c => { var serde = c.Resolve <ISerde <DeploymentConfig> >(); var deviceClientprovider = c.Resolve <IModuleClientProvider>(); var streamRequestListenerTask = c.Resolve <Task <IStreamRequestListener> >(); var requestManagerTask = c.Resolve <Task <IRequestManager> >(); IStreamRequestListener streamRequestListener = await streamRequestListenerTask; IRequestManager requestManager = await requestManagerTask; IEdgeAgentConnection edgeAgentConnection = new EdgeAgentConnection(deviceClientprovider, serde, requestManager, streamRequestListener, this.configRefreshFrequency); return(edgeAgentConnection); }) .As <Task <IEdgeAgentConnection> >() .SingleInstance(); // Task<IConfigSource> builder.Register( async c => { var serde = c.Resolve <ISerde <DeploymentConfigInfo> >(); var edgeAgentConnectionTask = c.Resolve <Task <IEdgeAgentConnection> >(); IEncryptionProvider encryptionProvider = await c.Resolve <Task <IEncryptionProvider> >(); IEdgeAgentConnection edgeAgentConnection = await edgeAgentConnectionTask; var twinConfigSource = new TwinConfigSource(edgeAgentConnection, this.configuration); IConfigSource backupConfigSource = new FileBackupConfigSource(this.backupConfigFilePath, twinConfigSource, serde, encryptionProvider); return(backupConfigSource); }) .As <Task <IConfigSource> >() .SingleInstance(); // Task<IReporter> builder.Register( async c => { var runtimeInfoDeserializerTypes = new Dictionary <string, Type> { [DockerType] = typeof(DockerReportedRuntimeInfo), [Constants.Unknown] = typeof(UnknownRuntimeInfo) }; var edgeAgentDeserializerTypes = new Dictionary <string, Type> { [DockerType] = typeof(EdgeAgentDockerRuntimeModule), [Constants.Unknown] = typeof(UnknownEdgeAgentModule) }; var edgeHubDeserializerTypes = new Dictionary <string, Type> { [DockerType] = typeof(EdgeHubDockerRuntimeModule), [Constants.Unknown] = typeof(UnknownEdgeHubModule) }; var moduleDeserializerTypes = new Dictionary <string, Type> { [DockerType] = typeof(DockerRuntimeModule) }; var deserializerTypesMap = new Dictionary <Type, IDictionary <string, Type> > { { typeof(IRuntimeInfo), runtimeInfoDeserializerTypes }, { typeof(IEdgeAgentModule), edgeAgentDeserializerTypes }, { typeof(IEdgeHubModule), edgeHubDeserializerTypes }, { typeof(IModule), moduleDeserializerTypes } }; var edgeAgentConnectionTask = c.Resolve <Task <IEdgeAgentConnection> >(); IEdgeAgentConnection edgeAgentConnection = await edgeAgentConnectionTask; return(new IoTHubReporter( edgeAgentConnection, new TypeSpecificSerDe <AgentState>(deserializerTypesMap), this.versionInfo) as IReporter); }) .As <Task <IReporter> >() .SingleInstance(); base.Load(builder); }
public void TestCheckIfTwinPropertiesAreSigned(bool expectedResult, TwinCollection twinDesiredProperties) { Assert.Equal(expectedResult, TwinConfigSource.CheckIfTwinPropertiesAreSigned(twinDesiredProperties)); }