コード例 #1
0
        private IEnumerable <NavigationNode> GetTargetItemNavigationNodes(SPWeb web, NavigationQueryParameters queryParameters, IEnumerable <NavigationNode> nodes)
        {
            // Adds the filter for each first level navigation term id
            var targetItemFilters = new List <string>();
            var additionalFilters = new List <string>(queryParameters.SearchSettings.TargetItemFilters ?? new string[] { });

            foreach (var node in nodes)
            {
                targetItemFilters.Add(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "{0}:#{1:D}",
                        queryParameters.SearchSettings.NavigationManagedPropertyName,
                        node.Id));
            }

            if (targetItemFilters.Count > 0)
            {
                var filterAsOrStatement = string.Format(
                    CultureInfo.InvariantCulture,
                    "({0})",
                    string.Join(" OR ", targetItemFilters));

                additionalFilters.Add(filterAsOrStatement);
            }

            return(this.GetNavigationNodesBySearch(web, queryParameters.SearchSettings, additionalFilters));
        }
コード例 #2
0
ファイル: NavigationService.cs プロジェクト: ASAGARG/Dynamite
        /// <summary>
        /// Gets all the navigation terms.
        /// </summary>
        /// <param name="web">The Current web</param>
        /// <param name="queryParameters">The navigation query parameters.</param>
        /// <returns>
        /// List of navigation node.
        /// </returns>
        public IEnumerable<NavigationNode> GetAllNavigationNodes(SPWeb web, NavigationQueryParameters queryParameters)
        {
            try
            {
                // Use the monitored scope to trace the execution time
                using (new SPMonitoredScope("GSoft.Dynamite.NavigationService::GetAllNavigationNodes"))
                {
                    // Get navigation terms from taxonomy
                    var navigationNodes = this.GetGlobalNavigationTaxonomyNodes(web);

                    // Make sure the nodes are not null
                    if (navigationNodes.Any(node => node != null))
                    {
                        // If specified, filter to the restricted term set
                        if (!queryParameters.RestrictedTermSetId.Equals(Guid.Empty))
                        {
                            navigationNodes = this.FilterNavigationNodesToRestrictedTermSet(web, queryParameters.RestrictedTermSetId, navigationNodes);
                        }

                        // If match settings are defined
                        if (queryParameters.NodeMatchingSettings != null)
                        {
                            // If specified, filter the navigation nodes to only the ones who are reacheable
                            // (i.e.) The nodes that have a target item search result
                            if (queryParameters.NodeMatchingSettings.RestrictToReachableTargetItems)
                            {
                                var targetItemNodes = this.GetTargetItemNavigationNodes(web, queryParameters, navigationNodes);
                                navigationNodes = this.FilterNavigationNodesToReacheableTargetItems(navigationNodes, targetItemNodes);
                            }

                            // If specified, include the catalog items from the search
                            if (queryParameters.NodeMatchingSettings.IncludeCatalogItems)
                            {
                                // Get catalog items from search
                                var catalogItemNavigationNodes = this.GetCatalogItemNavigationNodes(web, queryParameters);

                                // Map navigation terms to node object, including search items
                                navigationNodes = this.MapNavigationNodeTree(navigationNodes, catalogItemNavigationNodes);
                            }
                        }

                        this.logger.Info("GetAllNavigationNodes: Found {0} navigation nodes (including children).", navigationNodes.Flatten(n => n.ChildNodes).Count());
                    }

                    return navigationNodes;
                }
            }
            catch (Exception ex)
            {
                this.logger.Error("GetAllNavigationNodes: {0}", ex.Message);
                throw;
            }
        }
