// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <summary> /// Gets the media content items that meet the criteria /// </summary> /// <param name="obj">IRssMEdiaContent object</param> /// <param name="mimeType">Mime Type</param> /// <param name="minWidth">Minimun Width</param> /// <param name="maxWidth">Maximum width</param> /// <param name="minHeight">Minimum Height</param> /// <param name="maxHeight">Maximun Height</param> /// <returns>IEnumerable<RssMediaContent></returns> // ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- public IEnumerable<RssMediaContent> GetImageItems(IRssMediaContent obj, string mimeType = "", int minWidth = 0, int maxWidth = 0, int minHeight = 0, int maxHeight = 0, bool ExitAfterOneFound = false) { List<RssMediaContent> rt = new List<RssMediaContent>(); bool TestMimeType = mimeType.Length > 0 ? true : false; StringComparer cmp = StringComparer.OrdinalIgnoreCase; // loop through each content item getting the ones that match the criteria for (int i = 0; i < obj.mediaContentItems.Count; i++) { RssMediaContent rslt = obj.mediaContentItems[i].GetIfImageItem(mimeType, minWidth, maxWidth, minHeight, maxHeight); if (rslt != null) { rt.Add(rslt); if (ExitAfterOneFound) { break; } } } // next media content item return rt; }
// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <summary> /// Gets a single image /// </summary> /// <param name="obj">IRssMEdiaContent object</param> /// <param name="mimeType">Mime Type</param> /// <param name="minWidth">Minimun Width</param> /// <param name="maxWidth">Maximum width</param> /// <param name="minHeight">Minimum Height</param> /// <param name="maxHeight">Maximun Height</param> /// <returns>RssMediaContent</returns> // ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- public RssMediaContent GetImageItem(IRssMediaContent obj, string mimeType = "", int minWidth = 0, int maxWidth = 0, int minHeight = 0, int maxHeight = 0) { RssMediaContent rt = null; IEnumerable<RssMediaContent> lst = GetImageItems(obj, mimeType, minWidth, maxWidth, minHeight, maxHeight, true); if (lst.Count() > 0) { rt = lst.First(); } return rt; }
// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <summary> /// Gets the media content items /// </summary> /// <param name="obj">IRssMediaContent object</param> /// <param name="medium">medium, resource type</param> /// <param name="mimeType">mime type</param> /// <returns>IEnumerable<RssMediaContent></returns> // ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- public RssMediaContent GetFirstContentItem(IRssMediaContent obj, string medium = "", string mimeType = "") { RssMediaContent rt = null; // get the content items in a list. Should only be one. IEnumerable<RssMediaContent> lst = GetContentItems(obj, medium, mimeType, ExitAfterOneFound: true); // if the list count is greater than zero if (lst.Count() > 0) { // get the first one....the only one. rt = lst.First(); } return rt; }
// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <summary> /// Gets the media content items that meet the criteria /// </summary> /// <param name="obj">IRssMediaContent object</param> /// <param name="medium">medium, resource type</param> /// <param name="mimeType">mime type</param> /// <returns>IEnumerable<RssMediaContent></returns> // ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- public IEnumerable<RssMediaContent> GetContentItems(IRssMediaContent obj, string medium = "", string mimeType = "", bool ExitAfterOneFound = false) { List<RssMediaContent> rt = new List<RssMediaContent>(); bool TestMedium = medium.Length > 0 ? true : false; bool TestMimeType = mimeType.Length > 0 ? true : false; StringComparer cmp = StringComparer.OrdinalIgnoreCase; for (int i = 0; i < obj.mediaContentItems.Count; i++) { bool bRslt = false; // if test the medium if (TestMedium) { switch (medium) { case RSS.MEDIUM_TYPE_IMAGE: if (obj.mediaContentItems[i].GetIfImageItem() != null) { bRslt = true; } break; case RSS.MEDIUM_TYPE_VIDEO: if (obj.mediaContentItems[i].GetIfVideoItem() != null) { bRslt = true; } break; case RSS.MEDIUM_TYPE_AUDIO: if (obj.mediaContentItems[i].GetIfAudioItem() != null) { bRslt = true; } break; default: if (cmp.Compare(medium, obj.mediaContentItems[i].medium) == 0) { bRslt = true; } break; } } // if not brslt and test mime type if (!bRslt && TestMimeType) { if (cmp.Compare(mimeType, obj.mediaContentItems[i].type) == 0) { bRslt = true; } } // if we didn't test the medium or the mime type, set the result to true // so we add the item. because we are just accumulating the items in this case if (!TestMedium && !TestMimeType) { bRslt = true; } // if ok to add, then add it to the return set if (bRslt) { rt.Add(obj.mediaContentItems[i]); // if the ExitAfterOneFound flag is set, then we want to bail // this is for the get first things if (ExitAfterOneFound) { break; } } } // next media content item return rt; }