6
6
using Newtonsoft . Json ;
7
7
using Unity . Attributes ;
8
8
using XmrStakBootstrap . Common ;
9
- using XmrStakBootstrap . Common . Menu ;
10
9
using XmrStakBootstrap . MasterConfiguration . Model ;
11
10
using XmrStakBootstrap . RunConfiguration . Model ;
12
11
13
- namespace XmrStakBootstrap . Core . Runner . Miner
12
+ namespace XmrStakBootstrap . Core . Job . Miner
14
13
{
15
- public class MinerRunner : IRunner
14
+ public class MinerRunner : IMinerRunner
16
15
{
17
16
[ Dependency ]
18
17
public IFinalizer Finalizer { get ; set ; }
19
18
20
- [ Dependency ]
21
- public RunConfigurationModel RunConfigurationModel { get ; set ; }
22
-
23
19
[ Dependency ]
24
20
public MasterConfigurationModel MasterConfigurationModel { get ; set ; }
25
21
26
- private bool HasSolution
27
- =>
28
- MasterConfigurationModel . SolutionProfiles . ContainsKey (
29
- RunConfigurationModel . ActiveSolutionConfiguration ?? string . Empty ) ;
30
-
31
- private bool HasWorkload
32
- =>
33
- MasterConfigurationModel . WorkloadProfiles . ContainsKey (
34
- RunConfigurationModel . ActiveWorkloadConfiguration ?? string . Empty ) ;
35
-
36
- private bool CanRun => HasSolution && HasWorkload ;
22
+ [ Dependency ]
23
+ public RunConfigurationModel RunConfigurationModel { get ; set ; }
37
24
38
25
public void Run ( )
39
26
{
40
- if ( MasterConfigurationModel == null )
41
- {
42
- Console . WriteLine ( @"Master configuration file '{0}' was not loaded. Try running this program with argument --help." , RunConfigurationModel . MasterConfiguration ) ;
43
- return ;
44
- }
45
-
46
- var @continue = true ;
47
- while ( @continue )
48
- {
49
- Console . Clear ( ) ;
50
- Console . WriteLine ( @"Active solution: {0}" , HasSolution ? RunConfigurationModel . ActiveSolutionConfiguration : "<UNKNOWN>" ) ;
51
- Console . WriteLine ( @"Active workload: {0}" , HasWorkload ? RunConfigurationModel . ActiveWorkloadConfiguration : "<UNKNOWN>" ) ;
52
- Console . WriteLine ( ) ;
53
- Console . WriteLine ( @"What would you like to do?" ) ;
54
-
55
- @continue = MenuBuilder
56
- . Create ( ( ) => true )
57
- . AddConditionalOption ( @"Start/restart miners" , CanRun , ( ) =>
58
- {
59
- DoRun ( ) ;
60
- return false ;
61
- } )
62
- . AddEnabledOption ( @"Change solution" , ( ) =>
63
- {
64
- SelectSolution ( ) ;
65
- return true ;
66
- } )
67
- . AddEnabledOption ( @"Change workload" , ( ) =>
68
- {
69
- SelectWorkload ( ) ;
70
- return true ;
71
- } )
72
- . AddEnabledOption ( @"Exit" , ( ) =>
73
- {
74
- Environment . Exit ( 0 ) ;
75
- return false ;
76
- } )
77
- . AddEnabledOption ( @"Exit & terminate miners" , ( ) =>
78
- {
79
- KillMiners ( ) ;
80
- Environment . Exit ( 0 ) ;
81
- return false ;
82
- } )
83
- . Execute ( ) ;
84
- }
85
- }
86
-
87
- private class UtilizedHardware
88
- {
89
- public HardwareEntry Hardware { get ; set ; }
90
- public string Profile { get ; set ; }
91
- }
92
-
93
- private void DoRun ( )
94
- {
95
- KillMiners ( ) ;
96
-
97
27
var solution = MasterConfigurationModel . SolutionProfiles . GetValue ( RunConfigurationModel . ActiveSolutionConfiguration ) ;
98
28
var workload = MasterConfigurationModel . WorkloadProfiles . GetValue ( RunConfigurationModel . ActiveWorkloadConfiguration ) ;
99
29
@@ -124,22 +54,6 @@ private void DoRun()
124
54
}
125
55
}
126
56
127
- private void SelectSolution ( )
128
- {
129
- Console . WriteLine ( @"Available solutions: " ) ;
130
- RunConfigurationModel . ActiveSolutionConfiguration =
131
- MenuBuilder . CreateTextListMenu ( MasterConfigurationModel . SolutionProfiles . Keys )
132
- . Execute ( ) ;
133
- }
134
-
135
- private void SelectWorkload ( )
136
- {
137
- Console . WriteLine ( @"Available workloads: " ) ;
138
- RunConfigurationModel . ActiveWorkloadConfiguration =
139
- MenuBuilder . CreateTextListMenu ( MasterConfigurationModel . WorkloadProfiles . Keys )
140
- . Execute ( ) ;
141
- }
142
-
143
57
private List < PrioritizedPoolEntry > GetOutputPools ( IEnumerable < string > pools )
144
58
{
145
59
return pools
@@ -178,7 +92,7 @@ private string GetConfigurationArgument(IReadOnlyCollection<PrioritizedPoolEntry
178
92
return $ "--config \" { configPath } \" ";
179
93
}
180
94
181
- private string GetCpuArgument ( IList < UtilizedHardware > entry )
95
+ private string GetCpuArgument ( ICollection < UtilizedHardware > entry )
182
96
{
183
97
if ( entry . Count == 0 )
184
98
{
@@ -192,7 +106,7 @@ private string GetCpuArgument(IList<UtilizedHardware> entry)
192
106
return $ "--cpu \" { path } \" ";
193
107
}
194
108
195
- private string GetAmdArgument ( IList < UtilizedHardware > entry )
109
+ private string GetAmdArgument ( ICollection < UtilizedHardware > entry )
196
110
{
197
111
if ( entry . Count == 0 )
198
112
{
@@ -219,7 +133,7 @@ private string GetAmdArgument(IList<UtilizedHardware> entry)
219
133
return $ "--amd \" { path } \" ";
220
134
}
221
135
222
- private string GetNvidiaArgument ( IList < UtilizedHardware > entry )
136
+ private string GetNvidiaArgument ( ICollection < UtilizedHardware > entry )
223
137
{
224
138
if ( entry . Count == 0 )
225
139
{
@@ -274,31 +188,10 @@ private void ScheduleFileDelete(string file)
274
188
} ) ;
275
189
}
276
190
277
- private static void KillMiners ( )
278
- {
279
- foreach ( var process in Process . GetProcessesByName ( "xmr-stak" ) )
280
- {
281
- KillProcess ( process ) ;
282
- }
283
- }
284
-
285
- private static void KillProcess ( Process process )
286
- {
287
- KillProcess ( process . Id , process ) ;
288
- }
289
-
290
- private static void KillProcess ( int processId , Process process )
191
+ private class UtilizedHardware
291
192
{
292
- try
293
- {
294
- process . Kill ( ) ;
295
- process . Dispose ( ) ;
296
- Console . WriteLine ( @"Process {0} was killed." , processId ) ;
297
- }
298
- catch ( Exception )
299
- {
300
- Console . WriteLine ( @"Cannot kill process {0}!" , processId ) ;
301
- }
193
+ public HardwareEntry Hardware { get ; set ; }
194
+ public string Profile { get ; set ; }
302
195
}
303
196
}
304
197
}
0 commit comments