/// <summary>
        /// The get site taxonomy cache.
        /// </summary>
        /// <param name="site">
        /// The site.
        /// </param>
        /// <param name="termStoreName">
        /// The term store name.
        /// </param>
        /// <returns>
        /// The <see cref="SiteTaxonomyCache"/>.
        /// </returns>
        public SiteTaxonomyCache GetSiteTaxonomyCache(SPSite site, string termStoreName)
        {
            return NamedLocker.RunWithUpgradeableReadLock(
                site.ID,
                () =>
                    {
                        // Create the Site Taxonomy Cache because it does not yet exist.
                        if (!this.taxonomyCaches.ContainsKey(site.ID))
                        {
                            return NamedLocker.RunWithWriteLock(
                                site.ID,
                                () =>
                                    {
                                        // Double check for thread concurency
                                        if (!this.taxonomyCaches.ContainsKey(site.ID))
                                        {
                                            var newTaxCache = new SiteTaxonomyCache(site, termStoreName);

                                            this.log.Info("SiteTaxonomyCacheManager: Adding site taxonomy cache for site collection " + site.Url);
                                            this.taxonomyCaches.Add(site.ID, newTaxCache);

                                            return newTaxCache;
                                        }

                                        return this.taxonomyCaches[site.ID];
                                    });
                        }

                // Return the existing Session
                return this.taxonomyCaches[site.ID];
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves a TaxonomyValue corresponding to a term label within the default term store in the site collection's reserved group
        /// </summary>
        /// <remarks>
        /// Use other overloads and specify a group name to fetch from farm-global term sets instead of being limited
        /// to the site collection's associated term group
        /// </remarks>
        /// <param name="site">The current site</param>
        /// <param name="termSetName">The term set name</param>
        /// <param name="termLabel">The default label of the term</param>
        /// <returns>The taxonomy value or null if not found</returns>
        public TaxonomyValue GetTaxonomyValueForLabel(SPSite site, string termSetName, string termLabel)
        {
            SiteTaxonomyCache taxCache            = this.taxonomyCacheManager.GetSiteTaxonomyCache(site, null, this.taxonomyHelper);
            TermStore         termStore           = this.taxonomyHelper.GetDefaultSiteCollectionTermStore(taxCache.TaxonomySession);
            Group             siteCollectionGroup = taxCache.SiteCollectionGroup;
            TermSet           termSet             = this.GetTermSetFromGroup(termStore, siteCollectionGroup, termSetName);

            return(GetTaxonomyValueForLabelInternal(termStore, siteCollectionGroup, termSet, termLabel));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves all Terms corresponding to a term set in the default term store from the site collection's reserved group
        /// </summary>
        /// <remarks>
        /// Use other overloads and specify a group name to fetch from farm-global term sets instead of being limited
        /// to the site collection's associated term group
        /// </remarks>
        /// <param name="site">The current site</param>
        /// <param name="termSetName">The term set name</param>
        /// <returns>A list of taxonomy values</returns>
        public IList <Term> GetTermsForTermSet(SPSite site, string termSetName)
        {
            SiteTaxonomyCache taxCache            = this.taxonomyCacheManager.GetSiteTaxonomyCache(site, null, this.taxonomyHelper);
            TermStore         termStore           = this.taxonomyHelper.GetDefaultSiteCollectionTermStore(taxCache.TaxonomySession);
            Group             siteCollectionGroup = taxCache.SiteCollectionGroup;
            TermSet           termSet             = this.GetTermSetFromGroup(termStore, siteCollectionGroup, termSetName);

            return(GetTermsForTermSetInternal(termStore, siteCollectionGroup, termSet));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the term for identifier
        /// </summary>
        /// <param name="site">The Site.</param>
        /// <param name="termStoreGroupName">The Group Name in the term store</param>
        /// <param name="termSetName">The name of the term set containing the term</param>
        /// <param name="id">The GUID of the term to get.</param>
        /// <returns>The term</returns>
        public Term GetTermForIdInTermSet(SPSite site, string termStoreGroupName, string termSetName, Guid id)
        {
            SiteTaxonomyCache taxCache            = this.taxonomyCacheManager.GetSiteTaxonomyCache(site, null, this.taxonomyHelper);
            TermStore         termStore           = this.taxonomyHelper.GetDefaultSiteCollectionTermStore(taxCache.TaxonomySession);
            Group             siteCollectionGroup = GetGroupFromTermStore(termStore, termStoreGroupName);
            TermSet           termSet             = this.GetTermSetFromGroup(termStore, siteCollectionGroup, termSetName);

            return(termSet.GetTerm(id));
        }
        /// <summary>
        /// Retrieves a Term corresponding to a term label within the default term store in the site collection's reserved group
        /// </summary>
        /// <remarks>
        /// Use other overloads and specify a group name to fetch from farm-global term sets instead of being limited
        /// to the site collection's associated term group
        /// </remarks>
        /// <param name="site">The current site</param>
        /// <param name="termSetName">The term set name</param>
        /// <param name="termLabel">The default label of the term</param>
        /// <returns>A list of terms</returns>
        public IList <Term> GetTermsForLabel(SPSite site, string termSetName, string termLabel)
        {
            SiteTaxonomyCache taxCache            = this.taxonomyCacheManager.GetSiteTaxonomyCache(site, null);
            TermStore         termStore           = taxCache.TaxonomySession.DefaultSiteCollectionTermStore;
            Group             siteCollectionGroup = taxCache.SiteCollectionGroup;
            TermSet           termSet             = this.GetTermSetFromGroup(termStore, siteCollectionGroup, termSetName);

            return(GetTermsForLabelInternal(termStore, siteCollectionGroup, termSet, termLabel));
        }
        /// <summary>
        /// The get site taxonomy cache.
        /// </summary>
        /// <param name="site">
        /// The site.
        /// </param>
        /// <param name="termStoreName">
        /// The term store name.
        /// </param>
        /// <returns>
        /// The <see cref="SiteTaxonomyCache"/>.
        /// </returns>
        public SiteTaxonomyCache GetSiteTaxonomyCache(SPSite site, string termStoreName)
        {
            // No caching if outside HttpContext
            if (HttpContext.Current == null)
            {
                return new SiteTaxonomyCache(site, termStoreName);
            }

            string cacheKey = KeyPrefix + site.ID.ToString();

            // Create the Site Taxonomy Cache because it does not yet exist. No need for locking because
            // we only cache per-request using the HttpContext cache.
            if (HttpContext.Current.Items[cacheKey] == null)
            {
                var newTaxCache = new SiteTaxonomyCache(site, termStoreName);
                HttpContext.Current.Items[cacheKey] = newTaxCache;
            }

            // Return the existing Session
            return (SiteTaxonomyCache)HttpContext.Current.Items[cacheKey];
        }
Exemplo n.º 7
0
        /// <summary>
        /// The get site taxonomy cache.
        /// </summary>
        /// <param name="site">
        /// The site.
        /// </param>
        /// <param name="termStoreName">
        /// The term store name.
        /// </param>
        /// <returns>
        /// The <see cref="SiteTaxonomyCache"/>.
        /// </returns>
        public SiteTaxonomyCache GetSiteTaxonomyCache(SPSite site, string termStoreName)
        {
            // No caching if outside HttpContext
            if (HttpContext.Current == null)
            {
                return(new SiteTaxonomyCache(site, termStoreName));
            }

            string cacheKey = KeyPrefix + site.ID.ToString();

            // Create the Site Taxonomy Cache because it does not yet exist. No need for locking because
            // we only cache per-request using the HttpContext cache.
            if (HttpContext.Current.Items[cacheKey] == null)
            {
                var newTaxCache = new SiteTaxonomyCache(site, termStoreName);
                HttpContext.Current.Items[cacheKey] = newTaxCache;
            }

            // Return the existing Session
            return((SiteTaxonomyCache)HttpContext.Current.Items[cacheKey]);
        }