Ejemplo n.º 1
0
        /// <summary>
        /// Gets the highest-level album the current user can view. Guaranteed to not return null. If a user does not have permission to 
        /// view any objects, this function returns a virtual album with no objects and automatically assigns the <see cref="ClientMessage" /> 
        /// property to <see cref="MessageType.NoAuthorizedAlbumForUser" />, which will cause a message to be displayed to the user.
        /// </summary>
        /// <returns>Returns an IAlbum representing the highest-level album the current user can view.</returns>
        private IAlbum GetHighestAlbumUserCanView()
        {
            var galleryObjectSearcher = new GalleryObjectSearcher(new GalleryObjectSearchOptions()
                                                                                                                            {
                                                                                                                                GalleryId = GalleryId,
                                                                                                                                SearchType = GalleryObjectSearchType.HighestAlbumUserCanView,
                                                                                                                                Roles = RoleController.GetGalleryServerRolesForUser(),
                                                                                                                                IsUserAuthenticated = Utils.IsAuthenticated,
                                                                                                                                Filter = GalleryObjectType.Album
                                                                                                                            });

            var album = galleryObjectSearcher.FindOne();

            var tempAlbum = album as IAlbum;

            if (album != null && tempAlbum == null)
            {
                throw new WebException(String.Format(CultureInfo.InvariantCulture, "A gallery object search for {0} returned an object that couldn't be cast to IAlbum. It was a {1}.", GalleryObjectSearchType.HighestAlbumUserCanView, album.GetType()));
            }

            if (album == null)
            {
                // Create virtual album so that page has something to bind to.
                tempAlbum = Factory.CreateEmptyAlbumInstance(GalleryId);
                tempAlbum.IsVirtualAlbum = true;
                tempAlbum.VirtualAlbumType = VirtualAlbumType.Root;
                tempAlbum.Title = Resources.GalleryServerPro.Site_Virtual_Album_Title;
                tempAlbum.Caption = String.Empty;

                if (Array.IndexOf(new[] { PageId.login, PageId.recoverpassword, PageId.createaccount }, PageId) < 0)
                {
                    ClientMessage = GetMessageOptions(MessageType.NoAuthorizedAlbumForUser);
                }
            }

            return tempAlbum;
        }
        /// <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;
        }
        /// <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;
        }
        //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 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;
        }
Ejemplo n.º 6
0
		/// <summary>
		/// Return all top-level albums in the specified <paramref name = "galleryId">gallery</paramref> where the <paramref name = "roles" /> 
		/// provide view permission to the album. If more than one album is found, they are wrapped in a virtual container 
		/// album where the <see cref="IAlbum.IsVirtualAlbum" /> property is set to true. If the roles do not provide permission to any
		/// objects in the gallery, then a virtual album is returned where <see cref="IAlbum.IsVirtualAlbum" />=<c>true</c> and 
		/// <see cref="IGalleryObject.Id" />=<see cref="Int32.MinValue" />. Returns null if no matching albums are found.
		/// </summary>
		/// <param name="galleryId">The gallery ID.</param>
		/// <param name="roles">The roles belonging to a user.</param>
		/// <param name="isAuthenticated">Indicates whether the user belonging to the <paramref name="roles" /> is authenticated.</param>
		/// <returns>
		/// Returns an <see cref="IAlbum" /> that is or contains the top-level album(s) that the <paramref name = "roles" />
		/// provide view permission for. Returns null if no matching albums are found.
		/// </returns>
		public static IAlbum LoadRootAlbum(int galleryId, IGalleryServerRoleCollection roles, bool isAuthenticated)
		{
			var galleryObjectSearcher = new GalleryObjectSearcher(new GalleryObjectSearchOptions()
			{
				GalleryId = galleryId,
				SearchType = GalleryObjectSearchType.HighestAlbumUserCanView,
				Roles = roles,
				IsUserAuthenticated = isAuthenticated,
				Filter = GalleryObjectType.Album
			});

			return galleryObjectSearcher.FindOne() as IAlbum;
		}