Beispiel #1
0
        /// <summary>
        /// Saves the current <see cref="ITunesOwner"/> 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
            //------------------------------------------------------------
            ITunesSyndicationExtension extension = new ITunesSyndicationExtension();

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

            if (!String.IsNullOrEmpty(this.EmailAddress))
            {
                writer.WriteElementString("email", extension.XmlNamespace, this.EmailAddress);
            }

            if (!String.IsNullOrEmpty(this.Name))
            {
                writer.WriteElementString("name", extension.XmlNamespace, this.Name);
            }

            writer.WriteEndElement();
        }
Beispiel #2
0
        /// <summary>
        /// Loads this <see cref="ITunesOwner"/> 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="ITunesOwner"/> 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="ITunesOwner"/>.
        /// </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");
            ITunesSyndicationExtension extension = new ITunesSyndicationExtension();
            XmlNamespaceManager        manager   = extension.CreateNamespaceManager(source);

            if (source.HasChildren)
            {
                XPathNavigator emailNavigator = source.SelectSingleNode("itunes:email", manager);
                XPathNavigator nameNavigator  = source.SelectSingleNode("itunes:name", manager);

                if (emailNavigator != null && !String.IsNullOrEmpty(emailNavigator.Value))
                {
                    this.EmailAddress = emailNavigator.Value;
                    wasLoaded         = true;
                }

                if (nameNavigator != null && !String.IsNullOrEmpty(nameNavigator.Value))
                {
                    this.Name = nameNavigator.Value;
                    wasLoaded = true;
                }
            }

            return(wasLoaded);
        }
Beispiel #3
0
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns>
        /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception>
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            ITunesSyndicationExtension value = obj as ITunesSyndicationExtension;

            if (value != null)
            {
                int result = String.Compare(this.Context.Author, value.Context.Author, StringComparison.OrdinalIgnoreCase);
                result = result | ITunesSyndicationExtension.CompareSequence(this.Context.Categories, value.Context.Categories);
                result = result | this.Context.Duration.CompareTo(value.Context.Duration);
                result = result | this.Context.ExplicitMaterial.CompareTo(value.Context.ExplicitMaterial);
                result = result | Uri.Compare(this.Context.Image, value.Context.Image, UriComponents.AbsoluteUri, UriFormat.Unescaped, StringComparison.OrdinalIgnoreCase);
                result = result | this.Context.IsBlocked.CompareTo(value.Context.IsBlocked);
                result = result | ComparisonUtility.CompareSequence(this.Context.Keywords, value.Context.Keywords, StringComparison.OrdinalIgnoreCase);
                result = result | Uri.Compare(this.Context.NewFeedUrl, value.Context.NewFeedUrl, UriComponents.AbsoluteUri, UriFormat.Unescaped, StringComparison.OrdinalIgnoreCase);
                result = result | this.Context.Owner.CompareTo(value.Context.Owner);
                result = result | String.Compare(this.Context.Subtitle, value.Context.Subtitle, StringComparison.OrdinalIgnoreCase);
                result = result | String.Compare(this.Context.Summary, value.Context.Summary, StringComparison.OrdinalIgnoreCase);

                return(result);
            }
            else
            {
                throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj");
            }
        }
        //============================================================
        //	ICOMPARABLE IMPLEMENTATION
        //============================================================
        #region CompareTo(object obj)
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns>
        /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception>
        public int CompareTo(object obj)
        {
            //------------------------------------------------------------
            //	If target is a null reference, instance is greater
            //------------------------------------------------------------
            if (obj == null)
            {
                return(1);
            }

            //------------------------------------------------------------
            //	Determine comparison result using property state of objects
            //------------------------------------------------------------
            ITunesCategory value = obj as ITunesCategory;

            if (value != null)
            {
                int result = String.Compare(this.Text, value.Text, StringComparison.OrdinalIgnoreCase);
                result = result | ITunesSyndicationExtension.CompareSequence(this.Categories, value.Categories);

                return(result);
            }
            else
            {
                throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj");
            }
        }
        /// <summary>
        /// Saves the current <see cref="ITunesCategory"/> 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
            //------------------------------------------------------------
            ITunesSyndicationExtension extension = new ITunesSyndicationExtension();

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

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

            if (this.Categories.Count > 0)
            {
                foreach (ITunesCategory category in this.Categories)
                {
                    category.WriteTo(writer);
                }
            }

            writer.WriteEndElement();
        }
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="ITunesCategory"/> 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="ITunesCategory"/> 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="ITunesCategory"/>.
        /// </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");

            //------------------------------------------------------------
            //	Create namespace manager to resolve prefixed elements
            //------------------------------------------------------------
            ITunesSyndicationExtension extension = new ITunesSyndicationExtension();
            XmlNamespaceManager        manager   = extension.CreateNamespaceManager(source);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasAttributes)
            {
                string textAttribute = source.GetAttribute("text", String.Empty);
                if (!String.IsNullOrEmpty(textAttribute))
                {
                    this.Text = textAttribute;
                    wasLoaded = true;
                }
            }

            if (source.HasChildren)
            {
                XPathNodeIterator categoryIterator = source.Select("itunes:category", manager);

                if (categoryIterator != null && categoryIterator.Count > 0)
                {
                    while (categoryIterator.MoveNext())
                    {
                        ITunesCategory category = new ITunesCategory();
                        if (category.Load(categoryIterator.Current))
                        {
                            this.Categories.Add(category);
                            wasLoaded = true;
                        }
                    }
                }
            }

            return(wasLoaded);
        }
