/// <summary> /// Populate the sub entities of thingList /// </summary> /// <param name="things"></param> /// <param name="toPopulate"></param> public override void Populate(IEnumerable <Thing> things, Flags toPopulate) { Log("Populate", things.GetIdenties(), toPopulate); // Implement breadth first loading of related entities. // Any entity that has been requested to be loaded, should be loaded at this level where possible. // Remove all sub entity types that this entity relates to directly. Flags stillToPopulate = toPopulate; stillToPopulate = stillToPopulate.Remove(EntityType.Widget); // Get sub entities: Widget if ((toPopulate & EntityType.Widget) == EntityType.Widget) { // Grab the ones that actually need populating IEnumerable <Thing> toBePopulated = things.Where(entity => entity.WidgetListPopulated == false); // And load the sub entities for those ones. WidgetList childWidgetList = toBePopulated.Count() > 0 ? WidgetRepo.GetByThingId( toBePopulated.GetIdenties(), stillToPopulate) : new WidgetList(); Dictionary <int, List <Widget> > widgetListByThingId = childWidgetList.MapByThingId; // Now go over all the entites. For ones that need popualting, populate collection // directly. For those already populated, make a check on sub entities to ensure // they are loaded to the required level WidgetList toBeChecked = new WidgetList(); foreach (Thing thing in things) { if (!thing.WidgetListPopulated) { var WidgetListsForThing = widgetListByThingId.ContainsKey(thing.Identity) ? widgetListByThingId[thing.Identity] : null; if (WidgetListsForThing != null) { WidgetListsForThing.ForEach(entity => entity.Thing = thing); } thing.PopulateWidgetList(WidgetListsForThing); } else { toBeChecked.AddRange(thing.WidgetList); } } // If there's any "to be checked" (because they were already loaded) let the entities own // repo do whatever checks it needs to do if (toBeChecked.Count > 0) { WidgetRepo.Populate(toBeChecked, stillToPopulate); } } }
/// <summary> /// load all widgets/groups which is not in a group in current page. /// which means,only load top level widget/group. /// </summary> public void LoadPageWidgets() { if (_selectedWidget == null || _widgetShowHideAction == null) { DisableInteraction(); return; } WidgetList.Clear(); List <IWidgetPropertyData> allWidgets = SelectionService.GetCurrentPage().GetAllWidgets(); List <WidgetNode> TargetWidgets = new List <WidgetNode>(); foreach (IWidgetPropertyData it in allWidgets.Where(x => x.IsGroup == false)) { WidgetViewModBase wdg = it as WidgetViewModBase; if (wdg == null) { continue; } // load widget that is not in a group . if ((wdg.ParentID == Guid.Empty)) { bool bChecked = false; IRegion targetObject = wdg.WidgetModel.WdgDom; if (targetObject == null) { break; } //if the widget is already checked. var selWidget = _widgetShowHideAction.TargetObjects.FirstOrDefault(x => x.Guid == targetObject.Guid); if (selWidget != null) { bChecked = true; } TargetWidgets.Add(new WidgetNode(this, targetObject, wdg.Type, bChecked)); } } //load all groups. foreach (IGroup group in _currentPage.Groups) { bool bChecked = false; var selGroup = _widgetShowHideAction.TargetObjects.FirstOrDefault(x => x.Guid == group.Guid); if (selGroup != null) { bChecked = true; } TargetWidgets.Add(new WidgetNode(this, group, ObjectType.Group, bChecked)); } _isCheckAll = !TargetWidgets.Any(x => x.IsSelected == false); WidgetList.AddRange(TargetWidgets); FirePropertyChanged("IsCheckAll"); FirePropertyChanged("ShowHideType"); FirePropertyChanged("AnimateType"); FirePropertyChanged("AnimateTime"); FirePropertyChanged("IsShowHideEnabled"); }