public void AtomNewImageTest() { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://localhost/DBlog/AtomImage.aspx"); request.Method = "POST"; request.ContentType = "image/jpg"; string usernamePassword = string.Format("Administrator:"); string basicAuthorization = string.Format("Basic {0}", Convert.ToBase64String( Encoding.ASCII.GetBytes(usernamePassword))); request.Headers.Add("Authorization", basicAuthorization); byte[] postData = ThumbnailBitmap.GetBitmapDataFromText("x", 72, 100, 150); request.ContentLength = postData.Length; request.GetRequestStream().Write(postData, 0, postData.Length); request.GetRequestStream().Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string responseLocation = response.Headers["Location"]; Assert.IsNotEmpty(responseLocation); Console.WriteLine(responseLocation); // atom entry returned AtomEntry atomEntry = new AtomEntry(); atomEntry.Load(response.GetResponseStream()); Console.WriteLine(atomEntry.Id.Uri); int id = int.Parse(atomEntry.Id.Uri.ToString().Substring(atomEntry.Id.Uri.ToString().LastIndexOf("/") + 1)); Assert.IsTrue(id > 0); Console.WriteLine(string.Format("Id: {0}", id)); Blog.DeleteImage(Ticket, id); }
//============================================================ // CLASS SUMMARY //============================================================ /// <summary> /// Provides example code for the AtomGenerator class. /// </summary> public static void ClassExample() { #region AtomGenerator AtomFeed feed = new AtomFeed(); feed.Id = new AtomId(new Uri("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6")); feed.Title = new AtomTextConstruct("Example Feed"); feed.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2); feed.Links.Add(new AtomLink(new Uri("http://example.org/"))); feed.Links.Add(new AtomLink(new Uri("/feed"), "self")); feed.Authors.Add(new AtomPersonConstruct("John Doe")); // Identify the software used to generate the feed AtomGenerator generator = new AtomGenerator("Example Toolkit"); generator.Uri = new Uri("/myblog.php"); generator.Version = "1.0"; feed.Generator = generator; AtomEntry entry = new AtomEntry(); entry.Id = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a")); entry.Title = new AtomTextConstruct("Atom-Powered Robots Run Amok"); entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2); entry.Summary = new AtomTextConstruct("Some text."); feed.AddEntry(entry); #endregion }
public static DateTime GetPublishedDate(AtomEntry entry) { if (entry.PublishedOn == DateTime.MinValue) { return entry.UpdatedOn; } return entry.PublishedOn; }
//============================================================ // CLASS SUMMARY //============================================================ /// <summary> /// Provides example code for the AtomFeed class. /// </summary> public static void ClassExample() { #region AtomFeed AtomFeed feed = new AtomFeed(); feed.Id = new AtomId(new Uri("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6")); feed.Title = new AtomTextConstruct("Example Feed"); feed.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2); feed.Links.Add(new AtomLink(new Uri("http://example.org/"))); feed.Links.Add(new AtomLink(new Uri("/feed"), "self")); feed.Authors.Add(new AtomPersonConstruct("John Doe")); AtomEntry entry = new AtomEntry(); entry.Id = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a")); entry.Title = new AtomTextConstruct("Atom-Powered Robots Run Amok"); entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2); entry.Summary = new AtomTextConstruct("Some text."); feed.AddEntry(entry); #endregion }
//============================================================ // CLASS SUMMARY //============================================================ /// <summary> /// Provides example code for the AtomSource class. /// </summary> public static void ClassExample() { #region AtomSource AtomFeed feed = new AtomFeed(); feed.Id = new AtomId(new Uri("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6")); feed.Title = new AtomTextConstruct("Example Feed"); feed.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2); feed.Links.Add(new AtomLink(new Uri("http://example.org/"))); feed.Links.Add(new AtomLink(new Uri("/feed"), "self")); feed.Authors.Add(new AtomPersonConstruct("John Doe")); AtomEntry entry = new AtomEntry(); entry.Id = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a")); entry.Title = new AtomTextConstruct("Atom-Powered Robots Run Amok"); entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2); entry.Summary = new AtomTextConstruct("Some text."); // Entry was copied from another feed, so preserve source meta-data AtomSource source = new AtomSource(); source.Id = new AtomId(new Uri("http://example2.org/")); source.Title = new AtomTextConstruct("Fourty-Two"); source.UpdatedOn = new DateTime(2003, 11, 13, 18, 30, 2); source.Rights = new AtomTextConstruct("© 2003 Example, Inc."); entry.Source = source; feed.AddEntry(entry); #endregion }
//============================================================ // CLASS SUMMARY //============================================================ /// <summary> /// Provides example code for the AtomTextConstruct class. /// </summary> public static void ClassExample() { #region AtomTextConstruct AtomFeed feed = new AtomFeed(); feed.Id = new AtomId(new Uri("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6")); feed.Title = new AtomTextConstruct("Example Feed"); feed.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2); feed.Links.Add(new AtomLink(new Uri("http://example.org/"))); feed.Links.Add(new AtomLink(new Uri("/feed"), "self")); feed.Authors.Add(new AtomPersonConstruct("John Doe")); AtomEntry entry = new AtomEntry(); entry.Id = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a")); entry.Title = new AtomTextConstruct("Atom-Powered Robots Run Amok"); entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2); // Provide summary as entity escaped html AtomTextConstruct summary = new AtomTextConstruct(); summary.Content = "AT&amp;T bought <b>by SBC</b>!"; summary.TextType = AtomTextConstructType.Html; entry.Summary = summary; feed.AddEntry(entry); #endregion }
private static Item CreateFeedItem(AtomEntry atomEntry) { var item = new Item(); item.Title = HtmlHelper.DecodeHtml(atomEntry.Title.Content); item.Summary = GetItemSummary(atomEntry); item.Url = GetAtomLink(atomEntry.Links); item.Published = GetPublishedDate(atomEntry); item.IsRead = false; return item; }
private static string GetItemSummary(AtomEntry entry) { if (entry.Summary != null) { return GetHtmlString(entry.Summary.Content, MaxSummaryLength); } if (entry.Content != null) { return GetHtmlString(entry.Content.Content, MaxSummaryLength); } return String.Empty; }
/// <summary> /// Initializes a new instance of the <see cref="GenericSyndicationItem"/> class using the supplied <see cref="AtomEntry"/>. /// </summary> /// <param name="entry">The <see cref="AtomEntry"/> to build an abstraction against.</param> /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception> public GenericSyndicationItem(AtomEntry entry) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(entry, "entry"); //------------------------------------------------------------ // Extract information from the format specific content //------------------------------------------------------------ this.LoadFrom(entry); }
//============================================================ // ASYNC METHODS //============================================================ /// <summary> /// Provides example code for the LoadAsync(Uri, Object) method /// </summary> public static void LoadAsyncExample() { #region LoadAsync(Uri source, Object userToken) //------------------------------------------------------------ // Load entry asynchronously using event-based notification //------------------------------------------------------------ AtomEntry entry = new AtomEntry(); entry.Loaded += new EventHandler<SyndicationResourceLoadedEventArgs>(EntryLoadedCallback); entry.LoadAsync(new Uri("http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=Argotic&DownloadId=28707"), null); #endregion }
//============================================================ // CLASS SUMMARY //============================================================ /// <summary> /// Provides example code for the AtomEntry class. /// </summary> public static void ClassExample() { #region AtomEntry AtomEntry entry = new AtomEntry(); entry.Id = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a")); entry.Title = new AtomTextConstruct("Atom Entry Document"); entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2); entry.Authors.Add(new AtomPersonConstruct("John Doe")); entry.Links.Add(new AtomLink(new Uri("/blog/1234"), "alternate")); entry.Summary = new AtomTextConstruct("A stand-alone Atom Entry Document."); #endregion }
private static AtomEntry CreateAtomEntry(Article article) { var slugUri = string.Format("http://henrylawson.net/{0}", article.SlugTitle); var entry = new AtomEntry { Id = new AtomId(new Uri(slugUri)), Title = new AtomTextConstruct(article.Title), UpdatedOn = article.Date, PublishedOn = article.Date, Content = new AtomContent(article.Body, "html"), }; entry.Links.Add(new AtomLink { Uri = new Uri(slugUri) }); return entry; }
/// <summary> /// Modifies the <see cref="AtomEntry"/> to match the data source. /// </summary> /// <param name="resource">The <see cref="AtomEntry"/> to be filled.</param> /// <exception cref="ArgumentNullException">The <paramref name="resource"/> is a null reference (Nothing in Visual Basic).</exception> public void Fill(AtomEntry resource) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(resource, "resource"); //------------------------------------------------------------ // Create namespace resolver //------------------------------------------------------------ XmlNamespaceManager manager = AtomUtility.CreateNamespaceManager(this.Navigator.NameTable); //------------------------------------------------------------ // Attempt to fill syndication resource //------------------------------------------------------------ XPathNavigator entryNavigator = this.Navigator.SelectSingleNode("atom:entry", manager); if (entryNavigator != null) { Atom03SyndicationResourceAdapter.FillEntry(resource, entryNavigator, manager, this.Settings); } }
//============================================================ // CLASS SUMMARY //============================================================ /// <summary> /// Provides example code for the AtomPersonConstruct class. /// </summary> public static void ClassExample() { #region AtomPersonConstruct AtomFeed feed = new AtomFeed(); feed.Id = new AtomId(new Uri("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6")); feed.Title = new AtomTextConstruct("Example Feed"); feed.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2); feed.Links.Add(new AtomLink(new Uri("http://example.org/"))); feed.Links.Add(new AtomLink(new Uri("/feed"), "self")); // Identify the author of the feed feed.Authors.Add(new AtomPersonConstruct("John Doe")); // Identify the contributors to the feed feed.Contributors.Add(new AtomPersonConstruct("Jane Doe")); AtomPersonConstruct contributor = new AtomPersonConstruct(); contributor.EmailAddress = "*****@*****.**"; contributor.Name = "Some Person"; contributor.Uri = new Uri("http://example.org/somePerson"); feed.Contributors.Add(contributor); AtomEntry entry = new AtomEntry(); entry.Id = new AtomId(new Uri("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a")); entry.Title = new AtomTextConstruct("Atom-Powered Robots Run Amok"); entry.UpdatedOn = new DateTime(2003, 12, 13, 18, 30, 2); entry.Summary = new AtomTextConstruct("Some text."); // Identify the author of the entry entry.Authors.Add(new AtomPersonConstruct("Jane Doe")); feed.AddEntry(entry); #endregion }
/// <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) { //------------------------------------------------------------ // 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 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); } }
/// <summary> /// Modifies the <see cref="AtomEntry"/> collection 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 FillEntryCollections(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 //------------------------------------------------------------ XPathNodeIterator authorIterator = source.Select("atom:author", manager); XPathNodeIterator contributorIterator = source.Select("atom:contributor", manager); XPathNodeIterator linkIterator = source.Select("atom:link", manager); if (authorIterator != null && authorIterator.Count > 0) { while (authorIterator.MoveNext()) { AtomPersonConstruct author = Atom03SyndicationResourceAdapter.CreatePerson(authorIterator.Current, manager, settings); entry.Authors.Add(author); } } if (contributorIterator != null && contributorIterator.Count > 0) { while (contributorIterator.MoveNext()) { AtomPersonConstruct contributor = Atom03SyndicationResourceAdapter.CreatePerson(contributorIterator.Current, manager, settings); entry.Contributors.Add(contributor); } } if (linkIterator != null && linkIterator.Count > 0) { while (linkIterator.MoveNext()) { AtomLink link = new AtomLink(); if (link.Load(linkIterator.Current, settings)) { entry.Links.Add(link); } } } }
/// <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 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 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 modifiedNavigator = source.SelectSingleNode("atom:modified", manager); if (idNavigator != null) { entry.Id = new AtomId(); entry.Id.Load(idNavigator, settings); } if (titleNavigator != null) { entry.Title = Atom03SyndicationResourceAdapter.CreateTextContent(titleNavigator, manager, settings); } if (modifiedNavigator != null) { DateTime updatedOn; if (SyndicationDateTimeUtility.TryParseRfc3339DateTime(modifiedNavigator.Value, out updatedOn)) { entry.UpdatedOn = updatedOn; } } Atom03SyndicationResourceAdapter.FillEntryOptionals(entry, source, manager, settings); Atom03SyndicationResourceAdapter.FillEntryCollections(entry, source, manager, settings); SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings); adapter.Fill(entry, manager); }
/// <summary> /// Adds the supplied <see cref="AtomEntry"/> to the current instance's <see cref="Entries"/> collection. /// </summary> /// <param name="entry">The <see cref="AtomEntry"/> to be added.</param> /// <returns><b>true</b> if the <see cref="AtomEntry"/> was added to the <see cref="Entries"/> collection, otherwise <b>false</b>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception> public bool AddEntry(AtomEntry entry) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasAdded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(entry, "entry"); //------------------------------------------------------------ // Add entry to collection //------------------------------------------------------------ ((Collection<AtomEntry>)this.Entries).Add(entry); wasAdded = true; return wasAdded; }
/// <summary> /// Loads the generic syndication item using the supplied <see cref="AtomEntry"/>. /// </summary> /// <param name="entry">The <see cref="AtomEntry"/> to build an abstraction against.</param> /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception> private void LoadFrom(AtomEntry entry) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(entry, "entry"); //------------------------------------------------------------ // Initialize generic item //------------------------------------------------------------ if (entry.Title != null && !String.IsNullOrEmpty(entry.Title.Content)) { itemTitle = entry.Title.Content.Trim(); } if (entry.PublishedOn != DateTime.MinValue) { itemPublishedOn = entry.PublishedOn; } else if (entry.UpdatedOn != DateTime.MinValue) { itemPublishedOn = entry.UpdatedOn; } if (entry.Summary != null && !String.IsNullOrEmpty(entry.Summary.Content)) { itemSummary = entry.Summary.Content.Trim(); } else if (entry.Content != null && !String.IsNullOrEmpty(entry.Content.Content)) { itemSummary = entry.Content.Content.Trim(); } foreach (AtomCategory category in entry.Categories) { GenericSyndicationCategory genericCategory = new GenericSyndicationCategory(category); itemCategories.Add(genericCategory); } }
private void CreateOrUpdatePost(object sender, EventArgs e) { SessionManager.BasicAuth(); if (!SessionManager.IsAdministrator) { throw new ManagedLogin.AccessDeniedException(); } AtomEntry atomEntry = new AtomEntry(); atomEntry.Load(Request.InputStream); TransitPost post = (RequestId > 0) ? SessionManager.BlogService.GetPostById(SessionManager.Ticket, RequestId) : new TransitPost(); post.Title = atomEntry.Title.Content; List<TransitTopic> topics = new List<TransitTopic>(); foreach (AtomCategory category in atomEntry.Categories) { TransitTopic topic = SessionManager.BlogService.GetTopicByName(SessionManager.Ticket, category.Term); if (topic == null) { topic = new TransitTopic(); topic.Name = category.Term; } topics.Add(topic); } post.Topics = topics.ToArray(); post.Body = atomEntry.Content.Content; post.Publish = true; post.Display = true; post.Sticky = false; post.Export = false; if (atomEntry.PublishedOn != DateTime.MinValue) post.Created = atomEntry.PublishedOn; if (atomEntry.UpdatedOn != DateTime.MinValue) post.Modified = atomEntry.UpdatedOn; post.Id = SessionManager.BlogService.CreateOrUpdatePost(SessionManager.Ticket, post); Response.ContentType = "application/atom+xml;type=entry;charset=\"utf-8\""; Response.StatusCode = 201; Response.StatusDescription = "Created"; string location = string.Format("{0}AtomPost.aspx?id={1}", SessionManager.WebsiteUrl, post.Id); Response.Headers.Add("Location", location); Response.Headers.Add("Content-Location", location); Response.Headers.Add("ETag", string.Format("\"{0}\"", Guid.NewGuid().ToString())); atomEntry.Id = new AtomId(new Uri(string.Format("{0}Post/{1}", SessionManager.WebsiteUrl, post.Id))); atomEntry.Links.Add(new AtomLink(new Uri(string.Format("{0}AtomPost.aspx?id={1}", SessionManager.WebsiteUrl, post.Id)))); atomEntry.Links.Add(new AtomLink(new Uri(string.Format("{0}AtomPost.aspx?id={1}", SessionManager.WebsiteUrl, post.Id)), "edit")); AtomLink atomEntryUri = new AtomLink(new Uri(string.Format("{0}{1}", SessionManager.WebsiteUrl, post.LinkUri)), "alternate"); atomEntryUri.ContentType = "text/html"; atomEntry.Links.Add(atomEntryUri); atomEntry.Save(Response.OutputStream); Response.End(); }
private AtomEntry GetPost(TransitPost post) { AtomEntry atomEntry = new AtomEntry(); atomEntry.Title = new AtomTextConstruct(post.Title); foreach (TransitTopic topic in post.Topics) { atomEntry.Categories.Add(new AtomCategory(topic.Name)); } atomEntry.Content = new AtomContent(post.BodyXHTML, "html"); atomEntry.PublishedOn = post.Created; atomEntry.UpdatedOn = post.Modified; atomEntry.Id = new AtomId(new Uri(string.Format("{0}Post/{1}", SessionManager.WebsiteUrl, post.Id))); atomEntry.Links.Add(new AtomLink(new Uri(string.Format("{0}AtomBlog.aspx?id={1}", SessionManager.WebsiteUrl, post.Id)), "edit")); AtomLink atomEntryUri = new AtomLink(new Uri(string.Format("{0}{1}", SessionManager.WebsiteUrl, post.LinkUri)), "alternate"); atomEntryUri.ContentType = "text/html"; atomEntry.Links.Add(atomEntryUri); return atomEntry; }
public void AtomNewPostTest() { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://localhost/DBlog/AtomPost.aspx"); request.Method = "POST"; request.ContentType = "application/atom+xml;type=entry"; string usernamePassword = string.Format("Administrator:"); string basicAuthorization = string.Format("Basic {0}", Convert.ToBase64String( Encoding.ASCII.GetBytes(usernamePassword))); request.Headers.Add("Authorization", basicAuthorization); XmlDocument postXml = new XmlDocument(); postXml.LoadXml( "<?xml version=\"1.0\"?>" + "<entry xmlns=\"http://www.w3.org/2005/Atom\">" + "<title>Atom-Powered Robots Run Amok</title>" + "<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>" + "<updated>2003-12-13T18:30:02Z</updated>" + "<author><name>John Doe</name></author>" + "<content>Some text.</content>" + "</entry>"); byte[] postData = Encoding.UTF8.GetBytes(postXml.OuterXml); request.ContentLength = postData.Length; request.GetRequestStream().Write(postData, 0, postData.Length); request.GetRequestStream().Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string responseLocation = response.Headers["Location"]; Assert.IsNotEmpty(responseLocation); Console.WriteLine(responseLocation); // atom entry returned AtomEntry atomEntry = new AtomEntry(); atomEntry.Load(response.GetResponseStream()); Console.WriteLine(atomEntry.Id.Uri); int id = int.Parse(atomEntry.Id.Uri.ToString().Substring(atomEntry.Id.Uri.ToString().LastIndexOf("/") + 1)); Assert.IsTrue(id > 0); Console.WriteLine(string.Format("Id: {0}", id)); Blog.DeletePost(Ticket, id); }
/// <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); } }
/// <summary> /// Modifies the <see cref="AtomFeed"/> collection entities to match the supplied <see cref="XPathNavigator"/> data source. /// </summary> /// <param name="feed">The <see cref="AtomFeed"/> 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="AtomFeed"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="feed"/> 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 FillFeedCollections(AtomFeed feed, XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(feed, "feed"); Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ XPathNodeIterator authorIterator = source.Select("atom:author", manager); XPathNodeIterator contributorIterator = source.Select("atom:contributor", manager); XPathNodeIterator linkIterator = source.Select("atom:link", manager); XPathNodeIterator entryIterator = source.Select("atom:entry", manager); if (authorIterator != null && authorIterator.Count > 0) { while (authorIterator.MoveNext()) { AtomPersonConstruct author = Atom03SyndicationResourceAdapter.CreatePerson(authorIterator.Current, manager, settings); feed.Authors.Add(author); } } if (contributorIterator != null && contributorIterator.Count > 0) { while (contributorIterator.MoveNext()) { AtomPersonConstruct contributor = Atom03SyndicationResourceAdapter.CreatePerson(contributorIterator.Current, manager, settings); feed.Contributors.Add(contributor); } } if (entryIterator != null && entryIterator.Count > 0) { int counter = 0; while (entryIterator.MoveNext()) { AtomEntry entry = new AtomEntry(); counter++; Atom03SyndicationResourceAdapter.FillEntry(entry, entryIterator.Current, manager, settings); if (settings.RetrievalLimit != 0 && counter > settings.RetrievalLimit) { break; } ((Collection<AtomEntry>)feed.Entries).Add(entry); } } if (linkIterator != null && linkIterator.Count > 0) { while (linkIterator.MoveNext()) { AtomLink link = new AtomLink(); if (link.Load(linkIterator.Current, settings)) { feed.Links.Add(link); } } } }
/// <summary> /// Removes the supplied <see cref="AtomEntry"/> from the current instance's <see cref="Entries"/> collection. /// </summary> /// <param name="entry">The <see cref="AtomEntry"/> to be removed.</param> /// <returns><b>true</b> if the <see cref="AtomEntry"/> was removed from the <see cref="Entries"/> collection, otherwise <b>false</b>.</returns> /// <remarks> /// If the <see cref="Entries"/> collection of the current instance does not contain the specified <see cref="AtomEntry"/>, will return <b>false</b>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="entry"/> is a null reference (Nothing in Visual Basic).</exception> public bool RemoveEntry(AtomEntry entry) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasRemoved = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(entry, "entry"); //------------------------------------------------------------ // Remove entry from collection //------------------------------------------------------------ if (((Collection<AtomEntry>)this.Entries).Contains(entry)) { ((Collection<AtomEntry>)this.Entries).Remove(entry); wasRemoved = true; } return wasRemoved; }
private bool ReadFeedItem(AtomEntry i, Source source,bool? IsForTest) { //Check if there is another article with the same title var url = i.Links.FirstOrDefault(l => l.ContentType == "text/html"); NewsItem oldItem = this.Data.NewsItems.FirstOrDefault(s => s.Title.Trim().ToLower() == i.Title.Content.Trim().ToLower()); if (oldItem != null && new DateTime(oldItem.DatePublished).Date == i.UpdatedOn.Date) { UpdateOldItem(url.Uri.ToString(), source, oldItem); return false; } //Parse the article var article = ParseArticle(url.Uri.ToString(), source.SourceWebsite.Name); if (article == null) { throw new Exception(string.Format("Connot Parse Article url : {0}", url)); } if (string.IsNullOrEmpty(article.Href)) article.Href = url.Uri.ToString(); //Check if there is already an article var oldArticle = this.Data.NewsItems.All().FirstOrDefault(s => s.Href == article.Href); //If its new one if (oldArticle == null) { article.Media = source.SourceWebsite.Name; if (string.IsNullOrEmpty(article.Header)) { article.Header = Regex.Replace(i.Title.Content, @"<img\s[^>]*>(?:\s*?</img>)?", "", RegexOptions.IgnoreCase); } article.Title = article.Header; article.MainPic = article.MainPic; article.DatePublished = (i.UpdatedOn == DateTime.MinValue ? DateTime.Now : i.UpdatedOn).Ticks; article.Categories.Add(this.Data.Categories.All().FirstOrDefault(s => s.Id == source.CategoryId)); article.UsedForClassication = false; article.IsForTest = IsForTest.HasValue ? IsForTest.Value : false; this.Data.NewsItems.Add(article); this.Data.SaveChanges(); return true; } //if we already have it else { if (!oldArticle.Categories.Any(c => c.Id == source.CategoryId)) { oldArticle.Categories.Add(this.Data.Categories.All().FirstOrDefault(s => s.Id == source.CategoryId)); this.Data.NewsItems.Update(article); this.Data.SaveChanges(); } } return false; }
private static string GetOriginalUrl(AtomEntry entry) { var originalUrl = entry.Links.SingleOrDefault(x => String.IsNullOrWhiteSpace(x.Relation)); var alternateUrl = entry.Links.SingleOrDefault(x => x.Relation == "alternate"); var url = originalUrl ?? alternateUrl; return url.Uri.ToString(); }
/// <summary> /// Creates a new <see cref="AtomEntry"/> instance using the specified <see cref="Uri"/>, <see cref="ICredentials"/>, <see cref="IWebProxy"/>, and <see cref="SyndicationResourceLoadSettings"/> object. /// </summary> /// <param name="source">A <see cref="Uri"/> that represents the URL of the syndication resource XML data.</param> /// <param name="options">A <see cref="WebRequestOptions"/> that holds options that should be applied to web requests.</param> /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> object used to configure the <see cref="AtomEntry"/> instance. This value can be <b>null</b>.</param> /// <returns>An <see cref="AtomEntry"/> object loaded using the <paramref name="source"/> data.</returns> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="FormatException">The <paramref name="source"/> data does not conform to the expected syndication content format. In this case, the entry remains empty.</exception> public static AtomEntry Create(Uri source, WebRequestOptions options, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ AtomEntry syndicationResource = new AtomEntry(); //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Create new instance using supplied parameters //------------------------------------------------------------ syndicationResource.Load(source, options, settings); return syndicationResource; }
private AtomEntry GetImage(TransitImage image) { AtomEntry atomEntry = new AtomEntry(); atomEntry.Id = new AtomId(new Uri(string.Format("{0}Image/{1}", SessionManager.WebsiteUrl, image.Id))); atomEntry.Title = new AtomTextConstruct(image.Name); atomEntry.UpdatedOn = DateTime.UtcNow; atomEntry.Summary = new AtomTextConstruct(); atomEntry.Content = new AtomContent("", "image/jpg"); atomEntry.Content.Source = new Uri(string.Format("{0}ShowPicture.aspx?id={1}&ShowThumbnail=false", SessionManager.WebsiteUrl, image.Id)); atomEntry.Links.Add(new AtomLink(new Uri(string.Format("{0}AtomImage.aspx?id={1}", SessionManager.WebsiteUrl, image.Id)), "edit")); AtomLink atomEntryUri = new AtomLink(new Uri(string.Format("{0}ShowPicture.aspx?id={1}&ShowThumbnail=false", SessionManager.WebsiteUrl, image.Id)), "edit-media"); atomEntryUri.ContentType = "image/jpg"; atomEntry.Links.Add(atomEntryUri); return atomEntry; }
/// <summary> /// Instantiates a <see cref="ISyndicationResource"/> that conforms to the specified <see cref="SyndicationContentFormat"/> using the supplied <see cref="Stream"/>. /// </summary> /// <param name="stream">The <see cref="Stream"/> used to load the syndication resource.</param> /// <param name="format">A <see cref="SyndicationContentFormat"/> enumeration value that indicates the type syndication resource the <paramref name="stream"/> represents.</param> /// <returns> /// An <see cref="ISyndicationResource"/> object that conforms to the specified <paramref name="format"/>, initialized using the supplied <paramref name="stream"/>. /// If the <paramref name="format"/> is not supported by the provider, returns a <b>null</b> reference. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="stream"/> is a null reference (Nothing in Visual Basic).</exception> private static ISyndicationResource BuildResource(SyndicationContentFormat format, Stream stream) { //------------------------------------------------------------ // Validate parameters //------------------------------------------------------------ Guard.ArgumentNotNull(stream, "stream"); //------------------------------------------------------------ // Create syndication resource based on content format //------------------------------------------------------------ if (format == SyndicationContentFormat.Apml) { ApmlDocument document = new ApmlDocument(); document.Load(stream); return document; } else if (format == SyndicationContentFormat.Atom) { XPathDocument document = new XPathDocument(stream); XPathNavigator navigator = document.CreateNavigator(); navigator.MoveToRoot(); navigator.MoveToChild(XPathNodeType.Element); if(String.Compare(navigator.LocalName, "entry", StringComparison.OrdinalIgnoreCase) == 0) { AtomEntry entry = new AtomEntry(); entry.Load(navigator); return entry; } else if (String.Compare(navigator.LocalName, "feed", StringComparison.OrdinalIgnoreCase) == 0) { AtomFeed feed = new AtomFeed(); feed.Load(navigator); return feed; } else { return null; } } else if (format == SyndicationContentFormat.BlogML) { BlogMLDocument document = new BlogMLDocument(); document.Load(stream); return document; } else if (format == SyndicationContentFormat.Opml) { OpmlDocument document = new OpmlDocument(); document.Load(stream); return document; } else if (format == SyndicationContentFormat.Rsd) { RsdDocument document = new RsdDocument(); document.Load(stream); return document; } else if (format == SyndicationContentFormat.Rss) { RssFeed feed = new RssFeed(); feed.Load(stream); return feed; } else { return null; } }