GetByDomain() public method

Returns a Rock.Model.SiteDomain by Domain.
public GetByDomain ( string domain ) : SiteDomain
domain string A containing a domain/URL to search by.
return SiteDomain
Exemplo n.º 1
0
        /// <summary>
        /// Returns site based on domain
        /// </summary>
        /// <param name="host">The host.</param>
        /// <returns></returns>
        public static SiteCache GetSiteByDomain(string host)
        {
            int siteId = 0;

            if (_siteDomains.TryGetValue(host, out siteId))
            {
                return(Read(siteId));
            }

            using (var rockContext = new RockContext())
            {
                Rock.Model.SiteDomainService siteDomainService = new Rock.Model.SiteDomainService(rockContext);
                Rock.Model.SiteDomain        siteDomain        = siteDomainService.GetByDomain(host);
                if (siteDomain == null)
                {
                    siteDomain = siteDomainService.GetByDomainContained(host);
                }

                if (siteDomain != null)
                {
                    _siteDomains.AddOrUpdate(host, siteDomain.SiteId, (k, v) => siteDomain.SiteId);
                    return(Read(siteDomain.SiteId));
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns site based on domain
        /// </summary>
        /// <param name="id"></param>
        public static SiteCache GetSiteByDomain(string host)
        {
            SiteCache site = null;

            string cacheKey = "Rock:DomainSites";

            ObjectCache cache = MemoryCache.Default;
            Dictionary <string, int> sites = cache[cacheKey] as Dictionary <string, int>;

            if (sites == null)
            {
                sites = new Dictionary <string, int>();
            }

            // look in cache
            if (sites.ContainsKey(host))
            {
                site = Rock.Web.Cache.SiteCache.Read(sites[host]);
            }
            else
            {
                // get from database
                Rock.Model.SiteDomainService siteDomainService = new Rock.Model.SiteDomainService();
                Rock.Model.SiteDomain        siteDomain        = siteDomainService.GetByDomain(host);

                if (siteDomain == null)
                {
                    siteDomain = siteDomainService.GetByDomainContained(host);
                }

                if (siteDomain != null)
                {
                    return(SiteCache.Read(siteDomain.SiteId));
                }
            }

            return(site);
        }