This repository has been archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
198 lines (179 loc) · 7.57 KB
/
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//.____ __ _____ .__ .__ ____
//| | __ __ ____ | | __ ___.__. / \ |__| ____ |__| ____ / ___\
//| | | | \ _/ ___\ | |/ / < | | / \ / \ | | / \ | | / \ / /_/ >
//| |___ | | / \ \___ | < \___ | / Y \ | | | | \ | | | | \ \___ /
//|_______ \ |____/ \___ > |__|_ \ / ____| \____|__ / |__| |___| / |__| |___| / /_____/
// |
// Copyright 2021 by YK303
// |
// Licensed under the Apache License , Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// |
// http://www.apache.org/licenses/
// |
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using LibreHardwareMonitor.Hardware;
using LuckyMining.Models;
using LuckyMining.RestClient;
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace LuckyMining
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public static CryptoEco.Root eth;
public static string fanlive2;
public static string templive2;
public static string loadlive2;
public static BlockM.Root BL;
public static UserHash.Root hash;
public static Workers.Root workerscount;
public static MinerBalance.Root minerbalance;
public static SharesInfo.Root sharessinfo;
public static string workerscountapp;
public static string balanceunpaid;
public static string sharesvalid;
public static string hashratesfromminer;
//gpu
private Computer computer = new Computer
{
IsGpuEnabled = true
};
public async void ApplicationStart(object sender, StartupEventArgs e)
{
try
{
MainWindow mainwindow = new MainWindow();
mainwindow.Show();
//get gpu details
await Task.Run(gpu);
await Task.Run(minerapi);
await Task.Run(async () =>
{
//get eth balance
RestClient<CryptoEco.Root> ethh = new RestClient<CryptoEco.Root>();
eth = await ethh.GetAsync("https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=USD");
Debug.WriteLine("App.xaml.cs Crypto");
if (eth == null)
{
return;
}
//get blockchain details
RestClient<BlockM.Root> blocks = new RestClient<BlockM.Root>();
BL = await blocks.GetAsync("https://etherchain.org/api/basic_stats");
Debug.WriteLine("App.xaml.cs BlockM");
if (BL == null)
{
return;
}
});
}
catch
{
}
}
private async void gpu()
{
try
{
while (true)
{
//get gpu details by LibreHardwareMonitor
computer.Open();
{
foreach (IHardware hardware in computer.Hardware)
{
hardware.Update();
foreach (ISensor sensor in hardware.Sensors)
{
//get fan speed
if (sensor.Name.Equals("GPU Fan", StringComparison.OrdinalIgnoreCase))
{
fanlive2 = ($"{sensor.Value}%");
}
//get temp
if (sensor.SensorType == SensorType.Temperature)
{
templive2 = (sensor.Value + " " + "celsius (°C)");
}
//get gpu load
if (sensor.SensorType == SensorType.Load)
{
loadlive2 = (sensor.Value + "%");
}
}
}
};
await Task.Delay(500);
computer.Close();
}
}
catch
{
}
}
private async void minerapi()
{
try
{
while (true)
{
//workers
RestClient<Workers.Root> workersonline = new RestClient<Workers.Root>();
workerscount = await workersonline.GetAsync("https://api.flexpool.io/v2/miner/workerCount?coin=ETH&address=0x0473E7Ade3C7cc6371aFBa073f0E918134F20205");
Debug.WriteLine("App.xaml.cs Workers");
if (workerscount != null)
workerscountapp = workerscount.result.workersOnline + "/" + workerscount.result.workersOffline;
else
workerscountapp = "0" + "/" + "0";
await Task.Delay(500);
//unpaid balance
RestClient<MinerBalance.Root> unpaid = new RestClient<MinerBalance.Root>();
minerbalance = await unpaid.GetAsync("https://api.flexpool.io/v2/miner/balance?coin=ETH&address=0x0473E7Ade3C7cc6371aFBa073f0E918134F20205");
Debug.WriteLine("App.xaml.cs MinerBalance");
if (minerbalance != null)
balanceunpaid = minerbalance.result.balanceCountervalue + " " + "USD";
else
balanceunpaid = "0" + " " + "USD";
await Task.Delay(500);
//Shares Info
RestClient<SharesInfo.Root> sharesinfo = new RestClient<SharesInfo.Root>();
sharessinfo = await sharesinfo.GetAsync("https://api.flexpool.io/v2/miner/workers?coin=ETH&address=0x0473E7Ade3C7cc6371aFBa073f0E918134F20205&worker=" + $"Guest");
Debug.WriteLine("App.xaml.cs SharesInfo");
if (sharessinfo.result != null)
sharesvalid = sharessinfo.result[0].validShares.ToString();
else
sharesvalid = "0";
if (Process.GetProcesses().Count(p => p.ProcessName == "lolMiner") == 1)
{
RestClient<UserHash.Root> userhash1 = new RestClient<UserHash.Root>();
hash = await userhash1.GetAsync("http://localhost:4789");
Debug.WriteLine("App.xaml.cs UserHash");
if (hash != null)
hashratesfromminer = hash.Session.Performance_Summary.ToString();
else
hashratesfromminer = "0";
}
else
{
hashratesfromminer = "0";
}
}
}
catch
{
}
}
}
}