private async void firstTimeInstallDataBase (IMongoDatabase database, string rootPath){
			try {
				if (!CollectionExistsAsync (database, "actors").Result) {
					await database.CreateCollectionAsync ("actors");

					var actors = new ActorRepository();
					foreach (Actor actor in actors.Retrieve(rootPath))
					{
						var collectionActors = database.GetCollection<Actor>("actors");
						await collectionActors.InsertOneAsync(actor);
					}
				}

				if (!CollectionExistsAsync (database, "movies").Result) {
					await database.CreateCollectionAsync ("movies");

					var movies = new MovieRepository();
					foreach (Movie movie in movies.Retrieve(rootPath))
					{
						var collectionActors = database.GetCollection<Movie>("movies");
						await collectionActors.InsertOneAsync(movie);
					}
				}
			}
			catch {
				throw;
			}
		}
Example #2
0
 public Logger(string logger)
 {
     var client = new MongoClient(Properties.Settings.Default.Mongo_log);
     _db = client.GetDatabase("patientcarelog");
     _logCollection = _db.GetCollection<BsonDocument>("Logs");
     _logger = logger;
 }
Example #3
0
 public void Initialize()
 {
     var connect = "mongodb://localhost";
     _client = new MongoClient(connect);
     _db = _client.GetDatabase("local");
     _collection = _db.GetCollection<Person>("Person");
 }
 public AdminService(IMongoClient client, IMongoDatabase db, StoreSettings settings)
 {
     _client = client;
     _db = db;
     _settings = settings;
     _clientSerializer = new ClientSerializer();
 }
        public ClothesDbContext(string connectionString)
        {
            var mongoClient = new MongoClient(connectionString);
            _mongoDatabase = mongoClient.GetDatabase("ClothesWashing");

            RegisterClassMaps();
        }
Example #6
0
 public LogEntryRepository(MongoClient mongoClient, IConfiguration configuration, string databaseName = "Kelpie")
 {
     _mongoClient = mongoClient;
     _configuration = configuration;
     _database = _mongoClient.GetDatabase(databaseName);
     _collection = _database.GetCollection<LogEntry>("LogEntry");
 }
 public TodoItemRepository(string mongoConnection, string databaseName)
 {
     collectionName = "todoitems";
     var client = new MongoClient(mongoConnection);
     this.database = client.GetDatabase(databaseName);
     this.collection = database.GetCollection<TodoItem>(collectionName);
 }
        public IMongoCollection<BsonDocument> GetCollection(IMongoDatabase mongoDatabase, bool? cappedCollection,
            string collectionName, long? cappedCollectionSize, long? maxNumberOfDocuments)
        {
            IMongoCollection<BsonDocument> retVal = null;

            if (cappedCollection == null || !cappedCollection.Value)
            {
                retVal = mongoDatabase.GetCollection<BsonDocument>(collectionName ?? CollectionDefaulName);
                return retVal;
            }
            
            if (!IsCollectionExistsAsync(mongoDatabase, collectionName).Result)
            {
                CreateCollectionAsync(mongoDatabase, collectionName, cappedCollectionSize, maxNumberOfDocuments).Wait();
                retVal = mongoDatabase.GetCollection<BsonDocument>(collectionName ?? CollectionDefaulName);
                return retVal;
            }

            if (IsCappedCollection(collectionName, mongoDatabase).Result)
            {
                retVal = mongoDatabase.GetCollection<BsonDocument>(collectionName ?? CollectionDefaulName);
                return retVal;
            }


            if (ConvertCollectionToCapped(collectionName, mongoDatabase, cappedCollectionSize, maxNumberOfDocuments).Result)
            {
                retVal = mongoDatabase.GetCollection<BsonDocument>(collectionName ?? CollectionDefaulName);
            }
            
            return retVal;
        }
Example #9
0
 private void InitiateDatabase()
 {
     var connectionString = ConfigurationManager.ConnectionStrings["Mongo.ConnectionString"].ConnectionString;
     var mongoUrlBuilder = new MongoUrlBuilder(connectionString);
     mongoClient = new MongoClient(mongoUrlBuilder.ToMongoUrl());
     Database = mongoClient.GetDatabase(mongoUrlBuilder.DatabaseName);
 }
