コード例 #1
0
        public FileOperationWraper Get(FileOperationResult o)
        {
            var result = new FileOperationWraper
            {
                Id            = o.Id,
                OperationType = o.OperationType,
                Progress      = o.Progress,
                Error         = o.Error,
                Processed     = o.Processed,
                Finished      = o.Finished
            };

            if (!string.IsNullOrEmpty(o.Result) && result.OperationType != FileOperationType.Delete)
            {
                var arr     = o.Result.Split(':');
                var folders = arr.Where(s => s.StartsWith("folder_")).Select(s => s.Substring(7));
                if (folders.Any())
                {
                    var folderDao = DaoFactory.FolderDao;
                    result.Folders = folderDao.GetFolders(folders.ToArray()).Select(FolderWrapperHelper.Get).ToList();
                }
                var files = arr.Where(s => s.StartsWith("file_")).Select(s => s.Substring(5));
                if (files.Any())
                {
                    var fileDao = DaoFactory.FileDao;
                    result.Files = fileDao.GetFiles(files.ToArray()).Select(FilesWrapperHelper.Get).ToList();
                }

                if (result.OperationType == FileOperationType.Download)
                {
                    result.Url = CommonLinkUtility.GetFullAbsolutePath(o.Result);
                }
            }

            return(result);
        }
コード例 #2
0
        public FileOperationWraper Get(FileOperationResult o)
        {
            var result = new FileOperationWraper
            {
                Id            = o.Id,
                OperationType = o.OperationType,
                Progress      = o.Progress,
                Error         = o.Error,
                Processed     = o.Processed,
                Finished      = o.Finished
            };

            if (!string.IsNullOrEmpty(o.Result) && result.OperationType != FileOperationType.Delete)
            {
                var arr     = o.Result.Split(':');
                var folders = arr
                              .Where(s => s.StartsWith("folder_"))
                              .Select(s => s.Substring(7));

                if (folders.Any())
                {
                    var fInt    = new List <int>();
                    var fString = new List <string>();

                    foreach (var folder in folders)
                    {
                        if (int.TryParse(folder, out var f))
                        {
                            fInt.Add(f);
                        }
                        else
                        {
                            fString.Add(folder);
                        }
                    }

                    result.Folders = GetFolders(folders).ToList();
                    result.Folders.AddRange(GetFolders(fInt));
                }
                var files = arr
                            .Where(s => s.StartsWith("file_"))
                            .Select(s => s.Substring(5));

                if (files.Any())
                {
                    var fInt    = new List <int>();
                    var fString = new List <string>();

                    foreach (var file in files)
                    {
                        if (int.TryParse(file, out var f))
                        {
                            fInt.Add(f);
                        }
                        else
                        {
                            fString.Add(file);
                        }
                    }

                    result.Files = GetFiles(fString).ToList();
                    result.Files.AddRange(GetFiles(fInt));
                }

                if (result.OperationType == FileOperationType.Download)
                {
                    result.Url = CommonLinkUtility.GetFullAbsolutePath(o.Result);
                }
            }

            return(result);

            IEnumerable <FileEntryWrapper> GetFolders <T>(IEnumerable <T> folders)
            {
                var folderDao = DaoFactory.GetFolderDao <T>();

                return(folderDao.GetFolders(folders.ToArray())
                       .Select(FolderWrapperHelper.Get)
                       .Cast <FileEntryWrapper>());
            }

            IEnumerable <FileEntryWrapper> GetFiles <T>(IEnumerable <T> files)
            {
                var fileDao = DaoFactory.GetFileDao <T>();

                return(fileDao.GetFiles(files.ToArray())
                       .Select(FilesWrapperHelper.Get)
                       .Cast <FileEntryWrapper>());
            }
        }