private PoolViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                           action: message => {
         _dicById.Clear();
         Init();
     }, location: this.GetType());
     VirtualRoot.AddEventPath <ServerContextReInitedEventHandledEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                       action: message => {
         OnPropertyChanged(nameof(AllPools));
     }, location: this.GetType());
     AddEventPath <PoolAddedEvent>("添加矿池后刷新VM内存", LogEnum.DevConsole,
                                   action: (message) => {
         _dicById.Add(message.Source.GetId(), new PoolViewModel(message.Source));
         OnPropertyChanged(nameof(AllPools));
         if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coinVm))
         {
             coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.MainCoinPool));
             coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.DualCoinPool));
             coinVm.OnPropertyChanged(nameof(CoinViewModel.Pools));
             coinVm.OnPropertyChanged(nameof(CoinViewModel.OptionPools));
         }
     }, location: this.GetType());
     AddEventPath <PoolRemovedEvent>("删除矿池后刷新VM内存", LogEnum.DevConsole,
                                     action: (message) => {
         _dicById.Remove(message.Source.GetId());
         OnPropertyChanged(nameof(AllPools));
         if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coinVm))
         {
             coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.MainCoinPool));
             coinVm.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.DualCoinPool));
             coinVm.OnPropertyChanged(nameof(CoinViewModel.Pools));
             coinVm.OnPropertyChanged(nameof(CoinViewModel.OptionPools));
         }
     }, location: this.GetType());
     AddEventPath <PoolUpdatedEvent>("更新矿池后刷新VM内存", LogEnum.DevConsole,
                                     action: (message) => {
         if (_dicById.TryGetValue(message.Source.GetId(), out PoolViewModel vm))
         {
             vm.Update(message.Source);
         }
     }, location: this.GetType());
     Init();
 }
Exemple #2
0
            private FragmentWriterViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                this.Add = new DelegateCommand(() => {
                    new FragmentWriterViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add);
                });
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    OnPropertyChangeds();
                }, location: this.GetType());
                AddEventPath <FragmentWriterAddedEvent>("添加了命令行片段书写器后调整VM内存", LogEnum.DevConsole,
                                                        action: (message) => {
                    if (!_dicById.ContainsKey(message.Target.GetId()))
                    {
                        FragmentWriterViewModel groupVm = new FragmentWriterViewModel(message.Target);
                        _dicById.Add(message.Target.GetId(), groupVm);
                        OnPropertyChangeds();
                    }
                }, location: this.GetType());
                AddEventPath <FragmentWriterUpdatedEvent>("更新了命令行片段书写器后调整VM内存", LogEnum.DevConsole,
                                                          action: (message) => {
                    if (_dicById.ContainsKey(message.Target.GetId()))
                    {
                        FragmentWriterViewModel entity = _dicById[message.Target.GetId()];
                        entity.Update(message.Target);
                    }
                }, location: this.GetType());
                AddEventPath <FragmentWriterRemovedEvent>("删除了命令行片段书写器后调整VM内存", LogEnum.DevConsole,
                                                          action: (message) => {
                    _dicById.Remove(message.Target.GetId());
                    OnPropertyChangeds();
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
            private CoinGroupViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    _listByGroupId.Clear();
                    Init();
                }, location: this.GetType());
                AddEventPath <CoinGroupAddedEvent>("添加了币组后调整VM内存", LogEnum.DevConsole,
                                                   action: (message) => {
                    if (!_dicById.ContainsKey(message.Target.GetId()))
                    {
                        CoinGroupViewModel coinGroupVm = new CoinGroupViewModel(message.Target);
                        _dicById.Add(message.Target.GetId(), coinGroupVm);
                        if (!_listByGroupId.ContainsKey(coinGroupVm.GroupId))
                        {
                            _listByGroupId.Add(coinGroupVm.GroupId, new List <CoinGroupViewModel>());
                        }
                        _listByGroupId[coinGroupVm.GroupId].Add(coinGroupVm);
                        OnGroupPropertyChanged(coinGroupVm.GroupId);
                    }
                }, location: this.GetType());
                AddEventPath <CoinGroupRemovedEvent>("删除了币组后调整VM内存", LogEnum.DevConsole,
                                                     action: (message) => {
                    if (_dicById.ContainsKey(message.Target.GetId()))
                    {
                        var entity = _dicById[message.Target.GetId()];
                        _dicById.Remove(message.Target.GetId());
                        if (_listByGroupId.ContainsKey(entity.GroupId))
                        {
                            _listByGroupId[entity.GroupId].Remove(entity);
                        }
                        OnGroupPropertyChanged(entity.GroupId);
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
 private PoolKernelViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                           action: message => {
         _dicById.Clear();
         Init();
     }, location: this.GetType());
     VirtualRoot.AddEventPath <ServerContextReInitedEventHandledEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                       action: message => {
         OnPropertyChanged(nameof(AllPoolKernels));
     }, location: this.GetType());
     AddEventPath <PoolKernelAddedEvent>("新添了矿池内核后刷新矿池内核VM内存", LogEnum.DevConsole,
                                         action: (message) => {
         if (!_dicById.ContainsKey(message.Source.GetId()))
         {
             if (PoolVms.TryGetPoolVm(message.Source.PoolId, out PoolViewModel poolVm))
             {
                 _dicById.Add(message.Source.GetId(), new PoolKernelViewModel(message.Source));
                 poolVm.OnPropertyChanged(nameof(poolVm.PoolKernels));
             }
         }
     }, location: this.GetType());
     AddEventPath <PoolKernelRemovedEvent>("移除了币种内核后刷新矿池内核VM内存", LogEnum.DevConsole,
                                           action: (message) => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             var vm = _dicById[message.Source.GetId()];
             _dicById.Remove(message.Source.GetId());
             if (PoolVms.TryGetPoolVm(vm.PoolId, out PoolViewModel poolVm))
             {
                 poolVm.OnPropertyChanged(nameof(poolVm.PoolKernels));
             }
         }
     }, location: this.GetType());
     AddEventPath <PoolKernelUpdatedEvent>("更新了矿池内核后刷新VM内存", LogEnum.DevConsole,
                                           action: (message) => {
         if (_dicById.TryGetValue(message.Source.GetId(), out PoolKernelViewModel vm))
         {
             vm.Update(message.Source);
         }
     }, location: this.GetType());
     Init();
 }
 private NTMinerContext()
 {
     CreatedOn       = DateTime.Now;
     LocalMessageSet = new LocalMessageSet();
     if (ClientAppType.IsMinerClient)
     {
         SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
     }
     VirtualRoot.AddEventPath <AppExitEvent>($"程序退出时的{nameof(NTMinerContext)}退出逻辑", LogEnum.None,
                                             message => {
         if (LockedMineContext != null)
         {
             StopMine(StopMineReason.ApplicationExit);
         }
         SystemEvents.SessionSwitch -= SystemEvents_SessionSwitch;
     }, typeof(NTMinerContext));
 }
