//============================================================ // STATIC METHODS //============================================================ #region ExpressionAsString(YahooMediaExpression expression) /// <summary> /// Returns the content expression identifier for the supplied <see cref="YahooMediaExpression"/>. /// </summary> /// <param name="expression">The <see cref="YahooMediaExpression"/> to get the content expression identifier for.</param> /// <returns>The content expression identifier for the supplied <paramref name="expression"/>, otherwise returns an empty string.</returns> public static string ExpressionAsString(YahooMediaExpression expression) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ string name = String.Empty; //------------------------------------------------------------ // Return alternate value based on supplied protocol //------------------------------------------------------------ foreach (System.Reflection.FieldInfo fieldInfo in typeof(YahooMediaExpression).GetFields()) { if (fieldInfo.FieldType == typeof(YahooMediaExpression)) { YahooMediaExpression mediaExpression = (YahooMediaExpression)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name); if (mediaExpression == expression) { object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false); if (customAttributes != null && customAttributes.Length > 0) { EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute; name = enumerationMetadata.AlternateValue; break; } } } } return(name); }
/// <summary> /// Returns the <see cref="YahooMediaExpression"/> enumeration value that corresponds to the specified content expression name. /// </summary> /// <param name="name">The name of the content expression.</param> /// <returns>A <see cref="YahooMediaExpression"/> enumeration value that corresponds to the specified string, otherwise returns <b>YahooMediaExpression.None</b>.</returns> /// <remarks>This method disregards case of specified content expression name.</remarks> /// <exception cref="ArgumentNullException">The <paramref name="name"/> is a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException">The <paramref name="name"/> is an empty string.</exception> public static YahooMediaExpression ExpressionByName(string name) { YahooMediaExpression mediaExpression = YahooMediaExpression.None; Guard.ArgumentNotNullOrEmptyString(name, "name"); foreach (System.Reflection.FieldInfo fieldInfo in typeof(YahooMediaExpression).GetFields()) { if (fieldInfo.FieldType == typeof(YahooMediaExpression)) { YahooMediaExpression expression = (YahooMediaExpression)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name); object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false); if (customAttributes != null && customAttributes.Length > 0) { EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute; if (String.Compare(name, enumerationMetadata.AlternateValue, StringComparison.OrdinalIgnoreCase) == 0) { mediaExpression = expression; break; } } } } return(mediaExpression); }
/// <summary> /// Returns the content expression identifier for the supplied <see cref="YahooMediaExpression"/>. /// </summary> /// <param name="expression">The <see cref="YahooMediaExpression"/> to get the content expression identifier for.</param> /// <returns>The content expression identifier for the supplied <paramref name="expression"/>, otherwise returns an empty string.</returns> public static string ExpressionAsString(YahooMediaExpression expression) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ string name = String.Empty; //------------------------------------------------------------ // Return alternate value based on supplied protocol //------------------------------------------------------------ foreach (System.Reflection.FieldInfo fieldInfo in typeof(YahooMediaExpression).GetFields()) { if (fieldInfo.FieldType == typeof(YahooMediaExpression)) { YahooMediaExpression mediaExpression = (YahooMediaExpression)Enum.Parse(fieldInfo.FieldType, fieldInfo.Name); if (mediaExpression == expression) { object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EnumerationMetadataAttribute), false); if (customAttributes != null && customAttributes.Length > 0) { EnumerationMetadataAttribute enumerationMetadata = customAttributes[0] as EnumerationMetadataAttribute; name = enumerationMetadata.AlternateValue; break; } } } } return name; }
/// <summary> /// Loads the primary properties of this <see cref="YahooMediaContent"/> 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="YahooMediaContent"/> 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="YahooMediaContent"/>. /// </remarks> /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception> private bool LoadPrimary(XPathNavigator source) { bool wasLoaded = false; Guard.ArgumentNotNull(source, "source"); if (source.HasAttributes) { string urlAttribute = source.GetAttribute("url", String.Empty); string fileSizeAttribute = source.GetAttribute("fileSize", String.Empty); string typeAttribute = source.GetAttribute("type", String.Empty); string mediumAttribute = source.GetAttribute("medium", String.Empty); string isDefaultAttribute = source.GetAttribute("isDefault", String.Empty); string expressionAttribute = source.GetAttribute("expression", String.Empty); string bitrateAttribute = source.GetAttribute("bitrate", String.Empty); if (!String.IsNullOrEmpty(urlAttribute)) { Uri url; if (Uri.TryCreate(urlAttribute, UriKind.RelativeOrAbsolute, out url)) { this.Url = url; wasLoaded = true; } } if (!String.IsNullOrEmpty(fileSizeAttribute)) { long fileSize; if (Int64.TryParse(fileSizeAttribute, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out fileSize)) { this.FileSize = fileSize; wasLoaded = true; } } if (!String.IsNullOrEmpty(typeAttribute)) { this.ContentType = typeAttribute; wasLoaded = true; } if (!String.IsNullOrEmpty(mediumAttribute)) { YahooMediaMedium medium = YahooMediaSyndicationExtension.MediumByName(mediumAttribute); if (medium != YahooMediaMedium.None) { this.Medium = medium; wasLoaded = true; } } if (!String.IsNullOrEmpty(isDefaultAttribute)) { if (String.Compare(isDefaultAttribute, "true", StringComparison.OrdinalIgnoreCase) == 0) { this.IsDefault = true; wasLoaded = true; } else if (String.Compare(isDefaultAttribute, "false", StringComparison.OrdinalIgnoreCase) == 0) { this.IsDefault = false; wasLoaded = true; } } if (!String.IsNullOrEmpty(expressionAttribute)) { YahooMediaExpression expression = YahooMediaSyndicationExtension.ExpressionByName(expressionAttribute); if (expression != YahooMediaExpression.None) { this.Expression = expression; wasLoaded = true; } } if (!String.IsNullOrEmpty(bitrateAttribute)) { int bitrate; if (Int32.TryParse(bitrateAttribute, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out bitrate)) { this.Bitrate = bitrate; wasLoaded = true; } } } return(wasLoaded); }