66using Newtonsoft . Json ;
77using Unity . Attributes ;
88using XmrStakBootstrap . Common ;
9- using XmrStakBootstrap . Common . Menu ;
109using XmrStakBootstrap . MasterConfiguration . Model ;
1110using XmrStakBootstrap . RunConfiguration . Model ;
1211
13- namespace XmrStakBootstrap . Core . Runner . Miner
12+ namespace XmrStakBootstrap . Core . Job . Miner
1413{
15- public class MinerRunner : IRunner
14+ public class MinerRunner : IMinerRunner
1615 {
1716 [ Dependency ]
1817 public IFinalizer Finalizer { get ; set ; }
1918
20- [ Dependency ]
21- public RunConfigurationModel RunConfigurationModel { get ; set ; }
22-
2319 [ Dependency ]
2420 public MasterConfigurationModel MasterConfigurationModel { get ; set ; }
2521
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 ; }
3724
3825 public void Run ( )
3926 {
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-
9727 var solution = MasterConfigurationModel . SolutionProfiles . GetValue ( RunConfigurationModel . ActiveSolutionConfiguration ) ;
9828 var workload = MasterConfigurationModel . WorkloadProfiles . GetValue ( RunConfigurationModel . ActiveWorkloadConfiguration ) ;
9929
@@ -124,22 +54,6 @@ private void DoRun()
12454 }
12555 }
12656
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-
14357 private List < PrioritizedPoolEntry > GetOutputPools ( IEnumerable < string > pools )
14458 {
14559 return pools
@@ -178,7 +92,7 @@ private string GetConfigurationArgument(IReadOnlyCollection<PrioritizedPoolEntry
17892 return $ "--config \" { configPath } \" ";
17993 }
18094
181- private string GetCpuArgument ( IList < UtilizedHardware > entry )
95+ private string GetCpuArgument ( ICollection < UtilizedHardware > entry )
18296 {
18397 if ( entry . Count == 0 )
18498 {
@@ -192,7 +106,7 @@ private string GetCpuArgument(IList<UtilizedHardware> entry)
192106 return $ "--cpu \" { path } \" ";
193107 }
194108
195- private string GetAmdArgument ( IList < UtilizedHardware > entry )
109+ private string GetAmdArgument ( ICollection < UtilizedHardware > entry )
196110 {
197111 if ( entry . Count == 0 )
198112 {
@@ -219,7 +133,7 @@ private string GetAmdArgument(IList<UtilizedHardware> entry)
219133 return $ "--amd \" { path } \" ";
220134 }
221135
222- private string GetNvidiaArgument ( IList < UtilizedHardware > entry )
136+ private string GetNvidiaArgument ( ICollection < UtilizedHardware > entry )
223137 {
224138 if ( entry . Count == 0 )
225139 {
@@ -274,31 +188,10 @@ private void ScheduleFileDelete(string file)
274188 } ) ;
275189 }
276190
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
291192 {
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 ; }
302195 }
303196 }
304197}
0 commit comments