public bool PushDir(DirectoryInfo localDir, List <FileInfoWithPatchOptions> patchFiles, string remotePath, string linkPath, bool isDMFR) { VSSItem remoteDir = VSSDB.get_VSSItem(remotePath); VSSItem linkRootDir = VSSDB.get_VSSItem(linkPath); foreach (VSSItem item in linkRootDir.Items) { if (item.Type == 0 && item.Name.Equals(localDir.Name, StringComparison.InvariantCultureIgnoreCase)) { item.Destroy(); sender($"{item.Spec} найдена в {linkRootDir.Spec} и удалена!"); break; } } VSSItem linkDir = linkRootDir.NewSubproject(localDir.Name); sender($"{linkDir.Spec} создана в {linkRootDir.Spec}"); string dbScriptsRep = Properties.Settings.Default.ScriptsSubdir; string infaRep = Properties.Settings.Default.InfaSubdir; string repDir = Properties.Settings.Default.RemoteRoot; string mask; string[] patchRootDirs; List <string> patchesToFindObject = new List <string>(); bool patchSearchCompleted = false; foreach (FileInfoWithPatchOptions fi in patchFiles) { string fromPatchPath = fi.FileInfo.Directory.FullName.Substring(localDir.FullName.Length); string[] dirs = fromPatchPath.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); sender($"Создаем папки, если их нет: { string.Join(",", dirs) }"); bool found; IVSSItem currDir = linkDir; if (fi.AddToPatch) { foreach (string dir in dirs) { found = false; foreach (VSSItem currSubDir in currDir.Items) { if (currSubDir.Type == 0 && currSubDir.Name.Equals(dir, StringComparison.InvariantCultureIgnoreCase)) { found = true; sender($"{currSubDir.Spec} найдена в {currDir.Spec}"); break; } } if (!found) { string prevDir = currDir.Spec; currDir = currDir.NewSubproject(dir); sender($"{currDir.Spec} создана в {prevDir}"); } } } if (fi.AddInRepDir) { string sourceFolder; string repsubdir; //если это скрипт if (fi.FileInfo.Extension.Equals(".sql", StringComparison.InvariantCultureIgnoreCase)) { sender($"Ищем в {fi.FileInfo.FullName} по шаблону {dbScriptsRep}\\\\([^\\\\]+)"); sourceFolder = Regex.Match(fi.FileInfo.FullName, $"{dbScriptsRep}\\\\([^\\\\]+)").Groups[1].Value; repsubdir = dbScriptsRep; } else { sender($"Ищем в {fi.FileInfo.FullName} по шаблону {infaRep}\\\\([^\\\\]+)"); sourceFolder = Regex.Match(fi.FileInfo.FullName, $"{infaRep}\\\\([^\\\\]+)").Groups[1].Value; repsubdir = infaRep; } sender($"Ищем в папке {sourceFolder}"); if (FirstInEntireBase($"{repDir}/{repsubdir}/{sourceFolder}", fi.FileInfo.Name, -1, false, out string match)) { IVSSItem repItem = VSSDB.get_VSSItem(match); CreateLink(repItem, currDir); } else { if (!patchSearchCompleted) { if (isDMFR) { mask = Properties.Settings.Default.DMFRSubstring; patchRootDirs = Properties.Settings.Default.PatchesRootDirDMFR.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); } else { mask = Properties.Settings.Default.DWH4DMSubstring; patchRootDirs = Properties.Settings.Default.PatchesRootDirDWH4DM.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); } sender($"Ищем {mask} в { string.Join(",", patchRootDirs) }"); foreach (string root in patchRootDirs) { try { foreach (string patch in AllInEntireBase(root, mask, true, -1)) { patchesToFindObject.Add(patch); } } catch { } } patchSearchCompleted = true; } sender($"Ищем {fi.FileInfo.Name} в патчах"); foreach (string root in patchesToFindObject) { if (FirstInEntireBase(root, fi.FileInfo.Name, -1, false, out string prevVersion)) { IVSSItem prevItem = VSSDB.get_VSSItem(prevVersion); CreateLink(prevItem, currDir); break; } } } } PushFile(currDir.Spec, fi.FileInfo.Directory.FullName, fi.FileInfo.Name, localDir.Name, out VSSItem item); } return(true); }
/// <summary> /// 根据vss的绝对路径创建一个Folder /// </summary> /// <param name="absoluteVssPath"></param> /// <param name="comment"></param> public void NewProject(string absoluteVssPath, string comment) { //string vssFolder = @"$/LIS-CM-AB/05-项目任务/B-契约模块/ABLREQUEST-1396-团险添加投保率不足0.75的控制提示/test"; string vssFolder = @"$";//根目录 string[] dir = absoluteVssPath.Split('/'); IVSSDatabase vssDatabase = new VSSDatabase(); vssDatabase.Open(this.srcSafeIni, this.username, this.password); IVSSItem vssParentFolder = null;// = vssDatabase.get_VSSItem(vssFolder, false); bool existProject = false; for (int i = 1; i < dir.Length; i++) { vssFolder += @"/" + dir[i]; //暂时使用异常来判断是否存在,之后优化 try { vssParentFolder = vssDatabase.get_VSSItem(vssFolder, false); existProject = true; } catch (Exception e) { Console.WriteLine(e.Message); existProject = false; } if (!existProject) //不存在 { IVSSItem vssChildFolder = vssParentFolder.NewSubproject(dir[i], comment); vssParentFolder = vssChildFolder; } } }
/// <summary> /// /// </summary> public void NewProject(string foldName, string vssParentPath, string comment) { // Create a VSSDatabase object. IVSSDatabase vssDatabase = new VSSDatabase(); // Open a VSS database using network name // for automatic user login. vssDatabase.Open(this.srcSafeIni, this.username, this.password); IVSSItem vssParentFolder = vssDatabase.get_VSSItem(vssParentPath, false); DisplayFolder(vssParentFolder); // Create folder C in folder A. Console.WriteLine("- Creating folder C in folder A"); IVSSItem vssChildFolder = vssParentFolder.NewSubproject(foldName, comment); DisplayFolder(vssParentFolder); //// Remove folder C from folder A. //Console.WriteLine("- Remove folder C from folder A"); //vssChildFolder.Destroy(); //DisplayFolder(vssParentFolder); }
/// <summary> /// Create project hierarchy in vss /// </summary> /// <param name="file"></param> /// <returns></returns> protected IVSSItem CreateProjectPath(string file) { if (file.StartsWith(AddFileSet.BaseDirectory.FullName)) { FileInfo fi = new FileInfo(file); // Get file path relative to fileset base directory string relativePath = file.Replace(AddFileSet.BaseDirectory.FullName, "").Replace('/', '\\'); // Split path into its component parts; the last part is the filename itself string[] projects = relativePath.Split('\\'); // Now create any requisite subdirectories, if they don't already exist IVSSItem currentItem = null; string oldPath = Path; // Trim final "/" if present (not strictly required) if (oldPath.EndsWith("/")) { oldPath = oldPath.Substring(0, oldPath.Length - 1); } for (int i = 0; i < projects.Length - 1; i++) { currentItem = null; string newPath = oldPath + "/" + projects[i]; try { // Try to retrieve the VSS directory currentItem = Database.get_VSSItem(newPath, false); } catch { // Create it if it doesn't exist currentItem = Database.get_VSSItem(oldPath, false); currentItem = currentItem.NewSubproject(projects[i], "NAntContrib vssadd"); Log(Level.Info, "Adding VSS Project : " + newPath); } oldPath = newPath; } return(currentItem); } else { return(null); } }