public void UrlSerialiser_Serialise_ProvidingEverythingFormatsCorrectly()
        {
            float           priority = 0.195f;
            ChangeFrequency cf       = ChangeFrequency.Weekly;
            DateTime        dt       = new DateTime(2014, 12, 05, 07, 55, 0, DateTimeKind.Utc);

            var serialiser = new UrlSetSerialiser();

            var url = new Url("123");

            url.Priority        = priority;
            url.ChangeFrequency = cf;
            url.LastModified    = dt;

            var xUrl = serialiser.serialiseUrl(url);

            Assert.IsNotNull(xUrl);

            Assert.AreEqual(4, xUrl.Elements().Count());

            var xPriority = xUrl.Element(UrlSetSerialiser.SitemapNamespace + UrlSetSerialiser.UrlPriorityElementName);

            Assert.IsNotNull(xPriority);
            Assert.AreEqual("0.2", xPriority.Value);

            var xChange = xUrl.Element(UrlSetSerialiser.SitemapNamespace + UrlSetSerialiser.UrlChangeFrequencyElementName);

            Assert.IsNotNull(xChange);
            Assert.AreEqual("weekly", xChange.Value);

            var xMod = xUrl.Element(UrlSetSerialiser.SitemapNamespace + UrlSetSerialiser.UrlModifiedElementName);

            Assert.IsNotNull(xMod);
            Assert.AreEqual("2014-12-05T07:55:00Z", xMod.Value);
        }
Example #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="pageUrl">URL of the page. This URL must begin with the protocol (such as http) and end with a trailing slash, if your web server requires it. This value must be less than 2048 characters.</param>
 /// <param name="lastModified">he date of last modification of the file. This date should be in W3C Datetime format. This format allows you to omit the time portion, if desired, and use YYYY-MM-DD.</param>
 /// <param name="changeFrequency">How frequently the page is likely to change. This value provides general information to search engines and may not correlate exactly to how often they crawl the page. Valid values are:
 /// * always
 /// * hourly
 /// * daily
 /// * monthly
 /// * yearly
 /// * never
 /// The value "always" should be used to describe documents that change each time they are accessed. The value "never" should be used to describe archived URLs.
 /// Please note that the value of this tag is considered a hint and not a command. Even though search engine crawlers consider this information when making decisions, they may crawl pages marked "hourly" less frequently than that, and they may crawl pages marked "yearly" more frequently than that. It is also likely that crawlers will periodically crawl pages marked "never" so that they can handle unexpected changes to those pages.</param>
 /// <param name="priority">The priority of this URL relative to other URLs on your site. Valid values range from 0.0 to 1.0. This value has no effect on your pages compared to pages on other sites, and only lets the search engines know which of your pages you deem most important so they can order the crawl of your pages in the way you would most like.
 /// The default priority of a page is 0.5.
 /// Please note that the priority you assign to a page has no influence on the position of your URLs in a search engine's result pages. Search engines use this information when selecting between URLs on the same site, so you can use this tag to increase the likelihood that your more important pages are present in a search index.
 /// Also, please note that assigning a high priority to all of the URLs on your site will not help you. Since the priority is relative, it is only used to select between URLs on your site; the priority of your pages will not be compared to the priority of pages on other sites.</param>
 public UrlElement(Uri pageUrl, DateTime lastModified, ChangeFrequency changeFrequency, decimal priority)
 {
     _pageUrl = pageUrl;
     LastModified = lastModified;
     ChangeFrequency = changeFrequency;
     Priority = priority;
 }
Example #3
0
        private void OnChangeFrequency(ChangeFrequency obj)
        {
            var interval = FrequencyUtils.TimeSpanFromFrequency(obj.Frequency);

            // (Konrad) We should delay the execution by the new interval.
            Runner.Timer.Change(interval, interval);
        }
Example #4
0
        /// <summary>
        /// Get string value of ChangeFrequency enum.
        /// </summary>
        /// <param name="frequency"></param>
        /// <returns></returns>
        public static string GetChangeFrequency(ChangeFrequency frequency)
        {
            switch (frequency)
            {
            case ChangeFrequency.ALWAYS:
                return("always");

            case ChangeFrequency.DAILY:
                return("daily");

            case ChangeFrequency.HOURLY:
                return("hourly");

            case ChangeFrequency.MONTHLY:
                return("monthly");

            case ChangeFrequency.NEVER:
                return("never");

            case ChangeFrequency.WEEKLY:
                return("weekly");

            case ChangeFrequency.YEARLY:
                return("yearly");

            default:
                return("");
            }
        }
