1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Added some more plugin architecture (modules are now a type of plugin)

This commit is contained in:
SpoinkyNL 2018-01-07 14:54:09 +01:00
parent f093520ce8
commit c761c880ed
22 changed files with 122 additions and 122 deletions

View File

@ -185,7 +185,6 @@
<Compile Include="Exceptions\ArtemisCoreException.cs" />
<Compile Include="Exceptions\ArtemisModuleException.cs" />
<Compile Include="Models\ModuleInfo.cs" />
<Compile Include="Modules\Interfaces\IModule.cs" />
<Compile Include="Ninject\CoreModule.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Scripting.evaluator.cs" />
@ -194,9 +193,9 @@
<Compile Include="Services\CoreService.cs" />
<Compile Include="Services\Interfaces\IArtemisService.cs" />
<Compile Include="Services\Interfaces\ICoreService.cs" />
<Compile Include="Services\Interfaces\IModuleService.cs" />
<Compile Include="Services\Interfaces\IPluginService.cs" />
<Compile Include="Events\ModuleEventArgs.cs" />
<Compile Include="Services\ModuleService.cs" />
<Compile Include="Services\PluginService.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
@ -206,6 +205,12 @@
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Artemis.Plugins\Artemis.Plugins.csproj">
<Project>{cd23bc5e-57f0-46ce-a007-24d031146219}</Project>
<Name>Artemis.Plugins</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\RGB.NET.Devices.Asus.0.0.1.20\build\net45\RGB.NET.Devices.Asus.targets" Condition="Exists('..\packages\RGB.NET.Devices.Asus.0.0.1.20\build\net45\RGB.NET.Devices.Asus.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

View File

@ -1,9 +1,9 @@
using Artemis.Core.Modules.Interfaces;
using Artemis.Core.Plugins.Interfaces;
namespace Artemis.Core.Events
{
public class ModuleEventArgs : System.EventArgs
{
public IModule Module { get; set; }
public IPlugin Plugin { get; set; }
}
}

View File

@ -1,5 +1,5 @@
using System.Collections.Generic;
using Artemis.Core.Modules.Interfaces;
using Artemis.Core.Plugins.Interfaces;
using Newtonsoft.Json;
namespace Artemis.Core.Models
@ -12,6 +12,6 @@ namespace Artemis.Core.Models
public IReadOnlyList<string> SubFiles { get; set; }
[JsonIgnore]
public IModule Module { get; set; }
public IPlugin Plugin { get; set; }
}
}

View File

@ -1,6 +0,0 @@
namespace Artemis.Core.Modules.Interfaces
{
public interface IModule
{
}
}

View File