Example #10
0
        public ICollection<Product> GetAllProducts(IMongoDatabase database, string collectionName)
        {
            var collection = database.GetCollection<Product>(collectionName);
            var rest = collection.Find(_ => true).ToListAsync().Result;

            return rest;
        }
Example #11
0
        public ICollection<Trader> GetAllTraders(IMongoDatabase database)
        {
            var collection = database.GetCollection<Trader>(TradersCollectionName);
            var rest = collection.Find(t => true).ToListAsync().Result;

            return rest;
        }
 // static constructor
 static AggregateFluentBucketTests()
 {
     var databaseNamespace = DriverTestConfiguration.DatabaseNamespace;
     __database = DriverTestConfiguration.Client.GetDatabase(databaseNamespace.DatabaseName);
     __collectionNamespace = DriverTestConfiguration.CollectionNamespace;
     __ensureTestData = new Lazy<bool>(CreateTestData);
 }
Example #13
0
        public FullTextSearch(string databaseName = "test", MongoUrl url = null)
        {
            mongoClient = url == null ? new MongoClient() : new MongoClient(url);
            database = mongoClient.GetDatabase(databaseName);

            database.CreateCollectionAsync("Students").Wait();
        }
		public MongoDBStorage(IMongoDatabase database)
		{
			Revisions = database.GetCollection<RevisionModel>("revisions");
			Users = database.GetCollection<UserModel>("users");

			Task.Run(() => SetUp()).Wait();
		}
Example #15
0
 public MongoDbBase(string connectionString, string database)
 {
     this.connectionString = connectionString;
     this.database = database;
     Client = new MongoClient(connectionString);
     Database = Client.GetDatabase(database);
 }
Example #16
0
 /// <summary>
 /// Details controller constructor
 /// </summary>
 public DetailController()
 {
     var client = new MongoClient(ConfigurationManager.ConnectionStrings["Mongo_patientcare"].ConnectionString);
     _log = new Logger("WebAPI:DetailController");
     _db = client.GetDatabase("patientcaredb");
     _details = _db.GetCollection<BsonDocument>("Detail");
 }
Example #17
0
 /// <summary />
 public PatientRepository()
 {
     var client = new MongoClient(ConfigurationManager.ConnectionStrings["Mongo_patientcare_datamock"].ConnectionString);
     _log = new Logger("WebAPI : PatientRepository");
     _db = client.GetDatabase("patientcare_datamock");
     _patients = _db.GetCollection<BsonDocument>("Patients");
 }
Example #18
0
 public MongoDbDriver(string connectionString, string collectionName)
 {
     var builder = new SqlConnectionStringBuilder(connectionString);
     _client = new MongoClient(builder.DataSource);
     _database = _client.GetDatabase(builder.InitialCatalog);
     _collectionName = collectionName;
 }
 public TokenHandleStore(IMongoDatabase db, 
     StoreSettings settings, 
     IClientStore clientStore) 
     : base(db, settings.TokenHandleCollection)
 {
     _serializer = new TokenSerializer(clientStore);
 }
        public MongoConfigurationRepository(string connection, string databaseName)
        {
            var mongoClient = new MongoClient(MongoClientSettings.FromUrl(new MongoUrl(connection ?? Connection)));
            database = mongoClient.GetDatabase(databaseName ?? DatabaseName);

            InitCollection();
        }
Example #21
0
        static MProjects()
        {
            var connectionString = Settings.Default.MongoConnectionString;
            var mongoClient = new MongoClient(connectionString);

            Database = mongoClient.GetDatabase(Settings.Default.MongoDBName);
        }
Example #22
0
 public void Init()
 {
     Client = new MongoClient(ConnString);
     DataBase = Client.GetDatabase("mongoLog");
     Users = DataBase.GetCollection<User>("Users");
     Datas = DataBase.GetCollection<Data>("Datas");
 }
 public CollectionExpression(Alias alias, IMongoDatabase database, string collectionName, Type documentType)
     : base(MongoExpressionType.Collection, typeof(void), alias)
 {
     CollectionName = collectionName;
     Database = database;
     DocumentType = documentType;
 }
Example #24
0
        public Querying()
        {
            client = new MongoClient(); ;
            database = client.GetDatabase("test");

            collection = database.GetCollection<Student>("Users");
        }