Example #5
0
 public UrlElement(string location, DateTime lastModified, ChangeFrequency changeFrequency, Priority priority)
 {
     this._location        = location;
     this._lastModified    = lastModified;
     this._changeFrequency = changeFrequency;
     this._priority        = priority;
 }
Example #6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="pageUrl">URL of the page. This URL must begin with the protocol (such as http) and end with a trailing slash, if your web server requires it. This value must be less than 2048 characters.</param>
 /// <param name="lastModified">he date of last modification of the file. This date should be in W3C Datetime format. This format allows you to omit the time portion, if desired, and use YYYY-MM-DD.</param>
 /// <param name="changeFrequency">How frequently the page is likely to change. This value provides general information to search engines and may not correlate exactly to how often they crawl the page. Valid values are:
 /// * always
 /// * hourly
 /// * daily
 /// * monthly
 /// * yearly
 /// * never
 /// The value "always" should be used to describe documents that change each time they are accessed. The value "never" should be used to describe archived URLs.
 /// Please note that the value of this tag is considered a hint and not a command. Even though search engine crawlers consider this information when making decisions, they may crawl pages marked "hourly" less frequently than that, and they may crawl pages marked "yearly" more frequently than that. It is also likely that crawlers will periodically crawl pages marked "never" so that they can handle unexpected changes to those pages.</param>
 /// <param name="priority">The priority of this URL relative to other URLs on your site. Valid values range from 0.0 to 1.0. This value has no effect on your pages compared to pages on other sites, and only lets the search engines know which of your pages you deem most important so they can order the crawl of your pages in the way you would most like.
 /// The default priority of a page is 0.5.
 /// Please note that the priority you assign to a page has no influence on the position of your URLs in a search engine's result pages. Search engines use this information when selecting between URLs on the same site, so you can use this tag to increase the likelihood that your more important pages are present in a search index.
 /// Also, please note that assigning a high priority to all of the URLs on your site will not help you. Since the priority is relative, it is only used to select between URLs on your site; the priority of your pages will not be compared to the priority of pages on other sites.</param>
 public UrlElement(Uri pageUrl, DateTime lastModified, ChangeFrequency changeFrequency, decimal priority)
 {
     _pageUrl        = pageUrl;
     LastModified    = lastModified;
     ChangeFrequency = changeFrequency;
     Priority        = priority;
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SitemapItem"/> class.
 /// </summary>
 /// <param name="url">The URL to the item.</param>
 /// <param name="lastModified">The last modified date.</param>
 /// <param name="frequency">The frequently the page is likely to change.</param>
 /// <param name="priority">The priority of this URL relative to other URLs on your site.</param>
 public SitemapItem(string url, DateTime lastModified, ChangeFrequency frequency, decimal priority)
 {
     this.Url             = url;
     this.LastModified    = lastModified;
     this.ChangeFrequency = frequency;
     this.Priority        = priority;
 }
Example #8
0
 public SiteMapNode(string relativePath, DateTime modificationDate, ChangeFrequency changeFrequency, double priority = 0.5)
 {
     RelativePath     = relativePath;
     ModificationDate = modificationDate;
     ChangeFrequency  = changeFrequency;
     Priority         = priority;
 }
 private bool MatchUrl(List <Url> urls, string url, double priority, ChangeFrequency changeFrequency)
 {
     return
         (urls.Any(
              x =>
              x.ChangeFrequency == changeFrequency && x.Priority == priority && x.Location == url &&
              x.TimeStamp.Date == DateTime.UtcNow.Date));
 }
        protected XElement GetElement(string url, DateTime lastModified, ChangeFrequency changeFrequency, int priority)
        {
            var element = new XElement(Ns + "url", new XElement(Ns + "loc", url));

            element.Add(new XElement(Ns + "lastmod", lastModified.ToString("MM-dd-yyyy")));
            element.Add(new XElement(Ns + "changefreq", changeFrequency));
            element.Add(new XElement(Ns + "priority", priority.ToString(CultureInfo.InvariantCulture)));
            return(element);
        }
Example #11
0
 public UrlMap(string Url, string PageName, Double Priority, ChangeFrequency Frequency, DateTime Published)
 {
     this.Url       = Url;
     this.PageName  = PageName;
     this.Priority  = Priority;
     this.Frequency = Frequency;
     this.Published = Published;
     this.Type      = UrlType.Seo;
 }
Example #12
0
 public void AddUrl(string url, DateTime lastMod, ChangeFrequency changeFrequency, double priority)
 {
     this.SiteMapItems.Add(new SiteMapItem
     {
         Url             = url,
         LastMode        = lastMod,
         ChangeFrequency = changeFrequency,
         Priority        = priority
     });
 }
Example #13
0
 public void Create(string loc, DateTime lastModified, string prioity, ChangeFrequency changeFrequency)
 {
     var node = new MapNode
     {
         Loc = loc,
         Priority = prioity,
         ChangeFrequenty = changeFrequency.ToString().ToLowerInvariant(),
         LastModified = lastModified.ToString("yyyy-MM-ddThh:mm:ssK")
     };
     List.Add(node);
 }
Example #14
0
        public void AddLocation(String location, DateTime lastmod, String priority, ChangeFrequency changeFreq)
        {
            SiteMapItem item = new SiteMapItem();

            item.Loc        = location;
            item.LastMod    = lastmod;
            item.Priority   = priority;
            item.ChangeFreq = changeFreq;

            this.AddLocation(item);
        }
Example #15
0
 public UrlMap(string Url, string PageName, Double Priority, ChangeFrequency Frequency, DateTime Published, string UrlShortName, string UrlDescription, UrlType Type)
 {
     this.Url            = Url;
     this.PageName       = PageName;
     this.Priority       = Priority;
     this.Frequency      = Frequency;
     this.Published      = Published;
     this.UrlShortName   = UrlShortName;
     this.UrlDescription = UrlDescription;
     this.Type           = Type;
 }
        private void AssertStaticPageIsIncludedInSitemap(string url, double priority, ChangeFrequency changeFrequency)
        {
            _autoMocker.ClassUnderTest.BuildStaticPagesSitemap(_targetDirectory);

            //--assert
            _autoMocker.Get<ISitemapGenerator>()
                .Received()
                .GenerateSitemaps(
                    Arg.Is<List<Url>>(x => MatchUrl(x, url, priority, changeFrequency)),
                    Arg.Any<DirectoryInfo>(),
                    Arg.Any<string>());
        }
Example #17
0
 public int GetHashCode(IEqualityComparer comparer)
 {
     unchecked
     {
         var hashCode = ChangeFrequency.GetHashCode();
         hashCode = (hashCode * 397) ^ LastModified.GetHashCode();
         hashCode = (hashCode * 397) ^ Priority.GetHashCode();
         hashCode = (hashCode * 397) ^ (Url?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Metadata?.GetHashCode() ?? 0);
         return(hashCode);
     }
 }
Example #18
0
        public void Create(string loc, DateTime lastModified, string prioity, ChangeFrequency changeFrequency)
        {
            var node = new MapNode
            {
                Loc             = loc,
                Priority        = prioity,
                ChangeFrequenty = changeFrequency.ToString().ToLowerInvariant(),
                LastModified    = lastModified.ToString("yyyy-MM-ddThh:mm:ssK")
            };

            List.Add(node);
        }
Example #19
0
 public override int GetHashCode()
 {
     unchecked
     {
         // ReSharper disable NonReadonlyMemberInGetHashCode
         var hashCode = ChangeFrequency.GetHashCode();
         hashCode = (hashCode * 397) ^ LastModified.GetHashCode();
         hashCode = (hashCode * 397) ^ Priority.GetHashCode();
         hashCode = (hashCode * 397) ^ (Url?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Metadata?.GetHashCode() ?? 0);
         return(hashCode);
     }
 }
Example #20
0
 public UrlMap(string Url, string PageName, Double Priority, ChangeFrequency Frequency, DateTime Published, string UrlShortName, string UrlDescription, UrlType Type, string Author, string Keywords, string Description)
 {
     this.Url            = Url;
     this.PageName       = PageName;
     this.Priority       = Priority;
     this.Frequency      = Frequency;
     this.Published      = Published;
     this.UrlShortName   = UrlShortName;
     this.UrlDescription = UrlDescription;
     this.Type           = Type;
     this.Author         = Author;
     this.Keyword        = Keyword;
     this.Description    = Description;
 }
 /// <summary>
 /// Resolves all internal variables.
 /// </summary>
 private void Initialize()
 {
     if (!this.initialized)
     {
         this.itemObject           = this.Convert(this.item);
         this.location             = this.ResolveAbsoluteUrl(this.itemObject);
         this.lastModified         = this.ResolveUpdatedDate(this.itemObject);
         this.isPage               = this.CheckIsPage(this.itemObject);
         this.isListedInNavigation = this.CheckIsListedInNavigation(this.itemObject);
         this.shouldIndex          = this.CheckShouldIndex(this.itemObject);
         this.changeFrequency      = this.ResolveChangeFrequency(this.itemObject);
         this.priority             = this.ResolvePriority(this.itemObject);
         this.initialized          = true;
     }
 }
        public void UrlSerialiser_Serialise_ProvidingChangeFrequencyFormatsCorrectly()
        {
            ChangeFrequency cf = ChangeFrequency.Hourly;

            var serialiser = new UrlSetSerialiser();

            var url = new Url("123");

            url.ChangeFrequency = cf;

            var xUrl = serialiser.serialiseUrl(url);

            Assert.IsNotNull(xUrl);

            Assert.AreEqual(2, xUrl.Elements().Count());

            var xChange = xUrl.Element(UrlSetSerialiser.SitemapNamespace + UrlSetSerialiser.UrlChangeFrequencyElementName);

            Assert.IsNotNull(xChange);
            Assert.AreEqual("hourly", xChange.Value);
        }
        private static ChangeFrequency CalculateFrequency(Entry entry)
        {
            ChangeFrequency frequency = ChangeFrequency.Hourly;

            if (entry.DateModifiedUtc < DateTime.UtcNow.AddMonths(-12))
            {
                frequency = ChangeFrequency.Yearly;
            }
            else if (entry.DateModifiedUtc < DateTime.UtcNow.AddDays(-60))
            {
                frequency = ChangeFrequency.Monthly;
            }
            else if (entry.DateModifiedUtc < DateTime.UtcNow.AddDays(-14))
            {
                frequency = ChangeFrequency.Weekly;
            }
            else if (entry.DateModifiedUtc < DateTime.UtcNow.AddDays(-2))
            {
                frequency = ChangeFrequency.Daily;
            }
            return(frequency);
        }
        private static ChangeFrequency CalculateFrequency(DateTime modifiedAt)
        {
            ChangeFrequency frequency = ChangeFrequency.Hourly;

            if (modifiedAt < DateTime.Now.AddMonths(-12))
            {
                frequency = ChangeFrequency.Yearly;
            }
            else if (modifiedAt < DateTime.Now.AddDays(-60))
            {
                frequency = ChangeFrequency.Monthly;
            }
            else if (modifiedAt < DateTime.Now.AddDays(-14))
            {
                frequency = ChangeFrequency.Weekly;
            }
            else if (modifiedAt < DateTime.Now.AddDays(-2))
            {
                frequency = ChangeFrequency.Daily;
            }
            return(frequency);
        }
Example #25
0
        private void AddUrl(string location, DateTime lastModified, bool useLastModified, ChangeFrequency changeFrequency, bool useChangeFrequency)
        {
            StringBuilder url = new StringBuilder();

            url.Append("	<url>");
            url.AppendFormat("		<loc>{0}</loc>", location);

            if (useLastModified)
                url.AppendFormat("		<lastmod>{0:s}{0:zzz}</lastmod>", lastModified);

            if (useChangeFrequency)
                url.AppendFormat("		<changefreq>{0}</changefreq>", changeFrequency);

            url.Append("	</url>");

            // add the new url to the collection
            this._urls.Add(url.ToString());
        }
Example #26
0
 public void AddUrl(string location, ChangeFrequency changeFrequency)
 {
     this.AddUrl(location, DateTime.MinValue, false, changeFrequency, true);
 }
Example #27
0
 public void AddUrl(string location, DateTime lastModified, ChangeFrequency changeFrequency)
 {
     this.AddUrl(location, lastModified, true, changeFrequency, true);
 }
 protected CustomDynamicNodeProviderBase(ChangeFrequency nodeChangeFrequency)
 {
     _nodeChangeFrequency = nodeChangeFrequency;
 }
Example #29
0
 public SitemapUrl()
 {
     //Constructor
     _changefreq = ChangeFrequency.Never;
     _priority   = null;
 }
 public void It_Saves_The_Most_Important_Static_Pages_In_The_Sitemap(string url, double priority, ChangeFrequency changeFrequency)
 {
     //--act/assert
     AssertStaticPageIsIncludedInSitemap(url, priority, changeFrequency);
 }
Example #31
0
 public SitemapCore(ChangeFrequency changeFrequency, double priority)
     : this()
 {
     _changeFrequency = changeFrequency;
     _priority        = priority;
 }
Example #32
0
        public async Task HandleAsync(IMessageContext <AircraftTakenOff> context)
        {
            Console.WriteLine($"{nameof(AircraftTakenOff)} message received");

            // Get message context properties
            Console.WriteLine($"MessageId: {context.MessageId}");
            Console.WriteLine($"CorrelationId: {context.CorrelationId}");
            Console.WriteLine($"DeliveryCount: {context.DeliveryCount}");
            Console.WriteLine($"Raw message as text: {context.Body}");

            // Get message properties
            foreach (var property in context.Properties)
            {
                Console.WriteLine($"{property.Key}: {property.Value}");
            }

            try
            {
                // Deserialize message using default deserializer and return AircraftId
                Console.WriteLine($"AircraftId: {context.Message.AircraftId}");

                // Deserialize message using custom JSON Serializer Options
                var jsonOptions = new JsonSerializerOptions()
                {
                    PropertyNameCaseInsensitive = true
                };
                Console.WriteLine($"AircraftId using JSON serializer options: " +
                                  $"{context.Body.ToObjectFromJson<AircraftTakenOff>(jsonOptions).AircraftId}");
            }
            catch (Exception)
            {
                // Dead letter the received message
                await context.DeadLetterMessageAsync("Invalid message");

                throw;
            }

            // Do stuff
            _dependency.SaveMessageId(Guid.Parse(context.MessageId));

            // Publish a new event
            var aircraftLeftAirspaceEvent = new AircraftLeftAirspace {
                Airspace = "London"
            };
            await context.PublishAsync(new Message <IEvent>(aircraftLeftAirspaceEvent));

            // Send a command with custom message properties
            var changeFrequency = new ChangeFrequency {
                NewFrequency = 101.5m
            };
            var changeFrequencyCommand = new Message <ICommand>(changeFrequency)
            {
                MessageId         = $"MyMessageId-{context.Message.AircraftId}",
                CorrelationId     = $"MyCorrelationId-{context.Message.AircraftId}",
                MessageProperties = new Dictionary <string, string>
                {
                    { "AircraftId", context.Message.AircraftId }
                },
                Label = "ChangeFrequencyCommand"
            };

            await context.SendAsync(changeFrequencyCommand);

            Console.WriteLine();
        }
Example #33
0
        /// <summary>
        /// Обновление элемента карты сайта
        /// </summary>
        /// <param name="pathFile">Путь к файлу карты сайта</param>
        /// <param name="url">Ссылка, которую необходимо добавить</param>
        /// <param name="dateModified">Дата модификации</param>
        /// <param name="change">Когда роботу нужно делать переобход</param>
        /// <param name="priority">Приоритет. От 0.1 до 1.0</param>
        /// <returns>Успешное выполнение</returns>
        /// <returns></returns>
        public static bool UpdateItem(string pathFile, string url, DateTime dateModified, ChangeFrequency change, double priority)
        {
            try
            {
                XDocument  doc      = XDocument.Load(pathFile);
                XNamespace NS       = doc.Root.GetDefaultNamespace();
                XElement   root     = doc.Element(NS + "urlset");
                bool       modified = false;


                //Проход по всем url-элементам
                foreach (XElement el in root.Elements(NS + "url"))
                {
                    if (el.Element(NS + "loc") != null)
                    {
                        //Поиск совпадений дочернего элемента loc по url
                        //Если совпадение найдено, то вносим изменения
                        if (el.Element(NS + "loc").Value == url)
                        {
                            //Проверяем поле lastmod
                            if (el.Element(NS + "lastmod") != null)
                            {
                                el.Element(NS + "lastmod").Value = dateModified.ToString("yyyy-MM-ddTHH:mm:ss.f") + "+00:00";
                            }
                            else
                            {
                                XElement lastMod = new XElement(NS + "lastmod", dateModified.ToString("yyyy-MM-ddTHH:mm:ss.f") + "+00:00");
                                el.Add(lastMod);
                            }
                            //Проверяем поле priority
                            if (el.Element(NS + "priority") != null)
                            {
                                el.Element(NS + "priority").Value =
                                    priority.ToString("N1", CultureInfo.InvariantCulture);
                            }
                            else
                            {
                                XElement pr = new XElement(NS + "priority", priority.ToString("N1", CultureInfo.InvariantCulture));
                                el.Add(pr);
                            }
                            //Проверяем поле changefreq
                            if (el.Element(NS + "changefreq") != null)
                            {
                                el.Element(NS + "changefreq").Value = change.ToString().ToLower();
                            }
                            else
                            {
                                XElement ch = new XElement(NS + "changefreq", change.ToString().ToLower());
                                el.Add(ch);
                            }
                            //Сохраняем изменения в файл и указываем, что изменения внесены
                            doc.Save(pathFile);
                            modified = true;
                            return(true);
                        }
                    }
                }
                //Если изменения не внесены, значит не было найдено совпадение по url
                //Значит добавляем новый элемент в карту сайта
                if (!modified)
                {
                    return(AddItem(pathFile, url, dateModified, change, priority));
                }
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.StackTrace);
                return(false);
            }
        }
