Пример #1
0
 public KernelSelectViewModel(CoinViewModel coin, KernelViewModel selectedKernel, Action <KernelViewModel> onOk)
 {
     _coin             = coin;
     _selectedResult   = selectedKernel;
     OnOk              = onOk;
     this.ClearKeyword = new DelegateCommand(() => {
         this.Keyword = string.Empty;
     });
 }
Пример #2
0
 public KernelProfileViewModel(KernelViewModel kernelVm, IKernelProfile kernelProfile)
 {
     _kernelVm      = kernelVm;
     _kernelProfile = kernelProfile;
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     this.CancelDownload = new DelegateCommand(() => {
         _cancelDownload?.Invoke();
     });
     this.Install = new DelegateCommand(() => {
         this.Download();
     });
     this.UnInstall = new DelegateCommand(() => {
         if (this.UnInstallText == "确认卸载")
         {
             string processName = _kernelVm.GetProcessName();
             if (!string.IsNullOrEmpty(processName))
             {
                 Windows.TaskKill.Kill(processName, waitForExit: true);
                 string packageFileFullName = _kernelVm.GetPackageFileFullName();
                 if (!string.IsNullOrEmpty(packageFileFullName))
                 {
                     File.Delete(packageFileFullName);
                 }
                 string kernelDirFullName = _kernelVm.GetKernelDirFullName();
                 if (!string.IsNullOrEmpty(kernelDirFullName) && Directory.Exists(kernelDirFullName))
                 {
                     try {
                         Directory.Delete(kernelDirFullName, recursive: true);
                     }
                     catch (Exception e) {
                         Logger.ErrorDebugLine(e);
                     }
                 }
                 string downloadFileFullName = _kernelVm.GetDownloadFileFullName();
                 if (!string.IsNullOrEmpty(downloadFileFullName))
                 {
                     File.Delete(downloadFileFullName);
                 }
             }
             Refresh();
             this.InstallText = "卸载成功";
             TimeSpan.FromSeconds(2).Delay().ContinueWith(t => {
                 this.InstallText = "安装";
             });
         }
         else
         {
             this.UnInstallText = "确认卸载";
             TimeSpan.FromSeconds(2).Delay().ContinueWith(t => {
                 this.UnInstallText = "卸载";
             });
         }
     });
 }
Пример #3
0
 public KernelProfileViewModel(KernelViewModel kernelVm, IKernelProfile kernelProfile)
 {
     _kernelVm      = kernelVm;
     _kernelProfile = kernelProfile;
     if (Design.IsInDesignMode)
     {
         return;
     }
     this.CancelDownload = new DelegateCommand(() => {
         _cancelDownload?.Invoke();
     });
     this.Install = new DelegateCommand(() => {
         this.Download();
     });
     this.UnInstall = new DelegateCommand(() => {
         this.ShowDialog(new DialogWindowViewModel(message: $"您确定卸载{_kernelVm.FullName}内核吗?", title: "确认", onYes: () => {
             string processName = _kernelVm.GetProcessName();
             if (!string.IsNullOrEmpty(processName))
             {
                 Windows.TaskKill.Kill(processName, waitForExit: true);
                 string packageFileFullName = _kernelVm.GetPackageFileFullName();
                 if (!string.IsNullOrEmpty(packageFileFullName))
                 {
                     File.Delete(packageFileFullName);
                 }
                 string kernelDirFullName = _kernelVm.GetKernelDirFullName();
                 if (!string.IsNullOrEmpty(kernelDirFullName) && Directory.Exists(kernelDirFullName))
                 {
                     try {
                         Directory.Delete(kernelDirFullName, recursive: true);
                     }
                     catch (Exception e) {
                         Logger.ErrorDebugLine(e);
                     }
                 }
                 string downloadFileFullName = _kernelVm.GetDownloadFileFullName();
                 if (!string.IsNullOrEmpty(downloadFileFullName))
                 {
                     File.Delete(downloadFileFullName);
                 }
             }
             Refresh();
         }));
     });
 }
 public KernelProfileViewModel(KernelViewModel kernelVm, IKernelProfile kernelProfile)
 {
     _kernelVm           = kernelVm;
     _kernelProfile      = kernelProfile;
     this.CancelDownload = new DelegateCommand(() => {
         _cancelDownload?.Invoke();
     });
     this.Install = new DelegateCommand(() => {
         this.Download();
     });
     this.UnInstall = new DelegateCommand(() => {
         DialogWindow.ShowDialog(message: $"您确定卸载{_kernelVm.FullName}内核吗?", title: "确认", onYes: () => {
             string processName = _kernelVm.GetProcessName();
             if (!string.IsNullOrEmpty(processName))
             {
                 Windows.TaskKill.Kill(processName);
                 string packageFileFullName = _kernelVm.GetPackageFileFullName();
                 if (!string.IsNullOrEmpty(packageFileFullName))
                 {
                     File.Delete(packageFileFullName);
                 }
                 string kernelDirFullName = _kernelVm.GetKernelDirFullName();
                 if (!string.IsNullOrEmpty(kernelDirFullName) && Directory.Exists(kernelDirFullName))
                 {
                     try {
                         Directory.Delete(kernelDirFullName, recursive: true);
                     }
                     catch (Exception e) {
                         Logger.ErrorDebugLine(e.Message, e);
                     }
                 }
                 string downloadFileFullName = _kernelVm.GetDownloadFileFullName();
                 if (!string.IsNullOrEmpty(downloadFileFullName))
                 {
                     File.Delete(downloadFileFullName);
                 }
             }
             Refresh();
             KernelPageViewModel.Current.OnPropertyChanged(nameof(KernelPageViewModel.QueryResults));
         }, icon: IconConst.IconConfirm);
     });
 }
