/// <summary> /// Loads this <see cref="YahooMediaGroup"/> 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="YahooMediaGroup"/> 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="YahooMediaGroup"/>. /// </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"); YahooMediaSyndicationExtension extension = new YahooMediaSyndicationExtension(); XmlNamespaceManager manager = extension.CreateNamespaceManager(source); if (source.HasChildren) { XPathNodeIterator contentIterator = source.Select("media:content", manager); if (contentIterator != null && contentIterator.Count > 0) { while (contentIterator.MoveNext()) { YahooMediaContent content = new YahooMediaContent(); if (content.Load(contentIterator.Current)) { this.Contents.Add(content); wasLoaded = true; } } } } if (YahooMediaUtility.FillCommonObjectEntities(this, source)) { wasLoaded = true; } return(wasLoaded); }
private RssItem GetItem(string filePath) { var file = new FileInfo(filePath); if (!file.Exists) return null; string mimeType = GetMimeType(file); string fileName = Path.GetFileNameWithoutExtension(filePath); var uri = new Uri(GetUrl(Port, file.Name)); var item = new RssItem(); item.Title = fileName; item.Link = uri; item.Enclosures.Add(new RssEnclosure(file.Length, mimeType, item.Link)); var extension = new YahooMediaSyndicationExtension(); var mediaContent = new YahooMediaContent(uri); mediaContent.FileSize = file.Length; mediaContent.ContentType = mimeType; extension.Context.AddContent(mediaContent); item.AddExtension(extension); return item; }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source, XmlNamespaceManager manager) /// <summary> /// Initializes the syndication extension context using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="YahooMediaSyndicationExtensionContext"/>.</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="YahooMediaSyndicationExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source, XmlNamespaceManager manager) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); //------------------------------------------------------------ // Attempt to extract syndication extension information //------------------------------------------------------------ if (source.HasChildren) { XPathNodeIterator contentIterator = source.Select("media:content", manager); XPathNodeIterator groupIterator = source.Select("media:group", manager); if (contentIterator != null && contentIterator.Count > 0) { while (contentIterator.MoveNext()) { YahooMediaContent content = new YahooMediaContent(); if (content.Load(contentIterator.Current)) { this.AddContent(content); wasLoaded = true; } } } if (groupIterator != null && groupIterator.Count > 0) { while (groupIterator.MoveNext()) { YahooMediaGroup group = new YahooMediaGroup(); if (group.Load(groupIterator.Current)) { this.AddGroup(group); wasLoaded = true; } } } } if (YahooMediaUtility.FillCommonObjectEntities(this, source)) { wasLoaded = true; } return(wasLoaded); }
/// <summary> /// Adds the supplied <see cref="YahooMediaContent"/> to the current instance's <see cref="Contents"/> collection. /// </summary> /// <param name="content">The <see cref="YahooMediaContent"/> to be added.</param> /// <returns><b>true</b> if the <see cref="YahooMediaContent"/> was added to the <see cref="Contents"/> collection, otherwise <b>false</b>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="content"/> is a null reference (Nothing in Visual Basic).</exception> public bool AddContent(YahooMediaContent content) { bool wasAdded = false; Guard.ArgumentNotNull(content, "content"); ((Collection <YahooMediaContent>) this.Contents).Add(content); wasAdded = true; return(wasAdded); }
/// <summary> /// Removes the supplied <see cref="YahooMediaContent"/> from the current instance's <see cref="Contents"/> collection. /// </summary> /// <param name="content">The <see cref="YahooMediaContent"/> to be removed.</param> /// <returns><b>true</b> if the <see cref="YahooMediaContent"/> was removed from the <see cref="Contents"/> collection, otherwise <b>false</b>.</returns> /// <remarks> /// If the <see cref="Contents"/> collection of the current instance does not contain the specified <see cref="YahooMediaContent"/>, will return <b>false</b>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="content"/> is a null reference (Nothing in Visual Basic).</exception> public bool RemoveContent(YahooMediaContent content) { bool wasRemoved = false; Guard.ArgumentNotNull(content, "content"); if (((Collection <YahooMediaContent>) this.Contents).Contains(content)) { ((Collection <YahooMediaContent>) this.Contents).Remove(content); wasRemoved = true; } return(wasRemoved); }
//============================================================ // PUBLIC METHODS //============================================================ #region Load(XPathNavigator source) /// <summary> /// Loads this <see cref="YahooMediaGroup"/> 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="YahooMediaGroup"/> 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="YahooMediaGroup"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Initialize XML namespace resolver //------------------------------------------------------------ YahooMediaSyndicationExtension extension = new YahooMediaSyndicationExtension(); XmlNamespaceManager manager = extension.CreateNamespaceManager(source); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if (source.HasChildren) { XPathNodeIterator contentIterator = source.Select("media:content", manager); if (contentIterator != null && contentIterator.Count > 0) { while (contentIterator.MoveNext()) { YahooMediaContent content = new YahooMediaContent(); if (content.Load(contentIterator.Current)) { this.Contents.Add(content); wasLoaded = true; } } } } if (YahooMediaUtility.FillCommonObjectEntities(this, source)) { wasLoaded = true; } return(wasLoaded); }
/// <summary> /// Initializes the syndication extension context using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="YahooMediaSyndicationExtensionContext"/>.</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="YahooMediaSyndicationExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source, XmlNamespaceManager manager) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); if (source.HasChildren) { XPathNodeIterator contentIterator = source.Select("media:content", manager); XPathNodeIterator groupIterator = source.Select("media:group", manager); if (contentIterator != null && contentIterator.Count > 0) { while (contentIterator.MoveNext()) { YahooMediaContent content = new YahooMediaContent(); if (content.Load(contentIterator.Current)) { this.AddContent(content); wasLoaded = true; } } } if (groupIterator != null && groupIterator.Count > 0) { while (groupIterator.MoveNext()) { YahooMediaGroup group = new YahooMediaGroup(); if (group.Load(groupIterator.Current)) { this.AddGroup(group); wasLoaded = true; } } } } if (YahooMediaUtility.FillCommonObjectEntities(this, source)) { wasLoaded = true; } return(wasLoaded); }
//============================================================ // UTILITY METHODS //============================================================ #region AddContent(YahooMediaContent content) /// <summary> /// Adds the supplied <see cref="YahooMediaContent"/> to the current instance's <see cref="Contents"/> collection. /// </summary> /// <param name="content">The <see cref="YahooMediaContent"/> to be added.</param> /// <returns><b>true</b> if the <see cref="YahooMediaContent"/> was added to the <see cref="Contents"/> collection, otherwise <b>false</b>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="content"/> is a null reference (Nothing in Visual Basic).</exception> public bool AddContent(YahooMediaContent content) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasAdded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(content, "content"); //------------------------------------------------------------ // Add media object to collection //------------------------------------------------------------ ((Collection <YahooMediaContent>) this.Contents).Add(content); wasAdded = true; return(wasAdded); }
/// <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); } YahooMediaContent value = obj as YahooMediaContent; if (value != null) { int result = this.Bitrate.CompareTo(value.Bitrate); result = result | this.Channels.CompareTo(value.Channels); result = result | String.Compare(this.ContentType, value.ContentType, StringComparison.OrdinalIgnoreCase); result = result | this.Duration.CompareTo(value.Duration); result = result | this.Expression.CompareTo(value.Expression); result = result | this.FileSize.CompareTo(value.FileSize); result = result | this.FrameRate.CompareTo(value.FrameRate); result = result | this.Height.CompareTo(value.Height); result = result | this.IsDefault.CompareTo(value.IsDefault); string sourceLanguageName = this.Language != null ? this.Language.Name : String.Empty; string targetLanguageName = value.Language != null ? value.Language.Name : String.Empty; result = result | String.Compare(sourceLanguageName, targetLanguageName, StringComparison.OrdinalIgnoreCase); result = result | this.Medium.CompareTo(value.Medium); result = result | this.SamplingRate.CompareTo(value.SamplingRate); result = result | Uri.Compare(this.Url, value.Url, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase); result = result | this.Width.CompareTo(value.Width); result = result | YahooMediaUtility.CompareCommonObjectEntities(this, value); 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> /// Removes the supplied <see cref="YahooMediaContent"/> from the current instance's <see cref="Contents"/> collection. /// </summary> /// <param name="content">The <see cref="YahooMediaContent"/> to be removed.</param> /// <returns><b>true</b> if the <see cref="YahooMediaContent"/> was removed from the <see cref="Contents"/> collection, otherwise <b>false</b>.</returns> /// <remarks> /// If the <see cref="Contents"/> collection of the current instance does not contain the specified <see cref="YahooMediaContent"/>, will return <b>false</b>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="content"/> is a null reference (Nothing in Visual Basic).</exception> public bool RemoveContent(YahooMediaContent content) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasRemoved = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(content, "content"); //------------------------------------------------------------ // Remove media object from collection //------------------------------------------------------------ if (((Collection <YahooMediaContent>) this.Contents).Contains(content)) { ((Collection <YahooMediaContent>) this.Contents).Remove(content); wasRemoved = true; } return(wasRemoved); }
/// <summary> /// Removes the supplied <see cref="YahooMediaContent"/> from the current instance's <see cref="Contents"/> collection. /// </summary> /// <param name="content">The <see cref="YahooMediaContent"/> to be removed.</param> /// <returns><b>true</b> if the <see cref="YahooMediaContent"/> was removed from the <see cref="Contents"/> collection, otherwise <b>false</b>.</returns> /// <remarks> /// If the <see cref="Contents"/> collection of the current instance does not contain the specified <see cref="YahooMediaContent"/>, will return <b>false</b>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="content"/> is a null reference (Nothing in Visual Basic).</exception> public bool RemoveContent(YahooMediaContent content) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasRemoved = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(content, "content"); //------------------------------------------------------------ // Remove media object from collection //------------------------------------------------------------ if (((Collection<YahooMediaContent>)this.Contents).Contains(content)) { ((Collection<YahooMediaContent>)this.Contents).Remove(content); wasRemoved = true; } return wasRemoved; }
/// <summary> /// Initializes the syndication extension context using the supplied <see cref="XPathNavigator"/>. /// </summary> /// <param name="source">The <b>XPathNavigator</b> used to load this <see cref="YahooMediaSyndicationExtensionContext"/>.</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="YahooMediaSyndicationExtensionContext"/> was able to be initialized using the supplied <paramref name="source"/>; otherwise <b>false</b>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="manager"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source, XmlNamespaceManager manager) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); Guard.ArgumentNotNull(manager, "manager"); //------------------------------------------------------------ // Attempt to extract syndication extension information //------------------------------------------------------------ if(source.HasChildren) { XPathNodeIterator contentIterator = source.Select("media:content", manager); XPathNodeIterator groupIterator = source.Select("media:group", manager); if (contentIterator != null && contentIterator.Count > 0) { while (contentIterator.MoveNext()) { YahooMediaContent content = new YahooMediaContent(); if (content.Load(contentIterator.Current)) { this.AddContent(content); wasLoaded = true; } } } if (groupIterator != null && groupIterator.Count > 0) { while (groupIterator.MoveNext()) { YahooMediaGroup group = new YahooMediaGroup(); if (group.Load(groupIterator.Current)) { this.AddGroup(group); wasLoaded = true; } } } } if (YahooMediaUtility.FillCommonObjectEntities(this, source)) { wasLoaded = true; } return wasLoaded; }
/// <summary> /// Adds the supplied <see cref="YahooMediaContent"/> to the current instance's <see cref="Contents"/> collection. /// </summary> /// <param name="content">The <see cref="YahooMediaContent"/> to be added.</param> /// <returns><b>true</b> if the <see cref="YahooMediaContent"/> was added to the <see cref="Contents"/> collection, otherwise <b>false</b>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="content"/> is a null reference (Nothing in Visual Basic).</exception> public bool AddContent(YahooMediaContent content) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasAdded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(content, "content"); //------------------------------------------------------------ // Add media object to collection //------------------------------------------------------------ ((Collection<YahooMediaContent>)this.Contents).Add(content); wasAdded = true; return wasAdded; }
/// <summary> /// Loads this <see cref="YahooMediaGroup"/> 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="YahooMediaGroup"/> 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="YahooMediaGroup"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> public bool Load(XPathNavigator source) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ bool wasLoaded = false; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNull(source, "source"); //------------------------------------------------------------ // Initialize XML namespace resolver //------------------------------------------------------------ YahooMediaSyndicationExtension extension = new YahooMediaSyndicationExtension(); XmlNamespaceManager manager = extension.CreateNamespaceManager(source); //------------------------------------------------------------ // Attempt to extract syndication information //------------------------------------------------------------ if(source.HasChildren) { XPathNodeIterator contentIterator = source.Select("media:content", manager); if (contentIterator != null && contentIterator.Count > 0) { while (contentIterator.MoveNext()) { YahooMediaContent content = new YahooMediaContent(); if (content.Load(contentIterator.Current)) { this.Contents.Add(content); wasLoaded = true; } } } } if (YahooMediaUtility.FillCommonObjectEntities(this, source)) { wasLoaded = true; } return wasLoaded; }