/// <summary> /// 删除项目数据 /// </summary> /// <param name="datArray">项目数据标志队列集合</param> /// <param name="memo">变更备忘</param> /// <remarks>[TODO:Practice]</remarks> public void Delete(ProjectDataID[] datArray, string memo) { if (datArray == null || datArray.Length < 1) { return; } int total = datArray.Length; ProjectDataID CommonData = datArray[0]; ProjectRepository repos = new ProjectRepository() { RepositoryId = CommonData.RepositoryId }; List <string> ListDel = new List <string>(); string ReversionID = repos.GetNextReversionID(); string datDir = string.Concat(RootDirName, "\\", repos.RepositoryId, "\\", "dat", "\\"); string logDir = string.Concat(RootDirName, "\\", repos.RepositoryId, "\\", "log", "\\"); string fsvnFile = string.Empty; for (int i = 0; i < total; i++) { if (!Exists(repos.RepositoryId, datArray[i].IdentityName)) { //Console.WriteLine("{0} 在版本库中不存在!", datArray[i].IdentityName); //continue; throw new NotExistRepositoryItemException(string.Format("{0} 在版本库中不存在!", datArray[i].IdentityName)); } ListDel.Add(datArray[i].IdentityName); fsvnFile = datDir + datArray[i].IdentityName.Replace('/', '\\') + ".fsvn"; //文件删除 if (File.Exists(fsvnFile)) { byte[] fileDat = File.ReadAllBytes(fsvnFile); ProjectData oldData = fileDat.GetObject <ProjectData>(); //备份 File.WriteAllBytes(fsvnFile + ".r" + oldData.Reversion, fileDat); string targetDir = GetSubDirByType(repos.RepositoryId, RepositoryDirectory.Delete) + "\\rev" + oldData.Reversion; targetDir = Path.Combine(RootDirName, repos.RepositoryId + "\\" + targetDir); if (!Directory.Exists(targetDir)) { Directory.CreateDirectory(targetDir); } #region 移动文件 [fsvnFile].r* DirectoryInfo movDir = new DirectoryInfo(Path.GetDirectoryName(fsvnFile)); foreach (FileInfo rf in movDir.GetFiles(Path.GetFileName(fsvnFile) + ".r*")) { rf.MoveTo(targetDir + "\\" + rf.Name); Console.WriteLine("移动文件:{0} -> {1} ", rf.FullName, targetDir + "\\" + rf.Name); } #endregion //删除 File.Delete(fsvnFile); } else { //目录删除 (.del) string oldDir = datDir + datArray[i].IdentityName.Replace('/', '\\'); string delDir = GetSubDirByType(repos.RepositoryId, RepositoryDirectory.Delete) + "\\rev" + repos.Reversion; //TODO:记录目录的版本号 delDir += datArray[i].GetParentName(); delDir = Path.Combine(RootDirName, repos.RepositoryId + "\\" + delDir); Console.WriteLine("创建目录:{0}", delDir); Console.WriteLine("移动目录:{0} -> {1} ", oldDir, delDir + "\\" + datArray[i].GetName()); if (!Directory.Exists(delDir)) { Directory.CreateDirectory(delDir); } Directory.Move(oldDir, delDir + "\\" + datArray[i].GetName()); } //更新目录下的 .fsvn文件 Console.WriteLine("正在删除:{0}", datArray[i].IdentityName); } #region 变更日志 List <ChangeAction> cActs = new List <ChangeAction>(); if (ListDel.Count > 0) { cActs.Add(new DeleteAction { IdentityNames = ListDel.ToArray() }); } ChangeLog log = new ChangeLog(); log.Author = "ridge"; log.Message = memo; log.RepositoryId = repos.RepositoryId; log.ReversionId = ReversionID; log.Summary = cActs.ToArray().GetBytes(); File.WriteAllBytes(Path.Combine(logDir, "Rev" + log.ReversionId + ".dat"), log.GetBytes()); #endregion }
/// <summary> /// 移动(重命名)的项目数据对列 /// </summary> /// <param name="removArray">项目数据变更标识集</param> /// <param name="memo">操作备忘</param> /// <remarks>[TODO]</remarks> public void Remove(DataMoveAction[] removArray, string memo) { if (removArray == null || removArray.Length < 1) { return; } int total = removArray.Length; DataMoveAction CommonData = removArray[0]; ProjectRepository repos = new ProjectRepository() { RepositoryId = CommonData.RepositoryId }; List <string> listRemove = new List <string>(); List <string> listTarget = new List <string>(); string ReversionID = repos.GetNextReversionID(); string datDir = string.Concat(RootDirName, "\\", repos.RepositoryId, "\\", "dat", "\\"); string logDir = string.Concat(RootDirName, "\\", repos.RepositoryId, "\\", "log", "\\"); string fsvnFile = string.Empty; List <DataMoveAction> fMoveList = new List <DataMoveAction>(); List <DataMoveAction> fRenameList = new List <DataMoveAction>(); List <DataMoveAction> dMoveList = new List <DataMoveAction>(); List <DataMoveAction> dRenameList = new List <DataMoveAction>(); for (int i = 0; i < total; i++) { if (!Exists(repos.RepositoryId, removArray[i].IdentityName)) { throw new NotExistRepositoryItemException(string.Format("{0} 在版本库中不存在!", removArray[i].IdentityName)); } listRemove.Add(removArray[i].IdentityName); listTarget.Add(removArray[i].NewIdentityName); fsvnFile = datDir + removArray[i].IdentityName.Replace('/', '\\') + ".fsvn"; //移动目录 if (File.Exists(fsvnFile)) { string nFsvnFile = datDir + removArray[i].NewIdentityName.Replace('/', '\\') + ".fsvn"; #region 文件移动 if (removArray[i].IsSameParent()) { //重命名 fRenameList.Add(removArray[i]); } else { //目标库不存在则自动创建 fMoveList.Add(removArray[i]); ProjectDataID nId = new ProjectDataID { IdentityName = removArray[i].NewIdentityName, RepositoryId = repos.RepositoryId }; string parentIdName = nId.GetParentName(); if (parentIdName != string.Empty && !Exists(repos.RepositoryId, parentIdName)) { //完善默认数据值获取 ProjectData dDat = new ProjectData() { IncludeBinary = false, CreateDateTimeUTC = DateTime.Now.ToUniversalTime(), IdentityName = parentIdName }; Store(new ProjectData[] { dDat }, "[AUTO CREATE]"); } } #endregion File.Move(fsvnFile, nFsvnFile); } else { #region 目录移动 (.mov) if (removArray[i].IsSameParent()) { //重命名 dRenameList.Add(removArray[i]); } else { dMoveList.Add(removArray[i]); } string oldDir = datDir + removArray[i].IdentityName.Replace('/', '\\'); string newDir = datDir + removArray[i].NewIdentityName.Replace('/', '\\'); if (!Directory.Exists(newDir)) { Directory.CreateDirectory(newDir); } Directory.Move(oldDir, newDir); #endregion } //更新目录下的 .fsvn文件 Console.WriteLine("正在移动:{0}-{1}", removArray[i].IdentityName, removArray[i].NewIdentityName); } #region 变更存储 string targetDir = GetSubDirByType(repos.RepositoryId, RepositoryDirectory.Move) + "\\rev" + ReversionID; targetDir = Path.Combine(RootDirName, repos.RepositoryId + "\\" + targetDir); if (!Directory.Exists(targetDir)) { Directory.CreateDirectory(targetDir); } if (fRenameList.Count > 0) { File.WriteAllBytes(targetDir + "\\FileRename.fsvn", fRenameList.ToArray().GetBytes()); } if (fMoveList.Count > 0) { File.WriteAllBytes(targetDir + "\\FileMove.fsvn", fMoveList.ToArray().GetBytes()); } if (dRenameList.Count > 0) { File.WriteAllBytes(targetDir + "\\DirRename.fsvn", dRenameList.ToArray().GetBytes()); } if (dMoveList.Count > 0) { File.WriteAllBytes(targetDir + "\\DirMove.fsvn", dMoveList.ToArray().GetBytes()); } #endregion #region 变更日志 List <ChangeAction> cActs = new List <ChangeAction>(); if (listRemove.Count > 0) { cActs.Add(new MoveAction { IdentityNames = listRemove.ToArray(), TargetIdentityNames = listTarget.ToArray() }); } ChangeLog log = new ChangeLog(); log.Author = "ridge"; log.Message = memo; log.RepositoryId = repos.RepositoryId; log.ReversionId = ReversionID; log.Summary = cActs.ToArray().GetBytes(); File.WriteAllBytes(Path.Combine(logDir, "Rev" + log.ReversionId + ".dat"), log.GetBytes()); #endregion }
/// <summary> /// 存储项目数据 /// </summary> /// <param name="datArray">项目数据队列集合</param> /// <param name="memo">变更备忘</param> public void Store(ProjectData[] datArray, string memo) { if (datArray == null || datArray.Length < 1) { return; } /* * 1.存储目录 * 2.存储文件名 * 3.存储数据 * 4.设置创建、修改日期 * 5.记录变更日志 */ List <string> ListAdd = new List <string>(); List <string> ListUpdate = new List <string>(); int total = datArray.Length; ProjectData CommonData = datArray[0]; ProjectRepository repos = new ProjectRepository() { RepositoryId = CommonData.RepositoryId }; string ReversionID = repos.GetNextReversionID(); string datDir = string.Concat(RootDirName, "\\", repos.RepositoryId, "\\", "dat", "\\"); string logDir = string.Concat(RootDirName, "\\", repos.RepositoryId, "\\", "log", "\\"); string fsvnFile = string.Empty; for (int i = 0; i < total; i++) { #region 循环项目数据 if (datArray[i].IncludeBinary) { //文件 fsvnFile = datDir + datArray[i].IdentityName.Replace('/', '\\') + ".fsvn"; } else { //目录 string tarDir = Path.Combine(datDir, datArray[i].IdentityName.Replace('/', '\\')); if (!Directory.Exists(tarDir)) { Directory.CreateDirectory(tarDir); } fsvnFile = tarDir + "\\.fsvn"; } datArray[i].Reversion = ReversionID; //添加、修改 if (File.Exists(fsvnFile)) { byte[] fileDat = File.ReadAllBytes(fsvnFile); ProjectData oldData = fileDat.GetObject <ProjectData>(); datArray[i].LastModifiedVersion = oldData.Reversion; //备份 File.WriteAllBytes(fsvnFile + ".r" + oldData.Reversion, fileDat); ListAdd.Add(datArray[i].IdentityName); } else { datArray[i].LastModifiedVersion = ReversionID; ListUpdate.Add(datArray[i].IdentityName); } File.WriteAllBytes(fsvnFile, datArray[i].GetBytes()); Console.WriteLine("正在提交:{0}", datArray[i].IdentityName); #endregion } #region 变更日志 List <ChangeAction> cActs = new List <ChangeAction>(); if (ListAdd.Count > 0) { cActs.Add(new AddAction { IdentityNames = ListAdd.ToArray() }); } if (ListUpdate.Count > 0) { cActs.Add(new UpdateAction { IdentityNames = ListUpdate.ToArray() }); } ChangeLog log = new ChangeLog(); log.Author = CommonData.Author; log.Message = memo; log.RepositoryId = repos.RepositoryId; log.ReversionId = ReversionID; log.Summary = cActs.ToArray().GetBytes(); File.WriteAllBytes(Path.Combine(logDir, "Rev" + log.ReversionId + ".dat"), log.GetBytes()); #endregion }