Example #34
0
        /// <summary>
        /// Добавляет элемент в карту сайта
        /// </summary>
        /// <param name="pathFile">Путь к файлу карты сайта</param>
        /// <param name="url">Ссылка, которую необходимо добавить</param>
        /// <param name="dateModified">Дата модификации</param>
        /// <param name="change">Когда роботу нужно делать переобход</param>
        /// <param name="priority">Приоритет. От 0.1 до 1.0</param>
        /// <returns>Успешное выполнение</returns>
        public static bool AddItem(string pathFile, string url, DateTime dateModified, ChangeFrequency change, double priority)
        {
            try
            {
                //Проверяем наличие файла карты сайта,
                //если карта сайта не найдена, то создаем файл карты сайта
                if (!File.Exists(pathFile))
                {
                    CreateSitemap(pathFile);
                }

                XDocument  doc = XDocument.Load(pathFile);
                XNamespace NS  = doc.Root.GetDefaultNamespace();

                //Карты сайта имеют ограниечение на 50000 записей
                //проверяе количество записей
                //если число записей достигло предела, возвращаем false
                if (doc.Root.Nodes().Count() > 49998)
                {
                    Console.WriteLine("Превышено количество записей для одной карты сайта");
                    return(false);
                }

                XElement u   = new XElement(NS + "url");
                XElement loc = new XElement(NS + "loc", url);

                u.Add(loc);
                u.Add(new XElement(NS + "lastmod", dateModified.ToString("yyyy-MM-ddTHH:mm:ss.f") + "+00:00"));
                u.Add(new XElement(NS + "priority", priority.ToString("N1", CultureInfo.InvariantCulture)));
                u.Add(new XElement(NS + "changefreq", change.ToString().ToLower()));

                doc.Root.Add(u);
                doc.Save(pathFile);

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Ошибка при добавлении элемента в карту сайта");
                Console.WriteLine(ex.Message + ex.StackTrace);
                return(false);
            }
        }
        private void AssertStaticPageIsIncludedInSitemap(string url, double priority, ChangeFrequency changeFrequency)
        {
            _autoMocker.ClassUnderTest.BuildStaticPagesSitemap(_targetDirectory);

            //--assert
            _autoMocker.Get <ISitemapGenerator>()
            .Received()
            .GenerateSitemaps(
                Arg.Is <List <Url> >(x => MatchUrl(x, url, priority, changeFrequency)),
                Arg.Any <DirectoryInfo>(),
                Arg.Any <string>());
        }
 public void It_Saves_The_Most_Important_Static_Pages_In_The_Sitemap(string url, double priority, ChangeFrequency changeFrequency)
 {
     //--act/assert
     AssertStaticPageIsIncludedInSitemap(url, priority, changeFrequency);
 }
        public override void ProcessRequest()
        {
            HttpContextBase context = SubtextContext.HttpContext;

            context.Response.ContentType = "text/xml";

            var urlCollection = new UrlCollection();

            // Let's add home page
            var homePage = new UrlElement(Url.BlogUrl().ToFullyQualifiedUrl(Blog), DateTime.UtcNow, ChangeFrequency.Daily, 1.0M);

            urlCollection.Add(homePage);

            // then all the entries

            ICollection <Entry> posts = Repository.GetEntries(0, PostType.BlogPost, PostConfig.IsActive, false
                                                              /* includeCategories */);

            if (posts != null)
            {
                foreach (Entry post in posts)
                {
                    ChangeFrequency frequency = CalculateFrequency(post);
                    urlCollection.Add(
                        new UrlElement(Url.EntryUrl(post).ToFullyQualifiedUrl(Blog), post.DateModifiedUtc,
                                       frequency, 0.8M));
                }
            }

            // all articles
            ICollection <Entry> stories = Repository.GetEntries(0, PostType.Story, PostConfig.IsActive, false
                                                                /* includeCategories */);

            if (stories != null)
            {
                foreach (Entry story in stories)
                {
                    ChangeFrequency frequency = CalculateFrequency(story);
                    urlCollection.Add(
                        new UrlElement(Url.EntryUrl(story).ToFullyQualifiedUrl(Blog),
                                       story.DateModifiedUtc,
                                       frequency, 0.8M));
                }
            }

            // categories
            ICollection <LinkCategory> links = Repository.GetCategories(CategoryType.PostCollection, true
                                                                        /* activeOnly */);
            LinkCategory categories = Transformer.MergeLinkCategoriesIntoSingleLinkCategory(string.Empty /* title */,
                                                                                            CategoryType.PostCollection,
                                                                                            links, Url, Blog);

            if (categories != null)
            {
                foreach (Link category in categories.Links)
                {
                    urlCollection.Add(
                        new UrlElement(new Uri(Url.BlogUrl().ToFullyQualifiedUrl(Blog) + category.Url),
                                       DateTime.Today,
                                       ChangeFrequency.Weekly, 0.6M));
                }
            }

            // archives
            // categories
            ICollection <ArchiveCount> archiveCounts = Repository.GetPostCountsByMonth();
            LinkCategory archives = archiveCounts.MergeIntoLinkCategory(string.Empty, Url, Blog);

            if (archives != null)
            {
                foreach (Link archive in archives.Links)
                {
                    urlCollection.Add(
                        new UrlElement(
                            new Uri(Url.BlogUrl().ToFullyQualifiedUrl(Blog) + archive.Url), DateTime.Today,
                            ChangeFrequency.Weekly, 0.6M));
                }
            }

            // don't index contact form
            urlCollection.Add(new UrlElement(Url.ContactFormUrl().ToFullyQualifiedUrl(Blog), DateTime.Today,
                                             ChangeFrequency.Never, 0.0M));
            var serializer    = new XmlSerializer(typeof(UrlCollection));
            var xmlTextWriter = new XmlTextWriter(context.Response.Output);

            serializer.Serialize(xmlTextWriter, urlCollection);
        }
Example #38
0
 public SitemapUrl()
 {
     //Constructor
     _changefreq = ChangeFrequency.Never;
     _priority = null;
 }
Example #39
0
 public SitemapCore()
 {
     _urls            = new List <SitemapUrl>();
     _changeFrequency = ChangeFrequency.Never;
     _priority        = 0.5;
 }
 private bool MatchUrl(List<Url> urls, string url, double priority, ChangeFrequency changeFrequency)
 {
     return
         urls.Any(
             x =>
                 x.ChangeFrequency == changeFrequency && x.Priority == priority && x.Location == url &&
                 x.TimeStamp.Date == DateTime.UtcNow.Date);
 }
Example #41
0
 public SeoDynamicNodeProvider(string catalogActionName, ChangeFrequency nodeChangeFrequency)
     : base(nodeChangeFrequency)
 {
     _catalogActionName = catalogActionName;
 }