Beispiel #1
0
        public static SitemapIndexUrlSet GetSitemapIndex()
        {
            List <SitemapIndexUrl> sitemapIndexUrls = new List <SitemapIndexUrl>();
            String path;
            SitemapIndexSection section = (SitemapIndexSection)ConfigurationManager.GetSection("SitemapIndex");
            SitemapIndexProviderConfiguration config = section.Sitemaps;

            // Find all Sitemap elements within the Sitemaps collection and add their name (which is their URL) to the SitemapIndex
            foreach (SitemapProviderConfiguration element in config)
            {
                try
                {
                    path = ConfigurationManager.AppSettings["RootUrl"] + "/sitemaps/" + element.Name.ToLower();
                    sitemapIndexUrls.Add(new SitemapIndexUrl(path, DateTime.Now));
                }

                // If the sitemap index URL for this element can't be added, skip to the next element in the config.
                catch (XmlException ex)
                {
                    log.Error("A sitemap index URL has failed parsing in Sitemaps:GetSitemapIndex().\nFile: " + element.Name + "\nEnvironment: " + System.Environment.MachineName + "\nRequest Host: " + HttpContext.Current.Request.Url.Host + "\n" + ex.ToString() + "\n");
                    continue;
                }
            }

            return(new SitemapIndexUrlSet(sitemapIndexUrls));
        }
Beispiel #2
0
        public static SitemapProviderConfiguration GetProviderByName(string sitemapName)
        {
            SitemapProviderConfiguration rtnElem = null;

            try
            {
                SitemapIndexSection section = (SitemapIndexSection)ConfigurationManager.GetSection(sitemapIndexSection);
                SitemapIndexProviderConfiguration indexConfig = section.Sitemaps;
                rtnElem = indexConfig[sitemapName + ".xml"];
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Error when retrieving Sitemap Provider Configuration for {0}.", sitemapName);
                throw ex;
            }

            return(rtnElem);
        }
Beispiel #3
0
        private string GetSitemapName(string requestFilepath)
        {
            // check if filepath matches a sitemap given in the web.config
            string filepath = requestFilepath.Split('/').Last();

            SitemapIndexSection section = (SitemapIndexSection)ConfigurationManager.GetSection("SitemapIndex");
            SitemapIndexProviderConfiguration config = section.Sitemaps;

            foreach (SitemapProviderConfiguration element in config)
            {
                if (String.Equals(element.Name.ToLower(), filepath.ToLower()))
                {
                    string sitemapName = filepath.Replace(".xml", "");
                    return(sitemapName);
                }
            }

            // Return null if filepath isn't defined in web config, which will raise an error in ProcessRequest
            return(null);
        }
Beispiel #4
0
        public static void LoadStore()
        {
            SitemapIndexSection section = (SitemapIndexSection)ConfigurationManager.GetSection("SitemapIndex");
            SitemapIndexProviderConfiguration s_Config = section.Sitemaps;

            s_Stores = new SitemapUrlStoreCollection();

            Type providerType = typeof(SitemapUrlStoreBase);

            foreach (SitemapProviderConfiguration element in s_Config)
            {
                // Only use the first Provider.
                foreach (ProviderSettings settings in element.SitemapStores)
                {
                    Type settingsType = Type.GetType(settings.Type, true, true);

                    if (settingsType == null)
                    {
                        throw new ConfigurationErrorsException(String.Format("Could not find type: {0}", settings.Type));
                    }
                    if (!providerType.IsAssignableFrom(settingsType))
                    {
                        throw new ConfigurationErrorsException(String.Format("SitemapStore '{0}' must subclass from '{1}'", settings.Name, providerType));
                    }

                    SitemapUrlStoreBase store = Activator.CreateInstance(settingsType) as SitemapUrlStoreBase;

                    if (store != null)
                    {
                        store.Initialize(settings.Name.ToLower(), settings.Parameters);
                    }

                    s_Stores.Add(store);
                }
            }

            if (s_Stores.Count == 0)
            {
                throw new ConfigurationErrorsException(string.Format("No SitemapUrlStoreBase found"));
            }
        }