/// <summary> /// 以目录为单位导入 /// </summary> /// <param name="dto"></param> /// <param name="path"></param> private int ImportCat(DocDto dto, string path) { var qty = 0; var dirs = Directory.GetDirectories(path); if (dirs != null) { var docDao = new DocDao(); foreach (var dir in dirs) { var catDto = new CatImgDto(); catDto.path = dir; catDto.names = Path.GetFileName(dir); catDto.pid = dto.id; docDao.Save(catDto); qty += ImportCat(catDto, path); } } var files = System.IO.Directory.GetFiles(path); qty += ImportImg(dto, files); return(qty); }
/// <summary> /// 执行文件导入 /// </summary> /// <param name="docDao"></param> /// <param name="keyDao"></param> /// <param name="cat"></param> /// <param name="srcFile"></param> /// <returns></returns> private DocDto ImportImg(DocDao docDao, KeyDao keyDao, DocDto cat, string srcFile) { var name = Path.GetFileName(srcFile); var dstFile = DocDto.Combine(cat.FullRelativeFile, name); var docDto = new DocImgDto(); docDto.names = cat.GenDocName(name); docDto.path = dstFile; docDto.pid = cat.id; docDto.Init(_Cfg); var key = DocImgDto.GetFileHash(srcFile); if (string.IsNullOrEmpty(key)) { if (!docDto.ImportFile(srcFile, false)) { return(null); } } var keyDto = keyDao.Read(key); if (keyDto == null) { keyDto = new KeyDto(); keyDto.names = name; keyDto.key = key; keyDto.qty = 1; keyDto.file = dstFile; keyDao.Save(keyDto); if (!docDto.ImportFile(srcFile, false)) { return(null); } } else { keyDto.qty += 1; keyDao.Change(keyDto.id, 1); } docDto.key = keyDto.id; docDao.Save(docDto); return(docDto); }