Exemple #6
0
 private NTMinerRoot()
 {
     CreatedOn = DateTime.Now;
     if (VirtualRoot.IsMinerClient)
     {
         SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
     }
     VirtualRoot.AddEventPath <AppExitEvent>("程序退出时的NTMinerRoot退出逻辑", LogEnum.None,
                                             message => {
         if (LockedMineContext != null)
         {
             StopMine(StopMineReason.ApplicationExit);
         }
         SystemEvents.SessionSwitch -= SystemEvents_SessionSwitch;
         _computer?.Close();
     }, typeof(NTMinerRoot));
 }
 private PackageViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                           action: message => {
         _dicById.Clear();
         Init();
     }, location: this.GetType());
     VirtualRoot.AddEventPath <ServerContextReInitedEventHandledEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                       action: message => {
         OnPropertyChanged(nameof(AllPackages));
     }, location: this.GetType());
     AddEventPath <PackageAddedEvent>("添加了包后调整VM内存", LogEnum.DevConsole,
                                      action: (message) => {
         _dicById.Add(message.Source.GetId(), new PackageViewModel(message.Source));
         OnPropertyChanged(nameof(AllPackages));
         foreach (var item in KernelVms.AllKernels)
         {
             item.OnPropertyChanged(nameof(item.IsPackageValid));
         }
     }, location: this.GetType());
     AddEventPath <PackageRemovedEvent>("删除了包后调整VM内存", LogEnum.DevConsole,
                                        action: message => {
         _dicById.Remove(message.Source.GetId());
         OnPropertyChanged(nameof(AllPackages));
         foreach (var item in KernelVms.AllKernels)
         {
             item.OnPropertyChanged(nameof(item.IsPackageValid));
         }
     }, location: this.GetType());
     AddEventPath <PackageUpdatedEvent>("更新了包后调整VM内存", LogEnum.DevConsole,
                                        action: message => {
         if (_dicById.TryGetValue(message.Source.GetId(), out PackageViewModel vm))
         {
             vm.Update(message.Source);
             foreach (var item in KernelVms.AllKernels)
             {
                 item.OnPropertyChanged(nameof(item.IsPackageValid));
             }
         }
     }, location: this.GetType());
     Init();
 }
            private WalletViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <LocalContextReInitedEvent>("LocalContext刷新后刷新钱包Vm内存", LogEnum.None,
                                                                     action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                AddEventPath <WalletAddedEvent>("添加了钱包后调整VM内存", LogEnum.DevConsole,
                                                action: (message) => {
                    _dicById.Add(message.Target.GetId(), new WalletViewModel(message.Target));
                    OnPropertyChanged(nameof(WalletList));
                    if (AppContext.Instance.CoinVms.TryGetCoinVm(message.Target.CoinId, out CoinViewModel coin))
                    {
                        coin.OnPropertyChanged(nameof(CoinViewModel.Wallets));
                        coin.OnPropertyChanged(nameof(CoinViewModel.WalletItems));
                        coin.CoinKernel?.CoinKernelProfile?.SelectedDualCoin?.OnPropertyChanged(nameof(CoinViewModel.Wallets));
                    }
                }, location: this.GetType());
                AddEventPath <WalletRemovedEvent>("删除了钱包后调整VM内存", LogEnum.DevConsole,
                                                  action: (message) => {
                    _dicById.Remove(message.Target.GetId());
                    OnPropertyChanged(nameof(WalletList));
                    if (AppContext.Instance.CoinVms.TryGetCoinVm(message.Target.CoinId, out CoinViewModel coin))
                    {
                        coin.OnPropertyChanged(nameof(CoinViewModel.Wallets));
                        coin.OnPropertyChanged(nameof(CoinViewModel.WalletItems));
                        coin.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.SelectedWallet));
                        coin.CoinKernel?.CoinKernelProfile?.SelectedDualCoin?.OnPropertyChanged(nameof(CoinViewModel.Wallets));
                    }
                }, location: this.GetType());
                AddEventPath <WalletUpdatedEvent>("更新了钱包后调整VM内存", LogEnum.DevConsole,
                                                  action: (message) => {
                    _dicById[message.Target.GetId()].Update(message.Target);
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Exemple #9
0
 private CoinGroupViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                           action: message => {
         _dicById.Clear();
         _listByGroupId.Clear();
         Init();
     }, location: this.GetType());
     VirtualRoot.AddEventPath <ServerContextReInitedEventHandledEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                       action: message => {
         // 什么也不做,因为该集合没有什么属性
     }, location: this.GetType());
     AddEventPath <CoinGroupAddedEvent>("添加了币组后调整VM内存", LogEnum.DevConsole,
                                        action: (message) => {
         if (!_dicById.ContainsKey(message.Source.GetId()))
         {
             CoinGroupViewModel coinGroupVm = new CoinGroupViewModel(message.Source);
             _dicById.Add(message.Source.GetId(), coinGroupVm);
             if (!_listByGroupId.ContainsKey(coinGroupVm.GroupId))
             {
                 _listByGroupId.Add(coinGroupVm.GroupId, new List <CoinGroupViewModel>());
             }
             _listByGroupId[coinGroupVm.GroupId].Add(coinGroupVm);
             OnGroupPropertyChanged(coinGroupVm.GroupId);
         }
     }, location: this.GetType());
     AddEventPath <CoinGroupRemovedEvent>("删除了币组后调整VM内存", LogEnum.DevConsole,
                                          action: (message) => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             var entity = _dicById[message.Source.GetId()];
             _dicById.Remove(message.Source.GetId());
             if (_listByGroupId.ContainsKey(entity.GroupId))
             {
                 _listByGroupId[entity.GroupId].Remove(entity);
             }
             OnGroupPropertyChanged(entity.GroupId);
         }
     }, location: this.GetType());
     Init();
 }
 private WalletViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     VirtualRoot.AddEventPath <LocalContextReInitedEvent>("LocalContext刷新后刷新钱包Vm内存", LogEnum.None,
                                                          action: message => {
         _dicById.Clear();
         Init();
     }, location: this.GetType());
     AddEventPath <WalletAddedEvent>("添加了钱包后调整VM内存", LogEnum.DevConsole,
                                     action: (message) => {
         _dicById.Add(message.Source.GetId(), new WalletViewModel(message.Source));
         OnPropertyChanged(nameof(WalletList));
         if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coin))
         {
             coin.OnPropertyChanged(nameof(CoinViewModel.Wallets));
             coin.OnPropertyChanged(nameof(CoinViewModel.WalletItems));
             coin.CoinKernel?.CoinKernelProfile?.SelectedDualCoin?.OnPropertyChanged(nameof(CoinViewModel.Wallets));
         }
         VirtualRoot.RaiseEvent(new WalletVmAddedEvent(message));
     }, location: this.GetType());
     AddEventPath <WalletRemovedEvent>("删除了钱包后调整VM内存", LogEnum.DevConsole,
                                       action: (message) => {
         _dicById.Remove(message.Source.GetId());
         OnPropertyChanged(nameof(WalletList));
         if (CoinVms.TryGetCoinVm(message.Source.CoinId, out CoinViewModel coin))
         {
             coin.OnPropertyChanged(nameof(CoinViewModel.Wallets));
             coin.OnPropertyChanged(nameof(CoinViewModel.WalletItems));
             coin.CoinProfile?.OnPropertyChanged(nameof(CoinProfileViewModel.SelectedWallet));
             coin.CoinKernel?.CoinKernelProfile?.SelectedDualCoin?.OnPropertyChanged(nameof(CoinViewModel.Wallets));
         }
         VirtualRoot.RaiseEvent(new WalletVmRemovedEvent(message));
     }, location: this.GetType());
     AddEventPath <WalletUpdatedEvent>("更新了钱包后调整VM内存", LogEnum.DevConsole,
                                       action: (message) => {
         if (_dicById.TryGetValue(message.Source.GetId(), out WalletViewModel vm))
         {
             vm.Update(message.Source);
         }
     }, location: this.GetType());
     Init();
 }
 private PoolProfileViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     AddEventPath <PoolProfilePropertyChangedEvent>("矿池设置变更后刷新VM内存", LogEnum.DevConsole,
                                                    action: message => {
         if (_dicById.TryGetValue(message.PoolId, out PoolProfileViewModel vm))
         {
             vm.OnPropertyChanged(message.PropertyName);
         }
     }, location: this.GetType());
     VirtualRoot.AddEventPath <LocalContextReInitedEvent>("LocalContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                          action: message => {
         _dicById.Clear();
     }, location: this.GetType());
 }
 private KernelOutputViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                           action: message => {
         _dicById.Clear();
         Init();
     }, location: this.GetType());
     VirtualRoot.AddEventPath <ServerContextReInitedEventHandledEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                       action: message => {
         AllPropertyChanged();
     }, location: this.GetType());
     AddEventPath <KernelOutputAddedEvent>("添加了内核输出组后刷新VM内存", LogEnum.DevConsole,
                                           action: message => {
         var vm = new KernelOutputViewModel(message.Source);
         _dicById.Add(message.Source.GetId(), vm);
         OnPropertyChanged(nameof(AllKernelOutputVms));
         OnPropertyChanged(nameof(PleaseSelectVms));
     }, location: this.GetType());
     AddEventPath <KernelOutputUpdatedEvent>("更新了内核输出组后刷新VM内存", LogEnum.DevConsole,
                                             action: message => {
         if (_dicById.TryGetValue(message.Source.GetId(), out KernelOutputViewModel vm))
         {
             if (vm != null)
             {
                 vm.Update(message.Source);
             }
         }
     }, location: this.GetType());
     AddEventPath <KernelOutputRemovedEvent>("移除了内核输出组后刷新VM内存", LogEnum.DevConsole,
                                             action: message => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             _dicById.Remove(message.Source.GetId());
             OnPropertyChanged(nameof(AllKernelOutputVms));
             OnPropertyChanged(nameof(PleaseSelectVms));
         }
     }, location: this.GetType());
     Init();
 }