Пример #5
0
 public KernelProfileViewModel(KernelViewModel kernelVm, IKernelProfile kernelProfile)
 {
     _kernelVm           = kernelVm;
     _kernelProfile      = kernelProfile;
     this.CancelDownload = new DelegateCommand(() => {
         _cancelDownload?.Invoke();
     });
     this.Install = new DelegateCommand(() => {
         this.Download();
     });
     this.UnInstall = new DelegateCommand(() => {
         DialogWindow.ShowDialog(message: $"您确定卸载{_kernelVm.FullName}内核吗?", title: "确认", onYes: () => {
             string processName = _kernelVm.GetProcessName();
             if (!string.IsNullOrEmpty(processName))
             {
                 Process[] processes = Process.GetProcessesByName(processName);
                 if (processes != null && processes.Length != 0)
                 {
                     Windows.TaskKill.Kill(processName);
                 }
                 File.Delete(_kernelVm.GetPackageFileFullName());
                 if (Directory.Exists(_kernelVm.GetKernelDirFullName()))
                 {
                     try {
                         Directory.Delete(_kernelVm.GetKernelDirFullName(), recursive: true);
                     }
                     catch (Exception e) {
                         Global.Logger.Error(e.Message, e);
                     }
                 }
                 File.Delete(_kernelVm.GetDownloadFileFullName());
             }
             Refresh();
             KernelPageViewModel.Current.OnPropertyChanged(nameof(KernelPageViewModel.QueryResults));
         }, icon: "Icon_Confirm");
     });
 }
Пример #6
0
 public bool TryGetKernelVm(Guid kernelId, out KernelViewModel kernelVm)
 {
     return(_dicById.TryGetValue(kernelId, out kernelVm));
 }
