public File <TTo> PerformCrossDaoFileCopy <TFrom, TTo>( TFrom fromFileId, IFileDao <TFrom> fromFileDao, Func <TFrom, TFrom> fromConverter, TTo toFolderId, IFileDao <TTo> toFileDao, Func <TTo, TTo> toConverter, bool deleteSourceFile) { //Get File from first dao var fromFile = fromFileDao.GetFile(fromConverter(fromFileId)); if (fromFile.ContentLength > SetupInfo.AvailableFileSize) { throw new Exception(string.Format(deleteSourceFile ? FilesCommonResource.ErrorMassage_FileSizeMove : FilesCommonResource.ErrorMassage_FileSizeCopy, FileSizeComment.FilesSizeToString(SetupInfo.AvailableFileSize))); } var securityDao = ServiceProvider.GetService <ISecurityDao <TFrom> >(); var tagDao = ServiceProvider.GetService <ITagDao <TFrom> >(); var fromFileShareRecords = securityDao.GetPureShareRecords(fromFile).Where(x => x.EntryType == FileEntryType.File); var fromFileNewTags = tagDao.GetNewTags(Guid.Empty, fromFile).ToList(); var fromFileLockTag = tagDao.GetTags(fromFile.ID, FileEntryType.File, TagType.Locked).FirstOrDefault(); var fromFileFavoriteTag = tagDao.GetTags(fromFile.ID, FileEntryType.File, TagType.Favorite); var fromFileTemplateTag = tagDao.GetTags(fromFile.ID, FileEntryType.File, TagType.Template); var toFile = ServiceProvider.GetService <File <TTo> >(); toFile.Title = fromFile.Title; toFile.Encrypted = fromFile.Encrypted; toFile.FolderID = toConverter(toFolderId); fromFile.ID = fromConverter(fromFile.ID); var mustConvert = !string.IsNullOrEmpty(fromFile.ConvertedType); using (var fromFileStream = mustConvert ? FileConverter.Exec(fromFile) : fromFileDao.GetFileStream(fromFile)) { toFile.ContentLength = fromFileStream.CanSeek ? fromFileStream.Length : fromFile.ContentLength; toFile = toFileDao.SaveFile(toFile, fromFileStream); } if (fromFile.ThumbnailStatus == Thumbnail.Created) { using (var thumbnail = fromFileDao.GetThumbnail(fromFile)) { toFileDao.SaveThumbnail(toFile, thumbnail); } toFile.ThumbnailStatus = Thumbnail.Created; } if (deleteSourceFile) { if (fromFileShareRecords.Any()) { fromFileShareRecords.ToList().ForEach(x => { x.EntryId = toFile.ID; securityDao.SetShare(x); }); } var fromFileTags = fromFileNewTags; if (fromFileLockTag != null) { fromFileTags.Add(fromFileLockTag); } if (fromFileFavoriteTag != null) { fromFileTags.AddRange(fromFileFavoriteTag); } if (fromFileTemplateTag != null) { fromFileTags.AddRange(fromFileTemplateTag); } if (fromFileTags.Any()) { fromFileTags.ForEach(x => x.EntryId = toFile.ID); tagDao.SaveTags(fromFileTags); } //Delete source file if needed fromFileDao.DeleteFile(fromConverter(fromFileId)); } return(toFile); }