Esempio n. 1
0
        public static Site GetSite(this IWebsitesServiceManagement proxy, string subscriptionId, string website, string propertiesToInclude)
        {
            // Try to find webspace for site from cache
            Site site = Cache.GetSite(subscriptionId, website, propertiesToInclude);

            if (site != null)
            {
                try
                {
                    return(proxy.GetSite(subscriptionId, site.WebSpace, site.Name, propertiesToInclude));
                }
                catch
                {
                    Cache.RemoveSite(subscriptionId, site);
                    throw;
                }
            }

            // If site was not in cache, find out in which webspace it could be
            var webspaces = proxy.GetWebSpacesWithCache(subscriptionId);

            foreach (var webspace in webspaces)
            {
                var websites     = proxy.GetSites(subscriptionId, webspace.Name, propertiesToInclude);
                var matchWebsite = websites.FirstOrDefault(w => w.Name.Equals(website, System.StringComparison.InvariantCultureIgnoreCase));
                if (matchWebsite != null)
                {
                    return(matchWebsite);
                }
            }

            return(null);
        }
Esempio n. 2
0
        public static Site GetSiteWithCache(
            this IWebsitesServiceManagement proxy,
            string subscriptionId,
            string website,
            string propertiesToInclude)
        {
            // Try to get the website's webspace from the cache
            Site site = Cache.GetSite(subscriptionId, website, propertiesToInclude);

            if (site != null)
            {
                try
                {
                    return(proxy.GetSite(subscriptionId, site.WebSpace, site.Name, propertiesToInclude));
                }
                catch
                {
                    // The website is removed or it's webspace changed.
                    Cache.RemoveSite(subscriptionId, site);
                    throw;
                }
            }

            // Get all available webspace using REST API
            WebSpaces webspaces = proxy.GetWebSpaces(subscriptionId);

            // Iterate over all the webspaces until finding the website.
            foreach (WebSpace webspace in webspaces)
            {
                Sites websites     = proxy.GetSites(subscriptionId, webspace.Name, propertiesToInclude);
                var   matchWebsite = websites.FirstOrDefault(w => w.Name.Equals(website, System.StringComparison.InvariantCultureIgnoreCase));
                if (matchWebsite != null)
                {
                    return(matchWebsite);
                }
            }

            // The website does not exist.
            return(null);
        }