/// <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;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of an <see cref="Video" /> 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 image 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="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="videoFile">A <see cref="FileInfo"/> object containing the original video file for this object. This is intended to be
        /// specified when creating a new media object from a file. Specify null when instantiating an object for an existing database
        /// record.</param>
        /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.InvalidMediaObjectException">Thrown when
        /// <paramref name="videoFile"/> 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="GalleryServerPro.ErrorHandler.CustomExceptions.UnsupportedMediaObjectTypeException">Thrown when
        /// <paramref name="videoFile"/> is specified (not null) and its file extension does not correspond to an video MIME
        /// type, as determined by the MIME type definition in the configuration file.</exception>
        /// <remarks>This constructor does not verify that <paramref name="videoFile"/> refers to a file type that is enabled in the
        /// configuration file.</remarks>
        internal Video(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, int sequence, string createdByUsername, DateTime dateAdded, string lastModifiedByUsername, DateTime dateLastModified, bool isPrivate, bool isInflated, FileInfo videoFile)
        {
            System.Diagnostics.Debug.Assert(((originalFilename.Length > 0) || (videoFile != null)), "Invalid Video constructor arguments: The original filename or a FileInfo reference to the original file must be passed to the Video constructor.");

            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 GenericThumbnailCreator(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);
            }

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

            // Original video file
            this.Original = DisplayObject.CreateInstance(this, originalFilename, originalWidth, originalHeight, DisplayObjectType.Original, new NullObjects.NullDisplayObjectCreator());
            this.Original.ExternalHtmlSource = String.Empty;
            this.Original.ExternalType       = MimeTypeCategory.NotSet;

            if (videoFile != null)
            {
                this.Hashkey           = HelperFunctions.GetHashKeyUnique(videoFile);
                this.Original.FileInfo = videoFile;                 // Will throw InvalidMediaObjectException if the file's directory is not the same as the album's directory.

                if (this.Original.MimeType.TypeCategory != MimeTypeCategory.Video)
                {
                    throw new GalleryServerPro.ErrorHandler.CustomExceptions.UnsupportedMediaObjectTypeException(this.Original.FileInfo);
                }

                if (String.IsNullOrEmpty(title))
                {
                    this.Title = videoFile.Name;
                }
                this.Original.Width  = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultVideoPlayerWidth;
                this.Original.Height = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultVideoPlayerHeight;

                int fileSize = (int)(videoFile.Length / 1024);
                this.Original.FileSizeKB = (fileSize < 1 ? 1 : fileSize);                 // Very small files should be 1, not 0.
            }
            else
            {
                this.Original.FileNamePhysicalPath = System.IO.Path.Combine(parentPhysicalPath, originalFilename);
                this.Original.FileSizeKB           = originalSizeKb;
            }

            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 += Image_Saved;
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of a <see cref="GenericMediaObject" /> 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="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="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="file">A <see cref="FileInfo"/> object containing the original file for this object. This is intended to be
        /// specified when creating a new media object from a file. Specify null when instantiating an object for an existing database
        /// record.</param>
        /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.InvalidMediaObjectException">Thrown when
        /// the <paramref name="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>
        /// <remarks>This constructor does not verify that <paramref name="file"/> refers to a file type that is enabled in the
        /// configuration file.</remarks>
        internal GenericMediaObject(int id, IAlbum parentAlbum, string title, string hashKey, string thumbnailFilename,
                                    int thumbnailWidth, int thumbnailHeight, int thumbnailSizeKb, string originalFilename,
                                    int originalWidth, int originalHeight, int originalSizeKb, int sequence,
                                    string createdByUsername, DateTime dateAdded, string lastModifiedByUsername, DateTime dateLastModified,
                                    bool isPrivate, bool isInflated, System.IO.FileInfo file)
        {
            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 GenericThumbnailCreator(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);
            }

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

            // Original file
            this.Original = DisplayObject.CreateInstance(this, originalFilename, originalWidth, originalHeight, DisplayObjectType.Original, new NullObjects.NullDisplayObjectCreator());
            this.Original.ExternalHtmlSource = String.Empty;
            this.Original.ExternalType       = MimeTypeCategory.NotSet;

            if (file != null)
            {
                this.Hashkey           = HelperFunctions.GetHashKeyUnique(file);
                this.Original.FileInfo = file;                 // Will throw InvalidMediaObjectException if the file's directory is not the same as the album's directory.

                if (this.MimeType.TypeCategory == MimeTypeCategory.Other)
                {
                    // Specify a default width and height for any object other than audio, video, and image. We leave those to their default
                    // value of int.MinValue because we do not accurately know their real width and height. For example, a corrupt image file
                    // will be rejected by the Image class (an UnsupportedImageTypeException is thrown) and will be routed to this class instead.
                    // In this case, we don't know it's real width and height. Similarly, audio and video files are normally handled by the
                    // Audio and Video classes. If one of them ends up here, we need to treat it generically and not assign a width and height.
                    this.Original.Width  = gallerySetting.DefaultGenericObjectWidth;
                    this.Original.Height = gallerySetting.DefaultGenericObjectHeight;
                }

                int fileSize = (int)(file.Length / 1024);
                this.Original.FileSizeKB = (fileSize < 1 ? 1 : fileSize);                 // Very small files should be 1, not 0.

                if (gallerySetting.ExtractMetadata)
                {
                    // Get the metadata found in the original file.
                    MediaObjectMetadataExtractor metadata = new MediaObjectMetadataExtractor(file.FullName, this.GalleryId);
                    MetadataItems.AddRange(metadata.GetGalleryObjectMetadataItemCollection());
                }

                // Assign the title based on the template, resorting to the filename if necessary.
                if (String.IsNullOrEmpty(title))
                {
                    SetTitle(gallerySetting.MediaObjectCaptionTemplate);

                    if (String.IsNullOrEmpty(this.Title))
                    {
                        this.Title = file.Name;
                    }
                }
            }
            else
            {
                this.Original.FileNamePhysicalPath = System.IO.Path.Combine(parentPhysicalPath, originalFilename);
                this.Original.FileSizeKB           = originalSizeKb;
            }

            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 += Image_Saved;
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of an <see cref="Image" /> object.
        /// </summary>
        /// <param name="id">The <see cref="GalleryObject.Id">ID</see> 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="optimizedFilename">The filename of the optimized image.</param>
        /// <param name="optimizedWidth">The width (px) of the optimized image.</param>
        /// <param name="optimizedHeight">The height (px) of the optimized image.</param>
        /// <param name="optimizedSizeKb">The size (KB) of the optimized 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="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="imageFile">A <see cref="FileInfo"/> object containing the original image for this object. This is intended to be
        ///   specified when creating a new media object from a file. Specify null when instantiating an object for an existing database
        ///   record.</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
        /// <paramref name="imageFile"/> 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="GalleryServerPro.Events.CustomExceptions.UnsupportedMediaObjectTypeException">Thrown when
        /// <paramref name="imageFile"/> is specified (not null) and its file extension does not correspond to an image MIME
        /// type, as determined by the MIME type definition in the configuration file.</exception>
        /// <exception cref="GalleryServerPro.Events.CustomExceptions.UnsupportedImageTypeException">Thrown when the
        /// .NET Framework is unable to load an image file into the <see cref="System.Drawing.Bitmap"/> class. This is
        /// probably because it is corrupted, not an image supported by the .NET Framework, or the server does not have
        /// enough memory to process the image. The file cannot, therefore, be handled using the <see cref="Image"/>
        /// class; use <see cref="GenericMediaObject"/> instead. This exception is thrown only when <paramref name="imageFile"/>
        /// is specified (non-null).</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="parentAlbum" /> is null.</exception>
        /// <remarks>This constructor does not verify that <paramref name="imageFile"/> refers to a file type that is enabled in the
        /// configuration file.</remarks>
        internal Image(int id, IAlbum parentAlbum, string thumbnailFilename, int thumbnailWidth, int thumbnailHeight, int thumbnailSizeKb, string optimizedFilename, int optimizedWidth, int optimizedHeight, int optimizedSizeKb, string originalFilename, int originalWidth, int originalHeight, int originalSizeKb, int sequence, string createdByUsername, DateTime dateAdded, string lastModifiedByUsername, DateTime dateLastModified, bool isPrivate, bool isInflated, FileInfo imageFile, 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 ImageThumbnailCreator(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);
            }

            // Optimized image
            this.Optimized            = DisplayObject.CreateInstance(this, optimizedFilename, optimizedWidth, optimizedHeight, DisplayObjectType.Optimized, new ImageOptimizedCreator(this));
            this.Optimized.FileSizeKB = optimizedSizeKb;
            if (optimizedFilename.Length > 0)
            {
                // Calcululate the full file path to the optimized image. If the optimized filename is equal to the original filename, then no
                // optimized version exists, and we'll just point to the original. If the names are different, then there is a separate optimized
                // image file, and it is stored in either the album's physical path or an alternate location (if optimizedPath config setting is specified).
                string optimizedPath = parentPhysicalPath;

                if (optimizedFilename != originalFilename)
                {
                    optimizedPath = HelperFunctions.MapAlbumDirectoryStructureToAlternateDirectory(parentPhysicalPath, gallerySetting.FullOptimizedPath, gallerySetting.FullMediaObjectPath);
                }

                this.Optimized.FileNamePhysicalPath = System.IO.Path.Combine(optimizedPath, optimizedFilename);
            }

            // Original image
            this.Original = DisplayObject.CreateInstance(this, originalFilename, originalWidth, originalHeight, DisplayObjectType.Original, new ImageOriginalCreator(this));
            this.Original.ExternalHtmlSource = String.Empty;
            this.Original.ExternalType       = MimeTypeCategory.NotSet;

            if (imageFile != null)
            {
                this.Original.FileInfo = imageFile;                 // Will throw InvalidMediaObjectException if the file's directory is not the same as the album's directory.

                if (this.Original.MimeType.TypeCategory != MimeTypeCategory.Image)
                {
                    throw new GalleryServerPro.Events.CustomExceptions.UnsupportedMediaObjectTypeException(this.Original.FileInfo);
                }

                var size = this.Original.GetSize();
                if (!size.IsEmpty)
                {
                    this.Original.Width  = (int)size.Width;
                    this.Original.Height = (int)size.Height;
                }

                int fileSize = (int)(imageFile.Length / 1024);
                this.Original.FileSizeKB = (fileSize < 1 ? 1 : fileSize);                 // Very small files should be 1, not 0.

                // Get metadata from the image file.
                if (IsNew)
                {
                    try
                    {
                        ExtractMetadata();
                    }
                    catch (OutOfMemoryException ex)
                    {
                        this.Parent.RemoveGalleryObject(this);
                        throw new GalleryServerPro.Events.CustomExceptions.UnsupportedImageTypeException(this, ex);
                    }
                }
            }
            else
            {
                this.Original.FileNamePhysicalPath = System.IO.Path.Combine(parentPhysicalPath, originalFilename);
                this.Original.FileSizeKB           = originalSizeKb;
            }

            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;
        }
        /// <summary>
        /// Initializes a new instance of a <see cref="GenericMediaObject" /> 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="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="file">A <see cref="FileInfo"/> object containing the original file for this object. This is intended to be
        /// specified when creating a new media object from a file. Specify null when instantiating an object for an existing database
        /// record.</param>
        /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.InvalidMediaObjectException">Thrown when
        /// the <paramref name="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>
        /// <remarks>This constructor does not verify that <paramref name="file"/> refers to a file type that is enabled in the
        /// configuration file.</remarks>
        internal GenericMediaObject(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, int sequence,
                                    string createdByUsername, DateTime dateAdded, string lastModifiedByUsername, DateTime dateLastModified,
                                    bool isPrivate, bool isInflated, System.IO.FileInfo file)
        {
            System.Diagnostics.Debug.Assert(((originalFilename.Length > 0) || (file != null)), "Invalid GenericMediaObject constructor arguments: The original filename or a FileInfo reference to the original file must be passed to the GenericMediaObject constructor.");

            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 GenericThumbnailCreator(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);
            }

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

            // Original file
            this.Original = DisplayObject.CreateInstance(this, originalFilename, originalWidth, originalHeight, DisplayObjectType.Original, new NullObjects.NullDisplayObjectCreator());
            this.Original.ExternalHtmlSource = String.Empty;
            this.Original.ExternalType       = MimeTypeCategory.NotSet;

            if (file != null)
            {
                this.Hashkey           = HelperFunctions.GetHashKeyUnique(file);
                this.Original.FileInfo = file;                 // Will throw InvalidMediaObjectException if the file's directory is not the same as the album's directory.

                if (String.IsNullOrEmpty(title))
                {
                    this.Title = file.Name;
                }

                if (this.MimeType.TypeCategory == MimeTypeCategory.Other)
                {
                    // Specify a default width and height for any object other than audio, video, and image. We leave those to their default
                    // value of int.MinValue because we do not accurately know their real width and height. For example, a corrupt image file
                    // will be rejected by the Image class (an UnsupportedImageTypeException is thrown) and will be routed to this class instead.
                    // In this case, we don't know it's real width and height. Similarly, audio and video files are normally handled by the
                    // Audio and Video classes. If one of them ends up here, we need to treat it generically and not assign a width and height.
                    this.Original.Width  = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultGenericObjectWidth;
                    this.Original.Height = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().Core.DefaultGenericObjectHeight;
                }

                int fileSize = (int)(file.Length / 1024);
                this.Original.FileSizeKB = (fileSize < 1 ? 1 : fileSize);                 // Very small files should be 1, not 0.
            }
            else
            {
                this.Original.FileNamePhysicalPath = System.IO.Path.Combine(parentPhysicalPath, originalFilename);
                this.Original.FileSizeKB           = originalSizeKb;
            }

            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 += Image_Saved;
        }
