Esempio n. 1
0
        static Settings()
        {
            var configurationRoot = GetConfigurationRoot(Build.Environment);

            Elastic  = configurationRoot.GetSection(ElasticSettings.Key).Get <ElasticSettings>();
            Postgres = configurationRoot.GetSection(PostgresSettings.Key).Get <PostgresSettings>();
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var postgresSection = Configuration.GetSection("Postgresql");

            postgresSettings = postgresSection.Get <PostgresSettings>();

            services.AddScoped <IStorageRepository, StorageRepository>();

            services.AddLocalization(options => options.ResourcesPath = "Resources");

            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddViewLocalization();


            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                options.LoginPath = new PathString("/Account/Login");
            });


            if (postgresSettings != null && postgresSettings.ConnectionString != null)
            {
                services.AddSingleton(postgresSettings);
            }
        }
        public MartenAdapter(PostgresSettings settings)
        {
            _settings = settings;

            CreateDatabase();

            DocumentStore = DocumentStore.For(Configure);
        }
Esempio n. 4
0
        public void ConfigureContainer(ServiceRegistry services)
        {
            var twitterSettings = Configuration.GetSection("Twitter").Get <TwitterSettings>();

            services.For <TwitterSettings>().Use(x => twitterSettings);

            var instanceSettings = Configuration.GetSection("Instance").Get <InstanceSettings>();

            services.For <InstanceSettings>().Use(x => instanceSettings);

            var dbSettings = Configuration.GetSection("Db").Get <DbSettings>();

            services.For <DbSettings>().Use(x => dbSettings);

            var logsSettings = Configuration.GetSection("Logging").Get <LogsSettings>();

            services.For <LogsSettings>().Use(x => logsSettings);

            if (string.Equals(dbSettings.Type, DbTypes.Postgres, StringComparison.OrdinalIgnoreCase))
            {
                var connString       = $"Host={dbSettings.Host};Username={dbSettings.User};Password={dbSettings.Password};Database={dbSettings.Name}";
                var postgresSettings = new PostgresSettings
                {
                    ConnString = connString
                };
                services.For <PostgresSettings>().Use(x => postgresSettings);

                services.For <ITwitterUserDal>().Use <TwitterUserPostgresDal>().Singleton();
                services.For <IFollowersDal>().Use <FollowersPostgresDal>().Singleton();
                services.For <IDbInitializerDal>().Use <DbInitializerPostgresDal>().Singleton();
            }
            else
            {
                throw new NotImplementedException($"{dbSettings.Type} is not supported");
            }

            services.For <ITwitterUserService>().DecorateAllWith <CachedTwitterUserService>();
            services.For <ITwitterUserService>().Use <TwitterUserService>().Singleton();

            services.Scan(_ =>
            {
                _.Assembly("BirdsiteLive.Twitter");
                _.Assembly("BirdsiteLive.Domain");
                _.Assembly("BirdsiteLive.DAL");
                _.Assembly("BirdsiteLive.DAL.Postgres");
                _.Assembly("BirdsiteLive.Pipeline");
                _.TheCallingAssembly();

                //_.AssemblyContainingType<IDal>();
                //_.Exclude(type => type.Name.Contains("Settings"));

                _.WithDefaultConventions();

                _.LookForRegistries();
            });
        }
Esempio n. 5
0
 public PostgresTestingBase()
 {
     _settings = new PostgresSettings
     {
         ConnString            = "Host=127.0.0.1;Username=postgres;Password=mysecretpassword;Database=mytestdb",
         DbVersionTableName    = "DbVersionTableName" + RandomGenerator.GetString(4),
         CachedTweetsTableName = "CachedTweetsTableName" + RandomGenerator.GetString(4),
         FollowersTableName    = "FollowersTableName" + RandomGenerator.GetString(4),
         TwitterUserTableName  = "TwitterUserTableName" + RandomGenerator.GetString(4),
     };
     _tools = new PostgresTools(_settings);
 }
