コード例 #1
0
ファイル: CoinKernelViewModel.cs プロジェクト: vebin/ntminer
 public CoinKernelViewModel(Guid id)
 {
     _id = id;
     this.AddEnvironmentVariable = new DelegateCommand(() => {
         VirtualRoot.Execute(new EnvironmentVariableEditCommand(this, new EnvironmentVariable()));
     });
     this.EditEnvironmentVariable = new DelegateCommand <EnvironmentVariable>(environmentVariable => {
         VirtualRoot.Execute(new EnvironmentVariableEditCommand(this, environmentVariable));
     });
     this.RemoveEnvironmentVariable = new DelegateCommand <EnvironmentVariable>(environmentVariable => {
         this.ShowDialog(message: $"您确定删除环境变量{environmentVariable.Key}吗?", title: "确认", onYes: () => {
             this.EnvironmentVariables.Remove(environmentVariable);
             EnvironmentVariables = EnvironmentVariables.ToList();
         }, icon: IconConst.IconConfirm);
     });
     this.AddSegment = new DelegateCommand(() => {
         VirtualRoot.Execute(new InputSegmentEditCommand(this, new InputSegment()));
     });
     this.EditSegment = new DelegateCommand <InputSegment>((segment) => {
         VirtualRoot.Execute(new InputSegmentEditCommand(this, segment));
     });
     this.RemoveSegment = new DelegateCommand <InputSegment>((segment) => {
         this.ShowDialog(message: $"您确定删除片段{segment.Name}吗?", title: "确认", onYes: () => {
             this.InputSegments.Remove(segment);
             InputSegments = InputSegments.ToList();
         }, icon: IconConst.IconConfirm);
     });
     this.RemoveFileWriter = new DelegateCommand <FileWriterViewModel>((writer) => {
         this.ShowDialog(message: $"您确定删除文件书写器{writer.Name}吗?", title: "确认", onYes: () => {
             this.FileWriterVms.Remove(writer);
             List <Guid> writerIds = new List <Guid>(this.FileWriterIds);
             writerIds.Remove(writer.Id);
             this.FileWriterIds = writerIds;
         }, icon: IconConst.IconConfirm);
     });
     this.RemoveFragmentWriter = new DelegateCommand <FragmentWriterViewModel>((writer) => {
         this.ShowDialog(message: $"您确定删除文件书写器{writer.Name}吗?", title: "确认", onYes: () => {
             this.FragmentWriterVms.Remove(writer);
             List <Guid> writerIds = new List <Guid>(this.FragmentWriterIds);
             writerIds.Remove(writer.Id);
             this.FragmentWriterIds = writerIds;
         }, icon: IconConst.IconConfirm);
     });
     this.Save = new DelegateCommand(() => {
         if (NTMinerRoot.Instance.CoinKernelSet.Contains(this.Id))
         {
             VirtualRoot.Execute(new UpdateCoinKernelCommand(this));
         }
         CloseWindow?.Invoke();
     });
     this.Edit = new DelegateCommand <FormType?>((formType) => {
         VirtualRoot.Execute(new CoinKernelEditCommand(formType ?? FormType.Edit, this));
     });
     this.Remove = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         this.ShowDialog(message: $"您确定删除{Kernel.Code}币种内核吗?", title: "确认", onYes: () => {
             VirtualRoot.Execute(new RemoveCoinKernelCommand(this.Id));
             Kernel.OnPropertyChanged(nameof(Kernel.SupportedCoins));
         }, icon: IconConst.IconConfirm);
     });
     this.SortUp = new DelegateCommand(() => {
         CoinKernelViewModel upOne = AppContext.Instance.CoinKernelVms.AllCoinKernels.OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.CoinId == this.CoinId && a.SortNumber < this.SortNumber);
         if (upOne != null)
         {
             int sortNumber   = upOne.SortNumber;
             upOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateCoinKernelCommand(upOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateCoinKernelCommand(this));
             if (AppContext.Instance.CoinVms.TryGetCoinVm(this.CoinId, out CoinViewModel coinVm))
             {
                 coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels));
             }
             this.Kernel.OnPropertyChanged(nameof(this.Kernel.CoinKernels));
             AppContext.Instance.CoinVms.OnPropertyChanged(nameof(AppContext.CoinViewModels.MainCoins));
         }
     });
     this.SortDown = new DelegateCommand(() => {
         CoinKernelViewModel nextOne = AppContext.Instance.CoinKernelVms.AllCoinKernels.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.CoinId == this.CoinId && a.SortNumber > this.SortNumber);
         if (nextOne != null)
         {
             int sortNumber     = nextOne.SortNumber;
             nextOne.SortNumber = this.SortNumber;
             VirtualRoot.Execute(new UpdateCoinKernelCommand(nextOne));
             this.SortNumber = sortNumber;
             VirtualRoot.Execute(new UpdateCoinKernelCommand(this));
             if (AppContext.Instance.CoinVms.TryGetCoinVm(this.CoinId, out CoinViewModel coinVm))
             {
                 coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels));
             }
             this.Kernel.OnPropertyChanged(nameof(this.Kernel.CoinKernels));
             AppContext.Instance.CoinVms.OnPropertyChanged(nameof(AppContext.CoinViewModels.MainCoins));
         }
     });
 }