@ -5,24 +5,24 @@ namespace Artemis.Core.Services
{
public class CoreService : ICoreService
{
private readonly IModuleService _moduleService;
private readonly IPluginService _pluginService;
public CoreService(IModuleService moduleService)
public CoreService(IPluginService pluginService)
{
_moduleService = moduleService;
_pluginService = pluginService;
Task.Run(Initialize);
}
public void Dispose()
{
_moduleService.Dispose();
_pluginService.Dispose();
}
public bool IsInitialized { get; set; }
private async Task Initialize()
{
await _moduleService.LoadModules();
await _pluginService.LoadModules();
IsInitialized = true;
}

View File

@ -1,14 +1,14 @@
using System;
using System.Threading.Tasks;
using Artemis.Core.Events;
using Artemis.Core.Modules.Interfaces;
using Artemis.Plugins.Interfaces;
namespace Artemis.Core.Services.Interfaces
{
public interface IModuleService : IArtemisService, IDisposable
public interface IPluginService : IArtemisService, IDisposable
{
Task LoadModules();
Task ReloadModule(IModule module);
Task ReloadModule(IPlugin plugin);
event EventHandler<ModuleEventArgs> ModuleLoaded;
event EventHandler<ModuleEventArgs> ModuleReloaded;

View File

@ -6,27 +6,27 @@ using System.Threading.Tasks;
using Artemis.Core.Events;
using Artemis.Core.Exceptions;
using Artemis.Core.Models;
using Artemis.Core.Modules.Interfaces;
using Artemis.Core.Services.Interfaces;
using Artemis.Plugins.Interfaces;
using CSScriptLibrary;
using Newtonsoft.Json;
namespace Artemis.Core.Services
{
public class ModuleService : IModuleService
public class PluginService : IPluginService
{
private readonly List<IModule> _modules;
private readonly List<IPlugin> _modules;
public ModuleService()
public PluginService()
{
_modules = new List<IModule>();
_modules = new List<IPlugin>();
if (!Directory.Exists(Constants.DataFolder + "modules"))
Directory.CreateDirectory(Constants.DataFolder + "modules");
}
public bool LoadingModules { get; private set; }
public ReadOnlyCollection<IModule> Modules => _modules.AsReadOnly();
public ReadOnlyCollection<IPlugin> Modules => _modules.AsReadOnly();
/// <summary>
/// Loads all installed modules. If modules already loaded this will reload them all
@ -50,7 +50,7 @@ namespace Artemis.Core.Services
OnFinishedLoadedModules();
}
public async Task ReloadModule(IModule module)
public async Task ReloadModule(IPlugin plugin)
{
}
@ -58,7 +58,7 @@ namespace Artemis.Core.Services
{
}
private async Task<IModule> LoadModuleFromFolder(string folder)
private async Task<IPlugin> LoadModuleFromFolder(string folder)
{
if (!folder.EndsWith("\\"))
folder += "\\";
@ -67,7 +67,7 @@ namespace Artemis.Core.Services
var moduleInfo = JsonConvert.DeserializeObject<ModuleInfo>(File.ReadAllText(folder + "module.json"));
// Load the main module which will contain a class implementing IModule
var module = await CSScript.Evaluator.LoadFileAsync<IModule>(folder + moduleInfo.MainFile);
var module = await CSScript.Evaluator.LoadFileAsync<IPlugin>(folder + moduleInfo.MainFile);
return module;
}

View File

@ -1,8 +0,0 @@
using Artemis.Core.Modules.Interfaces;
namespace Artemis.Modules
{
public class TestModule : IModule
{
}
}

View File

@ -1,63 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.3.4.0" newVersion="3.3.4.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="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.2.0" newVersion="1.2.2.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.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.4.2.0" newVersion="1.4.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Xml.XPath.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.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>
<dependentAssembly>
<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>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -0,0 +1,9 @@
using Artemis.Plugins.Interfaces;
using Stylet;
namespace Artemis.Plugins.Abstract
{
public abstract class PluginViewModel : Screen, IPluginViewModel
{
}
}

View File

@ -4,11 +4,11 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6B62C017-8ED8-4076-BDF9-555918266D43}</ProjectGuid>
<ProjectGuid>{CD23BC5E-57F0-46CE-A007-24D031146219}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Artemis.Modules</RootNamespace>
<AssemblyName>Artemis.Modules</AssemblyName>
<RootNamespace>Artemis.Plugins</RootNamespace>
<AssemblyName>Artemis.Plugins</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
@ -30,6 +30,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Stylet, Version=1.1.21.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Stylet.1.1.21\lib\net45\Stylet.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@ -40,17 +43,16 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="TestModule.cs" />
<Compile Include="Abstract\PluginViewModel.cs" />
<Compile Include="Interfaces\IDevice.cs" />
<Compile Include="Interfaces\ILayerType.cs" />
<Compile Include="Interfaces\IModule.cs" />
<Compile Include="Interfaces\IPlugin.cs" />
<Compile Include="Interfaces\IPluginViewModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Artemis.Core\Artemis.Core.csproj">
<Project>{9b811f9b-86b9-4771-87af-72bae7078a36}</Project>
<Name>Artemis.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,6 @@
namespace Artemis.Plugins.Interfaces
{
public interface IDevice : IPlugin
{
}
}

View File

@ -0,0 +1,6 @@
namespace Artemis.Plugins.Interfaces
{
public interface ILayerType : IPlugin
{
}
}

View File

@ -0,0 +1,7 @@
namespace Artemis.Plugins.Interfaces
{
public interface IModule : IPlugin
{
IPluginViewModel GetMainViewModel();
}
}

View File

@ -0,0 +1,6 @@
namespace Artemis.Plugins.Interfaces
{
public interface IPlugin
{
}
}

View File

@ -0,0 +1,8 @@
using Stylet;
namespace Artemis.Plugins.Interfaces
{
public interface IPluginViewModel : IScreen
{
}
}

View File

@ -1,15 +1,14 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Artemis.Modules")]
[assembly: AssemblyTitle("Artemis.Plugins")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Artemis.Modules")]
[assembly: AssemblyProduct("Artemis.Plugins")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -20,7 +19,7 @@ using System.Runtime.InteropServices;
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6b62c017-8ed8-4076-bdf9-555918266d43")]
[assembly: Guid("cd23bc5e-57f0-46ce-a007-24d031146219")]
// Version information for an assembly consists of the following four values:
//
@ -33,4 +32,4 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Stylet" version="1.1.21" targetFramework="net46" />
</packages>

View File

@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Artemis.Storage", "Artemis.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Artemis.Core", "Artemis.Core\Artemis.Core.csproj", "{9B811F9B-86B9-4771-87AF-72BAE7078A36}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Artemis.Modules", "Artemis.Modules\Artemis.Modules.csproj", "{6B62C017-8ED8-4076-BDF9-555918266D43}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Artemis.Plugins", "Artemis.Plugins\Artemis.Plugins.csproj", "{CD23BC5E-57F0-46CE-A007-24D031146219}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -29,10 +29,10 @@ Global
{9B811F9B-86B9-4771-87AF-72BAE7078A36}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B811F9B-86B9-4771-87AF-72BAE7078A36}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B811F9B-86B9-4771-87AF-72BAE7078A36}.Release|Any CPU.Build.0 = Release|Any CPU
{6B62C017-8ED8-4076-BDF9-555918266D43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B62C017-8ED8-4076-BDF9-555918266D43}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B62C017-8ED8-4076-BDF9-555918266D43}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B62C017-8ED8-4076-BDF9-555918266D43}.Release|Any CPU.Build.0 = Release|Any CPU
{CD23BC5E-57F0-46CE-A007-24D031146219}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,8 @@
using Artemis.Core.Plugins.Interfaces;
namespace TestModule
{
public class TestModule : IModule
{
}
}

View File

@ -0,0 +1,10 @@
<UserControl x:Class="TestModule.TestModuleView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TestModule"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid />
</UserControl>

View File

@ -0,0 +1,6 @@
namespace TestModule
{
public class TestModuleViewModel
{
}
}