Example #1
0
		/// <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.NotSpecified) || (galleryObjectType == GalleryObjectType.Unknown))
			{
				galleryObjectType = HelperFunctions.DetermineGalleryObjectType(id);
			}

			IGalleryObject go;

			switch (galleryObjectType)
			{
				case GalleryObjectType.Album:
					{
						go = LoadAlbumInstance(id, false);
						break;
					}
				case GalleryObjectType.Image:
				case GalleryObjectType.Video:
				case GalleryObjectType.Audio:
				case GalleryObjectType.Generic:
				case GalleryObjectType.Unknown:
					{
						go = LoadMediaObjectInstance(id);
						break;
					}
				default:
					{
						throw new UnsupportedMediaObjectTypeException();
					}
			}

			return go;
		}
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CacheItemAlbum" /> class.
        /// </summary>
        /// <param name="id">The ID for this gallery object.</param>
        /// <param name="galleryId">The ID for the gallery.</param>
        /// <param name="albumId">The ID of the album this gallery asset belongs to.</param>
        /// <param name="galleryObjectType">Type of the gallery asset.</param>
        /// <param name="sequence">The sequence of this gallery asset.</param>
        /// <param name="dateAdded">The date this gallery asset was added.</param>
        /// <param name="metaItems">The meta items belonging to this gallery asset.</param>
        /// <param name="createdByUserName">Name of the user who created this gallery asset.</param>
        /// <param name="lastModifiedByUserName">The name of the user who last modified this gallery asset.</param>
        /// <param name="dateLastModified">The date this gallery asset was last modified.</param>
        /// <param name="isPrivate">A value indicating whether this instance if private.</param>
        /// <param name="directoryName">The name of the directory where the album is stored. Example: summervacation.</param>
        /// <param name="thumbnailMediaObjectId">The media object ID whose thumbnail image is to be used as the thumbnail image to represent this album.</param>
        /// <param name="sortByMetaName">The metadata property to sort the album by.</param>
        /// <param name="sortAscending">A value indicating whether the contents of the album are sorted in ascending order. A <c>false</c> value indicates
        /// a descending sort.</param>
        /// <param name="ownedBy">The user name of this album's owner.</param>
        /// <param name="ownerRoleName">The name of the role associated with this album's owner.</param>
        /// <param name="childAlbumIds">The ID's of all child albums in this album. The IDs must be in the key; the value is ignored.</param>
        /// <param name="childMediaObjectIds">The ID's of all child media assets in this album. The IDs must be in the key; the value is ignored.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when a required parameter is null.</exception>
        public CacheItemAlbum(int id, int galleryId, int albumId, GalleryObjectType galleryObjectType, int sequence, DateTime dateAdded, List <CacheItemMetaItem> metaItems, string createdByUserName, string lastModifiedByUserName, DateTime dateLastModified, bool isPrivate, string directoryName, int thumbnailMediaObjectId, MetadataItemName sortByMetaName, bool sortAscending, string ownedBy, string ownerRoleName, ConcurrentDictionary <int, byte> childAlbumIds, ConcurrentDictionary <int, byte> childMediaObjectIds)
            : base(id, galleryId, albumId, null, galleryObjectType, sequence, dateAdded, metaItems, createdByUserName, lastModifiedByUserName, dateLastModified, isPrivate)
        {
            if (metaItems == null)
            {
                throw new ArgumentNullException(nameof(metaItems));
            }

            if (childAlbumIds == null)
            {
                throw new ArgumentNullException(nameof(childAlbumIds));
            }

            if (childMediaObjectIds == null)
            {
                throw new ArgumentNullException(nameof(childMediaObjectIds));
            }

            DirectoryName          = directoryName;
            ThumbnailMediaObjectId = thumbnailMediaObjectId;
            SortByMetaName         = sortByMetaName;
            SortAscending          = sortAscending;
            OwnedBy             = ownedBy;
            OwnerRoleName       = ownerRoleName;
            ChildAlbumIds       = childAlbumIds;
            ChildMediaObjectIds = childMediaObjectIds;
        }