Beispiel #6
0
        /// <summary>
        /// Initializes a new instance of an <see cref="Image" /> object.
        /// </summary>
        /// <param name="id">The <see cref="GalleryObject.Id">ID</see> 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 image 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="optimizedFilename">The filename of the optimized image.</param>
        /// <param name="optimizedWidth">The width (px) of the optimized image.</param>
        /// <param name="optimizedHeight">The height (px) of the optimized image.</param>
        /// <param name="optimizedSizeKb">The size (KB) of the optimized 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="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="imageFile">A <see cref="FileInfo"/> object containing the original image for this object. This is intended to be
        /// specified when creating a new media object from a file. Specify null when instantiating an object for an existing database
        /// record.</param>
        /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.InvalidMediaObjectException">Thrown when
        /// <paramref name="imageFile"/> 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="GalleryServerPro.ErrorHandler.CustomExceptions.UnsupportedMediaObjectTypeException">Thrown when
        /// <paramref name="imageFile"/> is specified (not null) and its file extension does not correspond to an image MIME
        /// type, as determined by the MIME type definition in the configuration file.</exception>
        /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.UnsupportedImageTypeException">Thrown when the
        /// .NET Framework is unable to load an image file into the <see cref="System.Drawing.Bitmap"/> class. This is
        /// probably because it is corrupted, not an image supported by the .NET Framework, or the server does not have
        /// enough memory to process the image. The file cannot, therefore, be handled using the <see cref="Image"/>
        /// class; use <see cref="GenericMediaObject"/> instead. This exception is thrown only when <paramref name="imageFile"/>
        /// is specified (non-null).</exception>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="parentAlbum" /> is null.</exception>
        /// <remarks>This constructor does not verify that <paramref name="imageFile"/> refers to a file type that is enabled in the
        /// configuration file.</remarks>
        internal Image(int id, IAlbum parentAlbum, string title, string hashKey, string thumbnailFilename, int thumbnailWidth, int thumbnailHeight, int thumbnailSizeKb, string optimizedFilename, int optimizedWidth, int optimizedHeight, int optimizedSizeKb, string originalFilename, int originalWidth, int originalHeight, int originalSizeKb, int sequence, string createdByUsername, DateTime dateAdded, string lastModifiedByUsername, DateTime dateLastModified, bool isPrivate, bool isInflated, FileInfo imageFile)
        {
            if (parentAlbum == null)
            {
                throw new ArgumentNullException("parentAlbum");
            }

            System.Diagnostics.Debug.Assert(((originalFilename.Length > 0) || (imageFile != null)), "Invalid Image constructor arguments: The original filename or a FileInfo reference to the original file must be passed to the Image constructor.");

            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 ImageThumbnailCreator(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);
            }

            // Optimized image
            this.Optimized            = DisplayObject.CreateInstance(this, optimizedFilename, optimizedWidth, optimizedHeight, DisplayObjectType.Optimized, new ImageOptimizedCreator(this));
            this.Optimized.FileSizeKB = optimizedSizeKb;
            if (optimizedFilename.Length > 0)
            {
                // Calcululate the full file path to the optimized image. If the optimized filename is equal to the original filename, then no
                // optimized version exists, and we'll just point to the original. If the names are different, then there is a separate optimized
                // image file, and it is stored in either the album's physical path or an alternate location (if optimizedPath config setting is specified).
                string optimizedPath = parentPhysicalPath;

                if (optimizedFilename != originalFilename)
                {
                    optimizedPath = HelperFunctions.MapAlbumDirectoryStructureToAlternateDirectory(parentPhysicalPath, gallerySetting.FullOptimizedPath, gallerySetting.FullMediaObjectPath);
                }

                this.Optimized.FileNamePhysicalPath = System.IO.Path.Combine(optimizedPath, optimizedFilename);
            }

            // Original image
            this.Original = DisplayObject.CreateInstance(this, originalFilename, originalWidth, originalHeight, DisplayObjectType.Original, new ImageOriginalCreator(this));
            this.Original.ExternalHtmlSource = String.Empty;
            this.Original.ExternalType       = MimeTypeCategory.NotSet;

            if (imageFile != null)
            {
                this.Hashkey           = HelperFunctions.GetHashKeyUnique(imageFile);
                this.Original.FileInfo = imageFile;                 // Will throw InvalidMediaObjectException if the file's directory is not the same as the album's directory.

                if (this.Original.MimeType.TypeCategory != MimeTypeCategory.Image)
                {
                    throw new GalleryServerPro.ErrorHandler.CustomExceptions.UnsupportedMediaObjectTypeException(this.Original.FileInfo);
                }

                try
                {
                    this.Original.Width  = this.Original.Bitmap.Width;
                    this.Original.Height = this.Original.Bitmap.Height;
                }
                catch (GalleryServerPro.ErrorHandler.CustomExceptions.UnsupportedImageTypeException) { }

                int fileSize = (int)(imageFile.Length / 1024);
                this.Original.FileSizeKB = (fileSize < 1 ? 1 : fileSize);                 // Very small files should be 1, not 0.

                // Get metadata from the image file.
                if (gallerySetting.ExtractMetadata)
                {
                    try
                    {
                        MediaObjectMetadataExtractor metadata = new MediaObjectMetadataExtractor(imageFile.FullName, this.GalleryId);
                        this.MetadataItems.AddRange(metadata.GetGalleryObjectMetadataItemCollection());
                    }
                    catch (OutOfMemoryException ex)
                    {
                        // Normally, the Dispose method is called during the Image_Saved event. But when we get this exception, it
                        // never executes and therefore doesn't release the file lock. So we explicitly do so here and then
                        // throw a new exception.
                        this.Original.Dispose();
                        this.Parent.Remove(this);
                        throw new GalleryServerPro.ErrorHandler.CustomExceptions.UnsupportedImageTypeException(this, ex);
                    }
                }
                this.ExtractMetadataOnSave = false;

                // Assign the title based on the template, resorting to the filename if necessary.
                if (String.IsNullOrEmpty(title))
                {
                    SetTitle(gallerySetting.MediaObjectCaptionTemplate);

                    if (String.IsNullOrEmpty(this.Title))
                    {
                        this.Title = imageFile.Name;
                    }
                }
            }
            else
            {
                this.Original.FileNamePhysicalPath = System.IO.Path.Combine(parentPhysicalPath, originalFilename);
                this.Original.FileSizeKB           = originalSizeKb;
            }

            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 += Image_Saved;
        }
Beispiel #7
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);
        }