NTMinerUpdaterConfigViewModel.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using NTMiner.Core;
  2. using NTMiner.Vms;
  3. using System;
  4. using System.IO;
  5. using System.Windows.Input;
  6. namespace NTMiner.MinerStudio.Vms {
  7. public class NTMinerUpdaterConfigViewModel : ViewModelBase {
  8. public readonly Guid Id = Guid.NewGuid();
  9. public ICommand Save { get; private set; }
  10. public NTMinerUpdaterConfigViewModel() {
  11. if (WpfUtil.IsInDesignMode) {
  12. return;
  13. }
  14. this.Save = new DelegateCommand(() => {
  15. try {
  16. if (string.IsNullOrEmpty(this.FileName)) {
  17. this.FileName = HomePath.NTMinerUpdaterFileName;
  18. }
  19. VirtualRoot.Execute(new SetServerAppSettingCommand(new AppSettingData {
  20. Key = NTKeyword.NTMinerUpdaterFileNameAppSettingKey,
  21. Value = this.FileName
  22. }));
  23. VirtualRoot.Execute(new CloseWindowCommand(this.Id));
  24. }
  25. catch (Exception e) {
  26. Logger.ErrorDebugLine(e);
  27. }
  28. });
  29. RpcRoot.OfficialServer.FileUrlService.GetNTMinerUpdaterUrlAsync((fileDownloadUrl, e) => {
  30. if (!string.IsNullOrEmpty(fileDownloadUrl)) {
  31. Uri uri = new Uri(fileDownloadUrl);
  32. _fileName = Path.GetFileName(uri.LocalPath);
  33. }
  34. else {
  35. _fileName = HomePath.NTMinerUpdaterFileName;
  36. }
  37. });
  38. }
  39. private string _fileName;
  40. public string FileName {
  41. get {
  42. return _fileName;
  43. }
  44. set {
  45. if (_fileName != value) {
  46. _fileName = value;
  47. OnPropertyChanged(nameof(FileName));
  48. }
  49. }
  50. }
  51. }
  52. }