Example #3
0
        private void btnOkClicked()
        {
            object formFieldGalleryObjectIds = Request.Form["goIds"];

            if ((formFieldGalleryObjectIds == null) || (String.IsNullOrEmpty(formFieldGalleryObjectIds.ToString())))
            {
                // The hidden field will be empty when no changes have been made. Just return.
                return;
            }

            string strGoIds = formFieldGalleryObjectIds.ToString();

            string[] goIds = strGoIds.Split(new char[] { ',' });

            // User wants to persist the reordering changes to the data store. As the user has been dragging and dropping objects
            // in their new locations, server-side code has been keeping the CurrentSequences property synchronized with the order
            // of the objects in the user's browser. Now we want to loop through those objects and update the Sequence property
            // of each one according to it's position within the list.
            IGalleryObjectCollection galleryObjects = this.GetAlbum().GetChildGalleryObjects(true);

            int newSequence = 0;

            try
            {
                HelperFunctions.BeginTransaction();
                foreach (string galleryObjectIdentifier in goIds)
                {
                    // Parse the string into its 2 parts: (a) The first character is either "a" (for album) or "m" (for media object);
                    // (b) The rest of the string is the ID for the album of media object. Ex: "a132" is an album with ID=132.
                    GalleryObjectType galleryObjectType = (galleryObjectIdentifier.Substring(0, 1) == "a" ? GalleryObjectType.Album : GalleryObjectType.MediaObject);
                    int galleryObjectId = Convert.ToInt32(galleryObjectIdentifier.Substring(1), CultureInfo.InvariantCulture);

                    IGalleryObject matchingGalleryObject = galleryObjects.FindById(galleryObjectId, galleryObjectType);

                    if ((matchingGalleryObject != null) && (matchingGalleryObject.Sequence != newSequence))
                    {
                        matchingGalleryObject.Sequence = newSequence;
                        GalleryObjectController.SaveGalleryObject(matchingGalleryObject);
                    }
                    newSequence++;
                }
                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }

            HelperFunctions.PurgeCache();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CacheItemMedia"/> class.
 /// </summary>
 /// <param name="id">The ID for this gallery object.</param>
 /// <param name="galleryId">The ID for the gallery.</param>
 /// <param name="albumId">The ID of the album this gallery asset belongs to.</param>
 /// <param name="displayObjects">An array of cache-friendly display objects, representing the thumbnail, optimized and original display objects.
 /// Specify null for albums.</param>
 /// <param name="galleryObjectType">Type of the gallery asset.</param>
 /// <param name="sequence">The sequence of this gallery asset.</param>
 /// <param name="dateAdded">The date this gallery asset was added.</param>
 /// <param name="metaItems">The meta items belonging to this gallery asset.</param>
 /// <param name="createdByUserName">Name of the user who created this gallery asset.</param>
 /// <param name="lastModifiedByUserName">The name of the user who last modified this gallery asset.</param>
 /// <param name="dateLastModified">The date this gallery asset was last modified.</param>
 /// <param name="isPrivate">A value indicating whether this instance if private.</param>
 public CacheItemMedia(int id, int galleryId, int albumId, CacheItemDisplayObject[] displayObjects, GalleryObjectType galleryObjectType, int sequence, DateTime dateAdded, List <CacheItemMetaItem> metaItems, string createdByUserName, string lastModifiedByUserName, DateTime dateLastModified, bool isPrivate)
 {
     Id                     = id;
     GalleryId              = galleryId;
     AlbumId                = albumId;
     DisplayObjects         = displayObjects;
     GalleryObjectType      = galleryObjectType;
     Sequence               = sequence;
     DateAdded              = dateAdded;
     MetaItems              = metaItems;
     CreatedByUserName      = createdByUserName;
     LastModifiedByUserName = lastModifiedByUserName;
     DateLastModified       = dateLastModified;
     IsPrivate              = isPrivate;
 }
Example #5
0
        /// <summary>
        /// Find the gallery object in the collection that matches the specified <see cref="IGalleryObject.Id">ID</see> and type. If no matching object is found,
        /// null is returned.
        /// </summary>
        /// <param name="galleryObjectId">The <see cref="IGalleryObject.Id">ID</see> that uniquely identifies the album or media object.</param>
        /// <param name="galleryObjectType">The type of gallery object to which the galleryObjectId applies. Valid values
        /// are <see cref="GalleryObjectType.Album"/> and <see cref="GalleryObjectType.MediaObject"/>. An exception is thrown if any other value is specified.</param>
        /// <returns>
        /// Returns an <see cref="IGalleryObject"/>object from the collection that matches the specified
        /// <see cref="IGalleryObject.Id">ID</see> and type, or null if no matching object is found.
        /// </returns>
        /// <remarks>The <see cref="IGalleryObject.Id">ID</see> for albums and media objects are managed separately. As a result, the same
        /// <see cref="IGalleryObject.Id">ID</see> may be used for both an album and media object, and these two objects may end up in the
        /// same collection (for example, if they are both in the same parent album.) Therefore, this method requires that we specify the
        /// type of gallery object.</remarks>
        public IGalleryObject FindById(int galleryObjectId, GalleryObjectType galleryObjectType)
        {
            if ((galleryObjectType != GalleryObjectType.Album) && (galleryObjectType != GalleryObjectType.MediaObject))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryObjectCollection_FindById_Ex_Msg, galleryObjectType.ToString()));
            }

            Type           albumType             = typeof(Album);
            IGalleryObject matchingGalleryObject = null;

            foreach (IGalleryObject galleryObject in (List <IGalleryObject>)Items)
            {
                if (galleryObjectType == GalleryObjectType.Album)
                {
                    if ((galleryObject.Id == galleryObjectId) && (galleryObject.GetType() == albumType))
                    {
                        matchingGalleryObject = galleryObject;
                        break;
                    }
                }
                else if (galleryObjectType == GalleryObjectType.MediaObject)
                {
                    if ((galleryObject.Id == galleryObjectId) && (galleryObject.GetType() != albumType))
                    {
                        matchingGalleryObject = galleryObject;
                        break;
                    }
                }
                else
                {
                    // We are already validating at the beginning of the method, but let's do it again just to be double sure.
                    throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.GalleryObjectCollection_FindById_Ex_Msg, galleryObjectType.ToString()));
                }
            }

            return(matchingGalleryObject);
        }
 public IGalleryObjectCollection GetChildGalleryObjects(GalleryObjectType galleryObjectType)
 {
     return new GalleryObjectCollection();
 }
        /// <summary>
        /// Gets the gallery objects most recently added to the gallery having <paramref name="galleryId" />.
        /// </summary>
        /// <param name="top">The maximum number of results to return. Must be greater than zero.</param>
        /// <param name="galleryId">The gallery ID.</param>
        /// <param name="filter">A filter that limits the types of gallery objects that are returned.</param>
        /// <returns>An instance of <see cref="IAlbum" />.</returns>
        /// <exception cref="ArgumentException">Thrown when <paramref name="top" /> is less than or equal to zero.</exception>
        public static IAlbum GetMostRecentlyAddedGalleryObjects(int top, int galleryId, GalleryObjectType filter)
        {
            if (top <= 0)
                throw new ArgumentException("The top parameter must contain a number greater than zero.", "top");

            var tmpAlbum = Factory.CreateEmptyAlbumInstance(galleryId);

            tmpAlbum.IsVirtualAlbum = true;
            tmpAlbum.VirtualAlbumType = VirtualAlbumType.MostRecentlyAdded;
            tmpAlbum.Title = Resources.GalleryServerPro.Site_Recently_Added_Title;
            tmpAlbum.Caption = String.Empty;
            tmpAlbum.SortByMetaName = MetadataItemName.DateAdded;
            tmpAlbum.SortAscending = false;

            var searcher = new GalleryObjectSearcher(new GalleryObjectSearchOptions
            {
                SearchType = GalleryObjectSearchType.MostRecentlyAdded,
                GalleryId = galleryId,
                Roles = RoleController.GetGalleryServerRolesForUser(),
                IsUserAuthenticated = Utils.IsAuthenticated,
                MaxNumberResults = top,
                Filter = filter
            });

            foreach (var galleryObject in searcher.Find())
            {
                tmpAlbum.AddGalleryObject(galleryObject);
            }

            return tmpAlbum;
        }
