///<summary>After the FilePathHead is set, this takes the current beta and stable string and filles the rest of the paths in.</summary> public void GetFilePaths(List <string> listVersions, BackportProject currentProject, string headString) { if (currentProject.PatternMajor == MajorMinorPattern.MajorDotMinor) { foreach (string version in listVersions) { Version v = new Version(version); DictVersionFilePath.Add(version, FilePathHead.Replace(headString, Enum.GetName(currentProject.Name.GetType(), currentProject.Name) + v.Major + "." + v.Minor)); } } else //_Major_Minor { foreach (string version in listVersions) { Version v = new Version(version); string versionPath = FilePathHead.Replace(headString, Enum.GetName(currentProject.Name.GetType(), currentProject.Name) + "_" + v.Major + "_" + v.Minor); if (currentProject.Name == ProjectName.ODXam) { //ODXam is special as we change more than just the one path name. We also change the folder+csproj name. //These replaces will fix both of those. versionPath = versionPath.Replace("ODXam.Shared", $"ODXam_{v.Major}_{v.Minor}.Shared"); versionPath = versionPath.Replace("UnitTests.ODXam", $"UnitTests.ODXam_{v.Major}_{v.Minor}"); } else if (currentProject.Name == ProjectName.OpenDentalWebApps) { //Related to the ODXam replacement. ODXam business also has folder name changes. This allows backporting to work. versionPath = versionPath.Replace("OpenDentBusiness.ODXam", $"OpenDentBusiness.ODXam_{v.Major}_{v.Minor}"); } DictVersionFilePath.Add(version, versionPath); } } FileName = Path.GetFileName(FilePathHead); }
///<summary>Refreshes the data and changes the UI accordingly. Called from FillGrid when dataRefresh is true.</summary> private void RefreshData() { List <ODThread> listThreadsRunning = ODThread.GetThreadsByGroupName("FormBackport_Refresh"); //Quit all threads that are still running. The user may have changed the path. This way the grid will not be filled with false information. listThreadsRunning.ForEach(x => x.QuitAsync()); //Store path _pathOnRefresh = comboPath.Text.TrimEnd('\\'); _ignoreListNameOnRefresh = textIgnoreList.Text; _currentProject = BackportProjects.Unknown; _listFileChanges = new List <ODFileChanges>(); //Clear Rows gridMain.BeginUpdate(); gridMain.ListGridRows.Clear(); gridMain.EndUpdate(); if (!Directory.Exists(comboPath.Text)) { MessageBox.Show("The directory does not exist."); return; } else { if (_pathOnRefresh.Contains("OPEN DENTAL SUBVERSION")) //look for open dental first as its naming scheme does not match the rest. { _currentProject = BackportProjects.OpenDental; } else { for (int i = 0; i < Enum.GetNames(typeof(ProjectName)).Length; i++) { if (_pathOnRefresh.Contains(Enum.GetNames(typeof(ProjectName))[i])) { _currentProject = BackportProjects.ListProjects.Find(x => x.Name == ((ProjectName)i)); break; } } } } if (_currentProject == BackportProjects.Unknown) { MessageBox.Show("Could not find the correct project."); return; } //Get available versions based on folder structure. UpdateListVersions(); Cursor = Cursors.AppStarting; //Refresh Data string pathOnRefresh = _pathOnRefresh; string ignoreListNameOnRefresh = _ignoreListNameOnRefresh; BackportProject currentProject = _currentProject.Copy(); ODThread odThread = new ODThread((o) => { List <ODFileChanges> listFileChanges = GetListOfFiles(pathOnRefresh, _listAvailableVersions, ignoreListNameOnRefresh, currentProject); this.InvokeIfNotDisposed(() => { //If window quit, this action will not run and the thread will die. if (o.HasQuit) //If the user refreshed the path and this was marked to quit. { return; } Cursor = Cursors.Default; _listFileChanges = listFileChanges; labelCurProj.Text = "Current Project: " + Enum.GetName(_currentProject.Name.GetType(), _currentProject.Name); FillGrid(); _progressBarAction?.Invoke(); _progressBarAction = null; }); }); odThread.AddExceptionHandler(ex => { _progressBarAction?.Invoke(); _progressBarAction = null; this.InvokeIfNotDisposed(() => { //If there's an exception after the form is closed, swallow and do not do anything. FriendlyException.Show("Error refreshing data.", ex); }); }); odThread.GroupName = "FormBackport_Refresh"; odThread.Name = "FormBackport_Refresh" + DateTime.Now.Millisecond; odThread.Start(); if (_progressBarAction == null) { _progressBarAction = ODProgress.Show(); } }
///<summary>Gets a list of modified files with all changes recorded from SVN.</summary> public static List <ODFileChanges> GetListOfFiles(string pathOnRefresh, List <string> listVersions, string ignoreListName, BackportProject currentProject) { List <ODFileChanges> listFilesChanged = new List <ODFileChanges>(); string headString = ""; if (currentProject.PatternHead == HeadPattern.head) { headString = "head"; } else if (currentProject.PatternHead == HeadPattern.Name_head) { headString = Enum.GetName(currentProject.Name.GetType(), currentProject.Name) + "_head"; } string rawOutputFilesModified = RunWindowsCommand("svn diff --summarize \"" + pathOnRefresh + "\\" + headString + "\""); string rawOutputFilesIgnored = RunWindowsCommand("svn status --cl \"" + ignoreListName + "\" \"" + pathOnRefresh + "\\" + headString + "\""); //Change list List <string> listModifiedFiles = ExtractFileNames(rawOutputFilesModified); List <string> listIgnoreFiles = ExtractFileNames(rawOutputFilesIgnored); //gets the list of files to not include in the output. listModifiedFiles = listModifiedFiles.Except(listIgnoreFiles).ToList(); foreach (string modFile in listModifiedFiles) { ODFileChanges file = new ODFileChanges(); switch (modFile[0]) { case 'M': file.ModificationType = FileModificationType.Modified; break; case 'D': file.ModificationType = FileModificationType.Deleted; break; case 'A': file.ModificationType = FileModificationType.Added; break; default: file.ModificationType = FileModificationType.Unknown; break; } file.FilePathHead = modFile.Substring(1).Trim(); //Remove the modification type from the beginning to get the file path. file.GetFilePaths(listVersions, currentProject, headString); listFilesChanged.Add(file); } //Fill listFilesModified with information List <string> listLineChanges = new List <string>(); foreach (ODFileChanges file in listFilesChanged) { listLineChanges.Add(RunWindowsCommand("svn diff " + "\"" + file.FilePathHead + "\"")); } //Extract individual changes listLineChanges = ExtractModifiedLines(listLineChanges); if (listLineChanges.Count == 0) { return(new List <ODFileChanges>()); } //Extracts the exact lines that were changed and stores them in a list of LineChanges for (int i = 0; i < listLineChanges.Count; i++) { listFilesChanged[i].FillChanges(listLineChanges[i]); } return(listFilesChanged); }