Example #25
0
        public DeviceContext(IOptions <DbSettings> options)
        {
            var client = new MongoClient(options.Value.ConnectionString);

            _db = client.GetDatabase(options.Value.Database);
        }
Example #26
0
        public MongoDataStore(DataStoreConfiguration configuration)
        {
            var client = new MongoClient(configuration.ConnectionString);

            _database = client.GetDatabase(configuration.DatabaseName);
        }
Example #27
0
        public MongoDbItemsRepository(IMongoClient mongoClient)
        {
            IMongoDatabase database = mongoClient.GetDatabase(DATABASE_NAME);

            _itemsCollection = database.GetCollection <Item>(COLLECTION_NAME);
        }
Example #28
0
 public MongoQueryProvider(IMongoCtx ctx)
 {
     _database = ctx.Db;
 }
 public MongoGrantStore(IMongoDatabase db) : base(db, "grants")
 {
 }
 public MongodbRepositoryProvider(IMongoDatabase database, string collectionName)
 {
     this.collection = database.GetCollection <TImplementation>(collectionName);
 }
Example #31
0
 public static void Init(Configuration config)
 {
     _config = config;
     _auth   = new Auth();
     MongoDB = initMongoClient(config);
 }
 public SvishtovHighSchoolDbContext(IMongoDatabase mongoDatabases)
 {
     _database = mongoDatabases;
 }
Example #33
0
 public MongoRepository(IMongoSetting mongoSettings)
 {
     _mongoSettings = mongoSettings;
     _mongoClient   = new MongoClient(_mongoSettings.ConnectionString);
     _mongoDatabase = _mongoClient.GetDatabase(_mongoSettings.Database);
 }
Example #34
0
// Setting up a right collection to be used
        public static IMongoCollection <BsonDocument> GetCollection(string collectionName, IMongoDatabase database)
        {
            System.Diagnostics.Debug.WriteLine("Collection init: " + collectionName);
            return(database.GetCollection <BsonDocument>(collectionName));
        }
Example #35
0
        public BaseRepository()
        {
            MongoClient client = new MongoClient("mongodb+srv://product:[email protected]/test?retryWrites=true");

            db = client.GetDatabase("ProductCatalog");
        }
Example #36
0
 public MongoDbInitializer(IMongoDatabase database, IMongoDbSeeder seeder, MongoDbOptions options)
 {
     _database = database;
     _seeder   = seeder;
     _seed     = options.Seed;
 }
 public CarOwnersRepository(string connectionString)
 {
     _client = new MongoClient(connectionString); //("mongodb://localhost:27017");
     _db     = _client.GetDatabase("carsOwnersDB");
 }
 public MongoDbMessagesTracker(IMongoDatabase db)
 {
     _db    = db;
     Logger = NullLogger.Instance;
 }
Example #39
0
 public MongoUsageStore(IMongoDatabase database)
     : base(database)
 {
 }
Example #40
0
        static void Main(string[] args)
        {
            List <Table> m_rows = new CCsv().ReadCsv <Table>("history.csv");

            MongoClient    dbClient     = new MongoClient("mongodb://127.0.0.1:27017");
            IMongoDatabase db           = dbClient.GetDatabase("test");
            var            municipality = db.GetCollection <Municipality>("municipality");
            var            address      = db.GetCollection <ClientAddress>("ClientAddress");
            var            client       = db.GetCollection <Client>("Client");

            for (int i = 0; i < 4; i++)
            {
                // Municipality
                Municipality mun = new Municipality();
                mun.Name      = m_rows[i].City;
                mun.NameLower = m_rows[i].City.ToLower();
                mun.UpdatedAt = DateTime.UtcNow.ToString();
                mun.CreatedAt = DateTime.UtcNow.ToString();
                mun.Enabled   = true;
                mun.HubID     = null;
                municipality.InsertOne(mun);
                // Address
                ClientAddress adr = new ClientAddress();
                adr.City        = m_rows[i].City;
                adr.CityId      = mun._id;
                adr.Street      = m_rows[i].Street;
                adr.StreetLower = m_rows[i].Street.ToLower();
                adr.CivicNumber = m_rows[i].CivicNumber;
                adr.PostalCode  = m_rows[i].PostalCode;
                adr.ExternalId  = 0;
                adr.AptNumber   = m_rows[i].AptNumber;
                address.InsertOne(adr);
                // Client
                Client cli = new Client();
                cli.FirstName         = m_rows[i].FirstName;
                cli.FirstNameLower    = m_rows[i].FirstName.ToLower();
                cli.LastName          = m_rows[i].LastName;
                cli.LastNameLower     = m_rows[i].LastName.ToLower();
                cli.OBNLNumber        = null;
                cli.OBNLNumbers       = null;
                cli.Category          = "resident";
                cli.CategoryCustom    = null;
                cli.PhoneNumber       = "";
                cli.MobilePhoneNumber = m_rows[i].MobilePhoneNumber;
                cli.Email             = m_rows[i].Email;
                cli.EmailLower        = m_rows[i].Email.ToLower();
                cli.Address           = adr;
                cli.PreviousAddresses = new ClientAddress[0];
                cli.Hub                 = null;
                cli.MunicipalityId      = null;
                cli.Status              = 0;
                cli.RegistrationDate    = DateTime.UtcNow.ToString();
                cli.LastChange          = DateTime.UtcNow.ToString();
                cli.Verified            = true;
                cli.Comments            = "";
                cli.VisitsLimitExceeded = false;
                cli.PersonalVisitsLimit = 0;
                cli.RefId               = null;
                client.InsertOne(cli);
            }
        }
