Ejemplo n.º 1
0
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;

            mongoDbConfiguration  = configuration.GetSection(nameof(MongoDbConfiguration)).Get <MongoDbConfiguration>();
            securityConfiguration = configuration.GetSection(nameof(SecurityConfiguration)).Get <SecurityConfiguration>();
        }
Ejemplo n.º 2
0
        public Repository(MongoDbConfiguration settings, MongoClientProvider mongoClientProvider)
        {
            this.settings = settings;
            this.client   = mongoClientProvider.GetClient("default");

            this.SetCollection();
        }
Ejemplo n.º 3
0
        public MongoDbWriteModelUnitOfWorkTests()
        {
            fixture = new Fixture();

            //Setup mongo configuration
            configuration = fixture.Create <MongoDbConfiguration>();

            //Setup client factory
            client        = Substitute.For <IMongoClient>();
            sessionHandle = Substitute.For <IClientSessionHandle>();
            database      = Substitute.For <IMongoDatabase>();
            clientFactory = Substitute.For <IMongoClientFactory>();

            client.StartSession().Returns(sessionHandle);
            client.GetDatabase(Arg.Any <string>()).Returns(database);
            clientFactory.CreateClient(Arg.Any <MongoDbConfiguration>()).Returns(client);

            //Setup user factory
            cryptService = Substitute.For <ICryptService>();
            cryptService.Crypt(Arg.Any <string>()).Returns(args => args[0]);
            userFactory = new WriteModelUserFactory(cryptService);

            //Create unit of work
            unitOfWork = new MongoDbWriteModelUnitOfWork(configuration, clientFactory, userFactory);
        }
Ejemplo n.º 4
0
        public UserRepository(ILogger <UserRepository> logger, MongoDbConfiguration configuration) : base(configuration)
        {
            logger.ShouldNotBeNull();
            configuration.ShouldNotBeNull();

            _logger = logger;
        }
Ejemplo n.º 5
0
        public MongoTestFileResultRepository(MongoDbConfiguration mongoDbConfiguration)
        {
            var mongoClient = new MongoClient(mongoDbConfiguration.ConnectionString);

            _database   = mongoClient.GetDatabase(mongoDbConfiguration.DatabaseName);
            _collection = _database.GetCollection <TestFileResult>(MONGDB_COLLECTION_NAME);
        }
Ejemplo n.º 6
0
        public MongoClientProvider(MongoDbConfiguration configuration)
        {
            this.mongoConfiguration = configuration;
            this.clientsRepository  = new Dictionary <string, IMongoClient>();

            this.SetDefaultClient();
        }
Ejemplo n.º 7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var mongoConfiguration = new MongoDbConfiguration();

            Configuration.GetSection(MongoDbConfiguration.SectionKey).Bind(mongoConfiguration);

            var firebaseConfiguration = new FirebaseAuthConfiguration();

            Configuration.GetSection(FirebaseAuthConfiguration.SectionKey).Bind(firebaseConfiguration);

            var dialogFlowConfiguration = new DialogFlowConfiguration();

            Configuration.GetSection(DialogFlowConfiguration.SectionKey).Bind(dialogFlowConfiguration);

            var influxConfiguration = new InfluxDbConfiguration();

            Configuration.GetSection(InfluxDbConfiguration.SectionKey).Bind(influxConfiguration);

            services
            .AddCors()
            .AddFirebaseAuthModule(firebaseConfiguration)
            .AddMongoDbModule(mongoConfiguration)
            .AddDialogFlowModule(dialogFlowConfiguration)
            .AddInfluxStatisticsModule(influxConfiguration)
            .AddChatBotBusinessModule()
            .AddControllers();
        }
Ejemplo n.º 8
0
        public CatalogContext(MongoDbConfiguration mongoDbConfiguration)
        {
            var client = new MongoClient(mongoDbConfiguration.ConnectionString);

            this.database = client.GetDatabase(mongoDbConfiguration.Database);

            CatalogContextSeed.SeedData(this.database);
        }
Ejemplo n.º 9
0
        public CatalogContext(MongoDbConfiguration mongoDbConfiguration)
        {
            var client   = new MongoClient(mongoDbConfiguration.ConnectionString);
            var database = client.GetDatabase(mongoDbConfiguration.DatabaseName);

            this.Products = database.GetCollection <Product>(mongoDbConfiguration.CollectionName);
            CatalogContextSeed.SeedData(this.Products);
        }
Ejemplo n.º 10
0
        private void Init()
        {
            MongoDbConfiguration configuration = ConfigurationManager.GetSection(MongoDbConfiguration.PreferredSectionName) as MongoDbConfiguration;

            // client = new MongoClient(configuration.ConnectionString);
            client           = CreateClient(configuration.ConnectionString);
            DefaultDatabase  = configuration.DefaultDatabase;
            MongoCollections = configuration.MongoCollections;
        }
Ejemplo n.º 11
0
        public WebApiContext(MongoDbConfiguration config)
        {
            var client = new MongoClient(config.ConnectionString);

            _db     = client.GetDatabase(config.Database);
            _gridFS = new GridFSBucket(_db, new GridFSBucketOptions {
                BucketName = "fotos_funcionarios"
            });
        }
Ejemplo n.º 12
0
        public MongoDbRepository(
            MongoDbConfiguration mongoDbConfiguration,
            string collectionName,
            IMapper mapper)
        {
            Mapper = mapper;

            var database = new MongoClient(mongoDbConfiguration.ConnectionString).GetDatabase(mongoDbConfiguration.DatabaseName);

            Collection = database.GetCollection <TDocument>(collectionName);
        }
Ejemplo n.º 13
0
 public static IServiceCollection AddMongoDbModule(this IServiceCollection services,
                                                   MongoDbConfiguration configuration)
 {
     services
     .AddSingleton(configuration)
     .AddSingleton <IKnowledgeRepository, KnowledgeRepository>()
     .AddSingleton <IUserRepository, UserRepository>()
     .AddSingleton <IDepartmentRepository, DepartmentRepository>()
     .AddSingleton <IChatRepository, ChatRepository>();
     return(services);
 }
Ejemplo n.º 14
0
        public static void ConfigureDomainRepositories(this IServiceCollection services, IConfigurationManager configuration)
        {
            var orderManagementConfigration = new MongoDbConfiguration()
            {
                ConnectionString = configuration.AppSettings.OrderManagement.DomainConnectionString,
                Database         = configuration.AppSettings.OrderManagement.DomainDatabase,
            };

            services.AddTransient(sp => new OrderManagementDbContext(orderManagementConfigration));
            services.AddTransient <IOrderRepository, OrderRepository>();
        }
Ejemplo n.º 15
0
        public void MongoDbConfigurationTest(string connectionString, string dataBase, bool expectedResult)
        {
            var config = new MongoDbConfiguration
            {
                ConnectionString = connectionString,
                Database         = dataBase
            };

            var rule = new MongoDbConfigurationValidation();

            rule.Validate(null, config).Succeeded.Should().Be(expectedResult);
        }
Ejemplo n.º 16
0
        protected RepositoryBase(MongoDbConfiguration configuration)
        {
            var client   = new MongoClient(configuration.ConnectionString);
            var database = client.GetDatabase(configuration.Database);
            var collectionNameAttribute = (CollectionNameAttribute)typeof(T)
                                          .GetCustomAttributes(typeof(CollectionNameAttribute), false)
                                          .FirstOrDefault();

            collectionNameAttribute.ShouldNotBeNull();

            Collection = database.GetCollection <T>(collectionNameAttribute.CollectionName);
        }
Ejemplo n.º 17
0
 public MongoDbWriteModelUnitOfWork(
     MongoDbConfiguration configuration,
     IMongoClientFactory clientFactory,
     Budget.Users.Domain.WriteModel.Factories.WriteModelUserFactory userFactory
     )
 {
     Configuration  = configuration;
     Client         = clientFactory.CreateClient(configuration);
     Session        = Client.StartSession();
     Database       = Client.GetDatabase(databaseName);
     UserRepository = new MongoDbWriteModelUserRepository(Database, userFactory);
 }
Ejemplo n.º 18
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddScoped <IHardwareService, HardwareService>();
     services.AddScoped <IHardwareRepository, HardwareRepository>();
     services.AddSingleton <IMongoClient>((provider) => new MongoClient(Configuration.GetConnectionString("DefaultConnection")));
     services.AddMvc(option =>
     {
         option.Filters.Add <ActionLogger>();
     })
     .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
     AutoMapperConfiguration.Configure();
     MongoDbConfiguration.Map();
 }
Ejemplo n.º 19
0
        public void GetConnectionString_ThrowsArgumentException_WhenUserNameIsSetWithoutPassword()
        {
            //Arrange
            var config = new MongoDbConfiguration()
            {
                UserName = "******", Address = "127.0.0.1"
            };

            //Act
            Action action = (() => config.GetConnectionString());

            //Assert
            Assert.Throws <ArgumentException>(action);
        }
