Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PluginManager: Update PluginManager to handle runtime compiled plugins #2462

Merged
merged 1 commit into from Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Plugin/Plugin.cs
Expand Up @@ -15,6 +15,8 @@ public abstract class Plugin
public Assembly Assembly = null;

public PluginHost Host { get; internal set; }
public string FileName { get; set; } //contains the filename of the plugin (.dll or .cs)


public abstract string Name { get; }
public abstract string Version { get; }
Expand Down
16 changes: 12 additions & 4 deletions Plugin/PluginLoader.cs
Expand Up @@ -125,12 +125,12 @@ public static void Load(String file)
return;
}

InitPlugin(asm);
InitPlugin(asm, file);

log.InfoFormat("Plugin Load {0} time {1} s", file, (DateTime.Now - startDateTime).TotalSeconds);
}

public static void InitPlugin(Assembly asm)
public static void InitPlugin(Assembly asm, string pluginfilename)
{
if (asm == null)
return;
Expand All @@ -156,6 +156,7 @@ public static void InitPlugin(Assembly asm)
plugin.Assembly = asm;

plugin.Host = new PluginHost();
plugin.FileName = Path.GetFileName(pluginfilename);

if (plugin.Init())
{
Expand Down Expand Up @@ -191,6 +192,13 @@ public static void LoadAll()
foreach (var csFile in csFiles)
{
log.Info("Plugin: " + csFile);
//Check if it is disabled (moved out from the previous IF, to make it loggable)
if (DisabledPluginNames.Contains(Path.GetFileName(csFile).ToLower()))
{
log.InfoFormat("Plugin {0} is disabled in config.xml", Path.GetFileName(csFile));
continue;
}


try
{
Expand All @@ -203,7 +211,7 @@ public static void LoadAll()
// compile the code into an assembly
var results = CodeGen.CompileCodeFile(compiler, parms, csFile);

InitPlugin(results?.CompiledAssembly);
InitPlugin(results?.CompiledAssembly, Path.GetFileName(csFile));

if (results?.CompiledAssembly != null)
continue;
Expand All @@ -218,7 +226,7 @@ public static void LoadAll()
// csharp 8
var ans = CodeGenRoslyn.BuildCode(csFile);

InitPlugin(ans);
InitPlugin(ans, Path.GetFileName(csFile));

continue;
}
Expand Down
29 changes: 7 additions & 22 deletions Plugin/PluginUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Plugin/PluginUI.cs
Expand Up @@ -38,8 +38,8 @@ private void PopulateGridView()
row.Cells["pluginName"].Value = p.Name;
row.Cells["pluginAuthor"].Value = p.Author;
row.Cells["pluginVersion"].Value = p.Version;
row.Cells["pluginDll"].Value = Path.GetFileName(p.Assembly.Location).ToLower();
bool bEnabled = !Plugin.PluginLoader.DisabledPluginNames.Contains(Path.GetFileName(p.Assembly.Location), StringComparer.OrdinalIgnoreCase);
row.Cells["pluginDll"].Value = p.FileName.ToLower();
bool bEnabled = !Plugin.PluginLoader.DisabledPluginNames.Contains(p.FileName, StringComparer.OrdinalIgnoreCase);
row.Cells["pluginEnabled"].Value = bEnabled;
if (bEnabled) row.DefaultCellStyle.BackColor = Color.Green;
else row.DefaultCellStyle.BackColor = Color.DarkOrange;
Expand All @@ -52,7 +52,7 @@ private void PopulateGridView()
bool isLoaded = false;

foreach (Plugin.Plugin p in Plugin.PluginLoader.Plugins)
if (Path.GetFileName(p.Assembly.Location).ToLower().Contains(s)) isLoaded = true;
if (p.FileName.ToLower().Contains(s)) isLoaded = true;

if (File.Exists(path + s) && !isLoaded)
{
Expand Down Expand Up @@ -95,6 +95,8 @@ private void ResizeFormForDataGrid()
Control vertical = dgvPlugins.Controls[1];
dgvPlugins.Width = dgvPlugins.PreferredSize.Width - vertical.Width + 1;
this.Width = dgvPlugins.Width + 15;
this.Height = dgvPlugins.PreferredSize.Height + 80;
//this.Height = dgvPlugins.RowCount * 30 + 40;
this.ResumeLayout(true);
}

Expand All @@ -107,7 +109,6 @@ private void dgvPlugins_SelectionChanged(object sender, EventArgs e)
{
int selectedRow = dgvPlugins.CurrentCell.RowIndex;
string r = (string)dgvPlugins.Rows[selectedRow].Cells["pluginName"].Value;
if (r != null) btnLoadPlugin.Enabled = r.ToLower().Contains("not loaded");
}

private void btnLoadPlugin_Click(object sender, EventArgs e)
Expand Down