Example #41
0
        protected static async Task <Job> TryProcessOneJobUsingTakeNext(IMongoDatabase database, QueueId exampleQueueName, JobAttributes attributesThatShouldWork)
        {
            // Take Next available job
            var takeNextService = new MongoJobTakeNextService(database);
            var standardAck     = new JobAcknowledgment
            {
                { "RunnerId", Guid.NewGuid().ToString("N") }
            };
            var peekQuery = new TakeNextOptions
            {
                QueueId        = exampleQueueName,
                HasAttributes  = attributesThatShouldWork,
                Acknowledgment = standardAck
            };
            var nextJob = await takeNextService.TakeFor(peekQuery).ConfigureAwait(false);

            if (nextJob == null)
            {
                return(null);
            }

            var exampleReportMessage1 = "FooBar";
            var exampleReportMessage2 = "WizBang";
            var exampleReportMessage3 = "PowPop";

            // Send Reports
            var reportService = new MongoJobReportService(database);
            await
            reportService.AddReport(exampleQueueName, nextJob.Id,
                                    new JobReport { { "Timestamp", DateTime.UtcNow.ToString("O") }, { "Message", exampleReportMessage1 } }).ConfigureAwait(false);

            await
            reportService.AddReport(exampleQueueName, nextJob.Id,
                                    new JobReport { { "Timestamp", DateTime.UtcNow.ToString("O") }, { "Message", exampleReportMessage2 } }).ConfigureAwait(false);

            await
            reportService.AddReport(exampleQueueName, nextJob.Id,
                                    new JobReport { { "Timestamp", DateTime.UtcNow.ToString("O") }, { "Message", exampleReportMessage3 } }).ConfigureAwait(false);

            // Send Result
            var completionService = new MongoJobCompletionService(database);
            await completionService.Complete(exampleQueueName, nextJob.Id, new JobResult { { "Result", "Success" } }).ConfigureAwait(false);

            // Finish Job
            var finishedJobFromDb =
                await database.GetJobCollection().Find(Builders <Job> .Filter.Eq(x => x.Id, nextJob.Id)).FirstAsync().ConfigureAwait(false);

            Assert.That(finishedJobFromDb, Is.Not.Null);
            Assert.That(finishedJobFromDb.Acknowledgment, Is.Not.Null);

            Assert.That(finishedJobFromDb.Reports, Has.Length.EqualTo(3));
            var valuesOfReports = finishedJobFromDb.Reports.SelectMany(x => x.Values).ToList();

            Assert.That(valuesOfReports, Contains.Item(exampleReportMessage1));
            Assert.That(valuesOfReports, Contains.Item(exampleReportMessage2));
            Assert.That(valuesOfReports, Contains.Item(exampleReportMessage3));

            Assert.That(finishedJobFromDb.Result, Is.Not.Null);

            return(finishedJobFromDb);
        }
Example #42
0
        public MangoCRUD(string database)
        {
            var client = new MongoClient();

            db = client.GetDatabase(database);
        }
