mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Rely on CS-Script includes for modules view model matching
This commit is contained in:
1 parent
34b9c81df7
commit
9ad3e04a69
21 files changed
+301
-81
No files matched your search
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using Artemis.Plugins.Interfaces;
|
||||
|
||||
namespace Artemis.Plugins.Abstract
|
||||
{
|
||||
public abstract class ProfileModule : IModule
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public abstract Type ViewModelType { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public abstract bool ExpandsMainDataModel { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void LoadPlugin()
|
||||
{
|
||||
// Load and activate the last active profile
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void UnloadPlugin()
|
||||
{
|
||||
// Unload the last active profile
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Update(double deltaTime)
|
||||
{
|
||||
// Update the profile
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Render(double deltaTime)
|
||||
{
|
||||
// Render the profile
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@
|
||||
<AssemblyName>Artemis.Plugins</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -33,17 +35,17 @@
|
||||
<Reference Include="CSScriptLibrary, Version=3.28.0.0, Culture=neutral, PublicKeyToken=70fcc3d18c749033, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\CS-Script.bin.3.28.0.1\lib\net46\CSScriptLibrary.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CodeAnalysis, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.CodeAnalysis.Common.2.0.0\lib\netstandard1.3\Microsoft.CodeAnalysis.dll</HintPath>
|
||||
<Reference Include="Microsoft.CodeAnalysis, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.CodeAnalysis.Common.2.6.1\lib\netstandard1.3\Microsoft.CodeAnalysis.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CodeAnalysis.CSharp, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.2.0.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
|
||||
<Reference Include="Microsoft.CodeAnalysis.CSharp, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.2.6.1\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CodeAnalysis.CSharp.Scripting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.Scripting.2.0.0\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.Scripting.dll</HintPath>
|
||||
<Reference Include="Microsoft.CodeAnalysis.CSharp.Scripting, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.Scripting.2.6.1\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.Scripting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CodeAnalysis.Scripting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.CodeAnalysis.Scripting.Common.2.0.0\lib\netstandard1.3\Microsoft.CodeAnalysis.Scripting.dll</HintPath>
|
||||
<Reference Include="Microsoft.CodeAnalysis.Scripting, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.CodeAnalysis.Scripting.Common.2.6.1\lib\netstandard1.3\Microsoft.CodeAnalysis.Scripting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Mono.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\CS-Script.bin.3.28.0.1\lib\net46\Mono.CSharp.dll</HintPath>
|
||||
@@ -135,11 +137,13 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Abstract\ModuleViewModel.cs" />
|
||||
<Compile Include="Abstract\ProfileModule.cs" />
|
||||
<Compile Include="Exceptions\ArtemisPluginException.cs" />
|
||||
<Compile Include="Interfaces\IDataModelExpansion.cs" />
|
||||
<Compile Include="Interfaces\IDevice.cs" />
|
||||
<Compile Include="Interfaces\ILayerType.cs" />
|
||||
<Compile Include="Interfaces\IModule.cs" />
|
||||
<Compile Include="Interfaces\IModuleDataModel.cs" />
|
||||
<Compile Include="Interfaces\IPlugin.cs" />
|
||||
<Compile Include="Interfaces\IModuleViewModel.cs" />
|
||||
<Compile Include="Models\PluginInfo.cs" />
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
/// </summary>
|
||||
public interface IDataModelExpansion : IPlugin
|
||||
{
|
||||
void Update(double deltaTime);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
namespace Artemis.Plugins.Interfaces
|
||||
using System;
|
||||
using Ninject;
|
||||
|
||||
namespace Artemis.Plugins.Interfaces
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
@@ -6,6 +9,17 @@
|
||||
/// </summary>
|
||||
public interface IModule : IPlugin
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of this module's view model
|
||||
/// </summary>
|
||||
Type ViewModelType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Wether or not this module expands upon the main data model. If set to true any data in main data model can be
|
||||
/// accessed by profiles in this module
|
||||
/// </summary>
|
||||
bool ExpandsMainDataModel { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Called each frame when the module must update
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Artemis.Plugins.Interfaces
|
||||
{
|
||||
public interface IModuleDataModel
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -14,6 +13,8 @@ namespace Artemis.Plugins.Models
|
||||
{
|
||||
public class PluginInfo : IDisposable
|
||||
{
|
||||
private static Assembly _assembly;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the plugin
|
||||
/// </summary>
|
||||
@@ -29,11 +30,6 @@ namespace Artemis.Plugins.Models
|
||||
/// </summary>
|
||||
public string Main { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The file implementing IPluginViewModel, loaded when opened in the UI
|
||||
/// </summary>
|
||||
public string ViewModel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The instantiated plugin, available after successful load
|
||||
/// </summary>
|
||||
@@ -46,12 +42,6 @@ namespace Artemis.Plugins.Models
|
||||
[JsonIgnore]
|
||||
public string Folder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates wether this is a built-in plugin.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool IsBuiltIn { get; private set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Plugin.UnloadPlugin();
|
||||
@@ -68,7 +58,7 @@ namespace Artemis.Plugins.Models
|
||||
// Make sure the right engine is used
|
||||
CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom;
|
||||
CSScript.EvaluatorConfig.DebugBuild = true;
|
||||
|
||||
CSScript.GlobalSettings.SearchDirs = folder;
|
||||
if (!folder.EndsWith("\\"))
|
||||
folder += "\\";
|
||||
if (!File.Exists(folder + "plugin.json"))
|
||||
@@ -78,8 +68,8 @@ namespace Artemis.Plugins.Models
|
||||
pluginInfo.Folder = folder;
|
||||
|
||||
// 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();
|
||||
_assembly = await CSScript.Evaluator.CompileCodeAsync(File.ReadAllText(folder + pluginInfo.Main));
|
||||
var pluginType = _assembly.GetTypes().Where(t => typeof(IPlugin).IsAssignableFrom(t)).ToList();
|
||||
if (!pluginType.Any())
|
||||
throw new ArtemisPluginException(pluginInfo, "Failed to load plugin, no type found that implements IPlugin");
|
||||
if (pluginType.Count > 1)
|
||||
@@ -91,33 +81,27 @@ namespace Artemis.Plugins.Models
|
||||
|
||||
return pluginInfo;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the view model of the module accompanying the provided plugin info
|
||||
/// </summary>
|
||||
/// <param name="kernel">The Ninject kernel to use for DI</param>
|
||||
/// <returns></returns>
|
||||
public async Task<IModuleViewModel> GetModuleViewModel(IKernel kernel)
|
||||
public IModuleViewModel GetModuleViewModel(IKernel kernel)
|
||||
{
|
||||
// Make sure the right engine is used
|
||||
CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom;
|
||||
CSScript.EvaluatorConfig.DebugBuild = true;
|
||||
|
||||
// Don't attempt to locave VMs for something other than a module
|
||||
if (!(Plugin is IModule))
|
||||
if (Plugin == null)
|
||||
throw new ArtemisPluginException(this, "Cannot locate a view model for this plugin because it's not compiled.");
|
||||
if (!(Plugin is IModule module))
|
||||
throw new ArtemisPluginException(this, "Cannot locate a view model for this plugin as it's not a module.");
|
||||
|
||||
// Use the plugin's assembly as the VM is precompiled if built in, otherwise compile the VM into a new assembly
|
||||
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");
|
||||
// Get the type from the module
|
||||
var vmType = module.ViewModelType;
|
||||
if (!typeof(IModuleViewModel).IsAssignableFrom(vmType))
|
||||
throw new ArtemisPluginException(this, "ViewModel must implement IModuleViewModel.");
|
||||
|
||||
// Instantiate the ViewModel with Ninject
|
||||
var vm = (IModuleViewModel) kernel.Get(vmType.First());
|
||||
var vm = (IModuleViewModel) kernel.Get(vmType);
|
||||
vm.PluginInfo = this;
|
||||
return vm;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,22 @@
|
||||
<assemblyIdentity name="System.Diagnostics.StackTrace" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.CodeAnalysis.Scripting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.CodeAnalysis" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp.Scripting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.6.0.0" newVersion="2.6.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Console" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -2,10 +2,11 @@
|
||||
<packages>
|
||||
<package id="CS-Script.bin" version="3.28.0.1" targetFramework="net46" />
|
||||
<package id="Microsoft.CodeAnalysis.Analyzers" version="1.1.0" targetFramework="net46" />
|
||||
<package id="Microsoft.CodeAnalysis.Common" version="2.0.0" targetFramework="net46" />
|
||||
<package id="Microsoft.CodeAnalysis.CSharp" version="2.0.0" targetFramework="net46" />
|
||||
<package id="Microsoft.CodeAnalysis.CSharp.Scripting" version="2.0.0" targetFramework="net46" />
|
||||
<package id="Microsoft.CodeAnalysis.Scripting.Common" version="2.0.0" targetFramework="net46" />
|
||||
<package id="Microsoft.CodeAnalysis.Common" version="2.6.1" targetFramework="net46" />
|
||||
<package id="Microsoft.CodeAnalysis.CSharp" version="2.6.1" targetFramework="net46" />
|
||||
<package id="Microsoft.CodeAnalysis.CSharp.Scripting" version="2.6.1" targetFramework="net46" />
|
||||
<package id="Microsoft.CodeAnalysis.Scripting" version="2.6.1" targetFramework="net46" />
|
||||
<package id="Microsoft.CodeAnalysis.Scripting.Common" version="2.6.1" targetFramework="net46" />
|
||||
<package id="Newtonsoft.Json" version="11.0.1" targetFramework="net46" />
|
||||
<package id="Ninject" version="3.3.4" targetFramework="net46" />
|
||||
<package id="Stylet" version="1.1.21" targetFramework="net46" />
|
||||
|
||||
Reference in new issue
Block a user