Esempio n. 1
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="ApmlConcept"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="ApmlConcept"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="ApmlConcept"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string keyAttribute     = source.GetAttribute("key", String.Empty);
                string valueAttribute   = source.GetAttribute("value", String.Empty);
                string fromAttribute    = source.GetAttribute("from", String.Empty);
                string updatedAttribute = source.GetAttribute("updated", String.Empty);

                if (!String.IsNullOrEmpty(keyAttribute))
                {
                    this.Key  = keyAttribute;
                    wasLoaded = true;
                }

                if (!String.IsNullOrEmpty(valueAttribute))
                {
                    decimal value;
                    if (Decimal.TryParse(valueAttribute, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.InvariantInfo, out value))
                    {
                        if (value >= Decimal.MinusOne && value <= Decimal.One)
                        {
                            this.Value = value;
                            wasLoaded  = true;
                        }
                    }
                }

                if (!String.IsNullOrEmpty(fromAttribute))
                {
                    this.From = fromAttribute;
                    wasLoaded = true;
                }

                if (!String.IsNullOrEmpty(updatedAttribute))
                {
                    DateTime updatedOn;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedAttribute, out updatedOn))
                    {
                        this.UpdatedOn = updatedOn;
                        wasLoaded      = true;
                    }
                }
            }

            return(wasLoaded);
        }
Esempio n. 2
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source, XmlNamespaceManager manager)
        /// <summary>
        /// Initializes the syndication extension context using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="AtomPublishingEditedSyndicationExtensionContext"/>.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed syndication extension elements and attributes.</param>
        /// <returns><b>true</b> if the <see cref="AtomPublishingEditedSyndicationExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source, XmlNamespaceManager manager)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            if (source.HasChildren)
            {
                XPathNavigator editedNavigator = source.SelectSingleNode("app:edited", manager);
                if (editedNavigator != null && !String.IsNullOrEmpty(editedNavigator.Value))
                {
                    DateTime editedOn;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(editedNavigator.Value, out editedOn))
                    {
                        this.EditedOn = editedOn;
                        wasLoaded     = true;
                    }
                }
            }

            return(wasLoaded);
        }
Esempio n. 3
0
        /// <summary>
        /// Saves the current <see cref="ApmlSource"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public void WriteTo(XmlWriter writer)
        {
            Guard.ArgumentNotNull(writer, "writer");
            writer.WriteStartElement("Source", ApmlUtility.ApmlNamespace);

            writer.WriteAttributeString("key", this.Key);
            writer.WriteAttributeString("name", this.Name);
            writer.WriteAttributeString("value", this.Value.ToString("0.00", System.Globalization.NumberFormatInfo.InvariantInfo));
            writer.WriteAttributeString("type", this.MimeType);

            if (!String.IsNullOrEmpty(this.From))
            {
                writer.WriteAttributeString("from", this.From);
            }

            if (this.UpdatedOn != DateTime.MinValue)
            {
                writer.WriteAttributeString("updated", SyndicationDateTimeUtility.ToRfc3339DateTime(this.UpdatedOn));
            }

            foreach (ApmlAuthor author in this.Authors)
            {
                author.WriteTo(writer);
            }
            SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);

            writer.WriteEndElement();
        }
        /// <summary>
        /// Saves the current <see cref="FeedSynchronizationHistory"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public void WriteTo(XmlWriter writer)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");

            //------------------------------------------------------------
            //	Create extension instance to retrieve XML namespace
            //------------------------------------------------------------
            FeedSynchronizationSyndicationExtension extension = new FeedSynchronizationSyndicationExtension();

            //------------------------------------------------------------
            //	Write XML representation of the current instance
            //------------------------------------------------------------
            writer.WriteStartElement("history", extension.XmlNamespace);

            writer.WriteAttributeString("sequence", this.Sequence.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));

            if (this.When != DateTime.MinValue)
            {
                writer.WriteAttributeString("when", SyndicationDateTimeUtility.ToRfc3339DateTime(this.When));
            }

            if (!String.IsNullOrEmpty(this.By))
            {
                writer.WriteAttributeString("when", this.By);
            }

            writer.WriteEndElement();
        }