Ejemplo n.º 20
0
        public void Constructor_SetsProperty_ToEmptyValues()
        {
            //Arrange
            var config = new MongoDbConfiguration();

            //Act

            //Assert
            config.Address.Should().BeEmpty();
            config.UserName.Should().BeEmpty();
            config.Password.Should().BeEmpty();
            config.Port.Should().BeLessThan(0);
            config.EnableTransactions.Should().BeFalse();
        }
        public static IServiceCollection AddFeatureTogglesAdminSupport(this IServiceCollection services,
                                                                       IConfiguration configuration)
        {
            //TODO: configuration from env variables?
            //  to control it from integration tests
            var mongoDbConfiguration = new MongoDbConfiguration();

            configuration.GetSection("MongoDb").Bind(mongoDbConfiguration);
            services.AddSingleton(mongoDbConfiguration);
            services.AddScoped <IFeatureToggleRepository, MongoDbFeatureToggleRepository>();
            services.AddScoped <IFeatureToggleService, FeatureToggleService>();
            services.AddScoped <ITimeProvider, TimeProvider>();

            return(services);
        }
Ejemplo n.º 22
0
        public void GetConnectionString_WhenAddressAndPortAreSet_ReturnsValidString()
        {
            //Arrange
            var config = new MongoDbConfiguration()
            {
                Address = "127.0.0.1", Port = 42
            };
            var expectedConnectionString = "mongodb://127.0.0.1:42";

            //Act
            var connectionString = config.GetConnectionString();

            //Assert
            connectionString.Should().Be(expectedConnectionString);
        }
        public static void ConfigureAppServices(this IServiceCollection services, WebHostBuilderContext context)
        {
            var mongoDbConfigurationSection = context.Configuration.GetSection("MongoDb");
            var mongoDbConfiguration        = new MongoDbConfiguration
            {
                ConnectionString        = mongoDbConfigurationSection.GetValue <string>("ConnectionString"),
                DatabaseName            = mongoDbConfigurationSection.GetValue <string>("DatabaseName"),
                CustomersCollectionName = mongoDbConfigurationSection.GetValue <string>("CustomersCollectionName")
            };

            services.AddSingleton <IStoreCustomersInformation>(_ => new MongoDbCustomersInformationStore(mongoDbConfiguration));
            services.AddSingleton <IOperateOnMicrosoftOffice365Subscriptions, MicrosoftOffice365SubscriptionsOperations>();
            services.AddSingleton <IOperateOnMicrosoftOffice365Users, MicrosoftOffice365UsersOperations>();
            services.AddScoped <IPerformUserOperations, UserOperations>();
        }
Ejemplo n.º 24
0
        public Repository(IOptions <MongoDbConfiguration> configuration)
        {
            _configuration = configuration.Value;

            MongoClient = new MongoClient(_configuration.ConnectionString);
            Db          = MongoClient.GetDatabase(_configuration.DataBaseName);

            var tableName = typeof(TEntity).Name;

            Collection = Db.GetCollection <TEntity>(tableName);

            #region Initialization Of Class Maps

            SetProperAttributes();
            #endregion
        }
