public int Compare(object a, object b) { int returnVal = -1; string textA = ((ListViewItem)a).SubItems[column].Text; string textB = ((ListViewItem)b).SubItems[column].Text; switch (column) { case 0: // Path returnVal = String.Compare(textA, textB); break; case 1: // Project // TODO:(pv) Sort by Solution, then Solution Items, then Project(s)... returnVal = String.Compare(textA, textB); break; case 2: // Change PostReview.ChangeType changeA = (PostReview.ChangeType)Enum.Parse(typeof(PostReview.ChangeType), textA); PostReview.ChangeType changeB = (PostReview.ChangeType)Enum.Parse(typeof(PostReview.ChangeType), textB); returnVal = changeA.CompareTo(changeB); break; case 3: // Full Path returnVal = String.Compare(textA, textB); break; } // Determine whether the sort order is descending. if (order == SortOrder.Descending) { // Invert the value returned by String.Compare. returnVal *= -1; } return(returnVal); }
/// <summary> /// This method is called directly from the solution crawler and any solution/project file add/rename/remove events. /// It is also called via AddFilePathIfChanged(string filePath) when a file is saved outside of the context of a solution/project. /// </summary> /// <param name="filePath"></param> /// <param name="project"></param> /// <returns></returns> public void AddFilePathIfChanged(string filePathOs, string project, PostReview.ChangeType knownChangeType) { try { MyLog.DebugEnter(this, "AddFilePathIfChanged(\"" + filePathOs + "\", \"" + project + "\", " + knownChangeType + ")"); if (String.IsNullOrEmpty(filePathOs)) { throw new ArgumentNullException(filePathOs, "filePath cannot be null/empty"); } // Some SCCs are case sensitive; get the *exact* file case (or null if it does not exist) string filePathScc = MyUtils.GetCasedPath(filePathOs); if (String.IsNullOrEmpty(filePathScc)) { switch (knownChangeType) { case PostReview.ChangeType.Deleted: // If knownChangeType == Deleted then trust that the casing is already correct. filePathScc = filePathOs; break; case PostReview.ChangeType.Unknown: case PostReview.ChangeType.Added: // knownChangeType == Added during the Solution crawl and Solution/Project file adds. // If we got this far then the VS *Solution/Project* says there is a file. // But, the file can be an external/virtual/symbolic link/reference, not an actual file. // If GetCasedFilePath returned null then this file does not exist. // Ignore this situation and just continue the enumeration. Debug.WriteLine("File \"" + filePathOs + "\" does not exist; ignoring."); return; default: throw new FileNotFoundException("Could not get true cased filename needed for SCC.", filePathOs); } } if (BackgroundInitialSolutionCrawl != null && BackgroundInitialSolutionCrawl.IsBusy) { // Percent is currently always 0, since our progress is indeterminate // TODO:(pv) Find some way to determine # of nodes in tree *before* processing // Maybe do a quick first pass w/ no post-review? // NOTE:(pv) I did once have the debugger halt here complaining invalid state that the form is not active BackgroundInitialSolutionCrawl.ReportProgress(0, filePathScc); } string diff; PostReview.ChangeType changeType = PostReview.DiffFile(BackgroundInitialSolutionCrawl, filePathScc, out diff); // If the change type is known by the caller, use it. // Otherwise, use the type determined by the PostReview.DiffFile(...) if (knownChangeType != PostReview.ChangeType.Unknown) { changeType = knownChangeType; } filePathOs = filePathOs.ToLower(); switch (changeType) { case PostReview.ChangeType.Added: case PostReview.ChangeType.Copied: case PostReview.ChangeType.Deleted: case PostReview.ChangeType.Modified: PostReview.SubmitItem change = new PostReview.SubmitItem(filePathScc, project, changeType, diff); lock (changes) { changes[filePathOs] = change; } break; case PostReview.ChangeType.External: case PostReview.ChangeType.Normal: case PostReview.ChangeType.Unknown: default: // ignore break; } if (changeType == PostReview.ChangeType.Deleted) { // Stop tracking the file for changes. fileTracker.Unsubscribe(filePathOs, true); } else { // Track the file for *future* changes, even if there are no *current* changes. // This is a no-op if the path is already being tracked. fileTracker.Subscribe(filePathOs, true); } // Map the file path to the project so that future file changes can find out what project the file is in given just the file path. // This will overwrite any existing value...which seems fine for now. mapItemProjectNames[filePathOs] = project; } finally { MyLog.DebugLeave(this, "AddFilePathIfChanged(\"" + filePathOs + "\", \"" + project + "\", " + knownChangeType + ")"); } }