예제 #1
0
 /// <summary>
 /// Adds the galleryObjects to the current collection.
 /// </summary>
 /// <param name="galleryObjects">The gallery objects to add to the current collection.</param>
 public void AddRange(IGalleryObjectCollection galleryObjects)
 {
     foreach (IGalleryObject galleryObject in galleryObjects)
     {
         this.Add(galleryObject);
     }
 }
예제 #2
0
        private void ConfigureControls()
        {
            this.TaskHeaderText  = Resources.GalleryServerPro.Task_Edit_Captions_Header_Text;
            this.TaskBodyText    = String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.Task_Edit_Captions_Body_Text, GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().DataStore.MediaObjectTitleLength);
            this.OkButtonText    = Resources.GalleryServerPro.Task_Edit_Captions_Ok_Button_Text;
            this.OkButtonToolTip = Resources.GalleryServerPro.Task_Edit_Captions_Ok_Button_Tooltip;

            this.PageTitle = Resources.GalleryServerPro.Task_Edit_Captions_Page_Title;

            IGalleryObjectCollection albumChildren = this.GetAlbum().GetChildGalleryObjects(GalleryObjectType.MediaObject, true);

            if (albumChildren.Count > 0)
            {
                const int textareaWidthBuffer  = 30;                // Extra width padding to allow room for the caption.
                const int textareaHeightBuffer = 72;                // Extra height padding to allow room for the caption.
                SetThumbnailCssStyle(albumChildren, textareaWidthBuffer, textareaHeightBuffer);

                rptr.DataSource = albumChildren;
                rptr.DataBind();
            }
            else
            {
                this.RedirectToAlbumViewPage("msg={0}", ((int)Message.CannotEditCaptionsNoEditableObjectsExistInAlbum).ToString(CultureInfo.InvariantCulture));
            }
        }
예제 #3
0
        private void ConfigureControls()
        {
            this.TaskHeaderText = Resources.GalleryServerPro.Task_Rearrange_Objects_Header_Text;
            this.TaskBodyText   = Resources.GalleryServerPro.Task_Rearrange_Objects_Body_Text;
            this.OkButtonBottom.OnClientClick = "retrieveOrder();";
            this.OkButtonTop.OnClientClick    = "retrieveOrder();";

            this.PageTitle = Resources.GalleryServerPro.Task_Rearrange_Objects_Page_Title;

            IGalleryObjectCollection albumChildren = this.GetAlbum().GetChildGalleryObjects(true);

            if (albumChildren.Count > 0)
            {
                SetThumbnailCssStyle(albumChildren, 0, 0, new string[] { "thmb2", "snapDock" });

                // Bind the docking containers (really, just div tags) that will hold each snap control.
                this._snapDockIds  = new string[albumChildren.Count];
                rprDock.DataSource = albumChildren;
                rprDock.DataBind();                 // _snapDockIds is updated within GetSnapDockId() during data binding (it is invoked from aspx markup)

                // Reset media object index to 0 and bind the snaps to the page. Each snap is assigned to one of the snap docks that
                // were bound in the rprDock.DataBind method.
                this._galleryObjectIds = new string[albumChildren.Count];
                this._mediaObjectIndex = 0;
                rprSnap.DataSource     = albumChildren;
                rprSnap.DataBind();

                this.Page.ClientScript.RegisterArrayDeclaration("_snapDockIds", String.Concat("'", String.Join("','", this._snapDockIds), "'"));
            }
            else
            {
                this.RedirectToAlbumViewPage("msg={0}", ((int)Message.CannotRearrangeNoObjectsExistInAlbum).ToString(CultureInfo.InvariantCulture));
            }
        }
예제 #4
0
		public void DisplayThumbnails(IGalleryObjectCollection galleryObjects)
		{
			this.PageBase.SetThumbnailCssStyle(galleryObjects);

			rptr.DataSource = galleryObjects;
			rptr.DataBind();
		}
예제 #5
0
        private void ConfigureControls()
        {
            this.TaskHeaderText  = Resources.GalleryServerPro.Task_Edit_Captions_Header_Text;
            this.TaskBodyText    = Resources.GalleryServerPro.Task_Edit_Captions_Body_Text;
            this.OkButtonText    = SueetieLocalizer.GetString("process_updates", "MediaGallery.xml");
            this.OkButtonToolTip = Resources.GalleryServerPro.Task_Edit_Captions_Ok_Button_Tooltip;

            this.PageTitle = Resources.GalleryServerPro.Task_Edit_Captions_Page_Title;

            // Sueetie Modified - Converting GSP galleryObjects into SueetieGalleryObjects
            List <SueetieMediaObject> sueetieMediaObjects = new List <SueetieMediaObject>();

            IGalleryObjectCollection albumChildren = this.GetAlbum().GetChildGalleryObjects(GalleryObjectType.MediaObject, true);

            foreach (IGalleryObject _galleryObject in albumChildren)
            {
                SueetieMediaObject _sueetieMediaObject = SueetieMedia.GetSueetieMediaObject(this.CurrentSueetieGalleryID, _galleryObject.Id);
                MediaHelper.PopulateMediaObject(_sueetieMediaObject, _galleryObject);
                sueetieMediaObjects.Add(_sueetieMediaObject);
            }

            if (albumChildren.Count > 0)
            {
                const int textareaWidthBuffer  = 30;                // Extra width padding to allow room for the caption.
                const int textareaHeightBuffer = 72;                // Extra height padding to allow room for the caption.
                SetThumbnailCssStyle(albumChildren, textareaWidthBuffer, textareaHeightBuffer);

                rptr.DataSource = sueetieMediaObjects;
                rptr.DataBind();
            }
            else
            {
                this.RedirectToAlbumViewPage("msg={0}", ((int)Message.CannotEditCaptionsNoEditableObjectsExistInAlbum).ToString(CultureInfo.InvariantCulture));
            }
        }
예제 #6
0
        private void ConfigureControls()
        {
            this.TaskHeaderText  = Resources.GalleryServerPro.Task_Rotate_Images_Header_Text;
            this.TaskBodyText    = Resources.GalleryServerPro.Task_Rotate_Images_Body_Text;
            this.OkButtonText    = Resources.GalleryServerPro.Task_Rotate_Images_Ok_Button_Text;
            this.OkButtonToolTip = Resources.GalleryServerPro.Task_Rotate_Images_Ok_Button_Tooltip;

            this.PageTitle = Resources.GalleryServerPro.Task_Rotate_Image_Page_Title;

            IGalleryObjectCollection albumChildren = this.GetAlbum().GetChildGalleryObjects(GalleryObjectType.Image, true);

            if (albumChildren.Count > 0)
            {
                const int widthBuffer  = 20;                // Extra width padding to allow room for the icon images.
                const int heightBuffer = 20;                // Extra height padding to allow room for the icon images.
                SetThumbnailCssStyle(albumChildren, widthBuffer, heightBuffer, "thmbRotate");

                rptr.DataSource = albumChildren;
                rptr.DataBind();
            }
            else
            {
                this.RedirectToAlbumViewPage("msg={0}", ((int)Message.CannotRotateNoRotateableObjectsExistInAlbum).ToString(CultureInfo.InvariantCulture));
            }
        }
예제 #7
0
        private void SearchGallery(string searchText)
        {
            IGalleryObjectCollection galleryObjects = null;

            if (!String.IsNullOrEmpty(searchText))
            {
                // Search gallery and display results.
                galleryObjects = HelperFunctions.SearchGallery(this.GalleryId, searchText, this.GetGalleryServerRolesForUser(), Util.IsAuthenticated);

                if (galleryObjects != null)
                {
                    tv.GalleryObjectsDataSource = galleryObjects;
                    searchResultTitle.InnerText = String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.Search_Results_Text, galleryObjects.Count);
                }
                else
                {
                    tv.Visible = false;
                }
            }
            else // No search text found
            {
                searchResultTitle.InnerText = Resources.GalleryServerPro.Search_Instructions;
                tv.Visible = false;
            }
        }
		/// <summary>
		/// Adds the galleryObjects to the current collection.
		/// </summary>
		/// <param name="galleryObjects">The gallery objects to add to the current collection.</param>
		/// <exception cref="ArgumentNullException">Thrown when <paramref name="galleryObjects" /> is null.</exception>
		public void AddRange(IGalleryObjectCollection galleryObjects)
		{
			if (galleryObjects == null)
				throw new ArgumentNullException("galleryObjects");

			foreach (IGalleryObject galleryObject in galleryObjects)
			{
				this.Add(galleryObject);
			}
		}
예제 #9
0
파일: Album.cs 프로젝트: haimon74/KanNaim
		/// <summary>
		/// Initializes a new instance of the <see cref="Album"/> class.
		/// </summary>
		/// <param name="id">The album ID.</param>
		/// <param name="parentId">The ID of the parent album that contains this album.</param>
		/// <param name="title">The title.</param>
		/// <param name="directoryName">Name of the directory.</param>
		/// <param name="summary">The summary.</param>
		/// <param name="thumbnailMediaObjectId">The thumbnail media object id.</param>
		/// <param name="sequence">The sequence.</param>
		/// <param name="dateStart">The starting date for this album.</param>
		/// <param name="dateEnd">The ending date for this album.</param>
		/// <param name="createdByUsername">The user name of the user who created this gallery object.</param>
		/// <param name="dateAdded">The date this gallery object was created.</param>
		/// <param name="lastModifiedByUsername">The user name of the user who last modified this gallery object.</param>
		/// <param name="dateLastModified">The date and time this gallery object was last modified.</param>
		/// <param name="ownerUsername">The user name of this gallery object's owner.</param>
		/// <param name="ownerRoleName">The name of the role associated with this gallery object's owner.</param>
		/// <param name="isPrivate"><c>true</c> this gallery object is hidden from anonymous users; otherwise <c>false</c>.</param>
  	internal Album(int id, int parentId, string title, string directoryName, string summary, int thumbnailMediaObjectId, int sequence, DateTime dateStart, DateTime dateEnd, string createdByUsername, DateTime dateAdded, string lastModifiedByUsername, DateTime dateLastModified, string ownerUsername, string ownerRoleName, bool isPrivate)
  	{
  		this._galleryObjects = new GalleryObjectCollection();
  		System.Diagnostics.Debug.Assert(this._areChildrenInflated == false, string.Format(CultureInfo.CurrentCulture, "The private boolean field _areChildrenInflated should have been initialized to false, but instead it was {0}.", this._areChildrenInflated.ToString()));

  		this.Id = id;

  		if (parentId > 0)
  			this.Parent = Factory.CreateAlbumInstance(parentId);
  		else if (parentId == 0)
  			this.Parent.Id = parentId; // Parent ID of root album is always 0.

  		this.Title = title;
  		this._directoryName = directoryName;
  		this._summary = summary;
  		this.Sequence = sequence;
  		this._dateStart = dateStart;
  		this._dateEnd = dateEnd;
  		this.CreatedByUserName = createdByUsername;
  		this.DateAdded = dateAdded;
  		this.LastModifiedByUserName = lastModifiedByUsername;
  		this._ownerUsername = ownerUsername;
			this._ownerRoleName = ownerRoleName;
  		this.DateLastModified = dateLastModified;
  		this.IsPrivate = isPrivate;
  		this._fullPhysicalPathOnDisk = string.Empty;

  		//this._thumbnailMediaObjectId = (thumbnailMediaObjectId == int.MinValue ? 0 : thumbnailMediaObjectId);
  		this.ThumbnailMediaObjectId = (thumbnailMediaObjectId == int.MinValue ? 0 : thumbnailMediaObjectId);
  		this._isThumbnailInflated = false;

  		IDisplayObject albumThumbnail = null;
  		if (this._thumbnailMediaObjectId > 0)
  		{
  			albumThumbnail = DisplayObject.CreateInstance(this, this._thumbnailMediaObjectId, DisplayObjectType.Thumbnail);
  		}
  		else
  		{
  			albumThumbnail = GetDefaultAlbumThumbnail();
  		}

  		this.Thumbnail = albumThumbnail;

  		this.SaveBehavior = Factory.GetAlbumSaveBehavior(this);
  		this.DeleteBehavior = Factory.GetAlbumDeleteBehavior(this);

  		// Setting the previous properties has caused HasChanges = true, but we don't want this while
  		// we're instantiating a new object. Reset to false.
  		this.HasChanges = false;

  		this.Saving += new EventHandler(Album_Saving);
  		this.Saved += new EventHandler(Album_Saved);
  	}