Example #8
0
        /// <summary>
        /// Returns an unsorted collection of gallery objects that are direct children of the current gallery object or
        /// an empty list (Count = 0) if there are no child objects. Use the <paramref name="excludePrivateObjects" />
        /// parameter to optionally filter out private objects (if not specified, private objects are returned).
        /// </summary>
        /// <param name="galleryObjectType">A <see cref="GalleryObjectType" /> enum indicating the
        /// desired type of child objects to return.</param>
        /// <param name="excludePrivateObjects">Indicates whether to exclude objects that are marked as private
        /// (<see cref="IGalleryObject.IsPrivate" /> = <c>true</c>). Objects that are private should not be shown to anonymous users.</param>
        /// <returns>An instance of <see cref="IGalleryObjectCollection" />.</returns>
        public override IGalleryObjectCollection GetChildGalleryObjects(GalleryObjectType galleryObjectType = GalleryObjectType.All, bool excludePrivateObjects = false)
        {
            this.Inflate(true);

            switch (galleryObjectType)
            {
                case GalleryObjectType.All:
                    return new GalleryObjectCollection(_galleryObjects.Where(g => !g.IsPrivate || !excludePrivateObjects));
                case GalleryObjectType.MediaObject:
                    return new GalleryObjectCollection(_galleryObjects.Where(g => (!g.IsPrivate || !excludePrivateObjects) && g.GalleryObjectType != GalleryObjectType.Album));
                case GalleryObjectType.Album:
                    return new GalleryObjectCollection(_galleryObjects.Where(g => (!g.IsPrivate || !excludePrivateObjects) && g.GalleryObjectType == GalleryObjectType.Album));
                default:
                    return new GalleryObjectCollection(_galleryObjects.Where(g => (!g.IsPrivate || !excludePrivateObjects) && g.GalleryObjectType == galleryObjectType));
            }
        }
Example #9
0
 /// <summary>
 /// Returns a collection of gallery objects that are direct children of the current gallery object. Returns 
 /// an empty list (Count = 0) if there are no child objects. Use the overload with the galleryObjectType 
 /// parameter to return objects of the desired type. Use the overload with the sortBySequence parameter 
 /// to sort the collection by sequence number. If the sortBySequence is not specified, the collection is 
 /// not sorted in any particular order. Use the excludePrivateObjects parameter to optionally filter out private
 /// objects (if not specified, private objects are returned).
 /// </summary>
 /// <param name="galleryObjectType">A GalleryObjectType enum indicating the
 /// desired type of child objects to return.</param>
 /// <returns>Returns a collection of objects of type IGalleryObject whose
 /// parent is the current gallery object and are of the specified type.</returns>
 public override IGalleryObjectCollection GetChildGalleryObjects(GalleryObjectType galleryObjectType)
 {
     return GetChildGalleryObjects(galleryObjectType, false);
 }
Example #10
0
 /// <summary>
 /// Returns a collection of gallery objects that are direct children of the current gallery object. Returns 
 /// an empty list (Count = 0) if there are no child objects. Use the overload with the galleryObjectType 
 /// parameter to return objects of the desired type. Use the overload with the sortBySequence parameter 
 /// to sort the collection by sequence number. If the sortBySequence is not specified, the collection is 
 /// not sorted in any particular order. Use the excludePrivateObjects parameter to optionally filter out private
 /// objects (if not specified, private objects are returned).
 /// </summary>
 /// <param name="galleryObjectType">A GalleryObjectType enum indicating the
 /// desired type of child objects to return.</param>
 /// <param name="sortBySequence">Indicates whether to sort the child gallery objects by the Sequence property.</param>
 /// <param name="excludePrivateObjects">Indicates whether to exclude objects that are marked as private (IsPrivate = true).
 /// Objects that are private should not be shown to anonymous users.</param>
 /// <returns>Returns a collection of objects of type IGalleryObject whose
 /// parent is the current gallery object and are of the specified type.</returns>
 public override IGalleryObjectCollection GetChildGalleryObjects(GalleryObjectType galleryObjectType, bool sortBySequence, bool excludePrivateObjects)
 {
     if (galleryObjectType == GalleryObjectType.All)
     {
         return this.GetChildGalleryObjects(sortBySequence, excludePrivateObjects);
     }
     else
     {
         return this.GetChildGalleryObjects(sortBySequence, excludePrivateObjects).FindAll(galleryObjectType);
     }
 }
Example #11
0
 /// <summary>
 /// Returns an unsorted collection of gallery objects that are direct children of the current gallery object or
 /// an empty list (Count = 0) if there are no child objects. Use the <paramref name="excludePrivateObjects" />
 /// parameter to optionally filter out private objects (if not specified, private objects are returned).
 /// </summary>
 /// <param name="galleryObjectType">A <see cref="GalleryObjectType" /> enum indicating the
 /// desired type of child objects to return.</param>
 /// <param name="excludePrivateObjects">Indicates whether to exclude objects that are marked as private
 /// (<see cref="IGalleryObject.IsPrivate" /> = <c>true</c>). Objects that are private should not be shown to anonymous users.</param>
 /// <returns>An instance of <see cref="IGalleryObjectCollection" />.</returns>
 /// <exception cref="System.NotSupportedException"></exception>
 public virtual IGalleryObjectCollection GetChildGalleryObjects(GalleryObjectType galleryObjectType, bool excludePrivateObjects)
 {
     throw new NotSupportedException();
 }
Example #12
0
 public IGalleryObjectCollection GetChildGalleryObjects(GalleryObjectType galleryObjectType, bool sortBySequence, bool excludePrivateObjects)
 {
     return(new GalleryObjectCollection());
 }
Example #13
0
        /// <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 = null;
            try
            {
                switch (galleryObjectType)
                {
                    case GalleryObjectType.Album:
                        {
                            go = LoadAlbumInstance(id, false);
                            break;
                        }
                    case GalleryObjectType.Image:
                        {
                            go = LoadImageInstance(id);
                            break;
                        }
                    case GalleryObjectType.Video:
                        {
                            go = LoadVideoInstance(id);
                            break;
                        }
                    case GalleryObjectType.Audio:
                        {
                            go = LoadAudioInstance(id);
                            break;
                        }
                    case GalleryObjectType.Generic:
                    case GalleryObjectType.Unknown:
                        {
                            go = LoadGenericMediaObjectInstance(id);
                            break;
                        }
                    default:
                        {
                            throw new UnsupportedMediaObjectTypeException();
                        }
                }
            }
            catch
            {
                if (go != null)
                    go.Dispose();

                throw;
            }

            return go;
        }
