Ejemplo n.º 1
0
        public ActionResult PrepareZipDownload(Entity.GalleryItem[] galleryItems, DisplayObjectType mediaSize)
        {
            try
            {
                return(AlbumController.PrepareZipDownload(galleryItems, mediaSize));
            }
            catch (GallerySecurityException ex)
            {
                AppEventController.LogError(ex);

                return(new ActionResult
                {
                    Title = "Cannot Download",
                    Status = ActionResultStatus.Warning.ToString(),
                    Message = ex.Message
                });
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the name of the requested media file, without the prefix (e.g. "zThumb_", "zOpt_").
        /// If a media object does not have a physical file (for example, external media objects), then return <see cref="String.Empty"/>.
        /// Ex: C:\Inetpub\wwwroot\galleryserverpro\mediaobjects\Summer 2005\sunsets\desert sunsets\sonorandesert.jpg
        /// </summary>
        /// <param name="mediaObject">The media object for which to return a path to the media file.</param>
        /// <param name="mediaSize">Size of the media file to return.</param>
        /// <returns>Returns the full path to the media object file.</returns>
        private static string GetMediaFileNameForZip(IGalleryObject mediaObject, DisplayObjectType mediaSize)
        {
            string           fileName       = String.Empty;
            IGallerySettings gallerySetting = Factory.LoadGallerySetting(mediaObject.GalleryId);

            switch (mediaSize)
            {
            case DisplayObjectType.Thumbnail:
                fileName = mediaObject.Thumbnail.FileName.Replace(gallerySetting.ThumbnailFileNamePrefix, String.Empty);
                break;

            case DisplayObjectType.Optimized:
                fileName = mediaObject.Optimized.FileName.Replace(gallerySetting.OptimizedFileNamePrefix, String.Empty);
                break;

            case DisplayObjectType.Original:
                fileName = mediaObject.Original.FileNamePhysicalPath;
                break;
            }

            if (String.IsNullOrEmpty(fileName))
            {
                fileName = mediaObject.Original.FileName;
            }

            return(fileName);
        }
Ejemplo n.º 3
0
        public MediaObjectHtmlBuilder(IGalleryObject mediaObject, IDisplayObject displayObject, Array browsers)
        {
            if (mediaObject == null)
            {
                throw new ArgumentNullException("mediaObject");
            }

            if (displayObject == null)
            {
                throw new ArgumentNullException("displayObject");
            }

            if ((browsers == null) || (browsers.Length < 1))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.MediaObjectHtmlBuilder_Ctor_InvalidBrowsers_Msg));
            }

            this._galleryObject           = mediaObject;
            this._mediaObjectId           = mediaObject.Id;
            this._albumId                 = mediaObject.Parent.Id;
            this._mimeType                = displayObject.MimeType;
            this._mediaObjectPhysicalPath = displayObject.FileNamePhysicalPath;
            this._width              = displayObject.Width;
            this._height             = displayObject.Height;
            this._title              = mediaObject.Title;
            this._browsers           = browsers;
            this._displayType        = displayObject.DisplayType;
            this._isPrivate          = mediaObject.IsPrivate;
            this._galleryId          = mediaObject.GalleryId;
            this._externalHtmlSource = displayObject.ExternalHtmlSource;
        }
Ejemplo n.º 4
0
        private bool _hasBeenDisposed;         // Used by Dispose() methods

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="DisplayObject"/> class.
        /// </summary>
        /// <param name="width">The width of this object, in pixels.</param>
        /// <param name="height">The height of this object, in pixels.</param>
        /// <param name="filename">The name of the file representing this object. Example: sonorandesert.jpg</param>
        /// <param name="parent">The media object to which this display object applies.</param>
        /// <param name="displayType">The type of the display object.</param>
        /// <param name="displayObjectCreator">The object responsible for generating the file this display object points to.</param>
        private DisplayObject(int width, int height, string filename, IGalleryObject parent, DisplayObjectType displayType, IDisplayObjectCreator displayObjectCreator)
        {
#if DEBUG
            tt.Tools.StartingMethod(width, height, filename, parent, displayType, displayObjectCreator);
#endif

            this._width    = width;
            this._height   = height;
            this._filename = filename;

            if (!String.IsNullOrEmpty(filename))
            {
                this._mimeType = GalleryServerPro.Business.MimeType.LoadInstanceByFilePath(this._filename);
            }

            if (this._mimeType == null)
            {
                this._mimeType = new NullObjects.NullMimeType();
            }

            this._parent               = parent;
            this._displayType          = displayType;
            this._displayObjectCreator = displayObjectCreator;

            if (this._parent is IAlbum)
            {
                this._mediaObjectId = int.MinValue;
            }
            else
            {
                this._mediaObjectId = parent.Id;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the full file path of the requested media file, without the prefix (e.g. "zThumb_", "zOpt_").
        /// This will be the value that is used to name the file entry in the ZIP file and in many cases does not
        /// correspond to an actual path to a file on the server. If a media object does not have a physical file
        /// (for example, external media objects), then return <see cref="string.Empty" />.
        /// Ex: C:\Inetpub\wwwroot\galleryserverpro\mediaobjects\Summer 2005\sunsets\desert sunsets\sonorandesert.jpg
        /// </summary>
        /// <param name="mediaObject">The media object for which to return a path to the media file.</param>
        /// <param name="mediaSize">Size of the media file to return.</param>
        /// <returns>Returns the full path to the media object file or an empty string.</returns>
        private static string GetMediaFilePathForZip(IGalleryObject mediaObject, DisplayObjectType mediaSize)
        {
            string fileExtension;

            switch (mediaSize)
            {
            case DisplayObjectType.Thumbnail:
                fileExtension = Path.GetExtension(mediaObject.Thumbnail.FileName);
                break;

            case DisplayObjectType.Optimized:
                fileExtension = Path.GetExtension(mediaObject.Optimized.FileName);
                break;

            case DisplayObjectType.Original:
                fileExtension = Path.GetExtension(mediaObject.Original.FileName);
                break;

            default:
                return(string.Empty);
            }

            if (string.IsNullOrEmpty(fileExtension))
            {
                return(string.Empty);
            }

            // Combine original path with original file name and the thmb/opt/orig extension
            return(Path.Combine(mediaObject.FullPhysicalPathOnDisk, string.Concat(Path.GetFileNameWithoutExtension(mediaObject.Original.FileName), fileExtension)));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DisplayObject"/> class.
        /// </summary>
        /// <param name="width">The width of this object, in pixels.</param>
        /// <param name="height">The height of this object, in pixels.</param>
        /// <param name="filename">The name of the file representing this object. Example: sonorandesert.jpg</param>
        /// <param name="parent">The media object to which this display object applies.</param>
        /// <param name="displayType">The type of the display object.</param>
        /// <param name="displayObjectCreator">The object responsible for generating the file this display object points to.</param>
        private DisplayObject(int width, int height, string filename, IGalleryObject parent, DisplayObjectType displayType, IDisplayObjectCreator displayObjectCreator)
        {
            this._width    = width;
            this._height   = height;
            this._filename = filename;

            if (!String.IsNullOrEmpty(filename))
            {
                this._mimeType = Business.MimeType.LoadMimeType(parent.GalleryId, this._filename);
            }

            if (this._mimeType == null)
            {
                this._mimeType = new NullObjects.NullMimeType();
            }

            this._parent               = parent;
            this._displayType          = displayType;
            this._displayObjectCreator = displayObjectCreator;

            if (this._parent is IAlbum)
            {
                this._mediaObjectId = int.MinValue;
            }
            else
            {
                this._mediaObjectId = parent.Id;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DisplayObject"/> class.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="displayType">The display type.</param>
        /// <param name="mimeType">Specifies the category to which this mime type belongs. This usually corresponds to the first portion of
        /// the full mime type description. (e.g. "image" if the full mime type is "image/jpeg").</param>
        private DisplayObject(IGalleryObject parent, DisplayObjectType displayType, MimeTypeCategory mimeType)
        {
            if (displayType != DisplayObjectType.External)
            {
                throw new BusinessException(String.Format(CultureInfo.CurrentCulture, "This overload of the DisplayObject constructor can only be called when the displayType parameter is DisplayObjectType.External. Instead, it was {0}.", displayType.ToString()));
            }

            this._width                = int.MinValue;
            this._height               = int.MinValue;
            this._filename             = String.Empty;
            this._mimeType             = GalleryServerPro.Business.MimeType.CreateInstance(mimeType);
            this._externalType         = this._mimeType.TypeCategory;
            this._parent               = parent;
            this._displayType          = displayType;
            this._displayObjectCreator = new NullObjects.NullDisplayObjectCreator();

            if (this._parent is IAlbum)
            {
                this._mediaObjectId = int.MinValue;
            }
            else
            {
                this._mediaObjectId = parent.Id;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DisplayObject"/> class.
        /// </summary>
        /// <param name="width">The width of this object, in pixels.</param>
        /// <param name="height">The height of this object, in pixels.</param>
        /// <param name="filename">The name of the file representing this object. Example: sonorandesert.jpg</param>
        /// <param name="parent">The media object to which this display object applies.</param>
        /// <param name="displayType">The type of the display object.</param>
        /// <param name="displayObjectCreator">The object responsible for generating the file this display object points to.</param>
        private DisplayObject(int width, int height, string filename, IGalleryObject parent, DisplayObjectType displayType, IDisplayObjectCreator displayObjectCreator)
        {
            this._width = width;
            this._height = height;
            this._filename = filename;

            if (!String.IsNullOrEmpty(filename))
            {
                this._mimeType = Factory.LoadMimeType(parent.GalleryId, this._filename);
            }

            if (this._mimeType == null)
            {
                this._mimeType = new NullObjects.NullMimeType();
            }

            this._parent = parent;
            this._displayType = displayType;
            this._displayObjectCreator = displayObjectCreator;
            this._displayObjectCreator.Parent = this;

            if (this._parent is IAlbum)
            {
                this._mediaObjectId = int.MinValue;
            }
            else
            {
                this._mediaObjectId = parent.Id;
            }
        }
Ejemplo n.º 9
0
		private bool _hasBeenDisposed; // Used by Dispose() methods
		
		#endregion

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="DisplayObject"/> class.
		/// </summary>
		/// <param name="width">The width of this object, in pixels.</param>
		/// <param name="height">The height of this object, in pixels.</param>
		/// <param name="filename">The name of the file representing this object. Example: sonorandesert.jpg</param>
		/// <param name="parent">The media object to which this display object applies.</param>
		/// <param name="displayType">The type of the display object.</param>
		/// <param name="displayObjectCreator">The object responsible for generating the file this display object points to.</param>
		private DisplayObject(int width, int height, string filename, IGalleryObject parent, DisplayObjectType displayType, IDisplayObjectCreator displayObjectCreator)
		{
#if DEBUG
			tt.Tools.StartingMethod(width, height, filename, parent, displayType, displayObjectCreator);
#endif

			this._width = width;
			this._height = height;
			this._filename = filename;

			if (!String.IsNullOrEmpty(filename))
			{
				this._mimeType = GalleryServerPro.Business.MimeType.LoadInstanceByFilePath(this._filename);
			}

			if (this._mimeType == null)
			{
				this._mimeType = new NullObjects.NullMimeType();
			}

			this._parent = parent;
			this._displayType = displayType;
			this._displayObjectCreator = displayObjectCreator;

			if (this._parent is IAlbum)
			{
				this._mediaObjectId = int.MinValue;
			}
			else
			{
				this._mediaObjectId = parent.Id;
			}
		}
Ejemplo n.º 10
0
        /// <summary>
        /// Gets the full path to the media object file. If <paramref name="mediaObject"/>
        /// is an <see cref="Image"/>, then return the thumbnail, compressed, or original file as specified in <paramref name="imageSize"/>.
        /// If a media object does not have a physical file (for example, external media objects), then return <see cref="String.Empty"/>.
        /// Ex: C:\Inetpub\wwwroot\galleryserverpro\mediaobjects\Summer 2005\sunsets\desert sunsets\sonorandesert.jpg
        /// </summary>
        /// <param name="mediaObject">The media object for which to return a path to the media file.</param>
        /// <param name="imageSize">Size of the image to return. This parameter applies only to <see cref="Image"/> media objects.</param>
        /// <returns>Returns the full path to the media object file.</returns>
        private static string GetMediaFilePath(IGalleryObject mediaObject, DisplayObjectType imageSize)
        {
            string filePath = String.Empty;

            if (mediaObject is Image)
            {
                switch (imageSize)
                {
                case DisplayObjectType.Thumbnail:
                    filePath = mediaObject.Thumbnail.FileNamePhysicalPath;
                    break;

                case DisplayObjectType.Optimized:
                    filePath = mediaObject.Optimized.FileNamePhysicalPath;
                    break;

                case DisplayObjectType.Original:
                    filePath = mediaObject.Original.FileNamePhysicalPath;
                    break;
                }
            }

            if (String.IsNullOrEmpty(filePath))
            {
                filePath = mediaObject.Original.FileNamePhysicalPath;
            }

            return(filePath);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Create a new display object instance with the specified properties. No data is retrieved from the
        /// data store. A lazy load is used to inflate the object when necessary
        /// </summary>
        /// <param name="parent">The media object to which this display object applies.</param>
        /// <param name="displayType">The type of the display object.</param>
        /// <param name="mimeType">Specifies the category to which this mime type belongs. This usually corresponds to the first portion of
        /// the full mime type description. (e.g. "image" if the full mime type is "image/jpeg").</param>
        /// <returns>Create a new display object instance with the specified properties.</returns>
        public static IDisplayObject CreateInstance(IGalleryObject parent, DisplayObjectType displayType, MimeTypeCategory mimeType)
        {
            if (displayType != DisplayObjectType.External)
            {
                throw new BusinessException(String.Format(CultureInfo.CurrentCulture, "This overload of DisplayObject.CreateInstance can only be called when the displayType parameter is DisplayObjectType.External. Instead, it was {0}.", displayType.ToString()));
            }

            return(new DisplayObject(parent, displayType, mimeType));
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MediaObjectHtmlBuilderOptions"/> class.
 /// </summary>
 /// <param name="galleryObject">The gallery object. May be null. If null, <see cref="MediaObjectHtmlBuilderOptions.GalleryObject" />
 /// must be assigned before passing this instance to the <see cref="MediaObjectHtmlBuilder" /> constructor.</param>
 /// <param name="displayType">The display type. Optional. If not assigned or set to <see cref="DisplayObjectType.Unknown" />,
 /// <see cref="MediaObjectHtmlBuilderOptions.DisplayType" /> must be assigned before passing this instance to the
 /// <see cref="MediaObjectHtmlBuilder" /> constructor.</param>
 /// <param name="browsers">The browser IDs for current request.</param>
 /// <param name="destinationPageUrl">The URL, relative to the website root and optionally including any query string parameters,
 /// to the page any generated URLs should point to. Examples: "/dev/gs/gallery.aspx",
 /// "/dev/gs/gallery.aspx?g=admin_email&amp;aid=2389"</param>
 /// <param name="hostUrl">The URI scheme, DNS host name or IP address, and port number for the current application.
 /// Examples: "http://www.site.com", "http://localhost", "http://127.0.0.1", "http://godzilla"</param>
 /// <param name="appRoot">The path, relative to the web site root, to the current web application.
 /// Example: "/dev/gallery".</param>
 /// <param name="galleryRoot">The path, relative to the web site root, to the directory containing the Gallery Server user
 /// controls and other resources. Example: "/dev/gallery/gs".</param>
 ///
 public MediaObjectHtmlBuilderOptions(IGalleryObject galleryObject, DisplayObjectType displayType, Array browsers, string destinationPageUrl, string hostUrl, string appRoot, string galleryRoot)
 {
     GalleryObject      = galleryObject;
     DisplayType        = displayType;
     Browsers           = browsers;
     DestinationPageUrl = destinationPageUrl;
     HostUrl            = hostUrl;
     AppRoot            = appRoot;
     GalleryRoot        = galleryRoot;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MediaObjectHtmlBuilder"/> class.
        /// </summary>
        /// <param name="mediaObjectId">The media object id.</param>
        /// <param name="albumId">The album id.</param>
        /// <param name="mimeType">The MIME type.</param>
        /// <param name="mediaObjectPhysicalPath">The media object physical path.</param>
        /// <param name="width">The width of the media object, in pixels.</param>
        /// <param name="height">The height of the media object, in pixels.</param>
        /// <param name="title">The title.</param>
        /// <param name="browsers">An <see cref="System.Array"/> of browser ids for the current browser. This
        /// is a list of strings that represent the various categories of browsers the current browser belongs
        /// to. This is typically populated by calling ToArray() on the Request.Browser.Browsers property.</param>
        /// <param name="displayType">The display type.</param>
        /// <param name="isPrivate">if set to <c>true</c> the media object is private.</param>
        /// <param name="galleryId">The value that uniquely identifies the current gallery.</param>
        public MediaObjectHtmlBuilder(int mediaObjectId, int albumId, IMimeType mimeType, string mediaObjectPhysicalPath, int width, int height, string title, Array browsers, DisplayObjectType displayType, bool isPrivate, int galleryId)
        {
            #region Validation

            if (mediaObjectId <= 0)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.MediaObjectHtmlBuilder_Ctor_InvalidMediaObjectId_Msg, mediaObjectId));
            }

            if (albumId <= 0)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.MediaObjectHtmlBuilder_Ctor_InvalidAlbumId_Msg, albumId));
            }

            if (mimeType == null)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.MediaObjectHtmlBuilder_Ctor_InvalidMimeType_Msg));
            }

            if (width < 0)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.MediaObjectHtmlBuilder_Ctor_InvalidWidth_Msg, width));
            }

            if (height < 0)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.MediaObjectHtmlBuilder_Ctor_InvalidHeight_Msg, height));
            }

            if (title == null)
            {
                title = String.Empty;
            }

            if ((browsers == null) || (browsers.Length < 1))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.MediaObjectHtmlBuilder_Ctor_InvalidBrowsers_Msg));
            }

            #endregion

            this._mediaObjectId           = mediaObjectId;
            this._albumId                 = albumId;
            this._mimeType                = mimeType;
            this._mediaObjectPhysicalPath = mediaObjectPhysicalPath;
            this._width       = width;
            this._height      = height;
            this._title       = title;
            this._browsers    = browsers;
            this._displayType = displayType;
            this._cssClasses  = new StringCollection();
            this._isPrivate   = isPrivate;
            this._galleryId   = galleryId;
        }
