Ejemplo n.º 1
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(CultureInfo.CurrentCulture, "The parameter must be an instance of SynchronizeSettingsEntity. Instead, it was {0}.", syncSettingsObject.GetType()));
            }

            IAlbum album = syncSettings.AlbumToSynchronize;

            AppErrorController.LogEvent(String.Format(CultureInfo.CurrentCulture, "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(CultureInfo.CurrentCulture, "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);
        }
Ejemplo n.º 2
0
        public void Synchronize(int albumId, string synchId, bool isRecursive, bool rebuildThumbnails, bool rebuildOptimized, bool regenerateMetadata)
        {
            IAlbum album = null;

            try
            {
                #region Check user authorization

                bool isUserAuthenticated = Utils.IsAuthenticated;
                if (!isUserAuthenticated)
                    return;

                album = AlbumController.LoadAlbumInstance(albumId, true, true, false);

                if (!Utils.IsUserAuthorized(SecurityActions.Synchronize, RoleController.GetGalleryServerRolesForUser(), albumId, album.GalleryId, false))
                    return;

                #endregion

                SynchronizationManager synchMgr = new SynchronizationManager(album.GalleryId);

                synchMgr.IsRecursive = isRecursive;
                synchMgr.RebuildThumbnail = rebuildThumbnails;
                synchMgr.RebuildOptimized = rebuildOptimized;
                synchMgr.RegenerateMetadata = regenerateMetadata;

                synchMgr.Synchronize(synchId, album, Utils.UserName);
            }
            catch (Exception ex)
            {
                if (album != null)
                {
                    AppErrorController.LogError(ex, album.GalleryId);
                }
                else
                {
                    AppErrorController.LogError(ex);
                }
                throw;
            }
        }
Ejemplo n.º 3
0
		public static void Synchronize(int albumId, string synchId, bool isRecursive, bool overwriteThumb, bool overwriteOpt, bool regenerateMetadata)
		{
			// Refresh the synch status static variable. Each time we access the Instance property of the singleton, it gets its
			// properties refreshed with the latest values from the data store.
			_synchStatus = SynchronizationStatus.Instance;

			SynchronizationManager synchMgr = new SynchronizationManager();

			synchMgr.IsRecursive = isRecursive;
			synchMgr.OverwriteThumbnail = overwriteThumb;
			synchMgr.OverwriteOptimized = overwriteOpt;
			synchMgr.RegenerateMetadata = regenerateMetadata;

			try
			{
				synchMgr.Synchronize(synchId, Factory.LoadAlbumInstance(albumId, true), System.Web.HttpContext.Current.User.Identity.Name);
			}
			catch (Exception ex)
			{
				GalleryServerPro.ErrorHandler.AppErrorHandler.RecordErrorInfo(ex);
				throw;
			}
		}
Ejemplo n.º 4
0
		public void Synchronize(int albumId, string synchId, bool isRecursive, bool overwriteThumb, bool overwriteOpt, bool regenerateMetadata)
		{
			// Refresh the synch status static variable. Each time we access the Instance property of the singleton, it gets its
			// properties refreshed with the latest values from the data store.

			#region Check user authorization

			bool isUserAuthenticated = Util.IsAuthenticated;
			if (!isUserAuthenticated)
				return;

			if (!Util.IsUserAuthorized(SecurityActions.Synchronize, RoleController.GetGalleryServerRolesForUser(), albumId, false))
				return;

			#endregion
			
			lock (_synchStatus)
			{
				_synchStatus = SynchronizationStatus.Instance;
			}

			SynchronizationManager synchMgr = new SynchronizationManager();

			synchMgr.IsRecursive = isRecursive;
			synchMgr.OverwriteThumbnail = overwriteThumb;
			synchMgr.OverwriteOptimized = overwriteOpt;
			synchMgr.RegenerateMetadata = regenerateMetadata;

			try
			{
				synchMgr.Synchronize(synchId, Factory.LoadAlbumInstance(albumId, true), Util.UserName);
			}
			catch (Exception ex)
			{
				AppErrorController.LogError(ex);
				throw;
			}
		}
Ejemplo n.º 5
0
        /// <summary>
        /// Perform a synchronization according to the specified <paramref name="syncOptions" />. Any exceptions that occur during the
        /// sync are caught and logged to the event log. For auto-run syncs, the property <see cref="IGallerySettings.LastAutoSync" /> 
        /// is set to the current date/time and persisted to the data store.
        /// 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="syncOptions">An object specifying the parameters for the synchronization operation.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="syncOptions" /> is null.</exception>
        public static void BeginSync(SyncOptions syncOptions)
        {
            if (syncOptions == null)
                throw new ArgumentNullException("syncOptions");

            IAlbum album = null;

            try
            {
                album = AlbumController.LoadAlbumInstance(syncOptions.AlbumIdToSynchronize, true, true, true);

                AppEventController.LogEvent(String.Format(CultureInfo.InvariantCulture, "{0} synchronization of album '{1}' (ID {2}) has started.", syncOptions.UserName, album.Title, album.Id), album.GalleryId);

                var synchMgr = new SynchronizationManager(album.GalleryId);

                synchMgr.IsRecursive = syncOptions.IsRecursive;
                synchMgr.RebuildThumbnail = syncOptions.RebuildThumbnails;
                synchMgr.RebuildOptimized = syncOptions.RebuildOptimized;

                synchMgr.Synchronize(syncOptions.SyncId, album, syncOptions.UserName);

                if (syncOptions.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;
                }

                AppEventController.LogEvent(String.Format(CultureInfo.InvariantCulture, "{0} synchronization of album '{1}' (ID {2}) has finished.", syncOptions.UserName, album.Title, album.Id), album.GalleryId);
            }
            catch (SynchronizationInProgressException)
            {
                var message = String.Format(CultureInfo.InvariantCulture, "{0} synchronization of album '{1}' (ID {2}) could not be started because another one is in progress.", syncOptions.UserName, album != null ? album.Title : "N/A", album != null ? album.Id.ToString(CultureInfo.InvariantCulture) : "N/A");
                AppEventController.LogEvent(message, album != null ? album.GalleryId : (int?)null);
            }
            catch (Exception ex)
            {
                if (album != null)
                {
                    AppEventController.LogError(ex, album.GalleryId);
                }
                else
                {
                    AppEventController.LogError(ex);
                }

                var msg = String.Format(CultureInfo.InvariantCulture, "{0} synchronization of album '{1}' (ID {2}) has encountered an error and could not be completed.", syncOptions.UserName, album != null ? album.Title : "N/A", album != null ? album.Id.ToString(CultureInfo.InvariantCulture) : "N/A");
                AppEventController.LogEvent(msg, album != null ? album.GalleryId : (int?)null);
            }
        }