Example #14
0
 /// <summary>
 /// Create a read-only, fully inflated, properly typed media object instance from the specified <paramref name="id" />. If 
 /// <paramref name="id" /> is an image, video, audio, etc, then the appropriate object is returned. An 
 /// exception is thrown if the <paramref name="id" /> refers to an <see cref="Album" /> (use the <see 
 /// cref="LoadGalleryObjectInstance(int)" /> or <see cref="LoadAlbumInstance(int, bool)" /> method if  the <paramref name="id" />
 /// refers to an album). An exception is also thrown if no matching record exists for this <paramref name="id" />. If the 
 /// <paramref name="galleryObjectType" /> parameter is set to All, None, or Unknown, then an additional call to the data store 
 /// is made to determine the object's type. When you know the type you want (<see cref="Image" />, <see cref="Video" />, etc), 
 /// use the overload that takes the galleryObjectType parameter, or call the specific Factory method that loads the desired type, 
 /// as those are more efficient. This method is guaranteed to never return null.
 /// </summary>
 /// <param name="id">An integer representing the <see cref="IGalleryObject.Id">ID</see> of the media object 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. An exception is thrown if the Album enum value is specified, since this method
 /// is designed only for media objects.</param>
 /// <returns>Returns a read-only, fully inflated, properly typed media object instance.</returns>
 /// <exception cref="InvalidMediaObjectException">Thrown when no record exists in the data store for the specified 
 /// <paramref name="id" />, or when the id parameter refers to an album.</exception>
 public static IGalleryObject LoadMediaObjectInstance(int id, GalleryObjectType galleryObjectType)
 {
     return LoadMediaObjectInstance(id, galleryObjectType, false);
 }
Example #15
0
            /// <summary>
            /// Retrieve the specified media object. It is retrieved from the cache if it is there.
            /// If not, it is retrieved from the data store.
            /// </summary>
            /// <param name="mediaObjectId">The ID that uniquely identifies the media object to retrieve.</param>
            /// <param name="galleryObjectType">The type of gallery object that the mediaObjectId 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. An exception is thrown if the Album enum value is specified, since this method
            /// is designed only for media objects.</param>
            /// <param name="parentAlbum">The album containing the media object specified by mediaObjectId. Specify
            /// null if a reference to the album is not available, and it will be created based on the parent album
            /// specified in the data store.</param>
            /// <returns>Returns the specified media object.</returns>
            /// <exception cref="InvalidMediaObjectException">Thrown when
            /// an image is not found in the data store that matches the mediaObjectId parameter and the current gallery.</exception>
            private static IGalleryObject RetrieveMediaObject(int mediaObjectId, GalleryObjectType galleryObjectType, IAlbum parentAlbum)
            {
            // <exception cref="InvalidAlbumException">Thrown when an
            // album with the specified album ID is not found in the data store.</exception>
            Dictionary<int, IGalleryObject> mediaObjectCache = (Dictionary<int, IGalleryObject>)HelperFunctions.GetCache(CacheItem.MediaObjects);

            IGalleryObject mediaObject;
            if (mediaObjectCache != null)
            {
                if (!mediaObjectCache.TryGetValue(mediaObjectId, out mediaObject))
                {
                    // The cache exists, but there is no item matching the desired media object ID. Retrieve from data store and add to cache.
                    mediaObject = RetrieveMediaObjectFromDataStore(mediaObjectId, galleryObjectType, parentAlbum);

                    AddToMediaObjectCache(mediaObject);
                }
            #if DEBUG
                //else
                //{
                //  Trace.WriteLine(String.Format(CultureInfo.CurrentCulture, "Media object {0} retrieved from cache.", mediaObjectId));
                //}
            #endif
            }
            else
            {
                // There is no cache item. Retrieve from data store and create cache item so it's there next time we want it.
                mediaObject = RetrieveMediaObjectFromDataStore(mediaObjectId, galleryObjectType, parentAlbum);

                AddToMediaObjectCache(mediaObject);
            }

            return mediaObject;
            }
Example #16
0
            private static IGalleryObject RetrieveMediaObjectFromDataStore(int id, GalleryObjectType galleryObjectType, IAlbum parentAlbum)
            {
            // 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;

            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;
            }
Example #17
0
 /// <summary>
 /// Retrieve the specified media object. It is retrieved from the cache if it is there.
 /// If not, it is retrieved from the data store.
 /// </summary>
 /// <param name="mediaObjectId">The ID that uniquely identifies the media object to retrieve.</param>
 /// <param name="galleryObjectType">The type of gallery object that the mediaObjectId 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. An exception is thrown if the Album enum value is specified, since this method
 /// is designed only for media objects.</param>
 /// <returns>Returns the specified media object.</returns>
 /// <exception cref="InvalidMediaObjectException">Thrown when
 /// an image is not found in the data store that matches the mediaObjectId parameter and the current gallery.</exception>
 private static IGalleryObject RetrieveMediaObject(int mediaObjectId, GalleryObjectType galleryObjectType)
 {
 return RetrieveMediaObject(mediaObjectId, galleryObjectType, null);
 }