예제 #10
0
        /// <summary>
        /// Throw exception if the specified albums and/or media objects cannot be moved or copied for any reason,
        /// such as lack of user permission or trying to move/copy objects to itself.
        /// </summary>
        /// <param name="objectsToMoveOrCopy">The albums or media objects to move or copy.</param>
        /// <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 ValidateObjectsCanBeMovedOrCopied(IGalleryObjectCollection objectsToMoveOrCopy)
        {
            bool movingOrCopyingAtLeastOneAlbum       = false;
            bool movingOrCopyingAtLeastOneMediaObject = false;

            #region Validate the albums and media objects we are moving or copying

            bool securityCheckCompleteForAlbum       = false;
            bool securityCheckCompleteForMediaObject = false;

            foreach (IGalleryObject galleryObject in objectsToMoveOrCopy)
            {
                if (galleryObject is Album)
                {
                    ValidateAlbumCanBeMovedOrCopied((IAlbum)galleryObject);

                    if (!securityCheckCompleteForAlbum)                     // Only need to check albums once, since all albums belong to same parent.
                    {
                        ValidateSecurityForAlbumOrMediaObject(galleryObject, SecurityActions.DeleteAlbum);
                        securityCheckCompleteForAlbum = true;
                    }

                    movingOrCopyingAtLeastOneAlbum = true;                     // used below
                }
                else
                {
                    if (!securityCheckCompleteForMediaObject)                     // Only need to check media objects once, since they all belong to same parent.
                    {
                        ValidateSecurityForAlbumOrMediaObject(galleryObject.Parent, SecurityActions.DeleteMediaObject);
                        securityCheckCompleteForMediaObject = true;
                    }

                    movingOrCopyingAtLeastOneMediaObject = true;                     // used below
                }
            }

            #endregion

            #region Validate user has permission to add objects to destination album

            if (movingOrCopyingAtLeastOneAlbum && (!IsUserAuthorized(SecurityActions.AddChildAlbum, this.DestinationAlbum.Id)))
            {
                throw new GalleryServerPro.ErrorHandler.CustomExceptions.GallerySecurityException(String.Format(CultureInfo.CurrentCulture, "User '{0}' does not have permission '{1}' for album ID {2}.", Util.UserName, SecurityActions.AddChildAlbum.ToString(), this.DestinationAlbum.Id));
            }

            if (movingOrCopyingAtLeastOneMediaObject && (!IsUserAuthorized(SecurityActions.AddMediaObject, this.DestinationAlbum.Id)))
            {
                throw new GalleryServerPro.ErrorHandler.CustomExceptions.GallerySecurityException(String.Format(CultureInfo.CurrentCulture, "User '{0}' does not have permission '{1}' for album ID {2}.", Util.UserName, SecurityActions.AddMediaObject.ToString(), this.DestinationAlbum.Id));
            }

            #endregion
        }
예제 #11
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>
        /// Add the collection of albums to the specified treeview node.
        /// </summary>
        /// <param name="albums">The collection of albums to add the the treeview node.</param>
        /// <param name="parentNode">The treeview node that will receive child nodes representing the specified albums.</param>
        /// <param name="expandNode">Specifies whether the nodes should be expanded.</param>
        private void BindAlbumToTreeview(IGalleryObjectCollection albums, TreeViewNode parentNode, bool expandNode)
        {
            string handlerPath = String.Concat(Utils.GalleryRoot, "/handler/gettreeviewxml.ashx");

            foreach (IAlbum album in albums)
            {
                TreeViewNode node       = new TreeViewNode();
                string       albumTitle = Utils.RemoveHtmlTags(album.Title);
                node.Text     = albumTitle;
                node.ToolTip  = albumTitle;
                node.Value    = album.Id.ToString(CultureInfo.InvariantCulture);
                node.ID       = album.Id.ToString(CultureInfo.InvariantCulture);
                node.Expanded = expandNode;

                if (!String.IsNullOrEmpty(NavigateUrl))
                {
                    node.NavigateUrl   = Utils.AddQueryStringParameter(NavigateUrl, String.Concat("aid=", album.Id.ToString(CultureInfo.InvariantCulture)));
                    node.HoverCssClass = "tv0HoverTreeNodeLink";
                }

                node.ShowCheckBox = parentNode.ShowCheckBox;
                node.Selectable   = true;

                if (album.GetChildGalleryObjects(GalleryObjectType.Album, false, this.GalleryPage.IsAnonymousUser).Count > 0)
                {
                    string handlerPathWithAlbumId = Utils.AddQueryStringParameter(handlerPath, String.Concat("aid=", album.Id.ToString(CultureInfo.InvariantCulture)));
                    node.ContentCallbackUrl = String.Format(CultureInfo.CurrentCulture, "{0}{1}&sc={2}&nurl={3}", handlerPathWithAlbumId, this.SecurityPermissionQueryStringParm, node.ShowCheckBox, Utils.UrlEncode(NavigateUrl));
                }

                // Select and check this node if needed.
                if ((this._albumToSelect != null) && (album.Id == this._albumToSelect.Id))
                {
                    tv.SelectedNode = node;
                    node.Checked    = true;
                    node.Expanded   = true;
                    // Expand the child of the selected album.
                    BindAlbumToTreeview(album.GetChildGalleryObjects(GalleryObjectType.Album, true, this.GalleryPage.IsAnonymousUser), node, false);
                }

                // Check this node if needed.
                if (this._albumIdsToCheck.Contains(album.Id))
                {
                    node.Checked = true;
                }

                parentNode.Nodes.Add(node);
            }
        }
        private void ConfigureControls()
        {
            this.TaskHeaderText  = Resources.GalleryServerPro.Task_Edit_Captions_Header_Text;
            this.TaskBodyText    = Resources.GalleryServerPro.Task_Edit_Captions_Body_Text;
            this.OkButtonText    = SueetieLocalizer.GetString("process_updates", "MediaGallery.xml");
            this.OkButtonToolTip = Resources.GalleryServerPro.Task_Edit_Captions_Ok_Button_Tooltip;

            this.PageTitle = Resources.GalleryServerPro.Task_Edit_Captions_Page_Title;

            // Sueetie Modified - Converting GSP galleryObjects into SueetieGalleryObjects
            SueetieConfiguration      config = SueetieConfiguration.Get();
            List <SueetieMediaObject> sueetieMediaObjects = new List <SueetieMediaObject>();

            IGalleryObjectCollection albumChildren = this.GetAlbum().GetChildGalleryObjects(GalleryObjectType.Album, true);

            foreach (IGalleryObject _galleryObject in albumChildren)
            {
                SueetieMediaAlbum _album = SueetieMedia.GetSueetieMediaAlbum(CurrentSueetieGalleryID, _galleryObject.Id);
                sueetieMediaObjects.Insert(0, new SueetieMediaObject
                {
                    MediaObjectID          = _galleryObject.Id,
                    MediaObjectTitle       = _galleryObject.Title,
                    AlbumID                = _galleryObject.Id,
                    IsAlbum                = true,
                    MediaObjectUrl         = String.Concat(Util.GetUrl(PageId.album, "aid={0}", _galleryObject.Id)),
                    MediaObjectDescription = _album.AlbumDescription,
                    DisplayName            = _album.DisplayName,
                    ThumbnailHeight        = config.Media.ThumbnailHeight,
                    ThumbnailWidth         = config.Media.ThumbnailWidth
                });
            }

            if (albumChildren.Count > 0)
            {
                const int textareaWidthBuffer  = 30; // Extra width padding to allow room for the caption.
                const int textareaHeightBuffer = 72; // Extra height padding to allow room for the caption.
                SetThumbnailCssStyle(albumChildren, textareaWidthBuffer, textareaHeightBuffer);

                rptr.DataSource = sueetieMediaObjects;
                rptr.DataBind();
            }
            else
            {
                this.RedirectToAlbumViewPage("msg={0}", ((int)Message.CannotEditCaptionsNoEditableObjectsExistInAlbum).ToString(CultureInfo.InvariantCulture));
            }
        }
예제 #14
0
        private void ConfigureControls()
        {
            this.TaskHeaderText  = Resources.GalleryServerPro.Task_Assign_Thumbnail_Header_Text;
            this.TaskBodyText    = Resources.GalleryServerPro.Task_Assign_Thumbnail_Body_Text;
            this.OkButtonText    = Resources.GalleryServerPro.Task_AssignThumbnail_Ok_Button_Text;
            this.OkButtonToolTip = Resources.GalleryServerPro.Task_AssignThumbnail_Ok_Button_Tooltip;

            this.PageTitle = Resources.GalleryServerPro.Task_AssignThumbnail_Page_Title;

            this._thumbnailMediaObjectId = this.GetAlbum().Thumbnail.MediaObjectId;

            IGalleryObjectCollection albumChildren = this.GetAlbum().GetChildGalleryObjects(GalleryObjectType.All, true);

            SetThumbnailCssStyle(albumChildren);

            rptr.DataSource = albumChildren;
            rptr.DataBind();
        }
예제 #15
0
        /// <summary>
        /// Displays thumbnail versions of the specified <paramref name="galleryObjects"/>.
        /// </summary>
        /// <param name="galleryObjects">The gallery objects to display.</param>
        /// <param name="showAddObjectsLink">If set to <c>true</c> show a message and a link allowing the user to add objects to the
        /// current album as specified in the query string. Set to false when displaying objects that may belong to more than one
        /// album.</param>
        private void DisplayThumbnails(IGalleryObjectCollection galleryObjects, bool showAddObjectsLink)
        {
            string msg;

            if (galleryObjects.Count > 0)
            {
                // At least one album or media object in album.
                //msg = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_addtopmargin2'>{0}</p>", Resources.GalleryServerPro.UC_ThumbnailView_Intro_Text_With_Objects);
                //phMsg.Controls.Add(new LiteralControl(msg));
            }
            else if ((showAddObjectsLink) && (this.GalleryPage.UserCanAddMediaObject) && (!this.GalleryPage.GallerySettings.MediaObjectPathIsReadOnly))
            {
                // We have no objects to display. The user is authorized to add objects to this album and the gallery is writeable, so show
                // message and link to add objects page.
                string innerMsg = String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.UC_ThumbnailView_Intro_Text_No_Objects_User_Has_Add_MediaObject_Permission, Util.GetUrl(PageId.task_addobjects, "aid={0}", this.GalleryPage.GetAlbumId()));
                msg = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_addtopmargin2 gsp_msgfriendly'>{0}</p>", innerMsg);
                phMsg.Controls.Add(new LiteralControl(msg));
            }
            else
            {
                // No objects and/or user doesn't have permission to add media objects.
                msg = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_addtopmargin2 gsp_msgfriendly'>{0}</p>", Resources.GalleryServerPro.UC_ThumbnailView_Intro_Text_No_Objects);
                phMsg.Controls.Add(new LiteralControl(msg));
            }

            this.GalleryPage.SetThumbnailCssStyle(galleryObjects);

            // Sueetie Modified - Turn On Paging on Recent Photos
            if (PagingEnabled || DataHelper.GetIntFromQueryString("aid", 1) == -1)
            {
                rptr.DataSource = CreatePaging(galleryObjects);

                RegisterPagingScript();
            }
            else
            {
                rptr.DataSource = galleryObjects;
            }

            rptr.DataBind();
        }
        /// <summary>
        /// Filters the <paramref name="galleryObjects" /> by the filter specified in <see cref="SearchOptions" />.
        /// </summary>
        /// <param name="galleryObjects">The gallery objects.</param>
        /// <returns>An instance of <see cref="IGalleryObjectCollection" />.</returns>
        private IGalleryObjectCollection FilterGalleryObjects(IGalleryObjectCollection galleryObjects)
        {
            switch (SearchOptions.Filter)
            {
            case GalleryObjectType.Album:
                return(new GalleryObjectCollection(galleryObjects.Where(go => go.GalleryObjectType == GalleryObjectType.Album)));

            case GalleryObjectType.MediaObject:
                return(new GalleryObjectCollection(galleryObjects.Where(go => go.GalleryObjectType != GalleryObjectType.Album)));

            case GalleryObjectType.NotSpecified:
            case GalleryObjectType.All:
                return(galleryObjects);

            case GalleryObjectType.None:
                return(new GalleryObjectCollection());

            default:
                return(new GalleryObjectCollection(galleryObjects.Where(go => go.GalleryObjectType == SearchOptions.Filter)));
            }
        }
