|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.IO; |
| 4 | +using System.Linq; |
4 | 5 | using System.Text.Json; |
5 | 6 | using System.Text.Json.Nodes; |
6 | 7 | using System.Threading.Tasks; |
@@ -59,23 +60,40 @@ public TMeta LoadMetaData(string zip) |
59 | 60 |
|
60 | 61 | public void CheckMetaDataValid(TMeta meta) |
61 | 62 | { |
62 | | - throw new NotImplementedException(); |
63 | 63 | } |
64 | 64 |
|
| 65 | + /// <summary> |
| 66 | + /// <inheritdoc /> |
| 67 | + /// </summary> |
| 68 | + /// <exception cref="PluginImportException"></exception> |
65 | 69 | public async Task<Type> GetMainPluginType(TMeta meta) |
66 | 70 | { |
67 | 71 | if (!DllFiles.TryGetValue(meta.Id, out var path)) |
68 | 72 | { |
69 | 73 | throw new PluginImportException($"{meta.Id} Dll Path Not Found"); |
70 | 74 | } |
71 | 75 |
|
72 | | - var asm = await ApplicationExtensionHost.Current.LoadExtensionAsync(path); |
73 | | - if (!EntryPoints.TryGetValue("MainPlugin", out var mainTypeName) || mainTypeName == null) |
| 76 | + var assemblyName = Path.GetFileNameWithoutExtension(path); |
| 77 | + var assembly = AppDomain.CurrentDomain.GetAssemblies() |
| 78 | + .FirstOrDefault(assembly => assembly.GetName().Name == assemblyName); |
| 79 | + if (assembly == null) |
| 80 | + { |
| 81 | + var asm = await ApplicationExtensionHost.Current.LoadExtensionAsync(path); |
| 82 | + assembly = asm.ForeignAssembly; |
| 83 | + } |
| 84 | + |
| 85 | + if (!EntryPoints.TryGetValue(meta.Id, out var entryPoints) || entryPoints == null) |
| 86 | + { |
| 87 | + throw new PluginImportException($"{meta.Id} EntryPoints Not Found"); |
| 88 | + } |
| 89 | + |
| 90 | + if (!entryPoints.AsObject() |
| 91 | + .TryGetPropertyValue("MainPlugin", out var mainTypeName) || mainTypeName == null) |
74 | 92 | { |
75 | 93 | throw new PluginImportException($"{meta.Id} MainPlugin(EntryPoint) Not Found"); |
76 | 94 | } |
77 | 95 |
|
78 | | - var mainType = asm.ForeignAssembly.GetType(mainTypeName.GetValue<string>()); |
| 96 | + var mainType = assembly.GetType(mainTypeName.GetValue<string>()); |
79 | 97 | if (mainType == null) |
80 | 98 | { |
81 | 99 | throw new PluginImportException($"{meta.Id} MainPlugin(Type) Not Found"); |
|
0 commit comments