Esempio n. 5
0
        /// <summary>
        /// Saves the current <see cref="ApmlConcept"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public void WriteTo(XmlWriter writer)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");

            //------------------------------------------------------------
            //	Write XML representation of the current instance
            //------------------------------------------------------------
            writer.WriteStartElement("Concept", ApmlUtility.ApmlNamespace);

            writer.WriteAttributeString("key", this.Key);
            writer.WriteAttributeString("value", this.Value.ToString("0.00", System.Globalization.NumberFormatInfo.InvariantInfo));

            if (!String.IsNullOrEmpty(this.From))
            {
                writer.WriteAttributeString("from", this.From);
            }

            if (this.UpdatedOn != DateTime.MinValue)
            {
                writer.WriteAttributeString("updated", SyndicationDateTimeUtility.ToRfc3339DateTime(this.UpdatedOn));
            }

            //------------------------------------------------------------
            //	Write the syndication extensions of the current instance
            //------------------------------------------------------------
            SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);

            writer.WriteEndElement();
        }
        /// <summary>
        /// Saves the current <see cref="IBlogMLCommonObject"/> attributes to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="source">A object that implements the <see cref="IBlogMLCommonObject"/> interface to extract BlogML common object information from.</param>
        /// <param name="writer">The <see cref="XmlWriter"/> to which the <paramref name="source"/> information will be written.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public static void WriteCommonObjectAttributes(IBlogMLCommonObject source, XmlWriter writer)
        {
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(writer, "writer");

            if (!String.IsNullOrEmpty(source.Id))
            {
                writer.WriteAttributeString("id", source.Id);
            }

            if (source.CreatedOn != DateTime.MinValue)
            {
                writer.WriteAttributeString("date-created", SyndicationDateTimeUtility.ToRfc3339DateTime(source.CreatedOn));
            }

            if (source.LastModifiedOn != DateTime.MinValue)
            {
                writer.WriteAttributeString("date-modified", SyndicationDateTimeUtility.ToRfc3339DateTime(source.LastModifiedOn));
            }

            if (source.ApprovalStatus != BlogMLApprovalStatus.None)
            {
                writer.WriteAttributeString("approved", BlogMLUtility.ApprovalStatusAsString(source.ApprovalStatus));
            }
        }
        /// <summary>
        /// Modifies the <see cref="AtomEntry"/> optional entities to match the supplied <see cref="XPathNavigator"/> data source.
        /// </summary>
        /// <param name="entry">The <see cref="AtomEntry"/> to be filled.</param>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents an Atom 0.3 element.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        private static void FillEntryOptionals(AtomEntry entry, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            Guard.ArgumentNotNull(entry, "entry");
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            XPathNavigator contentNavigator = source.SelectSingleNode("atom:content", manager);
            XPathNavigator createdNavigator = source.SelectSingleNode("atom:created", manager);
            XPathNavigator summaryNavigator = source.SelectSingleNode("atom:summary", manager);

            if (contentNavigator != null)
            {
                entry.Content = Atom03SyndicationResourceAdapter.CreateContent(contentNavigator, manager, settings);
            }

            if (createdNavigator != null)
            {
                DateTime publishedOn;
                if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(createdNavigator.Value, out publishedOn))
                {
                    entry.PublishedOn = publishedOn;
                }
            }

            if (summaryNavigator != null)
            {
                entry.Summary = Atom03SyndicationResourceAdapter.CreateTextContent(summaryNavigator, manager, settings);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Saves the current <see cref="FeedSynchronizationSharingInformation"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public void WriteTo(XmlWriter writer)
        {
            Guard.ArgumentNotNull(writer, "writer");
            FeedSynchronizationSyndicationExtension extension = new FeedSynchronizationSyndicationExtension();

            writer.WriteStartElement("sharing", extension.XmlNamespace);

            if (!String.IsNullOrEmpty(this.Since))
            {
                writer.WriteAttributeString("since", this.Since);
            }

            if (!String.IsNullOrEmpty(this.Until))
            {
                writer.WriteAttributeString("until", this.Until);
            }

            if (this.ExpiresOn != DateTime.MinValue)
            {
                writer.WriteAttributeString("expires", SyndicationDateTimeUtility.ToRfc3339DateTime(this.ExpiresOn));
            }

            foreach (FeedSynchronizationRelatedInformation relation in this.Relations)
            {
                relation.WriteTo(writer);
            }

            writer.WriteEndElement();
        }
        /// <summary>
        /// Saves the current <see cref="ApmlHead"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public void WriteTo(XmlWriter writer)
        {
            Guard.ArgumentNotNull(writer, "writer");
            writer.WriteStartElement("Head", ApmlUtility.ApmlNamespace);

            if (!String.IsNullOrEmpty(this.Title))
            {
                writer.WriteElementString("Title", ApmlUtility.ApmlNamespace, this.Title);
            }

            if (!String.IsNullOrEmpty(this.Generator))
            {
                writer.WriteElementString("Generator", ApmlUtility.ApmlNamespace, this.Generator);
            }

            if (!String.IsNullOrEmpty(this.EmailAddress))
            {
                writer.WriteElementString("UserEmail", ApmlUtility.ApmlNamespace, this.EmailAddress);
            }

            if (this.CreatedOn != DateTime.MinValue)
            {
                writer.WriteElementString("DateCreated", ApmlUtility.ApmlNamespace, SyndicationDateTimeUtility.ToRfc3339DateTime(this.CreatedOn));
            }
            SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);

            writer.WriteEndElement();
        }
