Permalink
Browse files

Run miners inside application console window.

  • Loading branch information...
1 parent b253b6d commit 6f0dfc9dad49475e82e79c1c0ca3fdc74c8fe511 @StuffOfInterest committed Oct 18, 2014
Oops, something went wrong.
@@ -23,6 +23,7 @@ private bool IsMinimizedToTray
public MainWindow()
{
+ _engine.WriteConsoleAction = WriteConsole;
_engine.LoadConfig();
if (!string.IsNullOrWhiteSpace(_engine.CurrencyCode))
_engine.LoadExchangeRates();
@@ -64,6 +65,7 @@ private void MainWindow_Shown(object sender, EventArgs e)
UpdateButtons();
RunCycle();
UpdateGrid(true);
+
tmrPriceCheck.Enabled = true;
if (!string.IsNullOrWhiteSpace(_engine.CurrencyCode))
tmrExchangeUpdate.Enabled = true;
@@ -228,5 +230,27 @@ private string ActiveTime(PriceEntryBase priceEntry)
time += (DateTime.Now - _engine.StartMining.Value);
return time.FormatTime();
}
+
+ private void WriteConsole(string text)
+ {
+ Invoke(new MethodInvoker(
+ delegate
+ {
+ textConsole.AppendText(text + Environment.NewLine);
+ int numOfLines = textConsole.Lines.Length - 200;
+ if (numOfLines <= 0) return;
+
+ var lines = textConsole.Lines;
+ var newLines = lines.Skip(numOfLines);
+
+ textConsole.Lines = newLines.ToArray();
+ textConsole.Focus();
+ textConsole.SelectionStart = textConsole.Text.Length;
+ textConsole.SelectionLength = 0;
+ textConsole.ScrollToCaret();
+ textConsole.Refresh();
+ }
+ ));
+ }
}
}
@@ -6344,6 +6344,66 @@
<metadata name="btnNhStart.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
+ <metadata name="Id.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="ServicePrint.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="Algo.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="Hashrate.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="Price.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="Earn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="Fees.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="PowerCost.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="NetEarn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="Balance.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="AcceptSpeed.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="RejectSpeed.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="TimeMining.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="StatusPrint.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="btnNhStart.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="ServiceName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="ServiceLastUpdated.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="ServiceBalance.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="ServiceCurrency.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
+ <metadata name="ServiceRunning.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+ <value>True</value>
+ </metadata>
<metadata name="ServiceName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
@@ -38,8 +38,8 @@
{ "algo": "scryptn", "folder": "", "command": "TestMiner.exe", "arguments": "-a scrypt-n _PARAM1_:4 _ACCOUNT_._WORKER_ _PARAM2_" },
{ "algo": "keccak", "folder": "", "command": "TestMiner.exe", "arguments": "-a keccak _PARAM1_:5 _ACCOUNT_._WORKER_ _PARAM2_" },
{ "algo": "x15", "folder": "", "command": "TestMiner.exe", "arguments": "-a x15 _PARAM1_:6 _ACCOUNT_._WORKER_ _PARAM2_" },
- { "algo": "nist5", "folder": "", "command": "TestMiner.exe", "arguments": "-a nist5 _PARAM1_:7 _ACCOUNT_._WORKER_ _PARAM2_" },
- { "algo": "sha256", "folder": "", "command": "TestMiner.exe", "arguments": "-a sha256 _PARAM1_:8 _ACCOUNT_._WORKER_ _PARAM2_" }
+ { "algo": "nist5", "folder": "", "command": "cmd.exe", "arguments": "/c test-run.bat -a nist5 _PARAM1_:7 _ACCOUNT_._WORKER_ _PARAM2_ BATCH" },
+ { "algo": "sha256", "folder": "", "command": "cmd.exe", "arguments": "/c test-run.bat -a sha256 _PARAM1_:8 _ACCOUNT_._WORKER_ _PARAM2_ BATCH", "usewindow": true }
]
},
"westhash": {
@@ -91,6 +91,9 @@
<None Include="MinerControl.conf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
+ <None Include="test-run.bat">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
@@ -160,6 +160,11 @@ public MiningEngine()
}
public void Cleanup(){
+ WriteConsoleAction = null;
+
+ if (_currentRunning != null && _currentRunning.UseWindow == false)
+ StopMiner();
+
if (_process != null)
_process.Dispose();
}
@@ -243,6 +248,7 @@ public void StopMiner()
if (_process == null || _process.HasExited) return;
LogActivity(_donationMiningMode == MiningModeEnum.Donation ? "DonationStop" : "Stop");
+ WriteConsole(string.Format("Stopping {0} {1}", _currentRunning.ServicePrint, _currentRunning.AlgoName), true);
RecordMiningTime();
if (MinerKillMode == 0)
ProcessUtil.KillProcess(_process);
@@ -295,22 +301,48 @@ private void StartMiner(PriceEntryBase entry, bool isMinimizedToTray = false)
_process.StartInfo.FileName = entry.Command;
_process.StartInfo.Arguments = entry.Arguments;
}
- _process.StartInfo.WindowStyle = (isMinimizedToTray && TrayMode == 2) ? ProcessWindowStyle.Hidden : ProcessWindowStyle.Minimized;
- _process.Start();
- _startMining = DateTime.Now;
- _donationMiningMode = MiningMode;
- Thread.Sleep(100);
- try
+
+ WriteConsole(string.Format("Starting {0} {1}", _currentRunning.ServicePrint, _currentRunning.AlgoName), true);
+ if (entry.UseWindow)
{
- ProcessUtil.SetWindowTitle(_process, string.Format("{0} {1} Miner", entry.ServicePrint, entry.Name));
+ _process.StartInfo.WindowStyle = (isMinimizedToTray && TrayMode == 2) ? ProcessWindowStyle.Hidden : ProcessWindowStyle.Minimized;
+ _process.Start();
}
- catch (Exception ex)
+ else
{
- ErrorLogger.Log(ex);
+ _process.StartInfo.RedirectStandardOutput = true;
+ _process.StartInfo.RedirectStandardError = true;
+ _process.EnableRaisingEvents = true;
+ _process.StartInfo.CreateNoWindow = true;
+ _process.StartInfo.UseShellExecute = false;
+
+ _process.ErrorDataReceived += ProcessConsoleOutput;
+ _process.OutputDataReceived += ProcessConsoleOutput;
+
+ _process.Start();
+
+ _process.BeginOutputReadLine();
+ _process.BeginErrorReadLine();
}
- if (isMinimizedToTray && TrayMode == 1)
- HideMinerWindow();
+ _startMining = DateTime.Now;
+ _donationMiningMode = MiningMode;
+
+ if (!entry.UseWindow)
+ {
+ Thread.Sleep(100);
+ try
+ {
+ ProcessUtil.SetWindowTitle(_process, string.Format("{0} {1} Miner", entry.ServicePrint, entry.Name));
+ }
+ catch (Exception ex)
+ {
+ ErrorLogger.Log(ex);
+ }
+
+ if (isMinimizedToTray && TrayMode == 1)
+ HideMinerWindow();
+ }
entry.UpdateStatus();
@@ -355,6 +387,7 @@ public void RunBestAlgo(bool isMinimizedToTray)
{
_currentRunning.DeadTime = DateTime.Now;
LogActivity(_donationMiningMode == MiningModeEnum.Donation ? "DonationDead" : "Dead");
+ WriteConsole(string.Format("Dead {0} {1}", _currentRunning.ServicePrint, _currentRunning.AlgoName), true);
RecordMiningTime();
}
}
@@ -451,11 +484,15 @@ public void RunBestAlgo(bool isMinimizedToTray)
public void HideMinerWindow()
{
+ if (_currentRunning == null || !_currentRunning.UseWindow) return;
+
ProcessUtil.HideWindow(_process);
}
public void MinimizeMinerWindow()
{
+ if (_currentRunning == null || !_currentRunning.UseWindow) return;
+
ProcessUtil.MinimizeWindow(_process);
}
@@ -519,5 +556,27 @@ private void LogActivity(string action)
w.WriteLine(line);
}
}
+
+ #region Console interaction
+
+ public Action<string> WriteConsoleAction { get; set; }
+
+ private void WriteConsole(string text, bool prefixTime = false)
+ {
+ if (WriteConsoleAction == null) return;
+
+ if (prefixTime)
+ text = string.Format("[{0:hh:mm:ss}] {1}", DateTime.Now, text);
+
+ WriteConsoleAction(text);
+ }
+
+ private void ProcessConsoleOutput(object sender, DataReceivedEventArgs e)
+ {
+ if (e.Data == null) return;
+ WriteConsole(e.Data);
+ }
+
+ #endregion
}
}
@@ -18,6 +18,7 @@ public PriceEntryBase()
public IService ServiceEntry { get; set; }
public string AlgoName { get; set; }
public string Name { get { return GetAlgoDisplayName(AlgoName); } }
+ public bool UseWindow { get; set; }
public decimal Hashrate { get; set; }
public decimal Power { get; set; }
@@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.3.1.0")]
-[assembly: AssemblyFileVersion("1.3.1.0")]
+[assembly: AssemblyVersion("1.4.0.0")]
+[assembly: AssemblyFileVersion("1.4.0.0")]
@@ -34,6 +34,7 @@ public override void Initialize(IDictionary<string, object> data)
public override void CheckPrices()
{
+ ClearStalePrices();
WebUtil.DownloadJson(CurrentFormat, ProcessPrices);
WebUtil.DownloadJson(string.Format(BalanceFormat, _account), ProcessBalances);
}
@@ -110,6 +110,8 @@ protected TEntry GetEntry(Dictionary<string, object> item)
entry.Folder = ProcessedSubstitutions(item.GetString("folder")) ?? string.Empty;
entry.Command = ProcessedSubstitutions(item.GetString("command"));
entry.Arguments = ProcessedSubstitutions(item.GetString("arguments")) ?? string.Empty;
+ if(item.ContainsKey("usewindow"))
+ entry.UseWindow = bool.Parse(item["usewindow"].ToString());
if (!string.IsNullOrWhiteSpace(DonationAccount))
{
entry.DonationFolder = ProcessedDonationSubstitutions(item.GetString("folder")) ?? string.Empty;
@@ -130,5 +132,13 @@ protected string GetAlgoName(string name)
if (AlgoTranslations == null || !AlgoTranslations.ContainsKey(name)) return name;
return AlgoTranslations[name];
}
+
+ protected void ClearStalePrices()
+ {
+ if (!LastUpdated.HasValue || LastUpdated.Value.AddMinutes(30) > DateTime.Now) return;
+
+ foreach (var entry in PriceEntries)
+ entry.Price = 0;
+ }
}
}
@@ -44,6 +44,7 @@ public override void Initialize(IDictionary<string, object> data)
public override void CheckPrices()
{
+ ClearStalePrices();
WebUtil.DownloadJson(string.Format("https://pool.trademybit.com/api/bestalgo?key={0}", _apikey), ProcessPrices);
WebUtil.DownloadJson(string.Format("https://pool.trademybit.com/api/balance?key={0}", _apikey), ProcessBalances);
}
@@ -66,6 +66,7 @@ public override void Initialize(IDictionary<string, object> data)
public override void CheckPrices()
{
+ ClearStalePrices();
WebUtil.DownloadJson("http://wafflepool.com/api/stats", ProcessPrices);
WebUtil.DownloadJson(string.Format("http://wafflepool.com/api/miner?address={0}", _account), ProcessBalances);
}
@@ -30,6 +30,7 @@ public override void Initialize(IDictionary<string, object> data)
public override void CheckPrices()
{
+ ClearStalePrices();
WebUtil.DownloadJson("http://yaamp.com/api/status", ProcessPrices);
WebUtil.DownloadJson(string.Format("http://yaamp.com/api/wallet?address={0}", _account), ProcessBalances);
}
@@ -0,0 +1,4 @@
+@echo off
+echo Launching from batch file...
+testminer %1 %2 %3 %4 %5 %6 %7 %8 %9
+pause
@@ -14,13 +14,12 @@ static void Main(string[] args)
Console.WriteLine(string.Format("Arguments: {0}", string.Join(" ", args)));
}
- while (!Console.KeyAvailable)
+ while(true)
{
Thread.Sleep(1000);
Console.WriteLine(string.Format("Found block {0}!", x));
x++;
}
- Console.ReadKey(true);
}
}
}

0 comments on commit 6f0dfc9

Please sign in to comment.