예제 #17
0
        /// <summary>
        /// Add the collection of albums to the specified treeview node.
        /// </summary>
        /// <param name="albums">The collection of albums to add the the treeview node.</param>
        /// <param name="parentNode">The treeview node that will receive child nodes representing the specified albums.</param>
        /// <param name="expandNode">Specifies whether the nodes should be expanded.</param>
        private void BindAlbumToTreeview(IGalleryObjectCollection albums, TreeViewNode parentNode, bool expandNode)
        {
            string handlerPath = String.Concat(Util.GalleryRoot, "/handler/gettreeviewxml.ashx");

            foreach (IAlbum album in albums)
            {
                TreeViewNode node = new TreeViewNode();
                node.Text     = Util.RemoveHtmlTags(album.Title);
                node.Value    = album.Id.ToString(CultureInfo.InvariantCulture);
                node.ID       = album.Id.ToString(CultureInfo.InvariantCulture);
                node.Expanded = expandNode;

                node.ShowCheckBox = true;
                node.Selectable   = true;

                if (album.GetChildGalleryObjects(GalleryObjectType.Album).Count > 0)
                {
                    node.ContentCallbackUrl = String.Format(CultureInfo.CurrentCulture, "{0}?aid={1}{2}", handlerPath, album.Id.ToString(CultureInfo.InvariantCulture), this.SecurityPermissionQueryStringParm);
                }

                // Select and check this node if needed.
                if ((this._albumToSelect != null) && (album.Id == this._albumToSelect.Id))
                {
                    tv.SelectedNode = node;
                    node.Checked    = true;
                    node.Expanded   = true;
                    // Expand the child of the selected album.
                    BindAlbumToTreeview(album.GetChildGalleryObjects(GalleryObjectType.Album), node, false);
                }

                // Check this node if needed.
                if (this._albumIdsToSelect.Contains(album.Id))
                {
                    node.Checked = true;
                }

                parentNode.Nodes.Add(node);
            }
        }
예제 #18
0
        /// <summary>
        /// Bind the heirarchical list of albums to the specified treeview node.
        /// </summary>
        /// <param name="existingParentNode">The treeview node to add the first album in the stack to.</param>
        /// <param name="albumParents">A list of albums where the first album should be a child of the specified treeview
        /// node, and each subsequent album is a child of the previous album.</param>
        private void BindSpecificAlbumToTreeview(TreeViewNode existingParentNode, Stack <IAlbum> albumParents)
        {
            // Assumption: The first album in the stack is a child of the existingParentNode node.
            existingParentNode.Expanded = true;

            // For each album in the heirarchy of albums to the current album, add the album and all its siblings to the
            // treeview.
            foreach (IAlbum album in albumParents)
            {
                if (existingParentNode.Nodes.Count == 0)
                {
                    // Add all the album's siblings to the treeview.
                    IGalleryObjectCollection childAlbums = Factory.LoadAlbumInstance(Convert.ToInt32(existingParentNode.ID, CultureInfo.InvariantCulture), true).GetChildGalleryObjects(GalleryObjectType.Album, true, this.GalleryPage.IsAnonymousUser);
                    BindAlbumToTreeview(childAlbums, existingParentNode, false);
                }

                // Now find the album in the siblings we just added that matches the current album in the stack.
                // Set that album as the new parent and expand it.
                TreeViewNode nodeInAlbumHeirarchy = null;
                foreach (TreeViewNode node in existingParentNode.Nodes)
                {
                    if (node.ID == album.Id.ToString(CultureInfo.InvariantCulture))
                    {
                        nodeInAlbumHeirarchy          = node;
                        nodeInAlbumHeirarchy.Expanded = true;
                        break;
                    }
                }

                if (nodeInAlbumHeirarchy == null)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "Album ID {0} is not a child of the treeview node representing album ID {1}.", album.Id, Convert.ToInt32(existingParentNode.Value, CultureInfo.InvariantCulture)));
                }

                existingParentNode = nodeInAlbumHeirarchy;
            }
            existingParentNode.Expanded = false;
        }
예제 #19
0
        /// <summary>
        /// Finds the first album within the heirarchy of the specified <paramref name="album"/> whose ID is in
        /// <paramref name="albumIds"/>. Acts recursively in an across-first, then-down search pattern, resulting
        /// in the highest level matching album to be returned. Returns null if there are no matching albums.
        /// </summary>
        /// <param name="album">The album to be searched to see if it, or any of its children, matches one of the IDs
        /// in <paramref name="albumIds"/>.</param>
        /// <param name="albumIds">Contains the IDs of the albums to search for.</param>
        /// <returns>Returns the first album within the heirarchy of the specified <paramref name="album"/> whose ID is in
        /// <paramref name="albumIds"/>.</returns>
        private static IAlbum FindFirstMatchingAlbumRecursive(IAlbum album, ICollection <int> albumIds)
        {
            // Is the current album in the list?
            if (albumIds.Contains(album.Id))
            {
                return(album);
            }

            // Nope, so look at the child albums of this album.
            IAlbum albumToSelect = null;
            IGalleryObjectCollection childAlbums = album.GetChildGalleryObjects(GalleryObjectType.Album, true);

            foreach (IGalleryObject childAlbum in childAlbums)
            {
                if (albumIds.Contains(childAlbum.Id))
                {
                    albumToSelect = (IAlbum)childAlbum;
                    break;
                }
            }

            // Not the child albums either, so iterate through the children of the child albums. Act recursively.
            if (albumToSelect == null)
            {
                foreach (IGalleryObject childAlbum in childAlbums)
                {
                    albumToSelect = (IAlbum)FindFirstMatchingAlbumRecursive((IAlbum)childAlbum, albumIds);

                    if (albumToSelect != null)
                    {
                        break;
                    }
                }
            }

            return(albumToSelect);            // Returns null if no matching album is found
        }
예제 #20
0
        /// <summary>
        /// Delete any thumbnail and optimized images that do not have matching media objects.
        /// This can occur when a user manually transfers (e.g. uses Windows Explorer)
        /// original images to a new directory and leaves the thumbnail and optimized
        /// images in the original directory or when a user deletes the original media file in
        /// Explorer. This function *only* deletes files that begin the the thumbnail and optimized
        /// prefix (e.g. zThumb_, zOpt_).
        /// </summary>
        /// <param name="album">The album whose directory is to be processed for orphaned image files.</param>
        private void DeleteOrphanedImages(IAlbum album)
        {
            if (album == null)
            {
                throw new ArgumentNullException("album");
            }

            // STEP 1: Get list of directories that may contain thumbnail or optimized images for the current album
            string originalPath  = album.FullPhysicalPathOnDisk;
            string thumbnailPath = HelperFunctions.MapAlbumDirectoryStructureToAlternateDirectory(album.FullPhysicalPathOnDisk, AppSetting.Instance.ThumbnailPath);
            string optimizedPath = HelperFunctions.MapAlbumDirectoryStructureToAlternateDirectory(album.FullPhysicalPathOnDisk, AppSetting.Instance.OptimizedPath);

            List <string> albumPaths = new List <string>(3);

            // The original path may contain thumbnails or optimized images when the thumbnail/optimized path is the same as the original path
            if ((AppSetting.Instance.ThumbnailPath == AppSetting.Instance.MediaObjectPhysicalPath) || (AppSetting.Instance.OptimizedPath == AppSetting.Instance.MediaObjectPhysicalPath))
            {
                albumPaths.Add(originalPath);
            }

            if (!albumPaths.Contains(thumbnailPath))
            {
                albumPaths.Add(thumbnailPath);
            }

            if (!albumPaths.Contains(optimizedPath))
            {
                albumPaths.Add(optimizedPath);
            }


            string thumbnailPrefix = ConfigManager.GetGalleryServerProConfigSection().Core.ThumbnailFileNamePrefix;
            string optimizedPrefix = ConfigManager.GetGalleryServerProConfigSection().Core.OptimizedFileNamePrefix;

            IGalleryObjectCollection mediaObjects = album.GetChildGalleryObjects(GalleryObjectType.MediaObject);

            // STEP 2: Loop through each path and make sure all thumbnail and optimized files in each directory have
            // matching media objects. Delete any files that do not.
            foreach (string albumPath in albumPaths)
            {
                if (!Directory.Exists(albumPath))
                {
                    return;
                }

                DirectoryInfo directory = new DirectoryInfo(albumPath);

                // Loop through each file in the directory.
                foreach (FileInfo file in directory.GetFiles())
                {
                    if ((file.Name.StartsWith(thumbnailPrefix, StringComparison.OrdinalIgnoreCase)) || (file.Name.StartsWith(optimizedPrefix, StringComparison.OrdinalIgnoreCase)))
                    {
                        // This file is a thumbnail or optimized file. Check to see if any media object in this album
                        // refers to it.
                        bool foundMediaObject = false;
                        foreach (IGalleryObject mediaObject in mediaObjects)
                        {
                            if ((mediaObject.Optimized.FileName == file.Name) || (mediaObject.Thumbnail.FileName == file.Name))
                            {
                                foundMediaObject = true;
                                break;
                            }
                        }

                        if (!foundMediaObject)
                        {
                            // No media object in this album refers to this thumbnail or optimized image. Smoke it!
                            try
                            {
                                file.Delete();
                            }
                            catch (IOException ex)
                            {
                                // An exception occurred, probably because the account ASP.NET is running under does not
                                // have permission to delete the file. Let's record the error, but otherwise ignore it.
                                Error.Record(ex);
                            }
                            catch (System.Security.SecurityException ex)
                            {
                                // An exception occurred, probably because the account ASP.NET is running under does not
                                // have permission to delete the file. Let's record the error, but otherwise ignore it.
                                Error.Record(ex);
                            }
                            catch (UnauthorizedAccessException ex)
                            {
                                // An exception occurred, probably because the account ASP.NET is running under does not
                                // have permission to delete the file. Let's record the error, but otherwise ignore it.
                                Error.Record(ex);
                            }
                        }
                    }
                }
            }

            // Now recursively loop through any child albums.
            IGalleryObjectCollection childAlbums = album.GetChildGalleryObjects(GalleryObjectType.Album);

            if (this.IsRecursive)
            {
                foreach (IAlbum childAlbum in childAlbums)
                {
                    DeleteOrphanedImages(childAlbum);
                }
            }
        }
