/// <summary> /// 填充文件比较信息 /// </summary> /// <param name="operation">操作类型</param> /// <param name="serverfile">服务器文件</param> /// <param name="localfile">客户端文件</param> /// <returns>文件比较信息</returns> private static CompareFileEntity FillCompareFileEntity(int operation, FileEntity serverfile, FileEntity localfile) { CompareFileEntity cfEntity = new CompareFileEntity(); cfEntity.FileOpreation = operation;//标示修改 if (serverfile != null) { cfEntity.FileName = serverfile.FileName; cfEntity.FilePath = serverfile.FilePath; cfEntity.ServerCreateTime = serverfile.CreateTime; cfEntity.ServerUpdateTime = serverfile.UpdateTime; cfEntity.ServerHashCode = serverfile.HashCode; cfEntity.ServerFileVersion = serverfile.FileVersion; cfEntity.ServerFileSize = serverfile.FileSize; } if (localfile != null) { cfEntity.FileName = localfile.FileName; cfEntity.FilePath = localfile.FilePath; cfEntity.LocalCreateTime = localfile.CreateTime; cfEntity.LocalUpdateTime = localfile.UpdateTime; cfEntity.LocalHashCode = localfile.HashCode; cfEntity.LocalFileVersion = localfile.FileVersion; cfEntity.LocalFileSize = localfile.FileSize; } return(cfEntity); }
/// <summary> /// 更新单个文件 /// </summary> /// <param name="cfeEntity">文件比较信息</param> /// <param name="temppath">本地临时文件夹</param> /// <param name="path">本地应用文件夹</param> public static void UpdateTempSingleFile(CompareFileEntity cfeEntity, string temppath, string path) { switch (cfeEntity.FileOpreation) { case 1: //添加 CreateDirectory(path + cfeEntity.FilePath); File.Copy(temppath + cfeEntity.FilePath + cfeEntity.FileName, path + cfeEntity.FilePath + cfeEntity.FileName); break; case 0: //更新 DeleteFile(path + cfeEntity.FilePath + cfeEntity.FileName); File.Copy(temppath + cfeEntity.FilePath + cfeEntity.FileName, path + cfeEntity.FilePath + cfeEntity.FileName); break; case -1: //删除 DeleteFile(path + cfeEntity.FilePath + cfeEntity.FileName); break; } }
/// <summary> /// 填充文件比较信息 /// </summary> /// <param name="operation">操作类型</param> /// <param name="serverfile">服务器文件</param> /// <param name="localfile">客户端文件</param> /// <returns>文件比较信息</returns> private static CompareFileEntity FillCompareFileEntity(int operation, FileEntity serverfile, FileEntity localfile) { CompareFileEntity cfEntity = new CompareFileEntity(); cfEntity.FileOpreation = operation;//标示修改 if (serverfile != null) { cfEntity.FileName = serverfile.FileName; cfEntity.FilePath = serverfile.FilePath; cfEntity.ServerCreateTime = serverfile.CreateTime; cfEntity.ServerUpdateTime = serverfile.UpdateTime; cfEntity.ServerHashCode = serverfile.HashCode; cfEntity.ServerFileVersion = serverfile.FileVersion; cfEntity.ServerFileSize = serverfile.FileSize; } if (localfile != null) { cfEntity.FileName = localfile.FileName; cfEntity.FilePath = localfile.FilePath; cfEntity.LocalCreateTime = localfile.CreateTime; cfEntity.LocalUpdateTime = localfile.UpdateTime; cfEntity.LocalHashCode = localfile.HashCode; cfEntity.LocalFileVersion = localfile.FileVersion; cfEntity.LocalFileSize = localfile.FileSize; } return cfEntity; }
/// <summary> /// 更新单个文件 /// </summary> /// <param name="cfeEntity">文件比较信息</param> /// <param name="temppath">本地临时文件夹</param> /// <param name="path">本地应用文件夹</param> public static void UpdateTempSingleFile(CompareFileEntity cfeEntity, string temppath, string path) { switch (cfeEntity.FileOpreation) { case 1://添加 CreateDirectory(path + cfeEntity.FilePath); File.Copy(temppath + cfeEntity.FilePath + cfeEntity.FileName, path + cfeEntity.FilePath + cfeEntity.FileName); break; case 0://更新 DeleteFile(path + cfeEntity.FilePath + cfeEntity.FileName); File.Copy(temppath + cfeEntity.FilePath + cfeEntity.FileName, path + cfeEntity.FilePath + cfeEntity.FileName); break; case -1://删除 DeleteFile(path + cfeEntity.FilePath + cfeEntity.FileName); break; } }