Exemplo n.º 1
0
        private async Task RunAsync(CancellationToken cancellationToken)
        {
            var startTime = DateTime.Now;

            // Dependencies to inject into the Bulk Device Tester
            var logger           = new TraceLogger();
            var configProvider   = new ConfigurationProvider();
            var telemetryFactory = new CoolerTelemetryFactory(logger);

            var serializer       = new JsonSerialize();
            var transportFactory = new IotHubTransportFactory(serializer, logger, configProvider);

            IVirtualDeviceStorage deviceStorage = null;
            var useConfigforDeviceList          = Convert.ToBoolean(configProvider.GetConfigurationSettingValueOrDefault("UseConfigForDeviceList", "False"));

            if (useConfigforDeviceList)
            {
                deviceStorage = new AppConfigRepository(configProvider, logger);
            }
            else
            {
                deviceStorage = new VirtualDeviceTableStorage(configProvider);
            }

            IDeviceFactory deviceFactory = new CoolerDeviceFactory();

            var tester = new BulkDeviceTester(transportFactory, logger, configProvider, telemetryFactory, deviceFactory, deviceStorage);
            await tester.ProcessDevicesAsync(cancellationToken);

            Trace.TraceInformation("");
            Trace.TraceInformation("*********************************************************************************************************************");
            Trace.TraceInformation("ELAPSED TIME: {0}ms", (DateTime.Now - startTime).TotalMilliseconds);
            Trace.TraceInformation("*********************************************************************************************************************");
            Trace.TraceInformation("");
        }
        static void StartSimulator()
        {
            // Dependencies to inject into the Bulk Device Tester
            var logger = new TraceLogger();
            var configProvider = new ConfigurationProvider();
            var telemetryFactory = new CoolerTelemetryFactory(logger);

            var serializer = new JsonSerialize();
            var transportFactory = new IotHubTransportFactory(serializer, logger, configProvider);

            IVirtualDeviceStorage deviceStorage = null;
            var useConfigforDeviceList = Convert.ToBoolean(configProvider.GetConfigurationSettingValueOrDefault("UseConfigForDeviceList", "False"));

            if (useConfigforDeviceList)
            {
                deviceStorage = new AppConfigRepository(configProvider, logger);
            }
            else
            {
                deviceStorage = new VirtualDeviceTableStorage(configProvider);
            }

            IDeviceFactory deviceFactory = new CoolerDeviceFactory();

            // Start Simulator
            Trace.TraceInformation("Starting Simulator");
            var tester = new BulkDeviceTester(transportFactory, logger, configProvider, telemetryFactory, deviceFactory, deviceStorage);
            Task.Run(() => tester.ProcessDevicesAsync(cancellationTokenSource.Token), cancellationTokenSource.Token);
        }
        private async Task RunAsync(CancellationToken cancellationToken)
        {
            var startTime = DateTime.Now;

            // Dependencies to inject into the Bulk Device Tester
            var logger = new TraceLogger();
            var configProvider = new ConfigurationProvider();
            var telemetryFactory = new CoolerTelemetryFactory(logger);
            
            var serializer = new JsonSerialize();
            var transportFactory = new IotHubTransportFactory(serializer, logger, configProvider);

            IVirtualDeviceStorage deviceStorage = null;
            var useConfigforDeviceList = Convert.ToBoolean(configProvider.GetConfigurationSettingValueOrDefault("UseConfigForDeviceList", "False"));

            if (useConfigforDeviceList)
            {
                deviceStorage = new AppConfigRepository(configProvider, logger);
            }
            else 
            {
                deviceStorage = new VirtualDeviceTableStorage(configProvider);
            }

            IDeviceFactory deviceFactory = new CoolerDeviceFactory();

            var tester = new BulkDeviceTester(transportFactory, logger, configProvider, telemetryFactory, deviceFactory, deviceStorage);    
            await tester.ProcessDevicesAsync(cancellationToken);

            Trace.TraceInformation("");
            Trace.TraceInformation("*********************************************************************************************************************");
            Trace.TraceInformation("ELAPSED TIME: {0}ms", (DateTime.Now - startTime).TotalMilliseconds);
            Trace.TraceInformation("*********************************************************************************************************************");
            Trace.TraceInformation("");
        }