Ejemplo n.º 1
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="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;
        }
Ejemplo n.º 2
0
 public static GalleryObjectType DetermineMediaObjectType(MediaObjectDto moDto)
 {
     return DetermineMediaObjectType(moDto.OriginalFilename, moDto.ExternalHtmlSource);
 }
Ejemplo n.º 3
0
            /// <summary>
            /// Add metadata items to the specified gallery object from the DTO object. No action is taken if
            /// <paramref name="moDto" /> does not contain any metadata.
            /// </summary>
            /// <param name="go">The gallery object for which metadata items should be added to the MetadataItems collection.</param>
            /// <param name="moDto">A media object DTO containing information about the media object.</param>
            private static void AddMediaObjectMetadata(IGalleryObject go, MediaObjectDto moDto)
            {
            if (moDto.MediaObjectMetadata == null)
                return;

            foreach (MediaObjectMetadataDto mDto in moDto.MediaObjectMetadata)
            {
                FormattedMetadataItemName metaItemName = (FormattedMetadataItemName)mDto.MetadataNameIdentifier;

                go.MetadataItems.Add(new GalleryObjectMetadataItem(
                                                            mDto.MediaObjectMetadataId,
                                                            metaItemName,
                                                            mDto.Description.Trim(),
                                                            mDto.Value.Trim(),
                                                            false));
            }

            go.IsMetadataLoaded = true;
            }
Ejemplo n.º 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;
		}