/// <summary>
        /// Performs any necessary actions that must occur before an album is deleted. Specifically, it deletes the owner role
        /// if one exists for the album, but only when this album is the only one assigned to the role. It also clears out
        /// <see cref="IGallerySettings.UserAlbumParentAlbumId" /> if the album's ID matches it. This function recursively calls
        /// itself to make sure all child albums are processed.
        /// </summary>
        /// <param name="album">The album to be deleted, or one of its child albums.</param>
        private static void OnBeforeAlbumDelete(IAlbum album)
        {
            // If there is an owner role associated with this album, and the role is not assigned to any other albums, delete it.
            if (!String.IsNullOrEmpty(album.OwnerRoleName))
            {
                IGalleryServerRole role = RoleController.GetGalleryServerRoles().GetRole(album.OwnerRoleName);

                if ((role != null) && (role.AllAlbumIds.Count == 1) && role.AllAlbumIds.Contains(album.Id))
                {
                    RoleController.DeleteGalleryServerProRole(role.RoleName);
                }
            }

            // If the album is specified as the user album container, clear out the setting. The ValidateBeforeAlbumDelete()
            // function will throw an exception if user albums are enabled, so this should only happen when user albums
            // are disabled, so it is safe to clear it out.
            int userAlbumParentAlbumId = Factory.LoadGallerySetting(album.GalleryId).UserAlbumParentAlbumId;

            if (album.Id == userAlbumParentAlbumId)
            {
                IGallerySettings gallerySettingsWriteable = Factory.LoadGallerySetting(album.GalleryId, true);
                gallerySettingsWriteable.UserAlbumParentAlbumId = 0;
                gallerySettingsWriteable.Save();
            }

            // Recursively validate child albums.
            foreach (IGalleryObject childAlbum in album.GetChildGalleryObjects(GalleryObjectType.Album))
            {
                OnBeforeAlbumDelete((IAlbum)childAlbum);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Sets the media object path for the new gallery to the path of the current gallery. The change is persisted to the data store.
        /// </summary>
        /// <param name="gallery">The gallery.</param>
        private void SetMediaObjectPathForNewGallery(IGallery gallery)
        {
            IGallerySettings gallerySettings = Factory.LoadGallerySetting(gallery.GalleryId, true);

            gallerySettings.MediaObjectPath = GallerySettings.MediaObjectPath;
            gallerySettings.ThumbnailPath   = GallerySettings.ThumbnailPath;
            gallerySettings.OptimizedPath   = GallerySettings.OptimizedPath;

            gallerySettings.Save();
        }
Beispiel #3
0
        /// <summary>
        /// Perform a synchronize according to the specified <paramref name="syncSettingsObject" />.
        /// When complete, update the <see cref="IGallerySettings.LastAutoSync" /> property to the current date/time and persist
        /// to the data store. The <paramref name="syncSettingsObject" /> is specified as <see cref="Object" /> so that this method can
        /// be invoked on a separate thread using <see cref="System.Threading.Thread" />. Any exceptions that occur during the
        /// sync are caught and logged to the event log. NOTE: This method does not perform any security checks; the calling
        /// code must ensure the requesting user is authorized to run the sync.
        /// </summary>
        /// <param name="syncSettingsObject">The synchronize settings object. It must be of type <see cref="SynchronizeSettingsEntity" />.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="syncSettingsObject" /> is null.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="syncSettingsObject" /> is not of type
        /// <see cref="SynchronizeSettingsEntity" />.</exception>
        public static void Synchronize(object syncSettingsObject)
        {
            if (syncSettingsObject == null)
            {
                throw new ArgumentNullException("syncSettingsObject");
            }

            SynchronizeSettingsEntity syncSettings = syncSettingsObject as SynchronizeSettingsEntity;

            if (syncSettings == null)
            {
                throw new ArgumentException(String.Format("The parameter must be an instance of SynchronizeSettingsEntity. Instead, it was {0}.", syncSettingsObject.GetType()));
            }

            IAlbum album = syncSettings.AlbumToSynchronize;

            AppErrorController.LogEvent(String.Format("INFO (not an error): {0} synchronization of album '{1}' (ID {2}) and all child albums has started.", syncSettings.SyncInitiator, album.Title, album.Id), album.GalleryId);

            try
            {
                SynchronizationManager synchMgr = new SynchronizationManager(album.GalleryId);

                synchMgr.IsRecursive        = syncSettings.IsRecursive;
                synchMgr.OverwriteThumbnail = syncSettings.OverwriteThumbnails;
                synchMgr.OverwriteOptimized = syncSettings.OverwriteOptimized;
                synchMgr.RegenerateMetadata = syncSettings.RegenerateMetadata;

                synchMgr.Synchronize(Guid.NewGuid().ToString(), album, "Admin");

                if (syncSettings.SyncInitiator == SyncInitiator.AutoSync)
                {
                    // Update the date/time of this auto-sync and save to data store.
                    IGallerySettings gallerySettings = Factory.LoadGallerySetting(album.GalleryId, true);
                    gallerySettings.LastAutoSync = DateTime.Now;
                    gallerySettings.Save(false);

                    // The above Save() only updated the database; now we need to update the in-memory copy of the settings.
                    // We have to do this instead of simply calling gallerySettings.Save(true) because that overload causes the
                    // gallery settings to be cleared and reloaded, and the reloading portion done by the AddMembershipDataToGallerySettings
                    // function fails in DotNetNuke because there isn't a HttpContext.Current instance at this moment (because this code is
                    // run on a separate thread).
                    IGallerySettings gallerySettingsReadOnly = Factory.LoadGallerySetting(album.GalleryId, false);
                    gallerySettingsReadOnly.LastAutoSync = gallerySettings.LastAutoSync;
                }
            }
            catch (Exception ex)
            {
                AppErrorController.LogError(ex, album.GalleryId);
            }

            AppErrorController.LogEvent(String.Format("INFO (not an error): {0} synchronization of album '{1}' (ID {2}) and all child albums is complete.", syncSettings.SyncInitiator, album.Title, album.Id), album.GalleryId);
        }