Beispiel #7
0
        /// <summary>
        /// Saves the current <see cref="ITunesOwner"/> 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");
            ITunesSyndicationExtension extension = new ITunesSyndicationExtension();

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

            if (!String.IsNullOrEmpty(this.EmailAddress))
            {
                writer.WriteElementString("email", extension.XmlNamespace, this.EmailAddress);
            }

            if (!String.IsNullOrEmpty(this.Name))
            {
                writer.WriteElementString("name", extension.XmlNamespace, this.Name);
            }

            writer.WriteEndElement();
        }
        /// <summary>
        /// Saves the current <see cref="ITunesCategory"/> 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");
            ITunesSyndicationExtension extension = new ITunesSyndicationExtension();

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

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

            if (this.Categories.Count > 0)
            {
                foreach (ITunesCategory category in this.Categories)
                {
                    category.WriteTo(writer);
                }
            }

            writer.WriteEndElement();
        }
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>A 32-bit signed integer that indicates the relative order of the objects being compared.</returns>
        /// <exception cref="ArgumentException">The <paramref name="obj"/> is not the expected <see cref="Type"/>.</exception>
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            ITunesCategory value = obj as ITunesCategory;

            if (value != null)
            {
                int result = String.Compare(this.Text, value.Text, StringComparison.OrdinalIgnoreCase);
                result = result | ITunesSyndicationExtension.CompareSequence(this.Categories, value.Categories);

                return(result);
            }
            else
            {
                throw new ArgumentException(String.Format(null, "obj is not of type {0}, type was found to be '{1}'.", this.GetType().FullName, obj.GetType().FullName), "obj");
            }
        }
Beispiel #10
0
        //============================================================
        //	PUBLIC METHODS
        //============================================================
        #region Load(XPathNavigator source)
        /// <summary>
        /// Loads this <see cref="ITunesOwner"/> 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="ITunesOwner"/> 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="ITunesOwner"/>.
        /// </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");

            //------------------------------------------------------------
            //	Create namespace manager to resolve prefixed elements
            //------------------------------------------------------------
            ITunesSyndicationExtension extension = new ITunesSyndicationExtension();
            XmlNamespaceManager        manager   = extension.CreateNamespaceManager(source);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasChildren)
            {
                XPathNavigator emailNavigator = source.SelectSingleNode("itunes:email", manager);
                XPathNavigator nameNavigator  = source.SelectSingleNode("itunes:name", manager);

                if (emailNavigator != null && !String.IsNullOrEmpty(emailNavigator.Value))
                {
                    this.EmailAddress = emailNavigator.Value;
                    wasLoaded         = true;
                }

                if (nameNavigator != null && !String.IsNullOrEmpty(nameNavigator.Value))
                {
                    this.Name = nameNavigator.Value;
                    wasLoaded = true;
                }
            }

            return(wasLoaded);
        }
        /// <summary>
        /// Loads this <see cref="ITunesCategory"/> 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="ITunesCategory"/> 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="ITunesCategory"/>.
        /// </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");
            ITunesSyndicationExtension extension = new ITunesSyndicationExtension();
            XmlNamespaceManager        manager   = extension.CreateNamespaceManager(source);

            if (source.HasAttributes)
            {
                string textAttribute = source.GetAttribute("text", String.Empty);
                if (!String.IsNullOrEmpty(textAttribute))
                {
                    this.Text = textAttribute;
                    wasLoaded = true;
                }
            }

            if (source.HasChildren)
            {
                XPathNodeIterator categoryIterator = source.Select("itunes:category", manager);

                if (categoryIterator != null && categoryIterator.Count > 0)
                {
                    while (categoryIterator.MoveNext())
                    {
                        ITunesCategory category = new ITunesCategory();
                        if (category.Load(categoryIterator.Current))
                        {
                            this.Categories.Add(category);
                            wasLoaded = true;
                        }
                    }
                }
            }

            return(wasLoaded);
        }
