/// <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="moDto">A media object DTO 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>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name = "moDto" /> or <paramref name = "parentAlbum" /> is null.</exception>
        public static IGalleryObject LoadMediaObjectInstance(MediaObjectDto moDto, 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 (moDto == null)
                throw new ArgumentNullException("moDto");

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

            #if DEBUG
            //int id = moDto.MediaObjectId;

            //Trace.WriteLine(
            //  String.Format(
            //    "LoadMediaObjectInstance(IDataRecord dr, IAlbum parentAlbum): Retrieving media object {0} from data store...", id));
            #endif

            GalleryObjectType goType = HelperFunctions.DetermineMediaObjectType(moDto.OriginalFilename, moDto.ExternalHtmlSource);
            IGalleryObject go = null;

            try
            {
                // It is tempting to look in the media object cache for the desired object, but this does not work. If you try, then when you retrieve the
                // album from the cache on the next page load it will have zero media objects but the AreChildrenInflated property will be true, which
                // causes problems.
                switch (goType)
                {
                    case GalleryObjectType.Image:
                        {
                            #region Create Image

                            go = new Image(
                                moDto.MediaObjectId,
                                parentAlbum,
                                moDto.Title.Trim(),
                                moDto.HashKey.Trim(),
                                moDto.ThumbnailFilename,
                                moDto.ThumbnailWidth,
                                moDto.ThumbnailHeight,
                                moDto.ThumbnailSizeKB,
                                moDto.OptimizedFilename.Trim(),
                                moDto.OptimizedWidth,
                                moDto.OptimizedHeight,
                                moDto.OptimizedSizeKB,
                                moDto.OriginalFilename.Trim(),
                                moDto.OriginalWidth,
                                moDto.OriginalHeight,
                                moDto.OriginalSizeKB,
                                moDto.Seq,
                                moDto.CreatedBy.Trim(),
                                Convert.ToDateTime(moDto.DateAdded, CultureInfo.CurrentCulture),
                                moDto.LastModifiedBy.Trim(),
                                HelperFunctions.ToDateTime(moDto.DateLastModified),
                                moDto.IsPrivate,
                                true,
                                null);
                            break;

                            #endregion
                        }
                    case GalleryObjectType.Video:
                        {
                            #region Create Video

                            go = new Video(
                                moDto.MediaObjectId,
                                parentAlbum,
                                moDto.Title.Trim(),
                                moDto.HashKey.Trim(),
                                moDto.ThumbnailFilename,
                                moDto.ThumbnailWidth,
                                moDto.ThumbnailHeight,
                                moDto.ThumbnailSizeKB,
                                moDto.OptimizedFilename.Trim(),
                                moDto.OptimizedWidth,
                                moDto.OptimizedHeight,
                                moDto.OptimizedSizeKB,
                                moDto.OriginalFilename.Trim(),
                                moDto.OriginalWidth,
                                moDto.OriginalHeight,
                                moDto.OriginalSizeKB,
                                moDto.Seq,
                                moDto.CreatedBy.Trim(),
                                Convert.ToDateTime(moDto.DateAdded, CultureInfo.CurrentCulture),
                                moDto.LastModifiedBy.Trim(),
                                HelperFunctions.ToDateTime(moDto.DateLastModified),
                                moDto.IsPrivate,
                                true,
                                null);
                            break;

                            #endregion
                        }
                    case GalleryObjectType.Audio:
                        {
                            #region Create Audio

                            go = new Audio(
                                moDto.MediaObjectId,
                                parentAlbum,
                                moDto.Title.Trim(),
                                moDto.HashKey.Trim(),
                                moDto.ThumbnailFilename,
                                moDto.ThumbnailWidth,
                                moDto.ThumbnailHeight,
                                moDto.ThumbnailSizeKB,
                                moDto.OptimizedFilename.Trim(),
                                moDto.OptimizedWidth,
                                moDto.OptimizedHeight,
                                moDto.OptimizedSizeKB,
                                moDto.OriginalFilename.Trim(),
                                moDto.OriginalWidth,
                                moDto.OriginalHeight,
                                moDto.OriginalSizeKB,
                                moDto.Seq,
                                moDto.CreatedBy.Trim(),
                                Convert.ToDateTime(moDto.DateAdded, CultureInfo.CurrentCulture),
                                moDto.LastModifiedBy.Trim(),
                                HelperFunctions.ToDateTime(moDto.DateLastModified),
                                moDto.IsPrivate,
                                true,
                                null);
                            break;

                            #endregion
                        }
                    case GalleryObjectType.Generic:
                    case GalleryObjectType.Unknown:
                        {
                            #region Create Generic Media Object

                            go = new GenericMediaObject(
                                moDto.MediaObjectId,
                                parentAlbum,
                                moDto.Title.Trim(),
                                moDto.HashKey.Trim(),
                                moDto.ThumbnailFilename,
                                moDto.ThumbnailWidth,
                                moDto.ThumbnailHeight,
                                moDto.ThumbnailSizeKB,
                                moDto.OriginalFilename.Trim(),
                                moDto.OriginalWidth,
                                moDto.OriginalHeight,
                                moDto.OriginalSizeKB,
                                moDto.Seq,
                                moDto.CreatedBy.Trim(),
                                Convert.ToDateTime(moDto.DateAdded, CultureInfo.CurrentCulture),
                                moDto.LastModifiedBy.Trim(),
                                HelperFunctions.ToDateTime(moDto.DateLastModified),
                                moDto.IsPrivate,
                                true,
                                null);
                            break;

                            #endregion
                        }
                    case GalleryObjectType.External:
                        {
                            #region Create External

                            go = new ExternalMediaObject(
                                moDto.MediaObjectId,
                                parentAlbum,
                                moDto.Title.Trim(),
                                moDto.HashKey.Trim(),
                                moDto.ThumbnailFilename,
                                moDto.ThumbnailWidth,
                                moDto.ThumbnailHeight,
                                moDto.ThumbnailSizeKB,
                                moDto.ExternalHtmlSource.Trim(),
                                MimeTypeEnumHelper.ParseMimeTypeCategory(moDto.ExternalType.Trim()),
                                moDto.Seq,
                                moDto.CreatedBy.Trim(),
                                Convert.ToDateTime(moDto.DateAdded, CultureInfo.CurrentCulture),
                                moDto.LastModifiedBy.Trim(),
                                HelperFunctions.ToDateTime(moDto.DateLastModified),
                                moDto.IsPrivate,
                                true);
                            break;

                            #endregion
                        }
                    default:
                        {
                            throw new UnsupportedMediaObjectTypeException(Path.Combine(parentAlbum.FullPhysicalPath, moDto.OriginalFilename));
                        }
                }

                AddMediaObjectMetadata(go, moDto);

                AddToMediaObjectCache(go);
            }
            catch
            {
                if (go != null)
                    go.Dispose();

                throw;
            }

            return go;
        }
            private static IGalleryObject RetrieveGenericMediaObjectFromDataStore(int mediaObjectId, IAlbum parentAlbum)
            {
            bool includeMetadata = (parentAlbum == null || parentAlbum.AllowMetadataLoading);

            MediaObjectDto moDto = GetDataProvider().MediaObject_GetMediaObjectById(mediaObjectId, includeMetadata);

            if (moDto == null)
            {
                throw new InvalidMediaObjectException(mediaObjectId);
            }

            if (parentAlbum == null)
            {
                parentAlbum = Factory.LoadAlbumInstance(moDto.FKAlbumId, false);
            }

            IGalleryObject mo = new GenericMediaObject(
                moDto.MediaObjectId,
                parentAlbum,
                moDto.Title.Trim(),
                moDto.HashKey.Trim(),
                moDto.ThumbnailFilename,
                moDto.ThumbnailWidth,
                moDto.ThumbnailHeight,
                moDto.ThumbnailSizeKB,
                moDto.OriginalFilename.Trim(),
                moDto.OriginalWidth,
                moDto.OriginalHeight,
                moDto.OriginalSizeKB,
                moDto.Seq,
                moDto.CreatedBy.Trim(),
                moDto.DateAdded,
                moDto.LastModifiedBy.Trim(),
                HelperFunctions.ToDateTime(moDto.DateLastModified),
                moDto.IsPrivate,
                true,
                null);

            AddMediaObjectMetadata(mo, moDto);

            return mo;
            }
