public void SyncCollectionTest() { DataMigrationHelper.AddUsersFast(100, DbAccess); DbCollection <Users_Col> dbCollection = null; Assert.That(() => dbCollection = DbAccess.CreateDbCollection <Users_Col>(), Throws.Nothing); Assert.That(dbCollection, Is.Not.Empty); Assert.That(dbCollection.Count, Is.EqualTo(100)); Assert.That(() => dbCollection.Add(new Users_Col()), Throws.Nothing); Assert.That(dbCollection.Count, Is.EqualTo(101)); Assert.That(() => dbCollection.SaveChanges(DbAccess), Throws.Nothing); Assert.That(() => DbAccess.Select <Users_Col>().Length, Is.EqualTo(101)); Assert.That(() => dbCollection.Remove(dbCollection.First()), Throws.Nothing); Assert.That(dbCollection.Count, Is.EqualTo(100)); Assert.That(() => dbCollection.SaveChanges(DbAccess), Throws.Nothing); Assert.That(() => DbAccess.Select <Users_Col>().Length, Is.EqualTo(100)); var user25 = dbCollection[25]; user25.UserName = Guid.NewGuid().ToString(); Assert.That(() => dbCollection.GetEntryState(user25), Is.EqualTo(CollectionStates.Changed)); Assert.That(() => dbCollection.SaveChanges(DbAccess), Throws.Nothing); Assert.That(() => dbCollection.GetEntryState(user25), Is.EqualTo(CollectionStates.Unchanged)); Assert.That(() => DbAccess.SelectSingle <Users_Col>(user25.User_ID), Is.Not.Null.And .Property("User_ID").EqualTo(user25.User_ID) .And .Property("UserName").EqualTo(user25.UserName)); }
public async Task <OneOf <DbCollection> > CreateAsync(ObjectType type, CollectionBase model, string userId, string[] items = null, CancellationToken cancellationToken = default) { if (items != null && items.Length != 0) { var newItems = new string[items.Length]; var set = new HashSet <string>(items.Length, StringComparer.Ordinal); var count = 0; foreach (var item in items) { if (set.Add(item)) { newItems[count++] = item; } } Array.Resize(ref newItems, count); items = newItems; } var collection = new DbCollection { Type = type, OwnerIds = new[] { userId }, Items = items ?? Array.Empty <string>() }.ApplyBase(model, _services); return(await _client.Entry(collection).CreateAsync(cancellationToken)); }
public bool Test(DbCollection collection) { if (OwnerId != null && Array.IndexOf(collection.OwnerIds, OwnerId) == -1) { return(false); } return(true); }
public async Task <OneOf <DbCollection> > CreateAsync(ObjectType type, CollectionBase model, string userId, CancellationToken cancellationToken = default) { var collection = new DbCollection { Type = type, OwnerIds = new[] { userId }, Items = Array.Empty <string>() }.ApplyBase(model, _services); return(await _client.Entry(collection).CreateAsync(cancellationToken)); }
public Dictionary <string, ObjectId> GetCompanyId(List <string> symbols) { Dictionary <string, ObjectId> dictSymbolCompId = new Dictionary <string, ObjectId>(); foreach (var result in DbCollection.AsQueryable()) { if (symbols.Contains(result.symbol) && !dictSymbolCompId.ContainsKey(result.symbol)) { dictSymbolCompId.Add(result.symbol, result._id); } } return(dictSymbolCompId); }
public UtilityDbDetails() { var values = Enum.GetValues(typeof(DbEnum)); var length = values.Length; DbCollection[] oDbCollection = new DbCollection[length]; foreach (var item in values) { var index = Convert.ToInt32(item); oDbCollection[index] = new DbCollection(); var key = Enum.GetName(typeof(DbEnum), item); var dbName = ConfigurationManager.AppSettings[key]; var connectionString = "Data Source=" + Environment.CurrentDirectory + "\\Database\\" + dbName + "Compress=True;"; oDbCollection[index].ConnectionString = connectionString; } GetDbConnections = oDbCollection; }
private static async Task MakeSureDatabaseCreated(IMongoClient mongoDbClient) { try { var database = mongoDbClient.GetDatabase("BookStoreDB"); using (var session = await mongoDbClient.StartSessionAsync()) { var collections = DbCollection.All(); foreach (var collectionName in collections) { if (await database.ExistsCollection(collectionName)) { continue; } await database.CreateCollectionAsync(session, collectionName); } //var bookCollection = database.GetCollection<Book>("Book"); //bookCollection.InsertOne(new Book //{ // Name = "First book", // Author = "Tan Nguyen", // Category = "No name", // CreatedAt = DateTime.Now, // CreatedBy = "Tan" //}); } } catch (Exception e) { Console.WriteLine(e); // // TODO: Handle can't make sure database created throw; } }
private async Task <IList <GenericEvent> > PullEvents(DateTime from, DateTime to) { Log.Info(String.Format("Pulling events from [{0}] to [{1}]", from, to)); var myEvts = new DbCollection <GenericEvent>(); var evts = (await PullEvents()) as DbCollection <GenericEvent>; // note: google doesn't provide a direct way to filter events when listing them // so we have to filter them manually if (evts != null) { var excludedEvts = evts.Where(x => (x.Start <@from && x.End> to)).ToList(); // todo: have to test this foreach (var excludedEvt in excludedEvts) { evts.Remove(excludedEvt); } } else { throw new Exception(); } return(myEvts); }
private async Task <IList <GenericEvent> > PullEvents() { Log.Info("Pulling events"); var myEvts = new DbCollection <GenericEvent>(); try { var evts = await Service.Events.List(_settings.CalendarId).ExecuteAsync(); foreach (var evt in evts.Items) { var iCalUid = StringHelper.GetString(StringHelper.GoogleBase32.FromBaseString(evt.Id)); var myEvt = new GenericEvent(id: iCalUid, summary: evt.Summary, description: evt.Description, location: new GenericLocation { Name = evt.Location }); // Organizer if (evt.Organizer != null) { myEvt.Organizer = new GenericPerson { Email = evt.Organizer.Email, Name = evt.Organizer.DisplayName }; } // Creator if (evt.Creator != null) { myEvt.Creator = new GenericPerson { Email = evt.Creator.Email, Name = evt.Creator.DisplayName }; } // Start if (evt.Start != null) { myEvt.Start = evt.Start.DateTime; } // End if (evt.End != null) { myEvt.End = evt.End.DateTime; } // Creation date if (evt.Created.HasValue) { myEvt.Created = evt.Created; } // Recurrence if (evt.Recurrence != null) { myEvt.Recurrence = new GoogleRecurrence(); ((GoogleRecurrence)myEvt.Recurrence).Parse(evt.Recurrence[0]); //warning: this only parses one line inside Recurrence... } // Attendees if (evt.Attendees != null) { myEvt.Attendees = new List <GenericAttendee>(); foreach (var attendee in evt.Attendees) { ResponseStatus r; switch (attendee.ResponseStatus) { case "accepted": r = ResponseStatus.Accepted; break; case "tentative": r = ResponseStatus.Tentative; break; case "needsAction": r = ResponseStatus.NotResponded; break; case "declined": r = ResponseStatus.Declined; break; default: r = ResponseStatus.None; break; } myEvt.Attendees.Add( new GenericAttendee { Email = attendee.Email, Name = attendee.DisplayName, Response = r } ); } } myEvts.Add(myEvt); } } catch (Exception ex) { Log.Error("Exception", ex); } return(myEvts); }
private async Task<IList<GenericEvent>> PullEvents(DateTime from, DateTime to) { Log.Info(String.Format("Pulling events from [{0}] to [{1}]", from, to)); var myEvts = new DbCollection<GenericEvent>(); var evts = (await PullEvents()) as DbCollection<GenericEvent>; // note: google doesn't provide a direct way to filter events when listing them // so we have to filter them manually if (evts != null) { var excludedEvts = evts.Where(x => (x.Start < @from && x.End > to)).ToList(); // todo: have to test this foreach (var excludedEvt in excludedEvts) { evts.Remove(excludedEvt); } } else { throw new Exception(); } return myEvts; }
private async Task<IList<GenericEvent>> PullEvents() { Log.Info("Pulling events"); var myEvts = new DbCollection<GenericEvent>(); try { var evts = await Service.Events.List(_settings.CalendarId).ExecuteAsync(); foreach (var evt in evts.Items) { var iCalUid = StringHelper.GetString(StringHelper.GoogleBase32.FromBaseString(evt.Id)); var myEvt = new GenericEvent( id: iCalUid, summary: evt.Summary, description: evt.Description, location: new GenericLocation {Name = evt.Location}); // Organizer if (evt.Organizer != null) { myEvt.Organizer = new GenericPerson { Email = evt.Organizer.Email, Name = evt.Organizer.DisplayName }; } // Creator if (evt.Creator != null) { myEvt.Creator = new GenericPerson { Email = evt.Creator.Email, Name = evt.Creator.DisplayName }; } // Start if (evt.Start != null) { myEvt.Start = evt.Start.DateTime; } // End if (evt.End != null) { myEvt.End = evt.End.DateTime; } // Creation date if (evt.Created.HasValue) { myEvt.Created = evt.Created; } // Recurrence if (evt.Recurrence != null) { myEvt.Recurrence = new GoogleRecurrence(); ((GoogleRecurrence) myEvt.Recurrence).Parse(evt.Recurrence[0]); //warning: this only parses one line inside Recurrence... } // Attendees if (evt.Attendees != null) { myEvt.Attendees = new List<GenericAttendee>(); foreach (var attendee in evt.Attendees) { ResponseStatus r; switch (attendee.ResponseStatus) { case "accepted": r = ResponseStatus.Accepted; break; case "tentative": r = ResponseStatus.Tentative; break; case "needsAction": r = ResponseStatus.NotResponded; break; case "declined": r = ResponseStatus.Declined; break; default: r = ResponseStatus.None; break; } myEvt.Attendees.Add( new GenericAttendee { Email = attendee.Email, Name = attendee.DisplayName, Response = r } ); } } myEvts.Add(myEvt); } } catch (Exception ex) { Log.Error("Exception", ex); } return myEvts; }
public UserService(DbCollection<User> userCollection) { _userCollection = userCollection; }