Exemplo n.º 1
0
        /// <summary>
        /// Synchronize the media object library, starting with the root album. Optionally specify that only the
        /// specified album is synchronized. If <see cref="IsRecursive" /> = true, then child albums are recursively synchronized;
        /// otherwise, only the root album (or the specified album if that overload is used) is synchronized.
        /// </summary>
        /// <param name="synchId">A GUID that uniquely indentifies the synchronization. If another synchronization is in
        /// progress, a <see cref="GalleryServerPro.ErrorHandler.CustomExceptions.SynchronizationInProgressException" /> exception is thrown.</param>
        /// <param name="userName">The user name for the logged on user. This is used for the audit fields in the album
        /// and media objects.</param>
        /// <param name="album">The album to synchronize.</param>
        /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.SynchronizationInProgressException">
        /// Thrown if another synchronization is in progress.</exception>
        public void Synchronize(string synchId, IAlbum album, string userName)
        {
            Factory.GetDataProvider().BeginTransaction();

            try
            {
                Initialize(synchId, album, userName);                 // Will throw SynchronizationInProgressException if another is in progress. Will be caught by upstream code.

                DirectoryInfo albumDirectory = new DirectoryInfo(album.FullPhysicalPathOnDisk);

                // Update this album.
                album.IsSynchronized = true;

                // Synchronize the files in this album. No recursive action.
                SynchronizeMediaObjectFiles(albumDirectory, album);

                // Synchronize any external media objects previously added. No recursive action.
                SynchronizeExternalMediaObjects(album);

                if (this.IsRecursive)
                {
                    // Synchronize the child directories and their files. Acts recursively.
                    SynchronizeChildDirectories(albumDirectory, album);
                }

                // Persist synchronized objects to the data store and delete the unsynchronized ones.
                DeleteUnsynchronizedObjects();

                Album.AssignAlbumThumbnail(album, false, true, this._userName);

                DeleteOrphanedImages(album);
            }
            catch (GalleryServerPro.ErrorHandler.CustomExceptions.SynchronizationTerminationRequestedException)
            {
                // The user has cancelled the synchronization. Swallow the exception and return.
                Factory.GetDataProvider().RollbackTransaction();

                return;
            }
            catch
            {
                Factory.GetDataProvider().RollbackTransaction();
                throw;
            }
            finally
            {
                // Set the list of hash keys to null to clean up memory.
                MediaObjectHashKeys.Clear();

                HelperFunctions.PurgeCache();

                if (this._synchStatus != null)
                {
                    this._synchStatus.Finish(synchId);
                }
            }

            Factory.GetDataProvider().CommitTransaction();
        }
