private void ProcessProject(List <ListBoxItemData> allFiles, ref int totalLines, ref int totalItems, ref long totalSize, VsSolutionProjectPart each, string projectPath, VsProject proj) { foreach (string file in proj.IncludedFiles) { string filename = projectPath + "\\" + file; FileInfo info = new FileInfo(filename); bool alreadyIndexed = false; foreach (ListBoxItemData lbid in allFiles) { if (lbid.Path + "\\" + lbid.Name == info.FullName) { alreadyIndexed = true; lbid.Project += ", " + each.Name; break; } } if (!alreadyIndexed) { int lines = File.ReadAllLines(filename).Length; ListBoxItemData lbid = new ListBoxItemData(info.Name, info.DirectoryName, info.LastWriteTime, FileType(filename), IOHelpers.FormatFileSize(info.Length), lines, each.Name); totalLines += lines; totalItems++; totalSize += info.Length; allFiles.Add(lbid); } } foreach (VsProject project in proj.IncludedProjects) { ProcessProject(allFiles, ref totalLines, ref totalItems, ref totalSize, each, projectPath, project); } }
private void Sort(IEnumerable items, string sortBy) { List <ListBoxItemData> arrayList = (List <ListBoxItemData>)items; int length = arrayList.Count - 1; _PropertyInfo property = typeof(ListBoxItemData).GetProperty(sortBy); Func <object, object, int> ComparisonFunction; switch (sortBy) { case "Name": case "Type": case "Project": case "Path": ComparisonFunction = StringCompareTo; break; case "LineCount": ComparisonFunction = IntCompareTo; break; case "DateModified": ComparisonFunction = DateTimeCompareTo; break; case "Size": ComparisonFunction = SizeCompareTo; break; default: throw (new NotImplementedException("Unhandled sort parameter.")); } while (true) { bool _swapMade = false; for (int i = 0; i < length; i++) { ListBoxItemData i0 = arrayList[i]; ListBoxItemData i1 = arrayList[i + 1]; if (ComparisonFunction(property.GetValue(i0, null), property.GetValue(i1, null)) > 0) { arrayList[i + 1] = i0; arrayList[i] = i1; _swapMade = true; } } if (!_swapMade) { break; } } Dispatcher.BeginInvoke(() => { files.ItemsSource = null; files.ItemsSource = arrayList; }); }