Ejemplo n.º 1
0
        public void TestSingleModule()
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appSettings.json")
                                .AddEnvironmentVariables()
                                .Build();

            var host = new TypeEdgeHost(configuration);

            //register the modules
            host.RegisterModule <ITestModule, TestModule>();
            host.Upstream.Subscribe(host.GetProxy <ITestModule>().Output);

            //customize the runtime configuration
            var dockerRegistry = configuration.GetValue <string>("DOCKER_REGISTRY") ?? "";
            var manifest       = host.GenerateDeviceManifest((e, settings) =>
            {
                //this is the opportunity for the host to change the hosting settings of the module e
                if (!settings.IsExternalModule)
                {
                    settings.Config = new DockerConfig($"{dockerRegistry}{e}:latest", settings.Config.CreateOptions);
                }
                return(settings);
            });

            //provision a new device with the new manifest
            var sasToken = host.ProvisionDevice(manifest);

            //build an emulated device in memory
            host.BuildEmulatedDevice(sasToken);

            //run the emulated device
            var task = host.RunAsync();

            Console.WriteLine("Waiting for 20 seconds...");
            Thread.Sleep(20 * 1000);

            ProxyFactory.Configure(configuration["IotHubConnectionString"],
                                   configuration["DeviceId"]);

            var testModule = ProxyFactory.GetModuleProxy <ITestModule>();
            var offset     = new Random().Next(0, 1000);
            var lastTwin   = testModule.Twin.GetAsync().Result;

            lastTwin.Offset = offset;
            var res  = testModule.Twin.PublishAsync(lastTwin).Result;
            var res2 = testModule.TestDirectMethod(10);

            Assert.Equal(res.Offset, offset);
            Assert.Equal(10, res2);
        }
Ejemplo n.º 2
0
        private static async Task Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json")
                                .AddEnvironmentVariables()
                                .AddDotΕnv()
                                .AddCommandLine(args)
                                .Build();

            var host = new TypeEdgeHost(configuration);

            //register the modules
            host.RegisterModule <ITemperatureSensor, TemperatureSensor>();

            //var description = Microsoft.Azure.TypeEdge.Description.ServiceDescriptor.Describe<TemperatureSensor>();
            //Microsoft.Azure.TypeEdge.Host.Service.ServiceGenerator.CreateFiles(description);

            //host.RegisterExternalModule(new TypeEdge.Host.Docker.DockerModule("tempSensor",
            //    new HostingSettings("mcr.microsoft.com/azureiotedge-simulated-temperature-sensor:1.0", null),
            //    null,
            //    null));

            //add cross-module routes
            host.Upstream.Subscribe(host.GetProxy <ITemperatureSensor>().Temperature);

            //customize the runtime configuration
            var dockerRegistry = configuration.GetValue <string>("DOCKER_REGISTRY") ?? "";
            var manifest       = host.GenerateDeviceManifest((e, settings) =>
            {
                //this is the opportunity for the host to change the hosting settings of the module e
                if (!settings.IsExternalModule && !settings.IsSystemModule)
                {
                    settings.Config = new DockerConfig($"{dockerRegistry}{e}:latest", settings.Config.CreateOptions);
                }
                return(settings);
            });

            File.WriteAllText("../../../manifest.json", manifest);

            //provision a new device with the new manifest
            var sasToken = host.ProvisionDevice(manifest);

            //build an emulated device in memory
            host.BuildEmulatedDevice(sasToken);

            //run the emulated device
            await host.RunAsync();

            Console.WriteLine("Press <ENTER> to exit..");
            Console.ReadLine();
        }
Ejemplo n.º 3
0
        public static async Task Main(string[] args)
        {
            Console.WriteLine("Starting Emulator..");

            //TODO: Set your IoT Hub iothubowner connection string in appsettings.json
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appSettings.json")
                                .AddEnvironmentVariables()
                                .AddDotΕnv()
                                .AddCommandLine(args)
                                .Build();

            var host = new TypeEdgeHost(configuration);

            //TODO: Register your TypeEdge Modules here
            host.RegisterModule <ITypeEdgeModule1, Modules.TypeEdgeModule1>();
            host.RegisterModule <ITypeEdgeModule2, Modules.TypeEdgeModule2>();
            host.RegisterModule <ITypeEdgeModule3, Modules.TypeEdgeModule3>();

            //TODO: Define all cross-module subscriptions
            host.Upstream.Subscribe(host.GetProxy <ITypeEdgeModule3>().Output);

            //customize the runtime configuration
            var dockerRegistry = configuration.GetValue <string>("DOCKER_REGISTRY") ?? "";
            var manifest       = host.GenerateDeviceManifest((e, settings) =>
            {
                //this is the opportunity for the host to change the hosting settings of the module e
                if (!settings.IsExternalModule && !settings.IsSystemModule)
                {
                    settings.Config = new DockerConfig($"{dockerRegistry}{e}:latest", settings.Config.CreateOptions);
                }
                return(settings);
            });

            File.WriteAllText("../../../manifest.json", manifest);

            //provision a new device with the new manifest
            var sasToken = host.ProvisionDevice(manifest);

            //build an emulated device in memory
            host.BuildEmulatedDevice(sasToken);

            //run the emulated device
            await host.RunAsync();

            await host.RunAsync();

            Console.WriteLine("Press <ENTER> to exit..");
            Console.ReadLine();
        }
Ejemplo n.º 4
0
        private static async Task Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appSettings.json")
                                .AddEnvironmentVariables()
                                .AddDotΕnv()
                                .AddCommandLine(args)
                                .Build();

            var host = new TypeEdgeHost(configuration);

            host.RegisterModule <ITemperatureSensor, TemperatureSensor>();
            host.RegisterModule <IOrchestrator, Orchestrator>();
            host.RegisterModule <IModelTraining, ModelTraining>();
            host.RegisterModule <IVisualization, Visualization>();
            host.RegisterModule <IAnomalyDetection, AnomalyDetection>();

            host.Upstream.Subscribe(host.GetProxy <IAnomalyDetection>().Anomaly);

            var dockerRegistry = configuration.GetValue <string>("DOCKER_REGISTRY") ?? "";
            var manifest       = host.GenerateDeviceManifest((e, settings) =>
            {
                //this is the opportunity of the host to change the hosting settings of the module e
                if (!settings.IsExternalModule && !settings.IsSystemModule)
                {
                    settings.Config = new DockerConfig($"{dockerRegistry}{e}:latest", settings.Config.CreateOptions);
                }
                return(settings);
            });

            File.WriteAllText("../../../manifest.json", manifest);

            var sasToken = host.ProvisionDevice(manifest);

            host.BuildEmulatedDevice(sasToken);

            await host.RunAsync();

            Console.WriteLine("Press <ENTER> to exit..");
            Console.ReadLine();
        }