Beispiel #12
0
        /// <summary>
        /// Loads this <see cref="ITunesOwner"/> 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="ITunesOwner"/> 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="ITunesOwner"/>.
        /// </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");

            //------------------------------------------------------------
            //	Create namespace manager to resolve prefixed elements
            //------------------------------------------------------------
            ITunesSyndicationExtension extension    = new ITunesSyndicationExtension();
            XmlNamespaceManager manager             = extension.CreateNamespaceManager(source);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            if (source.HasChildren)
            {
                XPathNavigator emailNavigator   = source.SelectSingleNode("itunes:email", manager);
                XPathNavigator nameNavigator    = source.SelectSingleNode("itunes:name", manager);

                if (emailNavigator != null && !String.IsNullOrEmpty(emailNavigator.Value))
                {
                    this.EmailAddress   = emailNavigator.Value;
                    wasLoaded           = true;
                }

                if (nameNavigator != null && !String.IsNullOrEmpty(nameNavigator.Value))
                {
                    this.Name   = nameNavigator.Value;
                    wasLoaded   = true;
                }
            }

            return wasLoaded;
        }
Beispiel #13
0
        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 += "&nbsp;&nbsp;" + "<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>&#160;</p>"))
                    {
                        excerpt = excerpt
                            + config.ExcerptSuffix
                            + " <a href='"
                            + blogItemUrl + "'>" + config.MoreLinkText + "</a><div class='excerptspacer'>&nbsp;</div>";
                    }
                    else
                    {
                        excerpt = UIHelper.CreateExcerpt(dr["Description"].ToString(), config.ExcerptLength, config.ExcerptSuffix)
                            + " <a href='"
                            + blogItemUrl + "'>" + config.MoreLinkText + "</a><div class='excerptspacer'>&nbsp;</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);

            }
        }
