/// <summary> /// Create a fully inflated, properly typed instance based on the specified parameters. If the galleryObjectType /// parameter is All, None, or Unknown, then an additional call to the data store is made /// to determine the object's type. If no object is found that matches the ID and gallery object type, an /// <see cref="UnsupportedMediaObjectTypeException" /> exception is thrown. When you know the type you want (<see cref="Album" />, /// <see cref="Image" />, etc), specify the exact galleryObjectType, or call the specific Factory method that /// loads the desired type, as that is more efficient. This method is guaranteed to not return null. /// </summary> /// <param name="id">An integer representing the <see cref="IGalleryObject.Id">ID</see> of the media object or album to retrieve from the /// data store.</param> /// <param name="galleryObjectType">The type of gallery object that the id parameter represents. If the type is /// unknown, the Unknown enum value can be specified. Specify the actual type if possible (e.g. Video, Audio, Image, /// etc.), as it is more efficient.</param> /// <returns>Returns an <see cref="IGalleryObject" /> based on the ID. This method is guaranteed to not return null.</returns> /// <exception cref="UnsupportedMediaObjectTypeException">Thrown when a particular media object type is requested (e.g. Image, Video, etc.), /// but no media object with the specified ID is found in the data store.</exception> /// <exception cref="InvalidAlbumException">Thrown when an album is requested but no album with the specified ID is found in the data store.</exception> public static IGalleryObject LoadGalleryObjectInstance(int id, GalleryObjectType galleryObjectType) { // If the gallery object type is vague, we need to figure it out. if ((galleryObjectType == GalleryObjectType.All) || (galleryObjectType == GalleryObjectType.None) || (galleryObjectType == GalleryObjectType.Unknown)) { galleryObjectType = HelperFunctions.DetermineGalleryObjectType(id); } IGalleryObject go = new NullObjects.NullGalleryObject(); switch (galleryObjectType) { case GalleryObjectType.Album: { go = Factory.LoadAlbumInstance(id, false); break; } case GalleryObjectType.Image: { go = Factory.LoadImageInstance(id); break; } case GalleryObjectType.Video: { go = Factory.LoadVideoInstance(id); break; } case GalleryObjectType.Audio: { go = Factory.LoadAudioInstance(id); break; } case GalleryObjectType.Generic: case GalleryObjectType.Unknown: { go = Factory.LoadGenericMediaObjectInstance(id); break; } default: { throw new UnsupportedMediaObjectTypeException(); } } return go; }
private IDisplayObject GetDefaultAlbumThumbnail() { string defaultFilename = String.Empty; IGallerySettings gallerySetting = Factory.LoadGallerySetting(GalleryId); int maxLength = gallerySetting.MaxThumbnailLength; float ratio = gallerySetting.EmptyAlbumThumbnailWidthToHeightRatio; int width, height; if (ratio > 1) { width = maxLength; height = Convert.ToInt32((float)maxLength / ratio); } else { height = maxLength; width = Convert.ToInt32((float)maxLength * ratio); } IDisplayObject albumThumbnail = null; NullGalleryObject nullGalleryObject = null; try { nullGalleryObject = new NullGalleryObject(); albumThumbnail = DisplayObject.CreateInstance(nullGalleryObject, defaultFilename, width, height, DisplayObjectType.Thumbnail, new NullDisplayObjectCreator()); albumThumbnail.MediaObjectId = this._thumbnailMediaObjectId; albumThumbnail.FileNamePhysicalPath = defaultFilename; } catch (Exception) { if (albumThumbnail != null) albumThumbnail.Dispose(); if (nullGalleryObject != null) nullGalleryObject.Dispose(); throw; } return albumThumbnail; }
/// <summary> /// Gets a writable collection of the gallery objects in the album containing <paramref name="galleryItem" />, including /// <paramref name="galleryItem" />. If <paramref name="galleryItem" /> does not represent a valid object, an empty /// collection is returned. Guaranteed to not return null. /// </summary> /// <param name="galleryItem">A gallery item. The object must have the <see cref="GalleryItem.Id" /> and /// <see cref="GalleryItem.ItemType" /> properties specified; the others are optional.</param> /// <returns>An instance of <see cref="IGalleryObjectCollection" />.</returns> private static IGalleryObjectCollection GetWritableSiblingGalleryObjects(GalleryItem galleryItem) { IGalleryObject parentAlbum; try { int parentAlbumId; if ((GalleryObjectType)galleryItem.ItemType == GalleryObjectType.Album) { parentAlbumId = LoadAlbumInstance(galleryItem.Id, false).Parent.Id; } else { parentAlbumId = Factory.LoadMediaObjectInstance(galleryItem.Id).Parent.Id; } parentAlbum = LoadAlbumInstance(parentAlbumId, true, true); } catch (InvalidAlbumException) { parentAlbum = new NullGalleryObject(); } catch (InvalidMediaObjectException) { parentAlbum = new NullGalleryObject(); } return parentAlbum.GetChildGalleryObjects(); }
/// <summary> /// Create a fully inflated, properly typed media object instance based on the specified data record and /// belonging to the specified parent album. /// </summary> /// <param name="dr">A data record containing information about the media object.</param> /// <param name="parentAlbum">The album that contains the media obect to be returned.</param> /// <returns>Returns a fully inflated, properly typed media object instance based on the specified data /// record and belonging to the specified parent album.</returns> public static IGalleryObject LoadMediaObjectInstance(IDataRecord dr, IAlbum parentAlbum) { // SQL: // SELECT // mo.MediaObjectID, mo.FKAlbumID, mo.Title, mo.HashKey, mo.ThumbnailFilename, mo.ThumbnailWidth, mo.ThumbnailHeight, // mo.ThumbnailSizeKB, mo.OptimizedFilename, mo.OptimizedWidth, mo.OptimizedHeight, mo.OptimizedSizeKB, // mo.OriginalFilename, mo.OriginalWidth, mo.OriginalHeight, mo.OriginalSizeKB, mo.ExternalHtmlSource, mo.ExternalType, mo.Seq, // mo.CreatedBy, mo.DateAdded, mo.LastModifiedBy, mo.DateLastModified, mo.IsPrivate // FROM [gs_MediaObject] mo JOIN [gs_Album] a ON mo.FKAlbumID = a.AlbumID // WHERE mo.MediaObjectID = @MediaObjectId AND a.FKGalleryID = @GalleryID if (dr == null) throw new ArgumentNullException("dr"); GalleryObjectType goType = HelperFunctions.DetermineMediaObjectType(dr["OriginalFilename"].ToString(), Convert.ToInt32(dr["OriginalWidth"]), Convert.ToInt32(dr["OriginalHeight"]), dr["ExternalHtmlSource"].ToString()); IGalleryObject go = new NullObjects.NullGalleryObject(); switch (goType) { case GalleryObjectType.Image: { #region Create Image go = new Image( Int32.Parse(dr["MediaObjectId"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["FKAlbumID"].ToString(), CultureInfo.InvariantCulture), parentAlbum, dr["Title"].ToString().Trim(), dr["HashKey"].ToString().Trim(), dr["ThumbnailFilename"].ToString(), Int32.Parse(dr["ThumbnailWidth"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["ThumbnailHeight"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["ThumbnailSizeKB"].ToString(), CultureInfo.InvariantCulture), dr["OptimizedFilename"].ToString().Trim(), Int32.Parse(dr["OptimizedWidth"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["OptimizedHeight"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["OptimizedSizeKB"].ToString(), CultureInfo.InvariantCulture), dr["OriginalFilename"].ToString().Trim(), Int32.Parse(dr["OriginalWidth"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["OriginalHeight"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["OriginalSizeKB"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["Seq"].ToString(), CultureInfo.InvariantCulture), dr["CreatedBy"].ToString().Trim(), Convert.ToDateTime(dr["DateAdded"].ToString(), CultureInfo.CurrentCulture), dr["LastModifiedBy"].ToString().Trim(), HelperFunctions.ToDateTime(dr["DateLastModified"]), Convert.ToBoolean(dr["IsPrivate"].ToString(), CultureInfo.CurrentCulture), true, null); AddMediaObjectMetadata(go); break; #endregion } case GalleryObjectType.Video: { #region Create Video go = new Video( Int32.Parse(dr["MediaObjectId"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["FKAlbumID"].ToString(), CultureInfo.InvariantCulture), parentAlbum, // If null, Image ctor uses the previous parameter to do an Album CreateInstance. dr["Title"].ToString().Trim(), dr["HashKey"].ToString().Trim(), dr["ThumbnailFilename"].ToString(), Int32.Parse(dr["ThumbnailWidth"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["ThumbnailHeight"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["ThumbnailSizeKB"].ToString(), CultureInfo.InvariantCulture), dr["OriginalFilename"].ToString().Trim(), Int32.Parse(dr["OriginalWidth"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["OriginalHeight"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["OriginalSizeKB"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["Seq"].ToString(), CultureInfo.InvariantCulture), dr["CreatedBy"].ToString().Trim(), Convert.ToDateTime(dr["DateAdded"].ToString(), CultureInfo.CurrentCulture), dr["LastModifiedBy"].ToString().Trim(), HelperFunctions.ToDateTime(dr["DateLastModified"]), Convert.ToBoolean(dr["IsPrivate"].ToString(), CultureInfo.CurrentCulture), true, null); break; #endregion } case GalleryObjectType.Audio: { #region Create Audio go = new Audio( Int32.Parse(dr["MediaObjectId"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["FKAlbumID"].ToString(), CultureInfo.InvariantCulture), parentAlbum, // If null, Image ctor uses the previous parameter to do an Album CreateInstance. dr["Title"].ToString().Trim(), dr["HashKey"].ToString().Trim(), dr["ThumbnailFilename"].ToString(), Int32.Parse(dr["ThumbnailWidth"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["ThumbnailHeight"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["ThumbnailSizeKB"].ToString(), CultureInfo.InvariantCulture), dr["OriginalFilename"].ToString().Trim(), Int32.Parse(dr["OriginalWidth"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["OriginalHeight"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["OriginalSizeKB"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["Seq"].ToString(), CultureInfo.InvariantCulture), dr["CreatedBy"].ToString().Trim(), Convert.ToDateTime(dr["DateAdded"].ToString(), CultureInfo.CurrentCulture), dr["LastModifiedBy"].ToString().Trim(), HelperFunctions.ToDateTime(dr["DateLastModified"]), Convert.ToBoolean(dr["IsPrivate"].ToString(), CultureInfo.CurrentCulture), true, null); break; #endregion } case GalleryObjectType.Generic: case GalleryObjectType.Unknown: { #region Create Generic Media Object go = new GenericMediaObject( Int32.Parse(dr["MediaObjectId"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["FKAlbumID"].ToString(), CultureInfo.InvariantCulture), parentAlbum, // If null, Image ctor uses the previous parameter to do an Album CreateInstance. dr["Title"].ToString().Trim(), dr["HashKey"].ToString().Trim(), dr["ThumbnailFilename"].ToString(), Int32.Parse(dr["ThumbnailWidth"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["ThumbnailHeight"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["ThumbnailSizeKB"].ToString(), CultureInfo.InvariantCulture), dr["OriginalFilename"].ToString().Trim(), Int32.Parse(dr["OriginalWidth"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["OriginalHeight"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["OriginalSizeKB"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["Seq"].ToString(), CultureInfo.InvariantCulture), dr["CreatedBy"].ToString().Trim(), Convert.ToDateTime(dr["DateAdded"].ToString(), CultureInfo.CurrentCulture), dr["LastModifiedBy"].ToString().Trim(), HelperFunctions.ToDateTime(dr["DateLastModified"]), Convert.ToBoolean(dr["IsPrivate"].ToString(), CultureInfo.CurrentCulture), true, null); break; #endregion } case GalleryObjectType.External: { #region Create External go = new ExternalMediaObject( Int32.Parse(dr["MediaObjectId"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["FKAlbumID"].ToString(), CultureInfo.InvariantCulture), parentAlbum, // If null, Image ctor uses the previous parameter to do an Album CreateInstance. dr["Title"].ToString().Trim(), dr["HashKey"].ToString().Trim(), dr["ThumbnailFilename"].ToString(), Int32.Parse(dr["ThumbnailWidth"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["ThumbnailHeight"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["ThumbnailSizeKB"].ToString(), CultureInfo.InvariantCulture), dr["OriginalFilename"].ToString().Trim(), Int32.Parse(dr["OriginalWidth"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["OriginalHeight"].ToString(), CultureInfo.InvariantCulture), Int32.Parse(dr["OriginalSizeKB"].ToString(), CultureInfo.InvariantCulture), dr["ExternalHtmlSource"].ToString().Trim(), MimeTypeEnumHelper.ParseMimeTypeCategory(dr["ExternalType"].ToString().Trim()), Int32.Parse(dr["Seq"].ToString(), CultureInfo.InvariantCulture), dr["CreatedBy"].ToString(), Convert.ToDateTime(dr["DateAdded"].ToString(), CultureInfo.CurrentCulture), dr["LastModifiedBy"].ToString(), HelperFunctions.ToDateTime(dr["DateLastModified"]), Convert.ToBoolean(dr["IsPrivate"].ToString(), CultureInfo.CurrentCulture), true); break; #endregion } default: { throw new UnsupportedMediaObjectTypeException(Path.Combine(parentAlbum.FullPhysicalPath, dr["OriginalFilename"].ToString())); } } return go; }
private static IGalleryObject RetrieveMediaObjectFromDataStore(int id, GalleryObjectType galleryObjectType, IAlbum parentAlbum) { #if DEBUG tt.Tools.StartingMethod(id, galleryObjectType); #endif // If the gallery object type is vague, we need to figure it out. if ((galleryObjectType == GalleryObjectType.All) || (galleryObjectType == GalleryObjectType.None) || (galleryObjectType == GalleryObjectType.Unknown)) { galleryObjectType = HelperFunctions.DetermineGalleryObjectType(id); } IGalleryObject go = new NullObjects.NullGalleryObject(); switch (galleryObjectType) { case GalleryObjectType.Image: { go = RetrieveImageFromDataStore(id, parentAlbum); break; } case GalleryObjectType.Video: { go = RetrieveVideoFromDataStore(id, parentAlbum); break; } case GalleryObjectType.Audio: { go = RetrieveAudioFromDataStore(id, parentAlbum); break; } case GalleryObjectType.External: { go = RetrieveExternalFromDataStore(id, parentAlbum); break; } case GalleryObjectType.Generic: case GalleryObjectType.Unknown: { go = RetrieveGenericMediaObjectFromDataStore(id, parentAlbum); break; } default: { throw new InvalidMediaObjectException(id); } } return go; }