private static ActionResult CreateMediaObject(string filePath, IAlbum album, AddMediaObjectSettings options) { var result = new ActionResult { Title = Path.GetFileName(filePath) }; try { IGalleryObject go = Factory.CreateMediaObjectInstance(filePath, album); SaveGalleryObject(go, options.CurrentUserName); if (options.DiscardOriginalFile) { go.DeleteOriginalFile(); SaveGalleryObject(go); } result.Status = ActionResultStatus.Success.ToString(); } catch (UnsupportedMediaObjectTypeException ex) { try { File.Delete(filePath); } catch (UnauthorizedAccessException) { } // Ignore an error; the file will continue to exist in the destination album directory result.Status = ActionResultStatus.Error.ToString(); result.Message = ex.Message; } return(result); }
/// <summary> /// Adds the <paramref name="zipContentFile"/> as a media object to the <paramref name="album"/>. /// </summary> /// <param name="zipContentFile">A reference to a file in a ZIP archive.</param> /// <param name="album">The album to which the file should be added as a media object.</param> private void AddMediaObjectToGallery(ZipEntry zipContentFile, IAlbum album) { string zipFileName = Path.GetFileName(zipContentFile.Name).Trim(); if (zipFileName.Length == 0) { return; } string uniqueFilename = HelperFunctions.ValidateFileName(album.FullPhysicalPathOnDisk, zipFileName); string uniqueFilepath = Path.Combine(album.FullPhysicalPathOnDisk, uniqueFilename); // Extract the file from the zip stream and save as the specified filename. ExtractFileFromZipStream(uniqueFilepath); // Get the file we just saved to disk. FileInfo mediaObjectFile = new FileInfo(uniqueFilepath); try { using (IGalleryObject mediaObject = Factory.CreateMediaObjectInstance(mediaObjectFile, album)) { HelperFunctions.UpdateAuditFields(mediaObject, this._userName); mediaObject.Save(); if (_discardOriginalImage) { mediaObject.DeleteOriginalFile(); mediaObject.Save(); } this._fileExtractionResults.Add(new ActionResult() { Title = mediaObjectFile.Name, Status = ActionResultStatus.Success, Message = String.Empty }); } } catch (ErrorHandler.CustomExceptions.UnsupportedMediaObjectTypeException ex) { this._fileExtractionResults.Add(new ActionResult() { Title = mediaObjectFile.Name, Status = ActionResultStatus.Error, Message = ex.Message }); File.Delete(mediaObjectFile.FullName); } }
private void CreateNewMediaObject(IAlbum album, FileInfo file) { try { IGalleryObject mediaObject = Factory.CreateMediaObjectInstance(file, album); HelperFunctions.UpdateAuditFields(mediaObject, UserName); mediaObject.Save(); if (!GallerySettings.MediaObjectPathIsReadOnly && (GallerySettings.DiscardOriginalImageDuringImport)) { mediaObject.DeleteOriginalFile(); mediaObject.Save(); } mediaObject.IsSynchronized = true; } catch (UnsupportedMediaObjectTypeException) { _synchStatus.SkippedMediaObjects.Add(new KeyValuePair <string, string>(file.FullName.Remove(0, _fullMediaObjectPathLength + 1), Resources.SynchronizationStatus_Disabled_File_Type_Msg)); } }