Пример #1
0
        /// <summary>
        /// The method triggered when the command line arguments are parsed
        /// with success.
        /// </summary>
        /// <param name="options">
        /// An instance of <see cref="Options" /> containing the parsed command
        /// line arguments.
        /// </param>
        private static void CommandLineArgumentsParsed(Options options)
        {
            // Create our StructureMap registry and...
            Registry  registry  = new Registry();
            Container container = new Container(registry);

            string   logLevelStr = options.Verbosity.ToString();
            LogLevel logLevel    = LogLevel.FromString(logLevelStr);

            // Get the default NLog configuration - i.e. the one declared
            // in Nlog.config.
            LoggingConfiguration loggingConfiguration =
                LogManager.Configuration;

            // Add a rule for each target, based on the input Verbosity level.
            LoggingRule loggingRule = null;

            foreach (Target target in loggingConfiguration.AllTargets)
            {
                loggingRule = new LoggingRule("*", logLevel, target);

                loggingConfiguration.LoggingRules.Add(loggingRule);
            }

            // Get an instance.
            IOutputFileGenerator outputFileGenerator =
                container.GetInstance <IOutputFileGenerator>();

            Tuple <string, string> explicitKey = new Tuple <string, string>(
                options.AccessKeyId,
                options.SecretAccessKey);

            executionSuccess = outputFileGenerator.CreateOutputFile(
                explicitKey,
                options.AwsRegion,
                options.PasswordEncryptionKeyFile,
                options.PasswordEncryptionKeyFileDirectory,
                options.RoleArn,
                options.OutputFile);
        }
Пример #2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                await Task.Delay(2000, stoppingToken);

                if (!_firstTime)
                {
                    continue;
                }

                var createScope = _serviceScopeFactory.CreateScope();

                _clientReceiver = createScope.ServiceProvider.GetRequiredService <IRabbitMqClientReceiver>();

                _fileGenerator = createScope.ServiceProvider.GetRequiredService <IOutputFileGenerator>();

                _clientReceiver.ConfigureChannel(_configuration["RabbitMqHostName"]
                                                 , _configuration["RabbitMqUsername"]
                                                 , _configuration["RabbitMqPassword"]
                                                 , int.Parse(_configuration["RabbitMqRetryCount"])
                                                 , _configuration["RabbitMqReceiveQueueName"]);

                _clientReceiver.Receive += (sender, args) =>
                {
                    var outputContentDto =
                        JsonConvert.DeserializeObject <OutputFileContentDto>(Encoding.UTF8.GetString(sender as byte[]));

                    if (outputContentDto == null)
                    {
                        return;
                    }

                    _fileGenerator.GenerateFIle(outputContentDto);
                };

                _firstTime = false;
            }
        }