コード例 #1
0
        private IMongoCollection <ChangeRecord> GetCollection(string connectionName)
        {
            var mongoUrl = MongoFactory.GetMongoUrl(connectionName);
            var client   = new MongoClient(mongoUrl);

            return(GetCollection(client));
        }
コード例 #2
0
        public Stream DownLoad(string id)
        {
            //var bytes = MongoFactory.GetFileBytes(DateTime.Now.ToString("yyyy-MM-dd"), id);
            var stream = MongoFactory.GetFileStream(DateTime.Now.ToString("yyyy-MM-dd"), id);

            return(stream);
        }
コード例 #3
0
        private static IMongoCollection <LockData> GetCollection()
        {
            var database   = MongoFactory.GetDatabaseFromConnectionName("Messaging");
            var collection = database.GetCollection <LockData>("throttle-lock");

            return(collection);
        }
コード例 #4
0
        private static IMongoCollection <LockData> GetCollection()
        {
            var database   = MongoFactory.GetDatabaseFromConnectionString("mongodb://localhost/Messaging");
            var collection = database.GetCollection <LockData>("throttle-lock");

            return(collection);
        }
コード例 #5
0
        private static IDataBaseSetupFactory GetDataBaseType()
        {
            //Probably should be get from configuration
            Console.WriteLine("Choise DB Type you want to use? (M)ongo or (S)ql?");
            char input = Console.ReadKey().KeyChar;

            Console.WriteLine("\n");

            IDataBaseSetupFactory dbType;

            switch (input)
            {
            case 'M':
                dbType = new MongoFactory();
                break;

            case 'S':
                dbType = new SqlFactory();
                break;

            default:
                throw new NotImplementedException("Not Implemented. So what?");
            }
            return(dbType);
        }
コード例 #6
0
ファイル: MongoDBManagerTests.cs プロジェクト: ca-borja/MAQS
        public void RespectDriverOverrideInBase()
        {
            var collection = MongoFactory.GetDefaultCollection <BsonDocument>();

            this.OverrideConnectionDriver(new MongoDBDriver <BsonDocument>(collection));

            Assert.AreEqual(collection, this.MongoDBDriver.Collection);
        }
コード例 #7
0
ファイル: MongoDBManagerTests.cs プロジェクト: ca-borja/MAQS
        public void RespectCollectionOverride()
        {
            var collection = MongoFactory.GetDefaultCollection <BsonDocument>();

            this.TestObject.OverrideMongoDBDriver(() => collection);

            Assert.AreEqual(collection, this.MongoDBDriver.Collection);
        }
コード例 #8
0
        private static QueueRepository GetRepository()
        {
            var database   = MongoFactory.GetDatabaseFromConnectionName("Messaging");
            var collection = database.GetCollection <Message>("test-queue");
            var repo       = new QueueRepository(collection);

            return(repo);
        }
コード例 #9
0
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            builder.Register(c => MongoFactory.GetMongoUrl("EstimatorxMongo"))
            .AsSelf()
            .SingleInstance();
        }
コード例 #10
0
        public void OverrideDriver()
        {
            var firstDriver = this.MongoDBDriver;
            var newDriver   = new MongoDBDriver <BsonDocument>(MongoFactory.GetDefaultCollection <BsonDocument>());

            this.TestObject.OverrideMongoDBDriver(newDriver);

            Assert.AreNotEqual(firstDriver, this.MongoDBDriver);
            Assert.AreEqual(newDriver, this.MongoDBDriver);
            Assert.IsFalse(this.MongoDBDriver.IsCollectionEmpty());
        }
コード例 #11
0
        public void OverrideCollectionFunction()
        {
            var collection    = this.MongoDBDriver.Collection;
            var newCollection = MongoFactory.GetDefaultCollection <BsonDocument>();

            this.TestObject.OverrideMongoDBDriver(() => newCollection);

            Assert.AreNotEqual(collection, this.MongoDBDriver.Collection);
            Assert.AreEqual(newCollection, this.MongoDBDriver.Collection);
            Assert.IsFalse(this.MongoDBDriver.IsCollectionEmpty());
        }
