/// <summary> /// Import a single tip group. Parse all the tips declared in the group. Sort them by priority. /// </summary> private void ProcessTipGroup(ITipGroupProvider tipGroupProvider, TipGroup tipGroup, Dictionary <string, TipInfo> newTips) { // Create a new GroupOfTips for the tip group being processed GroupOfTips groupOfTips = GroupOfTips.Create(tipGroup); foreach (Tip tip in tipGroup.tips) { // Generate the tip content URI (from the provider) string tipContentUri = tipGroupProvider.GetTipPath(tip.content); tip.content = tipContentUri; // Add the TipInfo to the groupOfTips TipInfo tipInfo = TipInfo.Create(tipGroup, tip, tipContentUri); AddTipToPriListOfTips(groupOfTips, tipInfo); // Also add to the AllTips lookup dictionary newTips.Add(tipInfo.globalTipId, tipInfo); } // Build an ordered tips list (based on priority) List <string> tipsList = CreateSortedTipsList(groupOfTips.TipsPriList); groupOfTips.TipsSorted = tipsList; // Add the TipGroup to the correct PriList of ordered Groups (GroupsPriList) AddTipGroupToGroupsPriList(groupOfTips, tipGroup.groupPriority); // Add the TipGroup to the AllGroups lookup AddTipGroupToAllGroupsSet(groupOfTips); }
private void AddTipGroupToAllGroupsSet(GroupOfTips groupOfTips) { if (_allGroups == null) { _allGroups = new List <GroupOfTips>(); } _allGroups.Add(groupOfTips); }
private void AddTipToPriListOfTips(GroupOfTips groupOfTips, TipInfo tipInfo) { // Add Tip to the correct prioritized tip list within the groupOfTips int tipPriority = tipInfo.priority; List <TipInfo> tipList = groupOfTips.TipsPriList[tipPriority - 1]; // Initialize the tipList if required if (tipList == null) { tipList = new List <TipInfo>(); groupOfTips.TipsPriList[tipPriority - 1] = tipList; } tipList.Add(tipInfo); }
private void AddTipGroupToGroupsPriList(GroupOfTips groupOfTips, int groupPriority) { // Initialze GroupsPriList if required if (_groupsPriList == null) { _groupsPriList = new List <GroupOfTips> [3]; } List <GroupOfTips> groupsList = _groupsPriList[groupPriority - 1]; // Initialize groupsList if required if (groupsList == null) { groupsList = new List <GroupOfTips>(); _groupsPriList[groupPriority - 1] = groupsList; } groupsList.Add(groupOfTips); }
private List <GroupOfTips>[] GenerateTestTipGroups() { // Create GroupOfTips GroupOfTips generalGroup = new GroupOfTips { groupId = "General", groupPriority = 1 }; GroupOfTips editorGroup = new GroupOfTips { groupId = "Editor", groupPriority = 2 }; List <TipInfo>[] generalItems = SetupGroupOfTips("General", new string[] { "GN001" }); generalGroup.TipsPriList = generalItems; List <TipInfo>[] editorItems = SetupGroupOfTips("Editor", new string[] { "ED001", "ED002" }, new string[] { "ED003" }); editorGroup.TipsPriList = editorItems; List <GroupOfTips>[] list = new List <GroupOfTips> [3]; list[0] = new List <GroupOfTips> { generalGroup }; list[1] = new List <GroupOfTips> { editorGroup }; return(list); }
public TipInfo GetNextTipInGroup(string globalTipId) { // Get groupId and tipId of current tip string currentGroupId = TipInfo.GetGroupId(globalTipId); string currentTipId = TipInfo.GetTipId(globalTipId); // See if there is a further tip later in the list GroupOfTips currentGroup = _allGroups.Find(x => x.groupId == currentGroupId); List <string> tips = currentGroup.TipsSorted; int currentTipIndex = tips.IndexOf(currentTipId); int nextTipIndex = currentTipIndex + 1; if (nextTipIndex >= tips.Count) { // There are no more tips in this group Debug.WriteLine($"Tip of the Day: There are no more tips in tip group '{currentGroupId}' after tip '{globalTipId}'"); return(null); } // We have a tip. Fetch it and return it. string nextTipId = tips[nextTipIndex]; return(_allTips[TipInfo.GetGlobalTipId(currentGroupId, nextTipId)]); }