Beispiel #14
0
        /// <summary>
        /// Saves the current <see cref="ITunesOwner"/> 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
            //------------------------------------------------------------
            ITunesSyndicationExtension extension    = new ITunesSyndicationExtension();

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

            if(!String.IsNullOrEmpty(this.EmailAddress))
            {
                writer.WriteElementString("email", extension.XmlNamespace, this.EmailAddress);
            }

            if (!String.IsNullOrEmpty(this.Name))
            {
                writer.WriteElementString("name", extension.XmlNamespace, this.Name);
            }

            writer.WriteEndElement();
        }
        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;
        }
        /// <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.NewFeedUrl != null)
            {
                writer.WriteElementString("new-feed-url", xmlNamespace, this.NewFeedUrl.ToString());
            }

            if (!String.IsNullOrEmpty(this.Subtitle))
            {
                writer.WriteElementString("subtitle", xmlNamespace, this.Subtitle);
            }

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

            if (!String.IsNullOrEmpty(this.Summary))
            {
                writer.WriteElementString("summary", xmlNamespace, this.Summary);
            }

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

            if (this.Image != null)
            {
                writer.WriteStartElement("image", xmlNamespace);
                writer.WriteAttributeString("href", this.Image.ToString());
                writer.WriteEndElement();
            }

            if (this.Duration != TimeSpan.MinValue)
            {
                string hours    = this.Duration.Hours < 10 ? String.Concat("0", this.Duration.Hours.ToString(NumberFormatInfo.InvariantInfo)) : this.Duration.Hours.ToString(NumberFormatInfo.InvariantInfo);
                string minutes  = this.Duration.Minutes < 10 ? String.Concat("0", this.Duration.Minutes.ToString(NumberFormatInfo.InvariantInfo)) : this.Duration.Minutes.ToString(NumberFormatInfo.InvariantInfo);
                string seconds  = this.Duration.Seconds < 10 ? String.Concat("0", this.Duration.Seconds.ToString(NumberFormatInfo.InvariantInfo)) : this.Duration.Seconds.ToString(NumberFormatInfo.InvariantInfo);
                string duration = String.Format(null, "{0}:{1}:{2}", hours, minutes, seconds);

                writer.WriteElementString("duration", xmlNamespace, duration);
            }

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

                writer.WriteElementString("keywords", xmlNamespace, String.Join(",", keywords));
            }

            if (this.ExplicitMaterial != ITunesExplicitMaterial.None)
            {
                writer.WriteElementString("explicit", xmlNamespace, ITunesSyndicationExtension.ExplicitMaterialAsString(this.ExplicitMaterial));
            }

            if (this.IsBlocked)
            {
                writer.WriteElementString("block", xmlNamespace, "yes");
            }

            if (this.Categories.Count > 0)
            {
                foreach (ITunesCategory category in this.Categories)
                {
                    category.WriteTo(writer);
                }
            }
        }
 public void ITunesSyndicationExtensionConstructorTest()
 {
     ITunesSyndicationExtension target = new ITunesSyndicationExtension();
     Assert.IsNotNull(target);
     Assert.IsInstanceOfType(target, typeof(ITunesSyndicationExtension));
 }
 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;
 }
        /// <summary>
        /// Initializes the optional syndication extension information using the supplied <see cref="XPathNavigator"/>.
        /// </summary>
        /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="ITunesSyndicationExtensionContext"/>.</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="ITunesSyndicationExtensionContext"/> 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>
        private bool LoadOptionals(XPathNavigator source, XmlNamespaceManager manager)
        {
            bool wasLoaded = false;

            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(manager, "manager");
            if (source.HasChildren)
            {
                XPathNavigator blockNavigator    = source.SelectSingleNode("itunes:block", manager);
                XPathNavigator imageNavigator    = source.SelectSingleNode("itunes:image", manager);
                XPathNavigator durationNavigator = source.SelectSingleNode("itunes:duration", manager);
                XPathNavigator explicitNavigator = source.SelectSingleNode("itunes:explicit", manager);

                if (blockNavigator != null && !String.IsNullOrEmpty(blockNavigator.Value))
                {
                    if (String.Compare(blockNavigator.Value, "yes", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        this.IsBlocked = true;
                        wasLoaded      = true;
                    }
                    else if (String.Compare(blockNavigator.Value, "no", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        this.IsBlocked = false;
                        wasLoaded      = true;
                    }
                }

                if (imageNavigator != null && imageNavigator.HasAttributes)
                {
                    string hrefAttribute = imageNavigator.GetAttribute("href", String.Empty);
                    if (!String.IsNullOrEmpty(hrefAttribute))
                    {
                        Uri image;

                        if (Uri.TryCreate(hrefAttribute, UriKind.RelativeOrAbsolute, out image))
                        {
                            this.Image = image;
                            wasLoaded  = true;
                        }
                    }
                }

                if (durationNavigator != null && !String.IsNullOrEmpty(durationNavigator.Value))
                {
                    TimeSpan duration = ITunesSyndicationExtensionContext.ParseDuration(durationNavigator.Value);
                    if (duration != TimeSpan.MinValue)
                    {
                        this.Duration = duration;
                        wasLoaded     = true;
                    }
                }

                if (explicitNavigator != null && !String.IsNullOrEmpty(explicitNavigator.Value))
                {
                    ITunesExplicitMaterial explicitMaterial = ITunesSyndicationExtension.ExplicitMaterialByName(explicitNavigator.Value.Trim());
                    if (explicitMaterial != ITunesExplicitMaterial.None)
                    {
                        this.ExplicitMaterial = explicitMaterial;
                        wasLoaded             = true;
                    }
                }
            }

            return(wasLoaded);
        }
        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
            }
        }