コード例 #12
0
        public void OverrideWithCustomDriver()
        {
            var firstDriver = this.MongoDBDriver;
            var newDriver   = new MongoDBDriver <BsonDocument>(MongoFactory.GetCollection <BsonDocument>(MongoDBConfig.GetConnectionString(), MongoDBConfig.GetDatabaseString(), null, MongoDBConfig.GetCollectionString()));

            this.TestObject.OverrideMongoDBDriver(newDriver);

            Assert.AreNotEqual(firstDriver, this.MongoDBDriver);
            Assert.AreEqual(newDriver, this.MongoDBDriver);
            Assert.IsFalse(this.MongoDBDriver.IsCollectionEmpty());
        }
コード例 #13
0
        public void CanUseMultipleWithFunc()
        {
            var newCollection = MongoFactory.GetCollection <BsonDocument>(MongoDBConfig.GetConnectionString(), MongoDBConfig.GetDatabaseString(), MongoDBConfig.GetCollectionString());

            MongoDriverManager <BsonDocument> newDriver = new MongoDriverManager <BsonDocument>(() => newCollection, this.TestObject);

            this.ManagerStore.Add("test", newDriver);

            Assert.AreNotEqual(this.TestObject.MongoDBDriver, (MongoDriverManager <BsonDocument>) this.ManagerStore["test"]);
            Assert.AreNotEqual(this.TestObject.MongoDBManager.Get(), ((MongoDriverManager <BsonDocument>) this.ManagerStore["test"]).Get());
            Assert.AreEqual(newCollection, ((MongoDriverManager <BsonDocument>) this.ManagerStore["test"]).GetMongoDriver().Collection);
        }
コード例 #14
0
        public DatabaseFixture()
        {
            var enviromentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Test";
            var builder        = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
                                 .AddJsonFile("appsettings.json")
                                 .AddJsonFile($"appsettings.{enviromentName}.json", true);

            Configuration    = builder.Build();
            ConnectionString = Configuration.GetConnectionString(ConnectionName);

            var services = new ServiceCollection();

            services.AddSingleton <IConfiguration>(p => Configuration);
            services.AddLogging(f =>
            {
                f.SetMinimumLevel(LogLevel.Trace);
                f.AddMemory();
                f.AddFilter("Microsoft", LogLevel.Information);
                f.AddFilter("System", LogLevel.Warning);
            });
            services.AddOptions();

            services.TryAddTransient <ITenantResolver <string>, MockTenantResolver>();

            services.AddSingleton(s => MongoFactory.GetDatabaseFromConnectionString(ConnectionString));
            services.AddSingleton(typeof(IMongoEntityRepository <>), typeof(MongoEntityRepository <>));

            services.AddAutoMapper(typeof(DatabaseFixture).Assembly);
            services.AddMediator();
            services.AddValidatorsFromAssembly <DatabaseFixture>();

            services.KickStart(config => config
                               .IncludeAssemblyFor <DatabaseFixture>()
                               .IncludeAssemblyFor <DomainException>()
                               .Data("configuration", Configuration)
                               .Data("hostProcess", "test")
                               .UseStartupTask()
                               );

            ServiceProvider = services.BuildServiceProvider();

            var factory = ServiceProvider.GetService <ILoggerFactory>();

            _logger = factory.CreateLogger <DatabaseFixture>();

            CreateDatabase();
        }
コード例 #15
0
        public void Register(IServiceCollection services, IDictionary <string, object> data)
        {
            services.AddSingleton(sp =>
            {
                var configuration = sp.GetRequiredService <IConfiguration>();
                return(MongoFactory.GetDatabaseFromConnectionString(configuration.GetConnectionString("Tracker")));
            });

            services.AddSingleton(typeof(IMongoEntityRepository <>), typeof(MongoEntityRepository <>));

            services.AddSingleton <AuditRepository>();
            services.AddSingleton <PriorityRepository>();
            services.AddSingleton <RoleRepository>();
            services.AddSingleton <StatusRepository>();
            services.AddSingleton <TaskRepository>();
            services.AddSingleton <UserRepository>();
            services.AddSingleton <UserLoginRepository>();
        }
