protected override void Load(ContainerBuilder builder) { // Task<IConfigSource> builder.Register( async c => { var serde = c.Resolve <ISerde <DeploymentConfigInfo> >(); IConfigSource config = await FileConfigSource.Create( this.configFilename, this.configuration, serde); return(config); }) .As <Task <IConfigSource> >() .SingleInstance(); // Task<IReporter> // TODO: When using a file backed config source we need to figure out // how reporting will work. builder.Register(c => NullReporter.Instance as IReporter) .As <IReporter>() .SingleInstance(); base.Load(builder); }
public async void ChangeFileAndSeeChange() { // Set up initial config file and create `FileConfigSource` File.WriteAllText(this.tempFileName, ValidJson1); Diff validDiff1To2 = ValidSet2.Diff(ValidSet1); using (FileConfigSource configSource = await FileConfigSource.Create(this.tempFileName, this.config, this.serde)) { Assert.NotNull(configSource); DeploymentConfigInfo deploymentConfigInfo = await configSource.GetDeploymentConfigInfoAsync(); Assert.NotNull(deploymentConfigInfo); ModuleSet initialModuleSet = deploymentConfigInfo.DeploymentConfig.GetModuleSet(); Diff emptyDiff = ValidSet1.Diff(initialModuleSet); Assert.True(emptyDiff.IsEmpty); // Modify the config file by writing new content. File.WriteAllText(this.tempFileName, ValidJson2); await Task.Delay(TimeSpan.FromSeconds(20)); DeploymentConfigInfo updatedAgentConfig = await configSource.GetDeploymentConfigInfoAsync(); Assert.NotNull(updatedAgentConfig); ModuleSet updatedModuleSet = updatedAgentConfig.DeploymentConfig.GetModuleSet(); Diff newDiff = updatedModuleSet.Diff(initialModuleSet); Assert.False(newDiff.IsEmpty); Assert.Equal(newDiff, validDiff1To2); } }
public async void CreateSuccess() { File.WriteAllText(this.tempFileName, ValidJson1); using (FileConfigSource configSource = await FileConfigSource.Create(this.tempFileName, this.config, this.serde)) { Assert.NotNull(configSource); DeploymentConfigInfo deploymentConfigInfo = await configSource.GetDeploymentConfigInfoAsync(); Assert.NotNull(deploymentConfigInfo); Assert.NotNull(deploymentConfigInfo.DeploymentConfig); ModuleSet moduleSet = deploymentConfigInfo.DeploymentConfig.GetModuleSet(); Diff emptyDiff = ValidSet1.Diff(moduleSet); Assert.True(emptyDiff.IsEmpty); } }
protected override void Load(ContainerBuilder builder) { // Task<IConfigSource> builder.Register( async c => { var serde = c.Resolve <ISerde <DeploymentConfigInfo> >(); IConfigSource config = await FileConfigSource.Create( this.configFilename, this.configuration, serde); return(config); }) .As <Task <IConfigSource> >() .SingleInstance(); // IReporter // TODO: When using a file backed config source we need to figure out // how reporting will work. builder.Register(c => NullReporter.Instance as IReporter) .As <IReporter>() .SingleInstance(); // IRequestManager builder.Register( c => new RequestManager(Enumerable.Empty <IRequestHandler>(), TimeSpan.Zero) as IRequestManager) .As <IRequestManager>() .SingleInstance(); // Task<IStreamRequestListener> builder.Register(c => Task.FromResult(new NullStreamRequestListener() as IStreamRequestListener)) .As <Task <IStreamRequestListener> >() .SingleInstance(); base.Load(builder); }
protected override void Load(ContainerBuilder builder) { // Task<IConfigSource> builder.Register( async c => { var serde = c.Resolve <ISerde <DeploymentConfigInfo> >(); IConfigSource config = await FileConfigSource.Create( this.configFilename, this.configuration, serde); return(config); }) .As <Task <IConfigSource> >() .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>(); var deploymentMetrics = c.Resolve <IDeploymentMetrics>(); Option <X509Certificate2> manifestTrustBundle = Option.None <X509Certificate2>(); IEdgeAgentConnection edgeAgentConnection = new EdgeAgentConnection(deviceClientprovider, serde, requestManager, deviceManager, deploymentMetrics, manifestTrustBundle); return(edgeAgentConnection); }) .As <IEdgeAgentConnection>() .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(); // IRequestManager builder.Register( c => new RequestManager(Enumerable.Empty <IRequestHandler>(), TimeSpan.Zero) as IRequestManager) .As <IRequestManager>() .SingleInstance(); // Task<IStreamRequestListener> builder.Register(c => Task.FromResult(new NullStreamRequestListener() as IStreamRequestListener)) .As <Task <IStreamRequestListener> >() .SingleInstance(); base.Load(builder); }