Ejemplo n.º 14
0
 public MediaObjectWebEntity GetMediaObjectHtml(int mediaObjectId, DisplayObjectType displayType)
 {
     try
     {
         return(GalleryPage.GetMediaObjectHtml(Factory.LoadMediaObjectInstance(mediaObjectId), displayType, true));
     }
     catch (Exception ex)
     {
         AppErrorController.LogError(ex);
         throw;
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Adds the media objects in the <paramref name="album"/> to the ZIP archive. Only media objects associated with a
        /// physical file are added (that is, external media objects are excluded).
        /// </summary>
        /// <param name="zos">The ZipOutputStream (ZIP archive) the media object file is to be added to.</param>
        /// <param name="album">The album to be added to the ZIP archive.</param>
        /// <param name="imageSize">Size of the image to add to the ZIP archive. This parameter applies only to <see cref="Image"/>
        /// media objects.</param>
        /// <param name="basePath">The full path to the directory containing the highest-level media file to be added
        /// to the ZIP archive. Must include trailing slash. Ex: C:\Inetpub\wwwroot\galleryserverpro\mediaobjects\Summer 2005\sunsets\</param>
        /// <param name="applyWatermark">Indicates whether to apply a watermark to images as they are added to the archive.
        /// Applies only for media objects in the <see cref="album"/> that are an <see cref="Image"/>.</param>
        private void AddZipEntry(ZipOutputStream zos, IAlbum album, DisplayObjectType imageSize, string basePath, bool applyWatermark)
        {
            foreach (IAlbum childAlbum in album.GetChildGalleryObjects(GalleryObjectType.Album, false, !this._isAuthenticated))
            {
                AddZipEntry(zos, childAlbum, imageSize, basePath, applyWatermark);
            }

            foreach (IGalleryObject mediaObject in album.GetChildGalleryObjects(GalleryObjectType.MediaObject, false, !this._isAuthenticated))
            {
                AddFileZipEntry(zos, mediaObject, imageSize, basePath, applyWatermark);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Return the requested display object from the specified media object. If Unknown is passed in the
        /// displayType parameter, and the object is an image, return the optimized object. If an optimized
        /// version does not exist, return the original object. If Unknown is passed in the displayType parameter,
        /// and the object is NOT an image, return the original object. If a thumbnail is requested, always
        /// return a thumbnail object.
        /// </summary>
        /// <param name="mediaObject">The media object containing the display object to return.</param>
        /// <param name="displayType">One of the DisplayObjectType enumeration values indicating which object to return.</param>
        /// <returns>Returns the requested display object from the specified media object.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="mediaObject" /> is null.</exception>
        public static IDisplayObject GetDisplayObject(IGalleryObject mediaObject, DisplayObjectType displayType)
        {
            if (mediaObject == null)
            {
                throw new ArgumentNullException("mediaObject");
            }

            IDisplayObject displayObject;

            switch (displayType)
            {
            case DisplayObjectType.Thumbnail:
            {
                displayObject = mediaObject.Thumbnail;
                break;
            }

            case DisplayObjectType.Unknown:
            case DisplayObjectType.Optimized:
            {
                // Switch to original if it's not in the queue, there isn't an optimized file, or the opt file
                // is the same as the original file.
                bool isOptMissing        = String.IsNullOrEmpty(mediaObject.Optimized.FileName);
                bool notInQueue          = !MediaConversionQueue.Instance.IsWaitingInQueueOrProcessing(mediaObject.Id);
                bool isOptSameAsOriginal = (mediaObject.Optimized.FileName == mediaObject.Original.FileName);
                if (notInQueue && (isOptMissing || isOptSameAsOriginal))
                {
                    displayObject = mediaObject.Original;
                }
                else
                {
                    displayObject = mediaObject.Optimized;
                }

                //displayObject = (mediaObject.Optimized.FileName == mediaObject.Original.FileName) ? mediaObject.Original : mediaObject.Optimized;
                break;
            }

            case DisplayObjectType.Original:
            {
                displayObject = mediaObject.Original;
                break;
            }

            default:
            {
                displayObject = (mediaObject.Optimized.FileName == mediaObject.Original.FileName) ? mediaObject.Original : mediaObject.Optimized;
                break;
            }
            }

            return(displayObject);
        }
Ejemplo n.º 17
0
        private static string GetMediaObjectUrl(int galleryId, int mediaObjectId, DisplayObjectType displayType)
        {
            //string queryString = string.Format(CultureInfo.InvariantCulture, "moid={1}&aid={2}&mo={3}&mtc={4}&dt={5}&isp={6}", galleryId, mediaObjectId, albumId, Uri.EscapeDataString(mediaObjectPhysicalPath), (int)mimeType.TypeCategory, (int)displayType, isPrivate.ToString());
            string queryString = string.Format(CultureInfo.InvariantCulture, "moid={0}&dt={1}&g={2}", mediaObjectId, (int)displayType, galleryId);

            // If necessary, encrypt, then URL encode the query string.
            if (AppSetting.Instance.EncryptMediaObjectUrlOnClient)
            {
                queryString = Util.UrlEncode(HelperFunctions.Encrypt(queryString));
            }

            return(string.Concat(Util.GalleryRoot, "/handler/getmediaobject.ashx?", queryString));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// If an optimized version is being requested, make sure a file name is specified for it. If not, switch to the
        /// original version. This switch will be necessary for most non-image media objects, since the client usually
        /// requests optimized versions for everything.
        /// </summary>
        /// <remarks>This function became necessary when switching to the ID-based request in 2.4 (rather than the
        /// file-based request). It was considered to change the requesting logic to ensure the correct display type
        /// is specified, and while that seems preferable from an architectural perspective, it was more complex to
        /// implement and potentially more fragile than this simple function.</remarks>
        private void ValidateDisplayType()
        {
            if ((_displayType == DisplayObjectType.Optimized) && (String.IsNullOrEmpty(MediaObjectFilePath)))
            {
                _displayType         = DisplayObjectType.Original;
                _mediaObjectFilePath = null;

                // Comment out the exception, as it generates unnecessary errors when bots request deleted items
                //if (String.IsNullOrEmpty(MediaObjectFilePath))
                //{
                //  throw new InvalidMediaObjectException(String.Format(CultureInfo.CurrentCulture, "A request was made to the Gallery Server Pro HTTP handler to serve the optimized image for media object ID {0}, but either the media object does not exist or neither the optimized nor the original has a filename stored in the database, and therefore cannot be served.", _mediaObjectId));
                //}
            }
        }
Ejemplo n.º 19
0
		/// <summary>
		/// Determines if the displayType parameter is one of the defined enumerations. This method is more efficient than using
		/// <see cref="Enum.IsDefined" />, since <see cref="Enum.IsDefined" /> uses reflection.
		/// </summary>
		/// <param name="displayType">A <see cref="DisplayObjectType" /> to test.</param>
		/// <returns>Returns true if displayType is one of the defined items in the enumeration; otherwise returns false.</returns>
		public static bool IsValidDisplayObjectType(DisplayObjectType displayType)
		{
			switch (displayType)
			{
				case DisplayObjectType.External:
				case DisplayObjectType.Optimized:
				case DisplayObjectType.Original:
				case DisplayObjectType.Thumbnail:
				case DisplayObjectType.Unknown:
					break;

				default:
					return false;
			}
			return true;
		}
Ejemplo n.º 20
0
        /// <summary>
        /// Determines if the displayType parameter is one of the defined enumerations. This method is more efficient than using
        /// <see cref="Enum.IsDefined" />, since <see cref="Enum.IsDefined" /> uses reflection.
        /// </summary>
        /// <param name="displayType">A <see cref="DisplayObjectType" /> to test.</param>
        /// <returns>Returns true if displayType is one of the defined items in the enumeration; otherwise returns false.</returns>
        public static bool IsValidDisplayObjectType(DisplayObjectType displayType)
        {
            switch (displayType)
            {
            case DisplayObjectType.External:
            case DisplayObjectType.Optimized:
            case DisplayObjectType.Original:
            case DisplayObjectType.Thumbnail:
            case DisplayObjectType.Unknown:
                break;

            default:
                return(false);
            }
            return(true);
        }
        public async Task <IActionResult> GetMediaFile(int id, DisplayObjectType dt)
        {
            // GET api/mediaitems/file/12?dt=2 // Get the optimized file for media # 12
            _streamController.SetMedia(id, dt);

            return(File(await _streamController.GetStream(), _streamController.ContentType));

            //FYI: Here is how ASP.NET Core calculates etag (https://andrewlock.net/adding-cache-control-headers-to-static-files-in-asp-net-core/)
            //_length = _fileInfo.Length;

            //DateTimeOffset last = _fileInfo.LastModified;
            //// Truncate to the second.
            //_lastModified = new DateTimeOffset(last.Year, last.Month, last.Day, last.Hour, last.Minute, last.Second, last.Offset).ToUniversalTime();

            //long etagHash = _lastModified.ToFileTime() ^ _length;
            //_etag = new EntityTagHeaderValue('\"' + Convert.ToString(etagHash, 16) + '\"');
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Gets the full path to the media object file, returning the thumbnail, compressed, or
        /// original file as specified in <paramref name="mediaSize"/>.
        /// If a media object does not have a physical file (for example, external media objects), then return <see cref="string.Empty" />.
        /// Ex: C:\Inetpub\wwwroot\galleryserverpro\mediaobjects\Summer 2005\sunsets\desert sunsets\sonorandesert.jpg
        /// </summary>
        /// <param name="mediaObject">The media object for which to return a path to the media file.</param>
        /// <param name="mediaSize">Size of the media file to return.</param>
        /// <returns>Returns the full path to the media object file or an empty string.</returns>
        private static string GetMediaFilePath(IGalleryObject mediaObject, DisplayObjectType mediaSize)
        {
            switch (mediaSize)
            {
            case DisplayObjectType.Thumbnail:
                return(mediaObject.Thumbnail.FileNamePhysicalPath);

            case DisplayObjectType.Optimized:
                return(mediaObject.Optimized.FileNamePhysicalPath);

            case DisplayObjectType.Original:
                return(mediaObject.Original.FileNamePhysicalPath);

            default:
                return(string.Empty);
            }
        }
        /// <summary>
        /// Return the requested display object from the specified media object. If Unknown is passed in the
        /// displayType parameter, and the object is an image, return the optimized object. If an optimized
        /// version does not exist, return the original object. If Unknown is passed in the displayType parameter,
        /// and the object is NOT an image, return the original object. If a thumbnail is requested, always
        /// return a thumbnail object.
        /// </summary>
        /// <param name="mediaObject">The media object containing the display object to return.</param>
        /// <param name="displayType">One of the DisplayObjectType enumeration values indicating which object to return.</param>
        /// <returns>Returns the requested display object from the specified media object.</returns>
        public static IDisplayObject GetDisplayObject(IGalleryObject mediaObject, DisplayObjectType displayType)
        {
            IDisplayObject displayObject = null;

            if (displayType == DisplayObjectType.Thumbnail)
            {
                displayObject = mediaObject.Thumbnail;
            }
            else if (mediaObject is GalleryServerPro.Business.Image)
            {
                displayObject = GetDisplayObjectForImage(mediaObject, displayType);
            }
            else
            {
                displayObject = mediaObject.Original;
            }

            return(displayObject);
        }
        /// <summary>
        /// Return the requested display object from the specified media object. If Unknown is passed in the 
        /// displayType parameter, and the object is an image, return the optimized object. If an optimized 
        /// version does not exist, return the original object. If Unknown is passed in the displayType parameter, 
        /// and the object is NOT an image, return the original object. If a thumbnail is requested, always 
        /// return a thumbnail object.
        /// </summary>
        /// <param name="mediaObject">The media object containing the display object to return.</param>
        /// <param name="displayType">One of the DisplayObjectType enumeration values indicating which object to return.</param>
        /// <returns>Returns the requested display object from the specified media object.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="mediaObject" /> is null.</exception>
        public static IDisplayObject GetDisplayObject(IGalleryObject mediaObject, DisplayObjectType displayType)
        {
            if (mediaObject == null)
                throw new ArgumentNullException("mediaObject");

            IDisplayObject displayObject;
            switch (displayType)
            {
                case DisplayObjectType.Thumbnail:
                    {
                        displayObject = mediaObject.Thumbnail;
                        break;
                    }
                case DisplayObjectType.Unknown:
                case DisplayObjectType.Optimized:
                    {
                        // Switch to original if it's not in the queue, there isn't an optimized file, or the opt file
                        // is the same as the original file.
                        bool isOptMissing = String.IsNullOrEmpty(mediaObject.Optimized.FileName);
                        bool notInQueue = !MediaConversionQueue.Instance.IsWaitingInQueueOrProcessing(mediaObject.Id);
                        bool isOptSameAsOriginal = (mediaObject.Optimized.FileName == mediaObject.Original.FileName);
                        if (notInQueue && (isOptMissing || isOptSameAsOriginal))
                            displayObject = mediaObject.Original;
                        else
                            displayObject = mediaObject.Optimized;

                        //displayObject = (mediaObject.Optimized.FileName == mediaObject.Original.FileName) ? mediaObject.Original : mediaObject.Optimized;
                        break;
                    }
                case DisplayObjectType.Original:
                    {
                        displayObject = mediaObject.Original;
                        break;
                    }
                default:
                    {
                        displayObject = (mediaObject.Optimized.FileName == mediaObject.Original.FileName) ? mediaObject.Original : mediaObject.Optimized;
                        break;
                    }
            }

            return displayObject;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MediaObjectHtmlBuilder"/> class.
        /// </summary>
        /// <param name="mediaObjectId">The media object id.</param>
        /// <param name="albumId">The album id.</param>
        /// <param name="mimeType">The MIME type.</param>
        /// <param name="mediaObjectPhysicalPath">The media object physical path.</param>
        /// <param name="width">The width of the media object, in pixels.</param>
        /// <param name="height">The height of the media object, in pixels.</param>
        /// <param name="title">The title.</param>
        /// <param name="browsers">An <see cref="System.Array"/> of browser ids for the current browser. This
        /// is a list of strings that represent the various categories of browsers the current browser belongs
        /// to. This is typically populated by calling ToArray() on the Request.Browser.Browsers property.</param>
        /// <param name="displayType">The display type.</param>
        /// <param name="isPrivate">if set to <c>true</c> the media object is private.</param>
        /// <param name="galleryId">The value that uniquely identifies the current gallery.</param>
        public MediaObjectHtmlBuilder(int mediaObjectId, int albumId, IMimeType mimeType, string mediaObjectPhysicalPath, int width, int height, string title, Array browsers, DisplayObjectType displayType, bool isPrivate, int galleryId)
        {
            #region Validation

            if (mediaObjectId <= 0)
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.MediaObjectHtmlBuilder_Ctor_InvalidMediaObjectId_Msg, mediaObjectId));

            if (albumId <= 0)
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.MediaObjectHtmlBuilder_Ctor_InvalidAlbumId_Msg, albumId));

            if (mimeType == null)
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.MediaObjectHtmlBuilder_Ctor_InvalidMimeType_Msg));

            if (width < 0)
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.MediaObjectHtmlBuilder_Ctor_InvalidWidth_Msg, width));

            if (height < 0)
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.MediaObjectHtmlBuilder_Ctor_InvalidHeight_Msg, height));

            if (title == null)
                title = String.Empty;

            if ((browsers == null) || (browsers.Length < 1))
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.MediaObjectHtmlBuilder_Ctor_InvalidBrowsers_Msg));

            #endregion

            this._mediaObjectId = mediaObjectId;
            this._albumId = albumId;
            this._mimeType = mimeType;
            this._mediaObjectPhysicalPath = mediaObjectPhysicalPath;
            this._width = width;
            this._height = height;
            this._title = title;
            this._browsers = browsers;
            this._displayType = displayType;
            this._cssClasses = new StringCollection();
            this._isPrivate = isPrivate;
            this._galleryId = galleryId;
        }
        /// <summary>
        /// Return the requested display object from the specified media object. If Unknown is passed in the 
        /// displayType parameter, and the object is an image, return the optimized object. If an optimized 
        /// version does not exist, return the original object. If Unknown is passed in the displayType parameter, 
        /// and the object is NOT an image, return the original object. If a thumbnail is requested, always 
        /// return a thumbnail object.
        /// </summary>
        /// <param name="mediaObject">The media object containing the display object to return.</param>
        /// <param name="displayType">One of the DisplayObjectType enumeration values indicating which object to return.</param>
        /// <returns>Returns the requested display object from the specified media object.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="mediaObject" /> is null.</exception>
        public static IDisplayObject GetDisplayObject(IGalleryObject mediaObject, DisplayObjectType displayType)
        {
            if (mediaObject == null)
                throw new ArgumentNullException("mediaObject");

            IDisplayObject displayObject = null;

            if (displayType == DisplayObjectType.Thumbnail)
            {
                displayObject = mediaObject.Thumbnail;
            }
            else if (mediaObject is GalleryServerPro.Business.Image)
            {
                displayObject = GetDisplayObjectForImage(mediaObject, displayType);
            }
            else
            {
                displayObject = mediaObject.Original;
            }

            return displayObject;
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DisplayObject"/> class.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="displayType">The display type.</param>
        /// <param name="mimeType">Specifies the category to which this mime type belongs. This usually corresponds to the first portion of 
        /// the full mime type description. (e.g. "image" if the full mime type is "image/jpeg").</param>
        private DisplayObject(IGalleryObject parent, DisplayObjectType displayType, MimeTypeCategory mimeType)
        {
            if (displayType != DisplayObjectType.External)
                throw new BusinessException(String.Format(CultureInfo.CurrentCulture, "This overload of the DisplayObject constructor can only be called when the displayType parameter is DisplayObjectType.External. Instead, it was {0}.", displayType.ToString()));

            this._width = int.MinValue;
            this._height = int.MinValue;
            this._filename = String.Empty;
            this._mimeType = GalleryServerPro.Business.MimeType.CreateInstance(mimeType);
            this._externalType = this._mimeType.TypeCategory;
            this._parent = parent;
            this._displayType = displayType;
            this._displayObjectCreator = new NullObjects.NullDisplayObjectCreator { Parent = this };

            if (this._parent is IAlbum)
            {
                this._mediaObjectId = int.MinValue;
            }
            else
            {
                this._mediaObjectId = parent.Id;
            }
        }
Ejemplo n.º 28
0
        private DisplayObjectType GetImageSize()
        {
            DisplayObjectType displayType = DEFAULT_IMAGE_SIZE;

            try
            {
                displayType = (DisplayObjectType)Convert.ToInt32(this.ddlImageSize.SelectedValue, CultureInfo.InvariantCulture);
            }
            catch (FormatException) { }             // Suppress any parse errors
            catch (OverflowException) { }           // Suppress any parse errors
            catch (ArgumentOutOfRangeException) { } // Suppress any parse errors

            if (!DisplayObjectTypeEnumHelper.IsValidDisplayObjectType(displayType))
            {
                displayType = DEFAULT_IMAGE_SIZE;
            }

            if ((displayType == DisplayObjectType.Original) && (!this.IsUserAuthorized(SecurityActions.ViewOriginalMediaObject)))
            {
                displayType = DEFAULT_IMAGE_SIZE;
            }

            return(displayType);
        }
Ejemplo n.º 29
0
		/// <summary>
		/// Create a new display object instance with the specified properties. No data is retrieved from the
		/// data store. A lazy load is used to inflate the object when necessary
		/// </summary>
		/// <param name="parent">The media object to which this display object applies.</param>
		/// <param name="displayType">The type of the display object.</param>
		/// <param name="mimeType">Specifies the category to which this mime type belongs. This usually corresponds to the first portion of 
		/// the full mime type description. (e.g. "image" if the full mime type is "image/jpeg").</param>
		/// <returns>Create a new display object instance with the specified properties.</returns>
		public static IDisplayObject CreateInstance(IGalleryObject parent, DisplayObjectType displayType, MimeTypeCategory mimeType)
		{
			if (displayType != DisplayObjectType.External)
				throw new BusinessException(String.Format("This overload of DisplayObject.CreateInstance can only be called when the displayType parameter is DisplayObjectType.External. Instead, it was {0}.", displayType.ToString()));

			return new DisplayObject(parent, displayType, mimeType);
		}
Ejemplo n.º 30
0
 public MediaObjectWebEntity GetMediaObjectHtml(int mediaObjectId, DisplayObjectType displayType)
 {
     try
     {
         return GalleryPage.GetMediaObjectHtml(Factory.LoadMediaObjectInstance(mediaObjectId), displayType, true);
     }
     catch (Exception ex)
     {
         AppErrorController.LogError(ex);
         throw;
     }
 }
Ejemplo n.º 31
0
        /// <overloads>Adds an object to the ZIP archive.</overloads>
        /// <summary>
        /// Adds the file associated with the <paramref name="mediaObject"/> to the ZIP archive.
        /// </summary>
        /// <param name="zos">The ZipOutputStream (ZIP archive) the media object file is to be added to.</param>
        /// <param name="mediaObject">The media object to be added to the ZIP archive.</param>
        /// <param name="mediaSize">Size of the media file to add to the ZIP archive.</param>
        /// <param name="basePath">The full path to the directory containing the highest-level media file to be added
        /// to the ZIP archive. Must include trailing slash. Ex: C:\Inetpub\wwwroot\galleryserverpro\mediaobjects\Summer 2005\sunsets\</param>
        /// <param name="applyWatermark">Indicates whether to apply a watermark to images as they are added to the archive.
        /// Applies only when <paramref name="mediaObject"/> is an <see cref="Image"/>.</param>
        private static void AddFileZipEntry(ZipOutputStream zos, IGalleryObject mediaObject, DisplayObjectType mediaSize, string basePath, bool applyWatermark)
        {
            // Get the path to the file we'll be adding to the zip file.
            string filePath = GetMediaFilePath(mediaObject, mediaSize);

            // Get the name we want to use for the file we are adding to the zip file.
            string fileNameForZip = GetMediaFileNameForZip(mediaObject, mediaSize);

            if ((!String.IsNullOrEmpty(filePath)) && (!String.IsNullOrEmpty(fileNameForZip)))
            {
                AddFileZipEntry(zos, filePath, fileNameForZip, basePath, (mediaObject is Image), applyWatermark, mediaObject.GalleryId);
            }
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Create a new display object instance with the specified properties. No data is retrieved from the
        /// data store. A lazy load is used to inflate the object when necessary
        /// </summary>
        /// <param name="parent">The media object to which this display object applies. This will typically be
        /// an Album object.</param>
        /// <param name="sourceMediaObjectId">The ID of the media object to use as the source for setting this
        /// object's properties.</param>
        /// <param name="displayType">The display object type of the source media object to use to set this object's
        /// properties. For example, if displayType=Thumbnail, then use the properties of the source media
        /// object's thumbnail object to assign to this display object's properties.</param>
        /// <returns>Create a new display object instance with the specified properties.</returns>
        /// <remarks>This overload of CreateInstance() is typically used when instantiating albums.</remarks>
        public static IDisplayObject CreateInstance(IGalleryObject parent, int sourceMediaObjectId, DisplayObjectType displayType)
        {
            IDisplayObject newDisObject = CreateInstance(parent, string.Empty, int.MinValue, int.MinValue, displayType, new NullObjects.NullDisplayObjectCreator());

            newDisObject.MediaObjectId = sourceMediaObjectId;

            return(newDisObject);
        }
Ejemplo n.º 33
0
		public MediaObjectWebEntity GetMediaObjectHtml(int mediaObjectId, DisplayObjectType displayType)
		{
			return GalleryPage.GetMediaObjectHtml(Factory.LoadMediaObjectInstance(mediaObjectId), displayType, true);
		}
Ejemplo n.º 34
0
		/// <summary>
		/// Creates a ZIP archive, returned as a <see cref="ZipOutputStream"/>, containing the specified <paramref name="albumIds">albums
		/// </paramref> and <paramref name="mediaObjectIds">media objects</paramref>. Only media objects associated with a 
		/// physical file are included (in other words, external media objects are excluded). The archive is created in memory
		/// and is not stored on disk.
		/// </summary>
		/// <param name="parentAlbumId">The ID of the album containing the <paramref name="albumIds"/> and <paramref name="mediaObjectIds"/>.
		/// When <paramref name="albumIds"/> or <paramref name="mediaObjectIds"/> belong to more than one album, such as when a user is 
		/// downloading multiple albums contained within a virtual album, specify <see cref="Int32.MinValue"/>.</param>
		/// <param name="albumIds">The ID's of the albums to add to the ZIP archive. It's child albums and media objects are recursively 
		/// added. Each album must exist within the parent album, but does not have to be an immediate child (it can be a grandchild, etc).</param>
		/// <param name="mediaObjectIds">The ID's of the media objects to add to the archive. Each media object must exist within the parent album,
		/// but does not have to be an immediate child (it can be a grandchild, etc).</param>
		/// <param name="imageSize">Size of the image to add to the ZIP archive. This parameter applies only to <see cref="Image"/> 
		/// media objects.</param>
		/// <returns>Returns a <see cref="MemoryStream"/> of a ZIP archive that contains the specified albums and media objects.</returns>
		public Stream CreateZipStream(int parentAlbumId, List<int> albumIds, List<int> mediaObjectIds, DisplayObjectType imageSize)
		{
			string currentItemBasePath;
			string basePath = null;
			bool applyWatermark = true; // Will be overwritten later
			try
			{
				// Get the path to the parent album. This will fail when parentAlbumId does not refer to a valid album.
				basePath = String.Concat(Factory.LoadAlbumInstance(parentAlbumId, false).FullPhysicalPathOnDisk, Path.DirectorySeparatorChar);
				
				applyWatermark = this.DetermineIfWatermarkIsToBeApplied(parentAlbumId);
			}
			catch (ErrorHandler.CustomExceptions.InvalidAlbumException) { /* Ignore for now; we'll check basePath later */ }

			MemoryStream ms = new MemoryStream();
			ZipOutputStream zos = new ZipOutputStream(ms);

			zos.SetLevel(ZIP_COMPRESSION_LEVEL);

			if (albumIds != null)
			{
				foreach (int albumId in albumIds)
				{
					IAlbum album = Factory.LoadAlbumInstance(albumId, true);

					if (String.IsNullOrEmpty(basePath))
					{
						// The base path wasn't assigned because albumParentId does not refer to a valid album. Instead we will use the path
						// of the current album's parent.
						currentItemBasePath = String.Concat(album.Parent.FullPhysicalPathOnDisk, Path.DirectorySeparatorChar);

						applyWatermark = DetermineIfWatermarkIsToBeApplied(albumId);
					}
					else
					{
						currentItemBasePath = basePath;
					}

					AddZipEntry(zos, album, imageSize, currentItemBasePath, applyWatermark);
				}
			}

			if (mediaObjectIds != null)
			{
				foreach (int mediaObjectId in mediaObjectIds)
				{
					IGalleryObject mediaObject = Factory.LoadMediaObjectInstance(mediaObjectId);

					if (String.IsNullOrEmpty(basePath))
					{
						// The base path wasn't assigned because albumParentId does not refer to a valid album. Instead we will use the path
						// of the current media object's album.
						currentItemBasePath = String.Concat(mediaObject.Parent.FullPhysicalPathOnDisk, Path.DirectorySeparatorChar);

						applyWatermark = DetermineIfWatermarkIsToBeApplied(mediaObject.Parent.Id);
					}
					else
					{
						currentItemBasePath = basePath;
					}

					AddFileZipEntry(zos, mediaObject, imageSize, currentItemBasePath, applyWatermark);
				}
			}

			zos.Finish();

			return ms;
		}
Ejemplo n.º 35
0
		/// <summary>
		/// Adds the media objects in the <paramref name="album"/> to the ZIP archive. Only media objects associated with a 
		/// physical file are added (that is, external media objects are excluded).
		/// </summary>
		/// <param name="zos">The ZipOutputStream (ZIP archive) the media object file is to be added to.</param>
		/// <param name="album">The album to be added to the ZIP archive.</param>
		/// <param name="imageSize">Size of the image to add to the ZIP archive. This parameter applies only to <see cref="Image"/> 
		/// media objects.</param>
		/// <param name="basePath">The full path to the directory containing the highest-level media file to be added
		/// to the ZIP archive. Must include trailing slash. Ex: C:\Inetpub\wwwroot\galleryserverpro\mediaobjects\Summer 2005\sunsets\</param>
		/// <param name="applyWatermark">Indicates whether to apply a watermark to images as they are added to the archive.
		/// Applies only for media objects in the <see cref="album"/> that are an <see cref="Image"/>.</param>
		private void AddZipEntry(ZipOutputStream zos, IAlbum album, DisplayObjectType imageSize, string basePath, bool applyWatermark)
		{
			foreach (IAlbum childAlbum in album.GetChildGalleryObjects(GalleryObjectType.Album, false, !this._isAuthenticated))
			{
				AddZipEntry(zos, childAlbum, imageSize, basePath, applyWatermark);
			}

			foreach (IGalleryObject mediaObject in album.GetChildGalleryObjects(GalleryObjectType.MediaObject, false, !this._isAuthenticated))
			{
				AddFileZipEntry(zos, mediaObject, imageSize, basePath, applyWatermark);
			}
		}
Ejemplo n.º 36
0
        /// <summary>
        /// Gets the name of the requested media file, without the prefix (e.g. "zThumb_", "zOpt_").
        /// If a media object does not have a physical file (for example, external media objects), then return <see cref="String.Empty"/>.
        /// Ex: C:\Inetpub\wwwroot\galleryserverpro\mediaobjects\Summer 2005\sunsets\desert sunsets\sonorandesert.jpg
        /// </summary>
        /// <param name="mediaObject">The media object for which to return a path to the media file.</param>
        /// <param name="mediaSize">Size of the media file to return.</param>
        /// <returns>Returns the full path to the media object file.</returns>
        private static string GetMediaFileNameForZip(IGalleryObject mediaObject, DisplayObjectType mediaSize)
        {
            string fileName = String.Empty;
            IGallerySettings gallerySetting = Factory.LoadGallerySetting(mediaObject.GalleryId);

            switch (mediaSize)
            {
                case DisplayObjectType.Thumbnail:
                    fileName = mediaObject.Thumbnail.FileName.Replace(gallerySetting.ThumbnailFileNamePrefix, String.Empty);
                    break;
                case DisplayObjectType.Optimized:
                    fileName = mediaObject.Optimized.FileName.Replace(gallerySetting.OptimizedFileNamePrefix, String.Empty);
                    break;
                case DisplayObjectType.Original:
                    fileName = mediaObject.Original.FileNamePhysicalPath;
                    break;
            }

            if (String.IsNullOrEmpty(fileName))
            {
                fileName = mediaObject.Original.FileName;
            }

            return fileName;
        }
Ejemplo n.º 37
0
        /// <summary>
        /// Get the URL to the thumbnail, optimized, or original media object. Example:
        /// /dev/gs/handler/getmediaobject.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 GetMediaObjectUrl(IGalleryObject galleryObject, DisplayObjectType displayType)
        {
            if (galleryObject == null)
                throw new ArgumentNullException("galleryObject");

            return MediaObjectHtmlBuilder.GenerateUrl(galleryObject.GalleryId, galleryObject.Id, displayType);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MediaObjectHtmlBuilderOptions"/> class.
 /// </summary>
 /// <param name="galleryObject">The gallery object. May be null. If null, <see cref="MediaObjectHtmlBuilderOptions.GalleryObject" />
 /// must be assigned before passing this instance to the <see cref="MediaObjectHtmlBuilder" /> constructor.</param>
 /// <param name="displayType">The display type. Optional. If not assigned or set to <see cref="DisplayObjectType.Unknown" />,
 /// <see cref="MediaObjectHtmlBuilderOptions.DisplayType" /> must be assigned before passing this instance to the 
 /// <see cref="MediaObjectHtmlBuilder" /> constructor.</param>
 /// <param name="browsers">The browser IDs for current request.</param>
 /// <param name="destinationPageUrl">The URL, relative to the website root and optionally including any query string parameters,
 /// to the page any generated URLs should point to. Examples: "/dev/gs/gallery.aspx", 
 /// "/dev/gs/gallery.aspx?g=admin_email&amp;aid=2389"</param>
 /// <param name="isAuthenticated">If set to <c>true</c> the current user is authenticated.</param>
 /// <param name="hostUrl">The URI scheme, DNS host name or IP address, and port number for the current application. 
 /// Examples: "http://www.site.com", "http://localhost", "http://127.0.0.1", "http://godzilla"</param>
 /// <param name="appRoot">The path, relative to the web site root, to the current web application.
 /// Example: "/dev/gallery".</param>
 /// <param name="galleryRoot">The path, relative to the web site root, to the directory containing the Gallery Server Pro user 
 /// controls and other resources. Example: "/dev/gallery/gs".</param>
 public MediaObjectHtmlBuilderOptions(IGalleryObject galleryObject, DisplayObjectType displayType, Array browsers, string destinationPageUrl, bool isAuthenticated, string hostUrl, string appRoot, string galleryRoot)
 {
     GalleryObject = galleryObject;
     DisplayType = displayType;
     Browsers = browsers;
     DestinationPageUrl = destinationPageUrl;
     IsAuthenticated = isAuthenticated;
     HostUrl = hostUrl;
     AppRoot = appRoot;
     GalleryRoot = galleryRoot;
 }
        private static string GetMediaObjectUrl(int galleryId, int mediaObjectId, DisplayObjectType displayType)
        {
            //string queryString = String.Format(CultureInfo.InvariantCulture, "moid={1}&aid={2}&mo={3}&mtc={4}&dt={5}&isp={6}", galleryId, mediaObjectId, albumId, Uri.EscapeDataString(mediaObjectPhysicalPath), (int)mimeType.TypeCategory, (int)displayType, isPrivate.ToString());
            string queryString = String.Format(CultureInfo.InvariantCulture, "moid={0}&dt={1}&g={2}", mediaObjectId, (int)displayType, galleryId);

            // If necessary, encrypt, then URL encode the query string.
            if (AppSetting.Instance.EncryptMediaObjectUrlOnClient)
                queryString = Utils.UrlEncode(HelperFunctions.Encrypt(queryString));

            return string.Concat(Utils.GalleryRoot, "/handler/getmediaobject.ashx?", queryString);
        }
 /// <summary>
 /// Generate the URL to the media object. For example, for images this url can be assigned to the src attribute of an img tag.
 /// (ex: /galleryserverpro/handler/getmediaobject.ashx?moid=34&amp;dt=1&amp;g=1)
 /// The query string parameter will be encrypted if that option is enabled.
 /// </summary>
 /// <param name="galleryId">The gallery ID.</param>
 /// <param name="mediaObjectId">The unique identifier for the media object.</param>
 /// <param name="displayType">The type of the display object.</param>
 /// <returns>Gets the URL to the media object.</returns>
 public static string GenerateUrl(int galleryId, int mediaObjectId, DisplayObjectType displayType)
 {
     return GetMediaObjectUrl(galleryId, mediaObjectId, displayType);
 }
        public ActionResult RotateFlip(GalleryItem[] galleryItems, MediaAssetRotateFlip rotateFlip, DisplayObjectType viewSize)
        {
            try
            {
                return(GalleryObjectController.RotateFlip(galleryItems, rotateFlip, viewSize));
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }
Ejemplo n.º 42
0
        /// <summary>
        /// Extract information from the query string and assign to our class level variables. Return false if
        /// something goes wrong and the variables cannot be set. This will happen when the query string is in
        /// an unexpected format.
        /// </summary>
        /// <param name="queryString">The query string for the current request. Can be populated with
        /// HttpContext.Request.Url.Query. Must start with a question mark (?).</param>
        /// <returns>Returns true if all relevant variables were assigned from the query string; returns false
        /// if there was a problem.</returns>
        private bool ExtractQueryStringParms(string queryString)
        {
            if (String.IsNullOrEmpty(queryString))
            {
                return(false);
            }

            queryString = queryString.Remove(0, 1);             // Strip off the ?

            bool filepathIsEncrypted = AppSetting.Instance.EncryptMediaObjectUrlOnClient;

            if (filepathIsEncrypted)
            {
                // Decode, then decrypt the query string. Note that we must replace spaces with a '+'. This is required when the the URL is
                // used in javascript to create the Silverlight media player. Apparently, Silverlight or the media player javascript decodes
                // the query string when it requests the URL, so that means any instances of '%2b' are decoded into '+' before it gets here.
                // Ideally, we wouldn't even call UrlDecode in this case, but we don't have a way of knowing that it has already been decoded.
                // So we decode anyway, which doesn't cause any harm *except* it converts '+' to a space, so we need to convert them back.
                queryString = HelperFunctions.Decrypt(HttpUtility.UrlDecode(queryString).Replace(" ", "+"));
            }

            //moid={0}&dt={1}g={2}
            foreach (string nameValuePair in queryString.Split(new[] { '&' }))
            {
                string[] nameOrValue = nameValuePair.Split(new[] { '=' });
                switch (nameOrValue[0])
                {
                case "g":
                {
                    int gid;
                    if (Int32.TryParse(nameOrValue[1], out gid))
                    {
                        _galleryIdInQueryString = gid;
                    }
                    else
                    {
                        return(false);
                    }
                    break;
                }

                case "moid":
                {
                    int moid;
                    if (Int32.TryParse(nameOrValue[1], out moid))
                    {
                        _mediaObjectId = moid;
                    }
                    else
                    {
                        return(false);
                    }
                    break;
                }

                case "dt":
                {
                    int dtInt;
                    if (Int32.TryParse(nameOrValue[1], out dtInt))
                    {
                        if (DisplayObjectTypeEnumHelper.IsValidDisplayObjectType((DisplayObjectType)dtInt))
                        {
                            _displayType = (DisplayObjectType)dtInt; break;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }

                case "sa":
                {
                    _sendAsAttachment = ((nameOrValue[1].Equals("1", StringComparison.Ordinal)) || (nameOrValue[1].Equals("TRUE", StringComparison.OrdinalIgnoreCase)));
                    break;
                }

                default: return(false);                        // Unexpected query string parm. Return false so execution is aborted.
                }
            }

            ValidateDisplayType();

            return(true);
        }
Ejemplo n.º 43
0
		/// <summary>
		/// Create a new display object instance with the specified properties. No data is retrieved from the
		/// data store. A lazy load is used to inflate the object when necessary
		/// </summary>
		/// <param name="parent">The media object to which this display object applies.</param>
		/// <param name="fileName">The name of the file representing this object. Example: sonorandesert.jpg</param>
		/// <param name="width">The width of this object, in pixels.</param>
		/// <param name="height">The height of this object, in pixels.</param>
		/// <param name="displayType">The type of the display object.</param>
		/// <param name="displayObjectCreator">The object responsible for generating the file this display object points to.</param>
		/// <returns>Create a new display object instance with the specified properties.</returns>
		public static IDisplayObject CreateInstance(IGalleryObject parent, string fileName, int width, int height, DisplayObjectType displayType, IDisplayObjectCreator displayObjectCreator)
		{
			return new DisplayObject(width, height, fileName, parent, displayType, displayObjectCreator);
		}
Ejemplo n.º 44
0
        /// <summary>
        /// Get information for the specified media object, including its previous and next media object.
        /// </summary>
        /// <param name="mediaObject">The media object.</param>
        /// <param name="displayType">The type of display object to receive (thumbnail, optimized, original).</param>
        /// <param name="isCallBack">Indicates whether the current invocation is caused by an AJAX callback.</param>
        /// <returns>
        /// Returns an instance of MediaObjectWebEntity containing information for the specified media object,
        /// including its previous and next media object.
        /// </returns>
        internal static MediaObjectWebEntity GetMediaObjectHtml(IGalleryObject mediaObject, DisplayObjectType displayType, bool isCallBack)
        {
            // Get the information about the specified media object, its previous one, next one, and the next one in a slide show.
            Array browsers = Utils.GetBrowserIdsForCurrentRequest();

            if ((displayType == DisplayObjectType.Original) && (!Utils.IsUserAuthorized(SecurityActions.ViewOriginalImage, RoleController.GetGalleryServerRolesForUser(), mediaObject.Parent.Id, mediaObject.GalleryId, ((IAlbum)mediaObject.Parent).IsPrivate)))
            {
                displayType = DisplayObjectType.Optimized;
            }

            bool excludePrivateObjects = !Utils.IsAuthenticated;

            MediaObjectWebEntity mo = new MediaObjectWebEntity();

            #region Step 1: Process current media object

            if (mediaObject.Id > 0)
            {
                // This section is enclosed in the above if statement to force all declared variables within it to be local so they are
                // not accidentally re-used in steps 2 or 3. In reality, mediaObject.Id should ALWAYS be greater than 0.
                IDisplayObject displayObject = GalleryObjectController.GetDisplayObject(mediaObject, displayType);

                string htmlOutput = String.Empty;
                string scriptOutput = String.Empty;
                if (!String.IsNullOrEmpty(mediaObject.Original.ExternalHtmlSource))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(mediaObject.Original.ExternalHtmlSource, mediaObject.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                }
                else if ((displayObject.Width > 0) && (displayObject.Height > 0))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(mediaObject.Id, mediaObject.Parent.Id, displayObject.MimeType, displayObject.FileNamePhysicalPath, displayObject.Width, displayObject.Height, mediaObject.Title, browsers, displayType, mediaObject.IsPrivate, mediaObject.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                    scriptOutput = moBuilder.GenerateScript();
                }

                if (String.IsNullOrEmpty(htmlOutput))
                {
                    // We'll get here when the user is trying to view a media object that cannot be displayed in the browser or the
                    // config file does not have a definition for this MIME type. Default to a standard message noting that the user
                    // can download the object via one of the toolbar commands.
                    htmlOutput = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_msgfriendly'>{0}</p>", Resources.GalleryServerPro.UC_MediaObjectView_Browser_Cannot_Display_Media_Object_Text);
                }

                // Get the siblings of this media object and the index that specifies its position within its siblings.

                //TODO: This technique for identifying the index is very expensive when there are a lot of objects in the album.
                IGalleryObjectCollection siblings = ((IAlbum)mediaObject.Parent).GetChildGalleryObjects(GalleryObjectType.MediaObject, true, excludePrivateObjects);
                int mediaObjectIndex = siblings.IndexOf(mediaObject);

                // Build up the entity object we'll be sending to the client.
                bool moIsImage = (mediaObject is GalleryServerPro.Business.Image);
                bool moIsExternalObject = (mediaObject is GalleryServerPro.Business.ExternalMediaObject);
                mo.Id = mediaObject.Id;
                mo.Index = mediaObjectIndex;
                mo.NumObjectsInAlbum = siblings.Count;
                mo.Title = mediaObject.Title;
                mo.PrevId = GetPreviousMediaObjectId(mediaObjectIndex, siblings);
                mo.NextId = GetNextMediaObjectId(mediaObjectIndex, siblings);
                mo.NextSSId = GetNextMediaObjectIdForSlideshow(mediaObjectIndex, siblings);
                mo.HtmlOutput = htmlOutput;
                mo.ScriptOutput = scriptOutput;
                mo.Width = displayObject.Width;
                mo.Height = displayObject.Height;
                mo.HiResAvailable = (moIsImage && (!String.IsNullOrEmpty(mediaObject.Optimized.FileName)) && (mediaObject.Original.FileName != mediaObject.Optimized.FileName));
                mo.IsDownloadable = !moIsExternalObject;
            }

            #endregion

            #region Step 2: Process previous media object

            if (mo.PrevId > 0)
            {
                IGalleryObject prevMO = Factory.LoadMediaObjectInstance(mo.PrevId);

                IDisplayObject displayObject = GalleryObjectController.GetDisplayObject(prevMO, displayType);

                string htmlOutput = String.Empty;
                string scriptOutput = String.Empty;
                if (!String.IsNullOrEmpty(prevMO.Original.ExternalHtmlSource))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(prevMO.Original.ExternalHtmlSource, prevMO.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                }
                else if ((displayObject.Width > 0) && (displayObject.Height > 0))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(prevMO.Id, prevMO.Parent.Id, displayObject.MimeType, displayObject.FileNamePhysicalPath, displayObject.Width, displayObject.Height, prevMO.Title, browsers, displayType, prevMO.IsPrivate, prevMO.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                    scriptOutput = moBuilder.GenerateScript();
                }

                if (String.IsNullOrEmpty(htmlOutput))
                {
                    // We'll get here when the user is trying to view a media object that cannot be displayed in the browser or the
                    // config file does not have a definition for this MIME type. Default to a standard message noting that the user
                    // can download the object via one of the toolbar commands.
                    htmlOutput = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_msgfriendly'>{0}</p>", Resources.GalleryServerPro.UC_MediaObjectView_Browser_Cannot_Display_Media_Object_Text);
                }

                // Build up the entity object we'll be sending to the client.
                bool prevMoIsImage = (prevMO is GalleryServerPro.Business.Image);
                bool prevMoIsExternalObject = (prevMO is GalleryServerPro.Business.ExternalMediaObject);
                mo.PrevTitle = prevMO.Title;
                mo.PrevHtmlOutput = htmlOutput;
                mo.PrevScriptOutput = scriptOutput;
                mo.PrevWidth = displayObject.Width;
                mo.PrevHeight = displayObject.Height;
                mo.PrevHiResAvailable = (prevMoIsImage && (!String.IsNullOrEmpty(prevMO.Optimized.FileName)) && (prevMO.Original.FileName != prevMO.Optimized.FileName));
                mo.PrevIsDownloadable = !prevMoIsExternalObject;
            }

            #endregion

            #region Step 3: Process next media object

            if (mo.NextId > 0)
            {
                IGalleryObject nextMO = Factory.LoadMediaObjectInstance(mo.NextId);

                IDisplayObject displayObject = GalleryObjectController.GetDisplayObject(nextMO, displayType);

                string htmlOutput = String.Empty;
                string scriptOutput = String.Empty;
                if (!String.IsNullOrEmpty(nextMO.Original.ExternalHtmlSource))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(nextMO.Original.ExternalHtmlSource, nextMO.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                }
                else if ((displayObject.Width > 0) && (displayObject.Height > 0))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(nextMO.Id, nextMO.Parent.Id, displayObject.MimeType, displayObject.FileNamePhysicalPath, displayObject.Width, displayObject.Height, nextMO.Title, browsers, displayType, nextMO.IsPrivate, nextMO.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                    scriptOutput = moBuilder.GenerateScript();
                }

                if (String.IsNullOrEmpty(htmlOutput))
                {
                    // We'll get here when the user is trying to view a media object that cannot be displayed in the browser or the
                    // config file does not have a definition for this MIME type. Default to a standard message noting that the user
                    // can download the object via one of the toolbar commands.
                    htmlOutput = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_msgfriendly'>{0}</p>", Resources.GalleryServerPro.UC_MediaObjectView_Browser_Cannot_Display_Media_Object_Text);
                }

                // Build up the entity object we'll be sending to the client.
                bool nextMoIsImage = (nextMO is GalleryServerPro.Business.Image);
                bool nextMoIsExternalObject = (nextMO is GalleryServerPro.Business.ExternalMediaObject);
                mo.NextTitle = nextMO.Title;
                mo.NextHtmlOutput = htmlOutput;
                mo.NextScriptOutput = scriptOutput;
                mo.NextWidth = displayObject.Width;
                mo.NextHeight = displayObject.Height;
                mo.NextHiResAvailable = (nextMoIsImage && (!String.IsNullOrEmpty(nextMO.Optimized.FileName)) && (nextMO.Original.FileName != nextMO.Optimized.FileName));
                mo.NextIsDownloadable = !nextMoIsExternalObject;
            }

            #endregion

            #region Step 4: Process next slide show media object

            if (mo.NextSSId > 0)
            {
                IGalleryObject nextSSMO = Factory.LoadMediaObjectInstance(mo.NextSSId);

                IDisplayObject displayObject = GalleryObjectController.GetDisplayObject(nextSSMO, displayType);

                string htmlOutput = String.Empty;
                string scriptOutput = String.Empty;
                string url = String.Empty;
                if (!String.IsNullOrEmpty(nextSSMO.Original.ExternalHtmlSource))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(nextSSMO.Original.ExternalHtmlSource, nextSSMO.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                }
                else if ((displayObject.Width > 0) && (displayObject.Height > 0))
                {
                    IMediaObjectHtmlBuilder moBuilder = new MediaObjectHtmlBuilder(nextSSMO.Id, nextSSMO.Parent.Id, displayObject.MimeType, displayObject.FileNamePhysicalPath, displayObject.Width, displayObject.Height, nextSSMO.Title, browsers, displayType, nextSSMO.IsPrivate, nextSSMO.GalleryId);
                    htmlOutput = moBuilder.GenerateHtml();
                    scriptOutput = moBuilder.GenerateScript();
                    url = moBuilder.GenerateUrl();
                }

                if (String.IsNullOrEmpty(htmlOutput))
                {
                    // We'll get here when the user is trying to view a media object that cannot be displayed in the browser or the
                    // config file does not have a definition for this MIME type. Default to a standard message noting that the user
                    // can download the object via one of the toolbar commands.
                    htmlOutput = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_msgfriendly'>{0}</p>", Resources.GalleryServerPro.UC_MediaObjectView_Browser_Cannot_Display_Media_Object_Text);
                }

                // Get the siblings of this media object and the index that specifies its position within its siblings.

                //TODO: This technique for identifying the index is very expensive when there are a lot of objects in the album.
                IGalleryObjectCollection siblings = ((IAlbum)nextSSMO.Parent).GetChildGalleryObjects(GalleryObjectType.MediaObject, true, excludePrivateObjects);
                int mediaObjectIndex = siblings.IndexOf(nextSSMO);

                // Build up the entity object we'll be sending to the client.
                bool nextSSMoIsImage = (nextSSMO is GalleryServerPro.Business.Image);
                mo.NextSSIndex = mediaObjectIndex;
                mo.NextSSTitle = nextSSMO.Title;
                mo.NextSSUrl = url;
                mo.NextSSHtmlOutput = htmlOutput;
                mo.NextSSScriptOutput = scriptOutput;
                mo.NextSSWidth = displayObject.Width;
                mo.NextSSHeight = displayObject.Height;
                mo.NextSSHiResAvailable = (nextSSMoIsImage && (!String.IsNullOrEmpty(nextSSMO.Optimized.FileName)) && (nextSSMO.Original.FileName != nextSSMO.Optimized.FileName));
                mo.NextSSIsDownloadable = true; // Slide show objects are always locally stored images and are therefore always downloadable
            }

            #endregion

            #region Step 5: Update Previous Uri variable

            if (HttpContext.Current.Session != null)
            {
                Uri backURL = Utils.PreviousUri;
                if (isCallBack && (backURL != null))
                {
                    // We are in a callback. Even though the page hasn't changed, the user is probably viewing a different media object,
                    // so update the moid query string parameter so that the referring url points to the current media object.
                    backURL = UpdateUriQueryString(backURL, "moid", mediaObject.Id.ToString(CultureInfo.InvariantCulture));
                }
                else
                {
                    backURL = Utils.GetCurrentPageUri();
                }

                Utils.PreviousUri = backURL;
            }

            #endregion

            return mo;
        }
Ejemplo n.º 45
0
		/// <summary>
		/// Create a new display object instance with the specified properties. No data is retrieved from the
		/// data store. A lazy load is used to inflate the object when necessary
		/// </summary>
		/// <param name="parent">The media object to which this display object applies. This will typically be
		/// an Album object.</param>
		/// <param name="sourceMediaObjectId">The ID of the media object to use as the source for setting this 
		/// object's properties.</param>
		/// <param name="displayType">The display object type of the source media object to use to set this object's
		/// properties. For example, if displayType=Thumbnail, then use the properties of the source media
		/// object's thumbnail object to assign to this display object's properties.</param>
		/// <returns>Create a new display object instance with the specified properties.</returns>
		/// <remarks>This overload of CreateInstance() is typically used when instantiating albums.</remarks>
		public static IDisplayObject CreateInstance(IGalleryObject parent, int sourceMediaObjectId, DisplayObjectType displayType)
		{
			IDisplayObject newDisObject = CreateInstance(parent, string.Empty, int.MinValue, int.MinValue, displayType, new NullObjects.NullDisplayObjectCreator());

			newDisObject.MediaObjectId = sourceMediaObjectId;
				
			return newDisObject;
		}
 /// <summary>
 /// Gets an instance of <see cref="MediaObjectHtmlBuilderOptions" /> that can be supplied to the 
 /// <see cref="MediaObjectHtmlBuilder" /> constructor. This method requires access to <see cref="HttpContext.Current" />.
 /// </summary>
 /// <param name="galleryObject">The gallery object. May be null. If null, <see cref="MediaObjectHtmlBuilderOptions.GalleryObject" />
 /// must be assigned before passing this instance to the <see cref="MediaObjectHtmlBuilder" /> constructor.</param>
 /// <param name="displayType">The display type. Optional. If not assigned or set to <see cref="DisplayObjectType.Unknown" />,
 /// <see cref="MediaObjectHtmlBuilderOptions.DisplayType" /> must be assigned before passing this instance to the 
 /// <see cref="MediaObjectHtmlBuilder" /> constructor.</param>
 /// <returns>An instance of <see cref="MediaObjectHtmlBuilderOptions" />.</returns>
 public static MediaObjectHtmlBuilderOptions GetMediaObjectHtmlBuilderOptions(IGalleryObject galleryObject, DisplayObjectType displayType = DisplayObjectType.Unknown)
 {
     return new MediaObjectHtmlBuilderOptions(galleryObject, displayType, Utils.GetBrowserIdsForCurrentRequest(), Utils.GetCurrentPageUrl(), Utils.IsAuthenticated, Utils.GetHostUrl(), Utils.AppRoot, Utils.GalleryRoot);
 }
Ejemplo n.º 47
0
		/// <summary>
		/// Gets the full path to the media object file. If <paramref name="mediaObject"/>
		/// is an <see cref="Image"/>, then return the thumbnail, compressed, or original file as specified in <paramref name="imageSize"/>.
		/// If a media object does not have a physical file (for example, external media objects), then return <see cref="String.Empty"/>.
		/// Ex: C:\Inetpub\wwwroot\galleryserverpro\mediaobjects\Summer 2005\sunsets\desert sunsets\sonorandesert.jpg
		/// </summary>
		/// <param name="mediaObject">The media object for which to return a path to the media file.</param>
		/// <param name="imageSize">Size of the image to return. This parameter applies only to <see cref="Image"/> media objects.</param>
		/// <returns>Returns the full path to the media object file.</returns>
		private static string GetMediaFilePath(IGalleryObject mediaObject, DisplayObjectType imageSize)
		{
			string filePath = String.Empty;

			if (mediaObject is Image)
			{
				switch (imageSize)
				{
					case DisplayObjectType.Thumbnail:
						filePath = mediaObject.Thumbnail.FileNamePhysicalPath;
						break;
					case DisplayObjectType.Optimized:
						filePath = mediaObject.Optimized.FileNamePhysicalPath;
						break;
					case DisplayObjectType.Original:
						filePath = mediaObject.Original.FileNamePhysicalPath;
						break;
				}
			}

			if (String.IsNullOrEmpty(filePath))
			{
				filePath = mediaObject.Original.FileNamePhysicalPath;
			}

			return filePath;
		}
Ejemplo n.º 48
0
        /// <summary>
        /// Creates a ZIP archive, returned as a <see cref="ZipOutputStream"/>, containing the specified <paramref name="albumIds">albums
        /// </paramref> and <paramref name="mediaObjectIds">media objects</paramref>. Only media objects associated with a
        /// physical file are included (in other words, external media objects are excluded). The archive is created in memory
        /// and is not stored on disk.
        /// </summary>
        /// <param name="parentAlbumId">The ID of the album containing the <paramref name="albumIds"/> and <paramref name="mediaObjectIds"/>.
        /// When <paramref name="albumIds"/> or <paramref name="mediaObjectIds"/> belong to more than one album, such as when a user is
        /// downloading multiple albums contained within a virtual album, specify <see cref="Int32.MinValue"/>.</param>
        /// <param name="albumIds">The ID's of the albums to add to the ZIP archive. It's child albums and media objects are recursively
        /// added. Each album must exist within the parent album, but does not have to be an immediate child (it can be a grandchild, etc).</param>
        /// <param name="mediaObjectIds">The ID's of the media objects to add to the archive. Each media object must exist within the parent album,
        /// but does not have to be an immediate child (it can be a grandchild, etc).</param>
        /// <param name="imageSize">Size of the image to add to the ZIP archive. This parameter applies only to <see cref="Image"/>
        /// media objects.</param>
        /// <returns>Returns a <see cref="MemoryStream"/> of a ZIP archive that contains the specified albums and media objects.</returns>
        public Stream CreateZipStream(int parentAlbumId, List <int> albumIds, List <int> mediaObjectIds, DisplayObjectType imageSize)
        {
            string currentItemBasePath;
            string basePath       = null;
            bool   applyWatermark = true;           // Will be overwritten later

            try
            {
                // Get the path to the parent album. This will fail when parentAlbumId does not refer to a valid album.
                IAlbum album = Factory.LoadAlbumInstance(parentAlbumId, false);

                basePath = String.Concat(album.FullPhysicalPathOnDisk, Path.DirectorySeparatorChar);

                applyWatermark = this.DetermineIfWatermarkIsToBeApplied(album);
            }
            catch (ErrorHandler.CustomExceptions.InvalidAlbumException) { /* Ignore for now; we'll check basePath later */ }

            MemoryStream    ms  = new MemoryStream();
            ZipOutputStream zos = new ZipOutputStream(ms);

            zos.SetLevel(ZIP_COMPRESSION_LEVEL);

            if (albumIds != null)
            {
                foreach (int albumId in albumIds)
                {
                    IAlbum album;
                    try
                    {
                        album = Factory.LoadAlbumInstance(albumId, true);
                    }
                    catch (ErrorHandler.CustomExceptions.InvalidAlbumException ex)
                    {
                        ErrorHandler.Error.Record(ex);
                        continue;                         // Gallery object may have been deleted by someone else, so just skip it.
                    }

                    if (String.IsNullOrEmpty(basePath))
                    {
                        // The base path wasn't assigned because albumParentId does not refer to a valid album. Instead we will use the path
                        // of the current album's parent.
                        currentItemBasePath = String.Concat(album.Parent.FullPhysicalPathOnDisk, Path.DirectorySeparatorChar);

                        applyWatermark = DetermineIfWatermarkIsToBeApplied(album);
                    }
                    else
                    {
                        currentItemBasePath = basePath;
                    }

                    AddZipEntry(zos, album, imageSize, currentItemBasePath, applyWatermark);
                }
            }

            if (mediaObjectIds != null)
            {
                foreach (int mediaObjectId in mediaObjectIds)
                {
                    IGalleryObject mediaObject;
                    try
                    {
                        mediaObject = Factory.LoadMediaObjectInstance(mediaObjectId);
                    }
                    catch (ArgumentException ex)
                    {
                        ErrorHandler.Error.Record(ex);
                        continue;                         // Gallery object may have been deleted by someone else, so just skip it.
                    }
                    catch (InvalidMediaObjectException ex)
                    {
                        ErrorHandler.Error.Record(ex);
                        continue;                         // Gallery object may have been deleted by someone else, so just skip it.
                    }

                    if (String.IsNullOrEmpty(basePath))
                    {
                        // The base path wasn't assigned because albumParentId does not refer to a valid album. Instead we will use the path
                        // of the current media object's album.
                        currentItemBasePath = String.Concat(mediaObject.Parent.FullPhysicalPathOnDisk, Path.DirectorySeparatorChar);

                        applyWatermark = DetermineIfWatermarkIsToBeApplied((IAlbum)mediaObject.Parent);
                    }
                    else
                    {
                        currentItemBasePath = basePath;
                    }

                    AddFileZipEntry(zos, mediaObject, imageSize, currentItemBasePath, applyWatermark);
                }
            }

            zos.Finish();

            return(ms);
        }
Ejemplo n.º 49
0
		/// <summary>
		/// Adds the file associated with the <paramref name="mediaObject"/> to the ZIP archive.
		/// </summary>
		/// <param name="zos">The ZipOutputStream (ZIP archive) the media object file is to be added to.</param>
		/// <param name="mediaObject">The media object to be added to the ZIP archive.</param>
		/// <param name="imageSize">Size of the image to add to the ZIP archive. This parameter applies only to <see cref="Image"/> 
		/// media objects.</param>
		/// <param name="basePath">The full path to the directory containing the highest-level media file to be added
		/// to the ZIP archive. Must include trailing slash. Ex: C:\Inetpub\wwwroot\galleryserverpro\mediaobjects\Summer 2005\sunsets\</param>
		/// <param name="applyWatermark">Indicates whether to apply a watermark to images as they are added to the archive.
		/// Applies only when <paramref name="mediaObject"/> is an <see cref="Image"/>.</param>
		private static void AddFileZipEntry(ZipOutputStream zos, IGalleryObject mediaObject, DisplayObjectType imageSize, string basePath, bool applyWatermark)
		{
			// Get the path to the file we'll be adding to the zip file.
			string filePath = GetMediaFilePath(mediaObject, imageSize);

			// Always use the file name of the original for naming the entry in the zip file.
			string fileNameForZip = mediaObject.Original.FileNamePhysicalPath;

			if ((!String.IsNullOrEmpty(filePath)) && (!String.IsNullOrEmpty(fileNameForZip)))
			{
				AddFileZipEntry(zos, filePath, fileNameForZip, basePath, (mediaObject is Image), applyWatermark);
			}
		}
Ejemplo n.º 50
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();
        }
Ejemplo n.º 51
0
 /// <summary>
 /// Create a new display object instance with the specified properties. No data is retrieved from the
 /// data store. A lazy load is used to inflate the object when necessary
 /// </summary>
 /// <param name="parent">The media object to which this display object applies.</param>
 /// <param name="fileName">The name of the file representing this object. Example: sonorandesert.jpg</param>
 /// <param name="width">The width of this object, in pixels.</param>
 /// <param name="height">The height of this object, in pixels.</param>
 /// <param name="displayType">The type of the display object.</param>
 /// <param name="displayObjectCreator">The object responsible for generating the file this display object points to.</param>
 /// <returns>Create a new display object instance with the specified properties.</returns>
 public static IDisplayObject CreateInstance(IGalleryObject parent, string fileName, int width, int height, DisplayObjectType displayType, IDisplayObjectCreator displayObjectCreator)
 {
     return(new DisplayObject(width, height, fileName, parent, displayType, displayObjectCreator));
 }
Ejemplo n.º 52
0
 /// <summary>
 /// Generate the URL to the media object. For example, for images this url can be assigned to the src attribute of an img tag.
 /// (ex: /galleryserverpro/handler/getmediaobject.ashx?moid=34&amp;dt=1&amp;g=1)
 /// The query string parameter will be encrypted if that option is enabled.
 /// </summary>
 /// <param name="galleryId">The gallery ID.</param>
 /// <param name="mediaObjectId">The unique identifier for the media object.</param>
 /// <param name="displayType">The type of the display object.</param>
 /// <returns>Gets the URL to the media object.</returns>
 public static string GenerateUrl(int galleryId, int mediaObjectId, DisplayObjectType displayType)
 {
     return(GetMediaObjectUrl(galleryId, mediaObjectId, displayType));
 }
Ejemplo n.º 53
0
        /// <summary>
        /// Verifies the <paramref name="fullPathToTest" /> is valid and the logged-on user has the necessary permission to specify it.
        /// </summary>
        /// <param name="item">The binding item representing the control being tested.</param>
        /// <param name="fullPathToTest">The full file path the user wishes to use to store media objects, whether they are
        /// the original media object files, thumbnails, or optimized image files.
        /// Examples: "C:\inetpub\wwwroot\galleryserverpro\myimages\", "C:/inetpub/wwwroot/galleryserverpro/myimages"</param>
        /// <param name="pathDisplayControl">The Label control used to display the full, calculated path.</param>
        /// <param name="displayType">Indicates whether the <paramref name="fullPathToTest" /> is the path for the original, thumbnail,
        /// or optimized media object files.</param>
        /// <returns>
        /// Returns <c>true</c> if the path is valid; otherwise returns <c>false</c>.
        /// </returns>
        private bool ValidatePath(wwDataBindingItem item, string fullPathToTest, Label pathDisplayControl, DisplayObjectType displayType)
        {
            if (_validatePathFailed)
            {
                // To help prevent repeated error messages (one each for original, thumbnail, and optimized), if a previous execution of
                // this test has failed, then let's just return true, thus allowing the user to focus on a single message.
                return(true);
            }

            bool isValid;

            if (this.chkPathIsReadOnly.Checked)
            {
                if (displayType == DisplayObjectType.Original)
                {
                    isValid = ValidateReadOnlyGallery(item) && ValidatePathIsReadable(item, fullPathToTest, pathDisplayControl);
                }
                else
                {
                    isValid = ValidateReadOnlyGallery(item) && ValidatePathIsWritable(item, fullPathToTest);
                }
            }
            else
            {
                isValid = ValidatePathIsWritable(item, fullPathToTest);
            }

            isValid = isValid && ValidateUserHasPermissionToSpecifyPath(item, fullPathToTest);

            if (isValid)
            {
                pathDisplayControl.Text     = fullPathToTest;
                pathDisplayControl.CssClass = "gsp_msgfriendly";
            }
            else
            {
                if (!this.GallerySettings.FullMediaObjectPath.Equals(fullPathToTest, StringComparison.OrdinalIgnoreCase))
                {
                    pathDisplayControl.Text     = String.Concat("&lt;", Resources.GalleryServerPro.Admin_MediaObjects_InvalidPath, "&gt;");
                    pathDisplayControl.CssClass = "gsp_msgwarning";
                }
                _validatePathFailed = true;
            }

            return(isValid);
        }
Ejemplo n.º 54
0
        /// <summary>
        /// Verifies the <paramref name="fullPathToTest" /> is valid and the logged-on user has the necessary permission to specify it.
        /// </summary>
        /// <param name="item">The binding item representing the control being tested.</param>
        /// <param name="fullPathToTest">The full file path the user wishes to use to store media objects, whether they are
        /// the original media object files, thumbnails, or optimized image files. 
        /// Examples: "C:\inetpub\wwwroot\galleryserverpro\myimages\", "C:/inetpub/wwwroot/galleryserverpro/myimages"</param>
        /// <param name="pathDisplayControl">The Label control used to display the full, calculated path.</param>
        /// <param name="displayType">Indicates whether the <paramref name="fullPathToTest" /> is the path for the original, thumbnail,
        /// or optimized media object files.</param>
        /// <returns>
        /// Returns <c>true</c> if the path is valid; otherwise returns <c>false</c>.
        /// </returns>
        private bool ValidatePath(wwDataBindingItem item, string fullPathToTest, Label pathDisplayControl, DisplayObjectType displayType)
        {
            if (_validatePathFailed)
            {
                // To help prevent repeated error messages (one each for original, thumbnail, and optimized), if a previous execution of
                // this test has failed, then let's just return true, thus allowing the user to focus on a single message.
                return true;
            }

            bool isValid;

            if (this.chkPathIsReadOnly.Checked)
            {
                if (displayType == DisplayObjectType.Original)
                {
                    isValid = ValidateReadOnlyGallery(item) && ValidatePathIsReadable(item, fullPathToTest, pathDisplayControl);
                }
                else
                {
                    isValid = ValidateReadOnlyGallery(item) && ValidatePathIsWritable(item, fullPathToTest);
                }
            }
            else
                isValid = ValidatePathIsWritable(item, fullPathToTest);

            isValid = isValid && ValidateUserHasPermissionToSpecifyPath(item, fullPathToTest);

            if (isValid)
            {
                pathDisplayControl.Text = fullPathToTest;
                pathDisplayControl.CssClass = "gsp_msgfriendly";
            }
            else
            {
                if (!this.GallerySettings.FullMediaObjectPath.Equals(fullPathToTest, StringComparison.OrdinalIgnoreCase))
                {
                    pathDisplayControl.Text = String.Concat("&lt;", Resources.GalleryServerPro.Admin_MediaObjects_InvalidPath, "&gt;");
                    pathDisplayControl.CssClass = "gsp_msgwarning";
                }
                _validatePathFailed = true;
            }

            return isValid;
        }
        /// <summary>
        /// Extract information from the query string and assign to our class level variables. Return false if something goes wrong
        /// and the variables cannot be set. This will happen when the query string is in an unexpected format.
        /// </summary>
        /// <param name="queryString">The query string for the current request. Can be populated with HttpContext.Request.Url.Query.
        /// Must start with a question mark (?).</param>
        /// <returns>Returns true if all relevant variables were assigned from the query string; returns false if there was a problem.</returns>
        private bool ExtractQueryStringParms(string queryString)
        {
            if (String.IsNullOrEmpty(queryString)) return false;

            queryString = queryString.Remove(0, 1); // Strip off the ?

            bool filepathIsEncrypted = AppSetting.Instance.EncryptMediaObjectUrlOnClient;
            if (filepathIsEncrypted)
            {
                // Decode, then decrypt the query string. Note that we must replace spaces with a '+'. This is required when the the URL is
                // used in javascript to create the Silverlight media player. Apparently, Silverlight or the media player javascript decodes
                // the query string when it requests the URL, so that means any instances of '%2b' are decoded into '+' before it gets here.
                // Ideally, we wouldn't even call UrlDecode in this case, but we don't have a way of knowing that it has already been decoded.
                // So we decode anyway, which doesn't cause any harm *except* it converts '+' to a space, so we need to convert them back.
                queryString = HelperFunctions.Decrypt(HttpUtility.UrlDecode(queryString).Replace(" ", "+"));
            }

            //moid={0}&dt={1}g={2}
            foreach (string nameValuePair in queryString.Split(new char[] { '&' }))
            {
                string[] nameOrValue = nameValuePair.Split(new char[] { '=' });
                switch (nameOrValue[0])
                {
                    case "g":
                        {
                            int gid;
                            if (Int32.TryParse(nameOrValue[1], out gid))
                                _galleryIdInQueryString = gid;
                            else
                                return false;
                            break;
                        }
                    case "moid":
                        {
                            int moid;
                            if (Int32.TryParse(nameOrValue[1], out moid))
                                _mediaObjectId = moid;
                            else
                                return false;
                            break;
                        }
                    case "dt":
                        {
                            int dtInt;
                            if (Int32.TryParse(nameOrValue[1], out dtInt))
                            {
                                if (DisplayObjectTypeEnumHelper.IsValidDisplayObjectType((DisplayObjectType)dtInt))
                                {
                                    _displayType = (DisplayObjectType)dtInt; break;
                                }
                                else
                                    return false;
                            }
                            else
                                return false;
                        }
                    case "sa":
                        {
                            _sendAsAttachment = ((nameOrValue[1].Equals("1", StringComparison.Ordinal)) || (nameOrValue[1].Equals("TRUE", StringComparison.OrdinalIgnoreCase)));
                            break;
                        }
                    default: return false; // Unexpected query string parm. Return false so execution is aborted.
                }
            }

            ValidateDisplayType();

            return true;
        }
        /// <summary>
        /// If an optimized version is being requested, make sure a file name is specified for it. If not, switch to the original version.
        /// This switch will be necessary for most non-image media objects, since the client usually requests optimized versions for everything.
        /// </summary>
        /// <remarks>This function became necessary when switching to the ID-based request in 2.4 (rather than the file-based request). It was 
        /// considered to change the requesting logic to ensure the correct display type is specified, and while that seems preferable from an
        /// architectural perspective, it was more complex to implement and potentially more fragile than this simple function.</remarks>
        private void ValidateDisplayType()
        {
            if ((_displayType == DisplayObjectType.Optimized) && (String.IsNullOrEmpty(MediaObjectFilePath)))
            {
                _displayType = DisplayObjectType.Original;
                _mediaObjectFilePath = null;

                // Comment out the exception, as it generates unnecessary errors when bots request deleted items
                //if (String.IsNullOrEmpty(MediaObjectFilePath))
                //{
                //  throw new InvalidMediaObjectException(String.Format(CultureInfo.CurrentCulture, "A request was made to the Gallery Server Pro HTTP handler to serve the optimized image for media object ID {0}, but either the media object does not exist or neither the optimized nor the original has a filename stored in the database, and therefore cannot be served.", _mediaObjectId));
                //}
            }
        }
Ejemplo n.º 57
0
		/// <summary>
		/// Extract information from the query string and assign to our class level variables. Return false if something goes wrong
		/// and the variables cannot be set. This will happen when the query string is in an unexpected format.
		/// </summary>
		/// <param name="queryString">The query string for the current request. Can be populated with HttpContext.Request.Url.Query.
		/// Must start with a question mark (?).</param>
		/// <returns>Returns true if all relevant variables were assigned from the query string; returns false if there was a problem.</returns>
		private bool ExtractQueryStringParms(string queryString)
		{
			if (String.IsNullOrEmpty(queryString)) return false;

			queryString = queryString.Remove(0, 1); // Strip off the ?

			bool filepathIsEncrypted = WebsiteController.GetGalleryServerProConfigSection().Core.EncryptMediaObjectUrlOnClient;
			if (filepathIsEncrypted)
			{
				// Decode, then decrypt the query string. Note that we must replace spaces with a '+'. This is required when the the URL is
				// used in javascript to create the Silverlight media player. Apparently, Silverlight or the media player javascript decodes
				// the query string when it requests the URL, so that means any instances of '%2b' are decoded into '+' before it gets here.
				// Ideally, we wouldn't even call UrlDecode in this case, but we don't have a way of knowing that it has already been decoded.
				// So we decode anyway, which doesn't cause any harm *except* it converts '+' to a space, so we need to convert them back.
				queryString = HelperFunctions.Decrypt(HttpUtility.UrlDecode(queryString).Replace(" ", "+"));
			}

			//moid={0}&aid={1}&mo={2}&mtc={3}&dt={4}&isp={5}
			foreach (string nameValuePair in queryString.Split(new char[] { '&' }))
			{
				string[] nameOrValue = nameValuePair.Split(new char[] { '=' });
				switch (nameOrValue[0])
				{
					case "moid":
						{
							int moid;
							if (Int32.TryParse(nameOrValue[1], out moid))
								_mediaObjectId = moid;
							else
								return false;
							break;
						}
					case "aid":
						{
							int aid;
							if (Int32.TryParse(nameOrValue[1], out aid))
								_albumId = aid;
							else
								return false;
							break;
						}
					case "mo": _filepath = Uri.UnescapeDataString(nameOrValue[1]); break;
					case "mtc":
						{
							int mtcInt;
							if (Int32.TryParse(nameOrValue[1], out mtcInt))
							{
								if (MimeTypeEnumHelper.IsValidMimeTypeCategory((MimeTypeCategory)mtcInt))
								{
									_mimeTypeCategory = (MimeTypeCategory)mtcInt; break;
								}
								else
									return false;
							}
							else
								return false;
						}
					case "dt":
						{
							int dtInt;
							if (Int32.TryParse(nameOrValue[1], out dtInt))
							{
								if (DisplayObjectTypeEnumHelper.IsValidDisplayObjectType((DisplayObjectType)dtInt))
								{
									_displayType = (DisplayObjectType)dtInt; break;
								}
								else
									return false;
							}
							else
								return false;
						}
					case "isp":
						{
							bool isPrivate;

							if (Boolean.TryParse(nameOrValue[1], out isPrivate))
								_isPrivate = isPrivate;
							else
								_isPrivate = true;

							break;
						}
					default: return false; // Unexpected query string parm. Return false so execution is aborted.
				}
			}

			return true;
		}
Ejemplo n.º 58
0
		/// <summary>
		/// Get the URL to the thumbnail, optimized, or original media object. Example:
		/// /dev/gs/handler/getmediaobject.ashx?moid=34&amp;aid=8&amp;mo=C%3A%5Cgs%5Cmypics%5Cbirthday.jpeg&amp;mtc=1&amp;dt=1&amp;isp=false
		/// 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>
		public static string GetMediaObjectUrl(IGalleryObject galleryObject, DisplayObjectType displayType)
		{
			string filenamePhysicalPath = null;

			switch (displayType)
			{
				case DisplayObjectType.Thumbnail: filenamePhysicalPath = galleryObject.Thumbnail.FileNamePhysicalPath; break;
				case DisplayObjectType.Optimized: filenamePhysicalPath = galleryObject.Optimized.FileNamePhysicalPath; break;
				case DisplayObjectType.Original: filenamePhysicalPath = galleryObject.Original.FileNamePhysicalPath; break;
				default: throw new ArgumentOutOfRangeException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.Error_GetMediaObjectUrl_Ex_Msg1, displayType.ToString()));
			}
			
			return MediaObjectHtmlBuilder.GenerateUrl(galleryObject.Id, galleryObject.Parent.Id, galleryObject.MimeType, filenamePhysicalPath, displayType, galleryObject.IsPrivate);
		}
Ejemplo n.º 59
0
        /// <overloads>Adds an object to the ZIP archive.</overloads>
        /// <summary>
        /// Adds the file associated with the <paramref name="mediaObject"/> to the ZIP archive.
        /// </summary>
        /// <param name="zos">The ZipOutputStream (ZIP archive) the media object file is to be added to.</param>
        /// <param name="mediaObject">The media object to be added to the ZIP archive.</param>
        /// <param name="imageSize">Size of the image to add to the ZIP archive. This parameter applies only to <see cref="Image"/>
        /// media objects.</param>
        /// <param name="basePath">The full path to the directory containing the highest-level media file to be added
        /// to the ZIP archive. Must include trailing slash. Ex: C:\Inetpub\wwwroot\galleryserverpro\mediaobjects\Summer 2005\sunsets\</param>
        /// <param name="applyWatermark">Indicates whether to apply a watermark to images as they are added to the archive.
        /// Applies only when <paramref name="mediaObject"/> is an <see cref="Image"/>.</param>
        private static void AddFileZipEntry(ZipOutputStream zos, IGalleryObject mediaObject, DisplayObjectType imageSize, string basePath, bool applyWatermark)
        {
            // Get the path to the file we'll be adding to the zip file.
            string filePath = GetMediaFilePath(mediaObject, imageSize);

            // Always use the file name of the original for naming the entry in the zip file.
            string fileNameForZip = mediaObject.Original.FileNamePhysicalPath;

            if ((!String.IsNullOrEmpty(filePath)) && (!String.IsNullOrEmpty(fileNameForZip)))
            {
                AddFileZipEntry(zos, filePath, fileNameForZip, basePath, (mediaObject is Image), applyWatermark, mediaObject.GalleryId);
            }
        }
Ejemplo n.º 60
0
        public async Task <IActionResult> RotateFlip(GalleryItem[] galleryItems, MediaAssetRotateFlip rotateFlip, DisplayObjectType viewSize)
        {
            try
            {
                return(new JsonResult(await _galleryObjectController.RotateFlip(galleryItems, rotateFlip, viewSize)));
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                return(StatusCode(500, _exController.GetExString(ex)));
            }
        }