Esempio n. 10
0
        /// <summary>
        /// Writes the current context to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <b>XmlWriter</b> to which you want to write the current context.</param>
        /// <param name="xmlNamespace">The XML namespace used to qualify prefixed syndication extension elements and attributes.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="xmlNamespace"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="xmlNamespace"/> is an empty string.</exception>
        public void WriteTo(XmlWriter writer, string xmlNamespace)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");
            Guard.ArgumentNotNullOrEmptyString(xmlNamespace, "xmlNamespace");

            //------------------------------------------------------------
            //	Write current extension details to the writer
            //------------------------------------------------------------
            if (this.Period != SiteSummaryUpdatePeriod.None)
            {
                writer.WriteElementString("updatePeriod", xmlNamespace, SiteSummaryUpdateSyndicationExtension.PeriodAsString(this.Period));
            }

            if (this.Frequency != Int32.MinValue)
            {
                writer.WriteElementString("updateFrequency", xmlNamespace, this.Frequency.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
            }

            if (this.Base != DateTime.MinValue)
            {
                writer.WriteElementString("updateBase", xmlNamespace, SyndicationDateTimeUtility.ToRfc3339DateTime(this.Base));
            }
        }
        public void SingleResource_Verify_CanCreate()
        {
            var request = new SDataSingleResourceRequest(_service)
            {
                ResourceKind = "employees"
            };

            var payload = new SDataPayload();

            payload.Values["Title"]            = "create 1";
            payload.Values["NationalIdNumber"] = "44444";
            payload.Values["LoginId"]          = "create 4";
            payload.Values["ContactId"]        = "9999";
            payload.Values["BirthDate"]        = SyndicationDateTimeUtility.ToRfc3339DateTime(new DateTime(1970, 8, 2));
            payload.Values["HireDate"]         = SyndicationDateTimeUtility.ToRfc3339DateTime(DateTime.Now);
            payload.Values["ModifiedDate"]     = SyndicationDateTimeUtility.ToRfc3339DateTime(DateTime.Now);
            payload.Values["MaritalStatus"]    = "Single";
            payload.Values["SalariedFlag"]     = XmlConvert.ToString(true);
            payload.Values["CurrentFlag"]      = XmlConvert.ToString(true);
            payload.Values["Gender"]           = "Male";
            payload.Values["RowGuid"]          = Guid.NewGuid().ToString();

            var entry = new AtomEntry
            {
                UpdatedOn   = DateTime.Now,
                PublishedOn = DateTime.Now
            };

            entry.SetSDataPayload(payload);
            request.Entry = entry;
            _mock.Setup(s => s.CreateEntry(request, request.Entry)).Returns(TestData.Entry);

            entry = request.Create();
            Expect(entry, Is.Not.Null);
        }
        /// <summary>
        /// Initializes the supplied <see cref="RssChannel"/> optional entities using the specified <see cref="XPathNavigator"/> and <see cref="XmlNamespaceManager"/>.
        /// </summary>
        /// <param name="channel">The <see cref="RssChannel"/> to be filled.</param>
        /// <param name="navigator">The <see cref="XPathNavigator"/> used to navigate the channel XML data.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the load operation.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="channel"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="navigator"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        private static void FillChannelOptionals(RssChannel channel, XPathNavigator navigator, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            Guard.ArgumentNotNull(channel, "channel");
            Guard.ArgumentNotNull(navigator, "navigator");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            XPathNavigator copyrightNavigator      = navigator.SelectSingleNode("copyright", manager);
            XPathNavigator managingEditorNavigator = navigator.SelectSingleNode("managingEditor", manager);
            XPathNavigator webMasterNavigator      = navigator.SelectSingleNode("webMaster", manager);
            XPathNavigator ratingNavigator         = navigator.SelectSingleNode("rating", manager);
            XPathNavigator publicationNavigator    = navigator.SelectSingleNode("pubDate", manager);
            XPathNavigator lastBuildDateNavigator  = navigator.SelectSingleNode("lastBuildDate", manager);
            XPathNavigator textInputNavigator      = navigator.SelectSingleNode("textInput", manager);

            if (copyrightNavigator != null)
            {
                channel.Copyright = copyrightNavigator.Value;
            }

            if (managingEditorNavigator != null)
            {
                channel.ManagingEditor = managingEditorNavigator.Value;
            }

            if (webMasterNavigator != null)
            {
                channel.Webmaster = webMasterNavigator.Value;
            }

            if (ratingNavigator != null)
            {
                channel.Rating = ratingNavigator.Value;
            }

            if (publicationNavigator != null)
            {
                DateTime publicationDate;
                if (SyndicationDateTimeUtility.TryParseRfc822DateTime(publicationNavigator.Value, out publicationDate))
                {
                    channel.PublicationDate = publicationDate;
                }
            }

            if (lastBuildDateNavigator != null)
            {
                DateTime lastBuildDate;
                if (SyndicationDateTimeUtility.TryParseRfc822DateTime(lastBuildDateNavigator.Value, out lastBuildDate))
                {
                    channel.LastBuildDate = lastBuildDate;
                }
            }

            if (textInputNavigator != null)
            {
                channel.TextInput = new RssTextInput();
                Rss091SyndicationResourceAdapter.FillTextInput(channel.TextInput, textInputNavigator, manager, settings);
            }
        }
        /// <summary>
        /// Saves the current <see cref="RssItem"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public void WriteTo(XmlWriter writer)
        {
            Guard.ArgumentNotNull(writer, "writer");
            writer.WriteStartElement("item");

            if (!String.IsNullOrEmpty(this.Title))
            {
                writer.WriteElementString("title", this.Title);
            }

            if (!String.IsNullOrEmpty(this.Description))
            {
                writer.WriteElementString("description", this.Description);
            }

            if (this.Link != null)
            {
                writer.WriteElementString("link", this.Link.ToString());
            }

            if (!String.IsNullOrEmpty(this.Author))
            {
                writer.WriteElementString("author", this.Author);
            }

            if (this.Comments != null)
            {
                writer.WriteElementString("comments", this.Comments.ToString());
            }

            if (this.Guid != null)
            {
                this.Guid.WriteTo(writer);
            }

            if (this.PublicationDate != DateTime.MinValue)
            {
                writer.WriteElementString("pubDate", SyndicationDateTimeUtility.ToRfc822DateTime(this.PublicationDate));
            }

            if (this.Source != null)
            {
                this.Source.WriteTo(writer);
            }

            foreach (RssCategory category in this.Categories)
            {
                category.WriteTo(writer);
            }

            foreach (RssEnclosure enclosure in this.Enclosures)
            {
                enclosure.WriteTo(writer);
            }
            SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);

            writer.WriteEndElement();
        }