Exemple #13
0
 private static void Run()
 {
     try {
         HttpServer.Start($"http://localhost:{NTKeyword.NTMinerDaemonPort.ToString()}");
         Windows.ConsoleHandler.Register(Close);
         VirtualRoot.AddEventPath <Per10SecondEvent>("呼吸表示活着", LogEnum.None,
                                                     action: message => {
             NTMinerRegistry.SetDaemonActiveOn(DateTime.Now);
             NoDevFee.NoDevFeeUtil.StartAsync();
         }, typeof(HostRoot));
         _waitHandle.WaitOne();
         Close();
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
     }
     finally {
         Close();
     }
 }
 private FileWriterViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     this.Add = new DelegateCommand(() => {
         new FileWriterViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add);
     });
     VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                           action: message => {
         _dicById.Clear();
         Init();
     }, location: this.GetType());
     VirtualRoot.AddEventPath <ServerContextReInitedEventHandledEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                       action: message => {
         OnPropertyChangeds();
     }, location: this.GetType());
     AddEventPath <FileWriterAddedEvent>("添加了文件书写器后调整VM内存", LogEnum.DevConsole,
                                         action: (message) => {
         if (!_dicById.ContainsKey(message.Source.GetId()))
         {
             FileWriterViewModel groupVm = new FileWriterViewModel(message.Source);
             _dicById.Add(message.Source.GetId(), groupVm);
             OnPropertyChangeds();
         }
     }, location: this.GetType());
     AddEventPath <FileWriterUpdatedEvent>("更新了文件书写器后调整VM内存", LogEnum.DevConsole,
                                           action: (message) => {
         if (_dicById.TryGetValue(message.Source.GetId(), out FileWriterViewModel vm))
         {
             vm.Update(message.Source);
         }
     }, location: this.GetType());
     AddEventPath <FileWriterRemovedEvent>("删除了文件书写器后调整VM内存", LogEnum.DevConsole,
                                           action: (message) => {
         _dicById.Remove(message.Source.GetId());
         OnPropertyChangeds();
     }, location: this.GetType());
     Init();
 }
Exemple #15
0
 protected override void OnOpen()
 {
     base.OnOpen();
     if (_isFirst)
     {
         lock (_locker) {
             if (_isFirst)
             {
                 VirtualRoot.AddEventPath <Per10SecondEvent>("测试,周期getSpeed", LogEnum.None, action: message => {
                     foreach (var sessionId in _holdSessionIds)
                     {
                         base.Sessions.SendToAsync(new WsMessage().SetType(WsMessageType.GetSpeed).ToJson(), sessionId, completed: null);
                     }
                 }, location: this.GetType());
                 _isFirst = false;
             }
         }
     }
     Write.DevWarn("Sessions Count: " + base.Sessions.Count);
     _holdSessionIds.Add(base.ID);
 }
Exemple #16
0
        public static void Start(string baseAddress)
        {
            if (s_httpServer != null)
            {
                return;
            }
            var config = new HttpSelfHostConfiguration(baseAddress);

            config.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
            config.Routes.MapHttpRoute("API Default", "api/{controller}/{action}");
            s_httpServer = new HttpSelfHostServer(config);
            s_httpServer.OpenAsync().Wait();
            VirtualRoot.AddEventPath <AppExitEvent>("退出HttpServer", LogEnum.None, action: message => {
                var tmp = s_httpServer;
                if (tmp != null)
                {
                    s_httpServer = null;
                    tmp.Dispose();
                }
            }, typeof(HttpServer));
        }
Exemple #17
0
            private static void KernelProcessDaemon(IMineContext mineContext, Action clear)
            {
                if (clear != null)
                {
                    mineContext.Data["_clear"] = clear;
                }
                string processName = mineContext.Kernel.GetProcessName();

                mineContext.Data["_kernelProcessDaemon"] = VirtualRoot.AddEventPath <Per1MinuteEvent>("周期性检查挖矿内核是否消失,如果消失尝试重启", LogEnum.DevConsole,
                                                                                                      action: message => {
                    if (mineContext == Instance.LockedMineContext)
                    {
                        if (!string.IsNullOrEmpty(processName))
                        {
                            Process[] processes = Process.GetProcessesByName(processName);
                            if (processes.Length == 0)
                            {
                                mineContext.AutoRestartKernelCount += 1;
                                VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), processName + $"挖矿内核进程消失", toConsole: true);
                                if (Instance.MinerProfile.IsAutoRestartKernel && mineContext.AutoRestartKernelCount <= Instance.MinerProfile.AutoRestartKernelTimes)
                                {
                                    VirtualRoot.ThisLocalInfo(nameof(NTMinerRoot), $"尝试第{mineContext.AutoRestartKernelCount.ToString()}次重启,共{Instance.MinerProfile.AutoRestartKernelTimes.ToString()}次", toConsole: true);
                                    Instance.RestartMine();
                                    Instance.LockedMineContext.AutoRestartKernelCount = mineContext.AutoRestartKernelCount;
                                }
                                else
                                {
                                    Instance.StopMineAsync(StopMineReason.KernelProcessLost);
                                }
                                ReleaseKernelProcessDaemon(mineContext);
                            }
                        }
                    }
                    else
                    {
                        ReleaseKernelProcessDaemon(mineContext);
                    }
                }, location: typeof(MinerProcess));
            }
