Bläddra i källkod

Way sped up lookup factory initialisation. Made Console.Enabled a dependency property

Kenric Nugteren 1 år sedan
förälder
incheckning
5b2161d881

+ 14 - 35
InABox.Core/ILookupDefinition.cs

@@ -73,21 +73,18 @@ namespace InABox.Core
             {
                 _cache = new Dictionary<Type, LookupCacheEntry>();
 
+                var types = CoreUtils.TypeList(
+                    x => !x.IsAbstract
+                    && (x.HasInterface(typeof(ILookupDefinition<>))
+                        || x.HasInterface(typeof(ILookupDefinition<,>))
+                        || x.HasInterface(typeof(IStaticLookupDefinition<>))));
+
 
                 // Load up the default types
-                var defaulttypes = CoreUtils.TypeList(
-                    AppDomain.CurrentDomain.GetAssemblies(),
-                    x => !x.IsAbstract &&
-                         x.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition().Equals(typeof(ILookupDefinition<>))
-                         )
-                );
-                foreach (var type in defaulttypes)
+                foreach (var type in types)
                     try
                     {
-                        var intfs = type.GetInterfaces().Where(i =>
-                            i.IsGenericType
-                            && i.GetGenericTypeDefinition().Equals(typeof(ILookupDefinition<>))
-                        );
+                        var intfs = type.GetInterfaces(typeof(ILookupDefinition<>));
                         foreach (var intf in intfs)
                             _cache[intf.GenericTypeArguments.First()] = new LookupCacheEntry(Activator.CreateInstance(type));
                     }
@@ -97,19 +94,9 @@ namespace InABox.Core
                     }
 
                 // Now load up the specific types
