private static void SaveFile(IFileDao fileDao, object folder, string filePath, IDataStore storeTemp)
        {
            using (var stream = storeTemp.GetReadStream("", filePath))
            {
                var fileName = Path.GetFileName(filePath);
                var file     = new File
                {
                    Title         = fileName,
                    ContentLength = stream.CanSeek ? stream.Length : storeTemp.GetFileSize("", filePath),
                    FolderID      = folder,
                    Comment       = FilesCommonResource.CommentCreate,
                };
                stream.Position = 0;
                try
                {
                    file = fileDao.SaveFile(file, stream);

                    FileMarker.MarkAsNew(file);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
            }
        }
Beispiel #2
0
        public static void ReassignItems(object parentId, Guid fromUserId, Guid toUserId, IFolderDao folderDao, IFileDao fileDao)
        {
            var files = fileDao.GetFiles(parentId, new OrderBy(SortedByType.AZ, true), FilterType.ByUser, fromUserId, null, withSubfolders: true)
                        .Where(file => file.CreateBy == fromUserId);

            foreach (var file in files)
            {
                file.CreateBy = toUserId;
                fileDao.SaveFile(file, null);
            }

            var folders = folderDao.GetFolders(parentId, new OrderBy(SortedByType.AZ, true), FilterType.ByUser, fromUserId, null, true)
                          .Where(folder => folder.CreateBy == fromUserId);

            foreach (var folder in folders)
            {
                folder.CreateBy = toUserId;
                folderDao.SaveFolder(folder);
            }
        }
Beispiel #3
0
        private static void SaveFile(IFileDao fileDao, object folder, string filePath, IDataStore storeTemp)
        {
            try
            {
                if (FileUtility.GetFileExtension(filePath) == "." + ThumbnailExtension &&
                    storeTemp.IsFile("", Regex.Replace(filePath, "\\." + ThumbnailExtension + "$", "")))
                {
                    return;
                }

                var fileName = Path.GetFileName(filePath);
                var file     = new File
                {
                    Title    = fileName,
                    FolderID = folder,
                    Comment  = FilesCommonResource.CommentCreate,
                };

                using (var stream = storeTemp.GetReadStream("", filePath))
                {
                    file.ContentLength = stream.CanSeek ? stream.Length : storeTemp.GetFileSize("", filePath);
                    file = fileDao.SaveFile(file, stream);
                }

                var pathThumb = filePath + "." + ThumbnailExtension;
                if (storeTemp.IsFile("", pathThumb))
                {
                    using (var streamThumb = storeTemp.GetReadStream("", pathThumb))
                    {
                        fileDao.SaveThumbnail(file, streamThumb);
                    }
                    file.ThumbnailStatus = Thumbnail.Created;
                }

                FileMarker.MarkAsNew(file);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
Beispiel #4
0
 private static void SaveFile(IFileDao fileDao, object folder, string filePath, IDataStore storeTemp)
 {
     using (var stream = storeTemp.IronReadStream("", filePath, 10))
     {
         var fileName = Path.GetFileName(filePath);
         var file     = new File
         {
             Title         = ReplaceInvalidCharsAndTruncate(fileName),
             ContentLength = stream.Length,
             ContentType   = MimeMapping.GetMimeMapping(fileName),
             FolderID      = folder,
         };
         stream.Position = 0;
         try
         {
             fileDao.SaveFile(file, stream);
         }
         catch
         {
         }
     }
 }
Beispiel #5
0
        private void SaveFile(FileMarker fileMarker, IFileDao fileDao, object folder, string filePath, IDataStore storeTemp)
        {
            using var stream = storeTemp.GetReadStream("", filePath);
            var fileName = Path.GetFileName(filePath);
            var file     = ServiceProvider.GetService <File>();

            file.Title         = fileName;
            file.ContentLength = stream.CanSeek ? stream.Length : storeTemp.GetFileSize("", filePath);
            file.FolderID      = folder;
            file.Comment       = FilesCommonResource.CommentCreate;

            stream.Position = 0;
            try
            {
                file = fileDao.SaveFile(file, stream);

                fileMarker.MarkAsNew(file);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
Beispiel #6
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);
        }
Beispiel #7
0
        private static void SaveFile(IFileDao fileDao, object folder, string filePath, IDataStore storeTemp)
        {
            using (var stream = storeTemp.IronReadStream("", filePath, 10))
            {
                var fileName = Path.GetFileName(filePath);
                var file = new File
                    {
                        Title = fileName,
                        ContentLength = stream.Length,
                        FolderID = folder,
                    };
                stream.Position = 0;
                try
                {
                    file = fileDao.SaveFile(file, stream);

                    FileMarker.MarkAsNew(file);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
            }
        }
Beispiel #8
0
 private static void SaveFile(IFileDao fileDao, object folder, string filePath, IDataStore storeTemp)
 {
     using (var stream = storeTemp.IronReadStream("", filePath, 10))
     {
         var fileName = Path.GetFileName(filePath);
         var file = new File
                        {
                            Title = ReplaceInvalidCharsAndTruncate(fileName),
                            ContentLength = stream.Length,
                            ContentType = MimeMapping.GetMimeMapping(fileName),
                            FolderID = folder,
                        };
         stream.Position = 0;
         try
         {
             fileDao.SaveFile(file, stream);
         }
         catch
         {
         }
     }
 }