示例#1
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);
        }