Пример #7
0
 public KernelViewModel(Guid id)
 {
     _id       = id;
     this.Edit = new DelegateCommand(() => {
         if (this == Empty)
         {
             return;
         }
         KernelEdit.ShowEditWindow(this);
     });
     this.Remove = new DelegateCommand(() => {
         if (this.Id == Guid.Empty)
         {
             return;
         }
         DialogWindow.ShowDialog(message: $"您确定删除{this.FullName}内核吗?", title: "确认", onYes: () => {
             Global.Execute(new RemoveKernelCommand(this.Id));
         }, icon: "Icon_Confirm");
     });
     this.SortUp = new DelegateCommand(() => {
         KernelViewModel upOne = KernelViewModels.Current.AllKernels.OrderByDescending(a => a.SortNumber).FirstOrDefault(a => a.SortNumber < this.SortNumber);
         if (upOne != null)
         {
             int sortNumber   = upOne.SortNumber;
             upOne.SortNumber = this.SortNumber;
             Global.Execute(new UpdateKernelCommand(upOne));
             this.SortNumber = sortNumber;
             Global.Execute(new UpdateKernelCommand(this));
             KernelViewModels.Current.OnPropertyChanged(nameof(KernelViewModels.AllKernels));
             KernelPageViewModel.Current.OnPropertyChanged(nameof(KernelPageViewModel.QueryResults));
             KernelPageViewModel.Current.OnPropertyChanged(nameof(KernelPageViewModel.DownloadingVms));
         }
     });
     this.SortDown = new DelegateCommand(() => {
         KernelViewModel nextOne = KernelViewModels.Current.AllKernels.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.SortNumber > this.SortNumber);
         if (nextOne != null)
         {
             int sortNumber     = nextOne.SortNumber;
             nextOne.SortNumber = this.SortNumber;
             Global.Execute(new UpdateKernelCommand(nextOne));
             this.SortNumber = sortNumber;
             Global.Execute(new UpdateKernelCommand(this));
             KernelViewModels.Current.OnPropertyChanged(nameof(KernelViewModels.AllKernels));
             KernelPageViewModel.Current.OnPropertyChanged(nameof(KernelPageViewModel.QueryResults));
             KernelPageViewModel.Current.OnPropertyChanged(nameof(KernelPageViewModel.DownloadingVms));
         }
     });
     this.Publish = new DelegateCommand(() => {
         DialogWindow.ShowDialog(message: $"您确定发布{this.Code} (v{this.Version})吗?", title: "确认", onYes: () => {
             this.PublishState = PublishStatus.Published;
             this.PublishOn    = Global.GetTimestamp();
             Global.Execute(new UpdateKernelCommand(this));
         }, icon: "Icon_Confirm");
     });
     this.UnPublish = new DelegateCommand(() => {
         DialogWindow.ShowDialog(message: $"您确定取消发布{this.Code} (v{this.Version})吗?", title: "确认", onYes: () => {
             this.PublishState = PublishStatus.UnPublished;
             Global.Execute(new UpdateKernelCommand(this));
         }, icon: "Icon_Confirm");
     });
     this.BrowsePackage = new DelegateCommand(() => {
         OpenFileDialog openFileDialog = new OpenFileDialog {
             InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
             Filter           = "zip (*.zip)|*.zip",
             FilterIndex      = 1
         };
         if (openFileDialog.ShowDialog() == DialogResult.OK)
         {
             string package = Path.GetFileName(openFileDialog.FileName);
             this.Sha1      = HashUtil.Sha1(File.ReadAllBytes(openFileDialog.FileName));
             this.Package   = package;
             this.Size      = new FileInfo(openFileDialog.FileName).Length;
             this.KernelProfileVm.Refresh();
         }
     });
     this.AddCoinKernel = new DelegateCommand <CoinViewModel>((coinVm) => {
         int sortNumber = coinVm.CoinKernels.Count == 0 ? 1 : coinVm.CoinKernels.Max(a => a.SortNumber) + 1;
         Global.Execute(new AddCoinKernelCommand(new CoinKernelViewModel(Guid.NewGuid())
         {
             Args        = string.Empty,
             CoinId      = coinVm.Id,
             Description = string.Empty,
             KernelId    = this.Id,
             SortNumber  = sortNumber
         }));
     });
     this.AddKernelOutputFilter = new DelegateCommand(() => {
         new KernelOutputFilterViewModel(Guid.NewGuid())
         {
             KernelId = this.Id
         }.Edit.Execute(null);
     });
     this.AddKernelOutputTranslater = new DelegateCommand(() => {
         int sortNumber = this.KernelOutputTranslaters.Count == 0 ? 1 : this.KernelOutputTranslaters.Count + 1;
         new KernelOutputTranslaterViewModel(Guid.NewGuid())
         {
             KernelId   = this.Id,
             SortNumber = sortNumber
         }.Edit.Execute(null);
     });
     this.ShowKernelHelp = new DelegateCommand(() => {
         if (string.IsNullOrEmpty(HelpArg))
         {
             return;
         }
         string helpArg        = this.HelpArg.Trim();
         string asFileFullName = Path.Combine(this.GetKernelDirFullName(), helpArg);
         // 如果当前内核不处在挖矿中则可以解压缩,否则不能解压缩因为内核文件处在使用中无法覆盖
         if (!NTMinerRoot.Current.IsMining || NTMinerRoot.Current.CurrentMineContext.Kernel.GetId() != this.GetId())
         {
             this.ExtractPackage();
         }
         string helpText;
         if (File.Exists(asFileFullName))
         {
             helpText = File.ReadAllText(asFileFullName, Encoding.UTF8);
             KernelHelpPage.ShowWindow("内核帮助 - " + this.FullName, helpText);
         }
         else
         {
             string commandName           = this.GetCommandName(fromHelpArg: true);
             string kernelExeFileFullName = Path.Combine(this.GetKernelDirFullName(), commandName);
             int exitCode = -1;
             Windows.Cmd.RunClose(kernelExeFileFullName, helpArg.Substring(commandName.Length), ref exitCode, out helpText);
         }
         KernelHelpPage.ShowWindow("内核帮助 - " + this.FullName, helpText);
     });
     this.ClearTranslaterKeyword = new DelegateCommand(() => {
         this.TranslaterKeyword = string.Empty;
     });
     this.SelectCopySourceKernel = new DelegateCommand <string>((tag) => {
         KernelCopySourceSelect.ShowWindow(this, tag);
     });
 }
