Переглянути джерело

Removing a bunch of references to CoreUtils.TypeList to minimise reflection on startups

Kenric Nugteren 1 рік тому
батько
коміт
c63cc732fd

+ 1 - 6
prs.desktop/Configuration/CustomPropertyGrid.cs

@@ -69,14 +69,9 @@ namespace PRSDesktop.Configuration
             if (column != null)
             {
                 column.Lookups.Clear();
-                var classes = CoreUtils.TypeList(
-                    new[]
-                    {
-                        typeof(Setout).Assembly
-                    },
+                var classes = CoreUtils.Entities.Where(
                     myType =>
                         myType.IsClass
-                        && !myType.IsAbstract
                         && !myType.IsGenericType
                         && myType.IsSubclassOf(typeof(Entity))
                         && myType.GetInterfaces().Contains(typeof(IPersistent))

+ 2 - 3
prs.desktop/Dashboards/Common/DigitalFormsDashboard.xaml.cs

@@ -1052,9 +1052,8 @@ public partial class DigitalFormsDashboard : UserControl,
     {
         if (FormInstanceTypes == null)
         {
-            var instancetypes = CoreUtils.TypeList(
-                AppDomain.CurrentDomain.GetAssemblies(),
-                x => !x.IsAbstract && x.GetInterfaces().Contains(typeof(IDigitalFormInstance))
+            var instancetypes = CoreUtils.Entities.Where(
+                x => x.GetInterfaces().Contains(typeof(IDigitalFormInstance))
             ).Select(x =>
             {
                 var inter = x.GetInterfaces()

+ 2 - 4
prs.desktop/Dashboards/System/DatabaseActivityDashboard.xaml.cs

@@ -151,8 +151,7 @@ namespace PRSDesktop
             StaffView.ItemsSource = emplookups;
 
             var types = new Dictionary<string, string> { { "", "All Types" } };
-            var entities = CoreUtils.TypeList(
-                AppDomain.CurrentDomain.GetAssemblies(),
+            var entities = CoreUtils.Entities.Where(
                 x => x.IsSubclassOf(typeof(Entity)) && x.GetInterfaces().Contains(typeof(IRemotable))
             );
             foreach (var type in entities.OrderBy(x => x.Name))
@@ -202,8 +201,7 @@ namespace PRSDesktop
             history.Categories.Clear();
             if (string.IsNullOrWhiteSpace(typename))
             {
-                var entities = CoreUtils.TypeList(
-                    AppDomain.CurrentDomain.GetAssemblies(),
+                var entities = CoreUtils.Entities.Where(
                     x => x.IsSubclassOf(typeof(Entity)) && x.GetInterfaces().Contains(typeof(IRemotable))
                 );
                 foreach (var type in entities.OrderBy(x => x.Name))

+ 1 - 6
prs.desktop/Dashboards/UtilityDashboard.xaml.cs

@@ -582,12 +582,7 @@ namespace PRSDesktop
             if (_dashboardElements == null)
             {
                 _dashboardElements = new();
-                var types = CoreUtils.TypeList(
-                    new [] { Assembly.GetExecutingAssembly() },
-                    x => x.IsClass
-                        && !x.IsAbstract
-                        && !x.IsGenericType
-                        && x.GetInterfaces().Contains(typeof(IDashboardElement)));
+                var types = CoreUtils.Entities.Where(x => x.IsClass && !x.IsGenericType && x.GetInterfaces().Contains(typeof(IDashboardElement)));
                 foreach (var type in types)
                 {
                     var dashboardElementDef = type.GetSuperclassDefinition(typeof(DashboardElement<,,>));

+ 4 - 20
prs.desktop/Panels/Notifications/NotificationUtils.cs

@@ -27,24 +27,6 @@ namespace PRSDesktop
             return result;
         }
 
-        private static IDynamicGrid FindDataGrid(Type type)
-        {
-            var gridtypes = CoreUtils.TypeList(
-                AppDomain.CurrentDomain.GetAssemblies(),
-                myType =>
-                    myType.IsClass
-                    && !myType.IsAbstract
-                    && !myType.IsGenericType
-                    && myType.BaseType != null
-                    && myType.BaseType.Name == typeof(DynamicDataGrid<>).Name
-                    && myType.ContainsInheritedGenericType(type)
-            ).ToArray();
-
-            var gridtype = gridtypes.Any() ? gridtypes.First() : typeof(DynamicDataGrid<>).MakeGenericType(type);
-            var grid = Activator.CreateInstance(gridtype) as IDynamicGrid;
-            return grid;
-        }
-
         private static bool PerformAction(Guid[] ids, Func<Notification, bool> action)
         {
             if (!ids.Any())
@@ -143,7 +125,7 @@ namespace PRSDesktop
 
                 var entity = LoadEntity(type, id);
 
-                var grid = FindDataGrid(type);
+                var grid = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicDataGrid<>), type);
                 return grid.EditItems(new object[] { entity });
             });
         }
@@ -303,7 +285,9 @@ namespace PRSDesktop
             {
                 var job = new Client<Job>().Load(new Filter<Job>(x => x.ID).IsEqualTo(notification.Job.ID)).FirstOrDefault();
                 if (job != null)
-                    FindDataGrid(typeof(Job)).EditItems(new[] { job });
+                {
+                    DynamicGridUtils.EditEntity(job);
+                }
                 return false;
             });
         }

+ 1 - 0
prs.server/Forms/Configuration.xaml.cs

@@ -60,6 +60,7 @@ public partial class Configuration : ThemableWindow
             PRSSharedUtils.RegisterClasses();
             ReportUtils.RegisterClasses();
             ConfigurationUtils.RegisterClasses();
+            CoreUtils.RegisterClasses(typeof(Configuration).Assembly);
 
             Logger.OnLog += MainLogger.Send;
             MainLogger.AddLogger(new LogFileLogger(CoreUtils.GetPath()));