SitemapGenerator.cs :  » Web-Frameworks » nopCommerce » NopSolutions » NopCommerce » BusinessLogic » SEO » Sitemaps » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Web Frameworks » nopCommerce 
nopCommerce » NopSolutions » NopCommerce » BusinessLogic » SEO » Sitemaps » SitemapGenerator.cs
//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  http://www.nopCommerce.com/License.aspx. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations under the License.
// 
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
// 
// Contributor(s): _______. 
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration.Provider;
using System.Globalization;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml;
using NopSolutions.NopCommerce.BusinessLogic.Categories;
using NopSolutions.NopCommerce.BusinessLogic.Configuration;
using NopSolutions.NopCommerce.BusinessLogic.Configuration.Settings;
using NopSolutions.NopCommerce.BusinessLogic.Content.Blog;
using NopSolutions.NopCommerce.BusinessLogic.Content.NewsManagement;
using NopSolutions.NopCommerce.BusinessLogic.Content.Topics;
using NopSolutions.NopCommerce.BusinessLogic.Manufacturers;
using NopSolutions.NopCommerce.BusinessLogic.Products;
using NopSolutions.NopCommerce.BusinessLogic.Utils;
using NopSolutions.NopCommerce.Common.Utils;
using NopSolutions.NopCommerce.Common.Xml;

namespace NopSolutions.NopCommerce.BusinessLogic.SEO.Sitemaps{
    /// <summary>
    /// Represents a sitemap generator
    /// </summary>
    public partial class SitemapGenerator : BaseSitemapGenerator
    {
        #region Utilities

        /// <summary>
        /// Method that is overridden, that handles creation of child urls.
        /// Use the method WriteUrlLocation() within this method.
        /// </summary>
        protected override void GenerateUrlNodes()
        {
            bool IncludeCategories = SettingManager.GetSettingValueBoolean("SEO.Sitemaps.IncludeCategories", true);
            bool IncludeManufacturers = SettingManager.GetSettingValueBoolean("SEO.Sitemaps.IncludeManufacturers", false);
            bool IncludeProducts = SettingManager.GetSettingValueBoolean("SEO.Sitemaps.IncludeProducts", false);
            bool IncludeTopics = SettingManager.GetSettingValueBoolean("SEO.Sitemaps.IncludeTopics", false);
            string OtherPages = SettingManager.GetSettingValue("SEO.Sitemaps.OtherPages").ToLowerInvariant();
            
            if (IncludeCategories)
            {
                WriteCategories(0);
            }

            if (IncludeManufacturers)
            {
                WriteManufacturers();
            }

            if (IncludeProducts)
            {
                WriteProducts();
            }

            if (IncludeTopics)
            {
                WriteTopics();
            }

            WriteOtherPages(OtherPages);
        }

        private void WriteCategories(int parentCategoryId)
        {
            var categories = CategoryManager.GetAllCategories(parentCategoryId, false);
            foreach (var category in categories)
            {
                var url = SEOHelper.GetCategoryUrl(category.CategoryId);
                var updateFrequency = UpdateFrequency.Weekly;
                var updateTime = category.UpdatedOn;
                WriteUrlLocation(url, updateFrequency, updateTime);

                WriteCategories(category.CategoryId);
            }
        }

        private void WriteManufacturers()
        {
            var manufacturers = ManufacturerManager.GetAllManufacturers(false);
            foreach (var manufacturer in manufacturers)
            {
                var url = SEOHelper.GetManufacturerUrl(manufacturer);
                var updateFrequency = UpdateFrequency.Weekly;
                var updateTime = manufacturer.UpdatedOn;
                WriteUrlLocation(url, updateFrequency, updateTime);
            }
        }

        private void WriteProducts()
        {
            var products = ProductManager.GetAllProducts(false);
            foreach (var product in products)
            {
                var url = SEOHelper.GetProductUrl(product);
                var updateFrequency = UpdateFrequency.Weekly;
                var updateTime = product.UpdatedOn;
                WriteUrlLocation(url, updateFrequency, updateTime);
            }
        }

        private void WriteTopics()
        {
            var topics = TopicManager.GetAllTopics();
            foreach (Topic topic in topics)
            {
                var localizedTopics = TopicManager.GetAllLocalizedTopics(topic.Name);
                if (localizedTopics.Count > 0)
                {
                    //UNDONE add topic of one language only (they have the same URL now)
                    var localizedTopic = localizedTopics[0];
                    var url = SEOHelper.GetTopicUrl(localizedTopic.TopicId, localizedTopic.Title);
                    var updateFrequency = UpdateFrequency.Weekly;
                    var updateTime = localizedTopic.UpdatedOn;
                    WriteUrlLocation(url, updateFrequency, updateTime);
                }
            }
        }

        private void WriteOtherPages(string otherPages)
        {
            if (String.IsNullOrEmpty(otherPages))
                return;

            string[] pages = otherPages.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string page in pages)
            {
                string url = CommonHelper.GetStoreLocation() + page.Trim();
                var updateFrequency = UpdateFrequency.Weekly;
                var updateTime = DateTime.UtcNow;
                WriteUrlLocation(url, updateFrequency, updateTime);
            }
        }

        #endregion
    }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.