public FileOperationResult CopyFile(MediaFileInfo mediaFile, string destinationFileName, DuplicateFileHandling dupeFileHandling = DuplicateFileHandling.ThrowError) { Guard.NotNull(mediaFile, nameof(mediaFile)); Guard.NotEmpty(destinationFileName, nameof(destinationFileName)); var destPathData = CreateDestinationPathData(mediaFile.File, destinationFileName); var destFileName = destPathData.FileName; var destFolderId = destPathData.Folder.Id; var dupe = mediaFile.FolderId == destPathData.Folder.Id // Source folder equals dest folder, so same file ? mediaFile.File // Another dest folder, check for duplicate by file name : _fileRepo.Table.FirstOrDefault(x => x.Name == destFileName && x.FolderId == destFolderId); var copy = InternalCopyFile( mediaFile.File, destPathData, true /* copyData */, (DuplicateEntryHandling)((int)dupeFileHandling), () => dupe, p => CheckUniqueFileName(p), out var isDupe); return(new FileOperationResult { Operation = "copy", DuplicateFileHandling = dupeFileHandling, SourceFile = mediaFile, DestinationFile = ConvertMediaFile(copy, destPathData.Folder), IsDuplicate = isDupe, UniquePath = isDupe ? destPathData.FullPath : (string)null }); }
protected MediaFileInfo ConvertMediaFile(MediaFile file, MediaFolderNode folder) { var mediaFile = new MediaFileInfo(file, _storageProvider, _urlGenerator, folder?.Path) { ThumbSize = _mediaSettings.ProductThumbPictureSize }; return(mediaFile); }
public virtual string GenerateUrl( MediaFileInfo file, ProcessImageQuery imageQuery, string host = null, bool doFallback = true) { string path; // Build virtual path with pattern "media/{id}/{album}/{dir}/{NameWithExt}" if (file?.Path != null) { path = _processedImagesRootPath + file.Id.ToString(CultureInfo.InvariantCulture) + "/" + file.Path; } else if (doFallback) { path = _processedImagesRootPath + "0/" + _fallbackImageFileName; } else { return(null); } if (host == null) { host = _host; } else if (host == string.Empty) { host = _appPath; } else { host = host.EnsureEndsWith("/"); } var url = host; // Strip leading "/", the host/apppath has this already if (path[0] == '/') { path = path.Substring(1); } // Append media path url += path; // Append query var query = imageQuery?.ToString(false); if (query != null && query.Length > 0) { url += query; } return(url); }
public static string GetUrl(this IMediaService service, MediaFileInfo file, int thumbnailSize, string host = null, bool doFallback = true) { ProcessImageQuery query = thumbnailSize > 0 ? new ProcessImageQuery { MaxSize = thumbnailSize } : null; return(service.GetUrl(file, query, host, doFallback)); }
public string GetUrl(MediaFileInfo file, ProcessImageQuery imageQuery, string host = null, bool doFallback = true) { return(_urlGenerator.GenerateUrl(file, imageQuery, host, doFallback)); }
public DuplicateMediaFileException(string message, MediaFileInfo dupeFile, string uniquePath) : base(message) { File = dupeFile; UniquePath = uniquePath; }
public InvalidOperationException IdenticalPaths(MediaFileInfo file) { Guard.NotNull(file, nameof(file)); return(new InvalidOperationException(T("Admin.Media.Exception.FileNamesIdentical", file.Path))); }
public DuplicateMediaFileException DuplicateFile(string fullPath, MediaFileInfo dupeFile, string uniquePath) { return(new DuplicateMediaFileException(T("Admin.Media.Exception.DuplicateFile", fullPath), dupeFile, uniquePath)); }