Beispiel #1
0
 /// <summary>
 /// Calculates the URL to the thumbnail image of a media asset, with the host name excluded.
 /// Ex: "/gs/handler/getmedia.ashx?moid=34&amp;dt=1&amp;g=1"
 /// </summary>
 /// <param name="moBuilder">An instance of <see cref="MediaObjectHtmlBuilder" />.</param>
 /// <returns>An instance of <see cref="System.String" />.</returns>
 private static string GetThumbnailUrl(MediaObjectHtmlBuilder moBuilder)
 {
     // We remove the host URL (e.g. "http://localhost/dev/gs") to avoid sending the wrong host name to a user. For example, if two users are on the
     // media queue page but on different hosts (e.g. localhost and rdog), the GetMediaObjectUrl() function below will return the same host URL for
     // both users, potentially resulting in a broken link for one of them. This is because Utils.GetHostUrl() requires an HTTP context and when one
     // is not present (such as with SignalR), it falls back to the last known host URL (which may be for a different user).
     return(moBuilder.GetMediaObjectUrl().Replace(Utils.GetHostUrl(), string.Empty));
 }
Beispiel #2
0
        /// <summary>
        /// Get an absolute URL to the thumbnail, optimized, or original media object.
        /// Ex: "http://site.com/gallery/gs/handler/getmedia.ashx?moid=34&amp;dt=1&amp;g=1"
        /// The URL can be used to assign to the src attribute of an image tag (&lt;img src='...' /&gt;).
        /// Not tested: It should be possible to pass an album and request the url to its thumbnail image.
        /// </summary>
        /// <param name="galleryObject">The gallery object for which an URL to the specified image is to be generated.</param>
        /// <param name="displayType">A DisplayObjectType enumeration value indicating the version of the
        /// object for which the URL should be generated. Possible values: Thumbnail, Optimized, Original.
        /// An exception is thrown if any other enumeration is passed.</param>
        /// <returns>Returns the URL to the thumbnail, optimized, or original version of the requested media object.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="galleryObject" /> is null.</exception>
        public static string GetGalleryObjectUrl(IGalleryObject galleryObject, DisplayObjectType displayType)
        {
            if (galleryObject == null)
            {
                throw new ArgumentNullException("galleryObject");
            }

            if (galleryObject is Album && (displayType != DisplayObjectType.Thumbnail))
            {
                throw new ArgumentException(String.Format("It is invalid to request an URL for an album display type '{0}'.", displayType));
            }

            var moBuilder = new MediaObjectHtmlBuilder(MediaObjectHtmlBuilder.GetMediaObjectHtmlBuilderOptions(galleryObject, displayType));

            return moBuilder.GetMediaObjectUrl();
        }
        /// <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;
        }