Ejemplo n.º 25
0
        public static void ConfigureActivityStreams(this IServiceCollection services, IConfigurationManager configuration)
        {
            var orderManagementConfigration = new MongoDbConfiguration()
            {
                ConnectionString = configuration.AppSettings.OrderManagement.DomainConnectionString,
                Database         = configuration.AppSettings.OrderManagement.DomainDatabase,
            };

            // INFO: 这里注册更多的 ActivityStreamsDbContext
            services.AddTransient <IUrlSettings, UrlSettings>();
            services.AddTransient <IAppUrlProvider, AppUrlProvider>();
            services.AddTransient <HtmlContext>();
            services.AddTransient(sp => new OrderActivityStreamsDbContext(orderManagementConfigration));
            services.AddTransient <OrderHtmlContext>();
            services.AddTransient <IOrderActivityStreamsService, OrderActivityStreamsService>();
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Initialize the MongoDbPublishedVersionStore with option setting.
        /// </summary>
        /// <param name="eNodeConfiguration"></param>
        /// <param name="mongoDbConfiguration"></param>
        /// <param name="storeEntityName"></param>
        /// <param name="collectionCount"></param>
        /// <returns></returns>
        public static ENodeConfiguration InitializeMongoDbPublishedVersionStore(this ENodeConfiguration eNodeConfiguration,
                                                                                MongoDbConfiguration dbConfiguration,
                                                                                string storeEntityName = "PublishedVersion",
                                                                                int collectionCount    = 1)
        {
            var mongoDbConfiguration = ObjectContainer.Resolve <IPublishedVersionMongoDbConfiguration>();

            mongoDbConfiguration.ConnectionString = dbConfiguration.ConnectionString;
            mongoDbConfiguration.DatabaseName     = dbConfiguration.DatabaseName;

            var collectionConfiguration = ObjectContainer.Resolve <IPublishedVersionCollectionConfiguration>();

            collectionConfiguration.EntityName = storeEntityName;
            collectionConfiguration.ShardCount = collectionCount;

            return(eNodeConfiguration);
        }
        public static IMongoClient GetClient(MongoDbConfiguration mongoConfig)
        {
            if (mongoConfig == null)
            {
                throw new ArgumentNullException(nameof(mongoConfig));
            }

            BsonDefaults.GuidRepresentation = GuidRepresentation.Standard;

            var credentials = MongoCredential.CreateCredential(mongoConfig.UserDatabase, mongoConfig.User, mongoConfig.Password);

            var clientSettings = new MongoClientSettings
            {
                Credential = credentials,
                Server     = new MongoServerAddress(mongoConfig.Host, mongoConfig.Port)
            };

            return(new MongoClient(clientSettings));
        }
Ejemplo n.º 28
0
        public static IServiceCollection AddPrintlyDomainServices(
            this IServiceCollection services,
            MongoDbConfiguration configuration)
        {
            services.AddSingleton <IMongoClient>(new MongoClient(configuration.ConnectionString));

            services.AddSingleton <MongoDbStorageServiceConfiguration <Printer> >(new MongoDbStorageServiceConfiguration <Printer>
            {
                DatabaseName   = configuration.DatabaseName,
                CollectionName = "Printers"
            });
            services.AddSingleton <IDataStorageService <Printer>, PrinterStorageService>();

            services.AddSingleton <MongoDbStorageServiceConfiguration <Configuration> >(new MongoDbStorageServiceConfiguration <Configuration>
            {
                DatabaseName   = configuration.DatabaseName,
                CollectionName = "Configuration"
            });
            services.AddSingleton <IDataStorageService <Configuration>, ConfigurationDataStorageService>();

            return(services);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Initialize the MongoDbAggregateSnapshotter with option setting.
        /// </summary>
        /// <param name="eNodeConfiguration"></param>
        /// <param name="mongoDbConfiguration"></param>
        /// <param name="storeEntityName"></param>
        /// <param name="collectionCount"></param>
        /// <returns></returns>
        public static ENodeConfiguration InitializeMongoDbAggregateSnapshotter(this ENodeConfiguration eNodeConfiguration,
                                                                               MongoDbConfiguration dbConfiguration,
                                                                               string storeEntityName               = "AggregateSnapshot",
                                                                               int collectionCount                  = 1,
                                                                               int versionInterval                  = 50,
                                                                               int batchStoreIntervalMilliseconds   = 1000,
                                                                               int batchStoreMaximumCumulativeCount = 100
                                                                               )
        {
            eNodeConfiguration.InitializeAggregateSnapshotter(versionInterval, batchStoreIntervalMilliseconds, batchStoreMaximumCumulativeCount);

            var mongoDbConfiguration = ObjectContainer.Resolve <ISnapshotMongoDbConfiguration>();

            mongoDbConfiguration.ConnectionString = dbConfiguration.ConnectionString;
            mongoDbConfiguration.DatabaseName     = dbConfiguration.DatabaseName;

            var collectionConfiguration = ObjectContainer.Resolve <ISnapshotCollectionConfiguration>();

            collectionConfiguration.EntityName = storeEntityName;
            collectionConfiguration.ShardCount = collectionCount;

            return(eNodeConfiguration);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Initialize the MongoDbAggregateSnapshotter with option setting.
        /// </summary>
        /// <param name="eNodeConfiguration"></param>
        /// <param name="mongoDbConfiguration"></param>
        /// <param name="storeEntityName"></param>
        /// <param name="collectionCount"></param>
        /// <returns></returns>
        public static ENodeConfiguration InitializeMongoDbAggregateSnapshotter(this ENodeConfiguration eNodeConfiguration,
                                                                               MongoDbConfiguration dbConfiguration,
                                                                               int versionInterval    = 50,
                                                                               string storeEntityName = "AggregateSnapshot",
                                                                               int collectionCount    = 1
                                                                               )
        {
            var aggregateSnapshotConfiguration = ObjectContainer.Resolve <IAggregateSnapshotConfiguration>();

            aggregateSnapshotConfiguration.VersionInterval = versionInterval;

            var mongoDbConfiguration = ObjectContainer.Resolve <ISnapshotMongoDbConfiguration>();

            mongoDbConfiguration.ConnectionString = dbConfiguration.ConnectionString;
            mongoDbConfiguration.DatabaseName     = dbConfiguration.DatabaseName;

            var collectionConfiguration = ObjectContainer.Resolve <ISnapshotCollectionConfiguration>();

            collectionConfiguration.EntityName = storeEntityName;
            collectionConfiguration.ShardCount = collectionCount;

            return(eNodeConfiguration);
        }