/// <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); }
public void SyncAlbum(int albumId, bool isRecursive, bool rebuildThumbnails, bool rebuildOptimized, bool regenerateMetadata, string password) { IAlbum album = null; try { album = AlbumController.LoadAlbumInstance(albumId, true, true, false); if (!ValidateRemoteSync(album, password)) { return; } SynchronizeSettingsEntity syncSettings = new SynchronizeSettingsEntity(); syncSettings.SyncInitiator = SyncInitiator.RemoteApp; syncSettings.AlbumToSynchronize = album; syncSettings.IsRecursive = isRecursive; syncSettings.RebuildThumbnails = rebuildThumbnails; syncSettings.RebuildOptimized = rebuildOptimized; syncSettings.RegenerateMetadata = regenerateMetadata; // Start sync on new thread Thread notifyAdminThread = new Thread(GalleryController.Synchronize); notifyAdminThread.Start(syncSettings); } catch (Exception ex) { if (album != null) { AppErrorController.LogError(ex, album.GalleryId); } else { AppErrorController.LogError(ex); } throw; } }