-                var specifictypes = CoreUtils.TypeList(
-                    AppDomain.CurrentDomain.GetAssemblies(),
-                    x =>
-                        !x.IsAbstract &&
-                        x.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition().Equals(typeof(ILookupDefinition<,>))
-                        )
-                );
-                foreach (var type in specifictypes)
+                foreach (var type in types)
                 {
-                    var intfs = type.GetInterfaces().Where(i =>
-                        i.IsGenericType
-                        && i.GetGenericTypeDefinition().Equals(typeof(ILookupDefinition<,>))
-                    );
+                    var intfs = type.GetInterfaces(typeof(ILookupDefinition<,>));
                     foreach (var intf in intfs)
                     {
                         var lookuptype = intf.GenericTypeArguments.First();
@@ -122,19 +109,11 @@ namespace InABox.Core
 
 
                 // Load up the static lookups
-                var staticlookups = CoreUtils.TypeList(
-                    AppDomain.CurrentDomain.GetAssemblies(),
-                    x =>
-                        !x.IsAbstract &&
-                        x.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition().Equals(typeof(IStaticLookupDefinition<>))
-                        )
-                );
-                foreach (var type in staticlookups)
+                foreach (var type in types)
                 {
-                    var intf = type.GetInterfaces().First(i =>
-                        i.IsGenericType
-                        && i.GetGenericTypeDefinition().Equals(typeof(IStaticLookupDefinition<>))
-                    );
+                    var intf = type.GetInterfaces(typeof(IStaticLookupDefinition<>)).FirstOrDefault();
+                    if (intf is null) continue;
+
                     var iType = intf.GenericTypeArguments.First();
                     if (!_cache.ContainsKey(iType))
                         _cache[iType] = new LookupCacheEntry(null);

+ 66 - 67
inabox.wpf/DynamicGrid/DynamicGridColumnsEditor.xaml.cs

@@ -5,74 +5,73 @@ using System.Collections.Generic;
 using System.Windows;
 using System.Windows.Controls;
 
-namespace InABox.DynamicGrid
+namespace InABox.DynamicGrid;
+
+/// <summary>
+///     Interaction logic for DynamicGridColumnsEditor.xaml
+/// </summary>
+public partial class DynamicGridColumnsEditor : ThemableWindow
 {
-    /// <summary>
-    ///     Interaction logic for DynamicGridColumnsEditor.xaml
-    /// </summary>
-    public partial class DynamicGridColumnsEditor : ThemableWindow
+    private readonly DynamicColumnGrid ColumnGrid;
+
+    public DynamicGridColumnsEditor(Type type)
+    {
+        InitializeComponent();
+
+        Type = type;
+
+        Title = $"Select Columns for {CoreUtils.Neatify(type.Name)}";
+
+        ColumnGrid = new DynamicColumnGrid { Type = type };
+        ColumnGrid.SetValue(Grid.ColumnSpanProperty, 3);
+        ColumnGrid.Margin = new Thickness(5F, 5F, 5F, 5F);
+        grid.Children.Add(ColumnGrid);
+
+        Columns = ColumnGrid.Columns;
+
+        //ColumnGrid.OnEditItem += Columns_OnEditItem;
+    }
+
+    public Type Type { get; set; }
+
+    public DynamicGridColumns Columns { get; }
+
+    public bool DirectEdit
+    {
+        get => ColumnGrid.DirectEdit;
+        set => ColumnGrid.DirectEdit = value;
+    }
+
+    //private bool Columns_OnEditItem(object sender, object item)
+    //{
+    //	DynamicEditor editor = new DynamicEditor();
+    //	editor.OnDefineGridColumns += Editor_OnDefineGridColumns;
+    //	editor.Item = item;
+    //	if (editor.ShowDialog() == true)
+    //		return true;
+    //	return false;
+    //}
+
+    //private DynamicGridColumns Editor_OnDefineGridColumns(object sender, DynamicGridColumns master)
+    //{
+    //	return ColumnGrid.DefineColumns();
+    //}
+
+    private void OKButton_Click(object sender, RoutedEventArgs e)
+    {
+        DialogResult = true;
+        Close();
+    }
+
+    private void CancelButton_Click(object sender, RoutedEventArgs e)
+    {
+        DialogResult = false;
+        Close();
+    }
+
+    private void Window_Loaded(object sender, RoutedEventArgs e)
     {
-        private readonly DynamicColumnGrid ColumnGrid;
-
-        public DynamicGridColumnsEditor(Type type)
-        {
-            InitializeComponent();
-
-            Type = type;
-
-            Title = $"Select Columns for {CoreUtils.Neatify(type.Name)}";
-
-            ColumnGrid = new DynamicColumnGrid { Type = type };
-            ColumnGrid.SetValue(Grid.ColumnSpanProperty, 3);
-            ColumnGrid.Margin = new Thickness(5F, 5F, 5F, 5F);
-            grid.Children.Add(ColumnGrid);
-
-            Columns = ColumnGrid.Columns;
-
-            //ColumnGrid.OnEditItem += Columns_OnEditItem;
-        }
-
-        public Type Type { get; set; }
-
-        public DynamicGridColumns Columns { get; }
-
-        public bool DirectEdit
-        {
-            get => ColumnGrid.DirectEdit;
-            set => ColumnGrid.DirectEdit = value;
-        }
-
-        //private bool Columns_OnEditItem(object sender, object item)
-        //{
-        //	DynamicEditor editor = new DynamicEditor();
-        //	editor.OnDefineGridColumns += Editor_OnDefineGridColumns;
-        //	editor.Item = item;
-        //	if (editor.ShowDialog() == true)
-        //		return true;
-        //	return false;
-        //}
-
-        //private DynamicGridColumns Editor_OnDefineGridColumns(object sender, DynamicGridColumns master)
-        //{
-        //	return ColumnGrid.DefineColumns();
-        //}
-
-        private void OKButton_Click(object sender, RoutedEventArgs e)
-        {
-            DialogResult = true;
-            Close();
-        }
-
-        private void CancelButton_Click(object sender, RoutedEventArgs e)
-        {
-            DialogResult = false;
-            Close();
-        }
-
-        private void Window_Loaded(object sender, RoutedEventArgs e)
-        {
-            ColumnGrid.Type = Type;
-            ColumnGrid.Refresh(true, true);
-        }
+        ColumnGrid.Type = Type;
+        ColumnGrid.Refresh(true, true);
     }
 }

+ 5 - 8
inabox.wpf/Forms/Console/Console.xaml.cs

@@ -44,6 +44,9 @@ public static class ItemsControlExtensions
 /// </summary>
 public partial class ConsoleControl : UserControl, INotifyPropertyChanged
 {
+    public static readonly DependencyProperty EnabledProperty
+        = DependencyProperty.Register(nameof(Enabled), typeof(bool), typeof(ConsoleControl));
+
     private CollectionViewSource _filtered;
     public CollectionViewSource Filtered
     {
@@ -61,8 +64,6 @@ public partial class ConsoleControl : UserControl, INotifyPropertyChanged
 
     private Regex? searchRegex;
 
-    private bool _enabled = true;
-
     public event PropertyChangedEventHandler? PropertyChanged;
 
     public event Action? OnLoadLog;
@@ -99,12 +100,8 @@ public partial class ConsoleControl : UserControl, INotifyPropertyChanged
 
     public bool Enabled
     {
-        get => _enabled;
-        set
-        {
-            _enabled = value;
-            OnPropertyChanged();
-        }
+        get => (bool)GetValue(EnabledProperty);
+        set => SetValue(EnabledProperty, value);
     }
 
     public ConsoleControl()