public override void ViewDidLoad () { base.ViewDidLoad (); #if DEBUG debugServer = new Server(); debugServer.OnRequest += HandleDebugRequest; debugServer.Start("conversations"); debugGesture = new TapGestureAttacher (View, 3, ChangeThemeProps); // debugGesture = new TapGestureAttacher (View, 3, Theme.SetNextTheme); #endif Title = Strings.Chats.Title; //remove for now because we do on new friends list NavigationItem.BackBarButtonItem = new UIBarButtonItem (Strings.Chats.BackButtonTitle, UIBarButtonItemStyle.Plain, null, null); //NavigationItem.RightBarButtonItem.Clicked += OnFindNewPersonClicked; NavigationItem.RightBarButtonItem = null; viewModel = App.ConversationsViewModel; tableUpdater = new CollectionUpdater<Message> (viewModel.Conversations, messageCache); dataSource = new ConversationsDataSource (messageCache); TableView.Source = dataSource; TableView.SeparatorInset = UIEdgeInsets.Zero; TableView.RowHeight = 82; TableView.TableFooterView = new UIView (CGRect.Empty); InitPullToRefresh (); }
public void UpdateFrom(TodoList fromList) { base.UpdateFrom(fromList); Position = fromList.Position; CollectionUpdater <TodoListItem> .Update(Items, fromList.Items); }
public void UpdateFrom(TodoQuery fromQuery) { base.UpdateFrom(fromQuery); OrderBy = fromQuery.OrderBy; OrderByDirection = fromQuery.OrderByDirection; CollectionUpdater <TodoQueryPredicate> .Update(Predicates, fromQuery.Predicates); }
public void ShouldNotThrowIfCompareWithCalled() { Func <IEnumerable <Item> > func = () => { var sut = new CollectionUpdater <Item, Item>(new List <Item>(), new List <Item>()); return(sut .CompareWith((d, s) => d.Id == s.Id) .UpdateWith((d, s) => {}) .Execute()); }; func .Should() .NotThrow <MissingCompareFunctionException>(); }
public void UpdateFrom(DashboardDefinition fromDefinition) { base.UpdateFrom(fromDefinition); Columns = fromDefinition.Columns; RequestType = fromDefinition.RequestType; ValueAtTimeTarget = fromDefinition.ValueAtTimeTarget; if (fromDefinition.HistoryTimePeriod == null) { HistoryTimePeriod = null; } else { if (HistoryTimePeriod == null) { HistoryTimePeriod = new TimePeriod(); } HistoryTimePeriod.UpdateFrom(fromDefinition.HistoryTimePeriod); } CollectionUpdater <DashboardTile> .Update(Tiles, fromDefinition.Tiles); CollectionUpdater <DashboardSetting> .Update(Settings, fromDefinition.Settings); }
public IActionResult UpdateUserDetails([FromBody] UpdateUserRequest request) { if (request.Scopes.GroupBy(s => s, StringComparer.OrdinalIgnoreCase).Any(g => g.Count() > 1)) { throw new HttpStatusException(HttpStatusCode.BadRequest, "Duplicate scopes"); } var user = _dbContext.Users.Include(u => u.UserScopes).FirstOrDefault(u => u.AccountId == request.Id); if (user == null) { return(BadRequest(new ErrorResponse("User not found"))); } user.Name = request.Name; CollectionUpdater.UpdateCollection( user.UserScopes.ToDictionary(us => us.ScopeName, us => us, StringComparer.OrdinalIgnoreCase), request.Scopes.ToDictionary(s => s, s => s, StringComparer.OrdinalIgnoreCase), newScope => { _dbContext.UserScopes.Add(new DbUserScope { UserId = user.AccountId, ScopeName = newScope }); }, (existingScope, newScope) => { }, existingScope => { _dbContext.UserScopes.Remove(existingScope); } ); _dbContext.SaveChanges(); return(Ok()); }
private void FillDashboardDetails(DbDashboard existingDashboard, CreateDashboardRequest request) { if (request.Feedbacks == null) { request.Feedbacks = new List <CreateBotRequestFeedback>(); } if (request.Feedbacks.GroupBy(f => f.Id).Any(g => g.Count() > 1)) { throw new HttpStatusException(HttpStatusCode.BadRequest, "Duplicate feedback ids"); } if (request.ConflictExceptions == null) { request.ConflictExceptions = new List <CreateBotRequestExceptions>(); } if (request.ConflictExceptions.GroupBy(f => f.Id).Any(g => g.Count() > 1)) { throw new HttpStatusException(HttpStatusCode.BadRequest, "Duplicate conflict exception ids"); } ConflictHelper.AssertUniqueConflictFeedbacks(request.ConflictExceptions.Select(c => c.BotResponseConflictFeedbacks)); existingDashboard.BotName = request.BotName; existingDashboard.DashboardName = request.DashboardName; existingDashboard.Description = request.Description; if (!string.IsNullOrWhiteSpace(request.Secret)) { existingDashboard.Secret = BCrypt.Net.BCrypt.HashPassword(request.Secret); } if (request.OwnerAccountId.HasValue && User.HasClaim(Scopes.SCOPE_ADMIN)) { existingDashboard.OwnerAccountId = request.OwnerAccountId.Value; } existingDashboard.FavIcon = request.FavIcon; existingDashboard.Homepage = request.Homepage; existingDashboard.LogoUrl = request.LogoUrl; existingDashboard.TabTitle = request.TabTitle; existingDashboard.RequiredFeedback = request.RequiredFeedback; existingDashboard.RequiredFeedbackConflicted = request.RequiredFeedbackConflicted; var createdFeedbacks = new Dictionary <int, DbFeedback>(); CollectionUpdater.UpdateCollection( existingDashboard.Feedbacks.ToDictionary(f => f.Id, f => f), request.Feedbacks.ToDictionary(f => f.Id, f => f), newFeedback => { var dbFeedbackType = new DbFeedback { Dashboard = existingDashboard, Name = newFeedback.Name, Colour = newFeedback.Colour, Icon = newFeedback.Icon, IsActionable = newFeedback.IsActionable, IsEnabled = newFeedback.IsEnabled }; existingDashboard.Feedbacks.Add(dbFeedbackType); _dbContext.Feedbacks.Add(dbFeedbackType); createdFeedbacks.Add(newFeedback.Id, dbFeedbackType); }, (existingFeedback, newFeedback) => { existingFeedback.Name = newFeedback.Name; existingFeedback.Colour = newFeedback.Colour; existingFeedback.Icon = newFeedback.Icon; existingFeedback.IsActionable = newFeedback.IsActionable; existingFeedback.IsEnabled = newFeedback.IsEnabled; }, existingFeedback => { } ); if (existingDashboard.Feedbacks.GroupBy(f => f.Name, StringComparer.OrdinalIgnoreCase).Any(g => g.Count() > 1)) { throw new HttpStatusException(HttpStatusCode.BadRequest, "Feedback names must be unique"); } CollectionUpdater.UpdateCollection( existingDashboard.ConflictExceptions.ToDictionary(ce => ce.Id, ce => ce), request.ConflictExceptions.ToDictionary(ce => ce.Id, ce => ce), newConflict => { var dbConflictException = new DbConflictException { Dashboard = existingDashboard, IsConflict = newConflict.IsConflict, RequiresAdmin = newConflict.RequiresAdmin, RequiredFeedback = newConflict.RequiredFeedback }; foreach (var conflictFeedbackId in newConflict.BotResponseConflictFeedbacks) { var newConflictException = new DbConflictExceptionFeedback { ConflictException = dbConflictException }; if (conflictFeedbackId < 0) { if (createdFeedbacks.ContainsKey(conflictFeedbackId)) { newConflictException.Feedback = createdFeedbacks[conflictFeedbackId]; } else { throw new HttpStatusException(HttpStatusCode.BadRequest, "Invalid FeedbackId for conflict"); } } else { newConflictException.FeedbackId = conflictFeedbackId; } _dbContext.ConflictExceptionFeedbacks.Add(newConflictException); } existingDashboard.ConflictExceptions.Add(dbConflictException); _dbContext.ConflictExceptions.Add(dbConflictException); }, (existingConflict, newConflict) => { existingConflict.IsConflict = newConflict.IsConflict; existingConflict.RequiresAdmin = newConflict.RequiresAdmin; existingConflict.RequiredFeedback = newConflict.RequiredFeedback; CollectionUpdater.UpdateCollection( existingConflict.ConflictExceptionFeedbacks.ToDictionary(d => d.FeedbackId, d => d), newConflict.BotResponseConflictFeedbacks.ToDictionary(d => d, d => d), newConflictFeedbackId => { var newConflictException = new DbConflictExceptionFeedback { ConflictException = existingConflict }; if (newConflictFeedbackId < 0) { if (createdFeedbacks.ContainsKey(newConflictFeedbackId)) { newConflictException.Feedback = createdFeedbacks[newConflictFeedbackId]; } else { throw new HttpStatusException(HttpStatusCode.BadRequest, "Invalid FeedbackId for conflict"); } } else { newConflictException.FeedbackId = newConflictFeedbackId; } _dbContext.ConflictExceptionFeedbacks.Add(newConflictException); }, (existingConflictFeedback, newConflictFeedback) => { }, existingConflictFeedback => { _dbContext.ConflictExceptionFeedbacks.Remove(existingConflictFeedback); } ); }, existingConflict => { _dbContext.ConflictExceptions.Remove(existingConflict); } ); }
public void ConstructorTest() { _collectionUpdaterT = new CollectionUpdater<Entry>(_collectionUpdater); Assert.IsNotNull(_collectionUpdaterT); }
public void UpdateFrom(DashboardFolder fromEntity) { base.UpdateFrom(fromEntity); CollectionUpdater <DashboardDefinition> .Update(Definitions, fromEntity.Definitions); }
public async void Test() { _databaseConnection.Connect(); ///////////////////////////////////// // OPERATIONAL, CONTEXUAL SCOPE... // ///////////////////////////////////// // create a Writer to write to the database IWriter writer = new Writer(_databaseConnection); // create a Reader to read from the database IReader reader = new Reader(_databaseConnection); // create an Updater to update the database IUpdater updater = new Updater(_databaseConnection); Entry exampleMongoDBEntry = new Entry(); exampleMongoDBEntry.Message = "Hello"; // write the object to the "MyFirstCollection" Collection that exists within the // previously referenced "MyFirstDatabase" that was used to create the "writer" object writer.Write <Entry>("MyFirstCollection", exampleMongoDBEntry); IEnumerable <Entry> readEntrys = reader.Read <Entry>("MyFirstCollection", // within this collection... "Message", // for the object field "Description" "Hello"); // return matches for 'Hello' Assert.AreEqual(1, readEntrys.Count()); //////////////////////////////////// // AND ASYNCHRONOUS OPERATIONS... // //////////////////////////////////// // read, write and update asynchronously using System.Threading.Task IAsyncReader asyncReader = new AsyncReader(reader); readEntrys = await asyncReader.ReadAsync <Entry>("MyFirstCollection", "Message", "Hello"); Assert.AreEqual(1, readEntrys.Count()); IAsyncWriter asyncWriter = new AsyncWriter(writer); IAsyncUpdater asyncUpdater = new AsyncUpdater(updater); // or delegate call backs IAsyncDelegateReader asyncDelegateReader = new AsyncDelegateReader(reader); asyncDelegateReader.AsyncReadCompleted += new ReadCompletedEvent(readerCallBack); asyncDelegateReader.ReadAsync <Entry>("MyFirstCollection", "Message", "Hello"); _readerAutoResetEvent.WaitOne(); Assert.AreEqual(1, _asyncReadResults.Count()); IAsyncDelegateWriter asyncDelegateWriter = new AsyncDelegateWriter(writer); IAsyncDelegateUpdater asyncDelegateUpdater = new AsyncDelegateUpdater(updater); ///////////////////////////////////////////// // FOR A SERVER, DATABASE OR COLLECTION... // ///////////////////////////////////////////// // get a little higher level with the EasyMongo.Database namespace to target a database for operations IDatabaseReader databaseReader = new DatabaseReader(reader, asyncReader); IDatabaseWriter databaseWriter = new DatabaseWriter(writer, asyncWriter); IDatabaseUpdater databaseUpdater = new DatabaseUpdater(updater, asyncUpdater); // or a little lower level with the EasyMongo.Collection namespace to target a specific Collection ICollectionReader collectionReader = new CollectionReader(databaseReader, "MyFirstCollection"); ICollectionWriter collectionWriter = new CollectionWriter(databaseWriter, "MyFirstCollection"); ICollectionUpdater collectionUpdater = new CollectionUpdater(databaseUpdater, "MyFirstCollection"); /////////////////////////////////////////////// // TO RESTRICT CLIENT SCOPE (LAW OF DEMETER) // /////////////////////////////////////////////// // operate only against "MyFirstDatabase"'s "MySecondCollection" readEntrys = collectionReader.Read <Entry>("Message", "Hello"); Assert.AreEqual(1, readEntrys.Count()); ///////////////////// // GENERIC CLASSES // ///////////////////// // Instead of defining generic type arguments at the method level, // you can do it once at the class declaration IWriter <Entry> writerT = new Writer <Entry>(writer); writerT.Write("MySecondCollection", new Entry() { Message = "Goodbye World (Generically)" }); /////////////////////////////// // SIMPLIFY CREATION VIA IoC // /////////////////////////////// // because EasyMongo is a componentized framework built with blocks of functionality, EasyMongo // works great with DI containers and Inversion of Control. // here's an example of using the nuget Ninject extension to load EasyMongo mappings and a conn // string from configuration Ninject.IKernel kernel = new Ninject.StandardKernel(); ICollectionUpdater <Entry> collectionUpdaterT = kernel.TryGet <ICollectionUpdater <Entry> >(); // the alternative to this would be: IServerConnection serverConn = new ServerConnection(LOCAL_MONGO_SERVER_CONNECTION_STRING); IDatabaseConnection databaseConnn = new DatabaseConnection(serverConn, "MyFirstDatabase"); IDatabaseUpdater databaseUpdatr = new DatabaseUpdater(updater, asyncUpdater); ICollectionUpdater collectionUpdaterTheHardWay = new CollectionUpdater(databaseUpdater, "MySecondCollection"); ///////////////////////// // SIMPLE QUERIES... // ///////////////////////// databaseReader.Read <Entry>("MyFirstCollection", "Message", "Hello"); readEntrys = await databaseReader.ReadAsync <Entry>("MyFirstCollection", "Message", "Hello"); Assert.AreEqual(1, readEntrys.Count()); ///////////////////////// // POWERFUL QUERIES... // ///////////////////////// // when more robust querying is needed leverage power of underlying MongoDB driver IMongoQuery IMongoQuery query1 = Query.Matches("Message", new BsonRegularExpression("HE", "i")); IEnumerable <Entry> queryResults = reader.Execute <Entry>("MyFirstCollection", query1); Assert.AreEqual(1, queryResults.Count()); Assert.AreEqual("Hello", queryResults.ElementAt(0).Message); ////////////////////// // AND COMBINATIONS // ////////////////////// Entry exampleMongoDBEntry2 = new Entry(); exampleMongoDBEntry2.Message = "Hello Again"; Entry exampleMongoDBEntry3 = new Entry(); exampleMongoDBEntry3.Message = "Goodbye"; writer.Write <Entry>("MyFirstCollection", exampleMongoDBEntry2); writer.Write <Entry>("MyFirstCollection", exampleMongoDBEntry3); // "AND" multiple IMongoQueries... IMongoQuery query2 = Query.Matches("Message", new BsonRegularExpression("Again")); queryResults = reader.ExecuteAnds <Entry>("MyFirstCollection", new [] { query1, query2 }); Assert.AreEqual(1, queryResults.Count()); Assert.AreEqual("Hello Again", queryResults.ElementAt(0).Message); // "OR" multiple IMongoQueries... IMongoQuery query3 = Query.Matches("Message", new BsonRegularExpression("Goo")); queryResults = reader.ExecuteOrs <Entry>("MyFirstCollection", new[] { query1, query2, query3 }); Assert.AreEqual(3, queryResults.Count()); Assert.AreEqual("Hello", queryResults.ElementAt(0).Message); Assert.AreEqual("Hello Again", queryResults.ElementAt(1).Message); Assert.AreEqual("Goodbye", queryResults.ElementAt(2).Message); }
public void ConstructorTest() { _collectionUpdaterT = new CollectionUpdater <Entry>(_collectionUpdater); Assert.IsNotNull(_collectionUpdaterT); }
public async void Test() { _databaseConnection.Connect(); ///////////////////////////////////// // OPERATIONAL, CONTEXUAL SCOPE... // ///////////////////////////////////// // create a Writer to write to the database IWriter writer = new Writer(_databaseConnection); // create a Reader to read from the database IReader reader = new Reader(_databaseConnection); // create an Updater to update the database IUpdater updater = new Updater(_databaseConnection); Entry exampleMongoDBEntry = new Entry(); exampleMongoDBEntry.Message = "Hello"; // write the object to the "MyFirstCollection" Collection that exists within the // previously referenced "MyFirstDatabase" that was used to create the "writer" object writer.Write<Entry>("MyFirstCollection", exampleMongoDBEntry); IEnumerable<Entry> readEntrys = reader.Read<Entry>("MyFirstCollection", // within this collection... "Message",// for the object field "Description" "Hello");// return matches for 'Hello' Assert.AreEqual(1, readEntrys.Count()); //////////////////////////////////// // AND ASYNCHRONOUS OPERATIONS... // //////////////////////////////////// // read, write and update asynchronously using System.Threading.Task IAsyncReader asyncReader = new AsyncReader(reader); readEntrys = await asyncReader.ReadAsync<Entry>("MyFirstCollection", "Message", "Hello"); Assert.AreEqual(1, readEntrys.Count()); IAsyncWriter asyncWriter = new AsyncWriter(writer); IAsyncUpdater asyncUpdater = new AsyncUpdater(updater); // or delegate call backs IAsyncDelegateReader asyncDelegateReader = new AsyncDelegateReader(reader); asyncDelegateReader.AsyncReadCompleted += new ReadCompletedEvent(readerCallBack); asyncDelegateReader.ReadAsync<Entry>("MyFirstCollection", "Message", "Hello"); _readerAutoResetEvent.WaitOne(); Assert.AreEqual(1, _asyncReadResults.Count()); IAsyncDelegateWriter asyncDelegateWriter = new AsyncDelegateWriter(writer); IAsyncDelegateUpdater asyncDelegateUpdater = new AsyncDelegateUpdater(updater); ///////////////////////////////////////////// // FOR A SERVER, DATABASE OR COLLECTION... // ///////////////////////////////////////////// // get a little higher level with the EasyMongo.Database namespace to target a database for operations IDatabaseReader databaseReader = new DatabaseReader(reader, asyncReader); IDatabaseWriter databaseWriter = new DatabaseWriter(writer, asyncWriter); IDatabaseUpdater databaseUpdater = new DatabaseUpdater(updater, asyncUpdater); // or a little lower level with the EasyMongo.Collection namespace to target a specific Collection ICollectionReader collectionReader = new CollectionReader(databaseReader, "MyFirstCollection"); ICollectionWriter collectionWriter = new CollectionWriter(databaseWriter, "MyFirstCollection"); ICollectionUpdater collectionUpdater = new CollectionUpdater(databaseUpdater, "MyFirstCollection"); /////////////////////////////////////////////// // TO RESTRICT CLIENT SCOPE (LAW OF DEMETER) // /////////////////////////////////////////////// // operate only against "MyFirstDatabase"'s "MySecondCollection" readEntrys = collectionReader.Read<Entry>("Message", "Hello"); Assert.AreEqual(1, readEntrys.Count()); ///////////////////// // GENERIC CLASSES // ///////////////////// // Instead of defining generic type arguments at the method level, // you can do it once at the class declaration IWriter<Entry> writerT = new Writer<Entry>(writer); writerT.Write("MySecondCollection", new Entry() { Message = "Goodbye World (Generically)" }); /////////////////////////////// // SIMPLIFY CREATION VIA IoC // /////////////////////////////// // because EasyMongo is a componentized framework built with blocks of functionality, EasyMongo // works great with DI containers and Inversion of Control. // here's an example of using the nuget Ninject extension to load EasyMongo mappings and a conn // string from configuration Ninject.IKernel kernel = new Ninject.StandardKernel(); ICollectionUpdater<Entry> collectionUpdaterT = kernel.TryGet<ICollectionUpdater<Entry>>(); // the alternative to this would be: IServerConnection serverConn = new ServerConnection(LOCAL_MONGO_SERVER_CONNECTION_STRING); IDatabaseConnection databaseConnn = new DatabaseConnection(serverConn, "MyFirstDatabase"); IDatabaseUpdater databaseUpdatr = new DatabaseUpdater(updater, asyncUpdater); ICollectionUpdater collectionUpdaterTheHardWay = new CollectionUpdater(databaseUpdater, "MySecondCollection"); ///////////////////////// // SIMPLE QUERIES... // ///////////////////////// databaseReader.Read<Entry>("MyFirstCollection", "Message", "Hello"); readEntrys = await databaseReader.ReadAsync<Entry>("MyFirstCollection", "Message", "Hello"); Assert.AreEqual(1, readEntrys.Count()); ///////////////////////// // POWERFUL QUERIES... // ///////////////////////// // when more robust querying is needed leverage power of underlying MongoDB driver IMongoQuery IMongoQuery query1 = Query.Matches("Message", new BsonRegularExpression("HE", "i")); IEnumerable<Entry> queryResults = reader.Execute<Entry>("MyFirstCollection", query1); Assert.AreEqual(1, queryResults.Count()); Assert.AreEqual("Hello", queryResults.ElementAt(0).Message); ////////////////////// // AND COMBINATIONS // ////////////////////// Entry exampleMongoDBEntry2 = new Entry(); exampleMongoDBEntry2.Message = "Hello Again"; Entry exampleMongoDBEntry3 = new Entry(); exampleMongoDBEntry3.Message = "Goodbye"; writer.Write<Entry>("MyFirstCollection", exampleMongoDBEntry2); writer.Write<Entry>("MyFirstCollection", exampleMongoDBEntry3); // "AND" multiple IMongoQueries... IMongoQuery query2 = Query.Matches("Message", new BsonRegularExpression("Again")); queryResults = reader.ExecuteAnds<Entry>("MyFirstCollection", new []{ query1, query2}); Assert.AreEqual(1, queryResults.Count()); Assert.AreEqual("Hello Again", queryResults.ElementAt(0).Message); // "OR" multiple IMongoQueries... IMongoQuery query3 = Query.Matches("Message", new BsonRegularExpression("Goo")); queryResults = reader.ExecuteOrs<Entry>("MyFirstCollection", new[] { query1, query2, query3 }); Assert.AreEqual(3, queryResults.Count()); Assert.AreEqual("Hello", queryResults.ElementAt(0).Message); Assert.AreEqual("Hello Again", queryResults.ElementAt(1).Message); Assert.AreEqual("Goodbye", queryResults.ElementAt(2).Message); }