Exemple #18
0
            private CoinProfileViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                AddEventPath <CoinKernelProfilePropertyChangedEvent>("币种内核设置变更后刷新VM内存", LogEnum.DevConsole,
                                                                     action: message => {
                    if (_coinKernelProfileDicById.ContainsKey(message.CoinKernelId))
                    {
                        _coinKernelProfileDicById[message.CoinKernelId].OnPropertyChanged(message.PropertyName);
                    }
                }, location: this.GetType());
                AddEventPath <CoinProfilePropertyChangedEvent>("币种设置变更后刷新VM内存", LogEnum.DevConsole,
                                                               action: message => {
                    if (_coinProfileDicById.ContainsKey(message.CoinId))
                    {
                        _coinProfileDicById[message.CoinId].OnPropertyChanged(message.PropertyName);
                    }
                }, location: this.GetType());
                VirtualRoot.AddEventPath <LocalContextReInitedEvent>("LocalContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                     action: message => {
                    _coinKernelProfileDicById.Clear();
                    _coinProfileDicById.Clear();
                }, location: this.GetType());
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Exemple #19
0
            private PoolProfileViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                AddEventPath <PoolProfilePropertyChangedEvent>("矿池设置变更后刷新VM内存", LogEnum.DevConsole,
                                                               action: message => {
                    if (_dicById.TryGetValue(message.PoolId, out PoolProfileViewModel vm))
                    {
                        vm.OnPropertyChanged(message.PropertyName);
                    }
                }, location: this.GetType());
                VirtualRoot.AddEventPath <LocalContextReInitedEvent>("LocalContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                     action: message => {
                    _dicById.Clear();
                }, location: this.GetType());
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
        private void Link()
        {
            VirtualRoot.AddCmdPath <RegCmdHereCommand>(action: message => {
                try {
                    Windows.Cmd.RegCmdHere();
                    VirtualRoot.ThisLocalInfo(nameof(NTMinerContext), "添加windows右键命令行成功");
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                    VirtualRoot.ThisLocalError(nameof(NTMinerContext), "添加windows右键命令行失败", OutEnum.Warn);
                }
            }, location: this.GetType());
            VirtualRoot.AddCmdPath <UnRegCmdHereCommand>(action: message => {
                try {
                    Windows.Cmd.UnRegCmdHere();
                    VirtualRoot.ThisLocalInfo(nameof(NTMinerContext), "移除windows右键命令行成功");
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                    VirtualRoot.ThisLocalError(nameof(NTMinerContext), "移除windows右键命令行失败", OutEnum.Warn);
                }
            }, location: this.GetType());
            VirtualRoot.AddEventPath <Per1MinuteEvent>("每1分钟阻止系统休眠", LogEnum.None,
                                                       action: message => {
                Power.PreventSleep();
            }, location: this.GetType());
            #region 挖矿开始时将无份额内核重启份额计数置0
            int      shareCount   = 0;
            DateTime shareOn      = DateTime.Now;
            DateTime hightSpeedOn = DateTime.Now;
            VirtualRoot.AddEventPath <MineStartedEvent>("挖矿开始后将无份额内核重启份额计数置0", LogEnum.DevConsole,
                                                        action: message => {
                // 将无份额内核重启份额计数置0
                shareCount   = 0;
                hightSpeedOn = DateTime.Now;
                if (!message.MineContext.IsRestart)
                {
                    // 当不是内核重启时更新shareOn,如果是内核重启不用更新shareOn从而给不干扰无内核矿机重启的逻辑
                    shareOn = DateTime.Now;
                }
            }, location: this.GetType());
            #endregion
            #region 每20秒钟检查是否需要重启
            VirtualRoot.AddEventPath <Per20SecondEvent>("每20秒钟检查是否需要重启", LogEnum.None,
                                                        action: message => {
                #region 低算力重启电脑
                if (IsMining && LockedMineContext.ProcessCreatedOn != DateTime.MinValue)
                {
                    var coinProfile = MinerProfile.GetCoinProfile(MinerProfile.CoinId);
                    if (coinProfile.IsLowSpeedRestartComputer && coinProfile.LowSpeed != 0 && coinProfile.LowSpeedRestartComputerMinutes > 0)
                    {
                        IGpuSpeed totalSpeed = GpusSpeed.CurrentSpeed(GpuAllId);
                        if (totalSpeed.MainCoinSpeed.SpeedOn.AddMinutes(coinProfile.LowSpeedRestartComputerMinutes) >= message.BornOn)
                        {
                            if (totalSpeed.MainCoinSpeed.Value.ToNearSpeed(coinProfile.LowSpeed) >= coinProfile.LowSpeed)
                            {
                                hightSpeedOn = message.BornOn;
                            }
                        }
                        if (hightSpeedOn.AddMinutes(coinProfile.LowSpeedRestartComputerMinutes) < message.BornOn)
                        {
                            string coinCode = string.Empty;
                            if (ServerContext.CoinSet.TryGetCoin(MinerProfile.CoinId, out ICoin coin))
                            {
                                coinCode = coin.Code;
                            }
                            VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"{coinCode}总算力持续{coinProfile.LowSpeedRestartComputerMinutes}分钟低于{coinProfile.LowSpeed}重启电脑", toConsole: true);
                            VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10));
                            if (!MinerProfile.IsAutoBoot || !NTMinerRegistry.GetIsAutoStart())
                            {
                                VirtualRoot.Execute(new SetAutoStartCommand(true, true));
                            }
                            return;
                        }
                    }
                    else
                    {
                        hightSpeedOn = message.BornOn;
                    }
                }
                #endregion

                #region 周期重启电脑
                try {
                    if (MinerProfile.IsPeriodicRestartComputer)
                    {
                        if ((DateTime.Now - this.CreatedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartComputerHours + MinerProfile.PeriodicRestartComputerMinutes)
                        {
                            string content = $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartComputerMinutes.ToString()}分钟重启电脑";
                            VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), content, toConsole: true);
                            VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10));
                            if (!MinerProfile.IsAutoBoot || !NTMinerRegistry.GetIsAutoStart())
                            {
                                VirtualRoot.Execute(new SetAutoStartCommand(true, true));
                            }
                            return;    // 退出
                        }
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
                #endregion

                #region 周期重启内核
                try {
                    if (IsMining && MinerProfile.IsPeriodicRestartKernel && LockedMineContext.MineStartedOn != DateTime.MinValue)
                    {
                        if ((DateTime.Now - LockedMineContext.MineStartedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartKernelHours + MinerProfile.PeriodicRestartKernelMinutes)
                        {
                            VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartKernelMinutes.ToString()}分钟重启内核", toConsole: true);
                            RestartMine();
                            return;    // 退出
                        }
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
                #endregion

                #region 无份额重启内核
                try {
                    if (IsMining && this.LockedMineContext.MainCoin != null)
                    {
                        int totalShare       = 0;
                        bool restartComputer = MinerProfile.NoShareRestartComputerMinutes > 0 && MinerProfile.IsNoShareRestartComputer && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartComputerMinutes;
                        bool restartKernel   = MinerProfile.NoShareRestartKernelMinutes > 0 && MinerProfile.IsNoShareRestartKernel && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes;
                        if (restartComputer || restartKernel)
                        {
                            ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.LockedMineContext.MainCoin.GetId());
                            totalShare = mainCoinShare.TotalShareCount;
                            if ((this.LockedMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null)
                            {
                                ICoinShare dualCoinShare = this.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId());
                                totalShare += dualCoinShare.TotalShareCount;
                            }
                            // 如果份额没有增加
                            if (shareCount == totalShare)
                            {
                                bool isMineStartedARestartComputerMinutes = (DateTime.Now - this.LockedMineContext.MineStartedOn).TotalMinutes > MinerProfile.NoShareRestartComputerMinutes;
                                if (restartComputer && isMineStartedARestartComputerMinutes)
                                {
                                    if (!MinerProfile.IsAutoBoot || !NTMinerRegistry.GetIsAutoStart())
                                    {
                                        VirtualRoot.Execute(new SetAutoStartCommand(true, true));
                                    }
                                    string content = $"{MinerProfile.NoShareRestartComputerMinutes.ToString()}分钟无份额重启电脑";
                                    VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), content, toConsole: true);
                                    VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10));
                                    return;    // 退出
                                }
                                bool isMineStartedARestartKernelMinutes = (DateTime.Now - this.LockedMineContext.MineStartedOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes;
                                if (restartKernel && isMineStartedARestartKernelMinutes)
                                {
                                    VirtualRoot.ThisLocalWarn(nameof(NTMinerContext), $"{MinerProfile.NoShareRestartKernelMinutes.ToString()}分钟无份额重启内核", toConsole: true);
                                    RestartMine();
                                    return;    // 退出
                                }
                            }
                            if (totalShare > shareCount)
                            {
                                shareCount = totalShare;
                                shareOn    = DateTime.Now;
                            }
                        }