Example #43
0
 public void Dispose()
 {
     this.mongoDatabase = null;
     this.repositories  = null;
 }
Example #44
0
        public MongoDbContext()
        {
            var client = new MongoClient("mongodb://localhost:27017");

            this.database = client.GetDatabase("MediatRStudyDB");
        }
        public ContaRepository(IConfiguration configuration)
        {
            var client = new MongoClient(configuration.GetConnectionString("BancoDigitalConnection"));

            _database = client.GetDatabase("BancoDigital");
        }
Example #46
0
        protected static async Task <Job> TryProcessOneJobUsingPeekThanAck(IMongoDatabase database, QueueId exampleQueueName, JobAttributes attributesThatShouldWork)
        {
            // Query for next available a job for my datacenter
            var peekNextService = new MongoJobPeekNextService(new MongoJobQueryService(database));
            var peekQuery       = new PeekNextOptions
            {
                QueueId       = exampleQueueName,
                HasAttributes = attributesThatShouldWork,
                Limit         = 5
            };
            var jobs = (await peekNextService.PeekFor(peekQuery).ConfigureAwait(false)).ToList();

            if (!jobs.Any())
            {
                return(null);
            }

            foreach (var job in jobs)
            {
                // Acknowledge the job
                var acknowledgmentService = new MongoJobAcknowledgmentService(database);
                var standardAck           = new JobAcknowledgment
                {
                    { "RunnerId", Guid.NewGuid().ToString("N") }
                };
                var ackResult = await acknowledgmentService.Ack(exampleQueueName, job.Id, standardAck).ConfigureAwait(false);

                if (!ackResult.Success)
                {
                    continue;
                }

                var exampleReportMessage1 = "FooBar";
                var exampleReportMessage2 = "WizBang";
                var exampleReportMessage3 = "PowPop";

                // Send Reports
                var reportService = new MongoJobReportService(database);
                await
                reportService.AddReport(exampleQueueName, job.Id,
                                        new JobReport { { "Timestamp", DateTime.UtcNow.ToString("O") }, { "Message", exampleReportMessage1 } }).ConfigureAwait(false);

                await
                reportService.AddReport(exampleQueueName, job.Id,
                                        new JobReport { { "Timestamp", DateTime.UtcNow.ToString("O") }, { "Message", exampleReportMessage2 } }).ConfigureAwait(false);

                await
                reportService.AddReport(exampleQueueName, job.Id,
                                        new JobReport { { "Timestamp", DateTime.UtcNow.ToString("O") }, { "Message", exampleReportMessage3 } }).ConfigureAwait(false);

                // Send Result
                var completionService = new MongoJobCompletionService(database);
                await completionService.Complete(exampleQueueName, job.Id, new JobResult { { "Result", "Success" } }).ConfigureAwait(false);

                // Finish Job
                var finishedJobFromDb =
                    await database.GetJobCollection().Find(Builders <Job> .Filter.Eq(x => x.Id, job.Id)).FirstAsync().ConfigureAwait(false);

                Assert.That(finishedJobFromDb, Is.Not.Null);
                Assert.That(finishedJobFromDb.Acknowledgment, Is.Not.Null);

                Assert.That(finishedJobFromDb.Reports, Has.Length.EqualTo(3));
                var valuesOfReports = finishedJobFromDb.Reports.SelectMany(x => x.Values).ToList();
                Assert.That(valuesOfReports, Contains.Item(exampleReportMessage1));
                Assert.That(valuesOfReports, Contains.Item(exampleReportMessage2));
                Assert.That(valuesOfReports, Contains.Item(exampleReportMessage3));

                Assert.That(finishedJobFromDb.Result, Is.Not.Null);

                return(finishedJobFromDb);
            }
            return(null);
        }
Example #47
0
        static DataLogic()
        {
            MongoClient client = new MongoClient("mongodb://localhost:27017");

            _database = client.GetDatabase("BotData");
        }
Example #48
0
 public RepositoryFactory(IMongoDatabase mongoDatabase)
 {
     this.mongoDatabase = mongoDatabase;
     this.repositories  = new Dictionary <Type, object>();
 }
 public MongoRuleStatisticsCollection(IMongoDatabase database)
     : base(database)
 {
 }
        public ContaRepository(string connectionString)
        {
            var client = new MongoClient("connectionString");

            _database = client.GetDatabase("BancoDigital");
        }
