Beispiel #1
0
        public void UrlElement_CtorSetsPriority_ToLessThanZero()
        {
            // using property
            var url = new UrlElement();

            UnitTestHelper.AssertThrows<ArgumentOutOfRangeException>(() => url.Priority = -0.5M);
        }
Beispiel #2
0
 public void UrlElement_WithPropertiesSet_ReturnsSameValuesForProperties()
 {
     var url = new UrlElement(new Uri("http://someurl.com"), DateTime.MinValue, ChangeFrequency.Never, 0);
     StringAssert.AreEqualIgnoreCase("http://someurl.com/", url.Location);
     Assert.AreEqual(DateTime.MinValue, url.LastModified);
     Assert.AreEqual(ChangeFrequency.Never, url.ChangeFrequency);
     Assert.AreEqual(0, url.Priority);
 }
        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);
        }
        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);
        }