Exemplo n.º 1
0
        private void CropImage(IFileDao <T> fileDao, File <T> file)
        {
            logger.DebugFormat("CropImage: FileId: {0}.", file.ID);

            using (var stream = fileDao.GetFileStream(file))
            {
                Crop(fileDao, file, stream);
            }

            logger.DebugFormat("CropImage: FileId: {0}. Successfully saved.", file.ID);
        }
Exemplo n.º 2
0
        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 <SecurityDao <TFrom> >();
            var tagDao      = ServiceProvider.GetService <TagDao <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 (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);
        }