Ejemplo n.º 1
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 = "卸载";
             });
         }
     });
 }
Ejemplo n.º 2
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();
         }));
     });
 }
Ejemplo n.º 3
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))
             {
                 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);
     });
 }
Ejemplo n.º 4
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");
     });
 }
Ejemplo n.º 5
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 = "卸载";
             });
         }
     });
 }