FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SmartCode/src/SmartCode.App/PluginManager.cs at master · dotnetcore/SmartCode · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
dotnetcore
/
SmartCode
Public
Notifications
You must be signed in to change notification settings
Fork
168
Star
578
Code
Issues
15
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
SmartCode
/
src
/
SmartCode.App
/
PluginManager.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
78 lines (73 loc) · 2.85 KB
Breadcrumbs
SmartCode
/
src
/
SmartCode.App
/
PluginManager.cs
Copy path
File metadata and controls
78 lines (73 loc) · 2.85 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using
Microsoft
.
Extensions
.
DependencyInjection
;
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
Text
;
using
System
.
Linq
;
using
Microsoft
.
Extensions
.
Logging
;
namespace
SmartCode
.
App
{
public
class
PluginManager
:
IPluginManager
{
private
readonly
SmartCodeOptions
_smartCodeOptions
;
private
readonly
IServiceProvider
_serviceProvider
;
private
readonly
ILogger
<
PluginManager
>
_logger
;
public
PluginManager
(
SmartCodeOptions
smartCodeOptions
,
IServiceProvider
serviceProvider
,
ILogger
<
PluginManager
>
logger
)
{
_smartCodeOptions
=
smartCodeOptions
;
_serviceProvider
=
serviceProvider
;
_logger
=
logger
;
}
public
TPlugin
Resolve
<
TPlugin
>
(
string
name
=
""
)
where
TPlugin
:
IPlugin
{
var
plugins
=
ResolvePlugins
<
TPlugin
>
(
)
;
IPlugin
plugin
=
default
;
if
(
plugins
.
Count
(
)
==
0
)
{
var
errMsg
=
$
"Can not find any Plugin:
{
typeof
(
TPlugin
)
.
Name
}
"
;
_logger
.
LogError
(
errMsg
)
;
throw
new
SmartCodeException
(
errMsg
)
;
}
if
(
String
.
IsNullOrEmpty
(
name
)
)
{
plugin
=
plugins
.
FirstOrDefault
(
)
;
}
else
{
plugin
=
plugins
.
FirstOrDefault
(
m
=>
String
.
Equals
(
m
.
Name
,
name
,
StringComparison
.
CurrentCultureIgnoreCase
)
)
;
if
(
plugin
==
null
)
{
plugin
=
plugins
.
First
(
)
;
var
errMsg
=
$
"Can not find Plugin:
{
typeof
(
TPlugin
)
.
Name
}
,Name:
{
name
}
,Use Default Plugin:
{
plugin
.
GetType
(
)
.
FullName
}
"
;
_logger
.
LogWarning
(
errMsg
)
;
}
}
_logger
.
LogDebug
(
$
"GetPlugin Name:
{
name
}
,PluginType:
{
typeof
(
TPlugin
)
.
FullName
}
,ImplType:
{
plugin
.
GetType
(
)
.
FullName
}
!"
)
;
return
(
TPlugin
)
plugin
;
}
private
IEnumerable
<
TPlugin
>
ResolvePlugins
<
TPlugin
>
(
)
where
TPlugin
:
IPlugin
{
var
plugins
=
_serviceProvider
.
GetServices
<
TPlugin
>
(
)
;
foreach
(
var
plugin
in
plugins
)
{
lock
(
this
)
{
if
(
!
plugin
.
Initialized
)
{
var
pluginType
=
plugin
.
GetType
(
)
;
var
names
=
pluginType
.
AssemblyQualifiedName
.
Split
(
','
)
;
var
typeName
=
names
[
0
]
.
Trim
(
)
;
var
assName
=
names
[
1
]
.
Trim
(
)
;
var
pluginConfig
=
_smartCodeOptions
.
Plugins
.
FirstOrDefault
(
m
=>
m
.
ImplAssemblyName
==
assName
&&
m
.
ImplTypeName
==
typeName
)
;
plugin
.
Initialize
(
pluginConfig
.
Parameters
)
;
}
}
}
return
plugins
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL