public reading_empty_dependencies() { given_feed(AtomContent.Feed(CreationTime, NuGetBaseUri)); given_package(AtomContent.NuGetEntry("openwrap", "1.1.0", "The best package manager for .net")); when_reading_feed(); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>compares 2 content objects</summary> /// <param name="theOne">the One content </param> /// <param name="theOther">the Other content</param> /// <returns>true if identical </returns> ////////////////////////////////////////////////////////////////////// public static bool IsContentIdentical(AtomContent theOne, AtomContent theOther) { if (theOne == null && theOther == null) { return(true); } if (!ObjectModelHelper.IsBaseIdentical(theOne, theOther)) { return(false); } if (String.Compare(theOne.Type, theOther.Type) != 0) { return(false); } if (AtomUri.Compare(theOther.Src, theOther.Src) != 0) { return(false); } String content = theOther.Content == null ? "" : theOther.Content; String other = theOne.Content == null ? "" : theOne.Content; if (String.Compare(content, other) != 0) { return(false); } return(true); }
public AtomEntry updateWebpage(String path, String title, String html, String pageName, DateTime lastModified, bool isIndexPage, string indexHtmlPath = "") { if (cancel()) { return(null); } String url = "https://sites.google.com/feeds/content/site/" + m_siteName + "?path=" + path + (pageName == "" ? "" : "/") + pageName; printMessage(url); try { AtomEntry entry = m_service.Get(url); if (entry == null) { return(createWebPage(url, path, title, html, pageName, lastModified, isIndexPage)); } if (html != "") { double diff = 0; if (m_lastRunTimes.ContainsKey(url)) { DateTime lastRunTime = DateTime.Parse((String)m_lastRunTimes[url]); TimeSpan dt = lastModified - lastRunTime; diff = Math.Abs(dt.TotalSeconds); } if (!m_lastRunTimes.ContainsKey(url) || diff > 1) { AtomContent newContent = new AtomContent(); newContent.Type = "html"; newContent.Content = m_replaceLinks ? replaceLinks(html, url, isIndexPage, indexHtmlPath) : html; entry.Content = newContent; entry.Title.Text = m_convertCase ? IndianBridge.Common.Utilities.ConvertCaseString(title) : title; m_service.Update(entry); if (!m_lastRunTimes.ContainsKey(url)) { printMessage("UPDATED. No entry was found for last run time."); } else { DateTime lastRunTime = DateTime.Parse((String)m_lastRunTimes[url]); printMessage("UPDATED. (Last Modified Time " + lastModified.ToString() + " is later than last update time " + lastRunTime.ToString() + ")"); } m_lastRunTimes[url] = lastModified; } else { DateTime lastRunTime = DateTime.Parse((String)m_lastRunTimes[url]); printMessage("NOT UPDATED. (Last Modified Time " + lastModified.ToString() + " is earlier than (or equal to) last update time " + lastRunTime.ToString() + ")"); } } numberOfPagesAlreadyUploaded++; reportProgress(title); return(entry); } catch (Exception) { return(createWebPage(url, path, title, html, pageName, lastModified, isIndexPage, indexHtmlPath)); } }
/// <summary> /// Get the content of possibly null AtomContent /// </summary> /// <param name="content">The Google AtomContent</param> /// <returns>The content or empty string if the content or it's Content was null</returns> public static string SafeGetContent(AtomContent content) { if (content == null) { return(string.Empty); } return(content.Content ?? string.Empty); }
//============================================================ // PRIVATE METHODS //============================================================ #region CreateContent(XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) /// <summary> /// Creates a <see cref="AtomContent"/> using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <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> /// <returns>A <see cref="AtomContent"/> instance initialized using the supplied <paramref name="source"/>.</returns> /// <remarks> /// This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a Atom 0.3 Content construct. /// </remarks> /// <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 AtomContent CreateContent(XPathNavigator source, XmlNamespaceManager manager, SyndicationResourceLoadSettings settings) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ AtomContent content = new AtomContent(); string modeAttribute = String.Empty; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); Guard.ArgumentNotNull(settings, "settings"); //------------------------------------------------------------ // Attempt to extract common attributes information //------------------------------------------------------------ AtomUtility.FillCommonObjectAttributes(content, source); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if (source.HasAttributes) { string typeAttribute = source.GetAttribute("type", String.Empty); modeAttribute = source.GetAttribute("mode", String.Empty); if (!String.IsNullOrEmpty(typeAttribute)) { content.ContentType = typeAttribute; } } if (String.Compare(modeAttribute, "xml", StringComparison.OrdinalIgnoreCase) == 0) { XPathNavigator xhtmlDivNavigator = source.SelectSingleNode("xhtml:div", manager); if (xhtmlDivNavigator != null && !String.IsNullOrEmpty(xhtmlDivNavigator.Value)) { content.Content = xhtmlDivNavigator.Value; } else if (!String.IsNullOrEmpty(source.Value)) { content.Content = source.Value; } } else if (!String.IsNullOrEmpty(source.Value)) { content.Content = source.Value; } SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings); adapter.Fill(content, manager); return(content); }
public void AtomContentConstructorTest() { AtomContent target = new AtomContent(); Assert.IsNotNull(target); Assert.IsNull(target.Content); Assert.IsNull(target.Src); Assert.IsTrue(target.Type == "text"); }
public void TypeTest() { AtomContent target = new AtomContent(); // TODO: Initialize to an appropriate value string expected = "TestValue"; string actual; target.Type = expected; actual = target.Type; Assert.AreEqual(expected, actual); }
public void SrcTest() { AtomContent target = new AtomContent(); // TODO: Initialize to an appropriate value AtomUri expected = new AtomUri("http://www.test.com/"); AtomUri actual; target.Src = expected; actual = target.Src; Assert.AreEqual(expected, actual); }
public void ContentTest() { AtomEntry target = new AtomEntry(); // TODO: Initialize to an appropriate value AtomContent expected = new AtomContent(); AtomContent actual; target.Content = expected; actual = target.Content; Assert.AreEqual(expected, actual); }
public reading_one_dependency_without_version() { given_feed(AtomContent.Feed(CreationTime, NuGetBaseUri)); given_package(AtomContent.NuGetEntry( "openwrap", "1.1.0", "The best package manager for .net", dependencies: "openfilesystem")); when_reading_feed(); }
public void AbsoluteUriTest() { AtomContent target = new AtomContent(); // TODO: Initialize to an appropriate value AtomUri expected = new AtomUri("http://www.test.com/"); target.Src = expected; string actual; actual = target.AbsoluteUri; Assert.AreEqual(actual, "http://www.test.com/"); }
public reading_multiple_dependencies_with_ranges() { given_feed(AtomContent.Feed(CreationTime, NuGetBaseUri)); given_package(AtomContent.NuGetEntry( "openwrap", "1.1.0", "The best package manager for .net", dependencies: "openfilesystem:1.0.0|sharpziplib|mono.cecil:[0.9,1.0)")); when_reading_feed(); }
private static void RunSample(string username, string password, string accountId) { // Connect to the service ContentForShoppingService service = new ContentForShoppingService("ManagedAccounts-Sample", accountId); service.setUserCredentials(username, password); // Retrieve the list of all existing accounts ManagedAccountsFeed feed = service.QueryManagedAccounts(); // Display title and id for each managed account Console.WriteLine("Listing all managed accounts returned"); foreach (ManagedAccountsEntry m in feed.Entries) { Console.WriteLine("Managed Account: " + m.Title.Text + " (" + m.InternalId + ")"); } // Create a new subaccount entry ManagedAccountsEntry entry = new ManagedAccountsEntry(); entry.Title.Text = "Bob\'s Shirts"; AtomContent c = new AtomContent(); c.Content = "Founded in 1980, Bob has been selling shirts that you don\'t want for over 30 years."; entry.Content = c; entry.AdultContent = "no"; entry.InternalId = "Subaccount100"; entry.ReviewsUrl = "http://my.site.com/reviews?mo=user-rating&user=Subaccount100"; // Add the subaccount entry Console.WriteLine("Inserting managed account"); ManagedAccountsEntry inserted = service.InsertManagedAccount(entry); // Update the managed account we just inserted c = new AtomContent(); c.Content = "Founded in 1980, Bob has been selling shirts that you love for over 30 years."; inserted.Content = c; Console.WriteLine("Updating managed account"); ManagedAccountsEntry updated = service.UpdateManagedAccount(inserted); // Retrieve the new list of managed accounts feed = service.QueryManagedAccounts(); // Display title and id for each managed account Console.WriteLine("Listing all managed accounts returned"); foreach (ManagedAccountsEntry m in feed.Entries) { Console.WriteLine("Managed Account: " + m.Title.Text + " (" + m.InternalId + ")"); } // Delete the managed account we inserted and updated Console.WriteLine("Deleting product"); service.DeleteManagedAccount(updated); }
public reading_package_feeds() { given_remote_resource("http://localhost/packages/1", "application/atom+xml", AtomContent.Feed(Now, "http://localhost/packages/".ToUri(), "2".ToUri()) .Entry(AtomContent.NuGetEntry("openwrap", "1.0", "summary")) .ToString()); given_remote_resource("http://localhost/packages/2", "application/atom+xml", AtomContent.Feed(Now, "http://localhost/packages/".ToUri()) .Entry(AtomContent.NuGetEntry("openfilesystem", "1.0", "summary")) .ToString()); when_reading_packages(); }
public void TestContents() { AtomContent content = new AtomContent(); content.Content = "sample text"; content.Mode = Mode.Xml; content.Type = MediaType.TextPlain; entry.Contents.Add(content); Assert.AreEqual(content.LocalName, "content"); Assert.AreEqual(content.FullName, "atom:content"); Assert.AreSame(entry.Contents[0], content); Assert.AreEqual(entry.Contents[0], content); }
public from_user_input_by_name() { given_remote_resource( "https://go.microsoft.com/fwlink/?LinkID=206669", GET => new MemoryResponse(307) { Headers = { { "Location", "http://middle.earth/mordor/nuget" } } } ); given_remote_resource( "http://middle.earth/mordor/nuget", "application/atom+xml", AtomContent.ServiceDocument("http://middle.earth/mordor/nuget/", "Packages") ); when_detecting("nuget"); }
public void TestMultipleMultipartsContent() { AtomEntry entry = new AtomEntry(new Uri("http://purl.org/atom/ns#")); AtomContent content = new AtomContent(new Uri("http://purl.org/atom/ns#")); content.Content = "sample text"; content.Mode = Mode.Xml; content.Type = MediaType.MultipartAlternative; content.XmlLang = Language.en_US; entry.Contents.Add(content); content = new AtomContent(new Uri("http://purl.org/atom/ns#")); content.Content = "sample text"; content.Mode = Mode.Xml; content.Type = MediaType.MultipartAlternative; content.XmlLang = Language.en_US; entry.Contents.Add(content); }
/// <summary> /// Performs some checks inside the collection. Used for compliancy to the standard. /// </summary> /// <param name="content">The <see cref="AtomContent"/> to check.</param> private void CheckInsertion(AtomContent content) { if (this.List.Count != 0) { if (content.Type == MediaType.MultipartAlternative) { foreach (AtomContent item in this) { if (item.Type == MediaType.MultipartAlternative) { if (item.Type == content.Type) { throw new OnlyOneMultipartContentAllowedException( "There can't be more than one content with multipart/alternative media type."); } } } } } }
public SitesEntry AddSite(string url) { var entry = new AtomEntry(); var content = new AtomContent(); content.Src = new AtomUri(url); entry.Content = content; entry.Content.Type = ""; try { return(service.Insert(new Uri(SiteQueryUrl), entry) as SitesEntry); } catch (Exception ex) { var status = ((WebException)(ex.InnerException)).Status; if (status != WebExceptionStatus.ProtocolError) { Syslog.Write(ex); } } return(null); }
/// <summary>Removes the first occurrence of a specific <see cref="AtomContent"/> from the <see cref="AtomContentCollection"/>.</summary> /// <param name="content">The <see cref="AtomContent"/> to remove from the <see cref="AtomContentCollection"/>.</param> public void Remove(AtomContent content) { List.Remove(content); }
/// <summary>Inserts a <see cref="AtomContent"/> into this collection at the specified index.</summary> /// <param name="index">The zero-based index of the collection at which <i>content</i> should be inserted.</param> /// <param name="content">The <see cref="AtomContent"/> to insert into this collection.</param> public void Insert(int index, AtomContent content) { CheckInsertion(content); List.Insert(index, content); }
/// <summary> /// Searches for the specified <see cref="AtomContent"/> and returns the zero-based index of the first occurrence /// within the entire <see cref="AtomContentCollection"/>. /// </summary> /// <param name="content">The <see cref="AtomContent"/> to locate in the <see cref="AtomContentCollection"/>.</param> /// <returns>The zero-based index of the first occurrence of <i>content</i> within the entire <see cref="AtomContentCollection"/>, /// if found; otherwise, -1.</returns> public int IndexOf(AtomContent content) { return List.IndexOf(content); }
/// If no version specified and atom does not exist, creates atom with default version "1.0.0" /// If no version specified and atom does exist, or there is an atom with specified version, /// creates new version with the same major and middle versions and incremented minor version public async Task <AtomId> AddAsync(AtomId atomId, IEnumerable <AtomId> dependencies, byte[] content) { if (await ExistsExactAsync(atomId)) { throw new ArgumentException(string.Format(AtomAlreadyExists, atomId.Kind, atomId.Name, atomId.Version)); } var version = atomId.Version ?? await LastVersionAsync(atomId.Kind, atomId.Name); if (atomId.Version == null && version != null) { VersionUtils.TryParse(version, out int major, out int?middle, out int?minor, out string name); version = VersionUtils.Serialize(major, middle.GetValueOrDefault(), minor.GetValueOrDefault() + 1, null); } else if (atomId.Version == null) { version = AtomId.DefaultVersion; } var dbAtom = new Atom { Kind = atomId.Kind, Name = atomId.Name, Version = version, }; await _context.Atoms.AddAsync(dbAtom); dependencies = await FetchVersionsAsync(dependencies); var depRefs = dependencies.Select(depId => _context.Atoms.Single(a => a.Kind == depId.Kind && a.Name == depId.Name && a.Version == depId.Version)); var dbDeps = from dep in depRefs select new AtomDependency { Dependent = dbAtom, Dependency = dep }; await _context.AtomDependencies.AddRangeAsync(dbDeps); var dbContent = new AtomContent { Atom = dbAtom, Content = content }; await _context.AtomContents.AddAsync(dbContent); await _context.SaveChangesAsync(); return(new AtomId(atomId.Kind, atomId.Name, version)); }
private static void RunSample(string username, string password, string accountId) { // Connect to the service ContentForShoppingService service = new ContentForShoppingService("ContentForShopping-Sample"); service.setUserCredentials(username, password); // Retrieve the list of all existing products string projection = "schema"; ProductQuery query = new ProductQuery(projection, accountId); ProductFeed feed = service.Query(query); // Display title and id for each product Console.WriteLine("Listing all products"); foreach (ProductEntry p in feed.Entries) { Console.WriteLine("Product: " + p.Title.Text + " (" + p.ProductId + ")"); } // Create a new product ProductEntry entry = new ProductEntry(); entry.Title.Text = "Wool sweater"; AtomContent c = new AtomContent(); c.Content = "Comfortable and soft, this sweater will keep you warm on those cold winter nights. Red and blue stripes."; entry.Content = c; entry.ProductId = "123457"; entry.Language = "it"; entry.TargetCountry = "US"; entry.ContentLanguage = "en"; entry.Brand = "ACME"; entry.Condition = "new"; entry.Price = new Price("usd", "25"); entry.ProductType = "Clothing & Accessories > Clothing > Outerwear > Sweaters"; entry.Quantity = 3; entry.ShippingWeight = new ShippingWeight("lb", "0.1"); entry.ImageLink = new ImageLink("http://www.example.com/image.jpg"); entry.Availability = "available for order"; entry.Channel = "online"; entry.Gender = "female"; entry.Material = "wool"; entry.Pattern = "Red and blue stripes"; entry.Color = "red"; AtomLink link = new AtomLink(); link.HRef = "http://www.example.com"; link.Rel = "alternate"; link.Type = "text/html"; entry.Links.Add(link); // Shipping rules Shipping s1 = new Shipping(); s1.Country = "US"; s1.Region = "MA"; s1.Service = "Speedy Shipping - Ground"; s1.Price = new ShippingPrice("usd", "5.95"); Shipping s2 = new Shipping(); s2.Country = "US"; s2.Region = "024*"; s2.Service = "Speedy Shipping - Air"; s2.Price = new ShippingPrice("usd", "7.95"); entry.ShippingRules.Add(s1); entry.ShippingRules.Add(s2); // Tax rules Tax t1 = new Tax(); t1.Country = "US"; t1.Region = "CA"; t1.Rate = "8.25"; t1.Ship = true; Tax t2 = new Tax(); t2.Country = "US"; t2.Region = "926*"; t2.Rate = "8.75"; t2.Ship = false; entry.TaxRules.Add(t1); entry.TaxRules.Add(t2); // Additional Image Links AdditionalImageLink il1 = new AdditionalImageLink("http://www.example.com/1.jpg"); entry.AdditionalImageLinks.Add(il1); AdditionalImageLink il2 = new AdditionalImageLink("http://www.example.com/2.jpg"); entry.AdditionalImageLinks.Add(il2); // Add the product to the server feed Console.WriteLine("Inserting product"); ProductEntry inserted = service.Insert(feed, entry); // Update the product we just inserted inserted.Title.Text = "2011 Wool sweater"; Console.WriteLine("Updating product"); ProductEntry updated = service.Update(inserted); // Retrieve the new list of products feed = service.Query(query); // Display title and id for each product Console.WriteLine("Listing all products again"); foreach (ProductEntry p in feed.Entries) { Console.WriteLine("Product: " + p.Title.Text + " (" + p.ProductId + ")"); } // Delete the item we inserted and updated Console.WriteLine("Deleting product"); service.Delete(updated); }
/// <summary> /// Determines whether the <see cref="AtomContentCollection"/> contains a specific element. /// </summary> /// <param name="content">The <see cref="AtomContent"/> to locate in the <see cref="AtomContentCollection"/>.</param> /// <returns>true if the <see cref="AtomContentCollection"/> contains the specified item, otherwise false.</returns> public bool Contains(AtomContent content) { return this.List.Contains(content); }
/// <summary> /// Performs some checks inside the collection. Used for compliancy to the standard. /// </summary> /// <param name="content">The <see cref="AtomContent"/> to check.</param> private void CheckInsertion(AtomContent content) { if(this.List.Count != 0) if(content.Type == MediaType.MultipartAlternative) foreach(AtomContent item in this) if(item.Type == MediaType.MultipartAlternative) if(item.Type == content.Type) throw new OnlyOneMultipartContentAllowedException( "There can't be more than one content with multipart/alternative media type."); }
/// <summary> /// Determines whether the <see cref="AtomContentCollection"/> contains a specific element. /// </summary> /// <param name="content">The <see cref="AtomContent"/> to locate in the <see cref="AtomContentCollection"/>.</param> /// <returns>true if the <see cref="AtomContentCollection"/> contains the specified item, otherwise false.</returns> public bool Contains(AtomContent content) { return(this.List.Contains(content)); }
/// <summary> /// Adds an object to the end of the <see cref="AtomContentCollection"/>. /// </summary> /// <param name="content">The <see cref="AtomContent"/> to be added to the end of the <see cref="AtomContentCollection"/>.</param> /// <returns>The <see cref="AtomContentCollection"/> index at which the value has been added.</returns> public int Add(AtomContent content) { CheckInsertion(content); return(this.List.Add(content)); }
/// <summary> /// Adds an object to the end of the <see cref="AtomContentCollection"/>. /// </summary> /// <param name="content">The <see cref="AtomContent"/> to be added to the end of the <see cref="AtomContentCollection"/>.</param> /// <returns>The <see cref="AtomContentCollection"/> index at which the value has been added.</returns> public int Add(AtomContent content) { CheckInsertion(content); return this.List.Add(content); }
public AtomEntry updateWebpage(String path, String title, String html, String pageName, DateTime lastModified) { String url = "https://sites.google.com/feeds/content/site/" + sitename + "?path=" + path + "/" + pageName; if (this.debugFlag) { printDebugMessage("Updating Page : " + url); } AtomEntry entry = null; try { entry = service.Get(url); } catch (Exception) { return(createWebPage(url, path, title, html, pageName, lastModified)); } if (entry == null) { return(createWebPage(url, path, title, html, pageName, lastModified)); } if (html != "") { double diff = 0; if (lastRunTimes.ContainsKey(url)) { DateTime lastRunTime = (DateTime)lastRunTimes[url]; TimeSpan dt = lastModified - lastRunTime; diff = Math.Abs(dt.TotalSeconds); } if (!lastRunTimes.ContainsKey(url) || diff > 1) { AtomContent newContent = new AtomContent(); newContent.Type = "html"; newContent.Content = html; entry.Content = newContent; entry.Title.Text = IndianBridge.Common.Utility.ConvertCaseString(title); service.Update(entry); if (!lastRunTimes.ContainsKey(url)) { printDebugMessage(url + " - Updated. No entry was found for last run time."); } else { DateTime lastRunTime = (DateTime)lastRunTimes[url]; if (this.debugFlag) { printDebugMessage(url + " - Updated. (Last Modified Time " + lastModified.ToString() + " is later than last update time " + lastRunTime.ToString() + ")"); } } lastRunTimes[url] = lastModified; /*TextWriter tw = new StreamWriter(m_hashTableFileName, true); * tw.WriteLine(url + "," + lastModified); * tw.Close();*/ } else { DateTime lastRunTime = (DateTime)lastRunTimes[url]; if (this.debugFlag) { printDebugMessage(url + " - No Changes to Upload. (Last Modified Time " + lastModified.ToString() + " is earlier than (or equal to) last update time " + lastRunTime.ToString() + ")"); } } } return(entry); }
public reading_links() { given_feed( AtomContent.Feed(DateTimeOffset.Now, "http://localhost/".ToUri(), "http://localhost/next".ToUri())); when_reading_feed(); }
/// <summary> /// Searches for the specified <see cref="AtomContent"/> and returns the zero-based index of the first occurrence /// within the entire <see cref="AtomContentCollection"/>. /// </summary> /// <param name="content">The <see cref="AtomContent"/> to locate in the <see cref="AtomContentCollection"/>.</param> /// <returns>The zero-based index of the first occurrence of <i>content</i> within the entire <see cref="AtomContentCollection"/>, /// if found; otherwise, -1.</returns> public int IndexOf(AtomContent content) { return(List.IndexOf(content)); }
public void XmlNameTest() { AtomContent target = new AtomContent(); // TODO: Initialize to an appropriate value Assert.AreEqual(AtomParserNameTable.XmlContentElement, target.XmlName); }
private AtomRoot GetAtomCore(string category, int maxDayCount, int maxEntryCount) { if (RedirectToFeedBurnerIfNeeded(category) == true) { return(null); } EntryCollection entries = null; //We only build the entries if blogcore doesn't exist and we'll need them later... if (dataService.GetLastEntryUpdate() == DateTime.MinValue) { entries = BuildEntries(category, maxDayCount, maxEntryCount); } //Try to get out as soon as possible with as little CPU as possible if (inASMX) { if (SiteUtilities.GetStatusNotModified(SiteUtilities.GetLatestModifedEntryDateTime(dataService, entries))) { return(null); } } if (inASMX) { string referrer = Context.Request.UrlReferrer != null?Context.Request.UrlReferrer.AbsoluteUri:""; if (ReferralBlackList.IsBlockedReferrer(referrer)) { if (siteConfig.EnableReferralUrlBlackList404s) { return(null); } } else { loggingService.AddReferral( new LogDataItem( Context.Request.RawUrl, referrer, Context.Request.UserAgent, Context.Request.UserHostName)); } } //not-modified didn't work, do we have this in cache? string CacheKey = "Atom:" + category + ":" + maxDayCount.ToString() + ":" + maxEntryCount.ToString(); AtomRoot atomFeed = cache[CacheKey] as AtomRoot; if (atomFeed == null) //we'll have to build it... { atomFeed = new AtomRoot(); //However, if we made it this far, the not-modified check didn't work, and we may not have entries... if (entries == null) { entries = BuildEntries(category, maxDayCount, maxEntryCount); } if (siteConfig.RssLanguage != null && siteConfig.RssLanguage.Length > 0) { atomFeed.Lang = siteConfig.RssLanguage; } else //original default behavior of dasBlog { atomFeed.Lang = "en-us"; } if (category == null) { atomFeed.Title = siteConfig.Title; } else { atomFeed.Title = siteConfig.Title + " - " + category; } atomFeed.Tagline = siteConfig.Subtitle; atomFeed.Links.Add(new AtomLink(SiteUtilities.GetBaseUrl(siteConfig))); atomFeed.Links.Add(new AtomLink(SiteUtilities.GetAtomUrl(siteConfig), "self", null)); atomFeed.Author = new AtomParticipant(); // shouldn't we use the display name of an owner?? atomFeed.Author.Name = siteConfig.Copyright; atomFeed.Generator = new AtomGenerator(); atomFeed.Generator.Version = GetType().Assembly.GetName().Version.ToString(); atomFeed.Icon = "favicon.ico"; atomFeed.Id = SiteUtilities.GetBaseUrl(siteConfig); atomFeed.Logo = null; if (siteConfig.ChannelImageUrl != null && siteConfig.ChannelImageUrl.Trim().Length > 0) { if (siteConfig.ChannelImageUrl.StartsWith("http")) { atomFeed.Logo = siteConfig.ChannelImageUrl; } else { atomFeed.Logo = SiteUtilities.RelativeToRoot(siteConfig, siteConfig.ChannelImageUrl); } } DateTime feedModified = DateTime.MinValue; foreach (Entry entry in entries) { if (entry.IsPublic == false || entry.Syndicated == false) { continue; } string entryLink = SiteUtilities.GetPermaLinkUrl(siteConfig, (ITitledEntry)entry); string entryGuid = SiteUtilities.GetPermaLinkUrl(siteConfig, entry.EntryId); AtomEntry atomEntry = new AtomEntry(entry.Title, new AtomLink(entryLink), entryGuid, entry.CreatedUtc, entry.ModifiedUtc); //atomEntry.Created = entry.CreatedUtc; //not needed in 1.0 atomEntry.Summary = PreprocessItemContent(entry.EntryId, entry.Description); // for multiuser blogs we want to be able to // show the author per entry User user = SiteSecurity.GetUser(entry.Author); if (user != null) { // only the displayname atomEntry.Author = new AtomParticipant() { Name = user.DisplayName }; } if (entry.Categories != null && entry.Categories.Length > 0) { if (atomEntry.Categories == null) { atomEntry.Categories = new AtomCategoryCollection(); } string[] cats = entry.Categories.Split(';'); foreach (string c in cats) { AtomCategory cat = new AtomCategory(); //paulb: scheme should be a valid IRI, acsording to the spec // (http://www.atomenabled.org/developers/syndication/atom-format-spec.php#element.category) // so I changed this to the Category view for specified category. Now the feed validator likes us again ;-) cat.Scheme = SiteUtilities.GetCategoryViewUrl(siteConfig, c); // "hierarchical"; // sub categories should be delimited using the path delimiter string cleanCat = c.Replace('|', '/'); //Grab the first category, atom doesn't let us do otherwise! cat.Term = HttpUtility.HtmlEncode(cleanCat); cat.Label = HttpUtility.HtmlEncode(cleanCat); atomEntry.Categories.Add(cat); } } // only if we don't have a summary we emit the content if (siteConfig.AlwaysIncludeContentInRSS || entry.Description == null || entry.Description.Length == 0) { atomEntry.Summary = null; // remove empty summary tag try { AtomContent atomContent = new AtomContent(); atomContent.Type = "xhtml"; XmlDocument xmlDoc2 = new XmlDocument(); xmlDoc2.LoadXml(ContentFormatter.FormatContentAsXHTML(PreprocessItemContent(entry.EntryId, entry.Content), "div")); atomContent.anyElements = new XmlElement[] { xmlDoc2.DocumentElement }; // set the langauge for the content item atomContent.Lang = entry.Language; atomEntry.Content = atomContent; } catch (Exception) //XHTML isn't happening today { //Try again as HTML AtomContent atomContent = new AtomContent(); atomContent.Type = "html"; atomContent.TextContent = ContentFormatter.FormatContentAsHTML(PreprocessItemContent(entry.EntryId, entry.Content)); // set the langauge for the content item atomContent.Lang = entry.Language; atomEntry.Content = atomContent; } } if (atomEntry.ModifiedUtc > feedModified) { feedModified = atomEntry.ModifiedUtc; } atomFeed.Entries.Add(atomEntry); } // set feed modified date to the most recent entry date atomFeed.ModifiedUtc = feedModified; cache.Insert(CacheKey, atomFeed, DateTime.Now.AddMinutes(5)); } return(atomFeed); }