Esempio n. 14
0
        /// <summary>
        /// Loads this <see cref="FeedSynchronizationSharingInformation"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="FeedSynchronizationSharingInformation"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="FeedSynchronizationSharingInformation"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(source, "source");
            FeedSynchronizationSyndicationExtension extension = new FeedSynchronizationSyndicationExtension();
            XmlNamespaceManager manager = extension.CreateNamespaceManager(source);

            if (source.HasAttributes)
            {
                string sinceAttribute   = source.GetAttribute("since", String.Empty);
                string untilAttribute   = source.GetAttribute("until", String.Empty);
                string expiresAttribute = source.GetAttribute("expires", String.Empty);

                if (!String.IsNullOrEmpty(sinceAttribute))
                {
                    this.Since = sinceAttribute;
                    wasLoaded  = true;
                }

                if (!String.IsNullOrEmpty(untilAttribute))
                {
                    this.Until = untilAttribute;
                    wasLoaded  = true;
                }

                if (!String.IsNullOrEmpty(expiresAttribute))
                {
                    DateTime expiresOn;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(expiresAttribute, out expiresOn))
                    {
                        this.ExpiresOn = expiresOn;
                        wasLoaded      = true;
                    }
                }
            }

            if (source.HasChildren)
            {
                XPathNodeIterator relatedIterator = source.Select("sx:related", manager);

                if (relatedIterator != null && relatedIterator.Count > 0)
                {
                    while (relatedIterator.MoveNext())
                    {
                        FeedSynchronizationRelatedInformation relation = new FeedSynchronizationRelatedInformation();
                        if (relation.Load(relatedIterator.Current))
                        {
                            this.Relations.Add(relation);
                            wasLoaded = true;
                        }
                    }
                }
            }

            return(wasLoaded);
        }
Esempio n. 15
0
 /// <summary>
 /// Writes the current context to the specified <see cref="XmlWriter"/>.
 /// </summary>
 /// <param name="writer">The <b>XmlWriter</b> to which you want to write the current context.</param>
 /// <param name="xmlNamespace">The XML namespace used to qualify prefixed syndication extension elements and attributes.</param>
 /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
 /// <exception cref="ArgumentNullException">The <paramref name="xmlNamespace"/> is a null reference (Nothing in Visual Basic).</exception>
 /// <exception cref="ArgumentNullException">The <paramref name="xmlNamespace"/> is an empty string.</exception>
 public void WriteTo(XmlWriter writer, string xmlNamespace)
 {
     Guard.ArgumentNotNull(writer, "writer");
     Guard.ArgumentNotNullOrEmptyString(xmlNamespace, "xmlNamespace");
     if (this.EditedOn != DateTime.MinValue)
     {
         writer.WriteElementString("edited", xmlNamespace, SyndicationDateTimeUtility.ToRfc3339DateTime(this.EditedOn));
     }
 }
        /// <summary>
        /// Saves the current <see cref="OpmlHead"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public void WriteTo(XmlWriter writer)
        {
            Guard.ArgumentNotNull(writer, "writer");
            writer.WriteStartElement("head");

            if (!String.IsNullOrEmpty(this.Title))
            {
                writer.WriteElementString("title", this.Title);
            }

            if (this.CreatedOn != DateTime.MinValue)
            {
                writer.WriteElementString("dateCreated", SyndicationDateTimeUtility.ToRfc822DateTime(this.CreatedOn));
            }

            if (this.ModifiedOn != DateTime.MinValue)
            {
                writer.WriteElementString("dateModified", SyndicationDateTimeUtility.ToRfc822DateTime(this.ModifiedOn));
            }

            if (this.Owner != null)
            {
                this.Owner.WriteTo(writer);
            }

            if (this.Documentation != null)
            {
                writer.WriteElementString("docs", this.Documentation.ToString());
            }

            if (this.ExpansionState.Count > 0)
            {
                string[] values          = new string[this.ExpansionState.Count];
                int[]    expansionStates = new int[this.ExpansionState.Count];
                this.ExpansionState.CopyTo(expansionStates, 0);

                for (int i = 0; i < expansionStates.Length; i++)
                {
                    values[i] = expansionStates[i].ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
                }
                writer.WriteElementString("expansionState", String.Join(",", values));
            }

            if (this.VerticalScrollState != Int32.MinValue)
            {
                writer.WriteElementString("vertScrollState", this.VerticalScrollState.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
            }

            if (this.Window != null)
            {
                this.Window.WriteTo(writer);
            }
            SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);

            writer.WriteEndElement();
        }
