Esempio n. 1
0
 /// <summary>
 /// Inserts an element into the AtomEntryCollection at the specified index
 /// </summary>
 /// <param name="index">
 /// The index at which the AtomEntry is to be inserted.
 /// </param>
 /// <param name="value">
 /// The AtomEntry to insert.
 /// </param>
 public virtual void Insert(int index, AtomEntry value)
 {
     this.List.Insert(index, value);
 }
Esempio n. 2
0
 /// <summary>
 /// Removes the first occurrence of a specific AtomEntry from this AtomEntryCollection.
 /// </summary>
 /// <param name="value">
 /// The AtomEntry value to remove from this AtomEntryCollection.
 /// </param>
 public virtual void Remove(AtomEntry value)
 {
     this.List.Remove(value);
 }
Esempio n. 3
0
 /// <summary>
 /// Determines whether a specfic AtomEntry value is in this AtomEntryCollection.
 /// </summary>
 /// <param name="value">
 /// The AtomEntry value to locate in this AtomEntryCollection.
 /// </param>
 /// <returns>
 /// true if value is found in this AtomEntryCollection;
 /// false otherwise.
 /// </returns>
 public virtual bool Contains(AtomEntry value)
 {
     return(this.List.Contains(value));
 }
Esempio n. 4
0
 /// <summary>
 /// Return the zero-based index of the first occurrence of a specific value
 /// in this AtomEntryCollection
 /// </summary>
 /// <param name="value">
 /// The AtomEntry value to locate in the AtomEntryCollection.
 /// </param>
 /// <returns>
 /// The zero-based index of the first occurrence of the _ELEMENT value if found;
 /// -1 otherwise.
 /// </returns>
 public virtual int IndexOf(AtomEntry value)
 {
     return(this.List.IndexOf(value));
 }
        private AtomRoot GetAtomCore(string category, int maxDayCount, int maxEntryCount)
        {
            if (RedirectToFeedBurnerIfNeeded(category) == true)
            {
                return null;
            }

            EntryCollection entries = null;
            //We only build the entries if blogcore doesn't exist and we'll need them later...
            if (dataService.GetLastEntryUpdate() == DateTime.MinValue)
            {
                entries = BuildEntries(category, maxDayCount, maxEntryCount);
            }

            //Try to get out as soon as possible with as little CPU as possible
            if ( inASMX )
            {
                if (SiteUtilities.GetStatusNotModified(SiteUtilities.GetLatestModifedEntryDateTime(dataService, entries)))
                    return null;
            }

            if ( inASMX )
            {
                string referrer = Context.Request.UrlReferrer!=null?Context.Request.UrlReferrer.AbsoluteUri:"";
                if (ReferralBlackList.IsBlockedReferrer(referrer))
                {
                    if (siteConfig.EnableReferralUrlBlackList404s)
                    {
                        return null;
                    }
                }
                else
                {
                    loggingService.AddReferral(
                        new LogDataItem(
                        Context.Request.RawUrl,
                        referrer,
                        Context.Request.UserAgent,
                        Context.Request.UserHostName));
                }
            }

            //not-modified didn't work, do we have this in cache?
            string CacheKey = "Atom:" + category + ":" + maxDayCount.ToString() + ":" + maxEntryCount.ToString();
            AtomRoot atomFeed = cache[CacheKey] as AtomRoot;
            if (atomFeed == null) //we'll have to build it...
            {
                atomFeed = new AtomRoot();

                //However, if we made it this far, the not-modified check didn't work, and we may not have entries...
                if(entries == null)
                {
                    entries = BuildEntries(category, maxDayCount, maxEntryCount);
                }

                if (siteConfig.RssLanguage != null && siteConfig.RssLanguage.Length >0)
                {
                    atomFeed.Lang = siteConfig.RssLanguage;
                }
                else //original default behavior of dasBlog
                {
                    atomFeed.Lang = "en-us";
                }

                if(category == null)
                {
                    atomFeed.Title = siteConfig.Title;
                }
                else
                {
                    atomFeed.Title = siteConfig.Title + " - " + category;
                }

                atomFeed.Tagline = siteConfig.Subtitle;
                atomFeed.Links.Add(new AtomLink(SiteUtilities.GetBaseUrl(siteConfig)));
                atomFeed.Links.Add(new AtomLink(SiteUtilities.GetAtomUrl(siteConfig),"self",null));
                atomFeed.Author = new AtomParticipant();
                atomFeed.Author.Name = siteConfig.Copyright;
                atomFeed.Generator = new AtomGenerator();
                atomFeed.Generator.Version = GetType().Assembly.GetName().Version.ToString();
                atomFeed.Icon = "favicon.ico";

                atomFeed.Id = SiteUtilities.GetBaseUrl(siteConfig);

                atomFeed.Logo = null;
                if (siteConfig.ChannelImageUrl != null && siteConfig.ChannelImageUrl.Trim().Length > 0)
                {
                    if (siteConfig.ChannelImageUrl.StartsWith("http"))
                    {
                        atomFeed.Logo = siteConfig.ChannelImageUrl;
                    }
                    else
                    {
                        atomFeed.Logo= SiteUtilities.RelativeToRoot(siteConfig,siteConfig.ChannelImageUrl);
                    }
                }

                DateTime feedModified = DateTime.MinValue;

                foreach (Entry entry in entries)
                {
                    if (entry.IsPublic == false || entry.Syndicated == false)
                    {
                        continue;
                    }

                    string entryLink = SiteUtilities.GetPermaLinkUrl(siteConfig, entry);
                    string entryGuid = SiteUtilities.GetPermaLinkUrl(siteConfig, entry.EntryId);

                    AtomEntry atomEntry = new AtomEntry(entry.Title, new AtomLink(entryLink), entryGuid, entry.CreatedUtc, entry.ModifiedUtc);
                    //atomEntry.Created = entry.CreatedUtc; //not needed in 1.0
                    atomEntry.Summary = PreprocessItemContent(entry.EntryId, entry.Description);

                    if (entry.Categories != null && entry.Categories.Length > 0)
                    {
                        if(atomEntry.Categories == null) atomEntry.Categories = new AtomCategoryCollection();

                        string[] cats = entry.Categories.Split(';');
                        foreach(string c in cats)
                        {
                            AtomCategory cat = new AtomCategory();

                            //paulb: scheme should be a valid IRI, acsording to the spec
                            // (http://www.atomenabled.org/developers/syndication/atom-format-spec.php#element.category)
                            // so I changed this to the Category view for specified category. Now the feed validator likes us again ;-)
                            cat.Scheme = SiteUtilities.GetCategoryViewUrl( siteConfig, c ); // "hierarchical";
                            // sub categories should be delimited using the path delimiter
                            string cleanCat = c.Replace('|', '/');
                            //Grab the first category, atom doesn't let us do otherwise!
                            cat.Term = HttpUtility.HtmlEncode(cleanCat);
                            cat.Label = HttpUtility.HtmlEncode(cleanCat);
                            atomEntry.Categories.Add(cat);
                        }
                    }

                    // only if we don't have a summary we emit the content
                    if ( siteConfig.AlwaysIncludeContentInRSS || entry.Description == null || entry.Description.Length == 0 )
                    {
                        atomEntry.Summary = null; // remove empty summary tag

                        try
                        {
                            AtomContent atomContent = new AtomContent();
                            atomContent.Type = "xhtml";

                            XmlDocument xmlDoc2 = new XmlDocument();
                            xmlDoc2.LoadXml(ContentFormatter.FormatContentAsXHTML(PreprocessItemContent(entry.EntryId, entry.Content),"div"));
                            atomContent.anyElements = new XmlElement[]{xmlDoc2.DocumentElement};

                            // set the langauge for the content item
                            atomContent.Lang = entry.Language;

                            atomEntry.Content = atomContent;
                        }
                        catch(Exception) //XHTML isn't happening today
                        {
                            //Try again as HTML
                            AtomContent atomContent = new AtomContent();
                            atomContent.Type = "html";
                            atomContent.TextContent = ContentFormatter.FormatContentAsHTML(PreprocessItemContent(entry.EntryId, entry.Content));
                            // set the langauge for the content item
                            atomContent.Lang = entry.Language;

                            atomEntry.Content = atomContent;
                        }
                    }

                    if (atomEntry.ModifiedUtc > feedModified)
                        feedModified = atomEntry.ModifiedUtc;

                    atomFeed.Entries.Add(atomEntry);
                }

                // set feed modified date to the most recent entry date
                atomFeed.ModifiedUtc = feedModified;
                cache.Insert(CacheKey,atomFeed,DateTime.Now.AddMinutes(5));
            }
            return atomFeed;
        }
