public void ITunes_ExplicitMaterialByNameTest() { var expected = ITunesExplicitMaterial.Clean; var actual = ITunesSyndicationExtension.ExplicitMaterialByName("clean"); Assert.AreEqual((double)expected, (double)actual, 3e-6); }
public void ITunesSyndicationExtensionConstructorTest() { ITunesSyndicationExtension target = new ITunesSyndicationExtension(); Assert.IsNotNull(target); Assert.IsInstanceOfType(target, typeof(ITunesSyndicationExtension)); }
/// <summary> /// Provides example code for the ITunesSyndicationExtension class. /// </summary> public static void ClassExample() { // Framework auto-discovers supported extensions based on XML namespace attributes (xmlns) defined on root of resource RssFeed feed = RssFeed.Create(new Uri("http://www.example.com/feed.aspx?format=rss")); // Extensible framework entities provide properties/methods to determine if entity is extended and predicate based seaching against available extensions if (feed.Channel.HasExtensions) { ITunesSyndicationExtension channelExtension = feed.Channel.FindExtension(ITunesSyndicationExtension.MatchByType) as ITunesSyndicationExtension; if (channelExtension != null) { // Process channel extension } } foreach (RssItem item in feed.Channel.Items) { if (item.HasExtensions) { ITunesSyndicationExtension itemExtension = item.FindExtension(ITunesSyndicationExtension.MatchByType) as ITunesSyndicationExtension; if (itemExtension != null) { // Process extension for current item } } } // By default the framework will automatically determine what XML namespace attributes (xmlns) to write // on the root of the resource based on the extensions applied to extensible parent and child entities using (FileStream stream = new FileStream("Feed.xml", FileMode.Create, FileAccess.Write)) { feed.Save(stream); } }
public void ITunes_LoadTest() { ITunesSyndicationExtension target = new ITunesSyndicationExtension(); // TODO: Initialize to an appropriate value var nt = new NameTable(); var ns = new XmlNamespaceManager(nt); var xpc = new XmlParserContext(nt, ns, "US-en", XmlSpace.Default); var strXml = ExtensionTestUtil.GetWrappedXml(namespc, strExtXml); using (XmlReader reader = new XmlTextReader(strXml, XmlNodeType.Document, xpc)) { #if false //var document = new XPathDocument(reader); //var nav = document.CreateNavigator(); //nav.Select("//item"); do { if (!reader.Read()) { break; } } while (reader.NodeType != XmlNodeType.EndElement || reader.Name != "webMaster"); bool expected = true; bool actual; actual = target.Load(reader); Assert.AreEqual(expected, actual); #else RssFeed feed = new RssFeed(); feed.Load(reader); #endif } }
public void ITunes_ExplicitMaterialAsStringTest() { var value = ITunesExplicitMaterial.Clean; string expected = "clean"; string actual = ITunesSyndicationExtension.ExplicitMaterialAsString(value); Assert.AreEqual(expected, actual); }
public void ITunes_ToStringTest() { ITunesSyndicationExtension target = CreateExtension1(); string expected = nycText; string actual; actual = target.ToString(); Assert.AreEqual(expected, actual); }
public void ITunes_op_InequalityTest() { ITunesSyndicationExtension first = CreateExtension1(); ITunesSyndicationExtension second = CreateExtension2(); bool expected = true; bool actual = (first != second); Assert.AreEqual(expected, actual); }
public void ITunes_MatchByTypeTest() { ISyndicationExtension extension = CreateExtension1(); bool expected = true; bool actual; actual = ITunesSyndicationExtension.MatchByType(extension); Assert.AreEqual(expected, actual); }
public void ITunes_GetHashCodeTest() { ITunesSyndicationExtension target = CreateExtension1(); int expected = -765758449; int actual; actual = target.GetHashCode(); Assert.AreEqual(expected, actual); }
public void ITunes_op_EqualityTest_Failure() { ITunesSyndicationExtension first = CreateExtension1(); ITunesSyndicationExtension second = CreateExtension2(); bool expected = false; bool actual; actual = (first == second); Assert.AreEqual(expected, actual); }
public void ITunes_CompareToTest() { ITunesSyndicationExtension target = CreateExtension1(); object obj = CreateExtension1(); int expected = 0; int actual; actual = target.CompareTo(obj); Assert.AreEqual(expected, actual); }
public void ITunes_EqualsTest() { ITunesSyndicationExtension target = CreateExtension1(); object obj = CreateExtension1(); bool expected = true; bool actual; actual = target.Equals(obj); Assert.AreEqual(expected, actual); }
public void ITunes_op_GreaterThanTest() { ITunesSyndicationExtension first = CreateExtension1(); ITunesSyndicationExtension second = CreateExtension2(); bool expected = false; bool actual = false; actual = (first > second); Assert.AreEqual(expected, actual); }
public void ITunes_ContextTest() { ITunesSyndicationExtension target = CreateExtension1(); ITunesSyndicationExtensionContext expected = CreateContext1(); ITunesSyndicationExtensionContext actual; // target.Context = expected; actual = target.Context; var b = actual.Equals(expected); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void ITunes_LoadTest() { ITunesSyndicationExtension target = new ITunesSyndicationExtension(); // TODO: Initialize to an appropriate value var nt = new NameTable(); var ns = new XmlNamespaceManager(nt); var xpc = new XmlParserContext(nt, ns, "US-en", XmlSpace.Default); var strXml = ExtensionTestUtil.GetWrappedXml(namespc, strExtXml); using (XmlReader reader = new XmlTextReader(strXml, XmlNodeType.Document, xpc)) { RssFeed feed = new RssFeed(); feed.Load(reader); } }
private ITunesSyndicationExtension CreateExtension2() { var nyc = new ITunesSyndicationExtension(); nyc.Context.Author = "NewStar"; nyc.Context.Categories.Add(new ITunesCategory("Dance")); nyc.Context.Categories.Add(new ITunesCategory("Funk")); nyc.Context.Duration = new TimeSpan(0, 4, 32); nyc.Context.ExplicitMaterial = ITunesExplicitMaterial.Yes; nyc.Context.Image = new Uri("http://www.example.com/newimage.png"); nyc.Context.IsBlocked = true; nyc.Context.Keywords.Add("loud"); nyc.Context.Keywords.Add("offend your parents"); nyc.Context.NewFeedUrl = null; nyc.Context.Owner = new ITunesOwner("*****@*****.**", "NewStar's Friend's Uncle"); nyc.Context.Subtitle = "That song you will like."; nyc.Context.Summary = "Better than that other song."; return(nyc); }
private ITunesSyndicationExtension CreateExtension1() { var nyc = new ITunesSyndicationExtension(); nyc.Context.Author = "BigStar"; nyc.Context.Categories.Add(new ITunesCategory("Rock")); nyc.Context.Categories.Add(new ITunesCategory("Folk")); nyc.Context.Duration = new TimeSpan(0, 3, 21); nyc.Context.ExplicitMaterial = ITunesExplicitMaterial.Clean; nyc.Context.Image = new Uri("http://www.eexample.com/image.jpg"); nyc.Context.IsBlocked = false; nyc.Context.Keywords.Add("loud"); nyc.Context.Keywords.Add("good for parties"); nyc.Context.NewFeedUrl = null; nyc.Context.Owner = new ITunesOwner("*****@*****.**", "BigStar's Guy"); nyc.Context.Subtitle = "That song you like."; nyc.Context.Summary = "Duh... That song you like"; return(nyc); }
private void RenderRss() { Argotic.Syndication.RssFeed feed = new Argotic.Syndication.RssFeed(); RssChannel channel = new RssChannel(); channel.Generator = "mojoPortal Blog Module"; channel.Language = SiteUtils.GetDefaultCulture(); feed.Channel = channel; if (module.ModuleTitle.Length > 0) { channel.Title = module.ModuleTitle; } else { channel.Title = "Blog"; // it will cause an error if this is left blank so we must populate it if the module title is an emty string. } // this became broken when we combined query string params, since pageid is not one of the params this always returns the home page url // instead of the blog page url //string pu = WebUtils.ResolveServerUrl(SiteUtils.GetCurrentPageUrl()); string pu = WebUtils.ResolveServerUrl(SiteUtils.GetPageUrl(pageSettings)); channel.Link = new System.Uri(pu); channel.SelfLink = Request.Url; if (config.ChannelDescription.Length > 0) { channel.Description = config.ChannelDescription; } if (config.Copyright.Length > 0) { channel.Copyright = config.Copyright; } channel.ManagingEditor = config.ManagingEditorEmail; if (config.ManagingEditorName.Length > 0) { channel.ManagingEditor += " (" + config.ManagingEditorName + ")"; } if (config.FeedTimeToLive > -1) { channel.TimeToLive = config.FeedTimeToLive; } // Create and add iTunes information to feed channel ITunesSyndicationExtension channelExtension = new ITunesSyndicationExtension(); channelExtension.Context.Subtitle = config.ChannelDescription; if (config.HasExplicitContent) { channelExtension.Context.ExplicitMaterial = ITunesExplicitMaterial.Yes; } else { channelExtension.Context.ExplicitMaterial = ITunesExplicitMaterial.No; } channelExtension.Context.Author = config.ManagingEditorEmail; if (config.ManagingEditorName.Length > 0) { channelExtension.Context.Author += " (" + config.ManagingEditorName + ")"; } channelExtension.Context.Summary = config.ChannelDescription; channelExtension.Context.Owner = new ITunesOwner(config.ManagingEditorEmail, config.ManagingEditorName); if (config.FeedLogoUrl.Length > 0) { try { channelExtension.Context.Image = new Uri(config.FeedLogoUrl); } catch (ArgumentNullException) { } catch (UriFormatException) { } } if (config.FeedMainCategory.Length > 0) { ITunesCategory mainCat = new ITunesCategory(config.FeedMainCategory); if (config.FeedSubCategory.Length > 0) { mainCat.Categories.Add(new ITunesCategory(config.FeedSubCategory)); } channelExtension.Context.Categories.Add(mainCat); } feed.Channel.AddExtension(channelExtension); DataSet dsBlogPosts = GetData(); DataTable posts = dsBlogPosts.Tables["Posts"]; foreach (DataRow dr in posts.Rows) { bool inFeed = Convert.ToBoolean(dr["IncludeInFeed"]); if (!inFeed) { continue; } RssItem item = new RssItem(); int itemId = Convert.ToInt32(dr["ItemID"]); string blogItemUrl = FormatBlogUrl(dr["ItemUrl"].ToString(), itemId); item.Link = new Uri(Request.Url, blogItemUrl); item.Guid = new RssGuid(blogItemUrl); item.Title = dr["Heading"].ToString(); item.PublicationDate = Convert.ToDateTime(dr["StartDate"]); bool showAuthor = Convert.ToBoolean(dr["ShowAuthorName"]); if (showAuthor) { // techically this is supposed to be an email address // but wouldn't that lead to a lot of spam? string authorEmail = dr["Email"].ToString(); string authorName = dr["Name"].ToString(); if (BlogConfiguration.IncludeAuthorEmailInFeed) { item.Author = authorEmail + " (" + authorName + ")"; } else { item.Author = authorName; } } else if (config.ManagingEditorEmail.Length > 0) { item.Author = config.ManagingEditorEmail; } item.Comments = new Uri(blogItemUrl); string signature = string.Empty; if (config.AddSignature) { signature = "<br /><a href='" + blogItemUrl + "'>" + dr["Name"].ToString() + "</a>"; } if ((config.AddCommentsLinkToFeed) && (config.AllowComments)) { signature += " " + "<a href='" + blogItemUrl + "'>...</a>"; } if (config.AddTweetThisToFeed) { signature += GenerateTweetThisLink(item.Title, blogItemUrl); } if (config.AddFacebookLikeToFeed) { signature += GenerateFacebookLikeButton(blogItemUrl); } string blogPost = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(navigationSiteRoot, imageSiteRoot, dr["Description"].ToString().RemoveCDataTags()); string staticMapLink = BuildStaticMapMarkup(dr); if (staticMapLink.Length > 0) { // add a google static map blogPost += staticMapLink; } if ((!config.UseExcerptInFeed) || (blogPost.Length <= config.ExcerptLength)) { item.Description = blogPost + signature; } else { string excerpt = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(navigationSiteRoot, imageSiteRoot, dr["Abstract"].ToString().RemoveCDataTags()); if ((excerpt.Length > 0) && (excerpt != "<p> </p>")) { excerpt = excerpt + config.ExcerptSuffix + " <a href='" + blogItemUrl + "'>" + config.MoreLinkText + "</a><div class='excerptspacer'> </div>"; } else { excerpt = UIHelper.CreateExcerpt(dr["Description"].ToString(), config.ExcerptLength, config.ExcerptSuffix) + " <a href='" + blogItemUrl + "'>" + config.MoreLinkText + "</a><div class='excerptspacer'> </div>";; } item.Description = excerpt; } // how to add media enclosures for podcasting //http://www.podcast411.com/howto_1.html //http://argotic.codeplex.com/wikipage?title=Generating%20an%20extended%20RSS%20feed //http://techwhimsy.com/stream-mp3s-with-google-mp3-player //Uri url = new Uri("http://media.libsyn.com/media/podcast411/411_060325.mp3"); //string type = "audio/mpeg"; //long length = 11779397; string blogGuid = dr["BlogGuid"].ToString(); string whereClause = string.Format("ItemGuid = '{0}'", blogGuid); if (!config.UseExcerptInFeed) { DataView dv = new DataView(dsBlogPosts.Tables["Attachments"], whereClause, "", DataViewRowState.CurrentRows); foreach (DataRowView rowView in dv) { DataRow row = rowView.Row; Uri mediaUrl = new Uri(WebUtils.ResolveServerUrl(attachmentBaseUrl + row["ServerFileName"].ToString())); long contentLength = Convert.ToInt64(row["ContentLength"]); string contentType = row["ContentType"].ToString(); RssEnclosure enclosure = new RssEnclosure(contentLength, contentType, mediaUrl); item.Enclosures.Add(enclosure); //http://argotic.codeplex.com/wikipage?title=Generating%20an%20extended%20RSS%20feed ITunesSyndicationExtension itemExtension = new ITunesSyndicationExtension(); itemExtension.Context.Author = dr["Name"].ToString(); itemExtension.Context.Subtitle = dr["SubTitle"].ToString(); //itemExtension.Context.Summary = "The iTunes syndication extension properties that are used vary based on whether extending the channel or an item"; //itemExtension.Context.Duration = new TimeSpan(1, 2, 13); //itemExtension.Context.Keywords.Add("Podcast"); //itemExtension.Context.Keywords.Add("iTunes"); whereClause = string.Format("ItemID = '{0}'", itemId); DataView dvCat = new DataView(dsBlogPosts.Tables["Categories"], whereClause, "", DataViewRowState.CurrentRows); foreach (DataRowView rView in dvCat) { DataRow r = rView.Row; item.Categories.Add(new RssCategory(r["Category"].ToString())); itemExtension.Context.Keywords.Add(r["Category"].ToString()); } item.AddExtension(itemExtension); } } channel.AddItem(item); } if ((config.FeedburnerFeedUrl.Length > 0) || (Request.Url.AbsolutePath.Contains("localhost"))) { Response.Cache.SetExpires(DateTime.Now.AddMinutes(-30)); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.VaryByParams["r"] = true; } else { Response.Cache.SetExpires(DateTime.Now.AddMinutes(30)); Response.Cache.SetCacheability(HttpCacheability.Public); } Response.ContentType = "application/xml"; Encoding encoding = new UTF8Encoding(); Response.ContentEncoding = encoding; using (XmlTextWriter xmlTextWriter = new XmlTextWriter(Response.OutputStream, encoding)) { xmlTextWriter.Formatting = Formatting.Indented; ////////////////// // style for RSS Feed viewed in browsers if (ConfigurationManager.AppSettings["RSSCSS"] != null) { string rssCss = ConfigurationManager.AppSettings["RSSCSS"].ToString(); xmlTextWriter.WriteWhitespace(" "); xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/css\" href=\"" + cssBaseUrl + rssCss + "\" ?>"); } if (ConfigurationManager.AppSettings["RSSXsl"] != null) { string rssXsl = ConfigurationManager.AppSettings["RSSXsl"].ToString(); xmlTextWriter.WriteWhitespace(" "); xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/xsl\" href=\"" + cssBaseUrl + rssXsl + "\" ?>"); } /////////////////////////// feed.Save(xmlTextWriter); } }