Esempio n. 6
0
        public DbManager(string connectionString = null)
        {
            var postgresSettings = new PostgresSettings();

            if (connectionString != null)
            {
                postgresSettings.PostgresConnectionString = connectionString;
            }

            DataConnection.DefaultSettings = postgresSettings;

            UpgradeDatabase(postgresSettings.PostgresConnectionString);
        }
        public Container Init()
        {
            var container = new Container(x =>
            {
                x.For <DbSettings>().Use(x => _dbSettings);

                x.For <InstanceSettings>().Use(x => _instanceSettings);

                if (string.Equals(_dbSettings.Type, DbTypes.Postgres, StringComparison.OrdinalIgnoreCase))
                {
                    var connString       = $"Host={_dbSettings.Host};Username={_dbSettings.User};Password={_dbSettings.Password};Database={_dbSettings.Name}";
                    var postgresSettings = new PostgresSettings
                    {
                        ConnString = connString
                    };
                    x.For <PostgresSettings>().Use(x => postgresSettings);

                    x.For <ITwitterUserDal>().Use <TwitterUserPostgresDal>().Singleton();
                    x.For <IFollowersDal>().Use <FollowersPostgresDal>().Singleton();
                    x.For <IDbInitializerDal>().Use <DbInitializerPostgresDal>().Singleton();
                }
                else
                {
                    throw new NotImplementedException($"{_dbSettings.Type} is not supported");
                }

                var serviceProvider = new ServiceCollection().AddHttpClient().BuildServiceProvider();
                x.For <IHttpClientFactory>().Use(_ => serviceProvider.GetService <IHttpClientFactory>());

                x.For(typeof(ILogger <>)).Use(typeof(DummyLogger <>));

                x.Scan(_ =>
                {
                    _.Assembly("BirdsiteLive.Twitter");
                    _.Assembly("BirdsiteLive.Domain");
                    _.Assembly("BirdsiteLive.DAL");
                    _.Assembly("BirdsiteLive.DAL.Postgres");
                    _.Assembly("BirdsiteLive.Moderation");

                    _.TheCallingAssembly();

                    _.WithDefaultConventions();

                    _.LookForRegistries();
                });
            });

            return(container);
        }
Esempio n. 8
0
        public DbManager(string messagesPath, string ownerName, string newImagesPath = null, string connectionString = null)
        {
            var postgresSettings = new PostgresSettings();

            if (connectionString != null)
            {
                postgresSettings.PostgresConnectionString = connectionString;
            }

            DataConnection.DefaultSettings = postgresSettings;

            UpgradeDatabase(postgresSettings.PostgresConnectionString);

            _loader    = new Loader(messagesPath, newImagesPath);
            _ownerName = ownerName;

            InsertOwner();
        }
Esempio n. 9
0
        public void ConfigureServices(IServiceCollection services)
        {
            var postgresSection = Configuration.GetSection("Postgres");

            postgresSettings = postgresSection.Get <PostgresSettings>();

            var routesSection = Configuration.GetSection("Routes");

            routesSettings = routesSection.Get <RoutesSettings>();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddScoped <IResultRepository, ResultRepository>();

            if (postgresSettings != null && postgresSettings.ConnectionString != null)
            {
                services.AddSingleton(postgresSettings);
            }

            if (routesSettings != null && routesSettings.GetDataAddress != null)
            {
                services.AddSingleton(routesSettings);
            }
        }
Esempio n. 10
0
 public void Setup()
 {
     _memstateSettings = new EngineSettings();
     _settings         = new PostgresSettings();
 }
Esempio n. 11
0
 protected PostgresBase(PostgresSettings settings)
 {
     _settings = settings;
 }
Esempio n. 12
0
 public MartenHealthCheck(IServiceProvider serviceProvider, PostgresSettings postgresSettings, ILogger <MartenHealthCheck> logger)
 {
     _serviceProvider  = serviceProvider;
     _postgresSettings = postgresSettings;
     _logger           = logger;
 }
 public TwitterUserPostgresDal(PostgresSettings settings) : base(settings)
 {
 }
Esempio n. 14
0
 public ResultRepository(PostgresSettings settings)
 {
     this.settings = settings;
 }
Esempio n. 15
0
 public PostgresTools(PostgresSettings settings)
 {
     _settings = settings;
 }
Esempio n. 16
0
 public CachedTweetsPostgresDal(PostgresSettings settings) : base(settings)
 {
 }
 public DbInitializerPostgresDal(PostgresSettings settings, PostgresTools tools) : base(settings)
 {
     _tools = tools;
 }
Esempio n. 18
0
 public DbMigrator(PostgresSettings settings)
 {
     this.settings = settings;
 }
Esempio n. 19
0
 public StorageRepository(PostgresSettings settings)
 {
     this.settings = settings;
 }
Esempio n. 20
0
        public static IServiceCollection IncludePostgres <T>(this IServiceCollection services, PostgresSettings postgresSettings, PostgresContextSettings postgresContextSettings, bool shouldAddEntityFrameworkNpgsql = false) where T : DbContext
        {
            postgresSettings.AddContextSettings(postgresContextSettings);

            services
            .AddScoped(provider => postgresSettings)
            .AddDbContext <T>(options => options.UseNpgsql(postgresSettings.ConnectionString));

            if (shouldAddEntityFrameworkNpgsql)
            {
                services.AddEntityFrameworkNpgsql();
            }

            return(services);
        }
 public FollowersPostgresDal(PostgresSettings settings) : base(settings)
 {
 }