ntminer 5 years ago
parent
commit
21b5e6b44d

+ 22 - 0
src/AppModels/MinerStudio/Vms/GpuNameCountViewModel.cs

@@ -1,6 +1,7 @@
 using NTMiner.Core;
 using NTMiner.Core.Gpus;
 using NTMiner.Vms;
+using System.Collections.Generic;
 using System.Windows;
 
 namespace NTMiner.MinerStudio.Vms {
@@ -9,6 +10,7 @@ namespace NTMiner.MinerStudio.Vms {
         private string _name;
         private ulong _totalMemory;
         private int _count;
+        private GpuNameViewModel _matchName;
 
         public GpuNameCountViewModel(IGpuNameCount data) {
             _gpuType = data.GpuType;
@@ -74,6 +76,26 @@ namespace NTMiner.MinerStudio.Vms {
             }
         }
 
+        public GpuNameViewModel MatchName {
+            get => _matchName;
+            set {
+                if (_matchName != value) {
+                    _matchName = value;
+                    OnPropertyChanged(nameof(MatchName));
+                }
+            }
+        }
+
+        public void Match(IEnumerable<IGpuName> gpuNames) {
+            var matchName = this.GetMatchGpuName(gpuNames);
+            if (matchName == null) {
+                this.MatchName = null;
+            }
+            else {
+                this.MatchName = new GpuNameViewModel(matchName);
+            }
+        }
+
         public ulong TotalMemory {
             get => _totalMemory;
             set {

+ 5 - 1
src/AppModels/MinerStudio/Vms/GpuNameCountsViewModel.cs

@@ -1,5 +1,6 @@
 using NTMiner.Core.Gpus;
 using NTMiner.Vms;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Windows.Input;
@@ -19,7 +20,9 @@ namespace NTMiner.MinerStudio.Vms {
 
         public ICommand Search { get; private set; }
 
-        public GpuNameCountsViewModel() {
+        private readonly Action _onQueryResponsed;
+        public GpuNameCountsViewModel(Action onQueryResponsed) {
+            _onQueryResponsed = onQueryResponsed;
             this._pagingVm = new PagingViewModel(() => this.PageIndex, () => this.PageSize);
             this.Search = new DelegateCommand(() => {
                 this.PageIndex = 1;
@@ -50,6 +53,7 @@ namespace NTMiner.MinerStudio.Vms {
                     this.GpuNameCounts = new List<GpuNameCountViewModel>();
                     _pagingVm.Init(0);
                 }
+                _onQueryResponsed?.Invoke();
             });
         }
 

+ 10 - 2
src/AppModels/MinerStudio/Vms/GpuNamePageViewModel.cs

@@ -1,8 +1,16 @@
 namespace NTMiner.MinerStudio.Vms {
     public class GpuNamePageViewModel {
         public GpuNamePageViewModel() {
-            this.GpuNamesVm = new GpuNamesViewModel();
-            this.GpuNameCountsVm = new GpuNameCountsViewModel();
+            this.GpuNamesVm = new GpuNamesViewModel(OnQueryResponsed);
+            this.GpuNameCountsVm = new GpuNameCountsViewModel(OnQueryResponsed);
+        }
+
+        private void OnQueryResponsed() {
+            if (this.GpuNamesVm.GpuNames.Count > 0 && this.GpuNameCountsVm.GpuNameCounts.Count > 0) {
+                foreach (var item in this.GpuNameCountsVm.GpuNameCounts) {
+                    item.Match(this.GpuNamesVm.GpuNames);
+                }
+            }
         }
 
         public GpuNamesViewModel GpuNamesVm { get; private set; }

+ 5 - 1
src/AppModels/MinerStudio/Vms/GpuNamesViewModel.cs

@@ -1,5 +1,6 @@
 using NTMiner.Core.Gpus;
 using NTMiner.Vms;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Windows.Input;
@@ -22,7 +23,9 @@ namespace NTMiner.MinerStudio.Vms {
 
         public ICommand Search { get; private set; }
 
-        public GpuNamesViewModel() {
+        private readonly Action _onQueryResponsed;
+        public GpuNamesViewModel(Action onQueryResponsed) {
+            _onQueryResponsed = onQueryResponsed;
             this._pagingVm = new PagingViewModel(() => this.PageIndex, () => this.PageSize);
             this.Add = new DelegateCommand(() => {
                 VirtualRoot.Execute(new AddGpuNameCommand(new GpuNameViewModel(new GpuName {
@@ -79,6 +82,7 @@ namespace NTMiner.MinerStudio.Vms {
                     this.GpuNames = new List<GpuNameViewModel>();
                     _pagingVm.Init(0);
                 }
+                _onQueryResponsed?.Invoke();
             });
         }
 

+ 8 - 1
src/AppViews0/MinerStudio/Views/Ucs/GpuNameCounts.xaml

@@ -12,7 +12,7 @@
     Background="White"
 	mc:Ignorable="d" 
     d:DesignHeight="700" 
-    d:DesignWidth="600"
+    d:DesignWidth="800"
     d:DataContext="{d:DesignData Source=../Design/GpuNameCountsViewModel.xaml}">
     <Grid Background="{StaticResource ToolbarBackground}">
         <Grid.RowDefinitions>
@@ -88,6 +88,13 @@
                         </DataTemplate>
                     </DataGridTemplateColumn.CellTemplate>
                 </DataGridTemplateColumn>
+                <DataGridTemplateColumn Width="100" IsReadOnly="True" Header="匹配">
+                    <DataGridTemplateColumn.CellTemplate>
+                        <DataTemplate>
+                            <TextBlock Text="{Binding MatchName.Name}"></TextBlock>
+                        </DataTemplate>
+                    </DataGridTemplateColumn.CellTemplate>
+                </DataGridTemplateColumn>
                 <DataGridTemplateColumn Width="*" IsReadOnly="True" Header="名称">
                     <DataGridTemplateColumn.CellTemplate>
                         <DataTemplate>

+ 21 - 0
src/NTMinerDataSchemas/Core/Gpus/GpuNameCountExtensions.cs

@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace NTMiner.Core.Gpus {
+    public static class GpuNameCountExtensions {
+        public static IGpuName GetMatchGpuName(this IGpuNameCount gpuNameCount, IEnumerable<IGpuName> gpuNames) {
+            if (gpuNames == null) {
+                return null;
+            }
+            gpuNames = gpuNames.OrderByDescending(a => a.Name);
+            foreach (var gpuName in gpuNames) {
+                if (GpuName.ConvertToGb(gpuName.TotalMemory) == GpuName.ConvertToGb(gpuNameCount.TotalMemory) 
+                    && gpuNameCount.Name.IndexOf(gpuName.Name, StringComparison.OrdinalIgnoreCase) != -1) {
+                    return gpuName;
+                }
+            }
+            return null;
+        }
+    }
+}

+ 1 - 0
src/NTMinerDataSchemas/NTMinerDataSchemas.csproj

@@ -45,6 +45,7 @@
     <Compile Include="Core\CaptchaData.cs" />
     <Compile Include="Core\Gpus\GpuName.cs" />
     <Compile Include="Core\Gpus\GpuNameCount.cs" />
+    <Compile Include="Core\Gpus\GpuNameCountExtensions.cs" />
     <Compile Include="Core\Gpus\IGpuName.cs" />
     <Compile Include="Core\Gpus\IGpuNameCount.cs" />
     <Compile Include="Core\Gpus\QueryGpuNameCountsRequest.cs" />