示例#1
0
        private static async Task <DevicesConfiguration> ReadConfigurationAsync(Parameters parameters)
        {
            DevicesConfiguration config = null;

            if (_parameters.IsFileConfig())
            {
                config = await ReadFromFileConfigAsync(parameters);
            }
            else
            {
                config = await ReadFromBlobStorageAsync(parameters);
            }

            foreach (var device in config.Devices)
            {
                if (device.TemperatureGenerator == null)
                {
                    device.TemperatureGenerator = DefaultTemperatureGeneratorConfiguration;
                }
                if (device.HumidityGenerator == null)
                {
                    device.HumidityGenerator = DefaultHumidityGeneratorConfiguration;
                }
            }

            return(config);
        }
示例#2
0
        static async Task Main(string[] args)
        {
            ParserResult <Parameters> result = Parser.Default.ParseArguments <Parameters>(args)
                                               .WithParsed(parsedParams =>
            {
                _parameters = parsedParams;
            })
                                               .WithNotParsed(errors =>
            {
                Environment.Exit(1);
            });

            if (_parameters.IsValid())
            {
                Environment.Exit(1);
            }

            Console.WriteLine("Telemetry simulator.");

            DevicesConfiguration config = await ReadConfigurationAsync(_parameters);

            Console.WriteLine("Press control-C to exit.");

            using var cts = new CancellationTokenSource();

            if (_parameters.ActualDuration > 0)
            {
                cts.CancelAfter(_parameters.ActualDuration * 1000);
            }

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;
                cts.Cancel();
                Console.WriteLine("Exiting...");
            };

            var tasks = new List <Task>();

            foreach (var device in config.Devices)
            {
                tasks.Add(SendDeviceToCloudMessagesAsync(device, cts.Token));
                await Task.Delay(rand.Next(125, 2000));
            }

            Task.WaitAll(tasks.ToArray());
        }