static void Main(string[] args)
        {
            var options = new Options();
            if (!Parser.Default.ParseArgumentsStrict(args, options))
            {
                //Console.WriteLine(HelpText.AutoBuild(options).ToString());
                return;
            }

            if (options.CreateDeviceCount > 0)
            {
                CreateDevices(options).Wait();
            }

            string[] runnerConfigurationOptions = options.Runners;
            if (runnerConfigurationOptions.Length % 3 != 0)
            {
                Console.WriteLine("Could not parse runner configuration. Make sure runners are described in threes.");
            }

            var group = new MultithreadEventLoopGroup(Environment.ProcessorCount);
            var idProvider = new IdProvider(options.DeviceStartingFrom, options.DeviceNamePattern);

            var runnerConfigurations = new List<RunnerConfiguration>();
            foreach (List<string> runnerOptions in runnerConfigurationOptions.InSetsOf(3))
            {
                string name = runnerOptions[0];
                double startFrequency = double.Parse(runnerOptions[1]);
                int count = int.Parse(runnerOptions[2]);
                RunnerConfiguration config;
                switch (name)
                {
                    case "stable":
                        var stableRunner = new StableTelemetryRunner(group, options.DeviceKey, options.IotHubConnectionString,
                                new IPEndPoint(IPAddress.Parse(options.Address), options.Port), options.HostName);
                        config = stableRunner.CreateConfiguration(count, TimeSpan.FromSeconds(count / startFrequency));
                        break;
                    case "occasional":
                        var occasionalRunner = new OccasionalTelemetryRunner(group, options.DeviceKey, options.IotHubConnectionString,
                                new IPEndPoint(IPAddress.Parse(options.Address), options.Port), options.HostName);
                        config = occasionalRunner.CreateConfiguration(count, TimeSpan.FromSeconds(count / startFrequency));
                        break;
                    default:
                        Console.WriteLine("Unknown runner configuration `{0}`", name);
                        return;
                }
                runnerConfigurations.Add(config);
            }

            var cts = new CancellationTokenSource();
            var host = new RunnerHost(idProvider, runnerConfigurations, TimeSpan.FromSeconds(10));
            host.Run(cts.Token);

            Console.ReadLine();
            Console.WriteLine("Closing runners");
            cts.Cancel();
        }
예제 #2
0
        static void Main(string[] args)
        {
            var options = new Options();

            if (!Parser.Default.ParseArgumentsStrict(args, options))
            {
                //Console.WriteLine(HelpText.AutoBuild(options).ToString());
                return;
            }

            if (options.CreateDeviceCount > 0)
            {
                CreateDevices(options).Wait();
            }

            string[] runnerConfigurationOptions = options.Runners;
            if (runnerConfigurationOptions.Length % 3 != 0)
            {
                Console.WriteLine("Could not parse runner configuration. Make sure runners are described in threes.");
            }

            var group      = new MultithreadEventLoopGroup(Environment.ProcessorCount);
            var idProvider = new IdProvider(options.DeviceStartingFrom, options.DeviceNamePattern);

            var runnerConfigurations = new List <RunnerConfiguration>();

            foreach (List <string> runnerOptions in runnerConfigurationOptions.InSetsOf(3))
            {
                string name           = runnerOptions[0];
                double startFrequency = double.Parse(runnerOptions[1]);
                int    count          = int.Parse(runnerOptions[2]);
                RunnerConfiguration config;
                switch (name)
                {
                case "stable":
                    var stableRunner = new StableTelemetryRunner(group, options.DeviceKey, options.IotHubConnectionString,
                                                                 new IPEndPoint(IPAddress.Parse(options.Address), options.Port), options.HostName);
                    config = stableRunner.CreateConfiguration(count, TimeSpan.FromSeconds(count / startFrequency));
                    break;

                case "occasional":
                    var occasionalRunner = new OccasionalTelemetryRunner(group, options.DeviceKey, options.IotHubConnectionString,
                                                                         new IPEndPoint(IPAddress.Parse(options.Address), options.Port), options.HostName);
                    config = occasionalRunner.CreateConfiguration(count, TimeSpan.FromSeconds(count / startFrequency));
                    break;

                default:
                    Console.WriteLine("Unknown runner configuration `{0}`", name);
                    return;
                }
                runnerConfigurations.Add(config);
            }

            var cts  = new CancellationTokenSource();
            var host = new RunnerHost(idProvider, runnerConfigurations, TimeSpan.FromSeconds(10));

            host.Run(cts.Token);

            Console.ReadLine();
            Console.WriteLine("Closing runners");
            cts.Cancel();
        }
 public RunnerHost(IdProvider idProvider, IEnumerable<RunnerConfiguration> runners, TimeSpan settlePeriod)
 {
     this.runners = runners.ToArray();
     this.idProvider = idProvider;
     this.settlePeriod = settlePeriod;
 }
예제 #4
0
 public RunnerHost(IdProvider idProvider, IEnumerable <RunnerConfiguration> runners, TimeSpan settlePeriod)
 {
     this.runners      = runners.ToArray();
     this.idProvider   = idProvider;
     this.settlePeriod = settlePeriod;
 }