Esempio n. 6
0
 /// <summary>
 /// Adds an instance of type AtomEntry to the end of this AtomEntryCollection.
 /// </summary>
 /// <param name="value">
 /// The AtomEntry to be added to the end of this AtomEntryCollection.
 /// </param>
 public virtual void Add(AtomEntry value)
 {
     this.List.Add(value);
 }
Esempio n. 7
0
		/// <summary>
		/// Inserts an element into the AtomEntryCollection at the specified index
		/// </summary>
		/// <param name="index">
		/// The index at which the AtomEntry is to be inserted.
		/// </param>
		/// <param name="value">
		/// The AtomEntry to insert.
		/// </param>
		public virtual void Insert(int index, AtomEntry value)
		{
			this.List.Insert(index, value);
		}
Esempio n. 8
0
		/// <summary>
		/// Removes the first occurrence of a specific AtomEntry from this AtomEntryCollection.
		/// </summary>
		/// <param name="value">
		/// The AtomEntry value to remove from this AtomEntryCollection.
		/// </param>
		public virtual void Remove(AtomEntry value)
		{
			this.List.Remove(value);
		}
Esempio n. 9
0
		/// <summary>
		/// Return the zero-based index of the first occurrence of a specific value
		/// in this AtomEntryCollection
		/// </summary>
		/// <param name="value">
		/// The AtomEntry value to locate in the AtomEntryCollection.
		/// </param>
		/// <returns>
		/// The zero-based index of the first occurrence of the _ELEMENT value if found;
		/// -1 otherwise.
		/// </returns>
		public virtual int IndexOf(AtomEntry value)
		{
			return this.List.IndexOf(value);
		}
