1
1
using System . Collections . Generic ;
2
2
using System . Linq ;
3
3
using System . Threading ;
4
- using Common . Logging ;
5
4
using Microsoft . Extensions . Logging ;
6
5
7
6
namespace Common . Graph
8
7
{
9
8
public sealed class ParallelBuilder
10
9
{
11
- private static readonly ILogger Log = LogManager . GetLogger ( typeof ( ParallelBuilder ) ) ;
10
+ private readonly ILogger logger ;
11
+ private readonly GraphHelper graphHelper ;
12
+
12
13
public bool IsFailed ;
13
14
14
15
private readonly Dictionary < Dep , List < Dep > > graph = new Dictionary < Dep , List < Dep > > ( ) ;
@@ -20,16 +21,23 @@ public sealed class ParallelBuilder
20
21
private readonly List < Dep > built = new List < Dep > ( ) ;
21
22
private bool needChecking = true ;
22
23
23
- public ParallelBuilder ( Dictionary < Dep , List < Dep > > graph )
24
+ public ParallelBuilder ( ILogger < ParallelBuilder > logger , GraphHelper graphHelper )
25
+
26
+ {
27
+ this . logger = logger ;
28
+ this . graphHelper = graphHelper ;
29
+ }
30
+
31
+ public void Initialize ( Dictionary < Dep , List < Dep > > source )
24
32
{
25
- foreach ( var key in graph . Keys )
33
+ foreach ( var key in source . Keys )
26
34
{
27
- this . graph [ key ] = GraphHelper . GetChildren ( key , graph )
35
+ graph [ key ] = graphHelper . GetChildren ( key , source )
28
36
. Where ( d => d . Name != key . Name )
29
37
. ToList ( ) ;
30
38
}
31
39
32
- waiting . AddRange ( this . graph . Keys ) ;
40
+ waiting . AddRange ( graph . Keys ) ;
33
41
}
34
42
35
43
public Dep TryStartBuild ( )
@@ -83,7 +91,7 @@ private Dep TryStartOnce(out bool finished)
83
91
84
92
if ( ! needChecking )
85
93
{
86
- Log . LogInformation ( "Nothing to build - already checked." ) ;
94
+ logger . LogInformation ( "Nothing to build - already checked." ) ;
87
95
return null ;
88
96
}
89
97
@@ -100,14 +108,14 @@ private Dep TryStartOnce(out bool finished)
100
108
101
109
building . Add ( module ) ;
102
110
waiting . Remove ( module ) ;
103
- Log . LogInformation ( $ "Building { module } with { building . Count - 1 } others.") ;
111
+ logger . LogInformation ( $ "Building { module } with { building . Count - 1 } others.") ;
104
112
return module ;
105
113
}
106
114
107
115
needChecking = false ;
108
116
}
109
117
110
- Log . LogInformation ( "Nothing to build." ) ;
118
+ logger . LogInformation ( "Nothing to build." ) ;
111
119
return null ;
112
120
}
113
121
}
0 commit comments