Esempio n. 17
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="ApmlHead"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="ApmlHead"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="ApmlHead"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");

            //------------------------------------------------------------
            //	Initialize XML namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager = ApmlUtility.CreateNamespaceManager(source.NameTable);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            XPathNavigator titleNavigator       = source.SelectSingleNode("apml:Title", manager);
            XPathNavigator generatorNavigator   = source.SelectSingleNode("apml:Generator", manager);
            XPathNavigator userEmailNavigator   = source.SelectSingleNode("apml:UserEmail", manager);
            XPathNavigator dateCreatedNavigator = source.SelectSingleNode("apml:DateCreated", manager);

            if (titleNavigator != null)
            {
                this.Title = titleNavigator.Value;
                wasLoaded  = true;
            }

            if (generatorNavigator != null)
            {
                this.Generator = generatorNavigator.Value;
                wasLoaded      = true;
            }

            if (userEmailNavigator != null)
            {
                this.EmailAddress = userEmailNavigator.Value;
                wasLoaded         = true;
            }

            if (dateCreatedNavigator != null)
            {
                DateTime createdOn;
                if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(dateCreatedNavigator.Value, out createdOn))
                {
                    this.CreatedOn = createdOn;
                    wasLoaded      = true;
                }
            }

            return(wasLoaded);
        }
Esempio n. 18
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source, XmlNamespaceManager manager)
        /// <summary>
        /// Initializes the syndication extension context using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="SiteSummaryUpdateSyndicationExtensionContext"/>.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> object used to resolve prefixed syndication extension elements and attributes.</param>
        /// <returns><b>true</b> if the <see cref="SiteSummaryUpdateSyndicationExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source, XmlNamespaceManager manager)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            if (source.HasChildren)
            {
                XPathNavigator updatePeriodNavigator    = source.SelectSingleNode("sy:updatePeriod", manager);
                XPathNavigator updateFrequencyNavigator = source.SelectSingleNode("sy:updateFrequency", manager);
                XPathNavigator updateBaseNavigator      = source.SelectSingleNode("sy:updateBase", manager);

                if (updatePeriodNavigator != null && !String.IsNullOrEmpty(updatePeriodNavigator.Value))
                {
                    SiteSummaryUpdatePeriod period = SiteSummaryUpdateSyndicationExtension.PeriodByName(updatePeriodNavigator.Value);
                    if (period != SiteSummaryUpdatePeriod.None)
                    {
                        this.Period = period;
                        wasLoaded   = true;
                    }
                }

                if (updateFrequencyNavigator != null)
                {
                    int frequency;
                    if (Int32.TryParse(updateFrequencyNavigator.Value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out frequency))
                    {
                        this.Frequency = frequency;
                        wasLoaded      = true;
                    }
                }

                if (updateBaseNavigator != null)
                {
                    DateTime updateBase;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updateBaseNavigator.Value, out updateBase))
                    {
                        this.Base = updateBase;
                        wasLoaded = true;
                    }
                }
            }

            return(wasLoaded);
        }
Esempio n. 19
0
        /// <summary>
        /// Loads this <see cref="AtomSource"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="AtomSource"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomSource"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(source, "source");
            XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(source.NameTable);

            if (AtomUtility.FillCommonObjectAttributes(this, source))
            {
                wasLoaded = true;
            }
            XPathNavigator idNavigator      = source.SelectSingleNode("atom:id", manager);
            XPathNavigator titleNavigator   = source.SelectSingleNode("atom:title", manager);
            XPathNavigator updatedNavigator = source.SelectSingleNode("atom:updated", manager);

            if (idNavigator != null)
            {
                this.Id = new AtomId();
                if (this.Id.Load(idNavigator))
                {
                    wasLoaded = true;
                }
            }

            if (titleNavigator != null)
            {
                this.Title = new AtomTextConstruct();
                if (this.Title.Load(titleNavigator))
                {
                    wasLoaded = true;
                }
            }

            if (updatedNavigator != null)
            {
                DateTime updatedOn;
                if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedNavigator.Value, out updatedOn))
                {
                    this.UpdatedOn = updatedOn;
                    wasLoaded      = true;
                }
            }

            if (this.LoadOptionals(source, manager))
            {
                wasLoaded = true;
            }

            if (this.LoadCollections(source, manager))
            {
                wasLoaded = true;
            }

            return(wasLoaded);
        }
Esempio n. 20
0
        /// <summary>
        /// Modifies the <see cref="AtomFeed"/> to match the data source.
        /// </summary>
        /// <param name="resource">The <see cref="AtomFeed"/> to be filled.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        public void Fill(AtomFeed resource)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(resource, "resource");

            //------------------------------------------------------------
            //	Create namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(this.Navigator.NameTable);

            //------------------------------------------------------------
            //	Attempt to fill syndication resource
            //------------------------------------------------------------
            XPathNavigator feedNavigator = this.Navigator.SelectSingleNode("atom:feed", manager);

            if (feedNavigator != null)
            {
                AtomUtility.FillCommonObjectAttributes(resource, feedNavigator);

                XPathNavigator idNavigator      = feedNavigator.SelectSingleNode("atom:id", manager);
                XPathNavigator titleNavigator   = feedNavigator.SelectSingleNode("atom:title", manager);
                XPathNavigator updatedNavigator = feedNavigator.SelectSingleNode("atom:updated", manager);

                if (idNavigator != null)
                {
                    resource.Id = new AtomId();
                    resource.Id.Load(idNavigator, this.Settings);
                }

                if (titleNavigator != null)
                {
                    resource.Title = new AtomTextConstruct();
                    resource.Title.Load(titleNavigator, this.Settings);
                }

                if (updatedNavigator != null)
                {
                    DateTime updatedOn;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedNavigator.Value, out updatedOn))
                    {
                        resource.UpdatedOn = updatedOn;
                    }
                }

                Atom10SyndicationResourceAdapter.FillFeedOptionals(resource, feedNavigator, manager, this.Settings);
                Atom10SyndicationResourceAdapter.FillFeedCollections(resource, feedNavigator, manager, this.Settings);

                SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(feedNavigator, this.Settings);
                adapter.Fill(resource, manager);
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Modifies the <see cref="AtomEntry"/> optional entities to match the supplied <see cref="XPathNavigator"/> data source.
        /// </summary>
        /// <param name="entry">The <see cref="AtomEntry"/> to be filled.</param>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomEntry"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        private static void FillEntryOptionals(AtomEntry entry, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(entry, "entry");
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            XPathNavigator contentNavigator   = source.SelectSingleNode("atom:content", manager);
            XPathNavigator publishedNavigator = source.SelectSingleNode("atom:published", manager);
            XPathNavigator rightsNavigator    = source.SelectSingleNode("atom:rights", manager);
            XPathNavigator sourceNavigator    = source.SelectSingleNode("atom:source", manager);
            XPathNavigator summaryNavigator   = source.SelectSingleNode("atom:summary", manager);

            if (contentNavigator != null)
            {
                entry.Content = new AtomContent();
                entry.Content.Load(contentNavigator, settings);
            }

            if (publishedNavigator != null)
            {
                DateTime publishedOn;
                if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(publishedNavigator.Value, out publishedOn))
                {
                    entry.PublishedOn = publishedOn;
                }
            }

            if (rightsNavigator != null)
            {
                entry.Rights = new AtomTextConstruct();
                entry.Rights.Load(rightsNavigator, settings);
            }

            if (sourceNavigator != null)
            {
                entry.Source = new AtomSource();
                entry.Source.Load(sourceNavigator, settings);
            }

            if (summaryNavigator != null)
            {
                entry.Summary = new AtomTextConstruct();
                entry.Summary.Load(summaryNavigator, settings);
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Returns the string representation of the supplied scalar value using the specified <see cref="XmlRpcScalarValueType"/>.
        /// </summary>
        /// <param name="type">The data type used to determine string representation.</param>
        /// <param name="scalar">The scalar value to convert.</param>
        /// <returns>The string representation of the current instance's <see cref="Value"/>, based on its <see cref="ValueType"/>.</returns>
        private static string ValueAsString(XmlRpcScalarValueType type, object scalar)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            string value = String.Empty;

            //------------------------------------------------------------
            //	Return string representation based on data type
            //------------------------------------------------------------
            if (scalar == null)
            {
                return(String.Empty);
            }

            switch (type)
            {
            case XmlRpcScalarValueType.Base64:
                byte[] data = scalar as byte[];
                if (data != null)
                {
                    value = Convert.ToBase64String(data, Base64FormattingOptions.None);
                }
                else
                {
                    value = Convert.ToString(scalar, CultureInfo.InvariantCulture);
                }
                break;

            case XmlRpcScalarValueType.Boolean:
                value = Convert.ToBoolean(scalar, CultureInfo.InvariantCulture) ? "1" : "0";
                break;

            case XmlRpcScalarValueType.DateTime:
                value = SyndicationDateTimeUtility.ToRfc3339DateTime(Convert.ToDateTime(scalar, DateTimeFormatInfo.InvariantInfo));
                break;

            case XmlRpcScalarValueType.Double:
                value = Convert.ToDouble(scalar, NumberFormatInfo.InvariantInfo).ToString(NumberFormatInfo.InvariantInfo);
                break;

            case XmlRpcScalarValueType.Integer:
                value = Convert.ToInt32(scalar, NumberFormatInfo.InvariantInfo).ToString(NumberFormatInfo.InvariantInfo);
                break;

            case XmlRpcScalarValueType.String:
                value = Convert.ToString(scalar, CultureInfo.InvariantCulture).Trim();
                break;
            }

            return(value);
        }
        /// <summary>
        /// Saves the current <see cref="OpmlOutline"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public void WriteTo(XmlWriter writer)
        {
            Guard.ArgumentNotNull(writer, "writer");
            writer.WriteStartElement("outline");

            writer.WriteAttributeString("text", this.Text);

            if (!String.IsNullOrEmpty(this.ContentType))
            {
                writer.WriteAttributeString("type", this.ContentType);
            }

            if (this.IsCommented)
            {
                writer.WriteAttributeString("isComment", "true");
            }

            if (this.HasBreakpoint)
            {
                writer.WriteAttributeString("isBreakpoint", "true");
            }

            if (this.CreatedOn != DateTime.MinValue)
            {
                writer.WriteAttributeString("created", SyndicationDateTimeUtility.ToRfc822DateTime(this.CreatedOn));
            }

            if (this.Categories.Count > 0)
            {
                string[] categories = new string[this.Categories.Count];
                this.Categories.CopyTo(categories, 0);

                writer.WriteAttributeString("category", String.Join(",", categories));
            }

            if (this.Attributes.Count > 0)
            {
                foreach (string name in this.Attributes.Keys)
                {
                    writer.WriteAttributeString(name, this.Attributes[name]);
                }
            }

            foreach (OpmlOutline outline in this.Outlines)
            {
                outline.WriteTo(writer);
            }
            SyndicationExtensionAdapter.WriteExtensionsTo(this.Extensions, writer);

            writer.WriteEndElement();
        }
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="FeedSynchronizationHistory"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="FeedSynchronizationHistory"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="FeedSynchronizationHistory"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string sequenceAttribute = source.GetAttribute("sequence", String.Empty);
                string whenAttribute     = source.GetAttribute("when", String.Empty);
                string byAttribute       = source.GetAttribute("by", String.Empty);

                if (!String.IsNullOrEmpty(sequenceAttribute))
                {
                    int sequence;
                    if (Int32.TryParse(sequenceAttribute, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out sequence))
                    {
                        this.Sequence = sequence;
                        wasLoaded     = true;
                    }
                }

                if (!String.IsNullOrEmpty(whenAttribute))
                {
                    DateTime when;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(whenAttribute, out when))
                    {
                        this.When = when;
                        wasLoaded = true;
                    }
                }

                if (!String.IsNullOrEmpty(byAttribute))
                {
                    this.By   = byAttribute;
                    wasLoaded = true;
                }
            }

            return(wasLoaded);
        }
