Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
 public static GroupOfTips Create(TipGroup tipGroup)
 {
     return(new GroupOfTips
     {
         groupId = tipGroup.groupId,
         groupName = tipGroup.groupName,
         groupPriority = tipGroup.groupPriority,
         TipsPriList = new List <TipInfo> [3]
     });
 }
Esempio n. 3
0
        public static TipInfo Create(TipGroup tipGroup, Tip tip, string tipContentUri)
        {
            TipInfo tipInfo = new TipInfo
            {
                tipId         = tip.tipId,
                name          = tip.name,
                priority      = tip.priority,
                contentUri    = tipContentUri,
                groupId       = tipGroup.groupId,
                groupName     = tipGroup.groupName,
                groupPriority = tipGroup.groupPriority,
                globalTipId   = GetGlobalTipId(tipGroup.groupId, tip.tipId)
            };

            return(tipInfo);
        }
Esempio n. 4
0
        public static TipInfo Create(TipGroup tipGroup, Tip tip, string tipContentUri)
        {
            TipInfo tipInfo = new TipInfo
            {
                tipId         = tip.tipId,
                name          = tip.name,
                priority      = tip.priority,
                contentUri    = tipContentUri,
                groupId       = tipGroup.groupId,
                groupName     = tipGroup.groupName,
                groupPriority = tipGroup.groupPriority,
                globalTipId   = GetGlobalTipId(tipGroup.groupId, tip.tipId),
                Level         = tip.level,
                TipLikeStatus = TipLikeEnum.NORMAL
            };

            return(tipInfo);
        }
Esempio n. 5
0
        /// <summary>
        /// Top level Tip Group Process. Import all groups from all group providers.
        /// </summary>
        private void ProcessTipGroupProviders()
        {
            var newTips = new Dictionary <string, TipInfo>();

            // Get all tip group providers
            IEnumerable <ITipGroupProvider> tipGroupProviders = GetTipGroupProviders();

            foreach (ITipGroupProvider tipGroupProvider in tipGroupProviders)
            {
                List <string> groupFiles = tipGroupProvider.GetGroupDefinitions();
                // Parse each tip group
                foreach (string groupFile in groupFiles)
                {
                    // Read the group. Parse all tips. Create a TipGroup object with PriList of ordered Tips.

                    // Check that the groupFile exists
                    Debug.WriteLine($"Reading tip group: {groupFile}");
                    if (!File.Exists(groupFile))
                    {
                        // Unable to read group file from disc. Bail out.
                        Debug.WriteLine($"Unable to read tip group JSON file from disc: {groupFile}");
                        continue;
                    }

                    Debug.WriteLine($"Found file: {groupFile}");

                    // A groupFile is the file path of a JSON file that defines the tips for a group
                    // Parse the group file and extract a TipGroup object with a list of Tips
                    string   jsonString = GetJsonStringFromFile(groupFile);
                    TipGroup tipGroup   = JsonConvert.DeserializeObject <TipGroup>(jsonString);

                    ProcessTipGroup(tipGroupProvider, tipGroup, newTips);
                }
            }

            // Update the allTips list
            _allTips = newTips;
        }