From c761c880ed29a1ecd80dbffaa3d0f340a1ecfa73 Mon Sep 17 00:00:00 2001 From: SpoinkyNL Date: Sun, 7 Jan 2018 14:54:09 +0100 Subject: [PATCH] Added some more plugin architecture (modules are now a type of plugin) --- src/Artemis.Core/Artemis.Core.csproj | 11 +++- src/Artemis.Core/Events/ModuleEventArgs.cs | 4 +- src/Artemis.Core/Models/ModuleInfo.cs | 4 +- .../Modules/Interfaces/IModule.cs | 6 -- src/Artemis.Core/Services/CoreService.cs | 10 +-- .../{IModuleService.cs => IPluginService.cs} | 6 +- .../{ModuleService.cs => PluginService.cs} | 18 +++--- src/Artemis.Modules/TestModule.cs | 8 --- src/Artemis.Modules/app.config | 63 ------------------- .../Abstract/PluginViewModel.cs | 9 +++ .../Artemis.Plugins.csproj} | 24 +++---- src/Artemis.Plugins/Interfaces/IDevice.cs | 6 ++ src/Artemis.Plugins/Interfaces/ILayerType.cs | 6 ++ src/Artemis.Plugins/Interfaces/IModule.cs | 7 +++ src/Artemis.Plugins/Interfaces/IPlugin.cs | 6 ++ .../Interfaces/IPluginViewModel.cs | 8 +++ .../Properties/AssemblyInfo.cs | 9 ++- src/Artemis.Plugins/packages.config | 5 ++ src/Artemis.sln | 10 +-- src/TestModule/TestModule.cs | 8 +++ src/TestModule/TestModuleView.xaml | 10 +++ src/TestModule/TestModuleViewModel.cs | 6 ++ 22 files changed, 122 insertions(+), 122 deletions(-) delete mode 100644 src/Artemis.Core/Modules/Interfaces/IModule.cs rename src/Artemis.Core/Services/Interfaces/{IModuleService.cs => IPluginService.cs} (65%) rename src/Artemis.Core/Services/{ModuleService.cs => PluginService.cs} (88%) delete mode 100644 src/Artemis.Modules/TestModule.cs delete mode 100644 src/Artemis.Modules/app.config create mode 100644 src/Artemis.Plugins/Abstract/PluginViewModel.cs rename src/{Artemis.Modules/Artemis.Modules.csproj => Artemis.Plugins/Artemis.Plugins.csproj} (73%) create mode 100644 src/Artemis.Plugins/Interfaces/IDevice.cs create mode 100644 src/Artemis.Plugins/Interfaces/ILayerType.cs create mode 100644 src/Artemis.Plugins/Interfaces/IModule.cs create mode 100644 src/Artemis.Plugins/Interfaces/IPlugin.cs create mode 100644 src/Artemis.Plugins/Interfaces/IPluginViewModel.cs rename src/{Artemis.Modules => Artemis.Plugins}/Properties/AssemblyInfo.cs (83%) create mode 100644 src/Artemis.Plugins/packages.config create mode 100644 src/TestModule/TestModule.cs create mode 100644 src/TestModule/TestModuleView.xaml create mode 100644 src/TestModule/TestModuleViewModel.cs diff --git a/src/Artemis.Core/Artemis.Core.csproj b/src/Artemis.Core/Artemis.Core.csproj index 8760b66b8..93bb7c259 100644 --- a/src/Artemis.Core/Artemis.Core.csproj +++ b/src/Artemis.Core/Artemis.Core.csproj @@ -185,7 +185,6 @@ - @@ -194,9 +193,9 @@ - + - + @@ -206,6 +205,12 @@ + + + {cd23bc5e-57f0-46ce-a007-24d031146219} + Artemis.Plugins + + diff --git a/src/Artemis.Core/Events/ModuleEventArgs.cs b/src/Artemis.Core/Events/ModuleEventArgs.cs index 8c8c3459a..d2b6fa813 100644 --- a/src/Artemis.Core/Events/ModuleEventArgs.cs +++ b/src/Artemis.Core/Events/ModuleEventArgs.cs @@ -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; } } } \ No newline at end of file diff --git a/src/Artemis.Core/Models/ModuleInfo.cs b/src/Artemis.Core/Models/ModuleInfo.cs index e531ef967..e47e98dfe 100644 --- a/src/Artemis.Core/Models/ModuleInfo.cs +++ b/src/Artemis.Core/Models/ModuleInfo.cs @@ -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 SubFiles { get; set; } [JsonIgnore] - public IModule Module { get; set; } + public IPlugin Plugin { get; set; } } } \ No newline at end of file diff --git a/src/Artemis.Core/Modules/Interfaces/IModule.cs b/src/Artemis.Core/Modules/Interfaces/IModule.cs deleted file mode 100644 index d74e24855..000000000 --- a/src/Artemis.Core/Modules/Interfaces/IModule.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Artemis.Core.Modules.Interfaces -{ - public interface IModule - { - } -} \ No newline at end of file diff --git a/src/Artemis.Core/Services/CoreService.cs b/src/Artemis.Core/Services/CoreService.cs index d5cb56a48..ca61b1c68 100644 --- a/src/Artemis.Core/Services/CoreService.cs +++ b/src/Artemis.Core/Services/CoreService.cs @@ -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; } diff --git a/src/Artemis.Core/Services/Interfaces/IModuleService.cs b/src/Artemis.Core/Services/Interfaces/IPluginService.cs similarity index 65% rename from src/Artemis.Core/Services/Interfaces/IModuleService.cs rename to src/Artemis.Core/Services/Interfaces/IPluginService.cs index 47dd57750..ea83d4050 100644 --- a/src/Artemis.Core/Services/Interfaces/IModuleService.cs +++ b/src/Artemis.Core/Services/Interfaces/IPluginService.cs @@ -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 ModuleLoaded; event EventHandler ModuleReloaded; diff --git a/src/Artemis.Core/Services/ModuleService.cs b/src/Artemis.Core/Services/PluginService.cs similarity index 88% rename from src/Artemis.Core/Services/ModuleService.cs rename to src/Artemis.Core/Services/PluginService.cs index b2f48e14c..839dc12a9 100644 --- a/src/Artemis.Core/Services/ModuleService.cs +++ b/src/Artemis.Core/Services/PluginService.cs @@ -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 _modules; + private readonly List _modules; - public ModuleService() + public PluginService() { - _modules = new List(); + _modules = new List(); if (!Directory.Exists(Constants.DataFolder + "modules")) Directory.CreateDirectory(Constants.DataFolder + "modules"); } public bool LoadingModules { get; private set; } - public ReadOnlyCollection Modules => _modules.AsReadOnly(); + public ReadOnlyCollection Modules => _modules.AsReadOnly(); /// /// 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 LoadModuleFromFolder(string folder) + private async Task LoadModuleFromFolder(string folder) { if (!folder.EndsWith("\\")) folder += "\\"; @@ -67,7 +67,7 @@ namespace Artemis.Core.Services var moduleInfo = JsonConvert.DeserializeObject(File.ReadAllText(folder + "module.json")); // Load the main module which will contain a class implementing IModule - var module = await CSScript.Evaluator.LoadFileAsync(folder + moduleInfo.MainFile); + var module = await CSScript.Evaluator.LoadFileAsync(folder + moduleInfo.MainFile); return module; } diff --git a/src/Artemis.Modules/TestModule.cs b/src/Artemis.Modules/TestModule.cs deleted file mode 100644 index 2fec3d455..000000000 --- a/src/Artemis.Modules/TestModule.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Artemis.Core.Modules.Interfaces; - -namespace Artemis.Modules -{ - public class TestModule : IModule - { - } -} \ No newline at end of file diff --git a/src/Artemis.Modules/app.config b/src/Artemis.Modules/app.config deleted file mode 100644 index c1979efa0..000000000 --- a/src/Artemis.Modules/app.config +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Artemis.Plugins/Abstract/PluginViewModel.cs b/src/Artemis.Plugins/Abstract/PluginViewModel.cs new file mode 100644 index 000000000..269cb1869 --- /dev/null +++ b/src/Artemis.Plugins/Abstract/PluginViewModel.cs @@ -0,0 +1,9 @@ +using Artemis.Plugins.Interfaces; +using Stylet; + +namespace Artemis.Plugins.Abstract +{ + public abstract class PluginViewModel : Screen, IPluginViewModel + { + } +} \ No newline at end of file diff --git a/src/Artemis.Modules/Artemis.Modules.csproj b/src/Artemis.Plugins/Artemis.Plugins.csproj similarity index 73% rename from src/Artemis.Modules/Artemis.Modules.csproj rename to src/Artemis.Plugins/Artemis.Plugins.csproj index ddb2f94ca..4bc6760f5 100644 --- a/src/Artemis.Modules/Artemis.Modules.csproj +++ b/src/Artemis.Plugins/Artemis.Plugins.csproj @@ -4,11 +4,11 @@ Debug AnyCPU - {6B62C017-8ED8-4076-BDF9-555918266D43} + {CD23BC5E-57F0-46CE-A007-24D031146219} Library Properties - Artemis.Modules - Artemis.Modules + Artemis.Plugins + Artemis.Plugins v4.6 512 @@ -30,6 +30,9 @@ 4 + + ..\packages\Stylet.1.1.21\lib\net45\Stylet.dll + @@ -40,17 +43,16 @@ - + + + + + + - - {9b811f9b-86b9-4771-87af-72bae7078a36} - Artemis.Core - - - - + \ No newline at end of file diff --git a/src/Artemis.Plugins/Interfaces/IDevice.cs b/src/Artemis.Plugins/Interfaces/IDevice.cs new file mode 100644 index 000000000..b6508af47 --- /dev/null +++ b/src/Artemis.Plugins/Interfaces/IDevice.cs @@ -0,0 +1,6 @@ +namespace Artemis.Plugins.Interfaces +{ + public interface IDevice : IPlugin + { + } +} \ No newline at end of file diff --git a/src/Artemis.Plugins/Interfaces/ILayerType.cs b/src/Artemis.Plugins/Interfaces/ILayerType.cs new file mode 100644 index 000000000..012322ce5 --- /dev/null +++ b/src/Artemis.Plugins/Interfaces/ILayerType.cs @@ -0,0 +1,6 @@ +namespace Artemis.Plugins.Interfaces +{ + public interface ILayerType : IPlugin + { + } +} \ No newline at end of file diff --git a/src/Artemis.Plugins/Interfaces/IModule.cs b/src/Artemis.Plugins/Interfaces/IModule.cs new file mode 100644 index 000000000..377ad9c6e --- /dev/null +++ b/src/Artemis.Plugins/Interfaces/IModule.cs @@ -0,0 +1,7 @@ +namespace Artemis.Plugins.Interfaces +{ + public interface IModule : IPlugin + { + IPluginViewModel GetMainViewModel(); + } +} \ No newline at end of file diff --git a/src/Artemis.Plugins/Interfaces/IPlugin.cs b/src/Artemis.Plugins/Interfaces/IPlugin.cs new file mode 100644 index 000000000..8fdba572c --- /dev/null +++ b/src/Artemis.Plugins/Interfaces/IPlugin.cs @@ -0,0 +1,6 @@ +namespace Artemis.Plugins.Interfaces +{ + public interface IPlugin + { + } +} \ No newline at end of file diff --git a/src/Artemis.Plugins/Interfaces/IPluginViewModel.cs b/src/Artemis.Plugins/Interfaces/IPluginViewModel.cs new file mode 100644 index 000000000..9ba9cf6d1 --- /dev/null +++ b/src/Artemis.Plugins/Interfaces/IPluginViewModel.cs @@ -0,0 +1,8 @@ +using Stylet; + +namespace Artemis.Plugins.Interfaces +{ + public interface IPluginViewModel : IScreen + { + } +} \ No newline at end of file diff --git a/src/Artemis.Modules/Properties/AssemblyInfo.cs b/src/Artemis.Plugins/Properties/AssemblyInfo.cs similarity index 83% rename from src/Artemis.Modules/Properties/AssemblyInfo.cs rename to src/Artemis.Plugins/Properties/AssemblyInfo.cs index 16670c999..ab66f94cf 100644 --- a/src/Artemis.Modules/Properties/AssemblyInfo.cs +++ b/src/Artemis.Plugins/Properties/AssemblyInfo.cs @@ -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")] \ No newline at end of file diff --git a/src/Artemis.Plugins/packages.config b/src/Artemis.Plugins/packages.config new file mode 100644 index 000000000..0ef55cc6d --- /dev/null +++ b/src/Artemis.Plugins/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/Artemis.sln b/src/Artemis.sln index 7abd68f90..58e1f8529 100644 --- a/src/Artemis.sln +++ b/src/Artemis.sln @@ -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 diff --git a/src/TestModule/TestModule.cs b/src/TestModule/TestModule.cs new file mode 100644 index 000000000..c8dae1f71 --- /dev/null +++ b/src/TestModule/TestModule.cs @@ -0,0 +1,8 @@ +using Artemis.Core.Plugins.Interfaces; + +namespace TestModule +{ + public class TestModule : IModule + { + } +} \ No newline at end of file diff --git a/src/TestModule/TestModuleView.xaml b/src/TestModule/TestModuleView.xaml new file mode 100644 index 000000000..bc034ce86 --- /dev/null +++ b/src/TestModule/TestModuleView.xaml @@ -0,0 +1,10 @@ + + + \ No newline at end of file diff --git a/src/TestModule/TestModuleViewModel.cs b/src/TestModule/TestModuleViewModel.cs new file mode 100644 index 000000000..69dfdeded --- /dev/null +++ b/src/TestModule/TestModuleViewModel.cs @@ -0,0 +1,6 @@ +namespace TestModule +{ + public class TestModuleViewModel + { + } +} \ No newline at end of file