Example #18
0
 /// <summary>
 /// Returns a collection of gallery objects that are direct children of the current gallery object. Returns
 /// an empty list (Count = 0) if there are no child objects. Use the overload with the galleryObjectType
 /// parameter to return objects of the desired type. Use the overload with the sortBySequence parameter
 /// to sort the collection by sequence number. If the sortBySequence is not specified, the collection is
 /// not sorted in any particular order. Use the excludePrivateObjects parameter to optionally filter out private
 /// objects (if not specified, private objects are returned).
 /// </summary>
 /// <param name="galleryObjectType">A GalleryObjectType enum indicating the
 /// desired type of child objects to return.</param>
 /// <param name="sortBySequence">Indicates whether to sort the child gallery objects by the Sequence property.</param>
 /// <returns>
 /// Returns a collection of objects of type IGalleryObject whose
 /// parent is the current gallery object and are of the specified type.
 /// </returns>
 /// <exception cref="System.NotSupportedException">Thrown when an inherited type
 /// does not allow the addition of child gallery objects.</exception>
 public virtual IGalleryObjectCollection GetChildGalleryObjects(GalleryObjectType galleryObjectType, bool sortBySequence)
 {
     throw new NotSupportedException();
 }
        /// <summary>
        /// Gets the media objects having the specified <paramref name="rating" /> and belonging to the
        /// <paramref name="galleryId" />.
        /// </summary>
        /// <param name="rating">Identifies the type of rating to retrieve. Valid values: "highest", "lowest", "none", or a number
        /// from 0 to 5 in half-step increments (eg. 0, 0.5, 1, 1.5, ... 4.5, 5).</param>
        /// <param name="top">The maximum number of results to return. Must be greater than zero.</param>
        /// <param name="galleryId">The gallery ID.</param>
        /// <param name="filter">A filter that limits the types of gallery objects that are returned.</param>
        /// <returns>An instance of <see cref="IAlbum" />.</returns>
        /// <exception cref="ArgumentException">Thrown when <paramref name="top" /> is less than or equal to zero.</exception>
        public static IAlbum GetRatedMediaObjects(string rating, int top, int galleryId, GalleryObjectType filter)
        {
            if (top <= 0)
                throw new ArgumentException("The top parameter must contain a number greater than zero.", "top");

            var tmpAlbum = Factory.CreateEmptyAlbumInstance(galleryId);

            tmpAlbum.IsVirtualAlbum = true;
            tmpAlbum.VirtualAlbumType = VirtualAlbumType.Rated;
            tmpAlbum.Title = GetRatedAlbumTitle(rating);
            tmpAlbum.Caption = String.Empty;

            var ratingSortTrigger = new[] {"lowest", "highest"};
            if (ratingSortTrigger.Contains(rating))
            {
                // Sort on rating field for lowest or highest. All others use the default album sort setting.
                tmpAlbum.SortByMetaName = MetadataItemName.Rating;
                tmpAlbum.SortAscending = !rating.Equals("highest", StringComparison.OrdinalIgnoreCase);
            }

            var searcher = new GalleryObjectSearcher(new GalleryObjectSearchOptions
            {
                SearchType = GalleryObjectSearchType.SearchByRating,
                SearchTerms = new [] { rating },
                GalleryId = galleryId,
                Roles = RoleController.GetGalleryServerRolesForUser(),
                IsUserAuthenticated = Utils.IsAuthenticated,
                MaxNumberResults = top,
                Filter = filter
            });

            foreach (var galleryObject in searcher.Find())
            {
                tmpAlbum.AddGalleryObject(galleryObject);
            }

            return tmpAlbum;
        }
 public IGalleryObjectCollection GetChildGalleryObjects(GalleryObjectType galleryObjectType, bool sortBySequence)
 {
     return new GalleryObjectCollection();
 }
Example #21
0
 /// <summary>
 /// Create a fully inflated, properly typed, optionally updateable media object instance from the specified <paramref name="id" />. If 
 /// <paramref name="id" /> is an image, video, audio, etc, then the appropriate object is returned. An 
 /// exception is thrown if the <paramref name="id" /> refers to an <see cref="Album" /> (use the <see 
 /// cref="LoadGalleryObjectInstance(int)" /> or <see cref="LoadAlbumInstance(int, bool)" /> method if  the <paramref name="id" />
 /// refers to an album). An exception is also thrown if no matching record exists for this <paramref name="id" />. If the 
 /// <paramref name="galleryObjectType" /> parameter is set to All, None, or Unknown, then an additional call to the data store 
 /// is made to determine the object's type. When you know the type you want (<see cref="Image" />, <see cref="Video" />, etc), 
 /// use the overload that takes the galleryObjectType parameter, or call the specific Factory method that loads the desired type, 
 /// as those are more efficient. This method is guaranteed to never return null.
 /// </summary>
 /// <param name="id">An integer representing the <see cref="IGalleryObject.Id">ID</see> of the media object 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. An exception is thrown if the Album enum value is specified, since this method
 /// is designed only for media objects.</param>
 /// <param name="isWritable">When set to <c>true</c> then return a unique instance that is not shared across threads.
 /// The resulting instance can be modified and persisted to the data store.</param>
 /// <returns>Returns a read-only, fully inflated, properly typed media object instance.</returns>
 /// <exception cref="InvalidMediaObjectException">Thrown when no record exists in the data store for the specified 
 /// <paramref name="id" />, or when the id parameter refers to an album.</exception>
 public static IGalleryObject LoadMediaObjectInstance(int id, GalleryObjectType galleryObjectType, bool isWritable)
 {
     return (isWritable ? RetrieveMediaObjectFromDataStore(id, galleryObjectType, null) : RetrieveMediaObject(id, galleryObjectType));
 }
 public IGalleryObjectCollection GetChildGalleryObjects(GalleryObjectType galleryObjectType, bool sortBySequence, bool excludePrivateObjects)
 {
     return new GalleryObjectCollection();
 }
        /// <summary>
        /// Gets the meta item with the specified <paramref name="id" />. Since the current API
        /// cannot efficient look up the gallery object ID and type, those are included as required
        /// parameters. They are assigned to the corresponding properties of the returned instance.
        /// Verifies user has permission to view item, throwing <see cref="GallerySecurityException" /> 
        /// if authorization is denied.
        /// </summary>
        /// <param name="id">The value that uniquely identifies the metadata item.</param>
        /// <param name="galleryObjectId">The gallery object ID. It is assigned to 
        /// <see cref="Entity.MetaItem.MediaId" />.</param>
        /// <param name="goType">Type of the gallery object. It is assigned to 
        /// <see cref="Entity.MetaItem.GTypeId" />.</param>
        /// <returns>An instance of <see cref="Entity.MetaItem" />.</returns>
        /// <exception cref="GallerySecurityException">Thrown when user does not have permission to
        /// view the requested item.</exception>
        /// <exception cref="InvalidMediaObjectException">Thrown when the requested meta item or its
        /// associated media object does not exist in the data store.</exception>
        /// <exception cref="InvalidAlbumException">Thrown when the album associated with the
        /// meta item does not exist in the data store.</exception>
        public static Entity.MetaItem Get(int id, int galleryObjectId, GalleryObjectType goType)
        {
            var md = Factory.LoadGalleryObjectMetadataItem(id);
            if (md == null)
                throw new InvalidMediaObjectException(String.Format("No metadata item with ID {0} could be found in the data store.", id));

            // Security check: Make sure user has permission to view item
            IGalleryObject go;
            if (goType == GalleryObjectType.Album)
            {
                go = Factory.LoadAlbumInstance(galleryObjectId, false);
                SecurityManager.ThrowIfUserNotAuthorized(SecurityActions.ViewAlbumOrMediaObject, RoleController.GetGalleryServerRolesForUser(), go.Id, go.GalleryId, Utils.IsAuthenticated, go.IsPrivate, ((IAlbum)go).IsVirtualAlbum);
            }
            else
            {
                go = Factory.LoadMediaObjectInstance(galleryObjectId);
                SecurityManager.ThrowIfUserNotAuthorized(SecurityActions.ViewAlbumOrMediaObject, RoleController.GetGalleryServerRolesForUser(), go.Parent.Id, go.GalleryId, Utils.IsAuthenticated, go.Parent.IsPrivate, ((IAlbum)go.Parent).IsVirtualAlbum);
            }

            bool isEditable = Factory.LoadGallerySetting(go.GalleryId).MetadataDisplaySettings.Find(md.MetadataItemName).IsEditable;

            return new Entity.MetaItem
                         {
                             Id = md.MediaObjectMetadataId,
                             MediaId = galleryObjectId,
                             MTypeId = (int)md.MetadataItemName,
                             GTypeId = (int)goType,
                             Desc = md.Description,
                             Value = md.Value,
                             IsEditable = isEditable
                         };
        }
Example #24
0
 public IGalleryObjectCollection GetChildGalleryObjects(GalleryObjectType galleryObjectType)
 {
     return(new GalleryObjectCollection());
 }
 /// <summary>
 /// Gets the metadata collection for the specified <paramref name="galleryObjectId" /> and
 /// <paramref name="goType" />.
 /// </summary>
 /// <param name="galleryObjectId">The ID for either an album or a media object.</param>
 /// <param name="goType">The type of gallery object.</param>
 /// <returns>Returns an instance of <see cref="IGalleryObjectMetadataItemCollection" />.</returns>
 /// <exception cref="InvalidAlbumException">Thrown when the requested album does not exist.</exception>
 /// <exception cref="InvalidMediaObjectException">Thrown when the requested media object does not exist.</exception>
 private static IGalleryObjectMetadataItemCollection GetGalleryObjectMetadataItemCollection(int galleryObjectId, GalleryObjectType goType)
 {
     if (goType == GalleryObjectType.Album)
         return Factory.LoadAlbumInstance(galleryObjectId, false).MetadataItems;
     else
         return Factory.LoadMediaObjectInstance(galleryObjectId).MetadataItems;
 }
Example #26
0
            private static IGalleryObject RetrieveMediaObjectFromDataStore(int id, GalleryObjectType galleryObjectType, IAlbum parentAlbum)
            {
            #if DEBUG
            //Trace.WriteLine(String.Format(CultureInfo.CurrentCulture, "RetrieveMediaObjectFromDataStore: Retrieving media object {0} from data store...", id));
            #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;

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

            if (((IAlbum)go.Parent).AllowMetadataLoading)
            {
                AddMediaObjectMetadata(go);
            }

            return go;
            }
        /// <summary>
        /// Gets a virtual album containing gallery objects that match the specified <paramref name="tags" /> or <paramref name="people" />
        /// belonging to the specified <paramref name="galleryId" />. Guaranteed to not return null. The returned album 
        /// is a virtual one (<see cref="IAlbum.IsVirtualAlbum" />=<c>true</c>) containing the collection of matching 
        /// items the current user has permission to view. Returns an empty album when no matches are found or the 
        /// query string does not contain the search terms.
        /// </summary>
        /// <param name="tags">The tags to search for. If specified, the <paramref name="people" /> parameter must be null.</param>
        /// <param name="people">The people to search for. If specified, the <paramref name="tags" /> parameter must be null.</param>
        /// <param name="filter">A filter that limits the types of gallery objects that are returned.
        /// Maps to the <see cref="GalleryObjectType" /> enumeration.</param>
        /// <param name="galleryId">The ID of the gallery. Only objects in this gallery are returned.</param>
        /// <returns>An instance of <see cref="IAlbum" />.</returns>
        /// <exception cref="System.ArgumentException">Throw when the tags and people parameters are both null or empty, or both
        /// have values.</exception>
        public static IAlbum GetGalleryObjectsHavingTags(string[] tags, string[] people, GalleryObjectType filter, int galleryId)
        {
            if (((tags == null) || (tags.Length == 0)) && ((people == null) || (people.Length == 0)))
                throw new ArgumentException("GalleryObjectController.GetGalleryObjectsHavingTags() requires the tags or people parameters to be specified, but they were both null or empty.");

            if ((tags != null) && (tags.Length > 0) && (people != null) && (people.Length > 0))
                throw new ArgumentException("GalleryObjectController.GetGalleryObjectsHavingTags() requires EITHER the tags or people parameters to be specified, but not both. Instead, they were both populated.");

            var searchType = (tags != null && tags.Length > 0 ? GalleryObjectSearchType.SearchByTag : GalleryObjectSearchType.SearchByPeople);
            var searchTags = (searchType == GalleryObjectSearchType.SearchByTag ? tags : people);

            var tmpAlbum = Factory.CreateEmptyAlbumInstance(galleryId);
            tmpAlbum.IsVirtualAlbum = true;
            tmpAlbum.VirtualAlbumType = (searchType == GalleryObjectSearchType.SearchByTag ? VirtualAlbumType.Tag : VirtualAlbumType.People);
            tmpAlbum.Title = String.Concat(Resources.GalleryServerPro.Site_Tag_Title, String.Join(Resources.GalleryServerPro.Site_Search_Concat, searchTags));
            tmpAlbum.Caption = String.Empty;

            var searcher = new GalleryObjectSearcher(new GalleryObjectSearchOptions
            {
                SearchType = searchType,
                Tags = searchTags,
                GalleryId = galleryId,
                Roles = RoleController.GetGalleryServerRolesForUser(),
                IsUserAuthenticated = Utils.IsAuthenticated,
                Filter = filter
            });

            foreach (var galleryObject in searcher.Find())
            {
                tmpAlbum.AddGalleryObject(galleryObject);
            }

            return tmpAlbum;
        }
Example #28
0
 /// <summary>
 /// Returns a collection of gallery objects that are direct children of the current gallery object. Returns 
 /// an empty list (Count = 0) if there are no child objects. Use the overload with the galleryObjectType 
 /// parameter to return objects of the desired type. Use the overload with the sortBySequence parameter 
 /// to sort the collection by sequence number. If the sortBySequence is not specified, the collection is 
 /// not sorted in any particular order. Use the excludePrivateObjects parameter to optionally filter out private
 /// objects (if not specified, private objects are returned).
 /// </summary>
 /// <param name="galleryObjectType">A GalleryObjectType enum indicating the
 /// desired type of child objects to return.</param>
 /// <param name="sortBySequence">Indicates whether to sort the child gallery objects by the Sequence property.</param>
 /// <returns>Returns a collection of objects of type IGalleryObject whose
 /// parent is the current gallery object and are of the specified type.</returns>
 public override IGalleryObjectCollection GetChildGalleryObjects(GalleryObjectType galleryObjectType, bool sortBySequence)
 {
     return GetChildGalleryObjects(galleryObjectType, sortBySequence, false);
 }
Example #29
0
        /// <summary>
        /// Gets the gallery object filter specified in the filter query string parameter. If not present or is not a valid
        /// value, returns <paramref name="defaultFilter" />. If <paramref name="defaultFilter" /> is not specified, 
        /// it defaults to <see cref="GalleryObjectType.All" />.
        /// </summary>
        /// <param name="defaultFilter">The default filter. Defaults to <see cref="GalleryObjectType.All" /> when not specified.</param>
        /// <returns>An instance of <see cref="GalleryObjectType" />.</returns>
        private static GalleryObjectType GetGalleryObjectFilter(GalleryObjectType defaultFilter = GalleryObjectType.All)
        {
            if (Utils.IsQueryStringParameterPresent("filter"))
            {
                return GalleryObjectTypeEnumHelper.Parse(Utils.GetQueryStringParameterString("filter"), defaultFilter);
            }

            return defaultFilter;
        }
Example #30
0
        /// <summary>
        /// Return an unsorted list of items in the collection that match the specified gallery object type. Returns an empty
        /// collection if no matching objects are found.
        /// </summary>
        /// <param name="galleryObjectType">The type of gallery object to return. <see cref="GalleryObjectType.MediaObject"/> specifies
        /// all non-album media objects.</param>
        /// <returns>
        /// Returns an unsorted list of items in the collection that match the specified gallery object type.
        /// </returns>
        public IGalleryObjectCollection FindAll(GalleryObjectType galleryObjectType)
        {
            //TODO: There may be potential to significantly speed up this method. Profile the app to see how often - and how
            // slowly - this method runs. If it is significant, evaluate different techniques for type comparison.
            // Ref: http://blogs.msdn.com/vancem/archive/2006/10/01/779503.aspx
            Type albumType    = typeof(Album);
            Type imageType    = typeof(Image);
            Type videoType    = typeof(Video);
            Type audioType    = typeof(Audio);
            Type genericType  = typeof(GenericMediaObject);
            Type externalType = typeof(ExternalMediaObject);

            IGalleryObjectCollection filteredGalleryObjects = new GalleryObjectCollection();

            foreach (IGalleryObject galleryObject in (List <IGalleryObject>)Items)
            {
                Type goType = galleryObject.GetType();

                switch (galleryObjectType)
                {
                case GalleryObjectType.MediaObject:
                {
                    if (goType != albumType)
                    {
                        filteredGalleryObjects.Add(galleryObject);
                    }
                    break;
                }

                case GalleryObjectType.Album:
                {
                    if (goType == albumType)
                    {
                        filteredGalleryObjects.Add(galleryObject);
                    }
                    break;
                }

                case GalleryObjectType.Image:
                {
                    if (goType == imageType)
                    {
                        filteredGalleryObjects.Add(galleryObject);
                    }
                    break;
                }

                case GalleryObjectType.Video:
                {
                    if (goType == videoType)
                    {
                        filteredGalleryObjects.Add(galleryObject);
                    }
                    break;
                }

                case GalleryObjectType.Audio:
                {
                    if (goType == audioType)
                    {
                        filteredGalleryObjects.Add(galleryObject);
                    }
                    break;
                }

                case GalleryObjectType.Generic:
                {
                    if (goType == genericType)
                    {
                        filteredGalleryObjects.Add(galleryObject);
                    }
                    break;
                }

                case GalleryObjectType.External:
                {
                    if (goType == externalType)
                    {
                        filteredGalleryObjects.Add(galleryObject);
                    }
                    break;
                }

                case GalleryObjectType.All:
                {
                    filteredGalleryObjects.Add(galleryObject);
                    break;
                }

                case GalleryObjectType.None: break;

                case GalleryObjectType.Unknown: break;

                default: throw new BusinessException(String.Format("The method GalleryServerPro.Business.GalleryObjectCollection.FindAll encountered an enumeration it does not recognize. A developer must update this method to handle the {0} enumeration.", galleryObjectType));
                }
            }

            return(filteredGalleryObjects);
        }
        //public static IQueryable<GalleryItem> GetGalleryItemsHavingTags(string[] tags, string[] people, int galleryId, MetadataItemName sortByMetaName, bool sortAscending, GalleryObjectType filter)
        //{
        //    IAlbum album = GetGalleryObjectsHavingTags(tags, people, filter, galleryId);
        //    IList<IGalleryObject> galleryObjects;
        //    if (MetadataItemNameEnumHelper.IsValidFormattedMetadataItemName(sortByMetaName))
        //    {
        //        galleryObjects = album.GetChildGalleryObjects(GalleryObjectType.All, !Utils.IsAuthenticated).ToSortedList(sortByMetaName, sortAscending, album.GalleryId);
        //    }
        //    else
        //    {
        //        galleryObjects = album.GetChildGalleryObjects(GalleryObjectType.All, !Utils.IsAuthenticated).ToSortedList();
        //    }
        //    return ToGalleryItems(galleryObjects).AsQueryable();
        //}
        /// <summary>
        /// Return a virtual album containing gallery objects whose title or caption contain the specified search strings and
        /// for which the current user has authorization to view. Guaranteed to not return null. A gallery 
        /// object is considered a match when all search terms are found in the relevant fields.
        /// </summary>
        /// <param name="searchStrings">The strings to search for.</param>
        /// <param name="filter">A filter that limits the types of gallery objects that are returned.
        /// Maps to the <see cref="GalleryObjectType" /> enumeration.</param>
        /// <param name="galleryId">The ID for the gallery containing the objects to search.</param>
        /// <returns>
        /// Returns an <see cref="IAlbum" /> containing the matching items. This may include albums and media
        /// objects from different albums.
        /// </returns>
        public static IAlbum GetGalleryObjectsHavingTitleOrCaption(string[] searchStrings, GalleryObjectType filter, int galleryId)
        {
            if (searchStrings == null)
                throw new ArgumentNullException();

            var tmpAlbum = Factory.CreateEmptyAlbumInstance(galleryId);
            tmpAlbum.IsVirtualAlbum = true;
            tmpAlbum.VirtualAlbumType = VirtualAlbumType.TitleOrCaption;
            tmpAlbum.Title = String.Concat(Resources.GalleryServerPro.Site_Search_Title, String.Join(Resources.GalleryServerPro.Site_Search_Concat, searchStrings));
            tmpAlbum.Caption = String.Empty;

            var searchOptions = new GalleryObjectSearchOptions
            {
                GalleryId = galleryId,
                SearchType = GalleryObjectSearchType.SearchByTitleOrCaption,
                SearchTerms = searchStrings,
                IsUserAuthenticated = Utils.IsAuthenticated,
                Roles = RoleController.GetGalleryServerRolesForUser(),
                Filter = filter
            };

            var searcher = new GalleryObjectSearcher(searchOptions);

            foreach (var galleryObject in searcher.Find())
            {
                tmpAlbum.AddGalleryObject(galleryObject);
            }

            return tmpAlbum;
        }
        /// <summary>
        /// Gets the requested <paramref name="metaName" /> instance for the specified <paramref name="galleryObjectId" />
        /// having the specified <paramref name="goType" />. Returns null if no metadata item exists.
        /// Verifies user has permission to view item, throwing <see cref="GallerySecurityException" /> 
        /// if authorization is denied.
        /// </summary>
        /// <param name="galleryObjectId">The ID for either an album or a media object.</param>
        /// <param name="goType">The type of gallery object.</param>
        /// <param name="metaName">Name of the metaitem to return.</param>
        /// <returns>Returns an instance of <see cref="IGalleryObjectMetadataItemCollection" />.</returns>
        /// <exception cref="GallerySecurityException">Thrown when user does not have permission to
        /// view the requested item.</exception>
        /// <exception cref="InvalidMediaObjectException">Thrown when the requested meta item or its
        /// associated media object does not exist in the data store.</exception>
        /// <exception cref="InvalidAlbumException">Thrown when the album associated with the
        /// meta item does not exist in the data store.</exception>
        public static IGalleryObjectMetadataItem Get(int galleryObjectId, GalleryObjectType goType, MetadataItemName metaName)
        {
            // Security check: Make sure user has permission to view item
            IGalleryObject go;
            if (goType == GalleryObjectType.Album)
            {
                go = Factory.LoadAlbumInstance(galleryObjectId, false);
                SecurityManager.ThrowIfUserNotAuthorized(SecurityActions.ViewAlbumOrMediaObject, RoleController.GetGalleryServerRolesForUser(), go.Id, go.GalleryId, Utils.IsAuthenticated, go.IsPrivate, ((IAlbum)go).IsVirtualAlbum);
            }
            else
            {
                go = Factory.LoadMediaObjectInstance(galleryObjectId);
                SecurityManager.ThrowIfUserNotAuthorized(SecurityActions.ViewAlbumOrMediaObject, RoleController.GetGalleryServerRolesForUser(), go.Parent.Id, go.GalleryId, Utils.IsAuthenticated, go.Parent.IsPrivate, ((IAlbum)go.Parent).IsVirtualAlbum);
            }

            IGalleryObjectMetadataItem md;
            GetGalleryObjectMetadataItemCollection(galleryObjectId, goType).TryGetMetadataItem(metaName, out md);

            return md;
        }
        /// <summary>
        /// Creates a collection of <see cref="CacheItemMetaItem" /> instances from <paramref name="metadataItems" />. This instance is suitable for storing in cache.
        /// </summary>
        /// <param name="metadataItems">The metadata items.</param>
        /// <param name="galleryObjectId">The ID of the gallery object the <paramref name="metadataItems" /> belong to.</param>
        /// <param name="goType">The type of the gallery object the <paramref name="metadataItems" /> belong to. Any value other than <see cref="GalleryObjectType.Album" />
        /// is assumed to be a media object.</param>
        /// <returns>List&lt;CacheItemMetaItem&gt;.</returns>
        public static List <CacheItemMetaItem> FromMetaItems(IGalleryObjectMetadataItemCollection metadataItems, int galleryObjectId, GalleryObjectType goType)
        {
            var items = new List <CacheItemMetaItem>(metadataItems.Count);

            var albumId = (goType == GalleryObjectType.Album ? new int?(galleryObjectId) : null);
            var moId    = (goType == GalleryObjectType.Album ? null : new int?(galleryObjectId));

            foreach (var mi in metadataItems)
            {
                items.Add(new CacheItemMetaItem(mi.MediaObjectMetadataId, mi.MetadataItemName, moId, albumId, mi.RawValue, mi.Value));
            }

            return(items);
        }
 public IGalleryObjectCollection GetChildGalleryObjects(GalleryObjectType galleryObjectType, bool sortBySequence)
 {
     return(new GalleryObjectCollection());
 }
Example #35
0
		/// <summary>
		/// Create a fully inflated, properly typed media object instance based on the <see cref="IGalleryObject.Id">ID</see>. If <see cref="IGalleryObject.Id">ID</see> is an
		/// image, video, audio, etc, then the appropriate object is returned. An exception is thrown if the
		/// <see cref="IGalleryObject.Id">ID</see> refers to an <see cref="Album" /> (use the <see cref="LoadGalleryObjectInstance" /> or <see cref="LoadAlbumInstance" /> method if
		/// the <see cref="IGalleryObject.Id">ID</see> refers to an album). An exception is also thrown if no matching record exists for this <see cref="IGalleryObject.Id">ID</see>.
		/// If the galleryObjectType parameter is not specified, or is All, None, or Unknown, then an additional 
		/// call to the data store is made to determine the object's type. When you know the type you want (<see cref="Image" />, <see cref="Video" />, 
		/// etc), use the overload that takes the galleryObjectType parameter, or call the specific Factory method that 
		/// loads the desired type, as those are more efficient. This method is guaranteed to never return null.</summary>
		/// <param name="id">An integer representing the <see cref="IGalleryObject.Id">ID</see> of the media object 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. An exception is thrown if the Album enum value is specified, since this method
		/// is designed only for media objects.</param>
		/// <returns>Returns a fully inflated, properly typed media object instance based on the <see cref="IGalleryObject.Id">ID</see>.</returns>
		/// <exception cref="InvalidMediaObjectException">
		/// Thrown when no record exists in the data store for the specified id, or when the id parameter refers to an album.</exception>
		public static IGalleryObject LoadMediaObjectInstance(int id, GalleryObjectType galleryObjectType)
		{
			return RetrieveMediaObject(id, galleryObjectType);
		}