public void SyncAllBuilds() { string mainlineFolder = string.Format(@"{0}\SUP_Main", localMapFolder); foreach (string d in Directory.GetDirectories(mainlineFolder, buildPattern)) { if (!d.Contains("BAD")) { DirectoryInfo info = new System.IO.DirectoryInfo(d); DirectoryInfo remoteInfo = new System.IO.DirectoryInfo(d.Replace(localMapFolder, path)); string branchName = System.Text.RegularExpressions.Regex.Split(info.Name, @"_[0-9]\.[0-9][0-9]\.[0-9]+")[0]; string releaseAndNumber = System.Text.RegularExpressions.Regex.Match(info.Name, @"[0-9]\.[0-9][0-9]\.[0-9]+").Value; string number = releaseAndNumber.Substring(releaseAndNumber.LastIndexOf('.') + 1); string releaseName = releaseAndNumber.Substring(0, releaseAndNumber.LastIndexOf('.')); Branch tempBranch = new Branch { Name = branchName, Path = string.Empty, Description = branchName, Type = (int)SyncSourceType.FromBuildServer, ProductId = Product.GetProductByName(productName).ProductId, }; Branch branch = Branch.AddOrUpdateBranch(tempBranch); Release tempRelease = new Release { Name = releaseName, Description = releaseName, Type = (int)SyncSourceType.FromBuildServer, Path = string.Empty, ProductId = Product.GetProductByName(productName).ProductId, }; Release release = Release.AddOrUpdateRelease(tempRelease); if (IsBuildFinished(info)) { Build b = new Build { Name = info.Name, Description = info.Name, Location = remoteInfo.FullName, BranchId = branch.BranchId, ReleaseId = release.ReleaseId, Number = number, BuildType = BuildType.BuildMachine, ProductId = Product.GetProductByName(productName).ProductId, BuildStatus = BuildStatus.Success, ProviderId = Provider.ProviderId, }; if (null == Build.GetBuildByLocation(b.Location)) { Build.Add(b); } } } } }
public static Branch AddOrUpdateBranch(Branch branch) { using (ES1AutomationEntities context = new ES1AutomationEntities()) { Branch existingBranch = context.Branches.Where(b => b.Name.ToLower() == branch.Name.ToLower() && b.Type==branch.Type && b.ProductId==branch.ProductId).FirstOrDefault(); if (existingBranch != null) { existingBranch.Description = branch.Description; existingBranch.Path = branch.Path; context.Entry(existingBranch).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); return existingBranch; } else { Branch b = context.Branches.Add(branch); context.SaveChanges(); return b; } } }
private void getBuildsInFolder(IList<Build> builds, string rootFolder, string branchFolder, System.Text.RegularExpressions.Regex buildFolderPattern) { foreach (string d in System.IO.Directory.GetDirectories(rootFolder)) { System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(d); string buildName = info.Name; if (buildFolderPattern.IsMatch(buildName)) { string releaseName = buildName.Substring(0, buildName.LastIndexOf('.')); string number = info.Name.Substring(buildName.LastIndexOf('.') + 1); System.IO.DirectoryInfo remoteInfo = new System.IO.DirectoryInfo(d.Replace(localMapFolder, Path)); Branch tempBranch = new Branch { Name = branchFolder, Path = string.Empty, Description = branchFolder, Type = (int)SyncSourceType.FromBuildServer, ProductId = Product.GetProductByName(ProductName).ProductId, }; Branch branch = Branch.AddOrUpdateBranch(tempBranch); Release tempRelease = new Release { Name = releaseName, Description = releaseName, Type = (int)SyncSourceType.FromBuildServer, Path = string.Empty, ProductId = Product.GetProductByName(ProductName).ProductId, }; Release release = Release.AddOrUpdateRelease(tempRelease); if (IsBuildFinished(info)) { Build b = new Build { Name = info.Name, Description = info.Name, Location = remoteInfo.FullName, BranchId = branch.BranchId, ReleaseId = release.ReleaseId, Number = number, BuildType = BuildType.BuildMachine, ProductId = Product.GetProductByName("Common Index Search").ProductId, BuildStatus = BuildStatus.Success, }; builds.Add(b); } } else { string tempBranchFolder = string.IsNullOrEmpty(branchFolder) ? info.Name : branchFolder + @"\" + info.Name; getBuildsInFolder(builds, d, tempBranchFolder, buildFolderPattern); } } }
public IList<Build> GetAllBuildsOnBuildFileServer() { List<Build> builds = new List<Build>(); //update SourceOne builds const string BuildFolderIndexName = "PATH"; const string BuildPatternIndexName="PATTERN"; const string BuildBranchIndexName = "BRANCH"; List<Dictionary<string, string>> buildFoldersList = new List<Dictionary<string, string>>(); string es1Main = System.IO.Path.Combine(localMapFolder + @"\", mainlineBuildFolder); Dictionary<string, string> temp = new Dictionary<string, string>(); temp[BuildFolderIndexName] = es1Main; temp[BuildPatternIndexName] = mainlineBuildNamingPattern; temp[BuildBranchIndexName] = "Mainline"; buildFoldersList.Add(temp); string featureBranch = System.IO.Path.Combine(localMapFolder + @"\", featureBranchBuildFolder); temp = new Dictionary<string, string>(); temp[BuildFolderIndexName] = featureBranch; temp[BuildPatternIndexName] = featureBranchBuildNamingPatern; temp[BuildBranchIndexName] = string.Empty; buildFoldersList.Add(temp); string[] maintBranches = System.IO.Directory.GetDirectories(localMapFolder + @"\", maintBranchBuildFolderPattern); foreach (string maintBranch in maintBranches) { temp = new Dictionary<string, string>(); temp[BuildFolderIndexName] = maintBranch; temp[BuildPatternIndexName] = maintBranchBuildNamingPattern; temp[BuildBranchIndexName] = new System.IO.DirectoryInfo(maintBranch).Name;//The branch name is the folder name buildFoldersList.Add(temp); } foreach (Dictionary<string, string> buildFolder in buildFoldersList) { foreach (string d in System.IO.Directory.GetDirectories(buildFolder[BuildFolderIndexName], buildFolder[BuildPatternIndexName])) { if (!d.Contains("BAD")) { System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(d); System.IO.DirectoryInfo remoteInfo = new System.IO.DirectoryInfo(d.Replace(localMapFolder, Path)); string branchName = string.IsNullOrEmpty(buildFolder[BuildBranchIndexName]) ? System.Text.RegularExpressions.Regex.Split(info.Name, @"_[0-9]\.[0-9]\.[0-9]\.[0-9]+")[0] : buildFolder[BuildBranchIndexName]; string releaseAndNumber = System.Text.RegularExpressions.Regex.Match(info.Name, @"[0-9]\.[0-9]\.[0-9]\.[0-9]+").Value; string number = releaseAndNumber.Substring(releaseAndNumber.LastIndexOf('.') + 1); string releaseName = releaseAndNumber.Substring(0, releaseAndNumber.LastIndexOf('.')); Branch tempBranch = new Branch { Name = branchName, Path = string.Empty, Description = branchName, Type = (int)SyncSourceType.FromBuildServer, ProductId = Product.GetProductByName(ProductName).ProductId, }; Branch branch = Branch.AddOrUpdateBranch(tempBranch); Release tempRelease = new Release { Name = releaseName, Description = releaseName, Type = (int)SyncSourceType.FromBuildServer, Path = string.Empty, ProductId = Product.GetProductByName(ProductName).ProductId, }; Release release = Release.AddOrUpdateRelease(tempRelease); if (IsBuildFinished(info)) { Build b = new Build { Name = info.Name, Description = info.Name, Location = remoteInfo.FullName, BranchId = branch.BranchId, ReleaseId = release.ReleaseId, Number = number, BuildType = BuildType.BuildMachine, ProductId = Product.GetProductByName(ProductName).ProductId, BuildStatus = BuildStatus.Success, ProviderId = this.Provider.ProviderId, }; builds.Add(b); } } } } return builds; }
/// <summary> /// Invoked when <see cref="ToEntity"/> operation is about to return. /// </summary> /// <param name="entity"><see cref="Branch"/> converted from <see cref="BranchDTO"/>.</param> partial static void OnEntity(this BranchDTO dto, Branch entity);
/// <summary> /// Converts this instance of <see cref="BranchDTO"/> to an instance of <see cref="Branch"/>. /// </summary> /// <param name="dto"><see cref="BranchDTO"/> to convert.</param> public static Branch ToEntity(this BranchDTO dto) { if (dto == null) return null; var entity = new Branch(); entity.BranchId = dto.BranchId; entity.Name = dto.Name; entity.Path = dto.Path; entity.Description = dto.Description; entity.ProductId = dto.ProductId; dto.OnEntity(entity); return entity; }