diff --git a/src/Artemis.Plugins/Models/PluginInfo.cs b/src/Artemis.Plugins/Models/PluginInfo.cs index 6a1beb21a..9c4663e99 100644 --- a/src/Artemis.Plugins/Models/PluginInfo.cs +++ b/src/Artemis.Plugins/Models/PluginInfo.cs @@ -62,7 +62,7 @@ namespace Artemis.Plugins.Models var pluginInfo = JsonConvert.DeserializeObject(File.ReadAllText(folder + "plugin.json")); pluginInfo.Folder = folder; - // Load the main plugin which will contain a class implementing IPlugin + // Load the main script and get the type var assembly = await CSScript.Evaluator.CompileCodeAsync(File.ReadAllText(folder + pluginInfo.Main)); var pluginType = assembly.GetTypes().Where(t => typeof(IPlugin).IsAssignableFrom(t)).ToList(); if (!pluginType.Any()) @@ -70,6 +70,7 @@ namespace Artemis.Plugins.Models if (pluginType.Count > 1) throw new ArtemisPluginException(pluginInfo, "Failed to load plugin, more than one type found that implements IPlugin"); + // Instantiate the plugin with Ninject pluginInfo.Plugin = (IPlugin) kernel.Get(pluginType.First()); pluginInfo.Plugin.LoadPlugin(); @@ -93,5 +94,25 @@ namespace Artemis.Plugins.Models public void Dispose() { } + + public async Task GetModuleViewModel(IKernel kernel) + { + // Don't attempt to locave VMs for something other than a module + if (Plugin is IModule) + throw new ArtemisPluginException(this, "Cannot locate a view model for this plugin as it's not a module."); + + // Compile the ViewModel script and get the type + var assembly = await CSScript.Evaluator.CompileCodeAsync(File.ReadAllText(Folder + ViewModel)); + var vmType = assembly.GetTypes().Where(t => typeof(IModuleViewModel).IsAssignableFrom(t)).ToList(); + if (!vmType.Any()) + throw new ArtemisPluginException(this, "Failed to load plugin, no type found that implements IModuleViewModel"); + if (vmType.Count > 1) + throw new ArtemisPluginException(this, "Failed to load plugin, more than one type found that implements IModuleViewModel"); + + // Instantiate the ViewModel with Ninject + var vm = (IModuleViewModel)kernel.Get(vmType.First()); + vm.PluginInfo = this; + return vm; + } } } \ No newline at end of file diff --git a/src/Artemis.sln b/src/Artemis.sln index 58e1f8529..1b2bdc39f 100644 --- a/src/Artemis.sln +++ b/src/Artemis.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26730.12 +VisualStudioVersion = 15.0.27130.2036 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Artemis.UI", "Artemis.UI\Artemis.UI.csproj", "{46B74153-77CF-4489-BDF9-D53FDB1F7ACB}" EndProject @@ -11,6 +11,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Artemis.Core", "Artemis.Cor EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Artemis.Plugins", "Artemis.Plugins\Artemis.Plugins.csproj", "{CD23BC5E-57F0-46CE-A007-24D031146219}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{FAF4C738-F49C-490B-9134-57598FF5358C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Module.General", "Module.General\Module.General.csproj", "{58113CC5-A9CA-4EC3-AB4E-3C94B99268D8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,10 +37,17 @@ Global {CD23BC5E-57F0-46CE-A007-24D031146219}.Debug|Any CPU.Build.0 = Debug|Any CPU {CD23BC5E-57F0-46CE-A007-24D031146219}.Release|Any CPU.ActiveCfg = Release|Any CPU {CD23BC5E-57F0-46CE-A007-24D031146219}.Release|Any CPU.Build.0 = Release|Any CPU + {58113CC5-A9CA-4EC3-AB4E-3C94B99268D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {58113CC5-A9CA-4EC3-AB4E-3C94B99268D8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {58113CC5-A9CA-4EC3-AB4E-3C94B99268D8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {58113CC5-A9CA-4EC3-AB4E-3C94B99268D8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {58113CC5-A9CA-4EC3-AB4E-3C94B99268D8} = {FAF4C738-F49C-490B-9134-57598FF5358C} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C203080A-4473-4CC2-844B-F552EA43D66A} EndGlobalSection diff --git a/src/Module.General/Module.General.csproj b/src/Module.General/Module.General.csproj index 919ad00c0..4fe843fc0 100644 --- a/src/Module.General/Module.General.csproj +++ b/src/Module.General/Module.General.csproj @@ -9,8 +9,9 @@ Properties Artemis.BuiltIn.Module.General Module.General - v4.6.1 + v4.6 512 + true @@ -65,5 +66,8 @@ MSBuild:Compile + + + \ No newline at end of file diff --git a/src/Module.General/app.config b/src/Module.General/app.config index c27651ac4..4d7b27125 100644 --- a/src/Module.General/app.config +++ b/src/Module.General/app.config @@ -1,39 +1,39 @@ - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - \ No newline at end of file +