예제 #21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Album"/> class.
        /// </summary>
        /// <param name="id">The album ID.</param>
        /// <param name="galleryId">The gallery ID.</param>
        /// <param name="parentId">The ID of the parent album that contains this album.</param>
        /// <param name="title">The title.</param>
        /// <param name="directoryName">Name of the directory.</param>
        /// <param name="summary">The summary.</param>
        /// <param name="thumbnailMediaObjectId">The thumbnail media object id.</param>
        /// <param name="sequence">The sequence.</param>
        /// <param name="dateStart">The starting date for this album.</param>
        /// <param name="dateEnd">The ending date for this album.</param>
        /// <param name="createdByUsername">The user name of the user who created this gallery object.</param>
        /// <param name="dateAdded">The date this gallery object was created.</param>
        /// <param name="lastModifiedByUsername">The user name of the user who last modified this gallery object.</param>
        /// <param name="dateLastModified">The date and time this gallery object was last modified.</param>
        /// <param name="ownerUsername">The user name of this gallery object's owner.</param>
        /// <param name="ownerRoleName">The name of the role associated with this gallery object's owner.</param>
        /// <param name="isPrivate"><c>true</c> this gallery object is hidden from anonymous users; otherwise <c>false</c>.</param>
        internal Album(int id, int galleryId, int parentId, string title, string directoryName, string summary, int thumbnailMediaObjectId, int sequence, DateTime dateStart, DateTime dateEnd, string createdByUsername, DateTime dateAdded, string lastModifiedByUsername, DateTime dateLastModified, string ownerUsername, string ownerRoleName, bool isPrivate)
        {
            if (galleryId == int.MinValue)
            {
                throw new ArgumentOutOfRangeException("galleryId", String.Format(CultureInfo.CurrentCulture, "Gallery ID must be set to a valid value. Instead, the value was {0}.", galleryId));
            }

            this._galleryObjects = new GalleryObjectCollection();
            System.Diagnostics.Debug.Assert(this._areChildrenInflated == false, String.Format(CultureInfo.CurrentCulture, "The private boolean field _areChildrenInflated should have been initialized to false, but instead it was {0}.", this._areChildrenInflated));

            this.Id = id;

            // Specifiy gallery ID: Use galleryID parm if specified, otherwise, use gallery ID of parent. If no parent, use int.MinValue
            //this.GalleryId = (galleryId > int.MinValue ? galleryId : (parentId >= 0 ? this.Parent.GalleryId : int.MinValue));
            this.GalleryId = galleryId;

            if (parentId > 0)
            {
                this.Parent = Factory.CreateAlbumInstance(parentId, galleryId);
            }
            else if (parentId == 0)
            {
                this.Parent.Id = parentId; // Parent ID of root album is always 0.
            }

            this.Title = title;
            this._directoryName = directoryName;
            this._summary = summary;
            this.Sequence = sequence;
            this._dateStart = dateStart;
            this._dateEnd = dateEnd;
            this.CreatedByUserName = createdByUsername;
            this.DateAdded = dateAdded;
            this.LastModifiedByUserName = lastModifiedByUsername;
            this._ownerUsername = ownerUsername;
            this._ownerRoleName = ownerRoleName;
            this.DateLastModified = dateLastModified;
            this.IsPrivate = isPrivate;
            this.AllowMetadataLoading = true;
            this._fullPhysicalPathOnDisk = string.Empty;

            //this._thumbnailMediaObjectId = (thumbnailMediaObjectId == int.MinValue ? 0 : thumbnailMediaObjectId);
            this.ThumbnailMediaObjectId = (thumbnailMediaObjectId == int.MinValue ? 0 : thumbnailMediaObjectId);
            this._isThumbnailInflated = false;

            if (this._thumbnailMediaObjectId > 0)
            {
                this.Thumbnail = DisplayObject.CreateInstance(this, this._thumbnailMediaObjectId, DisplayObjectType.Thumbnail);
            }
            else
            {
                this.Thumbnail = GetDefaultAlbumThumbnail();
            }

            this.SaveBehavior = Factory.GetAlbumSaveBehavior(this);
            this.DeleteBehavior = Factory.GetAlbumDeleteBehavior(this);

            // Setting the previous properties has caused HasChanges = true, but we don't want this while
            // we're instantiating a new object. Reset to false.
            this.HasChanges = false;

            this.Saving += new EventHandler(Album_Saving);
            this.Saved += new EventHandler(Album_Saved);
        }
        /// <summary>
        /// Filters the <paramref name="galleryObjects" /> by the filter specified in <see cref="SearchOptions" />.
        /// </summary>
        /// <param name="galleryObjects">The gallery objects.</param>
        /// <returns>An instance of <see cref="IGalleryObjectCollection" />.</returns>
        private IGalleryObjectCollection FilterGalleryObjects(IGalleryObjectCollection galleryObjects)
        {
            switch (SearchOptions.Filter)
            {
                case GalleryObjectType.Album:
                    return new GalleryObjectCollection(galleryObjects.Where(go => go.GalleryObjectType == GalleryObjectType.Album));

                case GalleryObjectType.MediaObject:
                    return new GalleryObjectCollection(galleryObjects.Where(go => go.GalleryObjectType != GalleryObjectType.Album));

                case GalleryObjectType.NotSpecified:
                case GalleryObjectType.All:
                    return galleryObjects;

                case GalleryObjectType.None:
                    return new GalleryObjectCollection();

                default:
                    return new GalleryObjectCollection(galleryObjects.Where(go => go.GalleryObjectType == SearchOptions.Filter));
            }
        }
        /// <summary>
        /// Displays thumbnail versions of the specified <paramref name="galleryObjects"/>.
        /// </summary>
        /// <param name="galleryObjects">The gallery objects to display.</param>
        /// <param name="showAddObjectsLink">If set to <c>true</c> show a message and a link allowing the user to add objects to the 
        /// current album as specified in the query string. Set to false when displaying objects that may belong to more than one
        /// album.</param>
        private void DisplayThumbnails(IGalleryObjectCollection galleryObjects, bool showAddObjectsLink)
        {
            string msg;
            if (galleryObjects.Count > 0)
            {
                // At least one album or media object in album.
                //msg = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_addtopmargin2'>{0}</p>", Resources.GalleryServerPro.UC_ThumbnailView_Intro_Text_With_Objects);
                //phMsg.Controls.Add(new LiteralControl(msg));
            }
            else if ((showAddObjectsLink) && (this.GalleryPage.UserCanAddMediaObject) && (!this.GalleryPage.GallerySettings.MediaObjectPathIsReadOnly))
            {
                // We have no objects to display. The user is authorized to add objects to this album and the gallery is writeable, so show
                // message and link to add objects page.
                string innerMsg = String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.UC_ThumbnailView_Intro_Text_No_Objects_User_Has_Add_MediaObject_Permission, Utils.GetUrl(PageId.task_addobjects, "aid={0}", this.GalleryPage.GetAlbumId()));
                msg = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_addtopmargin2 gsp_msgfriendly'>{0}</p>", innerMsg);
                phMsg.Controls.Add(new LiteralControl(msg));
            }
            else
            {
                // No objects and/or user doesn't have permission to add media objects.
                msg = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_addtopmargin2 gsp_msgfriendly'>{0}</p>", Resources.GalleryServerPro.UC_ThumbnailView_Intro_Text_No_Objects);
                phMsg.Controls.Add(new LiteralControl(msg));
            }

            this.GalleryPage.SetThumbnailCssStyle(galleryObjects);

            if (PagingEnabled)
            {
                rptr.DataSource = CreatePaging(galleryObjects);
            }
            else
                rptr.DataSource = galleryObjects;

            rptr.DataBind();
        }
예제 #24
0
		/// <summary>
		/// Throw exception if the specified albums and/or media objects cannot be moved or copied for any reason, 
		/// such as lack of user permission or trying to move/copy objects to itself.
		/// </summary>
		/// <param name="objectsToMoveOrCopy">The albums or media objects to move or copy.</param>
		/// <exception cref="GalleryServerPro.Events.CustomExceptions.GallerySecurityException">Thrown when the logged on 
		/// user does not belong to a role that authorizes the moving or copying.</exception>
		/// <exception cref="GalleryServerPro.Events.CustomExceptions.CannotTransferAlbumToNestedDirectoryException">
		/// Thrown when the user tries to move or copy an album to one of its children albums.</exception>
		private void ValidateObjectsCanBeMovedOrCopied(IGalleryObjectCollection objectsToMoveOrCopy)
		{
			bool movingOrCopyingAtLeastOneAlbum = false;
			bool movingOrCopyingAtLeastOneMediaObject = false;

			#region Validate the albums and media objects we are moving or copying

			bool securityCheckCompleteForAlbum = false;
			bool securityCheckCompleteForMediaObject = false;

			foreach (IGalleryObject galleryObject in objectsToMoveOrCopy)
			{
				if (galleryObject is Album)
				{
					ValidateAlbumCanBeMovedOrCopied((IAlbum)galleryObject);

					if (!securityCheckCompleteForAlbum) // Only need to check albums once, since all albums belong to same parent.
					{
						ValidateSecurityForAlbumOrMediaObject(galleryObject, SecurityActions.DeleteAlbum);
						securityCheckCompleteForAlbum = true;
					}

					movingOrCopyingAtLeastOneAlbum = true; // used below
				}
				else
				{
					// Make sure file type is enabled (external objects don't have files so we don't check them)
					if (galleryObject.GalleryObjectType != GalleryObjectType.External && !HelperFunctions.IsFileAuthorizedForAddingToGallery(galleryObject.Original.FileName, galleryObject.GalleryId))
					{
						throw new UnsupportedMediaObjectTypeException(galleryObject.Original.FileName);
					}

					if (!securityCheckCompleteForMediaObject) // Only need to check media objects once, since they all belong to same parent.
					{
						ValidateSecurityForAlbumOrMediaObject(galleryObject.Parent, SecurityActions.DeleteMediaObject);
						securityCheckCompleteForMediaObject = true;
					}

					movingOrCopyingAtLeastOneMediaObject = true; // used below
				}
			}

			#endregion

			#region Validate user has permission to add objects to destination album

			if (this.DestinationAlbum.GalleryId == GalleryId)
			{
				if (GallerySettings.MediaObjectPathIsReadOnly)
				{
					// Rebind treeview, making sure current album is re-selected.
					var selectedId = this.tvUC.SelectedAlbum.Id;
					ShowTreeview();
					tvUC.SelectedAlbumIds.Clear();
					tvUC.SelectedAlbumIds.Add(selectedId);

					throw new GallerySecurityException("Cannot move or copy objects to a read only gallery");
				}
			}
			else
			{
				// User is transferring objects to another gallery. Make sure the user is an admin for the gallery
				// and that it is writeable.
				var isReadOnly = Factory.LoadGallerySetting(this.DestinationAlbum.GalleryId).MediaObjectPathIsReadOnly;
				var userIsNotAdmin = UserController.GetGalleriesCurrentUserCanAdminister().All(g => g.GalleryId != this.DestinationAlbum.GalleryId);

				if (isReadOnly || userIsNotAdmin)
				{
					// Rebind treeview, making sure current album is re-selected.
					var selectedId = this.tvUC.SelectedAlbum.Id;
					ShowTreeview();
					tvUC.SelectedAlbumIds.Clear();
					tvUC.SelectedAlbumIds.Add(selectedId);

					throw new GallerySecurityException("Cannot move or copy objects to a read only gallery");
				}
			}

			if (movingOrCopyingAtLeastOneAlbum && (!IsUserAuthorized(SecurityActions.AddChildAlbum, this.DestinationAlbum.Id, this.DestinationAlbum.GalleryId, this.DestinationAlbum.IsVirtualAlbum)))
			{
				throw new GallerySecurityException(String.Format(CultureInfo.CurrentCulture, "User '{0}' does not have permission '{1}' for album ID {2}.", Utils.UserName, SecurityActions.AddChildAlbum, this.DestinationAlbum.Id));
			}

			if (movingOrCopyingAtLeastOneMediaObject && (!IsUserAuthorized(SecurityActions.AddMediaObject, this.DestinationAlbum.Id, this.DestinationAlbum.GalleryId, this.DestinationAlbum.IsVirtualAlbum)))
			{
				throw new GallerySecurityException(String.Format(CultureInfo.CurrentCulture, "User '{0}' does not have permission '{1}' for album ID {2}.", Utils.UserName, SecurityActions.AddMediaObject, this.DestinationAlbum.Id));
			}

			#endregion
		}
