Commits

Mathias Kluba committed e2094f3 Merge

Merge gauthier branch

  • Participants
  • Parent commits c803e41, 532794d

Comments (0)

Files changed (2)

SOS.Net/FormMain.cs

             if(!string.IsNullOrEmpty(this.textBoxSearchProcesses.Text))
                 result = this.controller.FilterProcesses(this.textBoxSearchProcesses.Text);
 
-            this.listViewProcesses.BeginUpdate();
-            this.listViewProcesses.Items.Clear();
-            this.listViewProcesses.Items.AddRange(result);
-            this.listViewProcesses.EndUpdate();
+
+            updateListViewItemsWithNewItems(result, this.listViewProcesses);
+        }
+
+        private void updateListViewItemsWithNewItems(ListViewItem[] result, ListView listViewToRefreshWithNewItems)
+        {
+            listViewToRefreshWithNewItems.BeginUpdate();
+            listViewToRefreshWithNewItems.Items.Clear();
+            listViewToRefreshWithNewItems.Items.AddRange(result);
+            performSort(listViewToRefreshWithNewItems);
+            listViewToRefreshWithNewItems.EndUpdate();
         }
 
         private void textBoxSearchProcesses_TextChanged(object sender, EventArgs e)
 
         private void RefreshAppDomains()
         {
+            System.Diagnostics.Debug.Assert(controller.Attached,"can't refresh appdomains if not attached"); // occurs when clicking refresh on the app domain tab without attaching a process up front
             this.tabControlMain.SelectTab(this.tabPageAppDomain);
 
             this.listViewAppDomains.BeginUpdate();
 
             // Set the ascending property to sort in the opposite order.
             if (clickedCol.Tag == null)
-                clickedCol.Tag = true;
+                clickedCol.Tag = false;
             else
             {
                 clickedCol.Tag = !((bool)clickedCol.Tag);
 
             var ascending = (bool)clickedCol.Tag;
 
-            // Get the number of items in the list.
+            persistSort(listview, e.Column, ascending);
+            
+            performSort(listview);
+        }
+
+
+            Dictionary<ListView, KeyValuePair<int,bool>> columnSortByListViewMap = new Dictionary<ListView, KeyValuePair<int, bool>>();
+
+        private void persistSort(ListView listViewToPersistSortOrder, int columnIndex, bool isAscending)
+        {
+            var sortingDetails = new KeyValuePair<int,bool>(columnIndex, isAscending);
+                columnSortByListViewMap[listViewToPersistSortOrder] = sortingDetails;
+        }
+
+            private void getSort(ListView listViewToRetriveSortInfoFor, out int columnIndex, out bool isAscending)
+            {
+                if(columnSortByListViewMap.ContainsKey(listViewToRetriveSortInfoFor))
+                {
+                    var sortingdetails = columnSortByListViewMap[listViewToRetriveSortInfoFor];
+                    columnIndex = sortingdetails.Key;
+                    isAscending = sortingdetails.Value;
+                }
+                else
+                {
+									
+                    columnIndex = 0;
+                    isAscending = true;
+                	var sortingdetails = new KeyValuePair<int, bool>(columnIndex, isAscending);
+									columnSortByListViewMap[listViewToRetriveSortInfoFor] = sortingdetails;
+                }
+            }
+
+        private void performSort(ListView listview/*, ColumnClickEventArgs e, bool ascending*/)
+        {
+						// Get the number of items in the list.
+            int columnIndexToSortOver;
+            bool isAscending;
+            getSort(listview, out columnIndexToSortOver, out isAscending);
             int numItems = listview.Items.Count;
 
             // Turn off display while data is repoplulated.
             ArrayList SortArray = new ArrayList();
             for (int i = 0; i < numItems; i++)
             {
-                SortArray.Add(new SortWrapper(listview.Items[i], e.Column));
+                SortArray.Add(new SortWrapper(listview.Items[i],columnIndexToSortOver));
             }
 
             // Sort the elements in the ArrayList using a new instance of the SortComparer
             // and the IComparer implementation to use for comparing elements. Note that
             // the IComparer implementation (SortComparer) requires the sort
             // direction for its constructor; true if ascending, othwise false.
-            SortArray.Sort(0, SortArray.Count, new SortWrapper.SortComparer(ascending));
+            SortArray.Sort(0, SortArray.Count, new SortWrapper.SortComparer(isAscending));
 
             // Clear the list, and repopulate with the sorted items.
             listview.Items.Clear();
             listview.EndUpdate();
         }
     }
-}
+}

SOS.Net/SosController.cs

     {
         private ListViewItem[] processes;
 
-        private ListViewItem[] types;
+        /// <summary>
+        /// don't use me, use SosController.types instead
+        /// </summary>
+        private ListViewItem[] _types;
+
+        private ListViewItem[] types
+        {
+            get { return _types ?? new ListViewItem[] { }; }
+            set { _types = value; }
+        }
 
         private CdbProcess cdb;
 
 
             List<string> dotnetProcesses = new List<string>();
 
-            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Name FROM Win32_PerfFormattedData_NETFramework_NETCLRLoading");            
+            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Name FROM Win32_PerfFormattedData_NETFramework_NETCLRLoading");
             foreach (ManagementObject item in searcher.Get())
-            {                
+            {
                 string name = item.Properties["Name"].Value.ToString();
                 if (!name.Equals("_Global_"))
                 {
                 }));
             }
 
-            processes = result.OrderByDescending(item => item.SubItems[4].Text).ToArray();
+            processes = result.OrderBy(item => item.SubItems[4].Text).ToArray();
             return processes;
-        }       
+        }
 
         public ListViewItem[] FilterProcesses(string filter)
         {
 
         public ListViewItem[] FilterTypes(string typeName)
         {
-            return
-                this.types.Where(i => i.SubItems[3].Text.IndexOf(typeName, StringComparison.OrdinalIgnoreCase) != -1).
-                    ToArray();
+            Func<ListViewItem, bool> filteringPredicate =
+                (item) =>
+                item.SubItems[3].Text.IndexOf(typeName, StringComparison.OrdinalIgnoreCase) != -1;
+            return this.types.Where(filteringPredicate).ToArray();
         }
 
         public InstanceInfoDetails GetInstanceDumpDetails(string instanceAddress)