Exemple #1
0
        /// <summary>
        /// used to create a feed based on a stream
        /// </summary>
        /// <param name="inputStream"></param>
        /// <param name="uriToUse"></param>
        /// <returns></returns>
        internal AtomFeed CreateAndParseFeed(Stream inputStream, Uri uriToUse)
        {
            AtomFeed returnFeed = null;

            if (inputStream != null)
            {
                returnFeed = CreateFeed(uriToUse);
                _versionInfo.ImprintVersion(returnFeed);
                try
                {
                    returnFeed.NewAtomEntry        += new FeedParserEventHandler(OnParsedNewEntry);
                    returnFeed.NewExtensionElement += new ExtensionElementEventHandler(OnNewExtensionElement);
                    returnFeed.Parse(inputStream, AlternativeFormat.Atom);
                }
                finally
                {
                    inputStream.Close();
                }
            }

            return(returnFeed);
        }
Exemple #2
0
        /// <summary>creates a new feed instance to be returned by
        /// Batch(), Query() and other operations
        ///
        /// Subclasses can supply their own feed implementation by
        /// overriding this method.
        /// </summary>
        protected virtual AtomFeed CreateFeed(Uri uriToUse)
        {
            ServiceEventArgs args = null;
            AtomFeed         feed = null;

            if (NewFeed != null)
            {
                args = new ServiceEventArgs(uriToUse, this);
                NewFeed(this, args);
            }

            if (args != null)
            {
                feed = args.Feed;
            }

            if (feed == null)
            {
                feed = new AtomFeed(uriToUse, this);
            }

            return(feed);
        }
Exemple #3
0
        /// <summary>public AtomSource(AtomFeed feed)</summary>
        public AtomSource(AtomFeed feed)
            : this()
        {
            Tracing.Assert(feed != null, "feed should not be null");
            if (feed == null)
            {
                throw new ArgumentNullException("feed");
            }

            // now copy them
            _authors      = feed.Authors;
            _contributors = feed.Contributors;
            _categories   = feed.Categories;
            Generator     = feed.Generator;
            Icon          = feed.Icon;
            Logo          = feed.Logo;
            Id            = feed.Id;
            _links        = feed.Links;
            Rights        = feed.Rights;
            Subtitle      = feed.Subtitle;
            Title         = feed.Title;
            Updated       = feed.Updated;
        }
        /// <summary>
        /// parses the current position in the xml reader and fills
        /// the provided GDataFeedBatch property on the feed object
        /// </summary>
        /// <param name="reader">the xmlreader positioned at a batch element</param>
        /// <param name="feed">the atomfeed object to fill in</param>
        protected void ParseBatch(XmlReader reader, AtomFeed feed)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (feed == null)
            {
                throw new ArgumentNullException("feed");
            }

            if (IsCurrentNameSpace(reader, BaseNameTable.gBatchNamespace))
            {
                object elementName = reader.LocalName;

                if (feed.BatchData == null)
                {
                    feed.BatchData = new GDataBatchFeedData();
                }

                GDataBatchFeedData batch = feed.BatchData;

                if (elementName.Equals(_nameTable.BatchOperation))
                {
                    batch.Type = (GDataBatchOperationType)Enum.Parse(
                        typeof(GDataBatchOperationType),
                        reader.GetAttribute(BaseNameTable.XmlAttributeType), true);
                }
                else
                {
                    Tracing.TraceInfo("got an unknown batch element: " + elementName.ToString());
                    reader.Skip();
                }
            }
        }
