public void DoModifyFileOperations(string rootPathName, MaterialFileOeprationInfo fileOp, MaterialContent content) { string uploadRootPath = AppPathConfigSettings.GetConfig().Paths[rootPathName].Dir; ExceptionHelper.CheckStringIsNullOrEmpty(uploadRootPath, "uploadRootPath"); IMaterialContentPersistManager persistManager = GetMaterialContentPersistManager(rootPathName, fileOp); if (content == null) { content = fileOp.Material.GenerateMaterialContent(); } switch (fileOp.Operation) { case FileOperation.Add: case FileOperation.Update: persistManager.SaveMaterialContent(content); break; case FileOperation.Delete: persistManager.DeleteMaterialContent(content); break; default: break; } }
/// <summary> /// 复制文件 /// </summary> /// <param name="materials">文件集合</param> /// <param name="sourceRootPathName">源文件的主路径的配置节点名称</param> /// <param name="destRootPathName">目标文件的主路径的配置节点名称</param> /// <param name="copyFromTempFolder">是否从临时文件夹拷贝文件</param> private static void DoFilesCopy(MaterialList materials, string sourceRootPathName, string destRootPathName, bool copyFromTempFolder) { string sourceRootPath = AppPathConfigSettings.GetConfig().Paths[sourceRootPathName].Dir; string destRootPath = AppPathConfigSettings.GetConfig().Paths[destRootPathName].Dir; ExceptionHelper.CheckStringIsNullOrEmpty(sourceRootPath, "sourceRootPath"); ExceptionHelper.CheckStringIsNullOrEmpty(destRootPath, "destRootPath"); foreach (Material material in materials) { ExceptionHelper.TrueThrow <ArgumentNullException>(material.SourceMaterial == null, "material.SourceMaterial"); FileInfo sourceFile; if (copyFromTempFolder) { sourceFile = new FileInfo(sourceRootPath + @"Temp\" + Path.GetFileName(material.SourceMaterial.RelativeFilePath)); } else { sourceFile = new FileInfo(sourceRootPath + material.SourceMaterial.RelativeFilePath); } if (sourceFile.Exists) { FileInfo destFile = new FileInfo(destRootPath + material.RelativeFilePath); DoFileCopy(sourceFile, destFile); } } }
public static void DoFilesCopy(MaterialList materials, string sourceRootPathName, string destRootPathName) { string sourceRootPath = AppPathConfigSettings.GetConfig().Paths[sourceRootPathName].Dir; string destRootPath = AppPathConfigSettings.GetConfig().Paths[destRootPathName].Dir; ExceptionHelper.CheckStringIsNullOrEmpty(sourceRootPath, "sourceRootPath"); ExceptionHelper.CheckStringIsNullOrEmpty(destRootPath, "destRootPath"); foreach (Material material in materials) { FileInfo sourceFile = new FileInfo(sourceRootPath + material.RelativeFilePath); if (sourceFile.Exists == false) { sourceFile = new FileInfo(sourceRootPath + @"Temp\" + Path.GetFileName(material.RelativeFilePath)); } if (sourceFile.Exists) { FileInfo destFile = new FileInfo(Path.Combine(destRootPath, Path.GetFileName(material.RelativeFilePath))); DoFileCopy(sourceFile, destFile); } } }
/// <summary> /// 获得路径配置信息 /// </summary> /// <returns>路径配置信息</returns> public static AppPathConfigSettings GetConfig() { AppPathConfigSettings result = (AppPathConfigSettings)ConfigurationBroker.GetSection(AppPathConfigName); ConfigurationExceptionHelper.CheckSectionNotNull(result, AppPathConfigName); return(result); }
/// <summary> /// 得到附件的物理路径 /// </summary> /// <returns></returns> public string GetTempPhysicalFilePath(string rootPathName) { if (string.IsNullOrEmpty(rootPathName)) { rootPathName = MaterialAdapter.DefaultUploadPathName; } string uploadRootPath = AppPathConfigSettings.GetConfig().Paths[rootPathName].Dir; ExceptionHelper.CheckStringIsNullOrEmpty(uploadRootPath, "uploadRootPath"); FileInfo sourceFile = new FileInfo(uploadRootPath + @"Temp\" + Path.GetFileName(this.RelativeFilePath)); return(sourceFile.FullName); }
private static IMaterialContentPersistManager GetMaterialContentPersistManager(string rootPathName, MaterialFileOeprationInfo fileOp) { string uploadRootPath = AppPathConfigSettings.GetConfig().Paths[rootPathName].Dir; FileInfo sourceFile = new FileInfo(uploadRootPath + @"Temp\" + Path.GetFileName(fileOp.Material.RelativeFilePath)); FileInfo destFile = new FileInfo(uploadRootPath + fileOp.Material.RelativeFilePath); IMaterialContentPersistManager persistManager = MaterialContentSettings.GetConfig().PersistManager; persistManager.SourceFileInfo = sourceFile; persistManager.DestFileInfo = destFile; if (fileOp.Operation == FileOperation.Update) { persistManager.CheckSourceFileExists = false; } return(persistManager); }