コード例 #16
0
        private IMongoCollection <LogEvent> CreateCollection()
        {
            string collectionName = ConfigurationManager.AppSettings["LoggingCollectionName"];

            if (string.IsNullOrEmpty(collectionName))
            {
                collectionName = "Logging";
            }

            var database = MongoFactory.GetDatabaseFromConnectionName("LoggingConnection");

            var mongoCollection = database.GetCollection <LogEvent>(collectionName);

            mongoCollection.Indexes.CreateOneAsync(Builders <LogEvent> .IndexKeys.Descending(s => s.Date));
            mongoCollection.Indexes.CreateOneAsync(Builders <LogEvent> .IndexKeys.Ascending(s => s.Level));
            mongoCollection.Indexes.CreateOneAsync(Builders <LogEvent> .IndexKeys.Ascending(s => s.Source));
            mongoCollection.Indexes.CreateOneAsync(Builders <LogEvent> .IndexKeys.Ascending(s => s.Correlation));

            return(mongoCollection);
        }
コード例 #17
0
        private void CreateDatabase()
        {
            if (_database != null)
            {
                return;
            }

            // thread safe database creation
            lock (_databaseLock)
            {
                if (_database != null)
                {
                    return;
                }

                _database = string.IsNullOrEmpty(ConnectionString)
                    ? MongoFactory.GetDatabaseFromConnectionString("mongodb://localhost/Messaging")
                    : MongoFactory.GetDatabaseFromConnectionString(ConnectionString);
            }
        }
コード例 #18
0
 public MongoConversationRepository(IOptions <AppSettings> appSettings)
 {
     _appSettings = appSettings;
     _mongoClient = new MongoFactory(appSettings);
 }
コード例 #19
0
        public JsonResult UploadFile(HttpPostedFileBase file)
        {
            var objId = MongoFactory.UploadFile(DateTime.Now.ToString("yyyy-MM-dd"), file.FileName, file.InputStream);

            return(Json(objId));
        }
コード例 #20
0
ファイル: UserRepository.cs プロジェクト: rammybt/Estimatorx
 public UserRepository(MongoUrl mongoUrl)
     : base(MongoFactory.GetDatabaseFromMongoUrl(mongoUrl))
 {
 }
コード例 #21
0
ファイル: UserRepository.cs プロジェクト: rammybt/Estimatorx
 public UserRepository(string connectionName)
     : base(MongoFactory.GetDatabaseFromConnectionName(connectionName))
 {
 }
コード例 #22
0
 public MongoBusinessRepository(IOptions <AppSettings> appSettings)
 {
     _appSettings = appSettings;
     _mongoClient = new MongoFactory(appSettings);
 }
コード例 #23
0
 public MongoReferralRepository(IOptions <AppSettings> appSettings)
 {
     _mongoClient = new MongoFactory(appSettings);
     _appSettings = appSettings;
 }
コード例 #24
0
 public TemplateRepository(MongoUrl mongoUrl)
     : base(MongoFactory.GetDatabaseFromMongoUrl(mongoUrl))
 {
 }
コード例 #25
0
 public ProductsRepository(AppSettings appSettings)
 {
     _appSettings  = appSettings;
     _mongoFactory = new MongoFactory(appSettings);
 }
コード例 #26
0
 public LoggingRepository(MongoUrl mongoUrl)
     : base(MongoFactory.GetDatabaseFromMongoUrl(mongoUrl))
 {
 }
コード例 #27
0
 public WitTokenRepository(AppSettings appSettings)
 {
     _appSettings  = appSettings;
     _mongoFactory = new MongoFactory(appSettings);
 }
コード例 #28
0
 public MongoAttachmentRepository(IOptions <AppSettings> appSettings)
 {
     _appSettings = appSettings;
     _mongoClient = new MongoFactory(appSettings);
 }
コード例 #29
0
 public GridFsService(IOptions <MongoConnectionConfiguration> mongoConfiguration)
 {
     _mongoConfiguration = mongoConfiguration;
     _mongoDatabase      = MongoFactory.GetDatabaseFromConnectionString(_mongoConfiguration.Value.ConnectionString + "/" + _mongoConfiguration.Value.Database);
 }
コード例 #30
0
 public AiSuggestionsRepository(AppSettings appSettings)
 {
     _appSettings  = appSettings;
     _mongoFactory = new MongoFactory(appSettings);
 }