Example #51
0
 public InvalidCaseReportsFromUnknownDataCollectors(IMongoDatabase database)
 {
     _database   = database;
     _collection = database.GetCollection <InvalidCaseReportFromUnknownDataCollector>(CollectionName);
 }
Example #52
0
 public static void Initialize()
 {
     Client = new MongoClient(uri);
     Db     = Client.GetDatabase(db);
 }
 public UsersRepository()
 {
     _client = new MongoClient("mongodb://localhost:27017");
     _database = _client.GetDatabase("ChannelDB");
     _usersCollection = _database.GetCollection<User>("users");
 }
Example #54
0
 public ObjectsAuditor(IMongoDatabase mongoDb)
 {
     _mongoDb = mongoDb;
 }
 static DatabaseContext()
 {
     //var connectionString = ConfigurationManager.ConnectionStrings[CONNECTION_STRING_NAME].ConnectionString;
     var connectionString = "mongodb://*****:*****@ds055722.mongolab.com:55722/edubase";
     _client = new MongoClient(connectionString);
     _database = _client.GetDatabase(DATABASE_NAME);
 }
Example #56
-1
 public DocumentDb(string DBName,ISchemaContext SchemaContext)
 {
     _client = new MongoClient();
     _database = _client.GetDatabase(DBName);
     ctx = SchemaContext;
     this.DBName = DBName;
 }
        protected void SetUp()
        {
            var f = new FileStream("config.json", FileMode.Open);
            var sr = new StreamReader(f);
            try
            {
                var settings = JsonConvert
                    .DeserializeObject<MongoSettings>(sr.ReadToEnd());
                var client = new MongoClient(new MongoUrl(settings.Url));
                _database = client.GetDatabase(settings.DatabaseName);
            }
            catch (FileNotFoundException)
            {
                throw new Exception("Talk to John about why this one fails");
            }
            finally
            {
                f.Dispose();
                sr.Dispose();
            }

            _collectionName = Guid.NewGuid().ToString();
            _collection = _database.GetCollection<Container>(_collectionName);
            var mapper = new StringMapper<BasePaymentModel>(x => x.PaymentType)
                .Register<AchInputModel>("ach")
                .Register<CreditCardInputModel>("cc")
                .Register<PayPalInputModel>("paypal");
            BsonSerializer.RegisterDiscriminatorConvention(
                typeof(BasePaymentModel),
                new DiscriminatorConvention<string, BasePaymentModel>(mapper));
        }
 public static IMongoDatabase getMongoDB()
 {
     _client = new MongoClient("mongodb://145.24.222.168/CityGis"); //Connection string gaat hier
     //_client = new MongoClient("mongodb://localhost/CityGis");
     _database = _client.GetDatabase("CityGis");
     return _database;
 }
Example #59
-1
 public GameRepository()
 {
     string connection = System.Configuration.ConfigurationManager.ConnectionStrings["Mongodb"].ConnectionString;
     _client = new MongoClient(connection);
     _database = _client.GetDatabase(System.Configuration.ConfigurationManager.AppSettings["DataBaseName"]);
     _collection = _database.GetCollection<GameEntity>("games");
 }
        public static void Main(string[] args)
        {
            // #Connect to Db Shop => caseSensitive!!!
            client = new MongoClient("mongodb://127.0.0.1");
            database = client.GetDatabase("Shop");

            //var eDrink = new EnergyDrink("Hell", 1.05);

            // #connect to table EnergyDrinks
            var drinksCollection = database.GetCollection<EnergyDrink>("EnergyDrinks");

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Enter command:");
                Console.WriteLine("Add new drink: => 1");
                Console.WriteLine("Get all drinks: => 2");
                Console.WriteLine("Get drinks by name => 3");
                Console.WriteLine("Get drinks by price => 4");

                var command = Console.ReadLine();

                switch (command)
                {
                    case "1": InsertToDatabase(drinksCollection); break;
                    case "2": GetAllDrinks(drinksCollection); break;
                    case "3": SearchByName(drinksCollection); break;
                    case "4": SearchByPrice(drinksCollection); break;
                    default:
                        break;
                }
            }
        }