2022-03-18 22:48:14 +04:00
|
|
|
|
using ToolsDesktop.Interfaces;
|
2022-03-18 22:38:52 +04:00
|
|
|
|
using ToolsModule.Extensions;
|
2021-03-28 19:30:56 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
2022-03-18 22:48:14 +04:00
|
|
|
|
namespace ToolsDesktop.BusinessLogics
|
2021-03-28 19:30:56 +04:00
|
|
|
|
{
|
|
|
|
|
public static partial class DesktopLoader
|
|
|
|
|
{
|
|
|
|
|
private static readonly string _pathToWindowDestopExt = "..\\..\\..\\..\\WindowDestopExtensions\\";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Загрузка всех классов-реализаций IWindowDesktopExtension
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static List<IWindowDesktopExtension> GetWindowDesktopExtensions()
|
|
|
|
|
{
|
|
|
|
|
var list = new List<IWindowDesktopExtension>();
|
|
|
|
|
if (Directory.Exists(_pathToWindowDestopExt))
|
|
|
|
|
{
|
|
|
|
|
var files = Directory.GetFiles(_pathToWindowDestopExt, "*.dll", SearchOption.AllDirectories);
|
|
|
|
|
var loadedFiles = new List<string>();
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|