Skip to content

Commit 590045d

Browse files
committed
Correcting hardcode messages
#7
1 parent e532adb commit 590045d

3 files changed

Lines changed: 7 additions & 62 deletions

File tree

src/FlowPack/Packager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public bool Build()
4040
string pluginTempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".plugin");
4141
string pluginMetadataTempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".json");
4242

43-
var metadata = PluginReflector.ExtractPluginMetadata(tempOutput);
43+
var metadata = PluginReflector.ExtractPluginMetadata(tempOutput, _options.Verbose);
4444
if (metadata == null)
4545
{
4646
Console.WriteLine("No valid plugin metadata found.");

src/FlowPack/PluginReflector.cs

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class PluginReflector
77
{
88
private const string PluginSearchPattern = "*.dll";
99

10-
public static PluginMetadata? ExtractPluginMetadata(string pluginDirectory)
10+
public static PluginMetadata? ExtractPluginMetadata(string pluginDirectory, bool verbose)
1111
{
1212
var interfaceType = typeof(IPlugin);
1313
foreach (var dllPath in Directory.GetFiles(pluginDirectory, PluginSearchPattern))
@@ -20,7 +20,8 @@ public static class PluginReflector
2020
}
2121
catch (Exception ex)
2222
{
23-
Console.Error.WriteLine(ex.Message);
23+
if (verbose)
24+
Console.Error.WriteLine(ex.Message);
2425
}
2526
finally
2627
{
@@ -29,53 +30,6 @@ public static class PluginReflector
2930
}
3031

3132
return null;
32-
33-
34-
//foreach (var dllPath in Directory.GetFiles(pluginDirectory, "*.dll"))
35-
//{
36-
// try
37-
// {
38-
// var assembly = Assembly.LoadFrom(dllPath);
39-
40-
// foreach (var type in assembly.GetTypes())
41-
// {
42-
// if (!type.IsClass || type.IsAbstract || type.IsInterface)
43-
// continue;
44-
45-
// if (!interfaceType.IsAssignableFrom(type))
46-
// continue;
47-
48-
// var instance = Activator.CreateInstance(type);
49-
// if (instance == null)
50-
// continue;
51-
52-
// var metadata = new PluginMetadata
53-
// {
54-
// Id = GetPropertyValue<Guid>(type, instance, nameof(PluginMetadata.Id)),
55-
// Type = GetPropertyValue<string>(type, instance, nameof(PluginMetadata.Type)),
56-
// Version = GetPropertyValue<string>(type, instance, nameof(PluginMetadata.Version)),
57-
// CompanyName = GetPropertyValue<string>(type, instance, nameof(PluginMetadata.CompanyName)),
58-
// Description = GetPropertyValue<string?>(type, instance, nameof(PluginMetadata.Description)),
59-
// License = GetPropertyValue<string?>(type, instance, nameof(PluginMetadata.License)),
60-
// LicenseUrl = GetPropertyValue<string?>(type, instance, nameof(PluginMetadata.LicenseUrl)),
61-
// Icon = GetPropertyValue<string?>(type, instance, nameof(PluginMetadata.Icon)),
62-
// ProjectUrl = GetPropertyValue<string?>(type, instance, nameof(PluginMetadata.ProjectUrl)),
63-
// RepositoryUrl = GetPropertyValue<string?>(type, instance, nameof(PluginMetadata.RepositoryUrl)),
64-
// Copyright = GetPropertyValue<string?>(type, instance, nameof(PluginMetadata.Copyright)),
65-
// Authors = GetPropertyValue<List<string>>(type, instance, nameof(PluginMetadata.Authors)) ?? new(),
66-
// Tags = GetPropertyValue<List<string>>(type, instance, nameof(PluginMetadata.Tags)) ?? new()
67-
// };
68-
69-
// return metadata;
70-
// }
71-
// }
72-
// catch (Exception ex)
73-
// {
74-
// Console.Error.WriteLine($"Failed to read metadata from {dllPath}: {ex.Message}");
75-
// }
76-
//}
77-
78-
//return null;
7933
}
8034

8135
private static PluginMetadata CreatePluginMetadata(IPlugin plugin)
@@ -98,15 +52,6 @@ private static PluginMetadata CreatePluginMetadata(IPlugin plugin)
9852
};
9953
}
10054

101-
private static T? GetPropertyValue<T>(Type type, object instance, string propertyName)
102-
{
103-
var prop = type.GetProperty(propertyName);
104-
if (prop == null || !typeof(T).IsAssignableFrom(prop.PropertyType))
105-
return default;
106-
107-
return (T?)prop.GetValue(instance);
108-
}
109-
11055
public static string SaveMetadataToFile(PluginMetadata metadata, string outputDirectory)
11156
{
11257
var json = JsonSerializer.Serialize(metadata, new JsonSerializerOptions { WriteIndented = true });

src/FlowPack/TransientPluginLoader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void Load()
2626
var pluginType = LoadPluginType(pluginAssembly);
2727

2828
if (pluginType == null)
29-
throw new Exception($"Plugin_Loader_NoPluginFound: '{_pluginLocation}'");
29+
throw new Exception($"No plugin type found: '{_pluginLocation}'");
3030

3131
_pluginInstance = CreatePluginInstance(pluginType);
3232
}
@@ -36,7 +36,7 @@ private void ValidatePluginFile(string pluginLocation)
3636
{
3737
if (!File.Exists(pluginLocation))
3838
{
39-
throw new Exception($"Plugin_Loader_FileNotFound: {pluginLocation}");
39+
throw new Exception($"Plugin file not found: {pluginLocation}");
4040
}
4141
}
4242

@@ -52,7 +52,7 @@ private IPlugin CreatePluginInstance(Type pluginType)
5252
{
5353
if (Activator.CreateInstance(pluginType) is not IPlugin instance)
5454
{
55-
throw new Exception($"Plugin_Loader_FailedToCreateInstance '{pluginType.FullName}'");
55+
throw new Exception($"Failed to create plugin instance of type '{pluginType.FullName}'.");
5656
}
5757
return instance;
5858
}

0 commit comments

Comments
 (0)