public void MovedTo(ref CoinViewComponent view, ExclusiveGroupStruct previousGroup, EGID egid) { var mapper = entitiesDB.QueryMappedEntities <GridCellComponent>(GridGroups.GridWaterGroup); // Free the corresponding grid cell when a coin gets recycled. if (egid.groupID == CoinGroups.RecycledCoinsGroup) { var cellId = new EGID(_gridUtils.WorldToEnitityId(view.Transform.Position.xy), GridGroups.GridWaterGroup); if (entitiesDB.Exists <GridCellComponent>(cellId) == false) { return; } _freeCellFilter.Add(cellId.entityID, mapper); } else if (egid.groupID == CoinGroups.SpawnedCoinsGroup) { var cellId = new EGID(_gridUtils.WorldToEnitityId(view.Transform.Position.xy), GridGroups.GridWaterGroup); if (entitiesDB.Exists <GridCellComponent>(cellId) == false) { return; } _freeCellFilter.Remove(cellId.entityID); } }
public void Test_IsMatch_And_True() { TestArticle article = new TestArticle(); article.ID = Guid.NewGuid(); article.Title = "Article1"; FilterGroup group = new FilterGroup(); PropertyFilter filter1 = new PropertyFilter(); filter1.AddType(typeof(TestArticle)); filter1.PropertyName = "Title"; filter1.PropertyValue = article.Title; Assert.IsTrue(filter1.IsMatch(article), "filter1 failed to match article when it should."); PropertyFilter filter2 = new PropertyFilter(); filter2.AddType(typeof(TestArticle)); filter2.PropertyName = "ID"; filter2.PropertyValue = article.ID; Assert.IsTrue(filter2.IsMatch(article), "filter2 failed to match article when it should."); group.Add(filter1); group.Add(filter2); Assert.IsTrue(group.IsMatch(article), "group failed to match when it should"); }
public void Test_IsMatch_Or_True_OneMatches() { TestArticle article = new TestArticle(); article.ID = Guid.NewGuid(); article.Title = "Article1"; FilterGroup group = new FilterGroup(); group.Operator = FilterGroupOperator.Or; PropertyFilter filter1 = new PropertyFilter(); filter1.AddType(typeof(TestArticle)); filter1.PropertyName = "Title"; filter1.PropertyValue = article.Title; Assert.IsTrue(filter1.IsMatch(article), "filter1 failed to match article when it should."); PropertyFilter filter2 = new PropertyFilter(); filter2.AddType(typeof(TestArticle)); filter2.PropertyName = "Title"; filter2.PropertyValue = "MISMATCH"; // This one should fail Assert.IsFalse(filter2.IsMatch(article), "filter2 matched when it should fail."); group.Add(filter1); group.Add(filter2); Assert.IsTrue(group.IsMatch(article), "group failed when it should match"); }
private async Task <IEnumerable <BlogViewModel> > LoadAll() { var result = new List <BlogViewModel>(); var filterRules = new FilterCondition(); if (SelectedCategories.IsNotNullOrEmpty()) { var filterCategories = new FilterGroup(); foreach (var category in SelectedCategories) { filterCategories.Add(new FilterRule { Field = "CategoryId", FilterOperator = FilterOperator.Equal, PropertyValues = new List <object> { Guid.Parse(category) }, LogicalOperator = LogicalOperator.Or }); } filterRules.Add(filterCategories); } if (SearchText.IsNotNullOrEmpty()) { var filterGroup = new FilterGroup() { LogicalOperator = LogicalOperator.And }; filterGroup.Add(new FilterRule("Title", FilterOperator.Contains, LogicalOperator.Or, SearchText)); filterGroup.Add(new FilterRule("Summary", FilterOperator.Contains, LogicalOperator.Or, SearchText)); filterGroup.Add(new FilterRule("MarkdownContent", FilterOperator.Contains, LogicalOperator.Or, SearchText)); filterRules.Add(filterGroup); } var pageQuery = new PagingQuery { Pagination = new Pagination { PageNumber = PageNumber, PageSize = PageSize, }, FilterCondition = filterRules }; var entities = await _dataAdminService.GetPagedArticles(pageQuery); Total = entities.TotalRecords; if (entities.Count > 0) { var viewModels = AppRuntimeContext.Current.Adapt <List <BlogViewModel> >(entities); result.AddRange(viewModels); } // await Task.Delay(1000 * 3); return(result); }
public void Test_GetEntitiesByFilterGroup_ReferenceFilterAndPropertyFilter() { using (LogGroup logGroup = LogGroup.Start("Testing a simple query with the PropertyFilter.", NLog.LogLevel.Debug)) { TestUser user = new TestUser(); user.ID = Guid.NewGuid(); user.FirstName = "Test"; user.LastName = "User"; user.Username = "******"; TestRole role = new TestRole(); role.ID = Guid.NewGuid(); role.Name = "Test role"; user.Roles = new TestRole[] { role }; DataAccess.Data.Saver.Save(role); DataAccess.Data.Saver.Save(user); ReferenceFilter filter = (ReferenceFilter)DataAccess.Data.CreateReferenceFilter(); filter.PropertyName = "Roles"; filter.ReferencedEntityID = role.ID; filter.ReferenceType = role.GetType(); filter.AddType(typeof(TestUser)); PropertyFilter filter2 = (PropertyFilter)DataAccess.Data.CreatePropertyFilter(); filter2.PropertyName = "Username"; filter2.PropertyValue = user.Username; filter2.AddType(typeof(TestUser)); FilterGroup filterGroup = new FilterGroup(); filterGroup.Add(filter); filterGroup.Add(filter2); IEntity[] found = (IEntity[])DataAccess.Data.Indexer.GetEntities(filterGroup); Assert.IsNotNull(found, "Null value returned"); if (found != null) { Assert.IsTrue(found.Length > 0, "No results found."); if (found.Length > 0) { TestUser foundUser = (TestUser)found[0]; Assert.IsNotNull(foundUser, "foundUser == null"); Assert.AreEqual(user.ID, foundUser.ID, "The IDs don't match."); } } } }
public void Test_IsMatch_2SubGroups_True() { TestArticle article = new TestArticle(); article.ID = Guid.NewGuid(); article.Title = "Article1"; // Outer group FilterGroup group = new FilterGroup(); group.Operator = FilterGroupOperator.And; // BOTH child groups MUST match FilterGroup subGroup1 = new MockMatchingFilterGroup(); FilterGroup subGroup2 = new MockMatchingFilterGroup(); group.Add(subGroup1); group.Add(subGroup2); Assert.IsTrue(subGroup1.IsMatch(article), "First sub group doesn't match when it should."); Assert.IsTrue(subGroup2.IsMatch(article), "Second sub group doesn't match when it should."); Assert.IsTrue(group.IsMatch(article), "Entire group failed to match."); }
public void Test_GetEntitiesByFilterGroup_ReferenceFilterAndPropertyFilter() { using (LogGroup logGroup = LogGroup.Start("Testing a simple query with the PropertyFilter.", NLog.LogLevel.Debug)) { TestUser user = new TestUser(); user.ID = Guid.NewGuid(); user.FirstName = "Test"; user.LastName = "User"; user.Username = "******"; TestRole role = new TestRole(); role.ID = Guid.NewGuid(); role.Name = "Test role"; user.Roles = new TestRole[]{role}; DataAccess.Data.Saver.Save(role); DataAccess.Data.Saver.Save(user); ReferenceFilter filter = (ReferenceFilter)DataAccess.Data.CreateReferenceFilter(); filter.PropertyName = "Roles"; filter.ReferencedEntityID = role.ID; filter.ReferenceType = role.GetType(); filter.AddType(typeof(TestUser)); PropertyFilter filter2 = (PropertyFilter)DataAccess.Data.CreatePropertyFilter(); filter2.PropertyName = "Username"; filter2.PropertyValue = user.Username; filter2.AddType(typeof(TestUser)); FilterGroup filterGroup = new FilterGroup(); filterGroup.Add(filter); filterGroup.Add(filter2); IEntity[] found = (IEntity[])DataAccess.Data.Indexer.GetEntities(filterGroup); Assert.IsNotNull(found, "Null value returned"); if (found != null) { Assert.IsTrue(found.Length > 0, "No results found."); if (found.Length > 0) { TestUser foundUser = (TestUser)found[0]; Assert.IsNotNull(foundUser, "foundUser == null"); Assert.AreEqual(user.ID, foundUser.ID, "The IDs don't match."); } } } }
/// <summary> /// Adds Expression /// </summary> /// <param name="expression"></param> /// <returns></returns> public DbQuery Add(DbFilterNode expression) { FilterGroup.Add(expression); return(this); }