Beispiel #3
0
		/// <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;
		}
Beispiel #4
0
		/// <summary>
		/// Create a fully inflated, properly typed, media object instance from the specified <paramref name="moDto" />.
		/// This method is guaranteed to never return null.
		/// </summary>
		/// <param name="moDto">A media object entity. Typically this is generated from a database query.</param>
		/// <param name="parentAlbum">The album containing the media object. Specify null when it is not known, and the
		/// function will automatically generate it.</param>
		/// <returns>Returns a read-only, fully inflated, properly typed media object instance.</returns>
		/// <exception cref="UnsupportedMediaObjectTypeException"></exception>
		public static IGalleryObject GetMediaObjectFromDto(MediaObjectDto moDto, IAlbum parentAlbum)
		{
			if (parentAlbum == null)
			{
				parentAlbum = LoadAlbumInstance(moDto.FKAlbumId, false);
			}

			IGalleryObject mo;

			var goType = HelperFunctions.DetermineMediaObjectType(moDto);

			switch (goType)
			{
				case GalleryObjectType.Image:
					mo = new Image(
						moDto.MediaObjectId,
						parentAlbum,
						moDto.ThumbnailFilename,
						moDto.ThumbnailWidth,
						moDto.ThumbnailHeight,
						moDto.ThumbnailSizeKB,
						moDto.OptimizedFilename.Trim(),
						moDto.OptimizedWidth,
						moDto.OptimizedHeight,
						moDto.OptimizedSizeKB,
						moDto.OriginalFilename.Trim(),
						moDto.OriginalWidth,
						moDto.OriginalHeight,
						moDto.OriginalSizeKB,
						moDto.Seq,
						moDto.CreatedBy.Trim(),
						Convert.ToDateTime(moDto.DateAdded, CultureInfo.CurrentCulture),
						moDto.LastModifiedBy.Trim(),
						HelperFunctions.ToDateTime(moDto.DateLastModified),
						moDto.IsPrivate,
						true,
						null,
						moDto.Metadata);
					break;

				case GalleryObjectType.Video:
					{
						mo = new Video(
							moDto.MediaObjectId,
							parentAlbum,
							moDto.ThumbnailFilename,
							moDto.ThumbnailWidth,
							moDto.ThumbnailHeight,
							moDto.ThumbnailSizeKB,
							moDto.OptimizedFilename.Trim(),
							moDto.OptimizedWidth,
							moDto.OptimizedHeight,
							moDto.OptimizedSizeKB,
							moDto.OriginalFilename.Trim(),
							moDto.OriginalWidth,
							moDto.OriginalHeight,
							moDto.OriginalSizeKB,
							moDto.Seq,
							moDto.CreatedBy.Trim(),
							Convert.ToDateTime(moDto.DateAdded, CultureInfo.CurrentCulture),
							moDto.LastModifiedBy.Trim(),
							HelperFunctions.ToDateTime(moDto.DateLastModified),
							moDto.IsPrivate,
							true,
							null,
							moDto.Metadata);
						break;
					}
				case GalleryObjectType.Audio:
					{
						mo = new Audio(
							moDto.MediaObjectId,
							parentAlbum,
							moDto.ThumbnailFilename,
							moDto.ThumbnailWidth,
							moDto.ThumbnailHeight,
							moDto.ThumbnailSizeKB,
							moDto.OptimizedFilename.Trim(),
							moDto.OptimizedWidth,
							moDto.OptimizedHeight,
							moDto.OptimizedSizeKB,
							moDto.OriginalFilename.Trim(),
							moDto.OriginalWidth,
							moDto.OriginalHeight,
							moDto.OriginalSizeKB,
							moDto.Seq,
							moDto.CreatedBy.Trim(),
							Convert.ToDateTime(moDto.DateAdded, CultureInfo.CurrentCulture),
							moDto.LastModifiedBy.Trim(),
							HelperFunctions.ToDateTime(moDto.DateLastModified),
							moDto.IsPrivate,
							true,
							null,
							moDto.Metadata);
						break;
					}
				case GalleryObjectType.External:
					{
						mo = new ExternalMediaObject(
							moDto.MediaObjectId,
							parentAlbum,
							moDto.ThumbnailFilename,
							moDto.ThumbnailWidth,
							moDto.ThumbnailHeight,
							moDto.ThumbnailSizeKB,
							moDto.ExternalHtmlSource.Trim(),
							MimeTypeEnumHelper.ParseMimeTypeCategory(moDto.ExternalType.Trim()),
							moDto.Seq,
							moDto.CreatedBy.Trim(),
							Convert.ToDateTime(moDto.DateAdded, CultureInfo.CurrentCulture),
							moDto.LastModifiedBy.Trim(),
							HelperFunctions.ToDateTime(moDto.DateLastModified),
							moDto.IsPrivate,
							true,
							moDto.Metadata);
						break;
					}
				case GalleryObjectType.Generic:
				case GalleryObjectType.Unknown:
					{
						mo = new GenericMediaObject(
							moDto.MediaObjectId,
							parentAlbum,
							moDto.ThumbnailFilename,
							moDto.ThumbnailWidth,
							moDto.ThumbnailHeight,
							moDto.ThumbnailSizeKB,
							moDto.OriginalFilename.Trim(),
							moDto.OriginalWidth,
							moDto.OriginalHeight,
							moDto.OriginalSizeKB,
							moDto.Seq,
							moDto.CreatedBy.Trim(),
							Convert.ToDateTime(moDto.DateAdded, CultureInfo.CurrentCulture),
							moDto.LastModifiedBy.Trim(),
							HelperFunctions.ToDateTime(moDto.DateLastModified),
							moDto.IsPrivate,
							true,
							null,
							moDto.Metadata);
						break;
					}
				default:
					{
						throw new UnsupportedMediaObjectTypeException(Path.Combine(parentAlbum.FullPhysicalPath, moDto.OriginalFilename));
					}
			}

			return mo;
		}
Beispiel #5
0
		private static IGalleryObject RetrieveGenericMediaObjectFromDataStore(int mediaObjectId, IAlbum parentAlbum)
		{
#if DEBUG
			tt.Tools.StartingMethod(mediaObjectId); // Can't specify parentAlbum because this bombs when it's null.
#endif

			IGalleryObject genericMediaObject = null;
			IDataReader dr = null;
			try
			{
				using (dr = Factory.GetDataProvider().MediaObject_GetDataReaderMediaObjectById(mediaObjectId))
				{
					// 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
					while (dr.Read())
					{
						genericMediaObject = 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);
					}
				}
			}
			finally
			{
				if (dr != null) dr.Close();
			}

			if (genericMediaObject == null)
				throw new InvalidMediaObjectException(mediaObjectId);

			return genericMediaObject;
		}