/// <summary> /// Convert <paramref name="mqItem" /> to an instance of <see cref="MediaQueueItemWebEntity" />. Returns null if <paramref name="mqItem" /> is null. /// </summary> /// <param name="mqItem">The media queue item. May be null.</param> /// <returns><see cref="MediaQueueItemWebEntity" /> or null.</returns> private static MediaQueueItemWebEntity ToMediaQueueItem(MediaQueueItem mqItem) { if (mqItem == null) { return(null); } var mo = Factory.LoadMediaObjectInstance(mqItem.MediaObjectId); var moBuilderOptions = MediaObjectHtmlBuilder.GetMediaObjectHtmlBuilderOptions(mo); moBuilderOptions.DisplayType = DisplayObjectType.Thumbnail; var moBuilder = new MediaObjectHtmlBuilder(moBuilderOptions); return(new MediaQueueItemWebEntity() { MediaQueueId = mqItem.MediaQueueId, MediaObjectId = mqItem.MediaObjectId, StatusInt = mqItem.Status, Status = mqItem.Status, ConversionType = mqItem.ConversionType, DateAdded = mqItem.DateAdded, DateConversionStarted = mqItem.DateConversionStarted, DateConversionCompleted = mqItem.DateConversionCompleted, DurationMs = GetDurationMs(mqItem), StatusDetail = mqItem.StatusDetail, OriginalFilename = mo.Original.FileName, NewFilename = mqItem.NewFilename, ThumbnailUrl = GetThumbnailUrl(moBuilder), MediaObjectTitle = mo.Title, AlbumId = mo.Parent.Id, AlbumTitle = mo.Parent.Title }); }
/// <summary> /// Asynchronously writes an object of the specified type. /// </summary> /// <param name="type">The type of the object to write.</param> /// <param name="value">The object value to write. It may be null. If not null, must be able to /// be cast to an <see cref="IAlbum" />.</param> /// <param name="writeStream">The <see cref="T:System.IO.Stream" /> to which to write.</param> /// <param name="content">The <see cref="T:System.Net.Http.HttpContent" /> if available. It may be null.</param> /// <param name="transportContext">The <see cref="T:System.Net.TransportContext" /> if available. It may be null.</param> /// <returns>A <see cref="T:System.Threading.Tasks.Task" /> that will perform the write.</returns> /// <exception cref="GallerySecurityException">Thrown when the application is not running an Enterprise License. /// </exception> public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext) { if (value == null) { return(null); } var album = (IAlbum)value; var options = MediaObjectHtmlBuilder.GetMediaObjectHtmlBuilderOptions(album, DisplayObjectType.Thumbnail); var isAuthenticated = Utils.IsAuthenticated; options.DestinationPageUrl = album.FeedFormatterOptions.DestinationUrl; // Ex: "/dev/gs/default.aspx" return(Task.Factory.StartNew(() => BuildSyndicationFeed(album, writeStream, content.Headers.ContentType.MediaType, options, isAuthenticated))); }
/// <summary> /// Gets the media object with the specified <paramref name="id" />. /// Example: api/mediaitems/4/get /// </summary> /// <param name="id">The media object ID.</param> /// <returns>An instance of <see cref="Entity.MediaItem" />.</returns> /// <exception cref="System.Web.Http.HttpResponseException">Thrown when the media object is not found, the user /// doesn't have permission to view it, or some other error occurs.</exception> public Entity.MediaItem Get(int id) { try { IGalleryObject mediaObject = Factory.LoadMediaObjectInstance(id); SecurityManager.ThrowIfUserNotAuthorized(SecurityActions.ViewAlbumOrMediaObject, RoleController.GetGalleryServerRolesForUser(), mediaObject.Parent.Id, mediaObject.GalleryId, Utils.IsAuthenticated, mediaObject.Parent.IsPrivate, ((IAlbum)mediaObject.Parent).IsVirtualAlbum); var siblings = mediaObject.Parent.GetChildGalleryObjects(GalleryObjectType.MediaObject, !Utils.IsAuthenticated).ToSortedList(); int mediaObjectIndex = siblings.IndexOf(mediaObject); return(GalleryObjectController.ToMediaItem(mediaObject, mediaObjectIndex + 1, MediaObjectHtmlBuilder.GetMediaObjectHtmlBuilderOptions(mediaObject))); } catch (InvalidMediaObjectException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(String.Format("Could not find media object with ID = {0}", id)), ReasonPhrase = "Media Object Not Found" }); } catch (GallerySecurityException) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)); } catch (Exception ex) { AppEventController.LogError(ex); throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = Utils.GetExStringContent(ex), ReasonPhrase = "Server Error" }); } }
public MediaObjectHtmlBuilderOptions GetMediaObjectHtmlBuilderOptions(IGalleryObject galleryObject) { return(MediaObjectHtmlBuilder.GetMediaObjectHtmlBuilderOptions(galleryObject, _urlController)); }