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