private static AtomFeed CreateNewPage(
            IEnumerable <AtomEntry> entries,
            IEnumerable <AtomLink> links,
            DateTimeOffset now)
        {
            var selfLink = links.Single(l => l.IsSelfLink);
            var id       = AtomEventStorage.GetIdFromHref(selfLink.Href);

            return(new AtomFeed(
                       id,
                       "Partial event stream",
                       now,
                       new AtomAuthor("Grean"),
                       entries,
                       links));
        }
Beispiel #2
0
        /// <summary>
        /// Creates an <see cref="XmlReader" /> for reading an Atom feed from
        /// the provided <see cref="Uri" />.
        /// </summary>
        /// <param name="href">
        /// The relative <see cref="Uri" /> of the Atom feed to read.
        /// </param>
        /// <returns>
        /// An <see cref="XmlReader" /> over the Atom feed identified by
        /// <paramref name="href" />.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="href" /> is <see langword="null" />.
        /// </exception>
        /// <remarks>
        /// <para>
        /// This method attempts to find a file corresponding to
        /// <paramref name="href" />. If the file is found, an
        /// <see cref="XmlReader" /> over that file is created and returned. If
        /// the file isn't found, an XmlReader over an empty Atom Feed is
        /// returned. In this case, no file is created for the empty Atom Feed.
        /// In other words: this method has no observable side-effects.
        /// </para>
        /// </remarks>
        public XmlReader CreateFeedReaderFor(Uri href)
        {
            if (href == null)
            {
                throw new ArgumentNullException("href");
            }

            var fileName = this.CreateFileName(href);

            if (File.Exists(fileName))
            {
                return(XmlReader.Create(fileName));
            }

            return(AtomEventStorage.CreateNewFeed(href));
        }
Beispiel #3
0
        private void AddToIndexesIfIndex(AtomFeed atomFeed)
        {
            /* Look for self links which indicate that this Atom Feed is an
             * indexed index. The pattern to look for is:
             * id/id
             * i.e. a segmented URL where the first and last segment are
             * identical. */
            var selfLink = atomFeed.Links.Single(l => l.IsSelfLink);
            var segments = AtomEventStorage
                           .GetSegmentsFrom(selfLink.Href)
                           .Select(s => s.Trim('/'))
                           .Where(s => !string.IsNullOrWhiteSpace(s))
                           .ToArray();

            if (segments.Length == 2 && segments[0] == segments[1])
            {
                this.indexes.Add(atomFeed.Id);
            }
        }
Beispiel #4
0
        public XmlReader CreateFeedReaderFor(Uri href)
        {
            if (href == null)
            {
                throw new ArgumentNullException("href");
            }

            this.rwLock.EnterReadLock();
            try
            {
                if (this.feeds.ContainsKey(href))
                {
                    return(CreateReaderOver(this.feeds[href].ToString()));
                }
                else
                {
                    return(AtomEventStorage.CreateNewFeed(href));
                }
            }
            finally
            {
                this.rwLock.ExitReadLock();
            }
        }