/// <summary>takes the updated entry returned and sets the properties to this object</summary>
        /// <param name="updatedEntry"> </param>
        protected void CopyEntry(AtomEntry updatedEntry)
        {
            Tracing.Assert(updatedEntry != null, "updatedEntry should not be null");
            if (updatedEntry == null)
            {
                throw new ArgumentNullException("updatedEntry");
            }

            _title           = updatedEntry.Title;
            _authors         = updatedEntry.Authors;
            _id              = updatedEntry.Id;
            _links           = updatedEntry.Links;
            _lastUpdateDate  = updatedEntry.Updated;
            _publicationDate = updatedEntry.Published;
            _authors         = updatedEntry.Authors;
            _rights          = updatedEntry.Rights;
            _categories      = updatedEntry.Categories;
            _summary         = updatedEntry.Summary;
            _content         = updatedEntry.Content;
            _source          = updatedEntry.Source;

            ExtensionElements.Clear();

            foreach (IExtensionElementFactory extension in updatedEntry.ExtensionElements)
            {
                ExtensionElements.Add(extension);
            }
        }
Esempio n. 2
0
        ///<summary>Standard type converter method</summary>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, System.Type destinationType)
        {
            AtomSource atomSource = value as AtomSource;

            if (destinationType == typeof(System.String) && atomSource != null)
            {
                return("Feed: " + atomSource.Title);
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
        /// <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;
        }