Skip to content

Commit 5981505

Browse files
author
ntminer
committed
test
1 parent e1dfe1a commit 5981505

File tree

27 files changed

+391
-12212
lines changed

27 files changed

+391
-12212
lines changed

src/AppModels/AppStatic.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,7 @@ public static string ExportServerJsonFileName {
735735
});
736736

737737
public static ICommand OpenOfficialSite { get; private set; } = new DelegateCommand(() => {
738-
string url = "http://ntminer.com/";
739-
url = NTMinerContext.Instance.ServerContext.SysDicItemSet.TryGetDicItemValue(NTKeyword.ThisSystemSysDicCode, "HomePageUrl", defaultValue: url);
738+
string url = HomePageUrl;
740739
VirtualRoot.Execute(new UnTopmostCommand());
741740
Process.Start(url);
742741
});
@@ -750,16 +749,23 @@ public static string QQGroup {
750749
}
751750
}
752751

753-
public static string OfficialSiteName {
752+
public static string HomePageUrl {
754753
get {
755-
string url = "NTMiner.com";
754+
string url = "https://ntminer.com";
756755
if (WpfUtil.IsInDesignMode) {
757756
return url;
758757
}
759758
string dicItemValue = NTMinerContext.Instance.ServerContext.SysDicItemSet.TryGetDicItemValue(NTKeyword.ThisSystemSysDicCode, "HomePageUrl", defaultValue: url);
760759
if (!string.IsNullOrEmpty(dicItemValue)) {
761760
url = dicItemValue;
762761
}
762+
return url;
763+
}
764+
}
765+
766+
public static string OfficialSiteName {
767+
get {
768+
string url = HomePageUrl;
763769
if (!string.IsNullOrEmpty(url)) {
764770
if (url.StartsWith("https://")) {
765771
return url.Substring("https://".Length);

src/AppModels/MinerStudio/Vms/WebApiServerStateViewModel.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public WebApiServerStateViewModel(IWebApiServerState data) {
3838
_cpu = data.Cpu;
3939
_cpuVm = new CpuDataViewModel(data.Cpu);
4040
_wsServerNodes = data.WsServerNodes;
41+
_wsServerNodes.Sort((l, r) => string.Compare(l.Description, r.Description));
4142
_wsServerNodeVms = new ObservableCollection<WsServerNodeStateViewModel>(data.WsServerNodes.Select(a => new WsServerNodeStateViewModel(a)));
4243
}
4344

@@ -65,24 +66,34 @@ public List<WsServerNodeState> WsServerNodes {
6566
_wsServerNodeVms.Clear();
6667
}
6768
else {
69+
bool needSort = false;
6870
if (_wsServerNodeVms == null) {
71+
needSort = true;
6972
_wsServerNodeVms = new ObservableCollection<WsServerNodeStateViewModel>(value.Select(a => new WsServerNodeStateViewModel(a)));
7073
}
7174
else {
7275
var toRemoves = _wsServerNodeVms.Where(a => value.All(b => b.Address != a.Address)).ToArray();
76+
if (toRemoves.Length != 0) {
77+
needSort = true;
78+
}
7379
foreach (var item in toRemoves) {
74-
_wsServerNodeVms.Remove(item);
80+
_ = _wsServerNodeVms.Remove(item);
7581
}
7682
foreach (var item in value) {
7783
var vm = _wsServerNodeVms.FirstOrDefault(a => a.Address == item.Address);
7884
if (vm != null) {
7985
vm.Update(item);
8086
}
8187
else {
88+
needSort = true;
8289
_wsServerNodeVms.Add(new WsServerNodeStateViewModel(item));
8390
}
8491
}
8592
}
93+
if (needSort) {
94+
_wsServerNodeVms = new ObservableCollection<WsServerNodeStateViewModel>(_wsServerNodeVms.OrderBy(a => a.Description));
95+
OnPropertyChanged(nameof(WsServerNodeVms));
96+
}
8697
}
8798
OnPropertyChanged(nameof(MinerClientWsSessionCount));
8899
OnPropertyChanged(nameof(MinerClientSessionCount));

src/AppModels/Vms/SpeedTableViewModel.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using NTMiner.Gpus;
2-
using System.Windows;
1+
using System.Windows;
32

43
namespace NTMiner.Vms {
54
public class SpeedTableViewModel : ViewModelBase {
@@ -18,15 +17,6 @@ public Visibility IsPCIEVisible {
1817
}
1918
}
2019

21-
public Visibility IsVoltVisible {
22-
get {
23-
if (NTMinerContext.Instance.GpuSet.GpuType == GpuType.AMD) {
24-
return Visibility.Visible;
25-
}
26-
return Visibility.Collapsed;
27-
}
28-
}
29-
3020
public AppRoot.GpuSpeedViewModels GpuSpeedVms {
3121
get {
3222
return AppRoot.GpuSpeedViewModels.Instance;

src/AppViews0/MinerStudio/Views/Ucs/WsServerNodePage.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
</DataTemplate>
103103
</DataGridTemplateColumn.CellTemplate>
104104
</DataGridTemplateColumn>
105+
<DataGridTextColumn Width="100" IsReadOnly="True" Header="备注" Binding="{Binding Description}">
106+
</DataGridTextColumn>
105107
<DataGridTextColumn IsReadOnly="True" Width="100" Binding="{Binding MinerClientWsSessionCount}">
106108
<DataGridTextColumn.Header>
107109
<StackPanel>
@@ -163,7 +165,7 @@
163165
</DataGridTextColumn>
164166
<DataGridTextColumn IsReadOnly="True" Width="60" Header="CPU架构" Binding="{Binding CpuVm.ProcessorArchitecture}">
165167
</DataGridTextColumn>
166-
<DataGridTemplateColumn IsReadOnly="True" Width="280" Header="操作系统/CPU名称">
168+
<DataGridTemplateColumn IsReadOnly="True" Width="*" Header="操作系统/CPU名称">
167169
<DataGridTemplateColumn.CellTemplate>
168170
<DataTemplate>
169171
<StackPanel>
@@ -173,8 +175,6 @@
173175
</DataTemplate>
174176
</DataGridTemplateColumn.CellTemplate>
175177
</DataGridTemplateColumn>
176-
<DataGridTextColumn Width="*" IsReadOnly="True" Header="备注" Binding="{Binding Description}">
177-
</DataGridTextColumn>
178178
</DataGrid.Columns>
179179
</DataGrid>
180180
<TextBlock

src/AppViews0/Views/Ucs/AboutPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
KbDisplayLine="False"
3838
HorizontalAlignment="Left"
3939
Background="Transparent">
40-
<TextBlock Text="https://ntminer.com/"></TextBlock>
40+
<TextBlock Text="{x:Static app:AppStatic.HomePageUrl}"></TextBlock>
4141
</controls:KbLinkButton>
4242
</WrapPanel>
4343
</StackPanel>

src/AppViews0/Views/Ucs/SpeedTable.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@
367367
</DataTemplate>
368368
</DataGridTemplateColumn.CellTemplate>
369369
</DataGridTemplateColumn>
370-
<DataGridTemplateColumn MinWidth="50" Width="50" IsReadOnly="True" CanUserResize="False" Visibility="{Binding Data.IsVoltVisible,Source={StaticResource proxy}}">
370+
<DataGridTemplateColumn MinWidth="50" Width="50" IsReadOnly="True" CanUserResize="False">
371371
<DataGridTemplateColumn.HeaderTemplate>
372372
<DataTemplate>
373373
<StackPanel>
@@ -435,7 +435,7 @@
435435
</DataTemplate>
436436
</DataGridTemplateColumn.CellTemplate>
437437
</DataGridTemplateColumn>
438-
<DataGridTemplateColumn MinWidth="50" Width="50" IsReadOnly="True" Header="显存电压" CanUserResize="False" Visibility="{Binding Data.IsVoltVisible,Source={StaticResource proxy}}">
438+
<DataGridTemplateColumn MinWidth="50" Width="50" IsReadOnly="True" Header="显存电压" CanUserResize="False">
439439
<DataGridTemplateColumn.HeaderTemplate>
440440
<DataTemplate>
441441
<StackPanel>

src/CalcConfigUpdater/CalcConfigUpdater.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
</ItemGroup>
5858
<ItemGroup>
5959
<Compile Include="ConfigData.cs" />
60+
<Compile Include="HtmlUtil.cs" />
6061
<Compile Include="IncomeItem.cs" />
6162
<Compile Include="Program.cs" />
6263
<Compile Include="Properties\AssemblyInfo.cs" />

src/CalcConfigUpdater/HtmlUtil.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.IO;
3+
using System.Net;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace NTMiner {
8+
public static class HtmlUtil {
9+
public static async Task<string> GetF2poolHtmlAsync() {
10+
return await Task.Factory.StartNew(() => {
11+
try {
12+
string url = $"https://www.f2pool.com/?t={DateTime.Now.Ticks.ToString()}";
13+
if (url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) {
14+
// 没有这一行可能会报错:System.Net.WebException: 请求被中止: 未能创建 SSL/TLS 安全通道
15+
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
16+
}
17+
var httpWebRequest = WebRequest.Create(url) as HttpWebRequest;
18+
httpWebRequest.Timeout = 30 * 1000;
19+
httpWebRequest.Method = "GET";
20+
httpWebRequest.Referer= "http://dl.ntminer.top";
21+
httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9";
22+
httpWebRequest.Headers["accept-encoding"] = "gzip, deflate, br";
23+
httpWebRequest.Headers["accept-language"] = "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6";
24+
httpWebRequest.Headers["cache-control"] = "max-age=0";
25+
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.67";
26+
var response = httpWebRequest.GetResponse();
27+
using (Stream ms = new MemoryStream(), stream = response.GetResponseStream()) {
28+
byte[] buffer = new byte[NTKeyword.IntK];
29+
int n = stream.Read(buffer, 0, buffer.Length);
30+
while (n > 0) {
31+
ms.Write(buffer, 0, n);
32+
n = stream.Read(buffer, 0, buffer.Length);
33+
}
34+
byte[] data = new byte[ms.Length];
35+
ms.Position = 0;
36+
ms.Read(data, 0, data.Length);
37+
data = RpcRoot.ZipDecompress(data);
38+
return Encoding.UTF8.GetString(data);
39+
}
40+
}
41+
catch (Exception e) {
42+
Logger.ErrorDebugLine(e);
43+
return string.Empty;
44+
}
45+
});
46+
}
47+
}
48+
}

src/CalcConfigUpdater/Program.cs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
using System.Collections.Generic;
66
using System.IO;
77
using System.Linq;
8-
using System.Net;
9-
using System.Net.Http;
10-
using System.Text;
118
using System.Text.RegularExpressions;
129
using System.Threading.Tasks;
1310

@@ -63,19 +60,11 @@ static void Main() {
6360
}
6461

6562
private static void UpdateAsync() {
66-
Task.Factory.StartNew(() => {
63+
Task.Factory.StartNew(async () => {
6764
try {
68-
Task<byte[]> htmlDataTask = GetHtmlAsync("https://www.f2pool.com/");
69-
byte[] htmlData = null;
70-
try {
71-
Task.WaitAll(new Task[] { htmlDataTask }, 60 * 1000);
72-
htmlData = htmlDataTask.Result;
73-
}
74-
catch {
75-
}
76-
if (htmlData != null && htmlData.Length != 0) {
65+
string html = await HtmlUtil.GetF2poolHtmlAsync();
66+
if (!string.IsNullOrEmpty(html)) {
7767
NTMinerConsole.UserOk($"{DateTime.Now.ToString()} - 鱼池首页html获取成功");
78-
string html = Encoding.UTF8.GetString(htmlData);
7968
double usdCny = PickUsdCny(html);
8069
NTMinerConsole.UserInfo($"usdCny={usdCny.ToString()}");
8170
List<IncomeItem> incomeItems = PickIncomeItems(html);
@@ -288,20 +277,5 @@ private static double PickUsdCny(string html) {
288277
return 0;
289278
}
290279
}
291-
292-
private static async Task<byte[]> GetHtmlAsync(string url) {
293-
try {
294-
// 没有这一行可能会报错:System.Net.WebException: 请求被中止: 未能创建 SSL/TLS 安全通道
295-
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
296-
using (HttpClient client = RpcRoot.CreateHttpClient()) {
297-
client.Timeout = TimeSpan.FromSeconds(20);
298-
return await client.GetByteArrayAsync(url);
299-
}
300-
}
301-
catch (Exception e) {
302-
Logger.ErrorDebugLine(e);
303-
return new byte[0];
304-
}
305-
}
306280
}
307281
}

0 commit comments

Comments
 (0)