Esempio n. 25
0
        //============================================================
        //	PRIVATE METHODS
        //============================================================
        #region StringAsValue(XmlRpcScalarValueType type, string scalar)
        /// <summary>
        /// Returns an <see cref="Object"/> that represents the converted value for the specified <see cref="XmlRpcScalarValueType"/>.
        /// </summary>
        /// <param name="type">The <see cref="XmlRpcScalarValueType"/> that indicates the expected data type for the scalar value.</param>
        /// <param name="scalar">The string representation of the scalar value.</param>
        /// <returns>An <see cref="Object"/> that represents the converted value for the specified <paramref name="type"/> and <paramref name="scalar"/>.</returns>
        /// <exception cref="ArgumentNullException">The <paramref name="scalar"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="scalar"/> is an empty string.</exception>
        private static object StringAsValue(XmlRpcScalarValueType type, string scalar)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            object result = String.Empty;

            //------------------------------------------------------------
            //	Validate parameters
            //------------------------------------------------------------
            Guard.ArgumentNotNullOrEmptyString(scalar, "scalar");

            //------------------------------------------------------------
            //	Convert string representation to expected value type
            //------------------------------------------------------------
            switch (type)
            {
            case XmlRpcScalarValueType.Base64:
                result = Convert.FromBase64String(scalar);
                break;

            case XmlRpcScalarValueType.Boolean:
                bool boolean;
                if (XmlRpcClient.TryParseBoolean(scalar, out boolean))
                {
                    result = boolean;
                }
                break;

            case XmlRpcScalarValueType.DateTime:
                result = SyndicationDateTimeUtility.ParseRfc3339DateTime(scalar);
                break;

            case XmlRpcScalarValueType.Double:
                result = Double.Parse(scalar, NumberStyles.Float, NumberFormatInfo.InvariantInfo);
                break;

            case XmlRpcScalarValueType.Integer:
                result = Int32.Parse(scalar, NumberStyles.Float, NumberFormatInfo.InvariantInfo);
                break;

            case XmlRpcScalarValueType.String:
                result = scalar.Trim();
                break;
            }

            return(result);
        }
Esempio n. 26
0
        /// <summary>
        /// Writes the current context to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <b>XmlWriter</b> to which you want to write the current context.</param>
        /// <param name="xmlNamespace">The XML namespace used to qualify prefixed syndication extension elements and attributes.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="xmlNamespace"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="xmlNamespace"/> is an empty string.</exception>
        public void WriteTo(XmlWriter writer, string xmlNamespace)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(writer, "writer");
            Guard.ArgumentNotNullOrEmptyString(xmlNamespace, "xmlNamespace");

            //------------------------------------------------------------
            //	Write current extension details to the writer
            //------------------------------------------------------------
            if (this.EditedOn != DateTime.MinValue)
            {
                writer.WriteElementString("edited", xmlNamespace, SyndicationDateTimeUtility.ToRfc3339DateTime(this.EditedOn));
            }
        }