예제 #25
0
        /// <summary>
        /// Displays thumbnail versions of the specified <paramref name="galleryObjects"/>.
        /// </summary>
        /// <param name="galleryObjects">The gallery objects to display.</param>
        /// <param name="showAddObjectsLink">If set to <c>true</c> show a message and a link allowing the user to add objects to the
        /// current album as specified in the query string. Set to false when displaying objects that may belong to more than one
        /// album.</param>
        private void DisplayThumbnails(IGalleryObjectCollection galleryObjects, bool showAddObjectsLink)
        {
            string msg;

            if (galleryObjects.Count > 0)
            {
                // At least one album or media object in album.
                //msg = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_addtopmargin2'>{0}</p>", Resources.GalleryServerPro.UC_ThumbnailView_Intro_Text_With_Objects);
                //phMsg.Controls.Add(new LiteralControl(msg));
            }
            else if ((showAddObjectsLink) && (this.GalleryPage.UserCanAddMediaObject) && (!this.GalleryPage.GallerySettings.MediaObjectPathIsReadOnly))
            {
                // We have no objects to display. The user is authorized to add objects to this album and the gallery is writeable, so show
                // message and link to add objects page.
                string innerMsg = String.Format(CultureInfo.CurrentCulture, Resources.GalleryServerPro.UC_ThumbnailView_Intro_Text_No_Objects_User_Has_Add_MediaObject_Permission, Util.GetUrl(PageId.task_addobjects, "aid={0}", this.GalleryPage.GetAlbumId()));
                msg = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_addtopmargin2 gsp_msgfriendly'>{0}</p>", innerMsg);
                phMsg.Controls.Add(new LiteralControl(msg));
            }
            else
            {
                // No objects and/or user doesn't have permission to add media objects.
                msg = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_addtopmargin2 gsp_msgfriendly'>{0}</p>", Resources.GalleryServerPro.UC_ThumbnailView_Intro_Text_No_Objects);
                phMsg.Controls.Add(new LiteralControl(msg));
            }

            this.GalleryPage.SetThumbnailCssStyle(galleryObjects);

            // Sueetie Modified - Converting GSP galleryObjects into SueetieGalleryObjects
            SueetieConfiguration      config = SueetieConfiguration.Get();
            List <SueetieMediaObject> sueetieMediaObjects = new List <SueetieMediaObject>();


            foreach (IGalleryObject _galleryObject in galleryObjects)
            {
                if (_galleryObject is Album)
                {
                    SueetieMediaAlbum _album = SueetieMedia.GetSueetieMediaAlbum(CurrentSueetieGalleryID, _galleryObject.Id);
                    sueetieMediaObjects.Insert(0, new SueetieMediaObject
                    {
                        MediaObjectID          = _galleryObject.Id,
                        MediaObjectTitle       = _galleryObject.Title,
                        AlbumID                = _galleryObject.Id,
                        IsAlbum                = true,
                        MediaObjectUrl         = String.Concat(Util.GetUrl(PageId.album, "aid={0}", _galleryObject.Id)),
                        MediaObjectDescription = _album.AlbumDescription,
                        DisplayName            = _album.DisplayName,
                        ThumbnailHeight        = config.Media.ThumbnailHeight,
                        ThumbnailWidth         = config.Media.ThumbnailWidth,
                        DateTimeCreated        = _album.DateTimeCreated,
                        SueetieUserID          = _album.SueetieUserID
                    });
                }
                else
                {
                    SueetieMediaObject _sueetieMediaObject = SueetieMedia.GetSueetieMediaObject(this.CurrentSueetieGalleryID, _galleryObject.Id);
                    MediaHelper.PopulateMediaObject(_sueetieMediaObject, _galleryObject);
                    _sueetieMediaObject.MediaObjectUrl = GenerateUrl(_galleryObject);
                    sueetieMediaObjects.Add(_sueetieMediaObject);
                }
            }

            if (PagingEnabled)
            {
                rptr.DataSource = CreatePaging(sueetieMediaObjects);

                RegisterPagingScript();
            }
            else
            {
                rptr.DataSource = sueetieMediaObjects;
            }
            rptr.DataBind();
        }
예제 #26
0
        /// <summary>
        /// Set a page level CSS style defining the width and height of the containers of the thumbnail image of each gallery object.
        /// The width and height is based on the widest thumbnail image and the height of the tallest thumbnail image in the collection of
        /// specified gallery objects, plus a predefined buffer width and height specified by the configuration settings ThumbnailWidthBuffer
        /// and ThumbnailHeightBuffer. The values in <paramref name="widthBuffer"/> and <paramref name="heightBuffer"/> are added to the calculated
        /// width and height. This is useful when extra space is needed; for example, to make room the textbox on the edit captions page
        /// or the rotate icons on the rotate images page. The page level style is applied to each of the strings in
        /// <paramref name="thumbnailCssClasses"/> and is hard-coded to apply to a div tag. The style written to the page may look like this:
        /// &lt;style type="text/css"&gt;&lt;!-- div.thmb {width:145px;height:180px;} --&gt;&lt;/style&gt;
        /// </summary>
        /// <param name="galleryObjects">A collection of gallery objects from which the width and height is to be calculated.</param>
        /// <param name="widthBuffer">A value indicating extra horizontal padding for the thumbnail image container. An integer larger
        /// than zero increases the width; less than zero causes the width to decrease from its calculated value. This parameter is 
        /// typically specified when extra space is needed to make room for elements within the thumbnail image container, such as
        /// the textbox on the edit captions page or the rotate icons on the rotate images page.</param>
        /// <param name="heightBuffer">A value indicating extra vertical padding for the thumbnail image container. An integer larger
        /// than zero increases the height; less than zero causes the height to decrease from its calculated value. This parameter is 
        /// typically specified when extra space is needed to make room for elements within the thumbnail image container, such as
        /// the textbox on the edit captions page or the rotate icons on the rotate images page.</param>
        /// <param name="thumbnailCssClasses">A string array of CSS classes. The calculated width and height will be applied to these
        /// classes and written to the page header as a page level style. If not specified (null) or it has a length of zero, this 
        /// parameter defaults to a single string "thmb".</param>
        /// <remarks>If the thumbnail images were always the same dimension, the width and height for the thumbnail image container
        /// could be hardcoded in the global style sheet. But since it is variable, we need to programmatically set it.</remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="galleryObjects" /> is null.</exception>
        public void SetThumbnailCssStyle(IGalleryObjectCollection galleryObjects, int widthBuffer, int heightBuffer, string[] thumbnailCssClasses)
        {
            if (galleryObjects == null)
                throw new ArgumentNullException("galleryObjects");

            if ((thumbnailCssClasses == null) || (thumbnailCssClasses.Length == 0))
            {
                thumbnailCssClasses = new string[] { "thmb" };
            }

            // Calculate the width of the widest thumbnail image and the height of the tallest thumbnail
            // image in this album.
            int maxMoWidth = 0;
            int maxMoHeight = 0;

            foreach (IGalleryObject mo in galleryObjects)
            {
                if (mo.Thumbnail.Width > maxMoWidth)
                    maxMoWidth = mo.Thumbnail.Width;

                if (mo.Thumbnail.Height > maxMoHeight)
                    maxMoHeight = mo.Thumbnail.Height;
            }

            // If no width or height have been set, set to the default thumbnail width and height so
            // that we have reasonable minimum values.
            if ((maxMoWidth == 0) || (maxMoHeight == 0))
            {
                int maxLength = GallerySettings.MaxThumbnailLength;
                float ratio = GallerySettings.EmptyAlbumThumbnailWidthToHeightRatio;
                if (ratio > 1) // Landscape (width is greater than height)
                {
                    maxMoWidth = maxLength;
                    maxMoHeight = Convert.ToInt32((float)maxLength / ratio);
                }
                else // Portrait (width is less than height)
                {
                    maxMoHeight = maxLength;
                    maxMoWidth = Convert.ToInt32((float)maxLength * ratio);
                }
            }

            int maxWidth = maxMoWidth + GallerySettings.ThumbnailWidthBuffer + widthBuffer;
            int maxHeight = maxMoHeight + GallerySettings.ThumbnailHeightBuffer + heightBuffer;

            string pageStyle = "\n<style type=\"text/css\"><!-- ";
            foreach (string cssClass in thumbnailCssClasses)
            {
                pageStyle += String.Format(CultureInfo.CurrentCulture, "div.{0} {{width:{1}px;height:{2}px;}} ", cssClass, maxWidth, maxHeight);
            }
            pageStyle += "--></style>\n";

            this.Page.Header.Controls.Add(new System.Web.UI.LiteralControl(pageStyle));
        }
예제 #27
0
 /// <summary>
 /// Set a page level CSS style defining the width and height of the containers of the thumbnail image of each gallery object.
 /// The width and height is based on the widest thumbnail image and the height of the tallest thumbnail image in the collection of
 /// specified gallery objects, plus a predefined buffer width and height specified by the configuration settings ThumbnailWidthBuffer
 /// and ThumbnailHeightBuffer. The values in <paramref name="widthBuffer"/> and <paramref name="heightBuffer"/> are added to the calculated
 /// width and height. This is useful when extra space is needed; for example, to make room the textbox on the edit captions page
 /// or the rotate icons on the rotate images page. The page level style is applied to <paramref name="thumbnailCssClass"/> and is 
 /// hard-coded to apply to a div tag. The style written to the page may look like this:
 /// &lt;style type="text/css"&gt;&lt;!-- div.thmb {width:145px;height:180px;} --&gt;&lt;/style&gt;
 /// </summary>
 /// <param name="galleryObjects">A collection of gallery objects from which the width and height is to be calculated.</param>
 /// <param name="widthBuffer">A value indicating extra horizontal padding for the thumbnail image container. An integer larger
 /// than zero increases the width; less than zero causes the width to decrease from its calculated value. This parameter is 
 /// typically specified when extra space is needed to make room for elements within the thumbnail image container, such as
 /// the textbox on the edit captions page or the rotate icons on the rotate images page.</param>
 /// <param name="heightBuffer">A value indicating extra vertical padding for the thumbnail image container. An integer larger
 /// than zero increases the height; less than zero causes the height to decrease from its calculated value. This parameter is 
 /// typically specified when extra space is needed to make room for elements within the thumbnail image container, such as
 /// the textbox on the edit captions page or the rotate icons on the rotate images page.</param>
 /// <param name="thumbnailCssClass">A string representing a CSS class. The calculated width and height will be applied to this
 /// class and written to the page header as a page level style. If not specified (null), this parameter defaults to "thmb".</param>
 /// <remarks>If the thumbnail images were always the same dimension, the width and height for the thumbnail image container
 /// could be hardcoded in the global style sheet. But since it is variable, we need to programmatically set it.</remarks>
 /// <exception cref="System.ArgumentNullException">Thrown when the galleryObjects parameter is null.</exception>
 public void SetThumbnailCssStyle(IGalleryObjectCollection galleryObjects, int widthBuffer, int heightBuffer, string thumbnailCssClass)
 {
     SetThumbnailCssStyle(galleryObjects, widthBuffer, heightBuffer, new string[] { thumbnailCssClass });
 }