Пример #8
0
 public KernelProfileViewModel(KernelViewModel kernelVm, IKernelProfile kernelProfile)
 {
     _kernelVm      = kernelVm;
     _kernelProfile = kernelProfile;
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     this.CancelDownload = new DelegateCommand(() => {
         _cancelDownload?.Invoke();
     });
     this.Install = new DelegateCommand(() => {
         if (!ClientAppType.IsMinerClient)
         {
             VirtualRoot.Out.ShowWarn("非挖矿端不需要安装内核", autoHideSeconds: 4);
             return;
         }
         this.Download();
     });
     this.UnInstall = new DelegateCommand(() => {
         if (this.UnInstallText == "确认卸载")
         {
             string processName = _kernelVm.GetProcessName();
             if (NTMinerContext.Instance.IsMining)
             {
                 if (NTMinerContext.Instance.LockedMineContext.Kernel.Package == _kernelVm.Package)
                 {
                     VirtualRoot.Out.ShowWarn("该内核正在挖矿,请停止挖矿后再卸载", autoHideSeconds: 4);
                     return;
                 }
             }
             string packageFileFullName = _kernelVm.GetPackageFileFullName();
             if (!string.IsNullOrEmpty(packageFileFullName))
             {
                 File.Delete(packageFileFullName);
             }
             string kernelDirFullName = _kernelVm.GetKernelDirFullName();
             if (!string.IsNullOrEmpty(kernelDirFullName) && Directory.Exists(kernelDirFullName))
             {
                 try {
                     Directory.Delete(kernelDirFullName, recursive: true);
                 }
                 catch (Exception e) {
                     Logger.ErrorDebugLine(e);
                 }
             }
             string downloadFileFullName = _kernelVm.GetDownloadFileFullName();
             if (!string.IsNullOrEmpty(downloadFileFullName))
             {
                 File.Delete(downloadFileFullName);
             }
             Refresh();
             this.InstallText = "卸载成功";
             2.SecondsDelay().ContinueWith(t => {
                 this.InstallText = "安装";
             });
         }
         else
         {
             this.UnInstallText = "确认卸载";
             2.SecondsDelay().ContinueWith(t => {
                 this.UnInstallText = "卸载";
             });
         }
     });
 }