コード例 #1
0
ファイル: Program.cs プロジェクト: briansparks/HikesOfAmerica
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            IConfigurationRoot configuration = builder.Build();

            var dbConnectionString = configuration.GetConnectionString(database);

            var rabbitMQConfig = configuration.GetSection(messagingService);

            var host = configuration["RabbitMQ:Host"];
            var user = configuration["RabbitMQ:Username"];
            var pwd  = configuration["RabbitMQ:Password"];

            ConnectionFactory connectionFactory = new ConnectionFactory
            {
                UserName = user,
                Password = pwd,
                HostName = host
            };

            var connection = connectionFactory.CreateConnection();
            var channel    = connection.CreateModel();

            channel.QueueDeclare(queue: $"{typeof(LocationsConsumer)}Queue",
                                 durable: false,
                                 exclusive: false,
                                 autoDelete: false,
                                 arguments: null);

            channel.BasicQos(0, 1, false);

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.Console(restrictedToMinimumLevel: LogEventLevel.Debug)
                         .CreateLogger();

            //var serviceProvider = new ServiceCollection()
            //    .AddLogging()
            //    .AddS

            var mongoDbRepository  = new MongoDbRepository(dbConnectionString);
            var submissionsManager = new SubmissionsManager(mongoDbRepository, null);

            LocationsConsumer locationsConsumer = new LocationsConsumer(channel, submissionsManager, null);

            channel.BasicConsume($"{typeof(LocationsConsumer)}Queue", false, locationsConsumer);

            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: briansparks/HikesOfAmerica
        static async Task Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            IConfigurationRoot configuration = builder.Build();

            var mongoConnection = configuration.GetConnectionString(database);
            var apiKey          = configuration["EmailService:ApiKey"];
            var toAddress       = configuration["EmailService:ToAddress"];
            var fromAddress     = configuration["EmailService:FromAddress"];

            var emailConfig = new EmailClientConfiguration(toAddress, fromAddress);

            var repo = new MongoDbRepository(mongoConnection);

            var sendGridClient     = new SendGridEmailClient(new SendGridClient(apiKey), emailConfig);
            var submissionsManager = new SubmissionsManager(repo, null);

            const string loggerTemplate = @"{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:u4}]<{ThreadId}> [{SourceContext:l}] {Message:lj}{NewLine}{Exception}";
            var          baseDir        = "C:/logs/";
            var          logfile        = Path.Combine(baseDir, "notificationslog.txt");

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                         .Enrich.With(new ThreadIdEnricher())
                         .Enrich.FromLogContext()
                         .WriteTo.Console(LogEventLevel.Information, loggerTemplate)
                         .WriteTo.File(logfile, LogEventLevel.Information, loggerTemplate,
                                       rollingInterval: RollingInterval.Day, retainedFileCountLimit: 10)
                         .CreateLogger();

            var serviceProvider = new ServiceCollection()
                                  .AddLogging()
                                  .AddSingleton <IRepository>(repo)
                                  .AddSingleton <ISubmissionsManager>(x => { return(submissionsManager); })
                                  .AddSingleton <IEmailClientConfiguration, EmailClientConfiguration>(x => { return(emailConfig); })
                                  .AddSingleton <IEmailClient, SendGridEmailClient>(x => { return(sendGridClient); })
                                  .AddSingleton <IEmailService, EmailService>(x => { return(new EmailService(sendGridClient, submissionsManager)); })
                                  .BuildServiceProvider();

            var svc = serviceProvider.GetService <IEmailService>();

            Log.Information("Attmepting to send notifications email.");
            await svc.TrySendEmailAsync();

            Log.Information("Process complete.");
        }
コード例 #3
0
 public SubmissionsTests(ITestOutputHelper output, WebApplicationFactory <Startup> webApplicationFactory) : base(output, webApplicationFactory)
 {
     manager = services.GetRequiredService <SubmissionsManager>();
 }