/// <summary> /// Initializes a new instance of the <see cref="AlbumSyndicationFeedBuilder" /> class. /// </summary> /// <param name="album">The album used to generate the syndication feed.</param> /// <param name="moBuilderOptions">The options that direct the creation of HTML and URLs for a media object.</param> /// <param name="isAuthenticated">Indicates whether the current user is authenticated.</param> public AlbumSyndicationFeedBuilder(IAlbum album, MediaObjectHtmlBuilderOptions moBuilderOptions, bool isAuthenticated) { Album = album; Options = moBuilderOptions; IsAuthenticated = isAuthenticated; }
/// <summary> /// Initializes a new instance of the <see cref="AlbumSyndicationFeedBuilder"/> class. /// </summary> /// <param name="album">The album used to generate the syndication feed.</param> /// <param name="moBuilderOptions">The options that direct the creation of HTML and URLs for a media object.</param> public AlbumSyndicationFeedBuilder(IAlbum album, MediaObjectHtmlBuilderOptions moBuilderOptions) { Album = album; Options = moBuilderOptions; }
/// <summary> /// Builds the syndication feed from the specified <paramref name="album" /> and write it to the <paramref name="stream" />. /// </summary> /// <param name="album">The album from which to build the syndication feed.</param> /// <param name="stream">The <see cref="T:System.IO.Stream" /> to which to write.</param> /// <param name="contentType">Type of the requested content. Examples: "application/atom+xml", "application/rss+xml"</param> /// <param name="moBuilderOptions">The options that direct the creation of HTML and URLs for a media object.</param> private static void BuildSyndicationFeed(IAlbum album, Stream stream, string contentType, MediaObjectHtmlBuilderOptions moBuilderOptions) { var fb = new AlbumSyndicationFeedBuilder(album, moBuilderOptions); var feed = fb.Generate(); using (var writer = XmlWriter.Create(stream)) { if (String.Equals(contentType, AtomMediaType, StringComparison.InvariantCultureIgnoreCase)) { var atomFormatter = new Atom10FeedFormatter(feed); atomFormatter.WriteTo(writer); } else { var rssFormatter = new Rss20FeedFormatter(feed); rssFormatter.WriteTo(writer); } } }
/// <summary> /// Builds the syndication item from the <paramref name="galleryObject" /> and having the properties specified /// in <paramref name="options" />. /// </summary> /// <param name="galleryObject">The gallery object.</param> /// <param name="options">The options that direct the creation of HTML and URLs for a media object.</param> /// <returns>An instance of <see cref="SyndicationItem" />.</returns> private static SyndicationItem BuildSyndicationItem(IGalleryObject galleryObject, MediaObjectHtmlBuilderOptions options) { options.GalleryObject = galleryObject; options.DisplayType = (galleryObject.GalleryObjectType == GalleryObjectType.External ? DisplayObjectType.External : DisplayObjectType.Optimized); var moBuilder = new MediaObjectHtmlBuilder(options); var pageUrl = moBuilder.GetPageUrl(); var content = GetGalleryObjectContent(galleryObject, pageUrl, moBuilder); var item = new SyndicationItem( RssEncode(HtmlValidator.RemoveHtml(galleryObject.Title, false)), SyndicationContent.CreateHtmlContent(content), new Uri(pageUrl), galleryObject.Id.ToString(CultureInfo.InvariantCulture), galleryObject.DateLastModified); item.PublishDate = galleryObject.DateAdded; item.Authors.Add(new SyndicationPerson() { Name = galleryObject.CreatedByUserName }); item.Categories.Add(new SyndicationCategory(galleryObject.GalleryObjectType.ToString())); return item; }
/// <summary> /// Builds the syndication item from the <paramref name="galleryObject" /> and having the properties specified /// in <paramref name="options" />. /// </summary> /// <param name="galleryObject">The gallery object.</param> /// <param name="options">The options that direct the creation of HTML and URLs for a media object.</param> /// <returns>An instance of <see cref="SyndicationItem" />.</returns> private static SyndicationItem BuildSyndicationItem(IGalleryObject galleryObject, MediaObjectHtmlBuilderOptions options) { options.GalleryObject = galleryObject; options.DisplayType = (galleryObject.GalleryObjectType == GalleryObjectType.External ? DisplayObjectType.External : DisplayObjectType.Optimized); var moBuilder = new MediaObjectHtmlBuilder(options); var pageUrl = moBuilder.GetPageUrl(); var content = GetGalleryObjectContent(galleryObject, pageUrl, moBuilder); var item = new SyndicationItem( RssEncode(HtmlValidator.RemoveHtml(galleryObject.Title, false)), SyndicationContent.CreateHtmlContent(content), new Uri(pageUrl), galleryObject.Id.ToString(CultureInfo.InvariantCulture), galleryObject.DateLastModified); item.PublishDate = galleryObject.DateAdded; item.Authors.Add(new SyndicationPerson() { Name = galleryObject.CreatedByUserName }); item.Categories.Add(new SyndicationCategory(galleryObject.GalleryObjectType.ToString())); return(item); }
public MediaObjectHtmlBuilder GetMediaObjectHtmlBuilder(MediaObjectHtmlBuilderOptions options) { return(new MediaObjectHtmlBuilder(options)); }
/// <summary> /// Gets a collection of views corresponding to the gallery object and other specs in <paramref name="moBuilderOptions" />. /// </summary> /// <param name="moBuilderOptions">A set of properties to be used when building the output.</param> /// <returns>Returns a collection of <see cref="Entity.DisplayObject" /> instances.</returns> private static List<Entity.DisplayObject> GetViews(MediaObjectHtmlBuilderOptions moBuilderOptions) { var views = new List<Entity.DisplayObject>(3); moBuilderOptions.DisplayType = DisplayObjectType.Thumbnail; var moBuilder = new MediaObjectHtmlBuilder(moBuilderOptions); views.Add(new Entity.DisplayObject { ViewSize = (int)DisplayObjectType.Thumbnail, ViewType = (int)moBuilder.MimeType.TypeCategory, HtmlOutput = moBuilder.GenerateHtml(), ScriptOutput = moBuilder.GenerateScript(), Width = moBuilder.Width, Height = moBuilder.Height, Url = moBuilder.GetMediaObjectUrl() }); if (HasOptimizedVersion(moBuilderOptions.GalleryObject)) { moBuilderOptions.DisplayType = DisplayObjectType.Optimized; moBuilder = new MediaObjectHtmlBuilder(moBuilderOptions); views.Add(new Entity.DisplayObject { ViewSize = (int)DisplayObjectType.Optimized, ViewType = (int)moBuilder.MimeType.TypeCategory, HtmlOutput = moBuilder.GenerateHtml(), ScriptOutput = moBuilder.GenerateScript(), Width = moBuilder.Width, Height = moBuilder.Height, Url = moBuilder.GetMediaObjectUrl() }); } if (HasOriginalVersion(moBuilderOptions.GalleryObject)) { moBuilderOptions.DisplayType = moBuilderOptions.GalleryObject.Original.DisplayType; // May be Original or External moBuilder = new MediaObjectHtmlBuilder(moBuilderOptions); views.Add(new Entity.DisplayObject { ViewSize = (int)DisplayObjectType.Original, ViewType = (int)moBuilder.MimeType.TypeCategory, HtmlOutput = moBuilder.GenerateHtml(), ScriptOutput = moBuilder.GenerateScript(), Width = moBuilder.Width, Height = moBuilder.Height, Url = moBuilder.GetMediaObjectUrl() }); } return views; }
/// <summary> /// Converts the <paramref name="mediaObject"/> to an instance of <see cref="Entity.MediaItem" />. /// The returned object DOES have the <see cref="Entity.MediaItem.MetaItems" /> property assigned. /// The instance can be JSON-serialized and sent to the browser. Do not pass an /// <see cref="IAlbum" /> to this function. /// </summary> /// <param name="mediaObject">The media object to convert to an instance of /// <see cref="Entity.MediaItem"/>.</param> /// <param name="indexInAlbum">The one-based index of this media object within its album. This value is assigned to /// <see cref="Entity.MediaItem.Index" />.</param> /// <param name="moBuilderOptions">A set of properties to be used to build the HTML, JavaScript or URL for the /// <paramref name="mediaObject" />.</param> /// <returns>Returns an <see cref="Entity.MediaItem"/> object containing information /// about the requested media object.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="mediaObject" /> or /// <paramref name="moBuilderOptions" /> is null.</exception> /// <exception cref="System.ArgumentOutOfRangeException">Thrown when <paramref name="moBuilderOptions" /> does /// has a null or empty <see cref="MediaObjectHtmlBuilderOptions.Browsers" /> property.</exception> public static MediaItem ToMediaItem(IGalleryObject mediaObject, int indexInAlbum, MediaObjectHtmlBuilderOptions moBuilderOptions) { if (mediaObject == null) throw new ArgumentNullException("mediaObject"); if (moBuilderOptions == null) throw new ArgumentNullException("moBuilderOptions"); if (moBuilderOptions.Browsers == null || moBuilderOptions.Browsers.Length == 0) throw new ArgumentOutOfRangeException("moBuilderOptions.Browsers", "The Browsers array property must have at least one element."); moBuilderOptions.GalleryObject = mediaObject; var isBeingProcessed = MediaConversionQueue.Instance.IsWaitingInQueueOrProcessing(mediaObject.Id, MediaQueueItemConversionType.CreateOptimized); var moEntity = new MediaItem { Id = mediaObject.Id, AlbumId = mediaObject.Parent.Id, AlbumTitle = mediaObject.Parent.Title, Index = indexInAlbum, Title = mediaObject.Title, Views = GetViews(moBuilderOptions).ToArray(), HighResAvailable = isBeingProcessed || (!String.IsNullOrEmpty(mediaObject.Optimized.FileName)) && (mediaObject.Original.FileName != mediaObject.Optimized.FileName), IsDownloadable = !(mediaObject is ExternalMediaObject), MimeType = (int)mediaObject.MimeType.TypeCategory, ItemType = (int)mediaObject.GalleryObjectType, MetaItems = ToMetaItems(mediaObject.MetadataItems.GetVisibleItems(), mediaObject) }; return moEntity; }
/// <summary> /// Converts the <paramref name="galleryObject" /> to an instance of <see cref="Entity.GalleryItem" />. /// The instance can be JSON-serialized and sent to the browser. /// </summary> /// <param name="galleryObject">The gallery object to convert to an instance of /// <see cref="Entity.GalleryItem" />. It may be a media object or album.</param> /// <param name="moBuilderOptions">A set of properties to be used to build the HTML, JavaScript or URL for the /// <paramref name="galleryObject" />.</param> /// <returns>Returns an <see cref="Entity.GalleryItem" /> object containing information /// about the requested item.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="galleryObject" /> or /// <paramref name="moBuilderOptions" /> is null.</exception> /// <exception cref="System.ArgumentOutOfRangeException">Thrown when <paramref name="moBuilderOptions" /> does /// has a null or empty <see cref="MediaObjectHtmlBuilderOptions.Browsers" /> property.</exception> public static GalleryItem ToGalleryItem(IGalleryObject galleryObject, MediaObjectHtmlBuilderOptions moBuilderOptions) { if (galleryObject == null) throw new ArgumentNullException("galleryObject"); if (moBuilderOptions == null) throw new ArgumentNullException("moBuilderOptions"); if (moBuilderOptions.Browsers == null || moBuilderOptions.Browsers.Length == 0) throw new ArgumentOutOfRangeException("moBuilderOptions.Browsers", "The Browsers array property must have at least one element."); moBuilderOptions.GalleryObject = galleryObject; var gItem = new GalleryItem { Id = galleryObject.Id, Title = galleryObject.Title, Caption = galleryObject.Caption, Views = GetViews(moBuilderOptions).ToArray(), ViewIndex = 0, MimeType = (int)galleryObject.MimeType.TypeCategory, ItemType = (int)galleryObject.GalleryObjectType }; IAlbum album = galleryObject as IAlbum; if (album != null) { gItem.IsAlbum = true; //gItem.DateStart = album.DateStart; //gItem.DateEnd = album.DateEnd; gItem.NumAlbums = album.GetChildGalleryObjects(GalleryObjectType.All, !Utils.IsAuthenticated).Count; gItem.NumMediaItems = album.GetChildGalleryObjects(GalleryObjectType.MediaObject, !Utils.IsAuthenticated).Count; } return gItem; }