Example #1
0
        //Long operation
        public static void DeleteSubitems(object parentId, IFolderDao folderDao, IFileDao fileDao)
        {
            var folders = folderDao.GetFolders(parentId);

            foreach (var folder in folders)
            {
                DeleteSubitems(folder.ID, folderDao, fileDao);
                folderDao.DeleteFolder(folder.ID);
            }

            var files = fileDao.GetFiles(parentId, null, FilterType.None, Guid.Empty, string.Empty);

            foreach (var file in files)
            {
                fileDao.DeleteFile(file.ID);
            }
        }
        //Long operation
        public static void DeleteSubitems(object parentId, IFolderDao folderDao, IFileDao fileDao)
        {
            var folders = folderDao.GetFolders(parentId);

            foreach (var folder in folders)
            {
                DeleteSubitems(folder.ID, folderDao, fileDao);

                Global.Logger.InfoFormat("Delete folder {0} in {1}", folder.ID, parentId);
                folderDao.DeleteFolder(folder.ID);
            }

            var files = fileDao.GetFiles(parentId, null, FilterType.None, false, Guid.Empty, string.Empty, true);

            foreach (var file in files)
            {
                Global.Logger.InfoFormat("Delete file {0} in {1}", file.ID, parentId);
                fileDao.DeleteFile(file.ID);
            }
        }
Example #3
0
        public bool Delete(string id)
        {
            int rightId;

            if (Int32.TryParse(id, out rightId))
            {
                if (GetFileById(rightId) != null)
                {
                    _fileDao.DeleteFile(rightId);

                    return(true);
                }
                else
                {
                    Console.WriteLine("Can't find file");
                    return(false);
                }
            }
            else
            {
                Console.WriteLine("Incorrect ID (not number)");
                return(false);
            }
        }
Example #4
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);
        }
Example #5
0
 public void DeleteFile(string query, string title, DateTime date, int id)
 {
     _fileDao.DeleteFile(query, title, date, id);
 }