コード例 #3
0
        /// <summary>
        /// Gets all the navigation terms.
        /// </summary>
        /// <param name="web">The Current web</param>
        /// <param name="queryParameters">The navigation query parameters.</param>
        /// <returns>
        /// List of navigation node.
        /// </returns>
        public IEnumerable <NavigationNode> GetAllNavigationNodes(SPWeb web, NavigationQueryParameters queryParameters)
        {
            try
            {
                // Use the monitored scope to trace the execution time
                using (new SPMonitoredScope("GSoft.Dynamite.NavigationService::GetAllNavigationNodes"))
                {
                    // Get navigation terms from taxonomy
                    var navigationNodes = this.GetGlobalNavigationTaxonomyNodes(web, queryParameters);

                    // Make sure the nodes are not null
                    if (navigationNodes.Any(node => node != null))
                    {
                        // If specified, filter to the restricted term set
                        if (!queryParameters.RestrictedTermSetId.Equals(Guid.Empty))
                        {
                            navigationNodes = this.FilterNavigationNodesToRestrictedTermSet(web, queryParameters, navigationNodes);
                        }

                        // If match settings are defined
                        if (queryParameters.NodeMatchingSettings != null)
                        {
                            // If specified, filter the navigation nodes to only the ones who are reacheable
                            // (i.e.) The nodes that have a target item search result
                            if (queryParameters.NodeMatchingSettings.RestrictToReachableTargetItems)
                            {
                                var targetItemNodes = this.GetTargetItemNavigationNodes(web, queryParameters, navigationNodes);
                                navigationNodes = this.FilterNavigationNodesToReacheableTargetItems(navigationNodes, targetItemNodes);
                            }

                            // If specified, include the catalog items from the search
                            if (queryParameters.NodeMatchingSettings.IncludeCatalogItems)
                            {
                                // Get catalog items from search
                                var catalogItemNavigationNodes = this.GetCatalogItemNavigationNodes(web, queryParameters);

                                // Map navigation terms to node object, including search items
                                navigationNodes = this.MapNavigationNodeTree(navigationNodes, catalogItemNavigationNodes);
                            }
                        }

                        this.logger.Info("GetAllNavigationNodes: Found {0} navigation nodes (including children).", navigationNodes.Flatten(n => n.ChildNodes).Count());
                    }

                    return(navigationNodes);
                }
            }
            catch (Exception ex)
            {
                this.logger.Error("GetAllNavigationNodes: {0}", ex.Message);
                throw;
            }
        }
コード例 #4
0
        /// <summary>
        /// Gets all navigation nodes based on the navigation query parameters.
        /// </summary>
        /// <param name="queryParameters">The query parameters.</param>
        /// <returns>A hierarchy of navigation nodes.</returns>
        public IEnumerable<NavigationNode> GetAllNavigationNodes(NavigationQueryParameters queryParameters)
        {
            INavigationService navigationService;
            SPWeb currentWeb = SPContext.Current.Web;

            using (var scope = DynamiteWspContainerProxy.BeginLifetimeScope(currentWeb))
            {
                navigationService = scope.Resolve<INavigationService>();
            }

            return navigationService.GetAllNavigationNodes(currentWeb, queryParameters);
        }
コード例 #5
0
ファイル: NavigationService.cs プロジェクト: ASAGARG/Dynamite
        private IEnumerable<NavigationNode> GetTargetItemNavigationNodes(SPWeb web, NavigationQueryParameters queryParameters, IEnumerable<NavigationNode> nodes)
        {
            // Adds the filter for each first level navigation term id
            var targetItemFilters = new List<string>();
            var additionalFilters = new List<string>(queryParameters.SearchSettings.TargetItemFilters);
            foreach (var node in nodes)
            {
                targetItemFilters.Add(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "{0}:#{1:D}",
                        queryParameters.SearchSettings.NavigationManagedPropertyName,
                        node.Id));
            }

            if (targetItemFilters.Count > 0)
            {
                var filterAsOrStatement = string.Format(
                    CultureInfo.InvariantCulture,
                    "({0})",
                    string.Join(" OR ", targetItemFilters));

                additionalFilters.Add(filterAsOrStatement);
            }

            return this.GetNavigationNodesBySearch(web, queryParameters.SearchSettings, additionalFilters);
        }
コード例 #6
0
ファイル: NavigationService.cs プロジェクト: ASAGARG/Dynamite
 private IEnumerable<NavigationNode> GetCatalogItemNavigationNodes(SPWeb web, NavigationQueryParameters queryParameters)
 {
     return this.GetNavigationNodesBySearch(web, queryParameters.SearchSettings, queryParameters.SearchSettings.CatalogItemFilters);
 }
