// List<Emprunt> TrouverEmpruntLecteur private void btnListeEmprunts_Click(object sender, EventArgs ea) { if (saveFileDialog1.ShowDialog() == DialogResult.OK) { using (StreamWriter sw = new StreamWriter(saveFileDialog1.FileName, false, Encoding.Default)) { sw.WriteLine("Groupe;Nom;Prénom;Titre;Auteur;Date Emprunt;Date Retour;Exemplaire"); var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); var collNotice = db.GetCollection <Notice>("Notice"); lecteurBindingSource.EndEdit(); Lecteur lecteur = ((List <Lecteur>)lecteurBindingSource.DataSource)[0]; foreach (InfoLecteur il in db.GetCollection <InfoLecteur>("InfoLecteur").Find(a => a.lecteurId == lecteur._id).ToList()) { foreach (Emprunt emprunt in il.TrouverEmprunt()) { List <Notice> tmp = collNotice.Find(new BsonDocument("exemplaires._id", emprunt.IdExemplaire)).ToList(); if (tmp != null && tmp.Count > 0) { Exemplaire ex = tmp[0].exemplaires.Find(a => a._id == emprunt.IdExemplaire); sw.WriteLine($"{lecteur.titre};{il.nom};{il.prénom};{tmp[0].titre};{tmp[0].auteur};{emprunt.dateEmprunt.ToString("dd/MM/yyyy")};{emprunt.dateRetourPrévue.ToString("dd/MM/yyyy")};'{ex.codeBarre}"); } } } } System.Diagnostics.Process.Start("explorer.exe", "/select,\"" + saveFileDialog1.FileName + "\""); } }
void RefreshLecteursList() { var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); var infoLecteurs = db.GetCollection <InfoLecteur>("InfoLecteur").Find(a => a.lecteurId == m_lr.lecteur._id).ToList(); // Compléter le nombre d'emprunts BsonArray lecteurList = new BsonArray(); foreach (InfoLecteur il in infoLecteurs) { lecteurList.Add(il._id); } var emprunts = db.GetCollection <Emprunt>("Emprunt").Find( Builders <Emprunt> .Filter.And( Builders <Emprunt> .Filter.In("idLecteur", lecteurList), Builders <Emprunt> .Filter.Eq("etat", 1))).ToList(); foreach (Emprunt e in emprunts) { var t = infoLecteurs.Find(a => a._id == e.idLecteur); if (t != null) { t.nombreDemprunts++; m_total++; } } infoLecteurBindingSource.DataSource = infoLecteurs; lblTotal.Text = string.Format(lblTotal.Tag.ToString(), m_total); }
public static List <LecteurResult> TrouverLecteursParGroupe(InfoLecteur ilParent) { List <LecteurResult> result = new List <LecteurResult>(); var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); foreach (InfoLecteur il in db.GetCollection <InfoLecteur>("InfoLecteur").Find(a => a.lecteurId == ilParent.lecteurId).ToList()) { if (!il.deleted) { LecteurResult lr = new LecteurResult() { infoLecteur = il, lecteur = db.GetCollection <Lecteur>("Lecteur").Find(a => a._id == il.lecteurId).FirstOrDefault() }; result.Add(lr); } } result.Sort((a, b) => { if (a.infoLecteur.nom.ToLower() != b.infoLecteur.nom.ToLower()) { return(a.infoLecteur.nom.ToLower().CompareTo(b.infoLecteur.nom.ToLower())); } else { return(a.infoLecteur.prénom.ToLower().CompareTo(b.infoLecteur.prénom.ToLower())); } }); return(result); }
public static List <LecteurResult> TrouverLecteursParSearch(string search) { List <LecteurResult> result = new List <LecteurResult>(); var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); var s = new MongoDB.Bson.BsonRegularExpression(search, "/i"); foreach (InfoLecteur il in db.GetCollection <InfoLecteur>("InfoLecteur").Find( Builders <InfoLecteur> .Filter.And( Builders <InfoLecteur> .Filter.Eq(a => a.localisation, Properties.Settings.Default.Localisation), Builders <InfoLecteur> .Filter.Eq(a => a.deleted, false), Builders <InfoLecteur> .Filter.Or( Builders <InfoLecteur> .Filter.Regex(a => a.nom, s), Builders <InfoLecteur> .Filter.Regex(a => a.prénom, s), Builders <InfoLecteur> .Filter.Regex(a => a.commentaires, s) ) ) ).ToList()) { LecteurResult lr = new LecteurResult() { infoLecteur = il, lecteur = db.GetCollection <Lecteur>("Lecteur").Find(a => a._id == il.lecteurId).FirstOrDefault() }; result.Add(lr); } // Rechercher par titre foreach (Lecteur lecteur in db.GetCollection <Lecteur>("Lecteur").Find(Builders <Lecteur> .Filter.Regex(a => a.titre, s)).ToList()) { foreach (InfoLecteur il in db.GetCollection <InfoLecteur>("InfoLecteur").Find(a => a.lecteurId == lecteur._id).ToList()) { if (il.deleted == false && result.Find(a => a.infoLecteur._id == il._id) == null) { result.Add(new LecteurResult() { infoLecteur = il, lecteur = lecteur }); } } } result.Sort((a, b) => { a.infoLecteur.nom = a.infoLecteur.nom ?? ""; b.infoLecteur.nom = b.infoLecteur.nom ?? ""; if (a.infoLecteur.nom.ToLower() != b.infoLecteur.nom.ToLower()) { return(a.infoLecteur.nom.ToLower().CompareTo(b.infoLecteur.nom.ToLower())); } else { return(a.infoLecteur.prénom.ToLower().CompareTo(b.infoLecteur.prénom.ToLower())); } }); return(result); }
public static LecteurResult TrouverLecteurParId(ObjectId id) { var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); LecteurResult result = new LecteurResult() { infoLecteur = db.GetCollection <InfoLecteur>("InfoLecteur").Find(Builders <InfoLecteur> .Filter.Eq(a => a._id, id)).FirstOrDefault() }; if (result.infoLecteur != null) { result.lecteur = db.GetCollection <Lecteur>("Lecteur").Find(Builders <Lecteur> .Filter.Eq(a => a._id, result.infoLecteur.lecteurId)).FirstOrDefault(); } return(result); }
public static LecteurResult TrouverLecteurParId(ObjectId id) { var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); LecteurResult result = new LecteurResult() { infoLecteur = db.GetCollection <InfoLecteur>("InfoLecteur").Find(a => a._id == id /*&& a.deleted == false*/).FirstOrDefault() }; if (result.infoLecteur != null) { result.lecteur = db.GetCollection <Lecteur>("Lecteur").Find(a => a._id == result.infoLecteur.lecteurId /*&& a.deleted == false*/).FirstOrDefault(); } return(result); }
public void Aggregate_with_query() { var startDate = GetStartDate(); var endDate = GetEndDate(); var duration = new TimeSpan(endDate.Ticks - startDate.Ticks); var maxCount = duration.TotalMinutes / delta.TotalMinutes; var stopWatch = new Stopwatch(); var dataBase = new MongoClient("mongodb://localhost").GetServer().GetDatabase("MapReduce"); var sessions = dataBase.GetCollection<Session>("Sessions"); stopWatch.Start(); var statistic = new List<StatisticItem>(); for (int i = 0; i < maxCount; i++) { var startStroke = startDate.AddMinutes(delta.Minutes * i); var endStroke = startStroke.AddMinutes(delta.Minutes); statistic.Add(this.GetStatisticItem(startStroke, endStroke, sessions)); } stopWatch.Stop(); foreach (var statItem in statistic) { Trace.WriteLine(statItem.DateTime + " " + statItem.Count); } Trace.WriteLine("Aggregation: " + stopWatch.ElapsedTicks); }
private void supprimerToolStripMenuItem_Click(object sender, EventArgs e) { int total = 0; int users = 0; BsonArray ids = new BsonArray(); foreach (DataGridViewCell cell in infoLecteurDataGridView.SelectedCells) { InfoLecteur il = infoLecteurDataGridView.Rows[cell.RowIndex].DataBoundItem as InfoLecteur; if (il != null) { total += il.nombreDemprunts; ids.Add(il._id); } users++; } if (total > 0) { MessageBox.Show(toolTip1.GetToolTip(label1)); } else { if (MessageBox.Show(($"Confirmez-vous la suppression de {users} membre") + (users > 1 ? "s." : "." + "\r\nC'est irréverssible."), "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); db.GetCollection <InfoLecteur>("InfoLecteur").UpdateMany( Builders <InfoLecteur> .Filter.In("_id", ids), Builders <InfoLecteur> .Update.Set(a => a.lecteurId, ObjectId.Empty).CurrentDate(a => a.dateSuppression).Set(a => a.deleted, true) ); RefreshLecteursList(); } } }
public void Any(KnockPostV1 request) { var db = new MongoClient().GetDatabase("test"); var collection = db.GetCollection<Potato>("KnockKnock"); collection.FindOneAndReplace(Builders<Potato>.Filter.Eq(k => k.Id, request.Knock.Id), new Potato(request.Knock), new FindOneAndReplaceOptions<Potato, Potato>() { IsUpsert = true }); }
public void Init(LecteurResult lr) { m_lr = lr; RefreshLecteursList(); lecteurBindingSource.DataSource = new List <Lecteur>() { lr.lecteur }; lecteurBindingSource.Position = 0; var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); titreComboBox.DataSource = db.GetCollection <Lecteur>("Lecteur").Distinct <string>("titre", "{}").ToList(); villeComboBox.DataSource = db.GetCollection <Lecteur>("Lecteur").Distinct <string>("ville", "{}").ToList(); codePostalComboBox.DataSource = db.GetCollection <Lecteur>("Lecteur").Distinct <string>("codePostal", "{}").ToList(); }
public MongoDBRevisionStorage(string connectionString) { ConnectionString = connectionString; var mongoUrl = MongoUrl.Create(connectionString); var database = new MongoClient(mongoUrl).GetDatabase(mongoUrl.DatabaseName); _revisions = database.GetCollection<RevisionModel>("revisions"); }
public void Aggregate_with_map_reduce() { var dataBase = new MongoClient("mongodb://localhost").GetServer().GetDatabase("MapReduce"); var sessions = dataBase.GetCollection<Session>("Sessions"); BsonJavaScript map = new BsonJavaScript(Scipts.map); BsonJavaScript reduce = new BsonJavaScript(Scipts.reduce); var result = sessions.MapReduce(map, reduce); }
public RequestResponsePairQueryService(IConfig config) { var url = MongoUrl.Create(config.ProxyDbConnectionString); var db = new MongoClient(url) .GetServer() .GetDatabase(url.DatabaseName); _collection = db.GetCollection<RequestResponsePair>(); }
public UseCaseQueryService(IConfig config) { var url = MongoUrl.Create(config.ProxyDbConnectionString); var db = new MongoClient(url) .GetServer() .GetDatabase(url.DatabaseName); _collection = db.GetCollection<UseCase>(); }
public UseCaseUpdateTask(IConfig config, IDataList<UseCase> useCases) { var url = new MongoUrl(config.ProxyDbConnectionString); var db = new MongoClient(url) .GetServer() .GetDatabase(url.DatabaseName); _collection = db.GetCollection<UseCase>("UseCase"); _useCases = useCases; }
public MongoDBUserStorage(string connectionString) { ConnectionString = connectionString; var mongoUrl = MongoUrl.Create(connectionString); var database = new MongoClient(mongoUrl).GetDatabase(mongoUrl.DatabaseName); _users = database.GetCollection<UserModel>("users"); Task.Run(() => SetUp()).Wait(); }
private void btnOK_Click(object sender, EventArgs e) { lecteurBindingSource.EndEdit(); infoLecteurBindingSource.EndEdit(); var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); Lecteur lecteur = ((List <Lecteur>)lecteurBindingSource.DataSource)[0]; lecteur.localisation = Properties.Settings.Default.Localisation; var ops = new UpdateOptions { IsUpsert = true }; db.GetCollection <Lecteur>("Lecteur").ReplaceOne(x => x._id == lecteur._id, lecteur, ops); foreach (InfoLecteur il in (List <InfoLecteur>)infoLecteurBindingSource.DataSource) { il.localisation = Properties.Settings.Default.Localisation; il.lecteurId = lecteur._id; db.GetCollection <InfoLecteur>("InfoLecteur").ReplaceOne(x => x._id == il._id, il, ops); } }
public void Aggregate() { var dataBase = new MongoClient("mongodb://localhost").GetServer().GetDatabase("MapReduce"); var collection = dataBase.GetCollection<Session>("Sessions"); var match = GetMatchOperator(GetStartDate(), GetEndDate()); var project = GetProjectOperator(GetStartDate()); var pipeline = new[] { match, project }; var result = collection.Aggregate(pipeline); var matching = result.ResultDocuments.Count(); }
public static void AddMessage(string username, string text) { MongoDatabase db = new MongoClient("mongodb://*****:*****@ds061548.mongolab.com:61548/chat-db") .GetServer() .GetDatabase("chat-db"); var messagesCollection = db.GetCollection<Message>("messages"); var message = new Message { Date = DateTime.Now, Username = username, Text = text }; messagesCollection.Insert(message); }
public TableFiller(DbSettings configuration) { Configurations = configuration.collections.Configurations; Counters = configuration.collections.Counters; ConnectionString = configuration.connectionstring; DatabaseName = configuration.database; Database = new MongoClient(ConnectionString).GetServer().GetDatabase(DatabaseName); var configJson = Database.GetCollection(Configurations).FindOne().ToJson(); Config = JsonConvert.DeserializeObject<Configurations>(configJson); }
public static async Task mainAsync() { var db = new MongoClient().GetDatabase("school"); var collection = db.GetCollection<BsonDocument>("students"); var list = await collection.Find(new BsonDocument()).ToListAsync(); var newList = new List<BsonDocument>(); list.ForEach(data => newList.Add(dropScore(data))); await db.DropCollectionAsync("students"); await db.CreateCollectionAsync("students"); await collection.InsertManyAsync(newList); }
static async Task MainAsync() { var database = new MongoClient().GetDatabase("students"); var collection = database.GetCollection<BsonDocument>("grades"); List<BsonDocument> listStudents = await collection.Find(new BsonDocument("type", "homework")).ToListAsync(); listStudents.GroupBy(data => data["student_id"]).Select(data => new { student_id = data.Key, score = data.Min(x => x["score"]) }).ToList().ForEach(student => { Console.WriteLine(student + " score removed."); collection.DeleteOneAsync(new BsonDocument("student_id", student.student_id).Add("score", student.score).Add("type", "homework")); }); }
private void btnDelete_Click(object sender, EventArgs e) { int total = 0; int users = 0; BsonArray ids = new BsonArray(); foreach (DataGridViewRow row in infoLecteurDataGridView.Rows) { InfoLecteur il = row.DataBoundItem as InfoLecteur; if (il != null) { total += il.nombreDemprunts; ids.Add(il._id); } users++; } if (total > 0) { MessageBox.Show(toolTip1.GetToolTip(label1)); } else { if (MessageBox.Show("Confirmez-vous la suppression du groupe?\r\nC'est action est irréverssible.", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); db.GetCollection <InfoLecteur>("InfoLecteur").UpdateMany( Builders <InfoLecteur> .Filter.In("_id", ids), Builders <InfoLecteur> .Update.Set(a => a.lecteurId, ObjectId.Empty).CurrentDate(a => a.dateSuppression).Set(a => a.deleted, true) ); db.GetCollection <Lecteur>("Lecteur").UpdateOne( a => a._id == m_lr.lecteur._id, Builders <Lecteur> .Update.CurrentDate(a => a.dateSuppression).Set(a => a.deleted, true) ); Close(); } } }
public void Init(ObjectId lecteur) { LecteurResult lr = Lecteur.TrouverLecteurParId(lecteur); if (lr != null) { var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); infoLecteurBindingSource.DataSource = db.GetCollection <InfoLecteur>("InfoLecteur").Find(a => a.lecteurId == lr.lecteur._id).ToList(); lecteurBindingSource.DataSource = new List <Lecteur>() { lr.lecteur }; lecteurBindingSource.Position = 0; } }
public static void PrintAllMessages() { MongoDatabase db = new MongoClient("mongodb://*****:*****@ds061548.mongolab.com:61548/chat-db") .GetServer() .GetDatabase("chat-db"); var messagesCollection = db.GetCollection<Message>("messages"); var messages = messagesCollection.FindAll(); foreach (var message in messages) { Console.WriteLine("Message:\n User:{0}\n Text: {1}", message.Username, message.Text); Console.WriteLine(); } }
static void Main() { var db = new MongoClient(Connections.Default.MongoCloud).GetServer().GetDatabase("mongochat"); var messages = db.GetCollection<BsonDocument>("Messages"); Console.Write("Username: "******"> "); string input = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(input)) messages.Insert( new BsonDocument { { "Author", username }, { "Text", input }, { "Time", DateTime.Now } }); var formattedMessages = messages .FindAll() .Select(m => string.Format("[{0}] {1}: {2}", m["Time"].ToLocalTime(), m["Author"], m["Text"])); Console.WriteLine(string.Join(Environment.NewLine, formattedMessages)); } }
private void btnImport_Click(object sender, EventArgs e) { using (frmImport import = new frmImport()) { var tmp = import.ShowDialog(); switch (tmp) { case DialogResult.OK: if (import.m_append != null) { foreach (var item in import.m_append) { infoLecteurBindingSource.Add(new InfoLecteur() { _id = ObjectId.GenerateNewId(), nom = item.Item1, prénom = item.Item2 }); } } break; case DialogResult.Yes: if (import.m_replace != null) { int total = 0; int users = 0; BsonArray ids = new BsonArray(); foreach (DataGridViewRow row in infoLecteurDataGridView.Rows) { InfoLecteur il = row.DataBoundItem as InfoLecteur; if (il != null) { total += il.nombreDemprunts; ids.Add(il._id); } users++; } if (total > 0) { MessageBox.Show(toolTip1.GetToolTip(label1)); } else { var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); db.GetCollection <InfoLecteur>("InfoLecteur").UpdateMany( Builders <InfoLecteur> .Filter.In("_id", ids), Builders <InfoLecteur> .Update.Set(a => a.lecteurId, ObjectId.Empty).CurrentDate(a => a.dateSuppression).Set(a => a.deleted, true) ); infoLecteurBindingSource.Clear(); foreach (var item in import.m_replace) { infoLecteurBindingSource.Add(new InfoLecteur() { _id = ObjectId.GenerateNewId(), nom = item.Item1, prénom = item.Item2 }); } } } break; } } }
private void RegisterTenantServices() { foreach (var tenant in _manager.Tenants) { ITenant tenant1 = tenant; var esComponentName = tenant.Id + "-es"; var readModelDb = tenant1.Get<IMongoDatabase>("readmodel.db"); var mongoPersistenceOptions = new MongoPersistenceOptions(); mongoPersistenceOptions.DisableSnapshotSupport = true; mongoPersistenceOptions.ConcurrencyStrategy = ConcurrencyExceptionStrategy.FillHole; var nesUrl = new MongoUrl(tenant1.GetConnectionString("events")); var nesDb = new MongoClient(nesUrl).GetDatabase(nesUrl.DatabaseName); var eventsCollection = nesDb.GetCollection<BsonDocument>("Commits"); mongoPersistenceOptions.CheckpointGenerator = new InMemoryCheckpointGenerator(eventsCollection); tenant1.Container.Register( Classes .FromAssemblyContaining<DocumentDescriptor>() .BasedOn<IPipelineHook>() .WithServiceAllInterfaces(), Component .For<IStoreEvents>() .Named(esComponentName) .UsingFactory<EventStoreFactory, IStoreEvents>(f => { var hooks = tenant1.Container.ResolveAll<IPipelineHook>(); return f.BuildEventStore( tenant1.GetConnectionString("events"), hooks, mongoPersistenceOptions : mongoPersistenceOptions ); }) .LifestyleSingleton(), Component .For<IRepositoryEx, RepositoryEx>() .ImplementedBy<RepositoryEx>() .Named(tenant.Id + ".repository") .DependsOn(Dependency.OnComponent(typeof(IStoreEvents), esComponentName)) .LifestyleTransient(), Component .For<Func<IRepositoryEx>>() .Instance(() => tenant1.Container.Resolve<IRepositoryEx>()), Component .For<ISnapshotManager>() .DependsOn(Dependency.OnValue("cacheEnabled", _config.EnableSnapshotCache)) .ImplementedBy<CachedSnapshotManager>(), Component .For<IAggregateCachedRepositoryFactory>() .ImplementedBy<AggregateCachedRepositoryFactory>() .DependsOn(Dependency.OnValue("cacheDisabled", false)), Component .For<ISnapshotPersistenceStrategy>() .ImplementedBy<NumberOfCommitsShapshotPersistenceStrategy>() .DependsOn(Dependency.OnValue("commitsThreshold", 100)), Component.For<ISnapshotPersister>() .ImplementedBy<MongoSnapshotPersisterProvider>() .DependsOn(Dependency.OnValue<IMongoDatabase>(readModelDb)) ); } }
public UrlStore() { var database = new MongoClient("mongodb://*****:*****@kahana.mongohq.com:10070/shortUrl").GetServer().GetDatabase("shortUrl"); this.urls = database.GetCollection("urls"); }
private void EnsureIndexes() { var database = new MongoClient(_connectionString).GetServer().GetDatabase(_databaseName); var collectionNames = database.GetCollectionNames(); foreach (var collectionName in collectionNames) { var collection = database.GetCollection(collectionName); var indexesForCollection = _indexBuilder.Value.Get().Where(t => t.CollectionName.Equals(collectionName)).ToList(); foreach (var mongoDbIndex in indexesForCollection) { if (mongoDbIndex.IndexOptions.IsSome) collection.CreateIndex(mongoDbIndex.Index, mongoDbIndex.IndexOptions.Value); else collection.CreateIndex(mongoDbIndex.Index); } } }
public override void Initialize(string name, NameValueCollection config) { this.ApplicationName = config["applicationName"] ?? HostingEnvironment.ApplicationVirtualPath; var mongoDatabase = new MongoClient(config["connectionString"] ?? "mongodb://localhost").GetServer().GetDatabase(config["database"] ?? "ASPNETDB"); this.rolesMongoCollection = mongoDatabase.GetCollection(config["collection"] ?? "Roles"); this.usersInRolesMongoCollection = mongoDatabase.GetCollection("UsersInRoles"); this.rolesMongoCollection.EnsureIndex("ApplicationName"); this.rolesMongoCollection.EnsureIndex("ApplicationName", "Role"); this.usersInRolesMongoCollection.EnsureIndex("ApplicationName", "Role"); this.usersInRolesMongoCollection.EnsureIndex("ApplicationName", "Username"); this.usersInRolesMongoCollection.EnsureIndex("ApplicationName", "Role", "Username"); base.Initialize(name, config); }