Exemple #5
0
        /// <summary>public WebResponse Insert(Uri insertUri, Stream entryStream, ICredentials credentials)</summary>
        /// <param name="feed">the feed this entry should be inserted into</param>
        /// <param name="entry">the entry to be inserted</param>
        /// <returns> the inserted entry</returns>
        AtomEntry IService.Insert(AtomFeed feed, AtomEntry entry)
        {
            Tracing.Assert(feed != null, "feed should not be null");
            if (feed == null)
            {
                throw new ArgumentNullException("feed");
            }

            Tracing.Assert(entry != null, "entry should not be null");
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            if (feed.ReadOnly)
            {
                throw new GDataRequestException("Can not update a read-only feed");
            }

            Tracing.TraceMsg("Post URI is: " + feed.Post);
            Uri target = new Uri(feed.Post);

            return(Insert(target, entry));
        }
 public AsyncSendData(AsyncDataHandler handler, Uri uriToUse, AtomFeed feed, SendOrPostCallback callback, object userData)
     : this(handler, uriToUse, null, feed, callback, userData, false)
 {
 }
 private AsyncSendData(AsyncDataHandler handler, Uri uriToUse, AtomEntry entry, AtomFeed feed,
                       SendOrPostCallback callback, object userData, bool parseFeed)
     : base(uriToUse, null, userData, callback, parseFeed)
 {
     DataHandler = handler;
     _entry      = entry;
     Feed        = feed;
 }
        /// <summary>parses xml to fill a precreated AtomSource object (might be a feed)</summary>
        /// <param name="reader">correctly positioned reader</param>
        /// <param name="source">created source object to be filled</param>
        /// <returns> </returns>
        protected void ParseSource(XmlReader reader, AtomSource source)
        {
            Tracing.Assert(reader != null, "reader should not be null");
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            Tracing.Assert(source != null, "source should not be null");
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            Tracing.TraceCall();

            int depth = -1;

            ParseBasicAttributes(reader, source);

            while (NextChildElement(reader, ref depth))
            {
                object   localname = reader.LocalName;
                AtomFeed feed      = source as AtomFeed;
                if (IsCurrentNameSpace(reader, BaseNameTable.NSAtom))
                {
                    if (localname.Equals(_nameTable.Title))
                    {
                        source.Title = ParseTextConstruct(reader, source);
                    }
                    else if (localname.Equals(_nameTable.Updated))
                    {
                        source.Updated = DateTime.Parse(Utilities.DecodedValue(reader.ReadString()), CultureInfo.InvariantCulture);
                    }
                    else if (localname.Equals(_nameTable.Link))
                    {
                        source.Links.Add(ParseLink(reader, source));
                    }
                    else if (localname.Equals(_nameTable.Id))
                    {
                        source.Id = source.CreateAtomSubElement(reader, this) as AtomId;
                        ParseBaseLink(reader, source.Id);
                    }
                    else if (localname.Equals(_nameTable.Icon))
                    {
                        source.Icon = source.CreateAtomSubElement(reader, this) as AtomIcon;
                        ParseBaseLink(reader, source.Icon);
                    }
                    else if (localname.Equals(_nameTable.Logo))
                    {
                        source.Logo = source.CreateAtomSubElement(reader, this) as AtomLogo;
                        ParseBaseLink(reader, source.Logo);
                    }
                    else if (localname.Equals(_nameTable.Author))
                    {
                        source.Authors.Add(ParsePerson(reader, source));
                    }
                    else if (localname.Equals(_nameTable.Contributor))
                    {
                        source.Contributors.Add(ParsePerson(reader, source));
                    }
                    else if (localname.Equals(_nameTable.Subtitle))
                    {
                        source.Subtitle = ParseTextConstruct(reader, source);
                    }
                    else if (localname.Equals(_nameTable.Rights))
                    {
                        source.Rights = ParseTextConstruct(reader, source);
                    }
                    else if (localname.Equals(_nameTable.Generator))
                    {
                        source.Generator = ParseGenerator(reader, source);
                    }
                    else if (localname.Equals(_nameTable.Category))
                    {
                        // need to make this another colleciton
                        source.Categories.Add(ParseCategory(reader, source));
                    }
                    else if (feed != null && localname.Equals(_nameTable.Entry))
                    {
                        ParseEntry(reader);
                    }

                    // this will either move the reader to the end of an element
                    // if at the end, to the start of a new one.
                    reader.Read();
                }
                else if (feed != null && IsCurrentNameSpace(reader, BaseNameTable.gBatchNamespace))
                {
                    // parse the google batch extensions if they are there
                    ParseBatch(reader, feed);
                }
                else if (feed != null && (IsCurrentNameSpace(reader, BaseNameTable.NSOpenSearchRss) || IsCurrentNameSpace(reader, BaseNameTable.NSOpenSearch11)))
                {
                    if (localname.Equals(_nameTable.TotalResults))
                    {
                        feed.TotalResults = int.Parse(Utilities.DecodedValue(reader.ReadString()), CultureInfo.InvariantCulture);
                    }
                    else if (localname.Equals(_nameTable.StartIndex))
                    {
                        feed.StartIndex = int.Parse(Utilities.DecodedValue(reader.ReadString()), CultureInfo.InvariantCulture);
                    }
                    else if (localname.Equals(_nameTable.ItemsPerPage))
                    {
                        feed.ItemsPerPage = int.Parse(Utilities.DecodedValue(reader.ReadString()), CultureInfo.InvariantCulture);
                    }
                }
                else
                {
                    // default extension parsing.
                    ParseExtensionElements(reader, source);
                }
            }

            return;
        }
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////

        /// <summary>starts the parsing process</summary>
        /// <param name="streamInput">input stream to parse </param>
        /// <param name="feed">the feed object to construct</param>
        //////////////////////////////////////////////////////////////////////
        public override void Parse(Stream streamInput, AtomFeed feed)
        {
        }
Exemple #10
0
        /// <summary>overloaded to make eventfiring easier</summary>
        /// <param name="feed"> the new feed to fire</param>
        protected void OnNewAtomEntry(AtomFeed feed)
        {
            FeedParserEventArgs args = new FeedParserEventArgs(feed, null);

            OnNewAtomEntry(args);
        }
Exemple #11
0
 /// <summary>virtual, starts the parsing process</summary>
 /// <param name="streamInput">input stream to parse </param>
 /// <param name="feed">the basefeed object that should be set</param>
 public abstract void Parse(Stream streamInput, AtomFeed feed);
 /// <summary>constructor</summary>
 public AtomEntryCollection(AtomFeed feed)
     : base()
 {
     _feed = feed;
 }
Exemple #13
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////

        /// <summary>default constructor so that FxCop does not complain</summary>
        //////////////////////////////////////////////////////////////////////
        public GDataBatchRequestException(AtomFeed batchResult)
        {
            _batchResult = batchResult;
        }
Exemple #14
0
        /// <summary>
        /// templated type safe version of Insert
        /// </summary>
        /// <typeparam name="TEntry"></typeparam>
        /// <param name="feed"></param>
        /// <param name="entry"></param>
        /// <returns> the new Entry, as returned from the server</returns>
        public TEntry Insert <TEntry>(AtomFeed feed, TEntry entry) where TEntry : AtomEntry
        {
            IService s = this as IService;

            return(s.Insert(feed, entry) as TEntry);
        }
Exemple #15
0
 /// <summary>
 /// takes a given feed, and does a batch post of that feed
 /// against the batchUri parameter. If that one is NULL
 /// it will try to use the batch link URI in the feed
 /// </summary>
 /// <param name="feed">the feed to post</param>
 /// <param name="batchUri">the URI to user</param>
 /// <returns>the returned AtomFeed</returns>
 public AtomFeed Batch(AtomFeed feed, Uri batchUri)
 {
     return(Batch(feed, batchUri, null));
 }