diff --git a/CRSim.Core/CRSim.Core.csproj b/CRSim.Core/CRSim.Core.csproj index e50c54b..df37937 100644 --- a/CRSim.Core/CRSim.Core.csproj +++ b/CRSim.Core/CRSim.Core.csproj @@ -6,6 +6,8 @@ enable enable AnyCPU;x64 + CRSim.Core + True diff --git a/CRSim.Core/Services/PluginService.cs b/CRSim.Core/Services/PluginService.cs index c575f26..515b18f 100644 --- a/CRSim.Core/Services/PluginService.cs +++ b/CRSim.Core/Services/PluginService.cs @@ -49,13 +49,12 @@ public class PluginService : IPluginService PluginManifest manifest = new(); try { - Console.WriteLine(manifestYaml); manifest = JsonSerializer.Deserialize(manifestYaml,JsonContextWithCamelCase.Default.PluginManifest); - Console.WriteLine("成功解析YAML文件: " + manifestPath); + Console.WriteLine("成功解析JSON文件: " + manifestPath); } catch (Exception ex) { - Console.WriteLine("YAML解析失败"); + Console.WriteLine("JSON解析失败"); Console.WriteLine(ex.ToString()); continue; } @@ -91,8 +90,9 @@ public class PluginService : IPluginService { Console.WriteLine("尝试加载插件: " + manifest.Id); var fullPath = Path.GetFullPath(Path.Combine(pluginDir, manifest.EntranceAssembly)); - var asm = Assembly.LoadFrom(fullPath); - var entrance = asm.ExportedTypes.FirstOrDefault(x => + var loadContext = new PluginLoadContext(fullPath); + var assembly = loadContext.LoadFromAssemblyPath(fullPath); + var entrance = assembly.ExportedTypes.FirstOrDefault(x => x.BaseType == typeof(PluginBase) || x.GetCustomAttributes().FirstOrDefault(a => a.GetType() == typeof(PluginEntrance)) != null); diff --git a/CRSim.Core/Utils/PluginLoadContext.cs b/CRSim.Core/Utils/PluginLoadContext.cs new file mode 100644 index 0000000..8ce9894 --- /dev/null +++ b/CRSim.Core/Utils/PluginLoadContext.cs @@ -0,0 +1,21 @@ +锘縰sing System.Reflection; +using System.Runtime.Loader; + +namespace CRSim.Core.Utils +{ + internal class PluginLoadContext(string pluginPath) : AssemblyLoadContext + { + private readonly AssemblyDependencyResolver _resolver = new(pluginPath); + + protected override Assembly Load(AssemblyName assemblyName) + { + string assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName); + if (assemblyPath != null) + { + return LoadFromAssemblyPath(assemblyPath); + } + + return null; + } + } +} diff --git a/CRSim.ExamplePlugin/CRSim.ExamplePlugin.csproj b/CRSim.ExamplePlugin/CRSim.ExamplePlugin.csproj deleted file mode 100644 index fe37ee7..0000000 --- a/CRSim.ExamplePlugin/CRSim.ExamplePlugin.csproj +++ /dev/null @@ -1,33 +0,0 @@ -锘 - - net9.0-windows10.0.19041.0 - 10.0.19041.0 - CRSim.ExamplePlugin - win-x86;win-x64;win-arm64 - True - true - AnyCPU;x64 - enable - enable - - - - runtime - - - runtime - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - - \ No newline at end of file diff --git a/CRSim.ExamplePlugin/Plugin.cs b/CRSim.ExamplePlugin/Plugin.cs deleted file mode 100644 index d80be26..0000000 --- a/CRSim.ExamplePlugin/Plugin.cs +++ /dev/null @@ -1,21 +0,0 @@ -锘縰sing CRSim.Core.Abstractions; -using CRSim.Core.Attributes; -using CRSim.ExamplePlugin.ViewModels; -using CRSim.ExamplePlugin.Views; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using System; - -namespace CRSim.ExamplePlugin; - -[PluginEntrance] -public class Plugin : PluginBase -{ - public override Type ViewModel => typeof(ScreenViewModel); - public override Type View => typeof(ScreenView); - public override void Initialize(HostBuilderContext context, IServiceCollection services) - { - services.AddTransient(ViewModel); - services.AddTransient(View); - } -} \ No newline at end of file diff --git a/CRSim.ExamplePlugin/Properties/launchSettings.json b/CRSim.ExamplePlugin/Properties/launchSettings.json deleted file mode 100644 index 4c2cd5f..0000000 --- a/CRSim.ExamplePlugin/Properties/launchSettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "profiles": { - "CRSim 鎻掍欢": { - "commandName": "Executable", - "executablePath": "$(CRSim_DebugBinaryFile)", - "commandLineArgs": "-epp $(TargetDir) -debug", - "workingDirectory": "$(CRSim_DebugBinaryDirectory)", - "nativeDebugging": true - } - } -} \ No newline at end of file diff --git a/CRSim.ExamplePlugin/ViewModels/ScreenViewModel.cs b/CRSim.ExamplePlugin/ViewModels/ScreenViewModel.cs deleted file mode 100644 index c035da7..0000000 --- a/CRSim.ExamplePlugin/ViewModels/ScreenViewModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -锘縰sing CRSim.Core.Models; -using CRSim.Core.Abstractions; -using CRSim.ScreenSimulator.ViewModels; -namespace CRSim.ExamplePlugin.ViewModels -{ - public class ScreenViewModel : BaseScreenViewModel - { - public ScreenViewModel(ITimeService timeService, ISettingsService settingsService) - : base(timeService, settingsService) - { - Text = "鎴愰兘閾佽矾瀹㈡湇鐢佃瘽锛028-12306"; - ItemsPerPage = 12; - ScreenCount = 1; - StationType = StationType.Departure; - } - } -} diff --git a/CRSim.ExamplePlugin/Views/ScreenView.xaml b/CRSim.ExamplePlugin/Views/ScreenView.xaml deleted file mode 100644 index 12302b6..0000000 --- a/CRSim.ExamplePlugin/Views/ScreenView.xaml +++ /dev/null @@ -1,134 +0,0 @@ -锘 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/CRSim.ExamplePlugin/Views/ScreenView.xaml.cs b/CRSim.ExamplePlugin/Views/ScreenView.xaml.cs deleted file mode 100644 index 9c57c51..0000000 --- a/CRSim.ExamplePlugin/Views/ScreenView.xaml.cs +++ /dev/null @@ -1,16 +0,0 @@ -锘 -using CRSim.ExamplePlugin.ViewModels; -using System.Windows.Controls; -namespace CRSim.ExamplePlugin.Views -{ - public partial class ScreenView : Page - { - public ScreenViewModel ViewModel { get; } - public ScreenView(ScreenViewModel viewModel) - { - InitializeComponent(); - ViewModel = viewModel; - DataContext = viewModel; - } - } -} diff --git a/CRSim.ExamplePlugin/icon.png b/CRSim.ExamplePlugin/icon.png deleted file mode 100644 index eecd34e..0000000 Binary files a/CRSim.ExamplePlugin/icon.png and /dev/null differ diff --git a/CRSim.ExamplePlugin/manifest.json b/CRSim.ExamplePlugin/manifest.json deleted file mode 100644 index 0df8be5..0000000 --- a/CRSim.ExamplePlugin/manifest.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "entranceAssembly": "CRSim.ExamplePlugin.dll", - "name": "绀轰緥鎻掍欢", - "id": "CRSim.ExamplePlugin", - "url": "https://crsim.tech", - "version": "0.0.0.0", - "apiVersion": "3.0.0.0", - "author": "鐢垫帓楠", - "type": "ScreenStyle", - "description": "杩欐槸涓涓ず渚嬫彃浠躲" -} \ No newline at end of file diff --git a/CRSim.ExamplePlugin/style.json b/CRSim.ExamplePlugin/style.json deleted file mode 100644 index 018c1d5..0000000 --- a/CRSim.ExamplePlugin/style.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "parameters": [ "station", "text" ], - "region": "骞垮厓", - "type": "杞︾珯澶у睆" -} \ No newline at end of file diff --git a/CRSim.PluginSdk/CRSim.PluginSdk.csproj b/CRSim.PluginSdk/CRSim.PluginSdk.csproj deleted file mode 100644 index bc0350c..0000000 --- a/CRSim.PluginSdk/CRSim.PluginSdk.csproj +++ /dev/null @@ -1,19 +0,0 @@ -锘 - - - net9.0-windows10.0.19041.0 - enable - enable - CRSim Plugin SDK - - - - 鐢ㄤ簬寮鍙戝簲鐢 CRSim 鎻掍欢鐨 SDK銆 - True - - - - - - - diff --git a/CRSim.ScreenSimulator/CRSim.ScreenSimulator.csproj b/CRSim.ScreenSimulator/CRSim.ScreenSimulator.csproj index 0552491..1447cf2 100644 --- a/CRSim.ScreenSimulator/CRSim.ScreenSimulator.csproj +++ b/CRSim.ScreenSimulator/CRSim.ScreenSimulator.csproj @@ -6,7 +6,9 @@ enable true AnyCPU;x64 - enable + enable + CRSim.ScreenSimulator + True diff --git a/CRSim.sln b/CRSim.sln index e81ea93..c807cdb 100644 --- a/CRSim.sln +++ b/CRSim.sln @@ -7,12 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CRSim.Core", "CRSim.Core\CR EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CRSim", "CRSim\CRSim.csproj", "{9C334D96-6CE7-4137-9CA8-2969E4C67C0F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CRSim.ExamplePlugin", "CRSim.ExamplePlugin\CRSim.ExamplePlugin.csproj", "{FDD66ED3-4F7C-4A81-BE0F-F5E504BFCB2E}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CRSim.ScreenSimulator", "CRSim.ScreenSimulator\CRSim.ScreenSimulator.csproj", "{94927020-7AD7-4F6F-A456-F34A8E0BC40A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CRSim.PluginSdk", "CRSim.PluginSdk\CRSim.PluginSdk.csproj", "{2216DFBB-8EE2-4487-9772-7CAB0BF3A5C6}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -29,18 +25,10 @@ Global {9C334D96-6CE7-4137-9CA8-2969E4C67C0F}.Release|x64.ActiveCfg = Release|x64 {9C334D96-6CE7-4137-9CA8-2969E4C67C0F}.Release|x64.Build.0 = Release|x64 {9C334D96-6CE7-4137-9CA8-2969E4C67C0F}.Release|x64.Deploy.0 = Release|x64 - {FDD66ED3-4F7C-4A81-BE0F-F5E504BFCB2E}.Debug|x64.ActiveCfg = Debug|x64 - {FDD66ED3-4F7C-4A81-BE0F-F5E504BFCB2E}.Debug|x64.Build.0 = Debug|x64 - {FDD66ED3-4F7C-4A81-BE0F-F5E504BFCB2E}.Release|x64.ActiveCfg = Release|x64 - {FDD66ED3-4F7C-4A81-BE0F-F5E504BFCB2E}.Release|x64.Build.0 = Release|x64 {94927020-7AD7-4F6F-A456-F34A8E0BC40A}.Debug|x64.ActiveCfg = Debug|x64 {94927020-7AD7-4F6F-A456-F34A8E0BC40A}.Debug|x64.Build.0 = Debug|x64 {94927020-7AD7-4F6F-A456-F34A8E0BC40A}.Release|x64.ActiveCfg = Release|x64 {94927020-7AD7-4F6F-A456-F34A8E0BC40A}.Release|x64.Build.0 = Release|x64 - {2216DFBB-8EE2-4487-9772-7CAB0BF3A5C6}.Debug|x64.ActiveCfg = Debug|Any CPU - {2216DFBB-8EE2-4487-9772-7CAB0BF3A5C6}.Debug|x64.Build.0 = Debug|Any CPU - {2216DFBB-8EE2-4487-9772-7CAB0BF3A5C6}.Release|x64.ActiveCfg = Release|Any CPU - {2216DFBB-8EE2-4487-9772-7CAB0BF3A5C6}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..698c0e8 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,7 @@ + + + 2.3.103.0 + 鐢垫帓楠 + https://github.com/denglihong2007/CRSim + +