Exemple #21
0
            private CoinKernelViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    OnPropertyChanged(nameof(AllCoinKernels));
                }, location: this.GetType());
                AddEventPath <CoinKernelAddedEvent>("添加了币种内核后刷新VM内存", LogEnum.DevConsole,
                                                    action: (message) => {
                    var coinKernelVm = new CoinKernelViewModel(message.Target);
                    _dicById.Add(message.Target.GetId(), coinKernelVm);
                    OnPropertyChanged(nameof(AllCoinKernels));
                    if (AppContext.Instance.CoinVms.TryGetCoinVm(message.Target.CoinId, out CoinViewModel coinVm))
                    {
                        coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernel));
                        coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernels));
                        coinVm.OnPropertyChanged(nameof(CoinViewModel.IsSupported));
                    }
                    var kernelVm = coinKernelVm.Kernel;
                    if (kernelVm != null)
                    {
                        kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels));
                        kernelVm.OnPropertyChanged(nameof(kernelVm.CoinVms));
                        kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoinVms));
                        kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoins));
                    }
                }, location: this.GetType());
                AddEventPath <CoinKernelUpdatedEvent>("更新了币种内核后刷新VM内存", LogEnum.DevConsole,
                                                      action: (message) => {
                    CoinKernelViewModel entity = _dicById[message.Target.GetId()];
                    var supportedGpu           = entity.SupportedGpu;
                    Guid dualCoinGroupId       = entity.DualCoinGroupId;
                    entity.Update(message.Target);
                    if (supportedGpu != entity.SupportedGpu)
                    {
                        var coinKernels = AllCoinKernels.Where(a => a.KernelId == entity.Id);
                        foreach (var coinKernel in coinKernels)
                        {
                            if (AppContext.Instance.CoinVms.TryGetCoinVm(coinKernel.CoinId, out CoinViewModel coinVm))
                            {
                                coinVm.OnPropertyChanged(nameof(coinVm.IsSupported));
                                coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels));
                            }
                        }
                        var kernelVm = entity.Kernel;
                        kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels));
                    }
                }, location: this.GetType());
                AddEventPath <CoinKernelRemovedEvent>("移除了币种内核后刷新VM内存", LogEnum.DevConsole,
                                                      action: (message) => {
                    if (_dicById.TryGetValue(message.Target.GetId(), out CoinKernelViewModel coinKernelVm))
                    {
                        _dicById.Remove(message.Target.GetId());
                        OnPropertyChanged(nameof(AllCoinKernels));
                        if (AppContext.Instance.CoinVms.TryGetCoinVm(message.Target.CoinId, out CoinViewModel coinVm))
                        {
                            coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernel));
                            coinVm.OnPropertyChanged(nameof(CoinViewModel.CoinKernels));
                            coinVm.OnPropertyChanged(nameof(CoinViewModel.IsSupported));
                        }
                        var kernelVm = coinKernelVm.Kernel;
                        kernelVm.OnPropertyChanged(nameof(kernelVm.CoinKernels));
                        kernelVm.OnPropertyChanged(nameof(kernelVm.CoinVms));
                        kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoinVms));
                        kernelVm.OnPropertyChanged(nameof(kernelVm.SupportedCoins));
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Exemple #22
0
        private void BuildPaths()
        {
            VirtualRoot.AddCmdPath <MinerClientActionCommand>(action: message => {
                #region
                try {
                    switch (message.ActionType)
                    {
                    case MinerClientActionType.SwitchRadeonGpuOn:
                        VirtualRoot.Execute(new SwitchRadeonGpuCommand(on: true));
                        break;

                    case MinerClientActionType.SwitchRadeonGpuOff:
                        VirtualRoot.Execute(new SwitchRadeonGpuCommand(on: false));
                        break;

                    case MinerClientActionType.BlockWAU:
                        VirtualRoot.Execute(new BlockWAUCommand());
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
                #endregion
            }, location: this.GetType());
            #region 处理显示主界面命令
            VirtualRoot.AddCmdPath <ShowMainWindowCommand>(action: message => {
                UIThread.Execute(() => {
                    _appViewFactory.ShowMainWindow(message.IsToggle, out Window _);
                    // 使状态栏显示显示最新状态
                    if (NTMinerContext.Instance.IsMining)
                    {
                        var mainCoin = NTMinerContext.Instance.LockedMineContext.MainCoin;
                        if (mainCoin == null)
                        {
                            return;
                        }
                        var coinShare = NTMinerContext.Instance.CoinShareSet.GetOrCreate(mainCoin.GetId());
                        VirtualRoot.RaiseEvent(new ShareChangedEvent(PathId.Empty, coinShare));
                        if ((NTMinerContext.Instance.LockedMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null)
                        {
                            coinShare = NTMinerContext.Instance.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId());
                            VirtualRoot.RaiseEvent(new ShareChangedEvent(PathId.Empty, coinShare));
                        }
                        AppRoot.GpuSpeedVms.Refresh();
                    }
                });
            }, location: this.GetType());
            #endregion
            #region 周期确保守护进程在运行
            VirtualRoot.AddEventPath <Per1MinuteEvent>("周期确保守护进程在运行", LogEnum.DevConsole,
                                                       action: message => {
                Daemon.DaemonUtil.RunNTMinerDaemon();
                NoDevFee.NoDevFeeUtil.RunNTMinerNoDevFee();
            }, location: this.GetType());
            #endregion
            #region 开始和停止挖矿后
            VirtualRoot.AddEventPath <StartingMineEvent>("开始挖矿时更新挖矿按钮状态", LogEnum.DevConsole,
                                                         action: message => {
                AppRoot.MinerProfileVm.IsMining = true;
                // 因为无界面模式不一定会构建挖矿状态按钮,所以放在这里而不放在挖矿按钮的VM中
                StartStopMineButtonViewModel.Instance.BtnStopText = "正在挖矿";
            }, location: this.GetType());
            VirtualRoot.AddEventPath <MineStartedEvent>("启动1080ti小药丸、启动DevConsole? 更新挖矿按钮状态", LogEnum.DevConsole,
                                                        action: message => {
                // 启动DevConsole
                if (NTMinerContext.IsUseDevConsole)
                {
                    var mineContext     = message.MineContext;
                    string poolIp       = mineContext.MainCoinPool.GetIp();
                    string consoleTitle = mineContext.MainCoinPool.Server;
                    Daemon.DaemonUtil.RunDevConsoleAsync(poolIp, consoleTitle);
                }
                OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Start();
            }, location: this.GetType());
            VirtualRoot.AddEventPath <MineStopedEvent>("停止挖矿后停止1080ti小药丸 挖矿停止后更新界面挖矿状态", LogEnum.DevConsole,
                                                       action: message => {
                AppRoot.MinerProfileVm.IsMining = false;
                // 因为无界面模式不一定会构建挖矿状态按钮,所以放在这里而不放在挖矿按钮的VM中
                StartStopMineButtonViewModel.Instance.BtnStopText = "尚未开始";
                OhGodAnETHlargementPill.OhGodAnETHlargementPillUtil.Stop();
            }, location: this.GetType());
            #endregion
            #region 处理禁用win10系统更新
            VirtualRoot.AddCmdPath <BlockWAUCommand>(action: message => {
                NTMiner.Windows.WindowsUtil.BlockWAU().ContinueWith(t => {
                    if (t.Exception == null)
                    {
                        VirtualRoot.ThisLocalInfo(nameof(App), "禁用windows系统更新成功", OutEnum.Success);
                    }
                    else
                    {
                        VirtualRoot.ThisLocalError(nameof(App), "禁用windows系统更新失败", OutEnum.Error);
                    }
                });
            }, location: this.GetType());
            #endregion
            #region 优化windows
            VirtualRoot.AddCmdPath <Win10OptimizeCommand>(action: message => {
                NTMiner.Windows.WindowsUtil.Win10Optimize(e => {
                    if (e == null)
                    {
                        VirtualRoot.ThisLocalInfo(nameof(App), "优化Windows成功", OutEnum.Success);
                    }
                    else
                    {
                        VirtualRoot.ThisLocalError(nameof(App), "优化Windows失败", OutEnum.Error);
                    }
                });
            }, location: this.GetType());
            #endregion
            #region 处理开启A卡计算模式
            VirtualRoot.AddCmdPath <SwitchRadeonGpuCommand>(action: message => {
                if (NTMinerContext.Instance.GpuSet.GpuType == GpuType.AMD)
                {
                    AppRoot.SwitchRadeonGpu(message.On);
                }
            }, location: this.GetType());
            #endregion
            #region 处理A卡驱动签名
            VirtualRoot.AddCmdPath <AtikmdagPatcherCommand>(action: message => {
                if (NTMinerContext.Instance.GpuSet.GpuType == GpuType.AMD)
                {
                    AppRoot.OpenAtikmdagPatcher();
                }
            }, location: this.GetType());
            #endregion
            #region 启用或禁用windows远程桌面
            VirtualRoot.AddCmdPath <EnableRemoteDesktopCommand>(action: message => {
                if (NTMinerRegistry.GetIsRdpEnabled())
                {
                    return;
                }
                string msg = "确定启用Windows远程桌面吗?";
                DialogWindow.ShowSoftDialog(new DialogWindowViewModel(
                                                message: msg,
                                                title: "确认",
                                                onYes: () => {
                    NTMinerRegistry.SetIsRdpEnabled(true);
                    Firewall.AddRdpRule();
                }));
            }, location: this.GetType());
            #endregion
            #region 启用或禁用windows开机自动登录
            VirtualRoot.AddCmdPath <EnableOrDisableWindowsAutoLoginCommand>(action: message => {
                if (NTMiner.Windows.OS.Instance.IsAutoAdminLogon)
                {
                    return;
                }
                if (NTMiner.Windows.OS.Instance.IsGEWindows2004)
                {
                    WindowsAutoLogon.ShowWindow();
                }
                else
                {
                    VirtualRoot.Execute(new UnTopmostCommand());
                    NTMiner.Windows.Cmd.RunClose("control", "userpasswords2");
                }
            }, location: this.GetType());
            #endregion
        }
Exemple #23
0
            private CoinViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    AllPropertyChanged();
                }, location: this.GetType());
                AddEventPath <CoinAddedEvent>("添加了币种后刷新VM内存", LogEnum.DevConsole,
                                              action: (message) => {
                    _dicById.Add(message.Target.GetId(), new CoinViewModel(message.Target));
                    AppContext.Instance.MinerProfileVm.OnPropertyChanged(nameof(NTMiner.AppContext.Instance.MinerProfileVm.CoinVm));
                    AllPropertyChanged();
                }, location: this.GetType());
                AddEventPath <CoinRemovedEvent>("移除了币种后刷新VM内存", LogEnum.DevConsole,
                                                action: message => {
                    _dicById.Remove(message.Target.GetId());
                    AppContext.Instance.MinerProfileVm.OnPropertyChanged(nameof(NTMiner.AppContext.Instance.MinerProfileVm.CoinVm));
                    AllPropertyChanged();
                }, location: this.GetType());
                AddEventPath <CoinUpdatedEvent>("更新了币种后刷新VM内存", LogEnum.DevConsole,
                                                action: message => {
                    CoinViewModel coinVm = _dicById[message.Target.GetId()];
                    bool justAsDualCoin  = coinVm.JustAsDualCoin;
                    coinVm.Update(message.Target);
                    coinVm.TestWalletVm.Address = message.Target.TestWallet;
                    coinVm.OnPropertyChanged(nameof(coinVm.Wallets));
                    coinVm.OnPropertyChanged(nameof(coinVm.WalletItems));
                    if (AppContext.Instance.MinerProfileVm.CoinId == message.Target.GetId())
                    {
                        AppContext.Instance.MinerProfileVm.OnPropertyChanged(nameof(NTMiner.AppContext.Instance.MinerProfileVm.CoinVm));
                    }
                    CoinKernelViewModel coinKernelVm = AppContext.Instance.MinerProfileVm.CoinVm.CoinKernel;
                    if (coinKernelVm != null &&
                        coinKernelVm.CoinKernelProfile.SelectedDualCoin != null &&
                        coinKernelVm.CoinKernelProfile.SelectedDualCoin.GetId() == message.Target.GetId())
                    {
                        coinKernelVm.CoinKernelProfile.OnPropertyChanged(nameof(coinKernelVm.CoinKernelProfile.SelectedDualCoin));
                    }
                    if (justAsDualCoin != coinVm.JustAsDualCoin)
                    {
                        OnPropertyChanged(nameof(MainCoins));
                    }
                }, location: this.GetType());
                AddEventPath <CoinIconDownloadedEvent>("下载了币种图标后", LogEnum.DevConsole,
                                                       action: message => {
                    try {
                        if (string.IsNullOrEmpty(message.Target.Icon))
                        {
                            return;
                        }
                        string iconFileFullName = SpecialPath.GetIconFileFullName(message.Target);
                        if (string.IsNullOrEmpty(iconFileFullName) || !File.Exists(iconFileFullName))
                        {
                            return;
                        }
                        if (_dicById.TryGetValue(message.Target.GetId(), out CoinViewModel coinVm))
                        {
                            try {
                                coinVm.IconImageSource = new Uri(iconFileFullName, UriKind.Absolute).ToString();
                            }
                            catch (Exception e) {
                                File.Delete(iconFileFullName);
                                Logger.ErrorDebugLine(e);
                            }
                        }
                    }
                    catch (Exception e) {
                        Logger.ErrorDebugLine(e);
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Exemple #24
0
 public void Init(Action callback)
 {
     Task.Factory.StartNew(() => {
         bool isWork = Environment.GetCommandLineArgs().Contains("--work", StringComparer.OrdinalIgnoreCase);
         if (isWork)   // 是作业
         {
             DoInit(isWork, callback);
             if (VirtualRoot.IsMinerClient)
             {
                 NTMinerRegistry.SetIsLastIsWork(true);
             }
         }
         else   // 不是作业
         {
             if (VirtualRoot.IsMinerClient)
             {
                 NTMinerRegistry.SetIsLastIsWork(false);
             }
             // 如果是Debug模式且不是群控客户端则使用本地数据库初始化
             bool useLocalDb = DevMode.IsDevMode && !VirtualRoot.IsMinerStudio;
             if (useLocalDb)
             {
                 DoInit(isWork: false, callback: callback);
             }
             else
             {
                 Logger.InfoDebugLine(nameof(GetAliyunServerJson));
                 GetAliyunServerJson((data) => {
                     // 如果server.json未下载成功则不覆写本地server.json
                     if (data != null && data.Length != 0)
                     {
                         Logger.InfoDebugLine($"{nameof(GetAliyunServerJson)}成功");
                         var serverJson = Encoding.UTF8.GetString(data);
                         if (!string.IsNullOrEmpty(serverJson))
                         {
                             SpecialPath.WriteServerJsonFile(serverJson);
                         }
                         RpcRoot.OfficialServer.GetJsonFileVersionAsync(EntryAssemblyInfo.ServerJsonFileName, serverState => {
                             SetServerJsonVersion(serverState.JsonFileVersion);
                             AppVersionChangedEvent.PublishIfNewVersion(serverState.MinerClientVersion);
                             if (Math.Abs((long)Timestamp.GetTimestamp() - (long)serverState.Time) >= Timestamp.DesyncSeconds)
                             {
                                 Write.UserWarn($"本机和服务器时间不同步,请调整,本地:{DateTime.Now.ToString()},服务器:{Timestamp.FromTimestamp(serverState.Time).ToString()}。此问题不影响挖矿。");
                             }
                         });
                     }
                     else
                     {
                         if (!File.Exists(SpecialPath.ServerJsonFileFullName))
                         {
                             VirtualRoot.ThisLocalError(nameof(NTMinerRoot), "配置文件下载失败,这是第一次运行开源矿工,配置文件至少需要成功下载一次,请检查网络是否可用", OutEnum.Warn);
                         }
                         else
                         {
                             VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), "配置文件下载失败,使用最近一次成功下载的配置文件", OutEnum.Warn);
                         }
                     }
                     DoInit(isWork, callback);
                 });
                 #region 发生了用户活动时检查serverJson是否有新版本
                 VirtualRoot.AddEventPath <UserActionEvent>("发生了用户活动时检查serverJson是否有新版本", LogEnum.DevConsole,
                                                            action: message => {
                     RefreshServerJsonFile();
                 }, location: this.GetType());
                 #endregion
             }
         }
         VirtualRoot.ThisLocalInfo(nameof(NTMinerRoot), $"启动{VirtualRoot.AppName}");
     });
 }
            private SysDicItemViewModels()
            {
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    OnPropertyChangeds();
                }, location: this.GetType());
                AddEventPath <SysDicItemAddedEvent>("添加了系统字典项后调整VM内存", LogEnum.DevConsole,
                                                    action: (message) => {
                    if (!_dicById.ContainsKey(message.Target.GetId()))
                    {
                        _dicById.Add(message.Target.GetId(), new SysDicItemViewModel(message.Target));
                        OnPropertyChangeds();
                        if (AppContext.Instance.SysDicVms.TryGetSysDicVm(message.Target.DicId, out SysDicViewModel sysDicVm))
                        {
                            sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItems));
                            sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItemsSelect));
                        }
                    }
                }, location: this.GetType());
                AddEventPath <SysDicItemUpdatedEvent>("更新了系统字典项后调整VM内存", LogEnum.DevConsole,
                                                      action: (message) => {
                    if (_dicById.ContainsKey(message.Target.GetId()))
                    {
                        SysDicItemViewModel entity = _dicById[message.Target.GetId()];
                        int sortNumber             = entity.SortNumber;
                        entity.Update(message.Target);
                        if (sortNumber != entity.SortNumber)
                        {
                            if (AppContext.Instance.SysDicVms.TryGetSysDicVm(entity.DicId, out SysDicViewModel sysDicVm))
                            {
                                sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItems));
                                sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItemsSelect));
                            }
                        }
                    }
                }, location: this.GetType());
                AddEventPath <SysDicItemRemovedEvent>("删除了系统字典项后调整VM内存", LogEnum.DevConsole,
                                                      action: (message) => {
                    _dicById.Remove(message.Target.GetId());
                    OnPropertyChangeds();
                    if (AppContext.Instance.SysDicVms.TryGetSysDicVm(message.Target.DicId, out SysDicViewModel sysDicVm))
                    {
                        sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItems));
                        sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItemsSelect));
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Exemple #26
0
 private GpuProfileViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     VirtualRoot.AddEventPath <GpuProfileSetRefreshedEvent>("Gpu超频集合刷新后刷新附着在当前币种上的超频数据", LogEnum.DevConsole,
                                                            action: message => {
         lock (_locker) {
             _listByCoinId.Clear();
             _gpuAllVmDicByCoinId.Clear();
         }
         var coinVm = MinerProfileVm.CoinVm;
         if (coinVm != null)
         {
             coinVm.OnOverClockPropertiesChanges();
             VirtualRoot.Execute(new CoinOverClockCommand(coinVm.Id));
         }
     }, location: this.GetType());
     AddEventPath <GpuProfileAddedOrUpdatedEvent>("添加或更新了Gpu超频数据后刷新VM内存", LogEnum.DevConsole,
                                                  action: message => {
         lock (_locker) {
             if (_listByCoinId.TryGetValue(message.Source.CoinId, out List <GpuProfileViewModel> list))
             {
                 var vm = list.FirstOrDefault(a => a.Index == message.Source.Index);
                 if (vm != null)
                 {
                     vm.Update(message.Source);
                 }
                 else
                 {
                     if (GpuVms.TryGetGpuVm(message.Source.Index, out GpuViewModel gpuVm))
                     {
                         var item = new GpuProfileViewModel(message.Source, gpuVm);
                         list.Add(item);
                         list.Sort(new CompareByGpuIndex());
                         if (item.Index == NTMinerContext.GpuAllId)
                         {
                             _gpuAllVmDicByCoinId.Add(message.Source.CoinId, item);
                         }
                     }
                 }
             }
             else
             {
                 list = new List <GpuProfileViewModel>();
                 if (GpuVms.TryGetGpuVm(message.Source.Index, out GpuViewModel gpuVm))
                 {
                     var item = new GpuProfileViewModel(message.Source, gpuVm);
                     list.Add(item);
                     list.Sort(new CompareByGpuIndex());
                     if (item.Index == NTMinerContext.GpuAllId)
                     {
                         _gpuAllVmDicByCoinId.Add(message.Source.CoinId, item);
                     }
                 }
                 _listByCoinId.Add(message.Source.CoinId, list);
             }
         }
     }, location: this.GetType());
 }
