/// <summary> /// 初始化各个文件夹 /// </summary> /// <param name="parentForder"></param> private static void GetAllForders(Model.ForderModel parentForder, int projectId) { if (parentForder == null) { return; } parentForder.SubForders = new List <Model.ForderModel>(); parentForder.Files = new List <Model.FileModel>(); BLL.ForderBll forderBll = new ForderBll(); List <Model.FileModel> rootFiles = forderBll.GetSubFiles(parentForder.ID, projectId, string.Empty); parentForder.Files.AddRange(rootFiles); List <Model.ForderModel> rootForders = forderBll.GetSubForders(parentForder.ID, projectId); if (rootForders != null) { foreach (var item in rootForders) { GetAllForders(item, 0); } } }
/// <summary> /// 递归检查文件夹和文件 /// </summary> /// <param name="dirInfo"></param> /// <param name="parentId"></param> /// <param name="user"></param> private void CheckFolderDownloadAllFromDb_OtherUser(DirectoryInfo dirInfo, int parentId, string userName, int projectId) { //开始从文件夹获取子文件夹和文件列表 ForderBll forderBll = new ForderBll(); FileBll fileBll = new FileBll(); var subFiles = forderBll.GetSubFiles(parentId, projectId, string.Empty); var files = subFiles; //文件下载 foreach (var item in files) { Application.DoEvents(); var verModel = fileBll.GetFileLastVer(item.ID); if (verModel == null || verModel.Ver <= 0) { continue; } string fileClientPath = string.Format("{0}\\{1}", dirInfo.FullName, item.File_Name); FileInfo clientFileInfo = new FileInfo(fileClientPath); item.ActionNum = 1; AddFileToCache(fileClientPath, item); AddNeedAllDownloadFilesToCache(fileClientPath, item); } var subForders = forderBll.GetSubForders(parentId, projectId); if (subForders != null && subForders.Count > 0) { foreach (var item in subForders) { Application.DoEvents(); string forderPath = string.Format("{0}\\{1}", dirInfo.FullName, item.Title); //文件夹不存在,全部新增 List <Model.FileModel> fileLists = GetAllServerFiles_OtherUser(item); foreach (var subFileItem in fileLists) { AddFileToCache(subFileItem.ClientPath, subFileItem); AddNeedAllUploadFilesToCache(subFileItem.ClientPath, subFileItem); } DirectoryInfo dirItemInfo = new DirectoryInfo(forderPath); //判断文件夹操作 CheckFolderDownloadAllFromDb_OtherUser(dirItemInfo, item.ID, userName, projectId); } } }
/// <summary> /// 获取文件夹下所有文件为对象格式 /// </summary> /// <param name="forderInfo"></param> /// <returns></returns> private List <Model.FileModel> GetAllServerFiles_OtherUser(Model.ForderModel forderInfo) { List <Model.FileModel> fileModels = new List <Model.FileModel>(); ForderBll forderBll = new ForderBll(); var subFiles = forderBll.GetSubFiles(forderInfo.ID, forderInfo.Project_Id, string.Empty); fileModels.AddRange(subFiles); var suvDirs = forderBll.GetSubForders(forderInfo.ID, forderInfo.Project_Id); if (suvDirs != null && suvDirs.Count > 0) { foreach (var item in suvDirs) { fileModels.AddRange(GetAllServerFiles_OtherUser(item)); } } return(fileModels); }
/// <summary> /// 递归检查文件夹和文件 /// </summary> /// <param name="dirInfo"></param> /// <param name="parentId"></param> /// <param name="user"></param> private void CheckFolderDownloadAllFromDb(DirectoryInfo dirInfo, int parentId, string userName, int projectId) { //开始从文件夹获取子文件夹和文件列表 ForderBll forderBll = new ForderBll(); FileBll fileBll = new FileBll(); var subFiles = forderBll.GetSubFiles(parentId, projectId, string.Empty); var files = subFiles; //文件下载 foreach (var item in files) { Application.DoEvents(); var verModel = fileBll.GetFileLastVer(item.ID); if (verModel == null || verModel.Ver <= 0) { continue; } string fileClientPath = string.Format("{0}\\{1}", dirInfo.FullName, item.File_Name); FileInfo clientFileInfo = new FileInfo(fileClientPath); if (clientFileInfo.Exists) { if (clientFileInfo.LastAccessTime.Ticks == verModel.File_Modify_Time) { continue; } } //if (clientFileInfo.Exists && clientFileInfo.LastAccessTime.Ticks == item.File_Modify_Time) //{ // continue; //} if (clientFileInfo.Exists) { item.ActionNum = 2; if (verModel.File_Modify_Time == clientFileInfo.LastWriteTime.Ticks) { continue; } AddFileToCache(fileClientPath, item); //服务器文件最新 if (verModel.File_Modify_Time > clientFileInfo.LastWriteTime.Ticks) { AddNeedAllDownloadFilesToCache(fileClientPath, item); } } else { item.ActionNum = 1; AddFileToCache(fileClientPath, item); AddNeedAllDownloadFilesToCache(fileClientPath, item); } } var subForders = forderBll.GetSubForders(parentId, projectId); if (subForders != null && subForders.Count > 0) { foreach (var item in subForders) { Application.DoEvents(); string forderPath = string.Format("{0}\\{1}", dirInfo.FullName, item.Title); if (!Directory.Exists(forderPath)) { //文件夹不存在,全部新增 List <Model.FileModel> fileLists = GetAllServerFiles(item); foreach (var subFileItem in fileLists) { AddFileToCache(subFileItem.ClientPath, subFileItem); AddNeedAllUploadFilesToCache(subFileItem.ClientPath, subFileItem); } //Directory.CreateDirectory(forderPath); } DirectoryInfo dirItemInfo = new DirectoryInfo(forderPath); //判断文件夹操作 CheckFolderDownloadAllFromDb(dirItemInfo, item.ID, userName, projectId); } } }