/// <summary> /// Searches the treeview for classes that matches the given string. /// </summary> /// <param name="pattern">The string to match.</param> /// <returns>A list containing all the WbemTreeViewInstances that represent a class that matches the pattern.</returns> public IEnumerable <WbemTreeViewItem> Search(string pattern) { // The order of traversal does not matter since we have to scan every node anyway List <WbemTreeViewItem> resultClasses = new List <WbemTreeViewItem>(); Stack <WbemTreeViewItem> treeViewItemStack = new Stack <WbemTreeViewItem>(); foreach (WbemTreeViewItem t in Items) // initialize { treeViewItemStack.Push(t); } while (treeViewItemStack.Count != 0) { WbemTreeViewItem it = treeViewItemStack.Peek(); treeViewItemStack.Pop(); foreach (WbemTreeViewItem inner in it.Items) { treeViewItemStack.Push(inner); } WbemObject wbemObject = it.DataContext; if (Regex.IsMatch(wbemObject.Path.ClassName.ToLower(), pattern.ToLower())) { resultClasses.Add(it); } } resultClasses.Sort((x, y) => string.Compare(x.DataContext.Path.ClassName, y.DataContext.Path.ClassName, StringComparison.InvariantCulture)); return(resultClasses); }
/// <summary> /// Shows the class qualifiers of a class. This can only be called when a current class is selected. /// We also know which class this (The selected item in ClassNavigator). /// </summary> private void ShowClassQualifiers(object sender, RoutedEventArgs e) { WbemObject mObject = ClassNavigator.SelectedItem.DataContext; IList <DataGridClassQualifierView> qualifiers = mObject.Qualifiers.Values.Select(s => new DataGridClassQualifierView(s)).ToList(); ExtraDetails.ItemsSource = qualifiers; }
/// <summary> /// Populates the properties and methods from a class that is represented by a wbemTreeViewItem. /// </summary> /// <param name="wbemTreeViewItem">The WbemTreeViewItem that represents the class</param> private void PopulateClassDetails(WbemTreeViewItem wbemTreeViewItem) { PropertyList.ItemsSource = null; WbemObject mObject = wbemTreeViewItem.DataContext; TextBlockCurrentClass.Text = mObject.Path.ClassName; TextBlockCurrentClass.DataContext = mObject; IList <DataGridPropertyView> properties = mObject.GetAllProperties().Values.Select(s => new DataGridPropertyView(s)).ToList(); IList <DataGridMethodView> methods = mObject.Methods.Values.Select(s => new DataGridMethodView(s)).ToList(); PropertyList.ItemsSource = properties; MethodList.ItemsSource = methods; }
/// <summary> /// Shows the instances of a class. This can only be called when a current class is selected. /// We also know which class this (The selected item in ClassNavigator). /// </summary> private void ShowClassInstances(object sender, RoutedEventArgs e) { WbemObject mObject = ClassNavigator.SelectedItem.DataContext; IEnumerable <WbemObject> instances = service.InstancesOf(mObject.Path.ClassName); //todo: figure out how to show the different properties of the instances foreach (WbemObject instance in instances) { WbemProperty prop; instance.Properties.TryGetValue("Name", out prop); Debug.WriteLine(prop.Value); } ExtraDetails.ItemsSource = instances; }