Exemple #27
0
        private void Link()
        {
            VirtualRoot.AddCmdPath <RegCmdHereCommand>(action: message => {
                try {
                    Windows.Cmd.RegCmdHere();
                    VirtualRoot.ThisLocalInfo(nameof(NTMinerRoot), "添加windows右键命令行成功");
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                    VirtualRoot.ThisLocalError(nameof(NTMinerRoot), "添加windows右键命令行失败", OutEnum.Warn);
                }
            }, location: this.GetType());
            VirtualRoot.AddCmdPath <UnRegCmdHereCommand>(action: message => {
                try {
                    Windows.Cmd.UnRegCmdHere();
                    VirtualRoot.ThisLocalInfo(nameof(NTMinerRoot), "移除windows右键命令行成功");
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                    VirtualRoot.ThisLocalError(nameof(NTMinerRoot), "移除windows右键命令行失败", OutEnum.Warn);
                }
            }, location: this.GetType());
            VirtualRoot.AddEventPath <Per1MinuteEvent>("每1分钟阻止系统休眠", LogEnum.None,
                                                       action: message => {
                Windows.Power.PreventSleep();
            }, location: this.GetType());
            #region 挖矿开始时将无份额内核重启份额计数置0
            int      shareCount = 0;
            DateTime shareOn    = DateTime.Now;
            VirtualRoot.AddEventPath <MineStartedEvent>("挖矿开始后将无份额内核重启份额计数置0", LogEnum.DevConsole,
                                                        action: message => {
                // 将无份额内核重启份额计数置0
                shareCount = 0;
                if (!message.MineContext.IsRestart)
                {
                    // 当不是内核重启时更新shareOn,如果是内核重启不用更新shareOn从而给不干扰无内核矿机重启的逻辑
                    shareOn = DateTime.Now;
                }
            }, location: this.GetType());
            #endregion
            #region 每20秒钟检查是否需要重启
            VirtualRoot.AddEventPath <Per20SecondEvent>("每20秒钟检查是否需要重启", LogEnum.None,
                                                        action: message => {
                #region 重启电脑
                try {
                    if (MinerProfile.IsPeriodicRestartComputer)
                    {
                        if ((DateTime.Now - this.CreatedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartComputerHours + MinerProfile.PeriodicRestartComputerMinutes)
                        {
                            string content = $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartComputerMinutes.ToString()}分钟重启电脑";
                            VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), content, toConsole: true);
                            VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10));
                            return;    // 退出
                        }
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
                #endregion

                #region 周期重启内核
                try {
                    if (IsMining && MinerProfile.IsPeriodicRestartKernel && LockedMineContext.MineStartedOn != DateTime.MinValue)
                    {
                        if ((DateTime.Now - LockedMineContext.MineStartedOn).TotalMinutes > 60 * MinerProfile.PeriodicRestartKernelHours + MinerProfile.PeriodicRestartKernelMinutes)
                        {
                            VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), $"每运行{MinerProfile.PeriodicRestartKernelHours.ToString()}小时{MinerProfile.PeriodicRestartKernelMinutes.ToString()}分钟重启内核", toConsole: true);
                            RestartMine();
                            return;    // 退出
                        }
                    }
                }
                catch (Exception e) {
                    Logger.ErrorDebugLine(e);
                }
                #endregion

                #region 无份额重启内核
                try {
                    if (IsMining && this.LockedMineContext.MainCoin != null)
                    {
                        int totalShare       = 0;
                        bool restartComputer = MinerProfile.IsNoShareRestartComputer && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartComputerMinutes;
                        bool restartKernel   = MinerProfile.IsNoShareRestartKernel && (DateTime.Now - shareOn).TotalMinutes > MinerProfile.NoShareRestartKernelMinutes;
                        if (restartComputer || restartKernel)
                        {
                            ICoinShare mainCoinShare = this.CoinShareSet.GetOrCreate(this.LockedMineContext.MainCoin.GetId());
                            totalShare = mainCoinShare.TotalShareCount;
                            if ((this.LockedMineContext is IDualMineContext dualMineContext) && dualMineContext.DualCoin != null)
                            {
                                ICoinShare dualCoinShare = this.CoinShareSet.GetOrCreate(dualMineContext.DualCoin.GetId());
                                totalShare += dualCoinShare.TotalShareCount;
                            }
                            // 如果份额没有增加
                            if (shareCount == totalShare)
                            {
                                if (restartComputer)
                                {
                                    if (!MinerProfile.IsAutoBoot || !MinerProfile.IsAutoStart)
                                    {
                                        VirtualRoot.Execute(new SetAutoStartCommand(true, true));
                                    }
                                    string content = $"{MinerProfile.NoShareRestartComputerMinutes.ToString()}分钟无份额重启电脑";
                                    VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), content, toConsole: true);
                                    VirtualRoot.Execute(new ShowRestartWindowsCommand(countDownSeconds: 10));
                                    return;    // 退出
                                }
                                // 产生过份额或者已经两倍重启内核时间了
                                if (restartKernel && (totalShare > 0 || (DateTime.Now - shareOn).TotalMinutes > 2 * MinerProfile.NoShareRestartKernelMinutes))
                                {
                                    VirtualRoot.ThisLocalWarn(nameof(NTMinerRoot), $"{MinerProfile.NoShareRestartKernelMinutes.ToString()}分钟无份额重启内核", toConsole: true);
                                    RestartMine();
                                    return;    // 退出
                                }
                            }
                            if (totalShare > shareCount)
                            {
                                shareCount = totalShare;
                                shareOn    = DateTime.Now;
                            }
                        }