Esempio n. 10
0
		/// <summary>
		/// Determines whether a specfic AtomEntry value is in this AtomEntryCollection.
		/// </summary>
		/// <param name="value">
		/// The AtomEntry value to locate in this AtomEntryCollection.
		/// </param>
		/// <returns>
		/// true if value is found in this AtomEntryCollection;
		/// false otherwise.
		/// </returns>
		public virtual bool Contains(AtomEntry value)
		{
			return this.List.Contains(value);
		}
Esempio n. 11
0
		/// <summary>
		/// Adds an instance of type AtomEntry to the end of this AtomEntryCollection.
		/// </summary>
		/// <param name="value">
		/// The AtomEntry to be added to the end of this AtomEntryCollection.
		/// </param>
		public virtual void Add(AtomEntry value)
		{
			this.List.Add(value);
		}
Esempio n. 12
0
		/// <summary>
		/// Adds the elements of an array to the end of this AtomEntryCollection.
		/// </summary>
		/// <param name="entries">
		/// The array whose elements are to be added to the end of this AtomEntryCollection.
		/// </param>
		public virtual void AddRange(AtomEntry[] entries)
		{
			foreach (AtomEntry entry in entries)
			{
				this.List.Add(entry);
			}
		}
Esempio n. 13
0
		/// <summary>
		/// Initializes a new instance of the AtomEntryCollection class, containing elements
		/// copied from an array.
		/// </summary>
		/// <param name="entries">
		/// The array whose elements are to be added to the new AtomEntryCollection.
		/// </param>
		public AtomEntryCollection(AtomEntry[] entries)
		{
			this.AddRange(entries);
		}