Ejemplo n.º 1
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.º 2
0
        public static int ConvertContentType(MimeTypeCategory _mimeTypeCategory)
        {
            SueetieContentType sueetieContentType = new SueetieContentType();

            switch (_mimeTypeCategory)
            {
            case MimeTypeCategory.NotSet:
                sueetieContentType = SueetieContentType.MediaOther;
                break;

            case MimeTypeCategory.Other:
                sueetieContentType = SueetieContentType.MediaDocument;
                break;

            case MimeTypeCategory.Image:
                sueetieContentType = SueetieContentType.MediaImage;
                break;

            case MimeTypeCategory.Video:
                sueetieContentType = SueetieContentType.MediaVideo;
                break;

            case MimeTypeCategory.Audio:
                sueetieContentType = SueetieContentType.MediaAudioFile;
                break;

            default:
                sueetieContentType = SueetieContentType.MediaOther;
                break;
            }
            return((int)sueetieContentType);
        }
Ejemplo n.º 3
0
        private bool AddExternalHtmlContent()
        {
            string externalHtmlSource = txtExternalHtmlSource.Text.Trim();

            if (!this.ValidateExternalHtmlSource(externalHtmlSource))
            {
                return(false);
            }

            MimeTypeCategory mimeTypeCategory       = MimeTypeCategory.Other;
            string           mimeTypeCategoryString = ddlMediaTypes.SelectedValue;

            try
            {
                mimeTypeCategory = (MimeTypeCategory)Enum.Parse(typeof(MimeTypeCategory), mimeTypeCategoryString, true);
            }
            catch { }             // Suppress any parse errors so that category remains the default value 'Other'.

            string title = txtTitle.Text.Trim();

            if (String.IsNullOrEmpty(title))
            {
                // If user didn't enter a title, use the media category (e.g. Video, Audio, Image, Other).
                title = mimeTypeCategory.ToString();
            }

            IGalleryObject mediaObject = Factory.CreateExternalMediaObjectInstance(externalHtmlSource, mimeTypeCategory, this.GetAlbum());

            mediaObject.Title = Utils.CleanHtmlTags(title, GalleryId);
            GalleryObjectController.SaveGalleryObject(mediaObject);
            HelperFunctions.PurgeCache();

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeType"/> class.
        /// </summary>
        /// <param name="extension">A string representing the file's extension, including the period (e.g. ".jpg", ".avi").
        /// It is not case sensitive.</param>
        /// <param name="fullMimeType">The full mime type. This is the <see cref="MajorType"/> concatenated with the <see cref="Subtype"/>, with a '/' between them
        /// (e.g. image/jpeg, video/quicktime).</param>
        /// <param name="browserId">The id of the browser for the default browser as specified in the .Net Framework's browser definition file.
        /// This should always be the string "default", which means it will match all browsers. Once this instance is created, additional
        /// values that specify more specific browsers or browser families can be added to the private _browserMimeTypes member variable.</param>
        /// <param name="browserMimeType">The MIME type that can be understood by the browser for displaying this media object. The value will be applied
        /// to the browser specified in <paramref name="browserId"/>. Specify null or <see cref="String.Empty" /> if the MIME type appropriate for the
        /// browser is the same as <paramref name="fullMimeType"/>.</param>
        /// <param name="allowAddToGallery">Indicates whether a file having this MIME type can be added to Gallery Server Pro.</param>
        private MimeType(string extension, string fullMimeType, string browserId, string browserMimeType, bool allowAddToGallery)
        {
            #region Validation

            if (String.IsNullOrEmpty(extension))
            {
                throw new ArgumentNullException("extension");
            }

            if (String.IsNullOrEmpty(fullMimeType))
            {
                throw new ArgumentNullException("fullMimeType");
            }

            if (String.IsNullOrEmpty(browserId))
            {
                throw new ArgumentNullException("browserId");
            }

            if (!browserId.Equals("default", StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.MimeType_Ctor_Ex_Msg2, browserId));
            }

            // If browserMimeType is specified, it better be valid.
            if (!String.IsNullOrEmpty(browserMimeType))
            {
                ValidateMimeType(browserMimeType);
            }

            // Validate fullMimeType and separate it into its major and sub types.
            string majorType;
            string subType;
            ValidateMimeType(fullMimeType, out majorType, out subType);

            #endregion

            MimeTypeCategory mimeTypeCategory = MimeTypeCategory.Other;
            try
            {
                mimeTypeCategory = (MimeTypeCategory)Enum.Parse(typeof(MimeTypeCategory), majorType, true);
            }
            catch (ArgumentException) { /* Swallow exception so that we default to MimeTypeCategory.Other */ }

            this._extension         = extension;
            this._typeCategory      = mimeTypeCategory;
            this._majorType         = majorType;
            this._subtype           = subType;
            this._allowAddToGallery = allowAddToGallery;

            this._browserMimeTypes = new Dictionary <string, string>(1);
            if (String.IsNullOrEmpty(browserMimeType))
            {
                // When no browserMimeType is specified, default to the regular MIME type.
                browserMimeType = fullMimeType;
            }

            this._browserMimeTypes.Add(browserId, browserMimeType);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CacheItemDisplayObject"/> 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="fileSizeKb">The size of the file, in KB, for this display object.</param>
 /// <param name="externalHtmlSource">The HTML that defines an externally stored media object, such as videos hosted at YouTube.</param>
 /// <param name="externalType">The MIME type category for an externally stored media object. This property is not relevant for locally stored media objects.</param>
 public CacheItemDisplayObject(int width, int height, string fileName, int fileSizeKb, string externalHtmlSource, MimeTypeCategory externalType)
 {
     Width              = width;
     Height             = height;
     FileName           = fileName;
     FileSizeKB         = fileSizeKb;
     ExternalHtmlSource = externalHtmlSource;
     ExternalType       = externalType;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeType"/> class with the specified MIME type category. The <see cref="MajorType" /> property is
        /// assigned the string representation of the <paramref name="mimeType"/>. Remaining properties are set to empty strings or false
        /// (<see cref="AllowAddToGallery" />). This constructor is intended to be used to help describe an external media object, which is
        /// not represented by a locally stored file but for which it is useful to describe its general type (audio, video, etc).
        /// </summary>
        /// <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 MimeType(MimeTypeCategory mimeType)
        {
            this._typeCategory      = mimeType;
            this._majorType         = mimeType.ToString();
            this._extension         = String.Empty;
            this._subtype           = String.Empty;
            this._allowAddToGallery = false;

            this._browserMimeTypes = new Dictionary <string, string>(0);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeType"/> class with the specified MIME type category. The <see cref="MajorType" /> property is
 /// assigned the string representation of the <paramref name="mimeType"/>. Remaining properties are set to empty strings or false
 /// (<see cref="AllowAddToGallery" />). This constructor is intended to be used to help describe an external media object, which is
 /// not represented by a locally stored file but for which it is useful to describe its general type (audio, video, etc).
 /// </summary>
 /// <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 MimeType(MimeTypeCategory mimeType)
 {
     this._galleryId         = Int32.MinValue;
     this._typeCategory      = mimeType;
     this._majorType         = mimeType.ToString();
     this._extension         = String.Empty;
     this._subtype           = String.Empty;
     this._browserMimeType   = String.Empty;
     this._allowAddToGallery = false;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="MediaObjectMetadataExtractor"/> class. This object can
        /// interact with the metadata contained in the specified media object.
        /// </summary>
        /// <param name="mediaObjectFilePath">The path, either absolute or relative, that indicates the
        /// location of the media object file on disk. This value is used in the <see cref="FileStream"/> constructor.
        /// (e.g. C:\folder1\folder2\sunset.jpg, sunset.jpg).</param>
        /// <param name="galleryId">The ID of the gallery the <paramref name="mediaObjectFilePath"/> is associated with.</param>
        /// <param name="ffmpegOutput">The output from the utility FFmpeg. This data can be parsed for pieces of metadata for videos. Optional. 
        /// When null or an empty string, this utility will automatically run FFmpeg to generate the needed data. This parameter is used
        /// only for video media objects.</param>
        /// <exception cref="OutOfMemoryException">
        /// Thrown when the <paramref name="mediaObjectFilePath"/> is an image that is too large to be loaded into memory.</exception>
        public MediaObjectMetadataExtractor(string mediaObjectFilePath, int galleryId, string ffmpegOutput)
        {
            this._galleryId = galleryId;
            this._mediaObjectFilePath = mediaObjectFilePath;
            this._ffmpegOutput = ffmpegOutput;

            IMimeType mimeType = MimeType.LoadMimeType(galleryId, mediaObjectFilePath);
            this._mimeTypeCategory = (mimeType != null ? mimeType.TypeCategory : MimeTypeCategory.NotSet);

            if (this._mimeTypeCategory == MimeTypeCategory.Image)
            {
                ExtractImagePropertyItems(mediaObjectFilePath);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Determines if the mimeTypeCategory 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="mimeTypeCategory">An instance of <see cref="MimeTypeCategory" /> to test.</param>
        /// <returns>Returns true if mimeTypeCategory is one of the defined items in the enumeration; otherwise returns false.</returns>
        public static bool IsValidMimeTypeCategory(MimeTypeCategory mimeTypeCategory)
        {
            switch (mimeTypeCategory)
            {
            case MimeTypeCategory.NotSet:
            case MimeTypeCategory.Audio:
            case MimeTypeCategory.Image:
            case MimeTypeCategory.Other:
            case MimeTypeCategory.Video:
                break;

            default:
                return(false);
            }
            return(true);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeType"/> class.
        /// </summary>
        /// <param name="mimeTypeId">The value that uniquely identifies the MIME type.</param>
        /// <param name="mimeTypeGalleryId">The value that uniquely identifies the MIME type that applies to a particular gallery.</param>
        /// <param name="galleryId">The gallery ID. Specify <see cref="Int32.MinValue"/> if creating an instance that is not
        /// specific to a particular gallery.</param>
        /// <param name="fileExtension">A string representing the file's extension, including the period (e.g. ".jpg", ".avi").
        /// It is not case sensitive.</param>
        /// <param name="mimeTypeValue">The full mime type. This is the <see cref="MajorType"/> concatenated with the <see cref="Subtype"/>,
        /// with a '/' between them (e.g. image/jpeg, video/quicktime).</param>
        /// <param name="browserMimeType">The MIME type that can be understood by the browser for displaying this media object.  Specify null or
        /// <see cref="String.Empty"/> if the MIME type appropriate for the browser is the same as <paramref name="mimeTypeValue"/>.</param>
        /// <param name="allowAddToGallery">Indicates whether a file having this MIME type can be added to Gallery Server Pro.
        /// This parameter is only relevant when a valid <paramref name="galleryId"/> is specified.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="fileExtension" /> or <paramref name="mimeTypeValue" /> is
        /// null or an empty string.</exception>
        private MimeType(int mimeTypeId, int mimeTypeGalleryId, int galleryId, string fileExtension, string mimeTypeValue, string browserMimeType, bool allowAddToGallery)
        {
            #region Validation

            if (String.IsNullOrEmpty(fileExtension))
            {
                throw new ArgumentOutOfRangeException("fileExtension", "Parameter cannot be null or empty.");
            }

            if (String.IsNullOrEmpty(mimeTypeValue))
            {
                throw new ArgumentOutOfRangeException("mimeTypeValue", "Parameter cannot be null or empty.");
            }

            // If browserMimeType is specified, it better be valid.
            if (!String.IsNullOrEmpty(browserMimeType))
            {
                ValidateMimeType(browserMimeType);
            }

            // Validate fullMimeType and separate it into its major and sub types.
            string majorType;
            string subType;
            ValidateMimeType(mimeTypeValue, out majorType, out subType);

            #endregion

            MimeTypeCategory mimeTypeCategory = MimeTypeCategory.Other;
            try
            {
                mimeTypeCategory = (MimeTypeCategory)Enum.Parse(typeof(MimeTypeCategory), majorType, true);
            }
            catch (ArgumentException) { /* Swallow exception so that we default to MimeTypeCategory.Other */ }

            this._mimeTypeId        = mimeTypeId;
            this._mimeTypeGalleryId = mimeTypeGalleryId;
            this._galleryId         = galleryId;
            this._extension         = fileExtension;
            this._typeCategory      = mimeTypeCategory;
            this._majorType         = majorType;
            this._subtype           = subType;
            this._browserMimeType   = (String.IsNullOrEmpty(browserMimeType) ? mimeTypeValue : browserMimeType);
            this._allowAddToGallery = allowAddToGallery;
        }
Ejemplo n.º 11
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.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeType"/> class.
        /// </summary>
        /// <param name="mimeTypeId">The value that uniquely identifies the MIME type.</param>
        /// <param name="mimeTypeGalleryId">The value that uniquely identifies the MIME type that applies to a particular gallery.</param>
        /// <param name="galleryId">The gallery ID. Specify <see cref="Int32.MinValue"/> if creating an instance that is not
        /// specific to a particular gallery.</param>
        /// <param name="fileExtension">A string representing the file's extension, including the period (e.g. ".jpg", ".avi").
        /// It is not case sensitive.</param>
        /// <param name="mimeTypeValue">The full mime type. This is the <see cref="MajorType"/> concatenated with the <see cref="Subtype"/>,
        /// with a '/' between them (e.g. image/jpeg, video/quicktime).</param>
        /// <param name="browserMimeType">The MIME type that can be understood by the browser for displaying this media object.  Specify null or
        /// <see cref="String.Empty"/> if the MIME type appropriate for the browser is the same as <paramref name="mimeTypeValue"/>.</param>
        /// <param name="allowAddToGallery">Indicates whether a file having this MIME type can be added to Gallery Server.
        /// This parameter is only relevant when a valid <paramref name="galleryId"/> is specified.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="fileExtension" /> or <paramref name="mimeTypeValue" /> is
        /// null or an empty string.</exception>
        private MimeType(int mimeTypeId, int mimeTypeGalleryId, int galleryId, string fileExtension, string mimeTypeValue, string browserMimeType, bool allowAddToGallery)
        {
            #region Validation

            if (String.IsNullOrEmpty(fileExtension))
            {
                throw new ArgumentOutOfRangeException("fileExtension", "Parameter cannot be null or empty.");
            }

            if (String.IsNullOrEmpty(mimeTypeValue))
            {
                throw new ArgumentOutOfRangeException("mimeTypeValue", "Parameter cannot be null or empty.");
            }

            // If browserMimeType is specified, it better be valid.
            if (!String.IsNullOrEmpty(browserMimeType))
            {
                ValidateMimeType(browserMimeType);
            }

            // Validate fullMimeType and separate it into its major and sub types.
            string majorType;
            string subType;
            ValidateMimeType(mimeTypeValue, out majorType, out subType);

            #endregion

            this._mimeTypeId        = mimeTypeId;
            this._mimeTypeGalleryId = mimeTypeGalleryId;
            this._galleryId         = galleryId;
            this._extension         = fileExtension;
            this._typeCategory      = MimeTypeEnumHelper.ParseMimeTypeCategory(majorType);
            this._majorType         = majorType;
            this._subtype           = subType;
            this._browserMimeType   = (String.IsNullOrEmpty(browserMimeType) ? mimeTypeValue : browserMimeType);
            this._allowAddToGallery = allowAddToGallery;
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeType"/> class with the specified MIME type category. The <see cref="MajorType" /> property is
 /// assigned the string representation of the <paramref name="mimeType"/>. Remaining properties are set to empty strings or false
 /// (<see cref="AllowAddToGallery" />). This method is intended to be used to help describe an external media object, which is
 /// not represented by a locally stored file but for which it is useful to describe its general type (audio, video, etc).
 /// </summary>
 /// <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>Returns a new instance of <see cref="IMimeType"/>.</returns>
 public static IMimeType CreateInstance(MimeTypeCategory mimeType)
 {
     return(new MimeType(mimeType));
 }
Ejemplo n.º 14
0
		/// <overloads>
		/// Create a minimally populated <see cref="ExternalMediaObject" /> instance from the specified parameters. 
		/// </overloads>
		/// <summary>
		/// Create a minimally populated <see cref="ExternalMediaObject" /> instance from the specified parameters. 
		/// </summary>
		/// <param name="externalHtmlSource">The HTML that defines an externally stored media object, such as one hosted at 
		/// YouTube or Silverlight.live.com.</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>
		/// <param name="parentAlbum">The album in which the file exists (for media objects that already exist
		/// in the data store), or should be added to (for new media objects which need to be inserted into the 
		/// data store).</param>
		/// <returns>Returns a minimally populated <see cref="ExternalMediaObject" /> instance from the specified parameters.</returns>
		public static IGalleryObject CreateExternalMediaObjectInstance(string externalHtmlSource, MimeTypeCategory mimeType, IAlbum parentAlbum)
		{
			return CreateExternalMediaObjectInstance(externalHtmlSource, mimeType, parentAlbum, false);
		}
Ejemplo n.º 15
0
        /// <summary>
        /// Create a properly typed Gallery Object instance (e.g. <see cref="Image" />, <see cref="Video" />, etc.). If 
        /// <paramref name = "externalHtmlSource" /> is specified, then an <see cref="ExternalMediaObject" /> is created with the
        /// specified <paramref name = "mimeTypeCategory" />; otherwise a new instance is created based on <paramref name = "mediaObjectFile" />,
        /// where the exact type (e.g. <see cref="Image" />, <see cref="Video" />, etc.) is determined by the file's extension.
        /// </summary>
        /// <param name="mediaObjectFile">A <see cref="System.IO.FileInfo" /> object representing a supported media object type. The file must already
        /// exist in the album's directory. If the file has a matching record in the data store, a reference to the existing 
        /// object is returned; otherwise, a new instance is returned. For new instances, call <see cref="IGalleryObject.Save" /> to 
        ///		persist the object to the data store. A <see cref="UnsupportedMediaObjectTypeException" /> is thrown when the specified file cannot 
        /// be added to Gallery Server, perhaps because it is an unsupported type or the file is corrupt. Do not specify this parameter
        /// when using the <paramref name = "externalHtmlSource" /> parameter.</param>
        /// <param name="parentAlbum">The album in which the media object exists (for media objects that already exist
        /// in the data store), or should be added to (for new media objects which need to be inserted into the data store).</param>
        /// <param name="externalHtmlSource">The HTML that defines an externally stored media object, such as one hosted at 
        /// Silverlight.net or youtube.com. Using this parameter also requires specifying <paramref name = "mimeTypeCategory" />
        /// and passing null for <paramref name = "mediaObjectFile" />.</param>
        /// <param name="mimeTypeCategory">Specifies the category to which an externally stored media object belongs. 
        /// Must be set to a value other than MimeTypeCategory.NotSet when the <paramref name = "externalHtmlSource" /> is specified.</param>
        /// <returns>Returns a properly typed Gallery Object instance corresponding to the specified parameters.</returns>
        /// <exception cref="ArgumentException">Thrown when <paramref name = "mediaObjectFile" /> and <paramref name = "externalHtmlSource" />
        /// are either both specified, or neither.</exception>
        /// <exception cref="UnsupportedMediaObjectTypeException">Thrown when <paramref name = "mediaObjectFile" /> has a file 
        /// extension that Gallery Server Pro is configured to reject.</exception>
        /// <exception cref="InvalidMediaObjectException">Thrown when the  
        /// mediaObjectFile parameter refers to a file that is not in the same directory as the parent album's directory.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name = "parentAlbum" /> is null.</exception>
        /// <remarks>
        /// This method is marked internal to ensure it is not called from the web layer. It was noticed that
        /// calling this method from the web layer caused the file referenced in the mediaObjectFile parameter to remain
        /// locked beyond the conclusion of the page lifecycle, preventing manual deletion using Windows Explorer. Note 
        /// that restarting IIS (iisreset.exe) released the file lock, and presumably the next garbage collection would 
        /// have released it as well. The web page was modified to call the overload of this method that takes the filepath
        /// as a string parameter and then instantiates a FileInfo object. I am not sure why, but instantiating the FileInfo 
        /// object within this DLL in this way caused the file lock to be released at the end of the page lifecycle.
        /// </remarks>
        internal static IGalleryObject CreateMediaObjectInstance(FileInfo mediaObjectFile, IAlbum parentAlbum, string externalHtmlSource, MimeTypeCategory mimeTypeCategory)
        {
            #region Validation

            // Either mediaObjectFile or externalHtmlSource must be specified, but not both.
            if ((mediaObjectFile == null) && (String.IsNullOrEmpty(externalHtmlSource)))
                throw new ArgumentException("The method GalleryServerPro.Business.Factory.CreateMediaObjectInstance was invoked with invalid parameters. The parameters mediaObjectFile and externalHtmlSource cannot both be null or empty. One of these - but not both - must be populated.");

            if ((mediaObjectFile != null) && (!String.IsNullOrEmpty(externalHtmlSource)))
                throw new ArgumentException("The method GalleryServerPro.Business.Factory.CreateMediaObjectInstance was invoked with invalid parameters. The parameters mediaObjectFile and externalHtmlSource cannot both be specified.");

            if ((!String.IsNullOrEmpty(externalHtmlSource)) && (mimeTypeCategory == MimeTypeCategory.NotSet))
                throw new ArgumentException("The method GalleryServerPro.Business.Factory.CreateMediaObjectInstance was invoked with invalid parameters. The parameters mimeTypeCategory must be set to a value other than MimeTypeCategory.NotSet when the externalHtmlSource parameter is specified.");

            if (parentAlbum == null)
                throw new ArgumentNullException("parentAlbum");

            #endregion

            if (String.IsNullOrEmpty(externalHtmlSource))
                return CreateLocalMediaObjectInstance(mediaObjectFile, parentAlbum);
            else
                return CreateExternalMediaObjectInstance(externalHtmlSource, mimeTypeCategory, parentAlbum);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Create a minimally populated <see cref="ExternalMediaObject" /> instance from the specified parameters.
        /// </summary>
        /// <param name="externalHtmlSource">The HTML that defines an externally stored media object, such as one hosted at 
        /// YouTube or Silverlight.live.com.</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>
        /// <param name="parentAlbum">The album in which the file exists (for media objects that already exist
        /// in the data store), or should be added to (for new media objects which need to be inserted into the 
        /// data store).</param>
        /// <returns>Returns a minimally populated <see cref="ExternalMediaObject" /> instance from the specified parameters.</returns>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name = "externalHtmlSource" /> is an empty string or null.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="parentAlbum" /> is null.</exception>
        public static IGalleryObject CreateExternalMediaObjectInstance(string externalHtmlSource, MimeTypeCategory mimeType, IAlbum parentAlbum)
        {
            if (String.IsNullOrEmpty(externalHtmlSource))
                throw new ArgumentOutOfRangeException("externalHtmlSource", "The parameter is either null or an empty string.");

            if (parentAlbum == null)
                throw new ArgumentNullException("parentAlbum");

            // Create a new generic media object, which will cause a new record to be inserted in the data store when Save() is called.
            return new ExternalMediaObject(externalHtmlSource, mimeType, parentAlbum);
        }
Ejemplo n.º 17
0
		/// <summary>
		/// Determines if the mimeTypeCategory 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="mimeTypeCategory">An instance of <see cref="MimeTypeCategory" /> to test.</param>
		/// <returns>Returns true if mimeTypeCategory is one of the defined items in the enumeration; otherwise returns false.</returns>
		public static bool IsValidMimeTypeCategory(MimeTypeCategory mimeTypeCategory)
		{
			switch (mimeTypeCategory)
			{
				case MimeTypeCategory.NotSet:
				case MimeTypeCategory.Audio:
				case MimeTypeCategory.Image:
				case MimeTypeCategory.Other:
				case MimeTypeCategory.Video:
					break;

				default:
					return false;
			}
			return true;
		}
Ejemplo n.º 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeType"/> class.
        /// </summary>
        /// <param name="mimeTypeId">The value that uniquely identifies the MIME type.</param>
        /// <param name="mimeTypeGalleryId">The value that uniquely identifies the MIME type that applies to a particular gallery.</param>
        /// <param name="galleryId">The gallery ID. Specify <see cref="Int32.MinValue"/> if creating an instance that is not
        /// specific to a particular gallery.</param>
        /// <param name="fileExtension">A string representing the file's extension, including the period (e.g. ".jpg", ".avi").
        /// It is not case sensitive.</param>
        /// <param name="mimeTypeValue">The full mime type. This is the <see cref="MajorType"/> concatenated with the <see cref="Subtype"/>,
        /// with a '/' between them (e.g. image/jpeg, video/quicktime).</param>
        /// <param name="browserMimeType">The MIME type that can be understood by the browser for displaying this media object.  Specify null or
        /// <see cref="String.Empty"/> if the MIME type appropriate for the browser is the same as <paramref name="mimeTypeValue"/>.</param>
        /// <param name="allowAddToGallery">Indicates whether a file having this MIME type can be added to Gallery Server Pro.
        /// This parameter is only relevant when a valid <paramref name="galleryId"/> is specified.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="fileExtension" /> or <paramref name="mimeTypeValue" /> is
        /// null or an empty string.</exception>
        private MimeType(int mimeTypeId, int mimeTypeGalleryId, int galleryId, string fileExtension, string mimeTypeValue, string browserMimeType, bool allowAddToGallery)
        {
            #region Validation

            if (String.IsNullOrEmpty(fileExtension))
                throw new ArgumentOutOfRangeException("fileExtension", "Parameter cannot be null or empty.");

            if (String.IsNullOrEmpty(mimeTypeValue))
                throw new ArgumentOutOfRangeException("mimeTypeValue", "Parameter cannot be null or empty.");

            // If browserMimeType is specified, it better be valid.
            if (!String.IsNullOrEmpty(browserMimeType))
            {
                ValidateMimeType(browserMimeType);
            }

            // Validate fullMimeType and separate it into its major and sub types.
            string majorType;
            string subType;
            ValidateMimeType(mimeTypeValue, out majorType, out subType);

            #endregion

            MimeTypeCategory mimeTypeCategory = MimeTypeCategory.Other;
            try
            {
                mimeTypeCategory = (MimeTypeCategory)Enum.Parse(typeof(MimeTypeCategory), majorType, true);
            }
            catch (ArgumentException) {	/* Swallow exception so that we default to MimeTypeCategory.Other */	}

            this._mimeTypeId = mimeTypeId;
            this._mimeTypeGalleryId = mimeTypeGalleryId;
            this._galleryId = galleryId;
            this._extension = fileExtension;
            this._typeCategory = mimeTypeCategory;
            this._majorType = majorType;
            this._subtype = subType;
            this._browserMimeType = (String.IsNullOrEmpty(browserMimeType) ? mimeTypeValue : browserMimeType);
            this._allowAddToGallery = allowAddToGallery;
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeType"/> class with the specified MIME type category. The <see cref="MajorType" /> property is
 /// assigned the string representation of the <paramref name="mimeType"/>. Remaining properties are set to empty strings or false 
 /// (<see cref="AllowAddToGallery" />). This constructor is intended to be used to help describe an external media object, which is
 /// not represented by a locally stored file but for which it is useful to describe its general type (audio, video, etc).
 /// </summary>
 /// <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 MimeType(MimeTypeCategory mimeType)
 {
     this._galleryId = Int32.MinValue;
     this._typeCategory = mimeType;
     this._majorType = mimeType.ToString();
     this._extension = String.Empty;
     this._subtype = String.Empty;
     this._browserMimeType = String.Empty;
     this._allowAddToGallery = false;
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Initializes a new instance of a ExternalMediaObject object.
        /// </summary>
        /// <param name="id">The ID that uniquely identifies this object. Specify int.MinValue for a new object.</param>
        /// <param name="parentAlbum">The album that contains this object. This is a required parameter.</param>
        /// <param name="title">The title of this image.</param>
        /// <param name="hashKey">The hash key that uniquely identifies the original file.</param>
        /// <param name="thumbnailFilename">The filename of the thumbnail image.</param>
        /// <param name="thumbnailWidth">The width (px) of the thumbnail image.</param>
        /// <param name="thumbnailHeight">The height (px) of the thumbnail image.</param>
        /// <param name="thumbnailSizeKb">The size (KB) of the thumbnail image.</param>
        /// <param name="externalHtmlSource">The HTML that defines an externally stored media object, such as one hosted at
        /// YouTube or Silverlight.live.com.</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>
        /// <param name="sequence">An integer that represents the order in which this image should appear when displayed.</param>
        /// <param name="createdByUsername">The user name of the account that originally added this object to the data store.</param>
        /// <param name="dateAdded">The date this image was added to the data store.</param>
        /// <param name="lastModifiedByUsername">The user name of the account that last modified this object.</param>
        /// <param name="dateLastModified">The date this object was last modified.</param>
        /// <param name="isPrivate">Indicates whether this object should be hidden from un-authenticated (anonymous) users.</param>
        /// <param name="isInflated">A bool indicating whether this object is fully inflated.</param>
        /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.InvalidMediaObjectException">Thrown when
        /// the file parameter is specified (not null) and the file it refers to is not in the same directory
        /// as the parent album's directory.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="parentAlbum" /> is null.</exception>
        internal ExternalMediaObject(int id, IAlbum parentAlbum, string title, string hashKey, string thumbnailFilename,
                                     int thumbnailWidth, int thumbnailHeight, int thumbnailSizeKb, string externalHtmlSource, MimeTypeCategory mimeType, int sequence,
                                     string createdByUsername, DateTime dateAdded, string lastModifiedByUsername, DateTime dateLastModified,
                                     bool isPrivate, bool isInflated)
        {
            if (parentAlbum == null)
            {
                throw new ArgumentNullException("parentAlbum");
            }

            this.Id                     = id;
            this.Parent                 = parentAlbum;
            this.GalleryId              = this.Parent.GalleryId;
            this.Title                  = title;
            this.Sequence               = sequence;
            this.Hashkey                = hashKey;
            this.CreatedByUserName      = createdByUsername;
            this.DateAdded              = dateAdded;
            this.LastModifiedByUserName = lastModifiedByUsername;
            this.DateLastModified       = dateLastModified;
            this.IsPrivate              = isPrivate;

            string parentPhysicalPath = this.Parent.FullPhysicalPathOnDisk;

            IGallerySettings gallerySetting = Factory.LoadGallerySetting(GalleryId);

            // Thumbnail image
            this.Thumbnail            = DisplayObject.CreateInstance(this, thumbnailFilename, thumbnailWidth, thumbnailHeight, DisplayObjectType.Thumbnail, new ExternalThumbnailCreator(this));
            this.Thumbnail.FileSizeKB = thumbnailSizeKb;
            if (thumbnailFilename.Length > 0)
            {
                // The thumbnail is stored in either the album's physical path or an alternate location (if thumbnailPath config setting is specified).
                string thumbnailPath = HelperFunctions.MapAlbumDirectoryStructureToAlternateDirectory(parentPhysicalPath, gallerySetting.FullThumbnailPath, gallerySetting.FullMediaObjectPath);
                this.Thumbnail.FileNamePhysicalPath = System.IO.Path.Combine(thumbnailPath, thumbnailFilename);
            }

            // ExternalMediaObject instances do not have an optimized version.
            this.Optimized = new NullObjects.NullDisplayObject();

            // Original file
            this.Original = DisplayObject.CreateInstance(this, DisplayObjectType.External, mimeType);
            this.Original.ExternalHtmlSource = externalHtmlSource;

            switch (mimeType)
            {
            case MimeTypeCategory.Audio:
                this.Original.Width  = gallerySetting.DefaultAudioPlayerWidth;
                this.Original.Height = gallerySetting.DefaultAudioPlayerHeight;
                break;

            case MimeTypeCategory.Video:
                this.Original.Width  = gallerySetting.DefaultVideoPlayerWidth;
                this.Original.Height = gallerySetting.DefaultVideoPlayerHeight;
                break;

            case MimeTypeCategory.Image:
            case MimeTypeCategory.Other:
                this.Original.Width  = gallerySetting.DefaultGenericObjectWidth;
                this.Original.Height = gallerySetting.DefaultGenericObjectHeight;
                break;
            }

            this.ExtractMetadataOnSave = false;

            this.SaveBehavior   = Factory.GetMediaObjectSaveBehavior(this);
            this.DeleteBehavior = Factory.GetMediaObjectDeleteBehavior(this);

            this.IsInflated = isInflated;

            // Setting the previous properties has caused HasChanges = true, but we don't want this while
            // we're instantiating a new object. Reset to false.
            this.HasChanges = false;

            // Set up our event handlers.
            //this.Saving += new EventHandler(Image_Saving); // Don't need
            this.Saved += new EventHandler(Image_Saved);
        }
Ejemplo n.º 21
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeType"/> class with the specified MIME type category. The <see cref="MajorType" /> property is
		/// assigned the string representation of the <paramref name="mimeType"/>. Remaining properties are set to empty strings or false 
		/// (<see cref="AllowAddToGallery" />). This constructor is intended to be used to help describe an external media object, which is
		/// not represented by a locally stored file but for which it is useful to describe its general type (audio, video, etc).
		/// </summary>
		/// <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 MimeType(MimeTypeCategory mimeType)
		{
			this._typeCategory = mimeType;
			this._majorType = mimeType.ToString();
			this._extension = String.Empty;
			this._subtype = String.Empty;
			this._allowAddToGallery = false;

			this._browserMimeTypes = new Dictionary<string, string>(0);
		}
Ejemplo n.º 22
0
        /// <summary>
        /// Initializes a new instance of a ExternalMediaObject object.
        /// </summary>
        /// <param name="id">The ID that uniquely identifies this object. Specify int.MinValue for a new object.</param>
        /// <param name="parentAlbum">The album that contains this object. This is a required parameter.</param>
        /// <param name="thumbnailFilename">The filename of the thumbnail image.</param>
        /// <param name="thumbnailWidth">The width (px) of the thumbnail image.</param>
        /// <param name="thumbnailHeight">The height (px) of the thumbnail image.</param>
        /// <param name="thumbnailSizeKb">The size (KB) of the thumbnail image.</param>
        /// <param name="externalHtmlSource">The HTML that defines an externally stored media object, such as one hosted at
        ///   YouTube or Silverlight.live.com.</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>
        /// <param name="sequence">An integer that represents the order in which this image should appear when displayed.</param>
        /// <param name="createdByUsername">The user name of the account that originally added this object to the data store.</param>
        /// <param name="dateAdded">The date this image was added to the data store.</param>
        /// <param name="lastModifiedByUsername">The user name of the account that last modified this object.</param>
        /// <param name="dateLastModified">The date this object was last modified.</param>
        /// <param name="isPrivate">Indicates whether this object should be hidden from un-authenticated (anonymous) users.</param>
        /// <param name="isInflated">A bool indicating whether this object is fully inflated.</param>
        /// <param name="metadata">A collection of <see cref="Data.MetadataDto" /> instances containing metadata for the
        ///   object. Specify null if not available.</param>
        /// <exception cref="GalleryServerPro.Events.CustomExceptions.InvalidMediaObjectException">Thrown when
        /// the file parameter is specified (not null) and the file it refers to is not in the same directory
        /// as the parent album's directory.</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="parentAlbum" /> is null.</exception>
        internal ExternalMediaObject(int id, IAlbum parentAlbum, string thumbnailFilename, int thumbnailWidth, int thumbnailHeight, int thumbnailSizeKb, string externalHtmlSource, MimeTypeCategory mimeType, int sequence, string createdByUsername, DateTime dateAdded, string lastModifiedByUsername, DateTime dateLastModified, bool isPrivate, bool isInflated, IEnumerable<MetadataDto> metadata)
        {
            if (parentAlbum == null)
                throw new ArgumentNullException("parentAlbum");

            this.Id = id;
            this.Parent = parentAlbum;
            this.GalleryId = this.Parent.GalleryId;
            //this.Title = title;
            this.Sequence = sequence;
            this.CreatedByUserName = createdByUsername;
            this.DateAdded = dateAdded;
            this.LastModifiedByUserName = lastModifiedByUsername;
            this.DateLastModified = dateLastModified;
            this.IsPrivate = isPrivate;

            this.SaveBehavior = Factory.GetMediaObjectSaveBehavior(this);
            this.DeleteBehavior = Factory.GetMediaObjectDeleteBehavior(this);
            this.MetadataReadWriter = Factory.GetMetadataReadWriter(this);

            string parentPhysicalPath = this.Parent.FullPhysicalPathOnDisk;

            IGallerySettings gallerySetting = Factory.LoadGallerySetting(GalleryId);

            // Thumbnail image
            this.Thumbnail = DisplayObject.CreateInstance(this, thumbnailFilename, thumbnailWidth, thumbnailHeight, DisplayObjectType.Thumbnail, new ExternalThumbnailCreator(this));
            this.Thumbnail.FileSizeKB = thumbnailSizeKb;
            if (thumbnailFilename.Length > 0)
            {
                // The thumbnail is stored in either the album's physical path or an alternate location (if thumbnailPath config setting is specified).
                string thumbnailPath = HelperFunctions.MapAlbumDirectoryStructureToAlternateDirectory(parentPhysicalPath, gallerySetting.FullThumbnailPath, gallerySetting.FullMediaObjectPath);
                this.Thumbnail.FileNamePhysicalPath = System.IO.Path.Combine(thumbnailPath, thumbnailFilename);
            }

            // ExternalMediaObject instances do not have an optimized version.
            this.Optimized = new NullObjects.NullDisplayObject();

            // Original file
            this.Original = DisplayObject.CreateInstance(this, DisplayObjectType.External, mimeType);
            this.Original.ExternalHtmlSource = externalHtmlSource;

            switch (mimeType)
            {
                case MimeTypeCategory.Audio:
                    this.Original.Width = gallerySetting.DefaultAudioPlayerWidth;
                    this.Original.Height = gallerySetting.DefaultAudioPlayerHeight;
                    break;
                case MimeTypeCategory.Video:
                    this.Original.Width = gallerySetting.DefaultVideoPlayerWidth;
                    this.Original.Height = gallerySetting.DefaultVideoPlayerHeight;
                    break;
                case MimeTypeCategory.Image:
                case MimeTypeCategory.Other:
                    this.Original.Width = gallerySetting.DefaultGenericObjectWidth;
                    this.Original.Height = gallerySetting.DefaultGenericObjectHeight;
                    break;
            }

            if (IsNew)
            {
                ExtractMetadata();
            }

            if (metadata != null)
                AddMeta(GalleryObjectMetadataItemCollection.FromMetaDtos(this, metadata));

            this.IsInflated = isInflated;

            // Setting the previous properties has caused HasChanges = true, but we don't want this while
            // we're instantiating a new object. Reset to false.
            this.HasChanges = false;

            // Set up our event handlers.
            //this.Saving += new EventHandler(Image_Saving); // Don't need
            this.Saved += Image_Saved;
        }
Ejemplo n.º 23
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeType"/> class.
		/// </summary>
		/// <param name="extension">A string representing the file's extension, including the period (e.g. ".jpg", ".avi").
		/// It is not case sensitive.</param>
		/// <param name="fullMimeType">The full mime type. This is the <see cref="MajorType"/> concatenated with the <see cref="Subtype"/>, with a '/' between them
		/// (e.g. image/jpeg, video/quicktime).</param>
		/// <param name="browserId">The id of the browser for the default browser as specified in the .Net Framework's browser definition file. 
		/// This should always be the string "default", which means it will match all browsers. Once this instance is created, additional
		/// values that specify more specific browsers or browser families can be added to the private _browserMimeTypes member variable.</param>
		/// <param name="browserMimeType">The MIME type that can be understood by the browser for displaying this media object. The value will be applied
		/// to the browser specified in <paramref name="browserId"/>. Specify null or <see cref="String.Empty" /> if the MIME type appropriate for the 
		/// browser is the same as <paramref name="fullMimeType"/>.</param>
		/// <param name="allowAddToGallery">Indicates whether a file having this MIME type can be added to Gallery Server Pro.</param>
		private MimeType(string extension, string fullMimeType, string browserId, string browserMimeType, bool allowAddToGallery)
		{
			#region Validation

			if (String.IsNullOrEmpty(extension))
				throw new ArgumentNullException("extension");

			if (String.IsNullOrEmpty(fullMimeType))
				throw new ArgumentNullException("fullMimeType");

			if (String.IsNullOrEmpty(browserId))
				throw new ArgumentNullException("browserId");

			if (!browserId.Equals("default", StringComparison.OrdinalIgnoreCase))
			{
				throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.MimeType_Ctor_Ex_Msg2, browserId));
			}

			// If browserMimeType is specified, it better be valid.
			if (!String.IsNullOrEmpty(browserMimeType))
			{
				ValidateMimeType(browserMimeType);
			}

			// Validate fullMimeType and separate it into its major and sub types.
			string majorType;
			string subType;
			ValidateMimeType(fullMimeType, out majorType, out subType);

			#endregion

			MimeTypeCategory mimeTypeCategory = MimeTypeCategory.Other;
			try
			{
				mimeTypeCategory = (MimeTypeCategory)Enum.Parse(typeof(MimeTypeCategory), majorType, true);
			}
			catch (ArgumentException) {	/* Swallow exception so that we default to MimeTypeCategory.Other */	}

			this._extension = extension;
			this._typeCategory = mimeTypeCategory;
			this._majorType = majorType;
			this._subtype = subType;
			this._allowAddToGallery = allowAddToGallery;

			this._browserMimeTypes = new Dictionary<string, string>(1);
			if (String.IsNullOrEmpty(browserMimeType))
			{
				// When no browserMimeType is specified, default to the regular MIME type.
				browserMimeType = fullMimeType;
			}

			this._browserMimeTypes.Add(browserId, browserMimeType);
		}
Ejemplo n.º 24
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.º 25
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.º 26
0
		/// <summary>
		/// Create a minimally populated <see cref="ExternalMediaObject" /> instance from the specified parameters. 
		/// </summary>
		/// <param name="externalHtmlSource">The HTML that defines an externally stored media object, such as one hosted at 
		/// YouTube or Silverlight.live.com.</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>
		/// <param name="parentAlbum">The album in which the file exists (for media objects that already exist
		/// in the data store), or should be added to (for new media objects which need to be inserted into the 
		/// data store).</param>
		/// <param name="forceNew">Indicates whether to initialize a new, unsaved media object even if the imageFile
		/// parameter refers to an existing file in the album's directory. Typically used when copying an existing media 
		/// object where a subsequent operation will copy the existing file to the destination album, thus resulting in a
		/// new, independent media object.</param>
		/// <returns>Returns a minimally populated <see cref="ExternalMediaObject" /> instance from the specified parameters.</returns>
		public static IGalleryObject CreateExternalMediaObjectInstance(string externalHtmlSource, MimeTypeCategory mimeType, IAlbum parentAlbum, bool forceNew)
		{
#if DEBUG
			Tools.StartingMethod(externalHtmlSource, mimeType, parentAlbum);
#endif

			// If the file belongs to an existing media object, return a reference to it.
			if (!forceNew)
			{
				foreach (IGalleryObject childMediaObject in parentAlbum.GetChildGalleryObjects(GalleryObjectType.External))
				{
					if (childMediaObject.Original.ExternalHtmlSource == externalHtmlSource)
						return childMediaObject;
				}
			}

			if (forceNew) parentAlbum = null;

			// Create a new generic media object, which will cause a new record to be inserted in the data store when Save() is called.
			return new ExternalMediaObject(externalHtmlSource, mimeType, parentAlbum);
		}
Ejemplo n.º 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeType"/> class with the specified MIME type category. The <see cref="MajorType" /> property is
 /// assigned the string representation of the <paramref name="mimeType"/>. Remaining properties are set to empty strings or false 
 /// (<see cref="AllowAddToGallery" />). This method is intended to be used to help describe an external media object, which is
 /// not represented by a locally stored file but for which it is useful to describe its general type (audio, video, etc).
 /// </summary>
 /// <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>Returns a new instance of <see cref="IMimeType"/>.</returns>
 public static IMimeType CreateInstance(MimeTypeCategory mimeType)
 {
     return new MimeType(mimeType);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeType" /> class with the specified MIME type category and <paramref name="fileExtension" />.
 /// The <see cref="MajorType" /> property is assigned the string representation of the <paramref name="mimeType" />. Remaining properties
 /// are set to empty strings or false (<see cref="AllowAddToGallery" />). This method can be used to help describe an external media asset,
 /// which is not represented by a locally stored file but for which it is useful to describe its general type (audio, video, etc).
 /// </summary>
 /// <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>
 /// <param name="fileExtension">The file extension. Specify an empty string if no file extension is appropriate. (e.g. ".jpg")</param>
 /// <returns>Returns a new instance of <see cref="IMimeType" />.</returns>
 public static IMimeType CreateInstance(MimeTypeCategory mimeType, string fileExtension)
 {
     return(new MimeType(mimeType, fileExtension));
 }
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(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.º 30
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 = Config.GetCore().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.º 31
0
 /// <summary>
 /// Initializes a new instance of a ExternalMediaObject object.
 /// </summary>
 /// <param name="externalHtmlSource">The HTML that defines an externally stored media object, such as one hosted at
 /// YouTube or Silverlight.live.com.</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>
 /// <param name="parentAlbum">The album that contains this object. This is a required parameter.</param>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="parentAlbum" /> is null.</exception>
 internal ExternalMediaObject(string externalHtmlSource, MimeTypeCategory mimeType, IAlbum parentAlbum)
     : this(int.MinValue, parentAlbum, string.Empty, string.Empty, string.Empty, int.MinValue, int.MinValue, int.MinValue, externalHtmlSource, mimeType, int.MinValue, String.Empty,
            DateTime.MinValue, String.Empty, DateTime.MinValue, parentAlbum != null ? parentAlbum.IsPrivate : false, false)
 {
 }
Ejemplo n.º 32
0
		/// <summary>
		/// Initializes a new instance of a ExternalMediaObject object.
		/// </summary>
		/// <param name="externalHtmlSource">The HTML that defines an externally stored media object, such as one hosted at 
		/// YouTube or Silverlight.live.com.</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>
		/// <param name="parentAlbum">The album that contains this object. May be null.</param>
		internal ExternalMediaObject(string externalHtmlSource, MimeTypeCategory mimeType, IAlbum parentAlbum)
			: this(int.MinValue, parentAlbum != null ? parentAlbum.Id : int.MinValue, parentAlbum, string.Empty, string.Empty, string.Empty,
			       int.MinValue, int.MinValue, int.MinValue, string.Empty, int.MinValue, int.MinValue, int.MinValue, externalHtmlSource, mimeType, int.MinValue,
			       String.Empty, DateTime.MinValue, String.Empty, DateTime.MinValue, parentAlbum != null ? parentAlbum.IsPrivate : false, false)
		{
		}
Ejemplo n.º 33
0
		/// <summary>
		/// Initializes a new instance of a ExternalMediaObject object.
		/// </summary>
		/// <param name="id">The ID that uniquely identifies this object. Specify int.MinValue for a new object.</param>
		/// <param name="parentId">The ID of the album that contains this object.</param>
		/// <param name="parentAlbum">The album that contains this object.</param>
		/// <param name="title">The title of this image.</param>
		/// <param name="hashKey">The hash key that uniquely identifies the original file.</param>
		/// <param name="thumbnailFilename">The filename of the thumbnail image.</param>
		/// <param name="thumbnailWidth">The width (px) of the thumbnail image.</param>
		/// <param name="thumbnailHeight">The height (px) of the thumbnail image.</param>
		/// <param name="thumbnailSizeKb">The size (KB) of the thumbnail image.</param>
		/// <param name="originalFilename">The filename of the original image.</param>
		/// <param name="originalWidth">The width (px) of the original image.</param>
		/// <param name="originalHeight">The height (px) of the original image.</param>
		/// <param name="originalSizeKb">The size (KB) of the original image.</param>
		/// <param name="externalHtmlSource">The HTML that defines an externally stored media object, such as one hosted at 
		/// YouTube or Silverlight.live.com.</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>
		/// <param name="sequence">An integer that represents the order in which this image should appear when displayed.</param>
		/// <param name="createdByUsername">The user name of the account that originally added this object to the data store.</param>
		/// <param name="dateAdded">The date this image was added to the data store.</param>
		/// <param name="lastModifiedByUsername">The user name of the account that last modified this object.</param>
		/// <param name="dateLastModified">The date this object was last modified.</param>
		/// <param name="isPrivate">Indicates whether this object should be hidden from un-authenticated (anonymous) users.</param>
		/// <param name="isInflated">A bool indicating whether this object is fully inflated.</param>
		/// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.InvalidMediaObjectException">Thrown when 
		/// the file parameter is specified (not null) and the file it refers to is not in the same directory
		/// as the parent album's directory.</exception>
		internal ExternalMediaObject(int id, int parentId, IAlbum parentAlbum, string title, string hashKey, string thumbnailFilename,
		                             int thumbnailWidth, int thumbnailHeight, int thumbnailSizeKb, string originalFilename,
		                             int originalWidth, int originalHeight, int originalSizeKb, string externalHtmlSource, MimeTypeCategory mimeType, int sequence,
		                             string createdByUsername, DateTime dateAdded, string lastModifiedByUsername, DateTime dateLastModified,
		                             bool isPrivate, bool isInflated)
		{
			this.Id = id;
			this.Title = title;
			this.Sequence = sequence;
			this.Hashkey = hashKey;
			this.CreatedByUserName = createdByUsername;
			this.DateAdded = dateAdded;
			this.LastModifiedByUserName = lastModifiedByUsername;
			this.DateLastModified = dateLastModified;
			this.IsPrivate = isPrivate;

			// Set parent to album instance if present, otherwise create default Album instance if the album ID
			// is specified. If neither are specified, do not set parent (client will, however, need to set the
			// parent before saving).
			if (parentAlbum != null)
				this.Parent = parentAlbum;
			else if (parentId != int.MinValue)
				this.Parent = Factory.CreateAlbumInstance(parentId);

			string parentPhysicalPath = this.Parent.FullPhysicalPathOnDisk;

			// Thumbnail image
			this.Thumbnail = DisplayObject.CreateInstance(this, thumbnailFilename, thumbnailWidth, thumbnailHeight, DisplayObjectType.Thumbnail, new ExternalThumbnailCreator(this));
			this.Thumbnail.FileSizeKB = thumbnailSizeKb;
			if (thumbnailFilename.Length > 0)
			{
				// The thumbnail is stored in either the album's physical path or an alternate location (if thumbnailPath config setting is specified) .
				string thumbnailPath = HelperFunctions.MapAlbumDirectoryStructureToAlternateDirectory(parentPhysicalPath, AppSetting.Instance.ThumbnailPath);
				this.Thumbnail.FileNamePhysicalPath = System.IO.Path.Combine(thumbnailPath, thumbnailFilename);
			}

			// ExternalMediaObject instances do not have an optimized version.
			this.Optimized = new NullObjects.NullDisplayObject();

			// Original file
			this.Original = DisplayObject.CreateInstance(this, DisplayObjectType.External, mimeType);
			this.Original.ExternalHtmlSource = externalHtmlSource;

			switch (mimeType)
			{
				case MimeTypeCategory.Audio:
					this.Original.Width = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultAudioPlayerWidth;
					this.Original.Height = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultAudioPlayerHeight;
					break;
				case MimeTypeCategory.Video:
					this.Original.Width = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultVideoPlayerWidth;
					this.Original.Height = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultVideoPlayerHeight;
					break;
				case MimeTypeCategory.Image:
				case MimeTypeCategory.Other:
					this.Original.Width = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultGenericObjectWidth;
					this.Original.Height = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultGenericObjectHeight;
					break;
			}

			this.SaveBehavior = Factory.GetMediaObjectSaveBehavior(this);
			this.DeleteBehavior = Factory.GetMediaObjectDeleteBehavior(this);

			this.IsInflated = isInflated;

			// Setting the previous properties has caused HasChanges = true, but we don't want this while
			// we're instantiating a new object. Reset to false.
			this.HasChanges = false;

			// Set up our event handlers.
			//this.Saving += new EventHandler(Image_Saving); // Don't need
			this.Saved += new EventHandler(Image_Saved);
		}
Ejemplo n.º 34
0
        /// <summary>
        /// Initializes a new instance of a ExternalMediaObject object.
        /// </summary>
        /// <param name="id">The ID that uniquely identifies this object. Specify int.MinValue for a new object.</param>
        /// <param name="parentId">The ID of the album that contains this object.</param>
        /// <param name="parentAlbum">The album that contains this object.</param>
        /// <param name="title">The title of this image.</param>
        /// <param name="hashKey">The hash key that uniquely identifies the original file.</param>
        /// <param name="thumbnailFilename">The filename of the thumbnail image.</param>
        /// <param name="thumbnailWidth">The width (px) of the thumbnail image.</param>
        /// <param name="thumbnailHeight">The height (px) of the thumbnail image.</param>
        /// <param name="thumbnailSizeKb">The size (KB) of the thumbnail image.</param>
        /// <param name="originalFilename">The filename of the original image.</param>
        /// <param name="originalWidth">The width (px) of the original image.</param>
        /// <param name="originalHeight">The height (px) of the original image.</param>
        /// <param name="originalSizeKb">The size (KB) of the original image.</param>
        /// <param name="externalHtmlSource">The HTML that defines an externally stored media object, such as one hosted at
        /// YouTube or Silverlight.live.com.</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>
        /// <param name="sequence">An integer that represents the order in which this image should appear when displayed.</param>
        /// <param name="createdByUsername">The user name of the account that originally added this object to the data store.</param>
        /// <param name="dateAdded">The date this image was added to the data store.</param>
        /// <param name="lastModifiedByUsername">The user name of the account that last modified this object.</param>
        /// <param name="dateLastModified">The date this object was last modified.</param>
        /// <param name="isPrivate">Indicates whether this object should be hidden from un-authenticated (anonymous) users.</param>
        /// <param name="isInflated">A bool indicating whether this object is fully inflated.</param>
        /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.InvalidMediaObjectException">Thrown when
        /// the file parameter is specified (not null) and the file it refers to is not in the same directory
        /// as the parent album's directory.</exception>
        internal ExternalMediaObject(int id, int parentId, IAlbum parentAlbum, string title, string hashKey, string thumbnailFilename,
                                     int thumbnailWidth, int thumbnailHeight, int thumbnailSizeKb, string originalFilename,
                                     int originalWidth, int originalHeight, int originalSizeKb, string externalHtmlSource, MimeTypeCategory mimeType, int sequence,
                                     string createdByUsername, DateTime dateAdded, string lastModifiedByUsername, DateTime dateLastModified,
                                     bool isPrivate, bool isInflated)
        {
            this.Id                     = id;
            this.Title                  = title;
            this.Sequence               = sequence;
            this.Hashkey                = hashKey;
            this.CreatedByUserName      = createdByUsername;
            this.DateAdded              = dateAdded;
            this.LastModifiedByUserName = lastModifiedByUsername;
            this.DateLastModified       = dateLastModified;
            this.IsPrivate              = isPrivate;

            // Set parent to album instance if present, otherwise create default Album instance if the album ID
            // is specified. If neither are specified, do not set parent (client will, however, need to set the
            // parent before saving).
            if (parentAlbum != null)
            {
                this.Parent = parentAlbum;
            }
            else if (parentId != int.MinValue)
            {
                this.Parent = Factory.CreateAlbumInstance(parentId);
            }

            string parentPhysicalPath = this.Parent.FullPhysicalPathOnDisk;

            // Thumbnail image
            this.Thumbnail            = DisplayObject.CreateInstance(this, thumbnailFilename, thumbnailWidth, thumbnailHeight, DisplayObjectType.Thumbnail, new ExternalThumbnailCreator(this));
            this.Thumbnail.FileSizeKB = thumbnailSizeKb;
            if (thumbnailFilename.Length > 0)
            {
                // The thumbnail is stored in either the album's physical path or an alternate location (if thumbnailPath config setting is specified) .
                string thumbnailPath = HelperFunctions.MapAlbumDirectoryStructureToAlternateDirectory(parentPhysicalPath, AppSetting.Instance.ThumbnailPath);
                this.Thumbnail.FileNamePhysicalPath = System.IO.Path.Combine(thumbnailPath, thumbnailFilename);
            }

            // ExternalMediaObject instances do not have an optimized version.
            this.Optimized = new NullObjects.NullDisplayObject();

            // Original file
            this.Original = DisplayObject.CreateInstance(this, DisplayObjectType.External, mimeType);
            this.Original.ExternalHtmlSource = externalHtmlSource;

            switch (mimeType)
            {
            case MimeTypeCategory.Audio:
                this.Original.Width  = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultAudioPlayerWidth;
                this.Original.Height = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultAudioPlayerHeight;
                break;

            case MimeTypeCategory.Video:
                this.Original.Width  = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultVideoPlayerWidth;
                this.Original.Height = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultVideoPlayerHeight;
                break;

            case MimeTypeCategory.Image:
            case MimeTypeCategory.Other:
                this.Original.Width  = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultGenericObjectWidth;
                this.Original.Height = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultGenericObjectHeight;
                break;
            }

            this.SaveBehavior   = Factory.GetMediaObjectSaveBehavior(this);
            this.DeleteBehavior = Factory.GetMediaObjectDeleteBehavior(this);

            this.IsInflated = isInflated;

            // Setting the previous properties has caused HasChanges = true, but we don't want this while
            // we're instantiating a new object. Reset to false.
            this.HasChanges = false;

            // Set up our event handlers.
            //this.Saving += new EventHandler(Image_Saving); // Don't need
            this.Saved += new EventHandler(Image_Saved);
        }