Exemplo n.º 1
0
        private static async Task GenerateEntries(AccountInterfaceModels.Domain domain)
        {
            DateTime start = DateTime.UtcNow;

            using ILifetimeScope scope = _diContainer.BeginLifetimeScope();
            IMetricService         metricService    = scope.Resolve <IMetricService>();
            ITraceService          traceService     = scope.Resolve <ITraceService>();
            IExceptionService      exceptionService = scope.Resolve <IExceptionService>();
            SettingsFactory        settingsFactory  = scope.Resolve <SettingsFactory>();
            LogSettings            logSettings      = settingsFactory.CreateLog(_settings);
            Queue <Task <Metric> > queue            = new Queue <Task <Metric> >();

            Console.WriteLine($"Entry generation started at {start:HH:mm:ss}");
            await traceService.Create(logSettings, domain.DomainId.Value, "bl-t-client-gen", $"Entry generation started at {start:HH:mm:ss}", new { Date = DateTime.UtcNow });

            for (int i = 0; i < _settings.EntryCount; i += 1)
            {
                if (queue.Count >= _settings.ConcurentTaskCount)
                {
                    try
                    {
                        await queue.Dequeue();
                    }
                    catch (System.Exception ex)
                    {
                        await exceptionService.Create(settingsFactory.CreateLog(_settings), domain.DomainId.Value, ex);
                    }
                }
                queue.Enqueue(metricService.Create(logSettings, domain.DomainId.Value, DateTime.UtcNow, "bl-t-client-gen", DateTime.UtcNow.Subtract(new DateTime(2000, 1, 1)).TotalSeconds));
            }
            await Task.WhenAll(queue);

            DateTime end = DateTime.UtcNow;

            Console.WriteLine($"Entry generation ended at {end:HH:mm:ss} and took {end.Subtract(start).TotalMinutes:0.0##} minutes");
            await traceService.Create(logSettings, domain.DomainId.Value, "bl-t-client-gen", $"Entry generation ended at {end:HH:mm:ss} and took {end.Subtract(start).TotalMinutes:0.0##} minutes");

            Console.WriteLine($"{_settings.EntryCount} records created");
            await traceService.Create(logSettings, domain.DomainId.Value, "bl-t-client-gen", $"{_settings.EntryCount} records created");

            double rate = Math.Round((double)_settings.EntryCount / end.Subtract(start).TotalSeconds, 3, MidpointRounding.ToEven);

            Console.WriteLine($"at {rate} records per second");
            await traceService.Create(logSettings, domain.DomainId.Value, "bl-t-client-gen", $"at {rate} records per second");
        }
Exemplo n.º 2
0
        public static async Task Main(string[] args)
        {
            try
            {
                _settings = LoadSettings(args);
                if (ValidateArgs())
                {
                    _diContainer = LoadDiContainer();
                    AccountInterfaceModels.Domain domain = await GetDomain(_settings.DomainId);

                    Console.WriteLine($"Loaded domain {domain.Name}");
                    await GenerateEntries(domain);
                }
            }
            catch (System.Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
            }
        }