Esempio n. 27
0
        //============================================================
        //	PRIVATE METHODS
        //============================================================
        #region FillEntry(AtomEntry entry, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        /// <summary>
        /// Modifies the <see cref="AtomEntry"/> to match the supplied <see cref="XPathNavigator"/> data source.
        /// </summary>
        /// <param name="entry">The <see cref="AtomEntry"/> to be filled.</param>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="manager">The <see cref="XmlNamespaceManager"/> used to resolve XML namespace prefixes.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the fill operation.</param>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="AtomEntry"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception>
        private static void FillEntry(AtomEntry entry, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(entry, "entry");
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Attempt to fill syndication resource
            //------------------------------------------------------------
            AtomUtility.FillCommonObjectAttributes(entry, source);

            XPathNavigator idNavigator      = source.SelectSingleNode("atom:id", manager);
            XPathNavigator titleNavigator   = source.SelectSingleNode("atom:title", manager);
            XPathNavigator updatedNavigator = source.SelectSingleNode("atom:updated", manager);

            if (idNavigator != null)
            {
                entry.Id = new AtomId();
                entry.Id.Load(idNavigator, settings);
            }

            if (titleNavigator != null)
            {
                entry.Title = new AtomTextConstruct();
                entry.Title.Load(titleNavigator, settings);
            }

            if (updatedNavigator != null)
            {
                DateTime updatedOn;
                if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(updatedNavigator.Value, out updatedOn))
                {
                    entry.UpdatedOn = updatedOn;
                }
            }

            Atom10SyndicationResourceAdapter.FillEntryOptionals(entry, source, manager, settings);
            Atom10SyndicationResourceAdapter.FillEntryCollections(entry, source, manager, settings);

            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);

            adapter.Fill(entry, manager);
        }
        /// <summary>
        /// Modifies the <see cref="AtomFeed"/> to match the data source.
        /// </summary>
        /// <param name="resource">The <see cref="AtomFeed"/> to be filled.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception>
        public void Fill(AtomFeed resource)
        {
            Guard.ArgumentNotNull(resource, "resource");

            XmlNamespaceManager manager = Atom03SyndicationResourceAdapter.CreateNamespaceManager(this.Navigator.NameTable);

            XPathNavigator feedNavigator = this.Navigator.SelectSingleNode("atom:feed", manager);

            if (feedNavigator != null)
            {
                AtomUtility.FillCommonObjectAttributes(resource, feedNavigator);

                XPathNavigator idNavigator       = feedNavigator.SelectSingleNode("atom:id", manager);
                XPathNavigator titleNavigator    = feedNavigator.SelectSingleNode("atom:title", manager);
                XPathNavigator modifiedNavigator = feedNavigator.SelectSingleNode("atom:modified", manager);

                if (idNavigator != null)
                {
                    resource.Id = new AtomId();
                    resource.Id.Load(idNavigator, this.Settings);
                }

                if (titleNavigator != null)
                {
                    resource.Title = Atom03SyndicationResourceAdapter.CreateTextContent(titleNavigator, manager, this.Settings);
                }

                if (modifiedNavigator != null)
                {
                    DateTime updatedOn;
                    if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(modifiedNavigator.Value, out updatedOn))
                    {
                        resource.UpdatedOn = updatedOn;
                    }
                }

                Atom03SyndicationResourceAdapter.FillFeedOptionals(resource, feedNavigator, manager, this.Settings);
                Atom03SyndicationResourceAdapter.FillFeedCollections(resource, feedNavigator, manager, this.Settings);

                SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(feedNavigator, this.Settings);
                adapter.Fill(resource, manager);
            }
        }
        /// <summary>
        /// Saves the current <see cref="FeedSynchronizationHistory"/> to the specified <see cref="XmlWriter"/>.
        /// </summary>
        /// <param name="writer">The <see cref="XmlWriter"/> to which you want to save.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="writer"/> is a null reference (Nothing in Visual Basic).</exception>
        public void WriteTo(XmlWriter writer)
        {
            Guard.ArgumentNotNull(writer, "writer");
            FeedSynchronizationSyndicationExtension extension = new FeedSynchronizationSyndicationExtension();

            writer.WriteStartElement("history", extension.XmlNamespace);
            writer.WriteAttributeString("sequence", this.Sequence.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));

            if (this.When != DateTime.MinValue)
            {
                writer.WriteAttributeString("when", SyndicationDateTimeUtility.ToRfc3339DateTime(this.When));
            }

            if (!String.IsNullOrEmpty(this.By))
            {
                writer.WriteAttributeString("when", this.By);
            }

            writer.WriteEndElement();
        }
        /// <summary>
        /// Loads this <see cref="ApmlHead"/> using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <returns><b>true</b> if the <see cref="ApmlHead"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="ApmlHead"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(source, "source");
            XmlNamespaceManager manager              = ApmlUtility.CreateNamespaceManager(source.NameTable);
            XPathNavigator      titleNavigator       = source.SelectSingleNode("apml:Title", manager);
            XPathNavigator      generatorNavigator   = source.SelectSingleNode("apml:Generator", manager);
            XPathNavigator      userEmailNavigator   = source.SelectSingleNode("apml:UserEmail", manager);
            XPathNavigator      dateCreatedNavigator = source.SelectSingleNode("apml:DateCreated", manager);

            if (titleNavigator != null)
            {
                this.Title = titleNavigator.Value;
                wasLoaded  = true;
            }

            if (generatorNavigator != null)
            {
                this.Generator = generatorNavigator.Value;
                wasLoaded      = true;
            }

            if (userEmailNavigator != null)
            {
                this.EmailAddress = userEmailNavigator.Value;
                wasLoaded         = true;
            }

            if (dateCreatedNavigator != null)
            {
                DateTime createdOn;
                if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(dateCreatedNavigator.Value, out createdOn))
                {
                    this.CreatedOn = createdOn;
                    wasLoaded      = true;
                }
            }

            return(wasLoaded);
        }