コード例 #7
0
 private IEnumerable <NavigationNode> GetCatalogItemNavigationNodes(SPWeb web, NavigationQueryParameters queryParameters)
 {
     return(this.GetNavigationNodesBySearch(web, queryParameters.SearchSettings, queryParameters.SearchSettings.CatalogItemFilters));
 }
コード例 #8
0
        private IEnumerable <NavigationNode> FilterNavigationNodesToRestrictedTermSet(SPWeb web, NavigationQueryParameters queryParameters, IEnumerable <NavigationNode> nodes, Term[] restrictedTerms = null)
        {
            // If first pass, initialize the restricted nodes with first level terms
            if (restrictedTerms == null)
            {
                // Get restricted term set
                var       session   = new TaxonomySession(web.Site);
                TermStore termStore = null;

                if (queryParameters.TermStoreId == Guid.Empty)
                {
                    termStore = this.taxonomyHelper.GetDefaultSiteCollectionTermStore(session);
                }
                else
                {
                    termStore = session.TermStores[queryParameters.TermStoreId];
                }

                var termSet = termStore.GetTermSet(queryParameters.RestrictedTermSetId);

                var nodeMatchingSettings = queryParameters.NodeMatchingSettings;
                if ((nodeMatchingSettings != null) && nodeMatchingSettings.RestrictToCurrentNavigationLevel)
                {
                    var currentTermId = TaxonomyNavigationContext.Current.NavigationTerm.Id;
                    restrictedTerms = termSet.GetTerm(currentTermId).Parent.Terms.ToArray();
                }
                else
                {
                    restrictedTerms = termSet.Terms.ToArray();
                }
            }

            // Flattened navigation nodes for easier search
            var flattenedNodes  = nodes.Flatten(node => node.ChildNodes);
            var restrictedNodes = restrictedTerms.Select(term => flattenedNodes.SingleOrDefault(node => node.Id.Equals(term.Id))).ToArray();

            for (var i = 0; i < restrictedTerms.Length; i++)
            {
                var restrictedTerm = restrictedTerms[i];
                var restrictedNode = restrictedNodes[i];

                // If term contains children, recurvise call
                if (restrictedTerm.Terms.Count > 0)
                {
                    restrictedNode.ChildNodes = this.FilterNavigationNodesToRestrictedTermSet(web, queryParameters, nodes, restrictedTerm.Terms.ToArray());
                }
                else
                {
                    restrictedNode.ChildNodes = new List <NavigationNode>();
                }
            }

            return(restrictedNodes);
        }
コード例 #9
0
        private IEnumerable <NavigationNode> GetGlobalNavigationTaxonomyNodes(SPWeb web, NavigationQueryParameters queryParameters, IEnumerable <NavigationTerm> navigationTerms = null)
        {
            // If navigation terms is null, fetch this initial terms from the taxonomy navigation term set
            if (navigationTerms == null)
            {
                var nodeMatchingSettings = queryParameters.NodeMatchingSettings;
                if ((nodeMatchingSettings != null) && nodeMatchingSettings.RestrictToCurrentNavigationLevel)
                {
                    navigationTerms = TaxonomyNavigationContext.Current.NavigationTerm.Parent.Terms;
                }
                else
                {
                    // Create view to return all navigation terms
                    var view = new NavigationTermSetView(web, StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider)
                    {
                        ExcludeTermsByProvider = false
                    };

                    var navigationTermSet = TaxonomyNavigation.GetTermSetForWeb(web, StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider, true);

                    // Navigation termset might be null when crawling
                    if (navigationTermSet == null)
                    {
                        return(new NavigationNode[] { });
                    }

                    navigationTerms = navigationTermSet.GetWithNewView(view).Terms;
                }
            }

            // Gets terms which are not excluded from global navigation
            // Note: Navigation terms needs to be editable to get the taxonomy term
            var session = new TaxonomySession(web.Site);
            var terms   = navigationTerms.Where(x => !x.ExcludeFromGlobalNavigation).Select(x => x.GetAsEditable(session)).ToArray();
            var nodes   = terms.Select(x => new NavigationNode(x)).ToArray();

            for (var i = 0; i < terms.Length; i++)
            {
                var term = terms[i];
                var node = nodes[i];

                // If term contains children, recurvise call
                if (term.Terms.Count > 0)
                {
                    node.ChildNodes = this.GetGlobalNavigationTaxonomyNodes(web, queryParameters, term.Terms);
                }
            }

            return(nodes);
        }