예제 #28
0
 /// <summary>
 /// Set a page level CSS style defining the width and height of the containers of the thumbnail image of each gallery object.
 /// The width and height is based on the widest thumbnail image and the height of the tallest thumbnail image in the collection of
 /// specified gallery objects, plus a predefined buffer width and height specified by the configuration settings ThumbnailWidthBuffer
 /// and ThumbnailHeightBuffer. The page level style is applied to <paramref name="thumbnailCssClass"/> and is hard-coded to apply
 /// to a div tag. The style written to the page may look like this:
 /// &lt;style type="text/css"&gt;&lt;!-- div.thmb {width:145px;height:180px;} --&gt;&lt;/style&gt;
 /// </summary>
 /// <param name="galleryObjects">A collection of gallery objects from which the width and height is to be calculated.</param>
 /// <param name="thumbnailCssClass">A string representing a CSS class. The calculated width and height will be applied to this
 /// class and written to the page header as a page level style. If not specified (null), this parameter defaults to "thmb".</param>
 /// <remarks>If the thumbnail images were always the same dimension, the width and height for the thumbnail image container
 /// could be hardcoded in the global style sheet. But since it is variable, we need to programmatically set it.</remarks>
 /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="galleryObjects"/> is null.</exception>
 public void SetThumbnailCssStyle(IGalleryObjectCollection galleryObjects, string thumbnailCssClass)
 {
     SetThumbnailCssStyle(galleryObjects, 0, 0, new string[] { thumbnailCssClass });
 }
        /// <summary>
        /// Add the collection of albums to the specified treeview node.
        /// </summary>
        /// <param name="albums">The collection of albums to add the the treeview node.</param>
        /// <param name="parentNode">The treeview node that will receive child nodes representing the specified albums.</param>
        /// <param name="expandNode">Specifies whether the nodes should be expanded.</param>
        private void BindAlbumToTreeview(IGalleryObjectCollection albums, TreeViewNode parentNode, bool expandNode)
        {
            string handlerPath = String.Concat(Utils.GalleryRoot, "/handler/gettreeviewxml.ashx");

            foreach (IAlbum album in albums)
            {
                TreeViewNode node = new TreeViewNode();
                string albumTitle = Utils.RemoveHtmlTags(album.Title);
                node.Text = albumTitle;
                node.ToolTip = albumTitle;
                node.Value = album.Id.ToString(CultureInfo.InvariantCulture);
                node.ID = album.Id.ToString(CultureInfo.InvariantCulture);
                node.Expanded = expandNode;

                if (!String.IsNullOrEmpty(NavigateUrl))
                {
                    node.NavigateUrl = Utils.AddQueryStringParameter(NavigateUrl, String.Concat("aid=", album.Id.ToString(CultureInfo.InvariantCulture)));
                    node.HoverCssClass = "tv0HoverTreeNodeLink";
                }

                node.ShowCheckBox = parentNode.ShowCheckBox;
                node.Selectable = true;

                if (album.GetChildGalleryObjects(GalleryObjectType.Album, false, this.GalleryPage.IsAnonymousUser).Count > 0)
                {
                    string handlerPathWithAlbumId = Utils.AddQueryStringParameter(handlerPath, String.Concat("aid=", album.Id.ToString(CultureInfo.InvariantCulture)));
                    node.ContentCallbackUrl = String.Format(CultureInfo.CurrentCulture, "{0}{1}&sc={2}&nurl={3}", handlerPathWithAlbumId, this.SecurityPermissionQueryStringParm, node.ShowCheckBox, Utils.UrlEncode(NavigateUrl));
                }

                // Select and check this node if needed.
                if ((this._albumToSelect != null) && (album.Id == this._albumToSelect.Id))
                {
                    tv.SelectedNode = node;
                    node.Checked = true;
                    node.Expanded = true;
                    // Expand the child of the selected album.
                    BindAlbumToTreeview(album.GetChildGalleryObjects(GalleryObjectType.Album, true, this.GalleryPage.IsAnonymousUser), node, false);
                }

                // Check this node if needed.
                if (this._albumIdsToCheck.Contains(album.Id))
                {
                    node.Checked = true;
                }

                parentNode.Nodes.Add(node);
            }
        }
		/// <summary>
		/// Throw exception if the specified albums and/or media objects cannot be moved or copied for any reason, 
		/// such as lack of user permission or trying to move/copy objects to itself.
		/// </summary>
		/// <param name="objectsToMoveOrCopy">The albums or media objects to move or copy.</param>
		/// <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 ValidateObjectsCanBeMovedOrCopied(IGalleryObjectCollection objectsToMoveOrCopy)
		{
			bool movingOrCopyingAtLeastOneAlbum = false;
			bool movingOrCopyingAtLeastOneMediaObject = false;

			#region Validate the albums and media objects we are moving or copying

			bool securityCheckCompleteForAlbum = false;
			bool securityCheckCompleteForMediaObject = false;

			foreach (IGalleryObject galleryObject in objectsToMoveOrCopy)
			{
				if (galleryObject is Album)
				{
					ValidateAlbumCanBeMovedOrCopied((IAlbum)galleryObject);

					if (!securityCheckCompleteForAlbum) // Only need to check albums once, since all albums belong to same parent.
					{
						ValidateSecurityForAlbumOrMediaObject(galleryObject, SecurityActions.DeleteAlbum);
						securityCheckCompleteForAlbum = true;
					}

					movingOrCopyingAtLeastOneAlbum = true; // used below
				}
				else
				{
					if (!securityCheckCompleteForMediaObject) // Only need to check media objects once, since they all belong to same parent.
					{
						ValidateSecurityForAlbumOrMediaObject(galleryObject.Parent, SecurityActions.DeleteMediaObject);
						securityCheckCompleteForMediaObject = true;
					}

					movingOrCopyingAtLeastOneMediaObject = true; // used below
				}
			}

			#endregion

			#region Validate user has permission to add objects to destination album

			if (movingOrCopyingAtLeastOneAlbum && (!IsUserAuthorized(SecurityActions.AddChildAlbum, this.DestinationAlbum.Id, this.DestinationAlbum.GalleryId)))
			{
				throw new GallerySecurityException(String.Format(CultureInfo.CurrentCulture, "User '{0}' does not have permission '{1}' for album ID {2}.", Utils.UserName, SecurityActions.AddChildAlbum, this.DestinationAlbum.Id));
			}

			if (movingOrCopyingAtLeastOneMediaObject && (!IsUserAuthorized(SecurityActions.AddMediaObject, this.DestinationAlbum.Id, this.DestinationAlbum.GalleryId)))
			{
				throw new GallerySecurityException(String.Format(CultureInfo.CurrentCulture, "User '{0}' does not have permission '{1}' for album ID {2}.", Utils.UserName, SecurityActions.AddMediaObject, this.DestinationAlbum.Id));
			}

			#endregion
		}
예제 #31
0
		/// <summary>
		/// Add the collection of albums to the specified treeview node.
		/// </summary>
		/// <param name="albums">The collection of albums to add the the treeview node.</param>
		/// <param name="parentNode">The treeview node that will receive child nodes representing the specified albums.</param>
		/// <param name="expandNode">Specifies whether the nodes should be expanded.</param>
		private void BindAlbumToTreeview(IGalleryObjectCollection albums, TreeViewNode parentNode, bool expandNode)
		{
			string handlerPath = String.Concat(Util.GalleryRoot, "/handler/gettreeviewxml.ashx");

			foreach (IAlbum album in albums)
			{
				TreeViewNode node = new TreeViewNode();
				node.Text = Util.RemoveHtmlTags(album.Title);
				node.Value = album.Id.ToString(CultureInfo.InvariantCulture);
				node.ID = album.Id.ToString(CultureInfo.InvariantCulture);
				node.Expanded = expandNode;

				node.ShowCheckBox = true;
				node.Selectable = true;

				if (album.GetChildGalleryObjects(GalleryObjectType.Album).Count > 0)
				{
					node.ContentCallbackUrl = String.Format(CultureInfo.CurrentCulture, "{0}?aid={1}{2}", handlerPath, album.Id.ToString(CultureInfo.InvariantCulture), this.SecurityPermissionQueryStringParm);
				}

				// Select and check this node if needed.
				if ((this._albumToSelect != null) && (album.Id == this._albumToSelect.Id))
				{
					tv.SelectedNode = node;
					node.Checked = true;
					node.Expanded = true;
					// Expand the child of the selected album.
					BindAlbumToTreeview(album.GetChildGalleryObjects(GalleryObjectType.Album), node, false);
				}
				
				// Check this node if needed.
				if (this._albumIdsToSelect.Contains(album.Id))
				{
					node.Checked = true;
				}

				parentNode.Nodes.Add(node);
			}
		}
예제 #32
0
		/// <summary>
		/// Add the collection of albums to the specified treeview node.
		/// </summary>
		/// <param name="albums">The collection of albums to add the the treeview node.</param>
		/// <param name="parentNode">The treeview node that will receive child nodes representing the specified albums.</param>
		/// <param name="expandNode">Specifies whether the nodes should be expanded.</param>
		private void bindAlbumToTreeview(IGalleryObjectCollection albums, TreeViewNode parentNode, bool expandNode)
		{
			string handlerPath = ResolveUrl("~/handler/gettreeviewxml.ashx");

			foreach (IAlbum album in albums)
			{
				TreeViewNode node = new TreeViewNode();
				node.Text = WebsiteController.RemoveHtmlTags(album.Title);
				node.Value = album.Id.ToString(CultureInfo.InvariantCulture);
				node.ID = album.Id.ToString(CultureInfo.InvariantCulture);
				node.Expanded = expandNode;

				bool isUserAuthorized = (IsSecurityPermissionRequested() ? this.PageBase.IsUserAuthorized(this.RequiredSecurityPermissions, album) : true);
				node.ShowCheckBox = isUserAuthorized;
				node.Selectable = isUserAuthorized;
				if (!isUserAuthorized) node.HoverCssClass = String.Empty;

				if (album.GetChildGalleryObjects(GalleryObjectType.Album).Count > 0)
				{
					node.ContentCallbackUrl = String.Format(CultureInfo.CurrentCulture, "{0}?aid={1}{2}", handlerPath, album.Id.ToString(CultureInfo.InvariantCulture), this.SecurityPermissionQueryStringParm);
				}

				// Select and check this node if needed.
				if ((this._albumToSelect != null) && (album.Id == this._albumToSelect.Id))
				{
					tv.SelectedNode = node;
					node.Checked = true;
					node.Expanded = true;
					// Expand the child of the selected album.
					bindAlbumToTreeview(album.GetChildGalleryObjects(GalleryObjectType.Album), node, false);
				}
				
				// Check this node if needed.
				if (this._albumIdsToCheck.Contains(album.Id))
				{
					node.Checked = true;
				}

				parentNode.Nodes.Add(node);
			}
		}
        /// <summary>
        /// Delete any thumbnail and optimized files that do not have matching media objects.
        /// This can occur when a user manually transfers (e.g. uses Windows Explorer)
        /// original files to a new directory and leaves the thumbnail and optimized
        /// files in the original directory or when a user deletes the original media file in
        /// Explorer. This function *only* deletes files that begin the the thumbnail and optimized
        /// prefix (e.g. zThumb_, zOpt_).
        /// </summary>
        /// <param name="album">The album whose directory is to be processed for orphaned image files.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="album" /> is null.</exception>
        private void DeleteOrphanedThumbnailAndOptimizedFiles(IAlbum album)
        {
            if (album == null)
            {
                throw new ArgumentNullException("album");
            }

            // STEP 1: Get list of directories that may contain thumbnail or optimized images for the current album
            string originalPath  = album.FullPhysicalPathOnDisk;
            string thumbnailPath = HelperFunctions.MapAlbumDirectoryStructureToAlternateDirectory(album.FullPhysicalPathOnDisk, GallerySettings.FullThumbnailPath, GallerySettings.FullMediaObjectPath);
            string optimizedPath = HelperFunctions.MapAlbumDirectoryStructureToAlternateDirectory(album.FullPhysicalPathOnDisk, GallerySettings.FullOptimizedPath, GallerySettings.FullMediaObjectPath);

            List <string> albumPaths = new List <string>(3);

            // The original path may contain thumbnails or optimized images when the thumbnail/optimized path is the same as the original path
            if ((GallerySettings.FullThumbnailPath.Equals(GallerySettings.FullMediaObjectPath, StringComparison.OrdinalIgnoreCase)) ||
                (GallerySettings.FullOptimizedPath.Equals(GallerySettings.FullMediaObjectPath, StringComparison.OrdinalIgnoreCase)))
            {
                albumPaths.Add(originalPath);
            }

            if (!albumPaths.Contains(thumbnailPath))
            {
                albumPaths.Add(thumbnailPath);
            }

            if (!albumPaths.Contains(optimizedPath))
            {
                albumPaths.Add(optimizedPath);
            }


            string thumbnailPrefix = GallerySettings.ThumbnailFileNamePrefix;
            string optimizedPrefix = GallerySettings.OptimizedFileNamePrefix;

            IGalleryObjectCollection mediaObjects = album.GetChildGalleryObjects(GalleryObjectType.MediaObject);

            // STEP 2: Loop through each path and make sure all thumbnail and optimized files in each directory have
            // matching media objects. Delete any files that do not.
            foreach (string albumPath in albumPaths)
            {
                if (!Directory.Exists(albumPath))
                {
                    return;
                }

                DirectoryInfo directory = new DirectoryInfo(albumPath);

                // Loop through each file in the directory.
                FileInfo[] files;
                try
                {
                    files = directory.GetFiles();
                }
                catch (UnauthorizedAccessException)
                {
                    return;
                }

                var queueItems = GetCurrentAndCompleteMediaQueueItems();

                foreach (FileInfo file in files)
                {
                    if ((file.Name.StartsWith(thumbnailPrefix, StringComparison.OrdinalIgnoreCase)) || (file.Name.StartsWith(optimizedPrefix, StringComparison.OrdinalIgnoreCase)))
                    {
                        // This file is a thumbnail or optimized file.

                        // TEST 1: Check to see if any media object in this album refers to it.
                        var foundMediaObject = false;
                        foreach (IGalleryObject mediaObject in mediaObjects)
                        {
                            if ((mediaObject.Optimized.FileName.Equals(file.Name, StringComparison.OrdinalIgnoreCase)) ||
                                (mediaObject.Thumbnail.FileName.Equals(file.Name, StringComparison.OrdinalIgnoreCase)))
                            {
                                foundMediaObject = true;
                                break;
                            }
                        }

                        if (!foundMediaObject)
                        {
                            // TEST 2: Maybe the encoder engine is currently creating the file or just finished it.

                            // First check to see if we started processing a new media item since we started this loop.
                            // If so, add it to our list of queue items.
                            var currentQueueItem = MediaConversionQueue.Instance.GetCurrentMediaQueueItem();
                            if (currentQueueItem != null && !queueItems.Any(mq => mq.MediaQueueId == currentQueueItem.MediaQueueId))
                            {
                                queueItems = queueItems.Concat(new[] { currentQueueItem });
                            }

                            // See if this file is mentioned in any of the media queue items
                            foundMediaObject = queueItems.Any(mq => mq.StatusDetail.Contains(file.Name));
                        }

                        if (!foundMediaObject)
                        {
                            // No media object in this album refers to this thumbnail or optimized image. Smoke it!
                            try
                            {
                                file.Delete();
                            }
                            catch (IOException ex)
                            {
                                // An exception occurred, probably because the account ASP.NET is running under does not
                                // have permission to delete the file. Let's record the error, but otherwise ignore it.
                                EventController.RecordError(ex, AppSetting.Instance, _galleryId, Factory.LoadGallerySettings());
                            }
                            catch (SecurityException ex)
                            {
                                // An exception occurred, probably because the account ASP.NET is running under does not
                                // have permission to delete the file. Let's record the error, but otherwise ignore it.
                                EventController.RecordError(ex, AppSetting.Instance, _galleryId, Factory.LoadGallerySettings());
                            }
                            catch (UnauthorizedAccessException ex)
                            {
                                // An exception occurred, probably because the account ASP.NET is running under does not
                                // have permission to delete the file. Let's record the error, but otherwise ignore it.
                                EventController.RecordError(ex, AppSetting.Instance, _galleryId, Factory.LoadGallerySettings());
                            }
                        }
                    }
                }
            }
        }
예제 #34
0
        private static int GetNextMediaObjectId(int mediaObjectIndex, IGalleryObjectCollection siblings)
        {
            int nextMediaObjectId = 0;
            if (mediaObjectIndex < (siblings.Count - 1))
            {
                nextMediaObjectId = siblings[mediaObjectIndex + 1].Id;
            }

            return nextMediaObjectId;
        }
예제 #35
0
        private void ConfigureControls()
        {
            this.PageTitle = Resources.GalleryServerPro.Task_Transfer_Objects_Page_Title;

            switch (this.TransObjectState)
            {
                #region AlbumCopyStep2
            case TransferObjectState.AlbumCopyStep2:
            {
                this.TaskHeaderText  = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Album_Header_Text;
                this.TaskBodyText    = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Album_Body_Text;
                this.OkButtonText    = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Album_Ok_Button_Text;
                this.OkButtonToolTip = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Album_Ok_Button_Tooltip;

                // Assign the album ID for the object the user selected to the variable used by the moveObjects() method.
                // We use a string array even though we only have a single value so that we are compatible with the
                // view state variable "ids" that is also assigned by the StoreUserSelections() methods, where
                // the user is allowed to select more than one object to copy/move. We prepend an 'a' to the ID to
                // indicate this is an album ID rather than a media object ID.
                string[] ids = { "a" + this.AlbumId.ToString(CultureInfo.InvariantCulture) };

                // Persist the album ID to the view state, so it is available in subsequent postbacks
                ViewState["ids"] = ids;

                // Show the treeview control, so the user can select the destination album
                ShowTreeview();

                // Don't show the treeview on subsequent postbacks
                ViewState["ShowTreeView"] = "0";
                break;
            }
                #endregion

                #region AlbumMoveStep2
            case TransferObjectState.AlbumMoveStep2:
            {
                this.TaskHeaderText  = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Album_Header_Text;
                this.TaskBodyText    = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Album_Body_Text;
                this.OkButtonText    = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Album_Ok_Button_Text;
                this.OkButtonToolTip = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Album_Ok_Button_Tooltip;

                // Assign the album ID for the object the user selected to the variable used by the moveObjects() method.
                // We use a string array even though we only have a single value so that we are compatible with the
                // view state variable "ids" that is also assigned by the StoreUserSelections() methods, where
                // the user is allowed to select more than one object to copy/move. We prepend an 'a' to the ID to
                // indicate this is an album ID rather than a media object ID.
                string[] ids = { "a" + this.AlbumId.ToString(CultureInfo.InvariantCulture) };

                // Persist the album ID to the view state, so it is available in subsequent postbacks
                ViewState["ids"] = ids;

                // Show the treeview control, so the user can select the destination album
                ShowTreeview();

                // Don't show the treeview on subsequent postbacks
                ViewState["ShowTreeView"] = "0";
                break;
            }
                #endregion

                #region MediaObjectCopyStep2
            case TransferObjectState.MediaObjectCopyStep2:
            {
                this.TaskHeaderText  = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Media_Object_Header_Text;
                this.TaskBodyText    = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Media_Object_Body_Text;
                this.OkButtonText    = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Media_Object_Ok_Button_Text;
                this.OkButtonToolTip = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Media_Object_Ok_Button_Tooltip;

                // Assign the media object ID for the object the user selected to the variable used by the moveObjects() method.
                // We use a string array even though we only have a single value so that we are compatible with the
                // view state variable "ids" that is also assigned by the StoreUserSelections() methods, where
                // the user is allowed to select more than one object to copy/move. We prepend an 'm' to the ID to
                // indicate this is a media object ID rather than an album ID.
                string[] ids = { "m" + this.GetMediaObject().Id.ToString(CultureInfo.InvariantCulture) };

                // Persist the album ID to the view state, so it is available in subsequent postbacks
                ViewState["ids"] = ids;

                // Show the treeview control, so the user can select the destination album
                ShowTreeview();

                // Don't show the treeview on subsequent postbacks
                ViewState["ShowTreeView"] = "0";
                break;
            }
                #endregion

                #region MediaObjectMoveStep2
            case TransferObjectState.MediaObjectMoveStep2:
            {
                this.TaskHeaderText  = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Media_Object_Header_Text;
                this.TaskBodyText    = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Media_Object_Body_Text;
                this.OkButtonText    = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Media_Object_Ok_Button_Text;
                this.OkButtonToolTip = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Media_Object_Ok_Button_Tooltip;

                // Assign the media object ID for the object the user selected to the variable used by the moveObjects() method.
                // We use a string array even though we only have a single value so that we are compatible with the
                // view state variable "ids" that is also assigned by the StoreUserSelections() methods, where
                // the user is allowed to select more than one object to copy/move. We prepend an 'm' to the ID to
                // indicate this is a media object ID rather than an album ID.
                string[] ids = { "m" + this.GetMediaObject().Id.ToString(CultureInfo.InvariantCulture) };

                // Persist the album ID to the view state, so it is available in subsequent postbacks
                ViewState["ids"] = ids;

                // Show the treeview control, so the user can select the destination album
                ShowTreeview();

                // Don't show the treeview on subsequent postbacks
                ViewState["ShowTreeView"] = "0";
                break;
            }
                #endregion

                #region ObjectsCopyStep1
            case TransferObjectState.ObjectsCopyStep1:
            {
                this.TaskHeaderText  = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Media_Objects_Step1_Header_Text;
                this.TaskBodyText    = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Media_Objects_Step1_Body_Text;
                this.OkButtonText    = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Media_Objects_Step1_Ok_Button_Text;
                this.OkButtonToolTip = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Media_Objects_Step1_Ok_Button_Tooltip;

                // Get the children of the current album the user will be choosing from.
                IGalleryObjectCollection albumChildren = this.GetAlbum().GetChildGalleryObjects(true);

                if (albumChildren.Count == 0)
                {
                    this.RedirectToAlbumViewPage("msg={0}", ((int)Message.CannotCopyNoObjectsExistInAlbum).ToString(CultureInfo.InvariantCulture));
                }

                SetThumbnailCssStyle(albumChildren);

                rptr.DataSource = albumChildren;
                rptr.DataBind();

                AddCheckAllInputBox();

                ViewState["ShowTreeView"] = "1";

                break;
            }
                #endregion

                #region ObjectsMoveStep1
            case TransferObjectState.ObjectsMoveStep1:
            {
                this.TaskHeaderText  = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Media_Objects_Step1_Header_Text;
                this.TaskBodyText    = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Media_Objects_Step1_Body_Text;
                this.OkButtonText    = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Media_Objects_Step1_Ok_Button_Text;
                this.OkButtonToolTip = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Media_Objects_Step1_Ok_Button_Tooltip;

                // Get the children of the current album the user will be choosing from.
                IGalleryObjectCollection albumChildren = this.GetAlbum().GetChildGalleryObjects(true);

                if (albumChildren.Count == 0)
                {
                    this.RedirectToAlbumViewPage("msg={0}", ((int)Message.CannotMoveNoObjectsExistInAlbum).ToString(CultureInfo.InvariantCulture));
                }

                SetThumbnailCssStyle(albumChildren);

                rptr.DataSource = albumChildren;
                rptr.DataBind();

                AddCheckAllInputBox();

                ViewState["ShowTreeView"] = "1";

                break;
            }
                #endregion

                #region ObjectsCopyStep2
            case TransferObjectState.ObjectsCopyStep2:
            {
                this.TaskHeaderText  = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Media_Objects_Step2_Header_Text;
                this.TaskBodyText    = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Media_Objects_Step2_Body_Text;
                this.OkButtonText    = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Media_Objects_Step2_Ok_Button_Text;
                this.OkButtonToolTip = Resources.GalleryServerPro.Task_Transfer_Objects_Copy_Media_Objects_Step2_Ok_Button_Tooltip;

                break;
            }
                #endregion

                #region ObjectsMoveStep2
            case TransferObjectState.ObjectsMoveStep2:
            {
                this.TaskHeaderText  = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Media_Objects_Step2_Header_Text;
                this.TaskBodyText    = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Media_Objects_Step2_Body_Text;
                this.OkButtonText    = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Media_Objects_Step2_Ok_Button_Text;
                this.OkButtonToolTip = Resources.GalleryServerPro.Task_Transfer_Objects_Move_Media_Objects_Step2_Ok_Button_Tooltip;

                break;
            }
                #endregion

                #region ReadyToTransfer
            case TransferObjectState.ReadyToTransfer: break;
                #endregion
            }
        }
