готовая 4 лаба
This commit is contained in:
parent
d17275873b
commit
3c0d1f9d6a
@ -23,10 +23,4 @@
|
||||
<ProjectReference Include="..\PluginsConventionLibrary\PluginsConventionLibrary.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="System.IO.Packaging">
|
||||
<HintPath>$(SolutionDir)Plugins\System.IO.Packaging.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -20,56 +20,41 @@ namespace AppByPlugins
|
||||
public FormMain()
|
||||
{
|
||||
InitializeComponent();
|
||||
_plugins = new();
|
||||
LoadPlugins();
|
||||
_plugins = LoadPlugins();
|
||||
_selectedPlugin = string.Empty;
|
||||
}
|
||||
|
||||
private void LoadPlugins()
|
||||
private Dictionary<string, IPluginsConvention> LoadPlugins()
|
||||
{
|
||||
List<IPluginsConvention> pluginsList = GetPlugins();
|
||||
var plugins = new Dictionary<string, IPluginsConvention>();
|
||||
|
||||
foreach (var plugin in pluginsList)
|
||||
{
|
||||
_plugins[plugin.PluginName] = plugin;
|
||||
CreateMenuItem(plugin.PluginName);
|
||||
}
|
||||
}
|
||||
string pluginsDir = Directory.GetParent(Directory.GetCurrentDirectory())!.Parent!.Parent!.Parent!.FullName + "\\Plugins";
|
||||
|
||||
string[] dllFiles = Directory.GetFiles(pluginsDir, "*.dll", SearchOption.AllDirectories);
|
||||
|
||||
private List<IPluginsConvention> GetPlugins()
|
||||
{
|
||||
string currentDir = Environment.CurrentDirectory;
|
||||
string pluginsDir = Directory.GetParent(currentDir).Parent.Parent.Parent.FullName + "\\Plugins";
|
||||
string[] dllFiles = Directory.GetFiles(
|
||||
pluginsDir,
|
||||
"*.dll",
|
||||
SearchOption.AllDirectories
|
||||
);
|
||||
List<IPluginsConvention> plugins = new();
|
||||
foreach (string dllFile in dllFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
Assembly assembly = Assembly.LoadFrom(dllFile);
|
||||
Type[] types = assembly.GetTypes();
|
||||
foreach (Type type in types)
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (typeof(IPluginsConvention).IsAssignableFrom(type) && !type.IsInterface)
|
||||
{
|
||||
if (Activator.CreateInstance(type) is IPluginsConvention plugin)
|
||||
{
|
||||
plugins.Add(plugin);
|
||||
}
|
||||
var plugin = (IPluginsConvention)Activator.CreateInstance(type)!;
|
||||
plugins.Add(plugin.PluginName, plugin);
|
||||
CreateMenuItem(plugin.PluginName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
ex.Message
|
||||
);
|
||||
Console.WriteLine($"Îøèáêà ïðè çàãðóçêå ñáîðêè {dllFile}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return plugins;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,11 @@ namespace Components.Components
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null && checkedListBox.Items.Contains(value)) checkedListBox.SelectedItem = value;
|
||||
if (value != null && checkedListBox.Items.Contains(value))
|
||||
{
|
||||
checkedListBox.SelectedItem = value;
|
||||
checkedListBox.SetItemChecked(checkedListBox.SelectedIndex, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,6 +57,7 @@ namespace Components.Components
|
||||
if (index != checkedListBox.SelectedIndex)
|
||||
{
|
||||
checkedListBox.SetItemChecked(index, false);
|
||||
checkedListBox.SetItemChecked(checkedListBox.SelectedIndex, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user