1
- using System ;
1
+ using System ;
2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
4
using System . Linq ;
5
5
using System . Reflection ;
6
6
using System . Runtime . Loader ;
7
+ using System . Threading . Tasks ;
8
+ using System . Windows . Forms ;
7
9
using Flow . Launcher . Infrastructure ;
8
- using Flow . Launcher . Infrastructure . Exception ;
9
10
using Flow . Launcher . Infrastructure . Logger ;
10
11
using Flow . Launcher . Infrastructure . UserSettings ;
11
12
using Flow . Launcher . Plugin ;
@@ -29,6 +30,8 @@ public static List<PluginPair> Plugins(List<PluginMetadata> metadatas, PluginsSe
29
30
30
31
public static IEnumerable < PluginPair > DotNetPlugins ( List < PluginMetadata > source )
31
32
{
33
+ var erroredPlugins = new List < string > ( ) ;
34
+
32
35
var plugins = new List < PluginPair > ( ) ;
33
36
var metadatas = source . Where ( o => AllowedLanguage . IsDotNet ( o . Language ) ) ;
34
37
@@ -50,28 +53,44 @@ public static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source)
50
53
}
51
54
catch ( Exception e )
52
55
{
53
- Log . Exception ( $ "|PluginsLoader.DotNetPlugins|Couldn't load assembly for { metadata . Name } ", e ) ;
56
+ erroredPlugins . Add ( metadata . Name ) ;
57
+
58
+ Log . Exception ( $ "|PluginsLoader.DotNetPlugins|Couldn't load assembly for the plugin: { metadata . Name } ", e ) ;
54
59
return ;
55
60
}
56
- var types = assembly . GetTypes ( ) ;
61
+
57
62
Type type ;
58
63
try
59
64
{
65
+ var types = assembly . GetTypes ( ) ;
66
+
60
67
type = types . First ( o => o . IsClass && ! o . IsAbstract && o . GetInterfaces ( ) . Contains ( typeof ( IPlugin ) ) ) ;
61
68
}
62
69
catch ( InvalidOperationException e )
63
70
{
64
- Log . Exception ( $ "|PluginsLoader.DotNetPlugins|Can't find class implement IPlugin for <{ metadata . Name } >", e ) ;
71
+ erroredPlugins . Add ( metadata . Name ) ;
72
+
73
+ Log . Exception ( $ "|PluginsLoader.DotNetPlugins|Can't find the required IPlugin interface for the plugin: <{ metadata . Name } >", e ) ;
74
+ return ;
75
+ }
76
+ catch ( ReflectionTypeLoadException e )
77
+ {
78
+ erroredPlugins . Add ( metadata . Name ) ;
79
+
80
+ Log . Exception ( $ "|PluginsLoader.DotNetPlugins|The GetTypes method was unable to load assembly types for the plugin: <{ metadata . Name } >", e ) ;
65
81
return ;
66
82
}
83
+
67
84
IPlugin plugin ;
68
85
try
69
86
{
70
87
plugin = ( IPlugin ) Activator . CreateInstance ( type ) ;
71
88
}
72
89
catch ( Exception e )
73
90
{
74
- Log . Exception ( $ "|PluginsLoader.DotNetPlugins|Can't create instance for <{ metadata . Name } >", e ) ;
91
+ erroredPlugins . Add ( metadata . Name ) ;
92
+
93
+ Log . Exception ( $ "|PluginsLoader.DotNetPlugins|The following plugin has errored and can not be loaded: <{ metadata . Name } >", e ) ;
75
94
return ;
76
95
}
77
96
#endif
@@ -85,6 +104,26 @@ public static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source)
85
104
metadata . InitTime += milliseconds ;
86
105
87
106
}
107
+
108
+ if ( erroredPlugins . Count > 0 )
109
+ {
110
+ var errorPluginString = "" ;
111
+
112
+ var errorMessage = "The following "
113
+ + ( erroredPlugins . Count > 1 ? "plugins have " : "plugin has " )
114
+ + "errored and cannot be loaded:" ;
115
+
116
+ erroredPlugins . ForEach ( x => errorPluginString += x + Environment . NewLine ) ;
117
+
118
+ Task . Run ( ( ) =>
119
+ {
120
+ MessageBox . Show ( $ "{ errorMessage } { Environment . NewLine } { Environment . NewLine } " +
121
+ $ "{ errorPluginString } { Environment . NewLine } { Environment . NewLine } " +
122
+ $ "Please refer to the logs for more information", "" ,
123
+ MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
124
+ } ) ;
125
+ }
126
+
88
127
return plugins ;
89
128
}
90
129
0 commit comments