コード例 #2
0
 public CoinKernelViewModel(Guid id)
 {
     _id = id;
     this.AddEnvironmentVariable = new DelegateCommand(() => {
         VirtualRoot.Execute(new EnvironmentVariableEditCommand(this, new EnvironmentVariable()));
     });
     this.EditEnvironmentVariable = new DelegateCommand <EnvironmentVariable>(environmentVariable => {
         VirtualRoot.Execute(new EnvironmentVariableEditCommand(this, environmentVariable));
     });
     this.RemoveEnvironmentVariable = new DelegateCommand <EnvironmentVariable>(environmentVariable => {
         this.ShowSoftDialog(new DialogWindowViewModel(message: $"您确定删除环境变量{environmentVariable.Key}吗?", title: "确认", onYes: () => {
             this.EnvironmentVariables.Remove(environmentVariable);
             EnvironmentVariables = EnvironmentVariables.ToList();
         }));
     });
     this.AddSegment = new DelegateCommand(() => {
         VirtualRoot.Execute(new InputSegmentEditCommand(this, new InputSegmentViewModel()));
     });
     this.EditSegment = new DelegateCommand <InputSegmentViewModel>((segment) => {
         VirtualRoot.Execute(new InputSegmentEditCommand(this, segment));
     });
     this.RemoveSegment = new DelegateCommand <InputSegmentViewModel>((segment) => {
         this.ShowSoftDialog(new DialogWindowViewModel(message: $"您确定删除片段{segment.Name}吗?", title: "确认", onYes: () => {
             this.InputSegments.Remove(this.InputSegments.FirstOrDefault(a => a.Name == segment.Name && a.Segment == segment.Segment && a.TargetGpu == segment.TargetGpu));
             InputSegments = InputSegments.ToList();
         }));
     });
     this.RemoveFileWriter = new DelegateCommand <FileWriterViewModel>((writer) => {
         this.ShowSoftDialog(new DialogWindowViewModel(message: $"您确定删除文件书写器{writer.Name}吗?", title: "确认", onYes: () => {
             this.FileWriterVms.Remove(writer);
             List <Guid> writerIds = new List <Guid>(this.FileWriterIds);
             writerIds.Remove(writer.Id);
             this.FileWriterIds = writerIds;
         }));
     });
     this.RemoveFragmentWriter = new DelegateCommand <FragmentWriterViewModel>((writer) => {
         this.ShowSoftDialog(new DialogWindowViewModel(message: $"您确定删除文件书写器{writer.Name}吗?", title: "确认", onYes: () => {
             this.FragmentWriterVms.Remove(writer);
             List <Guid> writerIds = new List <Guid>(this.FragmentWriterIds);
             writerIds.Remove(writer.Id);
             this.FragmentWriterIds = writerIds;
         }));
     });
     this.Save = new DelegateCommand(() => {
         if (NTMinerRoot.Instance.ServerContext.CoinKernelSet.Contains(this.Id))
         {
             VirtualRoot.Execute(new UpdateCoinKernelCommand(this));
         }
         VirtualRoot.Execute(new CloseWindowCommand(this.Id));
     });
     this.Edit = new DelegateCommand <FormType?>((formType) => {
         VirtualRoot.Execute(new CoinKernelEditCommand(formType ?? FormType.Edit, this));
     });
     this.Remove = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         this.ShowSoftDialog(new DialogWindowViewModel(message: $"您确定删除{Kernel.Code}币种内核吗?", title: "确认", onYes: () => {
             VirtualRoot.Execute(new RemoveCoinKernelCommand(this.Id));
             Kernel.OnPropertyChanged(nameof(Kernel.SupportedCoins));
         }));
     });
 }