Exemplo n.º 2
0
        private bool Initialize(string synchId, IAlbum album, string userName)
        {
            if (String.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException("userName");
            }

            this._userName = userName;

            #region Set up the _synchStatus instance

            this._synchStatus = SynchronizationStatus.Instance;

            // Tell that status instance we are starting a new synchronization. It will throw
            // SynchronizationInProgressException if another is in progress.
            this._synchStatus.Start(synchId, CountFiles(album.FullPhysicalPathOnDisk));

            #endregion

            #region Populate the _albumsFromDataStore and _mediaObjectsFromDataStore dictionary objects and set each to IsSynchronized = false

            this._albumsFromDataStore       = new Dictionary <String, IAlbum>();
            this._mediaObjectsFromDataStore = new Dictionary <String, IGalleryObject>(this._synchStatus.TotalFileCount);

            // Fill _albums and _mediaObjects with the albums and media objects for this album as currently stored
            // in the data store. We'll be comparing these objects with those we find on the hard drive. Act recursively
            // if IsRecursive = true. Set IsSynchronized = false for each object. (We'll be setting it back to true
            // as we synchronize each object.)
            album.IsSynchronized            = false;
            album.RegenerateThumbnailOnSave = this.OverwriteThumbnail;

            this._albumsFromDataStore.Add(album.FullPhysicalPathOnDisk, album);

            foreach (IGalleryObject mediaObject in album.GetChildGalleryObjects(GalleryObjectType.MediaObject))
            {
                mediaObject.IsSynchronized            = false;
                mediaObject.RegenerateThumbnailOnSave = this.OverwriteThumbnail;
                mediaObject.RegenerateOptimizedOnSave = this.OverwriteOptimized;
                mediaObject.RegenerateMetadataOnSave  = this.RegenerateMetadata;

                if (!String.IsNullOrEmpty(mediaObject.Hashkey))
                {
                    this._mediaObjectsFromDataStore.Add(mediaObject.Hashkey, mediaObject);
                }
            }

            if (this._isRecursive)
            {
                AddChildAlbumsAndGalleryObjectsAndSetToUnsynchronized(this._albumsFromDataStore, this._mediaObjectsFromDataStore, album);
            }

            #endregion

            // Clear the list of hash keys so we're starting with a fresh load from the data store.
            MediaObjectHashKeys.Clear();

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Analyze the specified ZIP file for embedded files and directories. Create albums and media objects from the
        /// files. Skip any files whose type is not enabled within Gallery Server Pro. Return a list of skipped files
        /// and the reason why they were skipped.
        /// </summary>
        /// <param name="fileStream">A stream representing a ZIP file containing directories and files to be extracted
        /// to the Gallery Server Pro library.</param>
        /// <param name="parentAlbum">The album that should contain the top-level directories and files found in the ZIP
        /// file.</param>
        /// <param name="discardOriginalImage">Indicates whether to delete the original image file after the thumbnail/
        /// original images have been created. Ignored for non-image files.</param>
        /// <returns>
        /// Returns a <see cref="System.Collections.Generic.List{T}"/> where the key is the name
        /// of the skipped file and the value is the reason for the file being skipped.
        /// </returns>
        public List <KeyValuePair <string, string> > ExtractZipFile(Stream fileStream, IAlbum parentAlbum, bool discardOriginalImage)
        {
            if (String.IsNullOrEmpty(this._userName))
            {
                throw new InvalidOperationException("A username was not specified in the ZipUtility constructor. Media objects extracted from a ZIP archive must be associated with a logged on user.");
            }

            this._albumAndDirectoryNamesLookupTable = new Hashtable(10);

            try
            {
                this._zipStream            = new ZipInputStream(fileStream);
                this._discardOriginalImage = discardOriginalImage;
                ZipEntry zipContentFile;
                // Sueetie Modified - Want to log activity only once - passing "i" to AddMediaObjectToGallery()
                int i = 0;
                while ((zipContentFile = this._zipStream.GetNextEntry()) != null)
                {
                    IAlbum album = VerifyAlbumExistsAndReturnReference(zipContentFile, parentAlbum);

                    if (Path.GetExtension(zipContentFile.Name).Equals(".zip", StringComparison.OrdinalIgnoreCase))
                    {
                        // We have a ZIP file embedded within the parent zip file. Recursively extract the contents of this file.
                        ExtractEmbeddedZipFile(zipContentFile, parentAlbum);
                    }
                    else
                    {
                        AddMediaObjectToGallery(zipContentFile, album, i);
                    }
                    i++;
                }
            }
            finally
            {
                this._zipStream.Close();
                this._zipStream = null;

                // Clear the list of hash keys to to ensure a fresh load from the database the next time they are requested.
                MediaObjectHashKeys.Clear();
            }

            return(this._skippedFiles);
        }
Exemplo n.º 4
0
 private static void Initialize()
 {
     // Clear the list of hash keys so we're starting with a fresh load from the data store.
     MediaObjectHashKeys.Clear();
 }
Exemplo n.º 5
0
		/// <summary>
		/// Nulls out the singleton instance so that the next time it is requested, the latest set of hash keys are extracted
		/// from the data store.
		/// </summary>
		public static void Clear()
		{
			_instance = null;
		}
Exemplo n.º 6
0
 /// <summary>
 /// Nulls out the singleton instance so that the next time it is requested, the latest set of hash keys are extracted
 /// from the data store.
 /// </summary>
 public static void Clear()
 {
     _instance = null;
 }