Exemple #28
0
            private KernelInputViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    OnPropertyChangeds();
                }, location: this.GetType());
                AddEventPath <KernelInputAddedEvent>("添加了内核输入后刷新VM内存", LogEnum.DevConsole,
                                                     action: message => {
                    var vm = new KernelInputViewModel(message.Source);
                    _dicById.Add(message.Source.GetId(), vm);
                    OnPropertyChangeds();
                }, location: this.GetType());
                AddEventPath <KernelInputUpdatedEvent>("更新了内核输入后刷新VM内存", LogEnum.DevConsole,
                                                       action: message => {
                    if (_dicById.TryGetValue(message.Source.GetId(), out KernelInputViewModel vm))
                    {
                        if (vm != null)
                        {
                            bool isSupportDualMine = vm.IsSupportDualMine;
                            string args            = vm.Args;
                            vm.Update(message.Source);
                            if (args != vm.Args)
                            {
                                CoinViewModel coinVm = MinerProfileVm.CoinVm;
                                if (coinVm != null && coinVm.CoinKernel != null && coinVm.CoinKernel.Kernel.KernelInputId == vm.Id)
                                {
                                    NTMinerContext.RefreshArgsAssembly.Invoke("当前选用的内核引用的内核输入的形参发生了变更");
                                }
                            }
                            if (isSupportDualMine != vm.IsSupportDualMine)
                            {
                                foreach (var coinKernelVm in CoinKernelVms.AllCoinKernels.Where(a => a.KernelId == message.Source.GetId()))
                                {
                                    coinKernelVm.OnPropertyChanged(nameof(coinKernelVm.IsSupportDualMine));
                                }
                            }
                        }
                    }
                }, location: this.GetType());
                AddEventPath <KernelInputRemovedEvent>("移除了内核输入后刷新VM内存", LogEnum.DevConsole,
                                                       action: message => {
                    if (_dicById.ContainsKey(message.Source.GetId()))
                    {
                        _dicById.Remove(message.Source.GetId());
                        OnPropertyChangeds();
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Exemple #29
0
            private KernelOutputTranslaterViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicById.Clear();
                    _dicByKernelOutputId.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    OnPropertyChanged(nameof(AllKernelOutputTranslaterVms));
                }, location: this.GetType());
                AddEventPath <KernelOutputTranslaterAddedEvent>("添加了内核输出翻译器后刷新VM内存", LogEnum.DevConsole,
                                                                action: message => {
                    if (KernelOutputVms.TryGetKernelOutputVm(message.Source.KernelOutputId, out KernelOutputViewModel kernelOutputVm))
                    {
                        if (!_dicByKernelOutputId.ContainsKey(message.Source.KernelOutputId))
                        {
                            _dicByKernelOutputId.Add(message.Source.KernelOutputId, new List <KernelOutputTranslaterViewModel>());
                        }
                        var vm = new KernelOutputTranslaterViewModel(message.Source);
                        _dicByKernelOutputId[message.Source.KernelOutputId].Add(vm);
                        _dicById.Add(message.Source.GetId(), vm);
                        kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters));
                    }
                }, location: this.GetType());
                AddEventPath <KernelOutputTranslaterUpdatedEvent>("更新了内核输出翻译器后刷新VM内存", LogEnum.DevConsole,
                                                                  action: message => {
                    if (_dicByKernelOutputId.TryGetValue(message.Source.KernelOutputId, out List <KernelOutputTranslaterViewModel> vms))
                    {
                        var vm = vms.FirstOrDefault(a => a.Id == message.Source.GetId());
                        if (vm != null)
                        {
                            vm.Update(message.Source);
                        }
                    }
                }, location: this.GetType());
                AddEventPath <KernelOutputTranslaterRemovedEvent>("移除了内核输出翻译器后刷新VM内存", LogEnum.DevConsole,
                                                                  action: message => {
                    if (_dicByKernelOutputId.ContainsKey(message.Source.KernelOutputId))
                    {
                        var item = _dicByKernelOutputId[message.Source.KernelOutputId].FirstOrDefault(a => a.Id == message.Source.GetId());
                        if (item != null)
                        {
                            _dicByKernelOutputId[message.Source.KernelOutputId].Remove(item);
                        }
                    }
                    if (_dicById.ContainsKey(message.Source.GetId()))
                    {
                        _dicById.Remove(message.Source.GetId());
                    }
                    if (KernelOutputVms.TryGetKernelOutputVm(message.Source.KernelOutputId, out KernelOutputViewModel kernelOutputVm))
                    {
                        kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputTranslaters));
                    }
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
            private SysDicViewModels()
            {
                if (WpfUtil.IsInDesignMode)
                {
                    return;
                }
#if DEBUG
                NTStopwatch.Start();
#endif
                VirtualRoot.AddEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    _dicByCode.Clear();
                    _dicById.Clear();
                    Init();
                }, location: this.GetType());
                VirtualRoot.AddEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         action: message => {
                    OnPropertyChangeds();
                }, location: this.GetType());
                this.Add = new DelegateCommand(() => {
                    new SysDicViewModel(Guid.NewGuid()).Edit.Execute(null);
                });
                AddEventPath <SysDicAddedEvent>("添加了系统字典后调整VM内存", LogEnum.DevConsole,
                                                action: (message) => {
                    if (!_dicById.ContainsKey(message.Source.GetId()))
                    {
                        SysDicViewModel sysDicVm = new SysDicViewModel(message.Source);
                        _dicById.Add(message.Source.GetId(), sysDicVm);
                        if (!_dicByCode.ContainsKey(message.Source.Code))
                        {
                            _dicByCode.Add(message.Source.Code, sysDicVm);
                        }
                        OnPropertyChangeds();
                    }
                }, location: this.GetType());
                AddEventPath <SysDicUpdatedEvent>("更新了系统字典后调整VM内存", LogEnum.DevConsole,
                                                  action: (message) => {
                    if (_dicById.TryGetValue(message.Source.GetId(), out SysDicViewModel vm))
                    {
                        int sortNumber = vm.SortNumber;
                        vm.Update(message.Source);
                        if (sortNumber != vm.SortNumber)
                        {
                            this.OnPropertyChanged(nameof(List));
                        }
                    }
                }, location: this.GetType());
                AddEventPath <SysDicRemovedEvent>("删除了系统字典后调整VM内存", LogEnum.DevConsole,
                                                  action: (message) => {
                    _dicById.Remove(message.Source.GetId());
                    _dicByCode.Remove(message.Source.Code);
                    OnPropertyChangeds();
                }, location: this.GetType());
                Init();
#if DEBUG
                var elapsedMilliseconds = NTStopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }