/// <summary>
        /// Gets the media objects having all tags specified in the search options. Guaranteed to not return null.
        /// Only media objects the user has permission to view are returned.
        /// </summary>
        /// <returns>An instance of <see cref="IGalleryObjectCollection" />.</returns>
        private IGalleryObjectCollection GetMediaObjectsHavingTags()
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                var qry = repo.Where(m =>
                                     m.Album.FKGalleryId == SearchOptions.GalleryId &&
                                     m.Metadata.Any(md => md.MetaName == TagType && md.MetadataTags.Any(mdt => SearchOptions.Tags.Contains(mdt.FKTagName))), m => m.Metadata);

                foreach (var moDto in RestrictForCurrentUser(qry))
                {
                    var mediaObject = Factory.GetMediaObjectFromDto(moDto, null);

                    // We have a media object that contains at least one of the tags. If we have multiple tags, do an extra test to ensure
                    // media object matches ALL of them. (I wasn't able to write the LINQ to do this for me, so it's an extra step.)
                    if (SearchOptions.Tags.Length == 1)
                    {
                        galleryObjects.Add(mediaObject);
                    }
                    else if (MetadataItemContainsAllTags(mediaObject.MetadataItems.First(md => md.MetadataItemName == TagType)))
                    {
                        galleryObjects.Add(mediaObject);
                    }
                }
            }

            return(galleryObjects);
        }
Example #2
0
        private IEnumerable <IGalleryObject> FindItemsMatchingKeywords()
        {
            var results = new GalleryObjectCollection();

            using (var repo = new AlbumRepository())
            {
                var qry = repo.Where(a => true, a => a.Metadata);

                qry = SearchOptions.SearchTerms.Aggregate(qry, (current, searchTerm) => current.Where(a =>
                                                                                                      a.FKGalleryId == SearchOptions.GalleryId &&
                                                                                                      a.Metadata.Any(md => md.Value.Contains(searchTerm))));

                foreach (var album in qry)
                {
                    results.Add(Factory.GetAlbumFromDto(album));
                }
            }

            using (var repo = new MediaObjectRepository())
            {
                var qry = repo.Where(a => true, a => a.Metadata);

                qry = SearchOptions.SearchTerms.Aggregate(qry, (current, searchTerm) => current.Where(mo =>
                                                                                                      mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                                                                                                      mo.Metadata.Any(md => md.Value.Contains(searchTerm))));

                foreach (var mediaObject in qry)
                {
                    results.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return(results);
        }
        /// <summary>
        /// Finds the gallery objects with the specified rating. Guaranteed to not return null. Albums cannot be
        /// rated and are thus not returned. Only items the current user is authorized to view are returned.
        /// </summary>
        /// <returns><see cref="IEnumerable&lt;IGalleryObject&gt;" />.</returns>
        private IEnumerable <IGalleryObject> FindMediaObjectsMatchingRating()
        {
            var galleryObjects = new GalleryObjectCollection();

            if (SearchOptions.Filter != GalleryObjectType.Album)
            {
                galleryObjects.AddRange(GetRatedMediaObjects(SearchOptions.MaxNumberResults));
            }

            var filteredGalleryObjects = FilterGalleryObjects(galleryObjects);

            if (filteredGalleryObjects.Count != galleryObjects.Count && filteredGalleryObjects.Count < SearchOptions.MaxNumberResults && galleryObjects.Count >= SearchOptions.MaxNumberResults)
            {
                // We lost some objects in the filter and now we have less than the desired MaxNumberResults. Get more.
                // Note: Performance can be very poor for large galleries when using a filter. For example, a gallery where 20 videos
                // were added and then 200,000 images were added, a search for the most recent 20 videos causes this algorithm
                // to load all 200,000 images into memory before finding the videos. The good news is that by default the filter
                // is for media objects, which will be very fast. If filters end up being commonly used, this algorithm should be improved.
                var       max      = SearchOptions.MaxNumberResults * 2;
                var       skip     = SearchOptions.MaxNumberResults;
                const int maxTries = 5;

                for (var i = 0; i < maxTries; i++)
                {
                    // Add items up to maxTries times, each time doubling the number of items to retrieve.
                    filteredGalleryObjects.AddRange(GetRatedMediaObjects(max, skip));

                    filteredGalleryObjects = FilterGalleryObjects(filteredGalleryObjects);

                    if (filteredGalleryObjects.Count >= SearchOptions.MaxNumberResults)
                    {
                        break;
                    }

                    if (i < (maxTries - 1))
                    {
                        skip = skip + max;
                        max  = max * 2;
                    }
                }

                if (filteredGalleryObjects.Count < SearchOptions.MaxNumberResults)
                {
                    // We still don't have enough objects. Search entire set of albums and media objects.
                    filteredGalleryObjects.AddRange(GetRatedMediaObjects(int.MaxValue, skip));

                    filteredGalleryObjects = FilterGalleryObjects(filteredGalleryObjects);
                }
            }

            if (SearchOptions.MaxNumberResults > 0 && filteredGalleryObjects.Count > SearchOptions.MaxNumberResults)
            {
                return(filteredGalleryObjects.OrderByDescending(g => g.DateAdded).Take(SearchOptions.MaxNumberResults));
            }

            return(filteredGalleryObjects);
        }
Example #4
0
        /// <summary>
        /// Finds the gallery objects matching tags. Guaranteed to not return null. Call this function only when the search type
        /// is <see cref="GalleryObjectSearchType.SearchByTag" /> or <see cref="GalleryObjectSearchType.SearchByPeople" />.
        /// </summary>
        /// <returns>An instance of <see cref="IGalleryObjectCollection" />.</returns>
        private IEnumerable <IGalleryObject> FindItemsMatchingTags()
        {
            var galleryObjects = new GalleryObjectCollection();

            galleryObjects.AddRange(GetAlbumsHavingTags());

            galleryObjects.AddRange(GetMediaObjectsHavingTags());

            return(galleryObjects);
        }
        /// <summary>
        /// Wraps the <paramref name="album" /> in a gallery object collection. When <paramref name="album" /> is null,
        /// an empty collection is returned. Guaranteed to no return null.
        /// </summary>
        /// <param name="album">The album.</param>
        /// <returns>An instance of <see cref="IGalleryObjectCollection" />.</returns>
        private static IEnumerable <IGalleryObject> WrapInGalleryObjectCollection(IAlbum album)
        {
            var result = new GalleryObjectCollection();

            if (album != null)
            {
                result.Add(album);
            }

            return(result);
        }
        /// <summary>
        /// Finds the gallery objects matching tags. Guaranteed to not return null. Call this function only when the search type
        /// is <see cref="GalleryObjectSearchType.SearchByTag" /> or <see cref="GalleryObjectSearchType.SearchByPeople" />.
        /// Only items the user has permission to view are returned.
        /// </summary>
        /// <returns>An instance of <see cref="IGalleryObjectCollection" />.</returns>
        private IEnumerable <IGalleryObject> FindItemsMatchingTags()
        {
            var galleryObjects = new GalleryObjectCollection();

            if (SearchOptions.Filter == GalleryObjectType.All || SearchOptions.Filter == GalleryObjectType.Album)
            {
                galleryObjects.AddRange(GetAlbumsHavingTags());
            }

            if (SearchOptions.Filter != GalleryObjectType.Album)
            {
                galleryObjects.AddRange(GetMediaObjectsHavingTags());
            }

            var filteredGalleryObjects = FilterGalleryObjects(galleryObjects);

            return(SearchOptions.MaxNumberResults > 0 ? filteredGalleryObjects.ToSortedList().Take(SearchOptions.MaxNumberResults) : filteredGalleryObjects);
        }
        /// <summary>
        /// Gets the <paramref name="top" /> most recently added media objects, skipping the first
        /// <paramref name="skip" /> objects. Only media objects the current user is authorized to
        /// view are returned.
        /// </summary>
        /// <param name="top">The number of items to retrieve.</param>
        /// <param name="skip">The number of items to skip over in the data store.</param>
        /// <returns><see cref="IEnumerable&lt;IGalleryObject&gt;" />.</returns>
        private IEnumerable <IGalleryObject> GetRecentlyAddedMediaObjects(int top, int skip = 0)
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                var qry = RestrictForCurrentUser(repo.Where(mo => mo.Album.FKGalleryId == SearchOptions.GalleryId)
                                                 .OrderByDescending(m => m.DateAdded))
                          .Skip(skip).Take(top)
                          .Include(m => m.Metadata);

                foreach (var mediaObject in qry)
                {
                    galleryObjects.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return(galleryObjects);
        }
Example #8
0
		private void ConfigureControls()
		{
			Master.TaskHeader = Resources.GalleryServerPro.Task_Rotate_Image_Header_Text;
			Master.TaskBody = Resources.GalleryServerPro.Task_Rotate_Image_Body_Text;
			Master.OkButtonText = Resources.GalleryServerPro.Task_Rotate_Image_Ok_Button_Text;
			Master.OkButtonToolTip = Resources.GalleryServerPro.Task_Rotate_Image_Ok_Button_Tooltip;

			IGalleryObjectCollection images = new GalleryObjectCollection();
			IGalleryObject image = this.GetMediaObject();
			if (image is GalleryServerPro.Business.Image)
			{
				images.Add(image);
				rptr.DataSource = images;
				rptr.DataBind();
			}
			else
			{
				string[] queryStringNames = new string[] { "moid", "msg" };
				string[] queryStringValues = new string[] { image.Id.ToString(CultureInfo.InvariantCulture), ((int)Message.CannotRotateObjectNotRotatable).ToString(CultureInfo.InvariantCulture) };
				this.RedirectToHomePage(queryStringNames, queryStringValues);
			}
		}
        private IEnumerable <IGalleryObject> GetAlbumsMatchingKeywords()
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new AlbumRepository())
            {
                var qry = repo.Where(a => true, a => a.Metadata);

                qry = SearchOptions.SearchTerms.Aggregate(qry, (current, searchTerm) => current.Where(a =>
                                                                                                      a.FKGalleryId == SearchOptions.GalleryId &&
                                                                                                      a.Metadata.Any(md => md.Value.Contains(searchTerm))));

                qry = RestrictForCurrentUser(qry);

                foreach (var album in qry)
                {
                    galleryObjects.Add(Factory.GetAlbumFromDto(album));
                }
            }

            return(galleryObjects);
        }
Example #10
0
        /// <summary>
        /// Gets the media objects having all tags specified in the search options. Guaranteed to not return null. Only media objects the
        /// user has permission to view are returned.
        /// </summary>
        /// <returns>An instance of <see cref="IGalleryObjectCollection" />.</returns>
        private IEnumerable <IGalleryObject> GetMediaObjectsHavingTags()
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                foreach (var mediaObjectId in GetMediaObjectIdsHavingTags(repo))
                {
                    var mediaObject = Factory.LoadMediaObjectInstance(mediaObjectId);
                    // We have a media object that contains at least one of the tags. If we have multiple tags, do an extra test to ensure
                    // media object matches ALL of them. (I wasn't able to write the LINQ to do this for me, so it's an extra step.)
                    if (SearchOptions.Tags.Length == 1)
                    {
                        galleryObjects.Add(mediaObject);
                    }
                    else if (MetadataItemContainsAllTags(mediaObject.MetadataItems.First(md => md.MetadataItemName == TagType)))
                    {
                        galleryObjects.Add(mediaObject);
                    }
                }
            }

            return(galleryObjects);
        }
        private IEnumerable <IGalleryObject> GetMediaObjectsHavingTitleOrCaption()
        {
            var galleryObjects = new GalleryObjectCollection();

            var metaTagsToSearch = new[] { MetadataItemName.Title, MetadataItemName.Caption };

            using (var repo = new MediaObjectRepository())
            {
                var qry = repo.Where(a => true, a => a.Metadata);

                qry = RestrictForCurrentUser(qry);

                qry = SearchOptions.SearchTerms.Aggregate(qry, (current, searchTerm) => current.Where(mo =>
                                                                                                      mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                                                                                                      mo.Metadata.Any(md => metaTagsToSearch.Contains(md.MetaName) && md.Value.Contains(searchTerm))));

                foreach (var mediaObject in qry)
                {
                    galleryObjects.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return(galleryObjects);
        }
        private IEnumerable<IGalleryObject> FindItemsMatchingTitleOrCaption()
        {
            var galleryObjects = new GalleryObjectCollection();

            if (SearchOptions.Filter == GalleryObjectType.All || SearchOptions.Filter == GalleryObjectType.Album)
            {
                galleryObjects.AddRange(GetAlbumsHavingTitleOrCaption());
            }

            if (SearchOptions.Filter != GalleryObjectType.Album)
            {
                galleryObjects.AddRange(GetMediaObjectsHavingTitleOrCaption());
            }

            var filteredGalleryObjects = FilterGalleryObjects(galleryObjects);

            return (SearchOptions.MaxNumberResults > 0 ? filteredGalleryObjects.ToSortedList().Take(SearchOptions.MaxNumberResults) : filteredGalleryObjects);
        }
        /// <summary>
        /// Finds the gallery objects that have been recently added to the gallery. Guaranteed to not return null.
        /// Only items the current user is authorized to view are returned.
        /// </summary>
        /// <returns><see cref="IEnumerable&lt;IGalleryObject&gt;" />.</returns>
        private IEnumerable<IGalleryObject> FindRecentlyAdded()
        {
            var galleryObjects = new GalleryObjectCollection();

            if (SearchOptions.Filter == GalleryObjectType.All || SearchOptions.Filter == GalleryObjectType.Album)
            {
                galleryObjects.AddRange(GetRecentlyAddedAlbums(SearchOptions.MaxNumberResults));
            }

            if (SearchOptions.Filter != GalleryObjectType.Album)
            {
                galleryObjects.AddRange(GetRecentlyAddedMediaObjects(SearchOptions.MaxNumberResults));
            }

            var filteredGalleryObjects = FilterGalleryObjects(galleryObjects);

            if (filteredGalleryObjects.Count != galleryObjects.Count && filteredGalleryObjects.Count < SearchOptions.MaxNumberResults && galleryObjects.Count >= SearchOptions.MaxNumberResults)
            {
                // We lost some objects in the filter and now we have less than the desired MaxNumberResults. Get more.
                // Note: Performance can be very poor for large galleries when using a filter. For example, a gallery where 20 videos
                // were added and then 200,000 images were added, a search for the most recent 20 videos causes this algorithm
                // to load all 200,000 images into memory before finding the videos. The good news is that by default the filter
                // is for media objects, which will be very fast. If filters end up being commonly used, this algorithm should be improved.
                var max = SearchOptions.MaxNumberResults * 2;
                var skip = SearchOptions.MaxNumberResults;
                const int maxTries = 5;

                for (var i = 0; i < maxTries; i++)
                {
                    // Add items up to maxTries times, each time doubling the number of items to retrieve.
                    filteredGalleryObjects.AddRange(GetRecentlyAddedAlbums(max, skip));
                    filteredGalleryObjects.AddRange(GetRecentlyAddedMediaObjects(max, skip));

                    filteredGalleryObjects = FilterGalleryObjects(filteredGalleryObjects);

                    if (filteredGalleryObjects.Count >= SearchOptions.MaxNumberResults)
                    {
                        break;
                    }

                    if (i < (maxTries - 1))
                    {
                        skip = skip + max;
                        max = max * 2;
                    }
                }

                if (filteredGalleryObjects.Count < SearchOptions.MaxNumberResults)
                {
                    // We still don't have enough objects. Search entire set of albums and media objects.
                    filteredGalleryObjects.AddRange(GetRecentlyAddedAlbums(int.MaxValue, skip));
                    filteredGalleryObjects.AddRange(GetRecentlyAddedMediaObjects(int.MaxValue, skip));

                    filteredGalleryObjects = FilterGalleryObjects(filteredGalleryObjects);
                }
            }

            if (SearchOptions.MaxNumberResults > 0 && filteredGalleryObjects.Count > SearchOptions.MaxNumberResults)
            {
                return filteredGalleryObjects.OrderByDescending(g => g.DateAdded).Take(SearchOptions.MaxNumberResults);
            }

            return filteredGalleryObjects;
        }
        /// <summary>
        /// Gets the media objects having all tags specified in the search options. Guaranteed to not return null. 
        /// Only media objects the user has permission to view are returned.
        /// </summary>
        /// <returns>An instance of <see cref="IGalleryObjectCollection" />.</returns>
        private IGalleryObjectCollection GetMediaObjectsHavingTags()
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                var qry = repo.Where(m =>
                    m.Album.FKGalleryId == SearchOptions.GalleryId &&
                    m.Metadata.Any(md => md.MetaName == TagType && md.MetadataTags.Any(mdt => SearchOptions.Tags.Contains(mdt.FKTagName))), m => m.Metadata);

                foreach (var moDto in RestrictForCurrentUser(qry))
                {
                    var mediaObject = Factory.GetMediaObjectFromDto(moDto, null);

                    // We have a media object that contains at least one of the tags. If we have multiple tags, do an extra test to ensure
                    // media object matches ALL of them. (I wasn't able to write the LINQ to do this for me, so it's an extra step.)
                    if (SearchOptions.Tags.Length == 1)
                    {
                        galleryObjects.Add(mediaObject);
                    }
                    else if (MetadataItemContainsAllTags(mediaObject.MetadataItems.First(md => md.MetadataItemName == TagType)))
                    {
                        galleryObjects.Add(mediaObject);
                    }
                }
            }

            return galleryObjects;
        }
        /// <summary>
        /// Gets the <paramref name="top" /> media objects having the specified rating, skipping the first
        /// <paramref name="skip" /> objects. Only media objects the current user is authorized to
        /// view are returned. Albums cannot be rated and are thus not returned.
        /// </summary>
        /// <param name="top">The number of items to retrieve.</param>
        /// <param name="skip">The number of items to skip over in the data store.</param>
        /// <returns><see cref="IEnumerable&lt;IGalleryObject&gt;" />.</returns>
        private IEnumerable<IGalleryObject> GetRatedMediaObjects(int top, int skip = 0)
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                IQueryable<MediaObjectDto> qry;

                switch (SearchOptions.SearchTerms[0].ToLowerInvariant())
                {
                    case "highest": // Highest rated objects
                        qry = RestrictForCurrentUser(repo.Where(mo =>
                            mo.Album.FKGalleryId == SearchOptions.GalleryId
                            && mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && !String.IsNullOrEmpty(md.Value)))
                            .OrderByDescending(mo => mo.Metadata.Where(md => md.MetaName == MetadataItemName.Rating).Select(md => md.Value).FirstOrDefault())
                            .Include(mo => mo.Metadata)
                            .Skip(skip).Take(top));
                        break;

                    case "lowest": // Lowest rated objects
                        qry = RestrictForCurrentUser(repo.Where(mo =>
                            mo.Album.FKGalleryId == SearchOptions.GalleryId
                                //&& mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && md.Value == "5"))
                            && mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && !String.IsNullOrEmpty(md.Value)))
                            .OrderBy(mo => mo.Metadata.Where(md => md.MetaName == MetadataItemName.Rating).Select(md => md.Value).FirstOrDefault())
                            .Include(mo => mo.Metadata)
                            .Skip(skip).Take(top));
                        break;

                    case "none": // Having no rating
                        qry = RestrictForCurrentUser(repo.Where(mo =>
                            mo.Album.FKGalleryId == SearchOptions.GalleryId
                            && mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && String.IsNullOrEmpty(md.Value)))
                            .OrderBy(mo => mo.DateAdded)
                            .Include(mo => mo.Metadata)
                            .Skip(skip).Take(top));
                        break;

                    default: // Look for a specific rating
                        var r = ParseRating(SearchOptions.SearchTerms[0]);
                        if (r != null)
                        {
                            qry = RestrictForCurrentUser(repo.Where(mo =>
                                mo.Album.FKGalleryId == SearchOptions.GalleryId
                                && mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && r.Contains(md.Value)))
                                .OrderBy(mo => mo.DateAdded)
                                .Include(mo => mo.Metadata)
                                .Skip(skip).Take(top));
                        }
                        else
                        {
                            // The search term is a string other than highest, lowest, none or a decimal. Don't return anything.
                            qry = repo.Where(mo => false);
                        }
                        break;
                }

                foreach (var mediaObject in qry)
                {
                    galleryObjects.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return galleryObjects;
        }
        /// <summary>
        /// Gets the <paramref name="top" /> media objects having the specified rating, skipping the first
        /// <paramref name="skip" /> objects. Only media objects the current user is authorized to
        /// view are returned. Albums cannot be rated and are thus not returned.
        /// </summary>
        /// <param name="top">The number of items to retrieve.</param>
        /// <param name="skip">The number of items to skip over in the data store.</param>
        /// <returns><see cref="IEnumerable&lt;IGalleryObject&gt;" />.</returns>
        private IEnumerable <IGalleryObject> GetRatedMediaObjects(int top, int skip = 0)
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                IQueryable <MediaObjectDto> qry;

                switch (SearchOptions.SearchTerms[0].ToLowerInvariant())
                {
                case "highest":                         // Highest rated objects
                    qry = RestrictForCurrentUser(repo.Where(mo =>
                                                            mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                                                            mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && !String.IsNullOrEmpty(md.Value)))
                                                 .OrderByDescending(mo => mo.Metadata.Where(md => md.MetaName == MetadataItemName.Rating).Select(md => md.Value).FirstOrDefault())
                                                 .Include(mo => mo.Metadata)
                                                 .Skip(skip).Take(top));
                    break;

                case "lowest":                         // Lowest rated objects
                    qry = RestrictForCurrentUser(repo.Where(mo =>
                                                            mo.Album.FKGalleryId == SearchOptions.GalleryId
                                                            //&& mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && md.Value == "5"))
                                                            && mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && !String.IsNullOrEmpty(md.Value)))
                                                 .OrderBy(mo => mo.Metadata.Where(md => md.MetaName == MetadataItemName.Rating).Select(md => md.Value).FirstOrDefault())
                                                 .Include(mo => mo.Metadata)
                                                 .Skip(skip).Take(top));
                    break;

                case "none":                         // Having no rating
                    qry = RestrictForCurrentUser(repo.Where(mo =>
                                                            mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                                                            mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && String.IsNullOrEmpty(md.Value)))
                                                 .OrderBy(mo => mo.DateAdded)
                                                 .Include(mo => mo.Metadata)
                                                 .Skip(skip).Take(top));
                    break;

                default:                         // Look for a specific rating
                    var r = ParseRating(SearchOptions.SearchTerms[0]);
                    if (r != null)
                    {
                        qry = RestrictForCurrentUser(repo.Where(mo =>
                                                                mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                                                                mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && r.Contains(md.Value)))
                                                     .OrderBy(mo => mo.DateAdded)
                                                     .Include(mo => mo.Metadata)
                                                     .Skip(skip).Take(top));
                    }
                    else
                    {
                        // The search term is a string other than highest, lowest, none or a decimal. Don't return anything.
                        qry = repo.Where(mo => false);
                    }
                    break;
                }

                foreach (var mediaObject in qry)
                {
                    galleryObjects.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return(galleryObjects);
        }
Example #17
0
		/// <summary>
		/// Move or copy the objects. An exception is thrown if the user does not have the required permission or is 
		/// trying to transfer an object to itself.
		/// </summary>
		/// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.GallerySecurityException">Thrown when the logged on 
		/// user does not belong to a role that authorizes the moving or copying.</exception>
		/// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.CannotTransferAlbumToNestedDirectoryException">
		/// Thrown when the user tries to move or copy an album to one of its children albums.</exception>
		private void TransferObjects()
		{
			#region Get list of objects to move or copy

			string[] galleryObjectIds = (string[])ViewState["ids"];

			// Convert the string array of IDs to integers. Also assign whether each is an album or media object.
			// (Determined by the first character of each ids string: a=album; m=media object)
			int id;
			char idType;

			IGalleryObjectCollection objectsToMoveOrCopy = new GalleryObjectCollection();
			for (int i = 0; i < galleryObjectIds.Length; i++)
			{
				id = Convert.ToInt32(galleryObjectIds[i].Substring(1), CultureInfo.InvariantCulture);
				idType = Convert.ToChar(galleryObjectIds[i].Substring(0, 1), CultureInfo.InvariantCulture);

				if (idType == 'a')
				{
					objectsToMoveOrCopy.Add(Factory.LoadAlbumInstance(id, false));
				}
				else if (idType == 'm')
				{
					// Grab a reference to the media object through the base page's album instead of using Factory.LoadMediaObjectInstance().
					// This causes the base page's album object to have an accurate state of the child objects so that when we assign the
					// thumbnail object later in this page life cycle, it works correctly.
					objectsToMoveOrCopy.Add(this.GetAlbum().GetChildGalleryObjects(GalleryObjectType.MediaObject).FindById(id, GalleryObjectType.MediaObject));
				}
				else
					throw new WebException("Invalid object identifier in method transferObjects(). Expected: 'a' or 'm'. Found: " + idType.ToString());
			}

			#endregion

			#region Validate (throws exception if it doesn't validate)

			ValidateObjectsCanBeMovedOrCopied(objectsToMoveOrCopy);

			#endregion

			try
			{
				HelperFunctions.BeginTransaction();

				#region Move or copy each object

				foreach (IGalleryObject galleryObject in objectsToMoveOrCopy)
				{
					IAlbum album = galleryObject as IAlbum;
					if (album == null)
					{
						if (this.TransType == TransferType.Move)
							MoveMediaObject(galleryObject);
						else
							CopyMediaObject(galleryObject);
					}
					else
					{
						if (this.TransType == TransferType.Move)
							MoveAlbum(album);
						else
							CopyAlbum(album);
					}
				}

				#endregion

				#region Update album thumbnails

				// In case we moved the last object out of an album or we moved out the object that had also 
				// been the album's thumbnail image, run this method to make sure the album's thumbnail is
				// correct, as well as its parent, grandparent, and so on until the root album.
				Album.AssignAlbumThumbnail(this.GetAlbum(), true, false, User.Identity.Name);

				#endregion

				HelperFunctions.CommitTransaction();
			}
			catch
			{
				HelperFunctions.RollbackTransaction();	
				throw;
			}
		}
        private IEnumerable<IGalleryObject> GetMediaObjectsHavingTitleOrCaption()
        {
            var galleryObjects = new GalleryObjectCollection();

            var metaTagsToSearch = new[] { MetadataItemName.Title, MetadataItemName.Caption };

            using (var repo = new MediaObjectRepository())
            {
                var qry = repo.Where(a => true, a => a.Metadata);

                qry = RestrictForCurrentUser(qry);

                qry = SearchOptions.SearchTerms.Aggregate(qry, (current, searchTerm) => current.Where(mo =>
                    mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                    mo.Metadata.Any(md => metaTagsToSearch.Contains(md.MetaName) && md.Value.Contains(searchTerm))));

                foreach (var mediaObject in qry)
                {
                    galleryObjects.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return galleryObjects;
        }
Example #19
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);
        }
        /// <summary>
        /// Return gallery objects that match the specified search string and for which the specified user has authorization
        /// to view. A gallery object is considered a match when all search terms are found in the relevant fields.
        /// For albums, the title and summary fields are searched. For media objects, the title, original filename,
        /// and metadata are searched. The contents of documents are not searched (e.g. the text of a Word or PDF file).
        /// If no matches are found, an empty collection is returned. If the userIsAuthenticated parameter is true, only those
        /// objects for which the user has authorization are returned. If userIsAuthenticated=false (i.e. the user is anonymous),
        /// only non-private matching objects are returned.
        /// </summary>
        /// <param name="galleryId">The ID for the gallery containing the objects to search.</param>
        /// <param name="searchText">A space or comma-delimited string of search terms. Double quotes (") may be used
        /// to combine more than one word into a single search term. Example: cat "0 step" Mom will search for all
        /// objects that contain the strings "cat", "0 step", and "Mom".</param>
        /// <param name="roles">A collection of Gallery Server roles to which the currently logged-on user belongs.
        /// This parameter is ignored when userIsAuthenticated=false.</param>
        /// <param name="userIsAuthenticated">A value indicating whether the current user is logged on. If true, the
        /// roles parameter should contain the names of the roles for the current user. If userIsAuthenticated=true and
        /// the roles parameter is either null or an empty collection, this method returns an empty collection.</param>
        /// <returns>
        /// Returns a GalleryObjectCollection containing the matching items. This may include albums and media
        /// objects from different albums.
        /// </returns>
        public static IGalleryObjectCollection SearchGallery(int galleryId, string searchText, IGalleryServerRoleCollection roles, bool userIsAuthenticated)
        {
            string[] searchTerms = ParseSearchText(searchText);

            List<int> matchingAlbumIds;
            List<int> matchingMediaObjectIds;
            Factory.GetDataProvider().SearchGallery(galleryId, searchTerms, out matchingAlbumIds, out matchingMediaObjectIds);

            IGalleryObjectCollection galleryObjects = new GalleryObjectCollection();

            matchingAlbumIds.ForEach(delegate(int albumId)
                                                                {
                                                                    IGalleryObject album = Factory.LoadAlbumInstance(albumId, false);
                                                                    if (SecurityManager.IsUserAuthorized(SecurityActions.ViewAlbumOrMediaObject, roles, albumId, galleryId, userIsAuthenticated, album.IsPrivate))
                                                                    {
                                                                        galleryObjects.Add(album); // All security checks OK. Add to collection.
                                                                    }
                                                                });

            matchingMediaObjectIds.ForEach(delegate(int mediaObjectId)
                                                                            {
                                                                                IGalleryObject mediaObject = Factory.LoadMediaObjectInstance(mediaObjectId);
                                                                                if (SecurityManager.IsUserAuthorized(SecurityActions.ViewAlbumOrMediaObject, roles, mediaObject.Parent.Id, galleryId, userIsAuthenticated, mediaObject.IsPrivate))
                                                                                {
                                                                                    galleryObjects.Add(mediaObject); // User is authorized to view this media object.
                                                                                }
                                                                            });

            return galleryObjects;
        }
        /// <summary>
        /// Gets the <paramref name="top" /> most recently added media objects, skipping the first
        /// <paramref name="skip" /> objects. Only media objects the current user is authorized to
        /// view are returned.
        /// </summary>
        /// <param name="top">The number of items to retrieve.</param>
        /// <param name="skip">The number of items to skip over in the data store.</param>
        /// <returns><see cref="IEnumerable&lt;IGalleryObject&gt;" />.</returns>
        private IEnumerable<IGalleryObject> GetRecentlyAddedMediaObjects(int top, int skip = 0)
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                var qry = RestrictForCurrentUser(repo.Where(mo => mo.Album.FKGalleryId == SearchOptions.GalleryId)
                    .OrderByDescending(m => m.DateAdded))
                    .Skip(skip).Take(top)
                    .Include(m => m.Metadata);

                foreach (var mediaObject in qry)
                {
                    galleryObjects.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return galleryObjects;
        }
        /// <summary>
        /// Wraps the <paramref name="album" /> in a gallery object collection. When <paramref name="album" /> is null,
        /// an empty collection is returned. Guaranteed to no return null. 
        /// </summary>
        /// <param name="album">The album.</param>
        /// <returns>An instance of <see cref="IGalleryObjectCollection" />.</returns>
        private static IEnumerable<IGalleryObject> WrapInGalleryObjectCollection(IAlbum album)
        {
            var result = new GalleryObjectCollection();

            if (album != null)
                result.Add(album);

            return result;
        }
		/// <summary>
		/// Move or copy the objects. An exception is thrown if the user does not have the required permission or is 
		/// trying to transfer an object to itself.
		/// </summary>
		/// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.GallerySecurityException">Thrown when the logged on 
		/// user does not belong to a role that authorizes the moving or copying.</exception>
		/// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.CannotTransferAlbumToNestedDirectoryException">
		/// Thrown when the user tries to move or copy an album to one of its children albums.</exception>
		private void TransferObjects()
		{
			#region Get list of objects to move or copy

			string[] galleryObjectIds = (string[])ViewState["ids"];

			// Convert the string array of IDs to integers. Also assign whether each is an album or media object.
			// (Determined by the first character of each ids string: a=album; m=media object)
			IGalleryObjectCollection objectsToMoveOrCopy = new GalleryObjectCollection();
			for (int i = 0; i < galleryObjectIds.Length; i++)
			{
				int id = Convert.ToInt32(galleryObjectIds[i].Substring(1), CultureInfo.InvariantCulture);
				char idType = Convert.ToChar(galleryObjectIds[i].Substring(0, 1), CultureInfo.InvariantCulture);

				if (idType == 'a')
				{
					try
					{
						IAlbum album = AlbumController.LoadAlbumInstance(id, false, true);

						objectsToMoveOrCopy.Add(album);
					}
					catch (InvalidAlbumException) { /* Album may have been deleted by someone else, so just skip it. */ }
				}
				else if (idType == 'm')
				{
					// Grab a reference to the media object through the base page's album instead of using Factory.LoadMediaObjectInstance().
					// This causes the base page's album object to have an accurate state of the child objects so that when we assign the
					// thumbnail object later in this page life cycle, it works correctly.
					IGalleryObject mediaObject = Factory.LoadMediaObjectInstance(id, true);
					//IGalleryObject mediaObject = this.GetAlbum().GetChildGalleryObjects(GalleryObjectType.MediaObject).FindById(id, GalleryObjectType.MediaObject);

					if (mediaObject != null) /* Media object may have been deleted by someone else, so just skip it. */
					{
						objectsToMoveOrCopy.Add(mediaObject);
					}
				}
				else
					throw new WebException("Invalid object identifier in method transferObjects(). Expected: 'a' or 'm'. Found: " + idType);
			}

			#endregion

			#region Validate (throws exception if it doesn't validate)

			ValidateObjectsCanBeMovedOrCopied(objectsToMoveOrCopy);

			#endregion

			try
			{
				HelperFunctions.BeginTransaction();

				#region Move or copy each object

				foreach (IGalleryObject galleryObject in objectsToMoveOrCopy)
				{
					IAlbum album = galleryObject as IAlbum;
					if (album == null)
					{
						if (this.TransType == TransferType.Move)
							MoveMediaObject(galleryObject);
						else
							CopyMediaObject(galleryObject);
					}
					else
					{
						if (this.TransType == TransferType.Move)
							MoveAlbum(album);
						else
							CopyAlbum(album);
					}
				}

				#endregion

				HelperFunctions.CommitTransaction();
			}
			catch
			{
				HelperFunctions.RollbackTransaction();
				throw;
			}
		}
Example #24
0
		/// <summary>
		/// Prepare a list of albums whose thumbnail images will need updating after the move operation completes. Only applies to the album
		/// hierarchy the object is moved FROM (the thumbnail in the destination album is updated by code in the <see cref="Save" /> method). It works by
		/// analyzing the parent albums, recursively, of the current gallery object, until reaching either the root album or the specified
		/// destination album, looking for any album that has a thumbnail matching the specified thumbnailMediaObjectId. For each match,
		/// clear out the ThumbnailMediaObjectId property, add the album to a list, and finally return it. The caller is responsible 
		/// for iterating through this list and calling <see cref="Album.AssignAlbumThumbnail" /> for each album after the move operation is complete.
		/// This method should be called before the move operation takes place.
		/// </summary>
		/// <param name="mediaObjectId">The ID of a media object. If this media object is assigned as the thumbnail for any
		/// albums in the current gallery object's parent albums, then add those albums to a list and return it to the caller.</param>
		/// <param name="destinationAlbumId">The ID of the album the current gallery object will be in after the move operation completes.</param>
		/// <returns>Return a list of albums whose thumbnail images will need updating after the move operation completes.</returns>
		protected IGalleryObjectCollection ValidateAlbumThumbnailsForMove(int mediaObjectId, int destinationAlbumId)
		{
			IGalleryObjectCollection albumsNeedingNewThumbnails = new GalleryObjectCollection();
			IGalleryObject albumInSourceHierarchy = this.Parent;
			IAlbum albumToTest;

			while (!(albumInSourceHierarchy is NullObjects.NullGalleryObject))
			{
				// If we're at the same level as the destination album, don't go any further since there isn't any need to clear
				// out the album thumbnails for any albums above this point.
				if (albumInSourceHierarchy.Id == destinationAlbumId)
					break;

				albumToTest = (IAlbum)albumInSourceHierarchy;
				if ((mediaObjectId > 0) && (mediaObjectId == albumToTest.ThumbnailMediaObjectId))
				{
					albumToTest.ThumbnailMediaObjectId = 0;
					albumsNeedingNewThumbnails.Add(albumToTest);
				}

				albumInSourceHierarchy = albumInSourceHierarchy.Parent;
			}

			return albumsNeedingNewThumbnails;
		}
Example #25
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="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(bool sortBySequence, bool excludePrivateObjects)
        {
            GalleryObjectCollection childMediaObjects = (GalleryObjectCollection)this.GetChildGalleryObjects();

            if (sortBySequence)
            {
                childMediaObjects.Sort();
            }

            if (excludePrivateObjects)
            {
                // Only return public objects (IsPrivate = false).
                IGalleryObjectCollection filteredGalleryObjects = new GalleryObjectCollection();
                foreach (IGalleryObject galleryObject in childMediaObjects)
                {
                    if (!galleryObject.IsPrivate)
                    {
                        filteredGalleryObjects.Add(galleryObject);
                    }
                }

                return filteredGalleryObjects;
            }
            else
            {
                return childMediaObjects;
            }
        }
        private void ConfigureControls()
        {
            this.TaskHeaderText = Resources.GalleryServerPro.Task_Rotate_Image_Header_Text;
            this.TaskBodyText = Resources.GalleryServerPro.Task_Rotate_Image_Body_Text;
            this.OkButtonText = Resources.GalleryServerPro.Task_Rotate_Image_Ok_Button_Text;
            this.OkButtonToolTip = Resources.GalleryServerPro.Task_Rotate_Image_Ok_Button_Tooltip;

            this.PageTitle = Resources.GalleryServerPro.Task_Rotate_Image_Page_Title;

            IGalleryObjectCollection images = new GalleryObjectCollection();
            IGalleryObject image = this.GetMediaObject();

            if (image is GalleryServerPro.Business.Image)
            {
                images.Add(image);
                rptr.DataSource = images;
                rptr.DataBind();
            }
            else
            {
                Utils.Redirect(Web.PageId.mediaobject, "moid={0}&msg={1}", image.Id, ((int)Message.CannotRotateObjectNotRotatable).ToString(CultureInfo.InvariantCulture));
            }
        }
        private IEnumerable<IGalleryObject> GetMediaObjectsMatchingKeywords()
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                var qry = repo.Where(a => true, a => a.Metadata);

                qry = SearchOptions.SearchTerms.Aggregate(qry, (current, searchTerm) => current.Where(mo =>
                    mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                    mo.Metadata.Any(md => md.Value.Contains(searchTerm))));

                qry = RestrictForCurrentUser(qry);

                foreach (var mediaObject in qry)
                {
                    galleryObjects.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return galleryObjects;
        }