Beispiel #1
0
        private void AddChildren(FeatureDescription feature, Dictionary<string, List<FeatureDescription>> childRepository)
        {
            var strippedTitle = feature.Title.Replace(" ", String.Empty);

            if (childRepository.ContainsKey(strippedTitle))
            {
                feature.ChildFeatures = childRepository[strippedTitle];
                childRepository[strippedTitle].ForEach(f => AddChildren(f, childRepository));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets groups containing the descriptions for all features for the specified branch.
        /// </summary>
        /// <param name="productName">The name of the product for which the feature descriptions should be retrieved.</param>
        /// <param name="tagFilters">An optional set of tag which can be used to filter the results.</param>
        /// <returns>An enumerable collection of <see cref="Group"/> instances.</returns>
        public async Task<IEnumerable<Group>> GetGroupedFeatureDescriptionsAsync(string productName)
        {
            Dictionary<string, List<FeatureDescription>> featureDescriptions = new Dictionary<string, List<FeatureDescription>>();
            Dictionary<string, Group> groups = new Dictionary<string, Group>();

            using (var session = Database.DocumentStore.OpenAsyncSession())
            {
                var data = await session.Query<DbFeature, Features_ByTitleProductAndGroup>()
                                        .Where(feature => feature.Product.Equals(productName, StringComparison.OrdinalIgnoreCase))
                                        .Select(feature =>
                                                new
                                                {
                                                    feature.Group,
                                                    feature.ParentTitle,
                                                    feature.Title,
                                                    feature.Version
                                                })
                                        .Take(1000)
                                        .ToListAsync();

                foreach (var uniqueFeature in data.GroupBy(record => record.Title))
                {
                    var latestFeature = uniqueFeature.OrderByDescending(record => record.Version, new SemanticVersionComparer()).First();
                    var featureDescription = new FeatureDescription()
                    {
                        Title = uniqueFeature.Key,
                        LatestVersion = latestFeature.Version,
                    };

                    if (String.IsNullOrWhiteSpace(latestFeature.ParentTitle))
                    {
                        if (!groups.ContainsKey(latestFeature.Group))
                        {
                            // Create a new group
                            groups.Add(latestFeature.Group, new Group()
                            {
                                Name = latestFeature.Group,
                                Features = new List<FeatureDescription>()
                            });
                        }

                        // Add the feature to the group
                        ((List<FeatureDescription>)groups[latestFeature.Group].Features).Add(featureDescription);
                    }
                    else
                    {
                        if (!featureDescriptions.ContainsKey(latestFeature.ParentTitle))
                        {
                            featureDescriptions.Add(latestFeature.ParentTitle, new List<FeatureDescription>());
                        }

                        featureDescriptions[latestFeature.ParentTitle].Add(featureDescription);
                    }
                }

                // Map the lower levels
                foreach (var feature in groups.Values.SelectMany(group => group.Features))
                {
                    AddChildren(feature, featureDescriptions);
                }
            }

            return groups.Values.OrderBy(group => group.Name).ToList();
        }