예제 #36
0
        private static int GetNextMediaObjectIdForSlideshow(int mediaObjectIndex, IGalleryObjectCollection siblings)
        {
            int nextMediaObjectId = 0;
            while (mediaObjectIndex < (siblings.Count - 1))
            {
                IGalleryObject nextMediaObject = siblings[mediaObjectIndex + 1];
                if (nextMediaObject is GalleryServerPro.Business.Image)
                {
                    nextMediaObjectId = nextMediaObject.Id;
                    break;
                }

                mediaObjectIndex += 1;
            }

            return nextMediaObjectId;
        }
예제 #37
0
        private static int GetPreviousMediaObjectId(int mediaObjectIndex, IGalleryObjectCollection siblings)
        {
            int previousMediaObjectId = 0;
            if (mediaObjectIndex > 0)
            {
                previousMediaObjectId = siblings[mediaObjectIndex - 1].Id;
            }

            return previousMediaObjectId;
        }
예제 #38
0
        private IAlbum VerifyAlbumExistsAndReturnReference(ZipEntry zipContentFile, IAlbum rootParentAlbum)
        {
            // Get the directory path of the next file or directory within the zip file.
            // Ex: album1\album2\album3, album1
            string zipDirectoryPath = Path.GetDirectoryName(zipContentFile.Name);

            string[] directoryNames = zipDirectoryPath.Split(new char[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);

            string albumFullPhysicalPath = rootParentAlbum.FullPhysicalPathOnDisk;
            IAlbum currentAlbum          = rootParentAlbum;

            foreach (string directoryNameFromZip in directoryNames)
            {
                string shortenedDirName = GetPreviouslyCreatedTruncatedAlbumName(albumFullPhysicalPath, directoryNameFromZip);

                // Ex: c:\inetpub\wwwroot\galleryserver\mypics\2006\album1
                albumFullPhysicalPath = System.IO.Path.Combine(albumFullPhysicalPath, shortenedDirName);

                IAlbum newAlbum = null;
                if (Directory.Exists(albumFullPhysicalPath))
                {
                    // Directory exists, so there is probably an album corresponding to it. Find it.
                    IGalleryObjectCollection childGalleryObjects = currentAlbum.GetChildGalleryObjects(GalleryObjectType.Album);
                    foreach (IGalleryObject childGalleryObject in childGalleryObjects)
                    {
                        if (childGalleryObject.FullPhysicalPathOnDisk.Equals(albumFullPhysicalPath, StringComparison.OrdinalIgnoreCase))
                        {
                            newAlbum = childGalleryObject as Album; break;
                        }
                    }

                    if (newAlbum == null)
                    {
                        // No album in the database matches that directory. Add it.

                        // Before we add the album, we need to make sure the user has permission to add the album. Check if user
                        // is authenticated and if the current album is the one passed into this method. It can be assumed that any
                        // other album we encounter has been created by this method and we checked for permission when it was created.
                        if (this._isAuthenticated && (currentAlbum.Id == rootParentAlbum.Id))
                        {
                            SecurityManager.ThrowIfUserNotAuthorized(SecurityActions.AddChildAlbum, this._roles, currentAlbum.Id, currentAlbum.GalleryId, this._isAuthenticated, currentAlbum.IsPrivate);
                        }

                        newAlbum               = Factory.CreateEmptyAlbumInstance(currentAlbum.GalleryId);
                        newAlbum.Parent        = currentAlbum;
                        newAlbum.IsPrivate     = currentAlbum.IsPrivate;
                        newAlbum.DirectoryName = directoryNameFromZip;
                        HelperFunctions.UpdateAuditFields(newAlbum, this._userName);
                        newAlbum.Save();
                    }
                }
                else
                {
                    // The directory doesn't exist. Create an album.

                    // Before we add the album, we need to make sure the user has permission to add the album. Check if user
                    // is authenticated and if the current album is the one passed into this method. It can be assumed that any
                    // other album we encounter has been created by this method and we checked for permission when it was created.
                    if (this._isAuthenticated && (currentAlbum.Id == rootParentAlbum.Id))
                    {
                        SecurityManager.ThrowIfUserNotAuthorized(SecurityActions.AddChildAlbum, this._roles, currentAlbum.Id, currentAlbum.GalleryId, this._isAuthenticated, currentAlbum.IsPrivate);
                    }

                    newAlbum           = Factory.CreateEmptyAlbumInstance(currentAlbum.GalleryId);
                    newAlbum.IsPrivate = currentAlbum.IsPrivate;
                    newAlbum.Parent    = currentAlbum;
                    newAlbum.Title     = directoryNameFromZip;
                    HelperFunctions.UpdateAuditFields(newAlbum, this._userName);
                    newAlbum.Save();

                    // If the directory name written to disk is different than the name from the zip file, add it to
                    // our hash table.
                    if (!directoryNameFromZip.Equals(newAlbum.DirectoryName))
                    {
                        this._albumAndDirectoryNamesLookupTable.Add(Path.Combine(currentAlbum.FullPhysicalPathOnDisk, directoryNameFromZip), Path.Combine(currentAlbum.FullPhysicalPathOnDisk, newAlbum.DirectoryName));
                    }
                }
                currentAlbum = newAlbum;
            }

            return(currentAlbum);
        }
예제 #39
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Album" /> class.
        /// </summary>
        /// <param name="id">The album ID.</param>
        /// <param name="galleryId">The gallery ID.</param>
        /// <param name="parentId">The ID of the parent album that contains this album.</param>
        /// <param name="directoryName">Name of the directory.</param>
        /// <param name="thumbnailMediaObjectId">The thumbnail media object id.</param>
        /// <param name="sortByMetaName">The metadata item to sort the album by.</param>
        /// <param name="sortAscending">Indicates whether the contents of the album are sorted in ascending order. Specify null if 
        ///   the sort order is not known.</param>
        /// <param name="sequence">The sequence.</param>
        /// <param name="dateStart">The starting date for this album.</param>
        /// <param name="dateEnd">The ending date for this album.</param>
        /// <param name="createdByUsername">The user name of the user who created this gallery object.</param>
        /// <param name="dateAdded">The date this gallery object was created.</param>
        /// <param name="lastModifiedByUsername">The user name of the user who last modified this gallery object.</param>
        /// <param name="dateLastModified">The date and time this gallery object was last modified.</param>
        /// <param name="ownerUsername">The user name of this gallery object's owner.</param>
        /// <param name="ownerRoleName">The name of the role associated with this gallery object's owner.</param>
        /// <param name="isPrivate"><c>true</c> this gallery object is hidden from anonymous users; otherwise <c>false</c>.</param>
        /// <param name="isInflated">A bool indicating whether this object is fully inflated.</param>
        /// <param name="metadata">A collection of <see cref="Data.MetadataDto" /> instances containing metadata for the
        ///   object. Specify null if not available.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">galleryId</exception>
        internal Album(int id, int galleryId, int parentId, string directoryName, int thumbnailMediaObjectId, MetadataItemName sortByMetaName, bool? sortAscending, int sequence, DateTime dateStart, DateTime dateEnd, string createdByUsername, DateTime dateAdded, string lastModifiedByUsername, DateTime dateLastModified, string ownerUsername, string ownerRoleName, bool isPrivate, bool isInflated, IEnumerable<MetadataDto> metadata)
        {
            if (galleryId == int.MinValue)
            {
                throw new ArgumentOutOfRangeException("galleryId", String.Format(CultureInfo.CurrentCulture, "Gallery ID must be set to a valid value. Instead, the value was {0}.", galleryId));
            }

            this._galleryObjects = new GalleryObjectCollection();
            System.Diagnostics.Debug.Assert(this._areChildrenInflated == false, String.Format(CultureInfo.CurrentCulture, "The private boolean field _areChildrenInflated should have been initialized to false, but instead it was {0}.", this._areChildrenInflated));

            this.Id = id;

            // Specify gallery ID: Use galleryID parm if specified, otherwise, use gallery ID of parent. If no parent, use int.MinValue
            //this.GalleryId = (galleryId > int.MinValue ? galleryId : (parentId >= 0 ? this.Parent.GalleryId : int.MinValue));
            this.GalleryId = galleryId;

            if (parentId > 0)
            {
                this.Parent = Factory.CreateAlbumInstance(parentId, galleryId);
            }
            else if (parentId == 0)
            {
                this.Parent.Id = parentId; // Parent ID of root album is always 0.
            }

            //this.Title = title;
            this._directoryName = directoryName;
            //this._summary = summary;
            this.Sequence = sequence;
            this._dateStart = dateStart;
            this._dateEnd = dateEnd;
            this.CreatedByUserName = createdByUsername;
            this.DateAdded = dateAdded;
            this.LastModifiedByUserName = lastModifiedByUsername;
            this._ownerUsername = ownerUsername;
            this._ownerRoleName = ownerRoleName;
            this.DateLastModified = dateLastModified;
            this.IsPrivate = isPrivate;
            this.AllowMetadataLoading = true;
            this._fullPhysicalPathOnDisk = string.Empty;

            //this._thumbnailMediaObjectId = (thumbnailMediaObjectId == int.MinValue ? 0 : thumbnailMediaObjectId);
            this.ThumbnailMediaObjectId = (thumbnailMediaObjectId == int.MinValue ? 0 : thumbnailMediaObjectId);
            this._isThumbnailInflated = false;

            if (this._thumbnailMediaObjectId > 0)
            {
                this.Thumbnail = DisplayObject.CreateInstance(this, this._thumbnailMediaObjectId, DisplayObjectType.Thumbnail);
            }
            else
            {
                this.Thumbnail = GetDefaultAlbumThumbnail();
            }

            this.VirtualAlbumType = (id > int.MinValue ? VirtualAlbumType.NotVirtual : VirtualAlbumType.NotSpecified);

            this.SaveBehavior = Factory.GetAlbumSaveBehavior(this);
            this.DeleteBehavior = Factory.GetAlbumDeleteBehavior(this);
            this.MetadataReadWriter = Factory.GetMetadataReadWriter(this);

            IGallerySettings gallerySetting = Factory.LoadGallerySetting(GalleryId);

            if (this.IsNew)
            {
                if (sortByMetaName == MetadataItemName.NotSpecified)
                {
                    sortByMetaName = gallerySetting.DefaultAlbumSortMetaName;
                }

                if (!sortAscending.HasValue)
                {
                    sortAscending = gallerySetting.DefaultAlbumSortAscending;
                }

                if (gallerySetting.ExtractMetadata)
                {
                    ExtractMetadata();
                }
            }

            if (sortByMetaName != MetadataItemName.NotSpecified)
                this.SortByMetaName = sortByMetaName;

            if (sortAscending.HasValue)
                this.SortAscending = sortAscending.Value;

            if (metadata != null)
                AddMeta(GalleryObjectMetadataItemCollection.FromMetaDtos(this, metadata));

            this.IsInflated = isInflated;

            // Setting the previous properties has caused HasChanges = true, but we don't want this while
            // we're instantiating a new object. Reset to false.
            this.HasChanges = false;

            this.Saving += Album_Saving;
            this.Saved += Album_Saved;
        }