コード例 #1
0
        /// <summary>
        /// Persist the object to which this behavior belongs to the data store. Also persist to the file system, if
        /// the object has a representation on disk, such as albums (stored as directories) and media objects (stored
        /// as files). New objects with ID = int.MinValue will have a new <see cref="IGalleryObject.Id"/> assigned
        /// and <see cref="IGalleryObject.IsNew"/> set to false.
        /// All validation should have taken place before calling this method.
        /// </summary>
        public void Save()
        {
            // If the user requested a rotation, then rotate and save the original. If no rotation is requested,
            // the following line does nothing.
            this._galleryObject.Original.GenerateAndSaveFile();

            // Generate the thumbnail and optimized versions. These must run after the previous statement because when
            // the image is rotated, these methods assume the original has already been rotated.
            try
            {
                this._galleryObject.Thumbnail.GenerateAndSaveFile();
                this._galleryObject.Optimized.GenerateAndSaveFile();

                try
                {
                    // Now delete the temp file, but no worries if an error happens. The file is in the temp directory
                    // which is cleaned out each time the app starts anyway.
                    if (File.Exists(_galleryObject.Original.TempFilePath))
                    {
                        File.Delete(_galleryObject.Original.TempFilePath);
                    }
                }
                catch (IOException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
                catch (NotSupportedException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
                catch (UnauthorizedAccessException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
            }
            catch (UnsupportedImageTypeException)
            {
                // We'll get here when there is a corrupt image or the server's memory is not sufficient to process the image.
                // When this happens, replace the thumbnail creator object with a GenericThumbnailCreator. That one uses a
                // hard-coded thumbnail image rather than trying to generate a thumbnail from the original image.
                // Also, null out the Optimized object and don't bother to try to create an optimized image.
                this._galleryObject.Thumbnail.DisplayObjectCreator = new GenericThumbnailCreator(this._galleryObject);
                this._galleryObject.Thumbnail.GenerateAndSaveFile();

                this._galleryObject.Optimized = new NullObjects.NullDisplayObject();
            }

            var mediaItemsAreWritable = !Factory.LoadGallerySetting(_galleryObject.GalleryId).MediaObjectPathIsReadOnly;

            if (mediaItemsAreWritable)
            {
                SyncFilenameToMetadataFilename();
            }

            var isNew = this._galleryObject.IsNew;

            // Save the data to the data store
            using (var repo = new MediaObjectRepository())
            {
                repo.Save(this._galleryObject);
            }

            foreach (var item in this._galleryObject.MetadataItems)
            {
                if (mediaItemsAreWritable && !isNew && item.HasChanges && item.PersistToFile)
                {
                    // Persist meta property to original file, but only in writable galleries and for existing media objects
                    // (new ones have their meta extracted from the file so it doesn't make sense to write it back right away).
                    this._galleryObject.MetadataReadWriter.SaveMetaValue(item.MetadataItemName);
                }

                item.HasChanges = false;
            }
        }
コード例 #2
0
        /// <summary>
        /// Persist the object to which this behavior belongs to the data store. Also persist to the file system, if
        /// the object has a representation on disk, such as albums (stored as directories) and media objects (stored
        /// as files). New objects with ID = int.MinValue will have a new <see cref="IGalleryObject.Id"/> assigned
        /// and <see cref="IGalleryObject.IsNew"/> set to false.
        /// All validation should have taken place before calling this method.
        /// </summary>
        public void Save()
        {
            // If the user requested a rotation, then rotate and save the original. If no rotation is requested,
            // the following line does nothing.
            this._galleryObject.Original.GenerateAndSaveFile();

            // Generate the thumbnail and optimized versions. These must run after the previous statement because when
            // the image is rotated, these methods assume the original has already been rotated.
            try
            {
                this._galleryObject.Thumbnail.GenerateAndSaveFile();
                this._galleryObject.Optimized.GenerateAndSaveFile();

                try
                {
                    // Now delete the temp file, but no worries if an error happens. The file is in the temp directory
                    // which is cleaned out each time the app starts anyway.
                    if (File.Exists(_galleryObject.Original.TempFilePath))
                    {
                        File.Delete(_galleryObject.Original.TempFilePath);
                    }
                }
                catch (IOException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
                catch (NotSupportedException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
                catch (UnauthorizedAccessException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
            }
            catch (UnsupportedImageTypeException)
            {
                // We'll get here when there is a corrupt image or the server's memory is not sufficient to process the image.
                // When this happens, replace the thumbnail creator object with a GenericThumbnailCreator. That one uses a
                // hard-coded thumbnail image rather than trying to generate a thumbnail from the original image.
                // Also, null out the Optimized object and don't bother to try to create an optimized image.
                this._galleryObject.Thumbnail.DisplayObjectCreator = new GenericThumbnailCreator(this._galleryObject);
                this._galleryObject.Thumbnail.GenerateAndSaveFile();

                this._galleryObject.Optimized = new NullObjects.NullDisplayObject();
            }

            SyncFilenameToMetadataFilename();

            // Save the data to the data store
            //Factory.GetDataProvider().MediaObject_Save(this._galleryObject);
            using (var repo = new MediaObjectRepository())
            {
                repo.Save(this._galleryObject);
            }

            foreach (IGalleryObjectMetadataItem item in this._galleryObject.MetadataItems)
            {
                item.HasChanges = false;
            }
        }
コード例 #3
0
        /// <summary>
        /// Persist the object to which this behavior belongs to the data store. Also persist to the file system, if
        /// the object has a representation on disk, such as albums (stored as directories) and media objects (stored
        /// as files). New objects with ID = int.MinValue will have a new <see cref="IGalleryObject.Id"/> assigned
        /// and <see cref="IGalleryObject.IsNew"/> set to false.
        /// All validation should have taken place before calling this method.
        /// </summary>
        public void Save()
        {
            // If the user requested a rotation, then rotate and save the original. If no rotation is requested,
            // the following line does nothing.
            this._galleryObject.Original.GenerateAndSaveFile();

            // Generate the thumbnail and optimized versions. These must run after the previous statement because when
            // the image is rotated, these methods assume the original has already been rotated.
            try
            {
                this._galleryObject.Thumbnail.GenerateAndSaveFile();
                this._galleryObject.Optimized.GenerateAndSaveFile();

                try
                {
                    // Now delete the temp file, but no worries if an error happens. The file is in the temp directory
                    // which is cleaned out each time the app starts anyway.
                    if (File.Exists(_galleryObject.Original.TempFilePath))
                    {
                        File.Delete(_galleryObject.Original.TempFilePath);
                    }
                }
                catch (IOException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
                catch (NotSupportedException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
                catch (UnauthorizedAccessException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
            }
            catch (UnsupportedImageTypeException)
            {
                // We'll get here when there is a corrupt image or the server's memory is not sufficient to process the image.
                // When this happens, replace the thumbnail creator object with a GenericThumbnailCreator. That one uses a
                // hard-coded thumbnail image rather than trying to generate a thumbnail from the original image.
                // Also, null out the Optimized object and don't bother to try to create an optimized image.
                this._galleryObject.Thumbnail.DisplayObjectCreator = new GenericThumbnailCreator(this._galleryObject);
                this._galleryObject.Thumbnail.GenerateAndSaveFile();

                this._galleryObject.Optimized = new NullObjects.NullDisplayObject();
            }

            SyncFilenameToMetadataFilename();

            // Save the data to the data store
            //Factory.GetDataProvider().MediaObject_Save(this._galleryObject);
            using (var repo = new MediaObjectRepository())
            {
                repo.Save(this._galleryObject);
            }

            foreach (IGalleryObjectMetadataItem item in this._galleryObject.MetadataItems)
            {
                item.HasChanges = false;
            }
        }