From f63cbb816d30a36e77ad069dc20ae5a0f855ffd3 Mon Sep 17 00:00:00 2001 From: kotcheshir73 Date: Sun, 28 Mar 2021 19:30:56 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=BE=D1=81=20?= =?UTF-8?q?=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=B2=20desktop=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA?= =?UTF-8?q?=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/DesktopLoader.cs | 46 +++++++++++++++++++ .../Interfaces/IWindowDesktopExtension.cs | 4 +- .../WindowDesktopExtensionControlModel.cs | 6 +-- .../BusinessLogics/ServiceProviderLoader.cs | 33 +------------ .../DepartmentPortalDesctop/FormMain.cs | 6 +-- 5 files changed, 53 insertions(+), 42 deletions(-) create mode 100644 DepartmentPortal/Common/DesktopTools/BusinessLogics/DesktopLoader.cs rename DepartmentPortal/Common/{ModuleTools => DesktopTools}/Interfaces/IWindowDesktopExtension.cs (89%) rename DepartmentPortal/Common/{ModuleTools => DesktopTools}/Models/WindowDesktopExtensionControlModel.cs (62%) diff --git a/DepartmentPortal/Common/DesktopTools/BusinessLogics/DesktopLoader.cs b/DepartmentPortal/Common/DesktopTools/BusinessLogics/DesktopLoader.cs new file mode 100644 index 0000000..cdf05ae --- /dev/null +++ b/DepartmentPortal/Common/DesktopTools/BusinessLogics/DesktopLoader.cs @@ -0,0 +1,46 @@ +using DesktopTools.Interfaces; +using ModuleTools.Extensions; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; + +namespace DesktopTools.BusinessLogics +{ + public static partial class DesktopLoader + { + private static readonly string _pathToWindowDestopExt = "..\\..\\..\\..\\WindowDestopExtensions\\"; + + /// + /// Загрузка всех классов-реализаций IWindowDesktopExtension + /// + /// + public static List GetWindowDesktopExtensions() + { + var list = new List(); + if (Directory.Exists(_pathToWindowDestopExt)) + { + var files = Directory.GetFiles(_pathToWindowDestopExt, "*.dll", SearchOption.AllDirectories); + var loadedFiles = new List(); + foreach (var file in files.Distinct()) + { + if (loadedFiles.Contains(file.GetFileName())) + { + continue; + } + Assembly asm = Assembly.LoadFrom(file); + foreach (var t in asm.GetExportedTypes()) + { + if (t.IsClass && typeof(IWindowDesktopExtension).IsAssignableFrom(t)) + { + list.Add((IWindowDesktopExtension)Activator.CreateInstance(t)); + } + } + loadedFiles.Add(file.GetFileName()); + } + } + return list; + } + } +} \ No newline at end of file diff --git a/DepartmentPortal/Common/ModuleTools/Interfaces/IWindowDesktopExtension.cs b/DepartmentPortal/Common/DesktopTools/Interfaces/IWindowDesktopExtension.cs similarity index 89% rename from DepartmentPortal/Common/ModuleTools/Interfaces/IWindowDesktopExtension.cs rename to DepartmentPortal/Common/DesktopTools/Interfaces/IWindowDesktopExtension.cs index 5fdbb01..4a65857 100644 --- a/DepartmentPortal/Common/ModuleTools/Interfaces/IWindowDesktopExtension.cs +++ b/DepartmentPortal/Common/DesktopTools/Interfaces/IWindowDesktopExtension.cs @@ -1,7 +1,7 @@ -using ModuleTools.Models; +using DesktopTools.Models; using System.Collections.Generic; -namespace ModuleTools.Interfaces +namespace DesktopTools.Interfaces { /// /// Интерфейс для регистрации контролов для десктопного приложения diff --git a/DepartmentPortal/Common/ModuleTools/Models/WindowDesktopExtensionControlModel.cs b/DepartmentPortal/Common/DesktopTools/Models/WindowDesktopExtensionControlModel.cs similarity index 62% rename from DepartmentPortal/Common/ModuleTools/Models/WindowDesktopExtensionControlModel.cs rename to DepartmentPortal/Common/DesktopTools/Models/WindowDesktopExtensionControlModel.cs index 1d9e081..051577a 100644 --- a/DepartmentPortal/Common/ModuleTools/Models/WindowDesktopExtensionControlModel.cs +++ b/DepartmentPortal/Common/DesktopTools/Models/WindowDesktopExtensionControlModel.cs @@ -1,10 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace ModuleTools.Models +namespace DesktopTools.Models { public class WindowDesktopExtensionControlModel { diff --git a/DepartmentPortal/Common/ModuleTools/BusinessLogics/ServiceProviderLoader.cs b/DepartmentPortal/Common/ModuleTools/BusinessLogics/ServiceProviderLoader.cs index e46e0e8..1eeafc1 100644 --- a/DepartmentPortal/Common/ModuleTools/BusinessLogics/ServiceProviderLoader.cs +++ b/DepartmentPortal/Common/ModuleTools/BusinessLogics/ServiceProviderLoader.cs @@ -12,7 +12,7 @@ namespace ModuleTools.BusinessLogics /// /// Загрузчик данных /// - public static class ServiceProviderLoader + public static partial class ServiceProviderLoader { private static readonly string _configFileName = "DepartmentPortal.config"; @@ -71,37 +71,6 @@ namespace ModuleTools.BusinessLogics return list; } - /// - /// Загрузка всех классов-реализаций IWindowDesktopExtension - /// - /// - public static List GetWindowDesktopExtensions() - { - var list = new List(); - if (Directory.Exists(_pathToWindowDestopExt)) - { - var files = Directory.GetFiles(_pathToWindowDestopExt, "*.dll", SearchOption.AllDirectories); - var loadedFiles = new List(); - foreach (var file in files.Distinct()) - { - if (loadedFiles.Contains(file.GetFileName())) - { - continue; - } - Assembly asm = Assembly.LoadFrom(file); - foreach (var t in asm.GetExportedTypes()) - { - if (t.IsClass && typeof(IWindowDesktopExtension).IsAssignableFrom(t)) - { - list.Add((IWindowDesktopExtension)Activator.CreateInstance(t)); - } - } - loadedFiles.Add(file.GetFileName()); - } - } - return list; - } - /// /// Получение имени файла /// diff --git a/DepartmentPortal/DepartmentPortalDesctop/FormMain.cs b/DepartmentPortal/DepartmentPortalDesctop/FormMain.cs index 2b8c907..2a10eed 100644 --- a/DepartmentPortal/DepartmentPortalDesctop/FormMain.cs +++ b/DepartmentPortal/DepartmentPortalDesctop/FormMain.cs @@ -1,5 +1,5 @@ -using DesktopTools.Controls; -using ModuleTools.BusinessLogics; +using DesktopTools.BusinessLogics; +using DesktopTools.Controls; using System; using System.Collections.Generic; using System.Linq; @@ -19,7 +19,7 @@ namespace DepartmentPortalDesctop _baseControls = new Dictionary(); _controls = new Dictionary(); - var extensions = ServiceProviderLoader.GetWindowDesktopExtensions(); + var extensions = DesktopLoader.GetWindowDesktopExtensions(); foreach (var extens in extensions) { var list = extens?.GetListControlEntityList()?.OrderBy(x => x.Order).ToList();