Ejemplo n.º 1
0
        /// <summary>
        /// Return the media object for the specified <paramref name="mediaObjectId" />, optionally including the metadata
        /// for each item. Returns null if no matching object is found in the data store.
        /// </summary>
        /// <param name="mediaObjectId">The ID that uniquely identifies the desired media object.</param>
        /// <param name="includeMetadata">When <c>true</c> include metadata items on the
        /// <see cref="MediaObjectDto.MediaObjectMetadata" /> property. When <c>false</c>, the property is null.</param>
        /// <returns>Returns an instance of <see cref="MediaObjectDto" />, or null if no matching object is found.</returns>
        public static MediaObjectDto GetMediaObjectById(int mediaObjectId, bool includeMetadata)
        {
            MediaObjectDto moDto = null;

            using (SqlConnection cn = SqlDataProvider.GetDbConnection())
            {
                using (IDataReader dr = GetCommandMediaObjectSelectById(mediaObjectId, cn).ExecuteReader(CommandBehavior.SingleRow))
                {
                    while (dr.Read())
                    {
                        // SQL:
                        //SELECT
                        //  MediaObjectId, FKAlbumId, Title, HashKey, ThumbnailFilename, ThumbnailWidth, ThumbnailHeight,
                        //  ThumbnailSizeKB, OptimizedFilename, OptimizedWidth, OptimizedHeight, OptimizedSizeKB,
                        //  OriginalFilename, OriginalWidth, OriginalHeight, OriginalSizeKB, ExternalHtmlSource, ExternalType, Seq,
                        //  CreatedBy, DateAdded, LastModifiedBy, DateLastModified, IsPrivate
                        //FROM [gs_MediaObject]
                        //WHERE MediaObjectId = @MediaObjectId
                        moDto = new MediaObjectDto
                        {
                            MediaObjectId      = dr.GetInt32(0),
                            FKAlbumId          = dr.GetInt32(1),
                            Title              = dr.GetString(2),
                            HashKey            = dr.GetString(3),
                            ThumbnailFilename  = dr.GetString(4),
                            ThumbnailWidth     = dr.GetInt32(5),
                            ThumbnailHeight    = dr.GetInt32(6),
                            ThumbnailSizeKB    = dr.GetInt32(7),
                            OptimizedFilename  = dr.GetString(8),
                            OptimizedWidth     = dr.GetInt32(9),
                            OptimizedHeight    = dr.GetInt32(10),
                            OptimizedSizeKB    = dr.GetInt32(11),
                            OriginalFilename   = dr.GetString(12),
                            OriginalWidth      = dr.GetInt32(13),
                            OriginalHeight     = dr.GetInt32(14),
                            OriginalSizeKB     = dr.GetInt32(15),
                            ExternalHtmlSource = dr.GetString(16),
                            ExternalType       = dr.GetString(17),
                            Seq              = dr.GetInt32(18),
                            CreatedBy        = dr.GetString(19),
                            DateAdded        = dr.GetDateTime(20),
                            LastModifiedBy   = dr.GetString(21),
                            DateLastModified = dr.GetDateTime(22),
                            IsPrivate        = dr.GetBoolean(23)
                        };
                    }
                }

                if (includeMetadata && (moDto != null))
                {
                    moDto.MediaObjectMetadata = new HashSet <MediaObjectMetadataDto>(MediaObject.GetMetadataItemsByMediaObjectId(moDto.MediaObjectId, cn));
                }
            }

            return(moDto);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Return a collection representing the child media objects contained within the album specified by
        /// <paramref name="albumId"/> parameter, optionally including the metadata for each item. If no matching
        /// objects are found in the data store, an empty collection is returned.
        /// </summary>
        /// <param name="albumId">The ID that uniquely identifies the desired album.</param>
        /// <param name="includeMetadata">When <c>true</c> include metadata items on the
        /// <see cref="MediaObjectDto.MediaObjectMetadata" /> property. When <c>false</c>, the property is null.</param>
        /// <returns>
        /// Returns a collection of all media objects directly within the album represented by <paramref name="albumId"/>.
        /// </returns>
        internal static IEnumerable <MediaObjectDto> GetChildGalleryObjectsById(int albumId, bool includeMetadata)
        {
            List <MediaObjectDto> mediaObjects = new List <MediaObjectDto>();

            using (SqlConnection cn = SqlDataProvider.GetDbConnection())
            {
                using (IDataReader dr = GetCommandChildMediaObjectsById(albumId, cn).ExecuteReader())
                {
                    while (dr.Read())
                    {
                        // SQL:
                        //SELECT
                        //  MediaObjectId, FKAlbumId, Title, HashKey, ThumbnailFilename, ThumbnailWidth, ThumbnailHeight,
                        //  ThumbnailSizeKB, OptimizedFilename, OptimizedWidth, OptimizedHeight, OptimizedSizeKB,
                        //  OriginalFilename, OriginalWidth, OriginalHeight, OriginalSizeKB, ExternalHtmlSource, ExternalType, Seq,
                        //  CreatedBy, DateAdded, LastModifiedBy, DateLastModified, IsPrivate
                        //FROM [gs_MediaObject]
                        //WHERE FKAlbumId = @AlbumId
                        mediaObjects.Add(new MediaObjectDto
                        {
                            MediaObjectId      = dr.GetInt32(0),
                            FKAlbumId          = dr.GetInt32(1),
                            Title              = dr.GetString(2),
                            HashKey            = dr.GetString(3),
                            ThumbnailFilename  = dr.GetString(4),
                            ThumbnailWidth     = dr.GetInt32(5),
                            ThumbnailHeight    = dr.GetInt32(6),
                            ThumbnailSizeKB    = dr.GetInt32(7),
                            OptimizedFilename  = dr.GetString(8),
                            OptimizedWidth     = dr.GetInt32(9),
                            OptimizedHeight    = dr.GetInt32(10),
                            OptimizedSizeKB    = dr.GetInt32(11),
                            OriginalFilename   = dr.GetString(12),
                            OriginalWidth      = dr.GetInt32(13),
                            OriginalHeight     = dr.GetInt32(14),
                            OriginalSizeKB     = dr.GetInt32(15),
                            ExternalHtmlSource = dr.GetString(16),
                            ExternalType       = dr.GetString(17),
                            Seq              = dr.GetInt32(18),
                            CreatedBy        = dr.GetString(19),
                            DateAdded        = dr.GetDateTime(20),
                            LastModifiedBy   = dr.GetString(21),
                            DateLastModified = dr.GetDateTime(22),
                            IsPrivate        = dr.GetBoolean(23)
                        });
                    }
                }

                if (includeMetadata)
                {
                    foreach (MediaObjectDto moDto in mediaObjects)
                    {
                        moDto.MediaObjectMetadata = new HashSet <MediaObjectMetadataDto>(MediaObject.GetMetadataItemsByMediaObjectId(moDto.MediaObjectId, cn));
                    }
                }
            }

            return(mediaObjects);
        }