private PhotoInstance? GetPhotoInstance(newsItem ni, enumeratedTypes.enumPhotoInstanceType[] photoTypes) { IEnumerator<photo> phEn = ni.photos.GetEnumerator(); if (!phEn.MoveNext()) return null; PhotoInstance phIns = new PhotoInstance(); bool found = false; photo ph = phEn.Current; IEnumerator<photo.Instance> phIEn = ph.Instances.GetEnumerator(); while (phIEn.MoveNext()) { foreach (enumeratedTypes.enumPhotoInstanceType phType in photoTypes) { if (phIEn.Current.type == phType) { phIns.Width = phIEn.Current.width; phIns.Height = phIEn.Current.height; phIns.Url = phIEn.Current.url; phIns.Type = phIEn.Current.type; phIns.Type = phType; string cleanedUrl = phIns.Url; if (cleanedUrl.IndexOf('?') >= 0) cleanedUrl = cleanedUrl.Substring(0, cleanedUrl.IndexOf('?')); string phTypeSlug = Slugify(phType); phIns.DestinationFileName = Slugify(ni.headline) + (phTypeSlug == "" ? "" : "-" + phTypeSlug) + Path.GetExtension(cleanedUrl); found = true; break; } } if (found) { phIns.AltText = phEn.Current.htmlAlt; phIns.Caption = phEn.Current.caption; phIns.Id = phEn.Current.id; phIns.Orientation = phEn.Current.orientation; break; } } if (!found) return null; return phIns; }
private string Slugify(enumeratedTypes.enumPhotoInstanceType phType) { switch (phType) { case enumeratedTypes.enumPhotoInstanceType.Small: return "small"; case enumeratedTypes.enumPhotoInstanceType.Medium: return "med"; case enumeratedTypes.enumPhotoInstanceType.Thumbnail: return "thumb"; default: return ""; } }
private PhotoInstance? GetPhotoInstance(newsItem ni, enumeratedTypes.enumPhotoInstanceType photoType) { return GetPhotoInstance(ni, new enumeratedTypes.enumPhotoInstanceType[] { photoType }); }