コード例 #10
0
        private IEnumerable<NavigationNode> FilterNavigationNodesToRestrictedTermSet(SPWeb web, NavigationQueryParameters queryParameters, IEnumerable<NavigationNode> nodes, Term[] restrictedTerms = null)
        {
            // If first pass, initialize the restricted nodes with first level terms
            if (restrictedTerms == null)
            {
                // Get restricted term set
                var session = new TaxonomySession(web.Site);
                TermStore termStore = null;

                if (queryParameters.TermStoreId == Guid.Empty)
                {
                    termStore = this.taxonomyHelper.GetDefaultSiteCollectionTermStore(session);
                }
                else
                {
                    termStore = session.TermStores[queryParameters.TermStoreId];
                }

                var termSet = termStore.GetTermSet(queryParameters.RestrictedTermSetId);

                var nodeMatchingSettings = queryParameters.NodeMatchingSettings;
                if ((nodeMatchingSettings != null) && nodeMatchingSettings.RestrictToCurrentNavigationLevel)
                {
                    var currentTermId = TaxonomyNavigationContext.Current.NavigationTerm.Id;
                    restrictedTerms = termSet.GetTerm(currentTermId).Parent.Terms.ToArray();
                }
                else
                {
                    restrictedTerms = termSet.Terms.ToArray();
                }
            }

            // Flattened navigation nodes for easier search
            var flattenedNodes = nodes.Flatten(node => node.ChildNodes);
            var restrictedNodes = restrictedTerms.Select(term => flattenedNodes.SingleOrDefault(node => node.Id.Equals(term.Id))).ToArray();
            for (var i = 0; i < restrictedTerms.Length; i++)
            {
                var restrictedTerm = restrictedTerms[i];
                var restrictedNode = restrictedNodes[i];

                // If term contains children, recurvise call
                if (restrictedTerm.Terms.Count > 0)
                {
                    restrictedNode.ChildNodes = this.FilterNavigationNodesToRestrictedTermSet(web, queryParameters, nodes, restrictedTerm.Terms.ToArray());
                }
                else
                {
                    restrictedNode.ChildNodes = new List<NavigationNode>();
                }
            }

            return restrictedNodes;
        }
コード例 #11
0
        private IEnumerable<NavigationNode> GetGlobalNavigationTaxonomyNodes(SPWeb web, NavigationQueryParameters queryParameters, IEnumerable<NavigationTerm> navigationTerms = null)
        {
            // If navigation terms is null, fetch this initial terms from the taxonomy navigation term set
            if (navigationTerms == null)
            {
                var nodeMatchingSettings = queryParameters.NodeMatchingSettings;
                if ((nodeMatchingSettings != null) && nodeMatchingSettings.RestrictToCurrentNavigationLevel)
                {
                    navigationTerms = TaxonomyNavigationContext.Current.NavigationTerm.Parent.Terms;
                }
                else
                {
                    // Create view to return all navigation terms
                    var view = new NavigationTermSetView(web, StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider)
                    {
                        ExcludeTermsByProvider = false
                    };

                    var navigationTermSet = TaxonomyNavigation.GetTermSetForWeb(web, StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider, true);

                    // Navigation termset might be null when crawling
                    if (navigationTermSet == null)
                    {
                        return new NavigationNode[] { };
                    }

                    navigationTerms = navigationTermSet.GetWithNewView(view).Terms;
                }
            }

            // Gets terms which are not excluded from global navigation
            // Note: Navigation terms needs to be editable to get the taxonomy term
            var session = new TaxonomySession(web.Site);
            var terms = navigationTerms.Where(x => !x.ExcludeFromGlobalNavigation).Select(x => x.GetAsEditable(session)).ToArray();
            var nodes = terms.Select(x => new NavigationNode(x)).ToArray();
            for (var i = 0; i < terms.Length; i++)
            {
                var term = terms[i];
                var node = nodes[i];

                // If term contains children, recurvise call
                if (term.Terms.Count > 0)
                {
                    node.ChildNodes = this.GetGlobalNavigationTaxonomyNodes(web, queryParameters, term.Terms);
                }
            }

            return nodes;
        }