Skip to content

Commit 7e64d20

Browse files
committed
add a new feature: Add-ins -> Snoop loaded assemblies
1 parent 07cab8f commit 7e64d20

File tree

5 files changed

+170
-3
lines changed

5 files changed

+170
-3
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<Window x:Class="RevitDBExplorer.Assemblies"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:RevitDBExplorer"
7+
WindowStartupLocation="CenterOwner"
8+
Icon="/RevitDBExplorer;component/Resources/RDBE.ico"
9+
TextOptions.TextFormattingMode="Display"
10+
MinHeight="350"
11+
MaxHeight="600"
12+
13+
mc:Ignorable="d"
14+
Title="Assemblies" Height="450" Width="1000">
15+
<Grid Margin="7 7 7 7">
16+
<Grid.RowDefinitions>
17+
<RowDefinition Height="auto"/>
18+
<RowDefinition Height="7"/>
19+
<RowDefinition Height="1*"/>
20+
</Grid.RowDefinitions>
21+
22+
<Grid >
23+
<Grid.ColumnDefinitions>
24+
<ColumnDefinition Width="auto"/>
25+
<ColumnDefinition/>
26+
</Grid.ColumnDefinitions>
27+
28+
<TextBlock Text="Search" VerticalAlignment="Center" Margin="0 0 7 0"/>
29+
<TextBox Grid.Column="1" TextChanged="TextBox_TextChanged" x:Name="cFilter"/>
30+
</Grid>
31+
32+
<DataGrid
33+
Grid.Row="2"
34+
ItemsSource="{Binding Items}"
35+
AutoGenerateColumns="False"
36+
>
37+
<DataGrid.Columns>
38+
<DataGridTextColumn Header="No" Binding="{Binding No}" Width="27" />
39+
<DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="2*" />
40+
<DataGridTextColumn Header="Version" Binding="{Binding Version}" Width="0.5*" />
41+
<DataGridTextColumn Header="Path" Binding="{Binding Path}" Width="3*" />
42+
<DataGridTextColumn Header="AssemblyLoadContext" Binding="{Binding AssemblyLoadContext}" Width="1*" />
43+
</DataGrid.Columns>
44+
</DataGrid>
45+
</Grid>
46+
</Window>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using System.ComponentModel;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Runtime.CompilerServices;
8+
using System.Runtime.Loader;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
using System.Windows;
12+
using System.Windows.Controls;
13+
using System.Windows.Data;
14+
using System.Windows.Documents;
15+
using System.Windows.Input;
16+
using System.Windows.Media;
17+
using System.Windows.Media.Imaging;
18+
using System.Windows.Shapes;
19+
using RevitDBExplorer.WPF;
20+
21+
// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
22+
23+
namespace RevitDBExplorer
24+
{
25+
26+
public partial class Assemblies : Window, INotifyPropertyChanged
27+
{
28+
public ObservableCollection<AssemblyViewModel> Items { get; set; } = new ObservableCollection<AssemblyViewModel>();
29+
30+
31+
32+
public Assemblies()
33+
{
34+
InitializeComponent();
35+
36+
var viewModels = AppDomain.CurrentDomain.GetAssemblies().Select((x, i) => new AssemblyViewModel(i, x));
37+
Items = new ObservableCollection<AssemblyViewModel>(viewModels);
38+
39+
this.DataContext = this;
40+
}
41+
42+
43+
44+
45+
46+
#region INotifyPropertyChanged
47+
48+
public event PropertyChangedEventHandler PropertyChanged;
49+
50+
protected virtual void OnPropertyChanged([CallerMemberName] String propertyName = "")
51+
{
52+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
53+
}
54+
55+
#endregion
56+
57+
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
58+
{
59+
var lcv = (ListCollectionView)CollectionViewSource.GetDefaultView(Items);
60+
lcv.Filter = Filter;
61+
}
62+
63+
private bool Filter(object item)
64+
{
65+
if (item is AssemblyViewModel assemblyViewModel)
66+
{
67+
return assemblyViewModel.Filter(cFilter.Text);
68+
}
69+
return true;
70+
}
71+
}
72+
73+
74+
75+
public class AssemblyViewModel : BaseViewModel
76+
{
77+
public int No { get; set; }
78+
public string Name { get; set; }
79+
public string Version { get; private set; }
80+
public string Path { get; private set; }
81+
public string AssemblyLoadContext { get; private set; }
82+
83+
84+
public AssemblyViewModel(int no, Assembly asm)
85+
{
86+
No = no + 1;
87+
88+
var asmName = asm.GetName();
89+
Name = asmName.Name;
90+
Version = asmName.Version?.ToString();
91+
Path = asm.IsDynamic ? string.Empty : asm.Location;
92+
#if R2025_MIN
93+
var context = System.Runtime.Loader.AssemblyLoadContext.GetLoadContext(asm);
94+
AssemblyLoadContext = context.Name;
95+
#endif
96+
97+
}
98+
99+
100+
public bool Filter(string text)
101+
{
102+
if (string.IsNullOrEmpty(text)) return true;
103+
if (Name?.Contains(text, StringComparison.OrdinalIgnoreCase) == true) return true;
104+
if (Path?.Contains(text, StringComparison.OrdinalIgnoreCase) == true) return true;
105+
if (AssemblyLoadContext?.Contains(text, StringComparison.OrdinalIgnoreCase) == true) return true;
106+
if (Version?.Contains(text, StringComparison.OrdinalIgnoreCase) == true) return true;
107+
108+
return false;
109+
}
110+
}
111+
}

sources/RevitDBExplorer/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@
221221
<MenuItem Header="Snoop loaded external applications" InputGestureText="UIApplication.LoadedApplications" Click="SelectorButton_Click" Tag="LoadedApplications" />
222222
<MenuItem Header="Snoop updaters" InputGestureText="UpdaterRegistry.GetRegisteredUpdaterInfos()" Click="SelectorButton_Click" Tag="Updaters" />
223223
<MenuItem Header="Snoop external services" InputGestureText="ExternalServiceRegistry.GetServices()" Click="SelectorButton_Click" Tag="ExternalServices"/>
224+
<MenuItem Header="Snoop loaded assemblies" InputGestureText="AppDomain.CurrentDomain.GetAssemblies()" Click="SnoopLoadedAssemblies" />
224225
</ContextMenu>
225226
</Button.ContextMenu>
226227
</Button>

sources/RevitDBExplorer/MainWindow.xaml.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,18 @@ private void RDSButton_Click(object sender, RoutedEventArgs e)
301301
private void OpenRDS()
302302
{
303303
Application.RDSController.Open(this.Left, this.Top + this.ActualHeight);
304-
}
304+
}
305+
306+
307+
private void SnoopLoadedAssemblies(object sender, RoutedEventArgs e)
308+
{
309+
var window = new Assemblies();
310+
window.Owner = this;
311+
window.Show();
312+
}
313+
314+
305315

306-
307316
private void Window_Closed(object sender, EventArgs e)
308317
{
309318
globalKeyboardHook.unhook();

sources/RevitDBExplorer/WPF/BaseViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace RevitDBExplorer.WPF
66
{
7-
internal class BaseViewModel : INotifyPropertyChanged
7+
public class BaseViewModel : INotifyPropertyChanged
88
{
99
public event PropertyChangedEventHandler PropertyChanged;
1010

0 commit comments

Comments
 (0)