Skip to content
This repository was archived by the owner on Sep 30, 2023. It is now read-only.

Commit 0be4b3d

Browse files
ArXa1Lmadetara
authored andcommitted
refactor(common): GraphHelper теперь не статический класс, ParallerBuilder...
1 parent ad5bf19 commit 0be4b3d

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

Commands/BuildDeps.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Linq;
55
using System.Threading.Tasks;
66
using Common;
7-
using Common.Extensions;
87
using Common.Graph;
98
using Common.Logging;
109
using Microsoft.Extensions.Logging;
@@ -176,7 +175,12 @@ private static bool BuildDepsSequential(ModulesOrder modulesOrder, BuildInfoStor
176175

177176
private static bool BuildDepsParallel(ModulesOrder modulesOrder, BuildInfoStorage buildStorage, List<Dep> modulesToBuild, ModuleBuilder builder)
178177
{
179-
var parallelBuilder = new ParallelBuilder(modulesOrder.ConfigsGraph);
178+
var logger = LogManager.GetLogger<ParallelBuilder>();
179+
var graphHelper = new GraphHelper();
180+
181+
var parallelBuilder = new ParallelBuilder(logger, graphHelper);
182+
parallelBuilder.Initialize(modulesOrder.ConfigsGraph);
183+
180184
var tasks = new List<Task>();
181185
var builtCount = 1;
182186

Common/Graph/GraphHelper.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Common.Graph
44
{
5-
public static class GraphHelper
5+
public sealed class GraphHelper
66
{
7-
public static HashSet<Dep> GetChildren(Dep dep, Dictionary<Dep, List<Dep>> graph)
7+
public HashSet<Dep> GetChildren(Dep dep, Dictionary<Dep, List<Dep>> graph)
88
{
99
var result = new HashSet<Dep>();
1010
GetChildrenDfs(dep, graph, result);

Common/Graph/ParallelBuilder.cs

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using System.Threading;
4-
using Common.Logging;
54
using Microsoft.Extensions.Logging;
65

76
namespace Common.Graph
87
{
98
public sealed class ParallelBuilder
109
{
11-
private static readonly ILogger Log = LogManager.GetLogger(typeof(ParallelBuilder));
10+
private readonly ILogger logger;
11+
private readonly GraphHelper graphHelper;
12+
1213
public bool IsFailed;
1314

1415
private readonly Dictionary<Dep, List<Dep>> graph = new Dictionary<Dep, List<Dep>>();
@@ -20,16 +21,23 @@ public sealed class ParallelBuilder
2021
private readonly List<Dep> built = new List<Dep>();
2122
private bool needChecking = true;
2223

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)
2432
{
25-
foreach (var key in graph.Keys)
33+
foreach (var key in source.Keys)
2634
{
27-
this.graph[key] = GraphHelper.GetChildren(key, graph)
35+
graph[key] = graphHelper.GetChildren(key, source)
2836
.Where(d => d.Name != key.Name)
2937
.ToList();
3038
}
3139

32-
waiting.AddRange(this.graph.Keys);
40+
waiting.AddRange(graph.Keys);
3341
}
3442

3543
public Dep TryStartBuild()
@@ -83,7 +91,7 @@ private Dep TryStartOnce(out bool finished)
8391

8492
if (!needChecking)
8593
{
86-
Log.LogInformation("Nothing to build - already checked.");
94+
logger.LogInformation("Nothing to build - already checked.");
8795
return null;
8896
}
8997

@@ -100,14 +108,14 @@ private Dep TryStartOnce(out bool finished)
100108

101109
building.Add(module);
102110
waiting.Remove(module);
103-
Log.LogInformation($"Building {module} with {building.Count - 1} others.");
111+
logger.LogInformation($"Building {module} with {building.Count - 1} others.");
104112
return module;
105113
}
106114

107115
needChecking = false;
108116
}
109117

110-
Log.LogInformation("Nothing to build.");
118+
logger.LogInformation("Nothing to build.");
111119
return null;
112120
}
113121
}

0 commit comments

Comments
 (0)