Beispiel #1
0
        static void Main()
        {
            VirtualRoot.SetOut(new ConsoleOut());
            NTMinerConsole.MainUiOk();
            NTMinerConsole.DisbleQuickEditMode();
            try {
                VirtualRoot.StartTimer();
                // 将服务器地址设为localhost从而使用内网ip访问免于验证用户名密码
                RpcRoot.SetOfficialServerAddress(NTKeyword.Localhost);
                NTMinerRegistry.SetAutoBoot("NTMiner.CalcConfigUpdater", true);
                VirtualRoot.BuildEventPath <Per10MinuteEvent>("每10分钟更新收益计算器", LogEnum.DevConsole, location: typeof(Program), PathPriority.Normal,
                                                              path: message => {
                    UpdateAsync();
                });
                UpdateAsync();
                NTMinerConsole.UserInfo("输入exit并回车可以停止服务!");

                while (Console.ReadLine() != "exit")
                {
                }

                NTMinerConsole.UserOk($"服务停止成功: {DateTime.Now.ToString()}.");
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e);
            }

            System.Threading.Thread.Sleep(1000);
        }
 private GpuProfileViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     VirtualRoot.BuildEventPath <GpuProfileSetRefreshedEvent>("刷新附着在当前币种上的超频数据", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal,
                                                              path: message => {
         lock (_locker) {
             _listByCoinId.Clear();
             _gpuAllVmDicByCoinId.Clear();
         }
         var coinVm = MinerProfileVm.CoinVm;
         if (coinVm != null)
         {
             coinVm.OnOverClockPropertiesChanges();
         }
     });
     BuildEventPath <GpuProfileAddedOrUpdatedEvent>("刷新VM内存", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal,
                                                    path: 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);
             }
         }
     });
 }
Beispiel #3
0
 private ExtendedNotifyIcon(Icon icon, string text, bool isMinerStudio)
 {
     _isMinerStudio    = isMinerStudio;
     _targetNotifyIcon = new NotifyIcon {
         Icon             = icon,
         Visible          = isMinerStudio || NTMinerContext.Instance.MinerProfile.IsShowNotifyIcon,
         Text             = text,
         ContextMenuStrip = new ContextMenuStrip {
             BackColor       = Color.White,
             ShowImageMargin = false
         }
     };
     _targetNotifyIcon.ContextMenuStrip.Items.Add("退出" + text, null, (sender, e) => {
         VirtualRoot.Execute(new CloseNTMinerCommand("手动操作"));
     });
     _targetNotifyIcon.MouseDown += (object sender, MouseEventArgs e) => {
         if (e.Button == MouseButtons.Left)
         {
             VirtualRoot.Execute(new ShowMainWindowCommand(isToggle: true));
         }
     };
     VirtualRoot.BuildEventPath <AppExitEvent>("退出托盘图标", LogEnum.None, typeof(ExtendedNotifyIcon), PathPriority.Normal, path: message => {
         _targetNotifyIcon.Dispose();
     });
 }
            private CoinProfileViewModels()
            {
#if DEBUG
                Write.Stopwatch.Restart();
#endif
                AppContextEventPath <CoinKernelProfilePropertyChangedEvent>("币种内核设置变更后刷新VM内存", LogEnum.DevConsole,
                                                                            action: message => {
                    if (_coinKernelProfileDicById.ContainsKey(message.CoinKernelId))
                    {
                        _coinKernelProfileDicById[message.CoinKernelId].OnPropertyChanged(message.PropertyName);
                    }
                });
                AppContextEventPath <CoinProfilePropertyChangedEvent>("币种设置变更后刷新VM内存", LogEnum.DevConsole,
                                                                      action: message => {
                    if (_coinProfileDicById.ContainsKey(message.CoinId))
                    {
                        _coinProfileDicById[message.CoinId].OnPropertyChanged(message.PropertyName);
                    }
                });
                VirtualRoot.BuildEventPath <LocalContextReInitedEvent>("LocalContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                       action: message => {
                    _coinKernelProfileDicById.Clear();
                    _coinProfileDicById.Clear();
                });
#if DEBUG
                Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor");
#endif
            }
        public void Test2()
        {
            List <PathPriority> list = new List <PathPriority>();

            VirtualRoot.BuildEventPath <Event1>("Normal", LogEnum.DevConsole, this.GetType(), PathPriority.Normal, message => {
                list.Add(PathPriority.Normal);
            });
            VirtualRoot.BuildEventPath <Event1>("Normal", LogEnum.DevConsole, this.GetType(), PathPriority.Normal, message => {
                list.Add(PathPriority.Normal);
            });
            VirtualRoot.BuildEventPath <Event1>("BelowNormal", LogEnum.DevConsole, this.GetType(), PathPriority.BelowNormal, message => {
                list.Add(PathPriority.BelowNormal);
            });
            VirtualRoot.BuildEventPath <Event1>("BelowNormal", LogEnum.DevConsole, this.GetType(), PathPriority.BelowNormal, message => {
                list.Add(PathPriority.BelowNormal);
            });
            VirtualRoot.BuildEventPath <Event1>("AboveNormal", LogEnum.DevConsole, this.GetType(), PathPriority.AboveNormal, message => {
                list.Add(PathPriority.AboveNormal);
            });
            VirtualRoot.BuildEventPath <Event1>("AboveNormal", LogEnum.DevConsole, this.GetType(), PathPriority.AboveNormal, message => {
                list.Add(PathPriority.AboveNormal);
            });
            VirtualRoot.RaiseEvent(new Event1());
            Assert.AreEqual(list[0], PathPriority.AboveNormal);
            Assert.AreEqual(list[1], PathPriority.AboveNormal);
            Assert.AreEqual(list[2], PathPriority.Normal);
            Assert.AreEqual(list[3], PathPriority.Normal);
            Assert.AreEqual(list[4], PathPriority.BelowNormal);
            Assert.AreEqual(list[5], PathPriority.BelowNormal);
        }
Beispiel #6
0
 public static void Start(string baseAddress, Action <HttpSelfHostConfiguration> doConfig = null)
 {
     if (s_httpServer != null)
     {
         return;
     }
     try {
         var config = new HttpSelfHostConfiguration(baseAddress);
         config.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
         config.Formatters.JsonFormatter.SerializerSettings = NTJsonSerializer.SerializerSettings;
         doConfig?.Invoke(config);
         // 在默认路由之前doConfig从而使自定义路由的优先级高于默认路由
         config.Routes.MapHttpRoute("API Default", "api/{controller}/{action}");
         s_httpServer = new HttpSelfHostServer(config);
         s_httpServer.OpenAsync();
         VirtualRoot.BuildEventPath <AppExitEvent>("退出HttpServer", LogEnum.None, typeof(HttpServer), PathPriority.Normal, path: message => {
             var tmp = s_httpServer;
             if (tmp != null)
             {
                 s_httpServer = null;
                 tmp.Dispose();
             }
         });
     }
     catch (Exception e) {
         Logger.ErrorDebugLine(e);
     }
 }
Beispiel #7
0
        static void Main(string[] args)
        {
            VirtualRoot.StartTimer();
            try {
                // 将服务器地址设为localhost从而使用内网ip访问免于验证用户名密码
                MainAssemblyInfo.SetOfficialServerHost("localhost");
                NTMinerRegistry.SetAutoBoot("NTMiner.CalcConfigUpdater", true);
                VirtualRoot.BuildEventPath <Per10MinuteEvent>("每10分钟更新收益计算器", LogEnum.DevConsole,
                                                              action: message => {
                    UpdateAsync();
                });
                UpdateAsync();
                Write.UserInfo("输入exit并回车可以停止服务!");

                while (Console.ReadLine() != "exit")
                {
                }

                Write.UserOk($"服务停止成功: {DateTime.Now}.");
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e);
            }

            System.Threading.Thread.Sleep(1000);
        }
Beispiel #8
0
 private CoinProfileViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     BuildEventPath <CoinKernelProfilePropertyChangedEvent>("刷新VM内存", LogEnum.DevConsole,
                                                            path: message => {
         if (_coinKernelProfileDicById.ContainsKey(message.CoinKernelId))
         {
             _coinKernelProfileDicById[message.CoinKernelId].OnPropertyChanged(message.PropertyName);
         }
     }, location: this.GetType());
     BuildEventPath <CoinProfilePropertyChangedEvent>("刷新VM内存", LogEnum.DevConsole,
                                                      path: message => {
         if (_coinProfileDicById.ContainsKey(message.CoinId))
         {
             _coinProfileDicById[message.CoinId].OnPropertyChanged(message.PropertyName);
         }
     }, location: this.GetType());
     VirtualRoot.BuildEventPath <LocalContextReInitedEvent>("刷新VM内存", LogEnum.DevConsole,
                                                            path: message => {
         _coinKernelProfileDicById.Clear();
         _coinProfileDicById.Clear();
     }, location: this.GetType());
 }
Beispiel #9
0
            private SysDicViewModels()
            {
#if DEBUG
                Write.Stopwatch.Start();
#endif
                VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                        action: message => {
                    _dicByCode.Clear();
                    _dicById.Clear();
                    Init();
                });
                VirtualRoot.BuildEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                           action: message => {
                    OnPropertyChangeds();
                });
                this.Add = new DelegateCommand(() => {
                    new SysDicViewModel(Guid.NewGuid()).Edit.Execute(null);
                });
                BuildEventPath <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();
                    }
                });
                BuildEventPath <SysDicUpdatedEvent>("更新了系统字典后调整VM内存", LogEnum.DevConsole,
                                                    action: (message) => {
                    if (_dicById.ContainsKey(message.Source.GetId()))
                    {
                        SysDicViewModel entity = _dicById[message.Source.GetId()];
                        int sortNumber         = entity.SortNumber;
                        entity.Update(message.Source);
                        if (sortNumber != entity.SortNumber)
                        {
                            this.OnPropertyChanged(nameof(List));
                        }
                    }
                });
                BuildEventPath <SysDicRemovedEvent>("删除了系统字典后调整VM内存", LogEnum.DevConsole,
                                                    action: (message) => {
                    _dicById.Remove(message.Source.GetId());
                    _dicByCode.Remove(message.Source.Code);
                    OnPropertyChangeds();
                });
                Init();
#if DEBUG
                var elapsedMilliseconds = Write.Stopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Beispiel #10
0
 private KernelInputViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                             path: message => {
         _dicById.Clear();
         Init();
     }, location: this.GetType());
     VirtualRoot.BuildEventPath <ServerContextReInitedEventHandledEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         path: message => {
         OnPropertyChangeds();
     }, location: this.GetType());
     BuildEventPath <KernelInputAddedEvent>("添加了内核输入后刷新VM内存", LogEnum.DevConsole,
                                            path: message => {
         var vm = new KernelInputViewModel(message.Source);
         _dicById.Add(message.Source.GetId(), vm);
         OnPropertyChangeds();
     }, location: this.GetType());
     BuildEventPath <KernelInputUpdatedEvent>("更新了内核输入后刷新VM内存", LogEnum.DevConsole,
                                              path: 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());
     BuildEventPath <KernelInputRemovedEvent>("移除了内核输入后刷新VM内存", LogEnum.DevConsole,
                                              path: message => {
         if (_dicById.ContainsKey(message.Source.GetId()))
         {
             _dicById.Remove(message.Source.GetId());
             OnPropertyChangeds();
         }
     }, location: this.GetType());
     Init();
 }
Beispiel #11
0
            private KernelViewModels()
            {
#if DEBUG
                Write.Stopwatch.Restart();
#endif
                VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                        action: message => {
                    _dicById.Clear();
                    Init();
                });
                VirtualRoot.BuildEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                           action: message => {
                    OnPropertyChanged(nameof(AllKernels));
                });
                AppContextEventPath <KernelAddedEvent>("添加了内核后调整VM内存", LogEnum.DevConsole,
                                                       action: (message) => {
                    _dicById.Add(message.Source.GetId(), new KernelViewModel(message.Source));
                    OnPropertyChanged(nameof(AllKernels));
                    foreach (var coinKernelVm in AppContext.Instance.CoinKernelVms.AllCoinKernels.Where(a => a.KernelId == message.Source.GetId()))
                    {
                        coinKernelVm.OnPropertyChanged(nameof(coinKernelVm.IsSupportDualMine));
                    }
                });
                AppContextEventPath <KernelRemovedEvent>("删除了内核后调整VM内存", LogEnum.DevConsole,
                                                         action: message => {
                    _dicById.Remove(message.Source.GetId());
                    OnPropertyChanged(nameof(AllKernels));
                    foreach (var coinKernelVm in AppContext.Instance.CoinKernelVms.AllCoinKernels.Where(a => a.KernelId == message.Source.GetId()))
                    {
                        coinKernelVm.OnPropertyChanged(nameof(coinKernelVm.IsSupportDualMine));
                    }
                });
                AppContextEventPath <KernelUpdatedEvent>("更新了内核后调整VM内存", LogEnum.DevConsole,
                                                         action: message => {
                    var entity = _dicById[message.Source.GetId()];
                    PublishStatus publishStatus = entity.PublishState;
                    Guid kernelInputId          = entity.KernelInputId;
                    entity.Update(message.Source);
                    if (publishStatus != entity.PublishState)
                    {
                        foreach (var coinKernelVm in AppContext.Instance.CoinKernelVms.AllCoinKernels.Where(a => a.KernelId == entity.Id))
                        {
                            foreach (var coinVm in AppContext.Instance.CoinVms.AllCoins.Where(a => a.Id == coinKernelVm.CoinId))
                            {
                                coinVm.OnPropertyChanged(nameof(coinVm.CoinKernels));
                            }
                        }
                    }
                    if (kernelInputId != entity.KernelInputId)
                    {
                        NTMinerRoot.RefreshArgsAssembly.Invoke();
                    }
                });
                Init();
#if DEBUG
                Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor");
#endif
            }
Beispiel #12
0
 private MqRedis(ConnectionMultiplexer redisConn, IModel channel)
 {
     this._redisConn     = redisConn;
     this._mqChannel     = channel;
     this._mqCountSender = new MqCountSender(this);
     VirtualRoot.BuildEventPath <Per20SecondEvent>("周期将本节点的MqCountData广播到Mq上去", LogEnum.None, message => {
         this._mqCountSender.SendMqCounts(MqCountRoot.GetMqCount());
     }, typeof(MqCountRoot));
 }
Beispiel #13
0
 private SysDicItemViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("刷新VM内存", LogEnum.DevConsole,
                                                             path: message => {
         _dicById.Clear();
         Init();
     }, location: this.GetType());
     VirtualRoot.BuildEventPath <ServerContextReInitedEventHandledEvent>("刷新视图界面", LogEnum.DevConsole,
                                                                         path: message => {
         AllPropertyChanged();
     }, location: this.GetType());
     BuildEventPath <SysDicItemAddedEvent>("调整VM内存", LogEnum.DevConsole,
                                           path: (message) => {
         if (!_dicById.ContainsKey(message.Source.GetId()))
         {
             _dicById.Add(message.Source.GetId(), new SysDicItemViewModel(message.Source));
             AllPropertyChanged();
             if (SysDicVms.TryGetSysDicVm(message.Source.DicId, out SysDicViewModel sysDicVm))
             {
                 sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItems));
                 sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItemsSelect));
             }
         }
     }, location: this.GetType());
     BuildEventPath <SysDicItemUpdatedEvent>("调整VM内存", LogEnum.DevConsole,
                                             path: (message) => {
         if (_dicById.TryGetValue(message.Source.GetId(), out SysDicItemViewModel vm))
         {
             int sortNumber = vm.SortNumber;
             vm.Update(message.Source);
             if (sortNumber != vm.SortNumber)
             {
                 if (SysDicVms.TryGetSysDicVm(vm.DicId, out SysDicViewModel sysDicVm))
                 {
                     sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItems));
                     sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItemsSelect));
                 }
             }
         }
     }, location: this.GetType());
     BuildEventPath <SysDicItemRemovedEvent>("调整VM内存", LogEnum.DevConsole,
                                             path: (message) => {
         _dicById.Remove(message.Source.GetId());
         AllPropertyChanged();
         if (SysDicVms.TryGetSysDicVm(message.Source.DicId, out SysDicViewModel sysDicVm))
         {
             sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItems));
             sysDicVm.OnPropertyChanged(nameof(sysDicVm.SysDicItemsSelect));
         }
     }, location: this.GetType());
     Init();
 }
            private GroupViewModels()
            {
#if DEBUG
                Write.Stopwatch.Restart();
#endif
                this.Add = new DelegateCommand(() => {
                    new GroupViewModel(Guid.NewGuid())
                    {
                        SortNumber = Count + 1
                    }.Edit.Execute(FormType.Add);
                });
                VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                        action: message => {
                    _dicById.Clear();
                    Init();
                });
                VirtualRoot.BuildEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                           action: message => {
                    OnPropertyChangeds();
                });
                AppContextEventPath <GroupAddedEvent>("添加了组后调整VM内存", LogEnum.DevConsole,
                                                      action: (message) => {
                    if (!_dicById.ContainsKey(message.Source.GetId()))
                    {
                        GroupViewModel groupVm = new GroupViewModel(message.Source);
                        _dicById.Add(message.Source.GetId(), groupVm);
                        OnPropertyChangeds();
                    }
                });
                AppContextEventPath <GroupUpdatedEvent>("更新了组后调整VM内存", LogEnum.DevConsole,
                                                        action: (message) => {
                    if (_dicById.ContainsKey(message.Source.GetId()))
                    {
                        GroupViewModel entity = _dicById[message.Source.GetId()];
                        int sortNumber        = entity.SortNumber;
                        entity.Update(message.Source);
                        if (sortNumber != entity.SortNumber)
                        {
                            this.OnPropertyChanged(nameof(List));
                            OnPropertyChanged(nameof(SelectionOptions));
                        }
                    }
                });
                AppContextEventPath <GroupRemovedEvent>("删除了组后调整VM内存", LogEnum.DevConsole,
                                                        action: (message) => {
                    _dicById.Remove(message.Source.GetId());
                    OnPropertyChangeds();
                });
                Init();
#if DEBUG
                Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor");
#endif
            }
Beispiel #15
0
 private static void MinerClientsBreatherInit()
 {
     // 这样做以消减WebApiServer收到的Mq消息的数量,能消减90%以上,降低CPU使用率
     VirtualRoot.BuildEventPath <Per1SecondEvent>("每1秒钟将WsServer暂存的来自挖矿端的呼吸通过Mq发送给WebApiServer", LogEnum.None, message => {
         Guid[] clientIds;
         lock (_lockerForToBreathClientIds) {
             clientIds = _toBreathClientIds.ToArray();
             _toBreathClientIds.Clear();
         }
         MinerClientMqSender.SendMinerClientsWsBreathed(clientIds);
     }, typeof(AppRoot));
 }
Beispiel #16
0
            private KernelOutputFilterViewModels()
            {
#if DEBUG
                Write.Stopwatch.Restart();
#endif
                VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                        action: message => {
                    _dicById.Clear();
                    _dicByKernelOutputId.Clear();
                    Init();
                });
                AppContextEventPath <KernelOutputFilterAddedEvent>("添加了内核输出过滤器后刷新VM内存", LogEnum.DevConsole,
                                                                   action: message => {
                    if (!_dicById.ContainsKey(message.Source.GetId()))
                    {
                        KernelOutputFilterViewModel vm = new KernelOutputFilterViewModel(message.Source);
                        _dicById.Add(vm.Id, vm);
                        if (AppContext.Instance.KernelOutputVms.TryGetKernelOutputVm(vm.KernelOutputId, out KernelOutputViewModel kernelOutputVm))
                        {
                            if (!_dicByKernelOutputId.ContainsKey(vm.KernelOutputId))
                            {
                                _dicByKernelOutputId.Add(vm.KernelOutputId, new List <KernelOutputFilterViewModel>());
                            }
                            _dicByKernelOutputId[vm.KernelOutputId].Add(vm);
                            kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputFilters));
                        }
                    }
                });
                AppContextEventPath <KernelOutputFilterUpdatedEvent>("更新了内核输出过滤器后刷新VM内存", LogEnum.DevConsole,
                                                                     action: message => {
                    if (_dicById.TryGetValue(message.Source.GetId(), out KernelOutputFilterViewModel vm))
                    {
                        vm.Update(message.Source);
                    }
                });
                AppContextEventPath <KernelOutputFilterRemovedEvent>("删除了内核输出过滤器后刷新VM内存", LogEnum.DevConsole,
                                                                     action: message => {
                    if (_dicById.TryGetValue(message.Source.GetId(), out KernelOutputFilterViewModel vm))
                    {
                        _dicById.Remove(vm.Id);
                        _dicByKernelOutputId[vm.KernelOutputId].Remove(vm);
                        KernelOutputViewModel kernelOutputVm;
                        if (AppContext.Instance.KernelOutputVms.TryGetKernelOutputVm(vm.KernelOutputId, out kernelOutputVm))
                        {
                            kernelOutputVm.OnPropertyChanged(nameof(kernelOutputVm.KernelOutputFilters));
                        }
                    }
                });
                Init();
#if DEBUG
                Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor");
#endif
            }
Beispiel #17
0
 static WsMessageFromMinerClientHandler()
 {
     // 这样做以消减WebApiServer收到的Mq消息的数量,能消减90%以上,降低CPU使用率
     VirtualRoot.BuildEventPath <Per1SecondEvent>("每1秒钟将WsServer暂存的来自挖矿端的SpeedData通过Mq发送给WebApiServer", LogEnum.None, message => {
         ClientIdIp[] clientIdIps;
         lock (_lockerForClientIdIps) {
             clientIdIps = _clientIdIps.ToArray();
             _clientIdIps.Clear();
         }
         AppRoot.MinerClientMqSender.SendSpeeds(clientIdIps);
     }, typeof(WsMessageFromMinerClientHandler));
 }
 private SysDicViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("刷新VM内存", LogEnum.DevConsole,
                                                             path: message => {
         _dicByCode.Clear();
         _dicById.Clear();
         Init();
     }, location: this.GetType());
     VirtualRoot.BuildEventPath <ServerContextReInitedEventHandledEvent>("刷新视图界面", LogEnum.DevConsole,
                                                                         path: message => {
         OnPropertyChangeds();
     }, location: this.GetType());
     this.Add = new DelegateCommand(() => {
         new SysDicViewModel(Guid.NewGuid()).Edit.Execute(null);
     });
     BuildEventPath <SysDicAddedEvent>("调整VM内存", LogEnum.DevConsole,
                                       path: (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());
     BuildEventPath <SysDicUpdatedEvent>("调整VM内存", LogEnum.DevConsole,
                                         path: (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());
     BuildEventPath <SysDicRemovedEvent>("调整VM内存", LogEnum.DevConsole,
                                         path: (message) => {
         _dicById.Remove(message.Source.GetId());
         _dicByCode.Remove(message.Source.Code);
         OnPropertyChangeds();
     }, location: this.GetType());
     Init();
 }
Beispiel #19
0
 private MqRedis(ConnectionMultiplexer redisConn, IModel channel)
 {
     this._redisConn     = redisConn;
     this._mqChannel     = channel;
     this._mqCountSender = new MqCountSender(this);
     VirtualRoot.BuildEventPath <Per20SecondEvent>("周期将本节点的MqCountData广播到Mq上去", LogEnum.None, typeof(MqCountRoot), PathPriority.Normal, message => {
         this._mqCountSender.SendMqCounts(MqCountRoot.GetMqCount());
     });
     VirtualRoot.BuildCmdPath <RefreshMinerTestIdMqCommand>(this.GetType(), LogEnum.DevConsole, message => {
         RefreshClientTestId();
     });
     RefreshClientTestId();
 }
            private PoolViewModels()
            {
#if DEBUG
                Write.Stopwatch.Start();
#endif
                VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                        action: message => {
                    _dicById.Clear();
                    Init();
                });
                VirtualRoot.BuildEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                           action: message => {
                    OnPropertyChanged(nameof(AllPools));
                });
                BuildEventPath <PoolAddedEvent>("添加矿池后刷新VM内存", LogEnum.DevConsole,
                                                action: (message) => {
                    _dicById.Add(message.Source.GetId(), new PoolViewModel(message.Source));
                    OnPropertyChanged(nameof(AllPools));
                    if (AppContext.Instance.CoinVms.TryGetCoinVm((Guid)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(NTMiner.Vms.CoinViewModel.OptionPools));
                    }
                });
                BuildEventPath <PoolRemovedEvent>("删除矿池后刷新VM内存", LogEnum.DevConsole,
                                                  action: (message) => {
                    _dicById.Remove(message.Source.GetId());
                    OnPropertyChanged(nameof(AllPools));
                    if (AppContext.Instance.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));
                    }
                });
                BuildEventPath <PoolUpdatedEvent>("更新矿池后刷新VM内存", LogEnum.DevConsole,
                                                  action: (message) => {
                    _dicById[message.Source.GetId()].Update(message.Source);
                });
                Init();
#if DEBUG
                var elapsedMilliseconds = Write.Stopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
            private static void KernelProcessDaemon(IMineContext mineContext, Action clear)
            {
                if (_kernelProcessDaemon != null)
                {
                    VirtualRoot.DeletePath(_kernelProcessDaemon);
                    _kernelProcessDaemon = null;
                    clear?.Invoke();
                }
                string processName = mineContext.Kernel.GetProcessName();

                _kernelProcessDaemon = VirtualRoot.BuildEventPath <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);
                                }
                                if (_kernelProcessDaemon != null)
                                {
                                    VirtualRoot.DeletePath(_kernelProcessDaemon);
                                    clear?.Invoke();
                                }
                            }
                        }
                    }
                    else
                    {
                        if (_kernelProcessDaemon != null)
                        {
                            VirtualRoot.DeletePath(_kernelProcessDaemon);
                            _kernelProcessDaemon = null;
                            clear?.Invoke();
                        }
                    }
                });
            }
            private PackageViewModels()
            {
#if DEBUG
                Write.Stopwatch.Start();
#endif
                VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                        action: message => {
                    _dicById.Clear();
                    Init();
                });
                VirtualRoot.BuildEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                           action: message => {
                    OnPropertyChanged(nameof(AllPackages));
                });
                BuildEventPath <PackageAddedEvent>("添加了包后调整VM内存", LogEnum.DevConsole,
                                                   action: (message) => {
                    _dicById.Add(message.Source.GetId(), new PackageViewModel(message.Source));
                    OnPropertyChanged(nameof(AllPackages));
                    foreach (var item in AppContext.Instance.KernelVms.AllKernels)
                    {
                        item.OnPropertyChanged(nameof(item.IsPackageValid));
                    }
                });
                BuildEventPath <PackageRemovedEvent>("删除了包后调整VM内存", LogEnum.DevConsole,
                                                     action: message => {
                    _dicById.Remove(message.Source.GetId());
                    OnPropertyChanged(nameof(AllPackages));
                    foreach (var item in AppContext.Instance.KernelVms.AllKernels)
                    {
                        item.OnPropertyChanged(nameof(item.IsPackageValid));
                    }
                });
                BuildEventPath <PackageUpdatedEvent>("更新了包后调整VM内存", LogEnum.DevConsole,
                                                     action: message => {
                    var entity = _dicById[message.Source.GetId()];
                    entity.Update(message.Source);
                    foreach (var item in AppContext.Instance.KernelVms.AllKernels)
                    {
                        item.OnPropertyChanged(nameof(item.IsPackageValid));
                    }
                });
                Init();
#if DEBUG
                var elapsedMilliseconds = Write.Stopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Beispiel #23
0
 private GroupViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     this.Add = new DelegateCommand(() => {
         new GroupViewModel(Guid.NewGuid())
         {
             SortNumber = Count + 1
         }.Edit.Execute(FormType.Add);
     });
     VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("刷新VM内存", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal,
                                                             path: message => {
         _dicById.Clear();
         Init();
     });
     VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("刷新视图界面", LogEnum.DevConsole, location: this.GetType(), PathPriority.BelowNormal,
                                                             path: message => {
         OnPropertyChangeds();
     });
     BuildEventPath <GroupAddedEvent>("调整VM内存", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal,
                                      path: (message) => {
         if (!_dicById.ContainsKey(message.Source.GetId()))
         {
             GroupViewModel groupVm = new GroupViewModel(message.Source);
             _dicById.Add(message.Source.GetId(), groupVm);
             OnPropertyChangeds();
         }
     });
     BuildEventPath <GroupUpdatedEvent>("调整VM内存", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal,
                                        path: (message) => {
         if (_dicById.TryGetValue(message.Source.GetId(), out GroupViewModel vm))
         {
             int sortNumber = vm.SortNumber;
             vm.Update(message.Source);
             if (sortNumber != vm.SortNumber)
             {
                 this.OnPropertyChanged(nameof(List));
                 OnPropertyChanged(nameof(SelectionOptions));
             }
         }
     });
     BuildEventPath <GroupRemovedEvent>("调整VM内存", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal,
                                        path: (message) => {
         _dicById.Remove(message.Source.GetId());
         OnPropertyChangeds();
     });
     Init();
 }
Beispiel #24
0
            private KernelOutputViewModels()
            {
#if DEBUG
                Write.Stopwatch.Start();
#endif
                VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                        action: message => {
                    _dicById.Clear();
                    Init();
                });
                VirtualRoot.BuildEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                           action: message => {
                    AllPropertyChanged();
                });
                BuildEventPath <KernelOutputAddedEvent>("添加了内核输出组后刷新VM内存", LogEnum.DevConsole,
                                                        action: message => {
                    var vm = new KernelOutputViewModel(message.Source);
                    _dicById.Add(message.Source.GetId(), vm);
                    OnPropertyChanged(nameof(AllKernelOutputVms));
                    OnPropertyChanged(nameof(PleaseSelectVms));
                });
                BuildEventPath <KernelOutputUpdatedEvent>("更新了内核输出组后刷新VM内存", LogEnum.DevConsole,
                                                          action: message => {
                    if (_dicById.ContainsKey(message.Source.GetId()))
                    {
                        var item = _dicById[message.Source.GetId()];
                        if (item != null)
                        {
                            item.Update(message.Source);
                        }
                    }
                });
                BuildEventPath <KernelOutputRemovedEvent>("移除了内核输出组后刷新VM内存", LogEnum.DevConsole,
                                                          action: message => {
                    if (_dicById.ContainsKey(message.Source.GetId()))
                    {
                        _dicById.Remove(message.Source.GetId());
                        OnPropertyChanged(nameof(AllKernelOutputVms));
                        OnPropertyChanged(nameof(PleaseSelectVms));
                    }
                });
                Init();
#if DEBUG
                var elapsedMilliseconds = Write.Stopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Beispiel #25
0
            private WalletViewModels()
            {
#if DEBUG
                Write.Stopwatch.Start();
#endif
                VirtualRoot.BuildEventPath <LocalContextReInitedEvent>("LocalContext刷新后刷新钱包Vm内存", LogEnum.None,
                                                                       action: message => {
                    _dicById.Clear();
                    Init();
                });
                BuildEventPath <WalletAddedEvent>("添加了钱包后调整VM内存", LogEnum.DevConsole,
                                                  action: (message) => {
                    _dicById.Add(message.Source.GetId(), new WalletViewModel(message.Source));
                    OnPropertyChanged(nameof(WalletList));
                    CoinViewModel coin;
                    if (AppContext.Instance.CoinVms.TryGetCoinVm((Guid)message.Source.CoinId, out coin))
                    {
                        coin.OnPropertyChanged(nameof(CoinViewModel.Wallets));
                        coin.OnPropertyChanged(nameof(CoinViewModel.WalletItems));
                        coin.CoinKernel?.CoinKernelProfile?.SelectedDualCoin?.OnPropertyChanged(nameof(CoinViewModel.Wallets));
                    }
                });
                BuildEventPath <WalletRemovedEvent>("删除了钱包后调整VM内存", LogEnum.DevConsole,
                                                    action: (message) => {
                    _dicById.Remove(message.Source.GetId());
                    OnPropertyChanged(nameof(WalletList));
                    CoinViewModel coin;
                    if (AppContext.Instance.CoinVms.TryGetCoinVm((Guid)message.Source.CoinId, out 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));
                    }
                });
                BuildEventPath <WalletUpdatedEvent>("更新了钱包后调整VM内存", LogEnum.DevConsole,
                                                    action: (message) => {
                    _dicById[message.Source.GetId()].Update(message.Source);
                });
                Init();
#if DEBUG
                var elapsedMilliseconds = Write.Stopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
            private FileWriterViewModels()
            {
#if DEBUG
                Write.Stopwatch.Start();
#endif
                this.Add = new DelegateCommand(() => {
                    new FileWriterViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add);
                });
                VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                        action: message => {
                    _dicById.Clear();
                    Init();
                });
                VirtualRoot.BuildEventPath <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                           action: message => {
                    OnPropertyChangeds();
                });
                BuildEventPath <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();
                    }
                });
                BuildEventPath <FileWriterUpdatedEvent>("更新了文件书写器后调整VM内存", LogEnum.DevConsole,
                                                        action: (message) => {
                    if (_dicById.ContainsKey(message.Source.GetId()))
                    {
                        FileWriterViewModel entity = _dicById[message.Source.GetId()];
                        entity.Update(message.Source);
                    }
                });
                BuildEventPath <FileWriterRemovedEvent>("删除了文件书写器后调整VM内存", LogEnum.DevConsole,
                                                        action: (message) => {
                    _dicById.Remove(message.Source.GetId());
                    OnPropertyChangeds();
                });
                Init();
#if DEBUG
                var elapsedMilliseconds = Write.Stopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Beispiel #27
0
 private PoolViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("刷新VM内存", LogEnum.DevConsole,
                                                             path: message => {
         _dicById.Clear();
         Init();
     }, location: this.GetType());
     VirtualRoot.BuildEventPath <ServerContextReInitedEventHandledEvent>("刷新视图界面", LogEnum.DevConsole,
                                                                         path: message => {
         OnPropertyChanged(nameof(AllPools));
     }, location: this.GetType());
     BuildEventPath <PoolAddedEvent>("刷新VM内存", LogEnum.DevConsole,
                                     path: (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());
     BuildEventPath <PoolRemovedEvent>("刷新VM内存", LogEnum.DevConsole,
                                       path: (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());
     BuildEventPath <PoolUpdatedEvent>("刷新VM内存", LogEnum.DevConsole,
                                       path: (message) => {
         if (_dicById.TryGetValue(message.Source.GetId(), out PoolViewModel vm))
         {
             vm.Update(message.Source);
         }
     }, location: this.GetType());
     Init();
 }
            private CoinGroupViewModels()
            {
#if DEBUG
                Write.Stopwatch.Start();
#endif
                VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                                        action: message => {
                    _dicById.Clear();
                    _listByGroupId.Clear();
                    Init();
                });
                BuildEventPath <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);
                    }
                });
                BuildEventPath <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);
                    }
                });
                Init();
#if DEBUG
                var elapsedMilliseconds = Write.Stopwatch.Stop();
                if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds)
                {
                    Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor");
                }
#endif
            }
Beispiel #29
0
            public static void CreateProcessAsync(IMineContext mineContext)
            {
                Task.Factory.StartNew(() => {
                    lock (_locker) {
                        try {
#if DEBUG
                            Write.Stopwatch.Restart();
#endif
                            // 清理除当前外的Temp/Kernel
                            Cleaner.Instance.Clear();
#if DEBUG
                            Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {nameof(MinerProcess)}.{nameof(CreateProcessAsync)}[{nameof(Cleaner)}.{nameof(Cleaner.Clear)}]");
#endif
                            Write.UserOk("场地打扫完毕");
                            // 应用超频
                            if (Instance.GpuProfileSet.IsOverClockEnabled(mineContext.MainCoin.GetId()))
                            {
                                Write.UserWarn("应用超频,如果CPU性能较差耗时可能超过1分钟,请耐心等待");
                                var cmd = new CoinOverClockCommand(mineContext.MainCoin.GetId());
                                // N卡超频当cpu性能非常差时较耗时,所以这里弄个回调
                                IMessagePathId callback = null;
                                callback = VirtualRoot.BuildEventPath <CoinOverClockDoneEvent>("超频完成后继续流程", LogEnum.DevConsole,
                                                                                               message => {
                                    if (mineContext != Instance.CurrentMineContext)
                                    {
                                        VirtualRoot.DeletePath(callback);
                                    }
                                    else if (message.CmdId == cmd.Id)
                                    {
                                        VirtualRoot.DeletePath(callback);
                                        ContinueCreateProcess(mineContext);
                                    }
                                });
                                VirtualRoot.Execute(cmd);
                            }
                            else
                            {
                                ContinueCreateProcess(mineContext);
                            }
                        }
                        catch (Exception e) {
                            Logger.ErrorDebugLine(e);
                            Write.UserFail("挖矿内核启动失败,请联系开发人员解决");
                        }
                    }
                });
            }
Beispiel #30
0
 private PoolKernelViewModels()
 {
     if (WpfUtil.IsInDesignMode)
     {
         return;
     }
     VirtualRoot.BuildEventPath <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole,
                                                             path: message => {
         _dicById.Clear();
         Init();
     }, location: this.GetType());
     VirtualRoot.BuildEventPath <ServerContextReInitedEventHandledEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole,
                                                                         path: message => {
         OnPropertyChanged(nameof(AllPoolKernels));
     }, location: this.GetType());
     BuildEventPath <PoolKernelAddedEvent>("新添了矿池内核后刷新矿池内核VM内存", LogEnum.DevConsole,
                                           path: (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());
     BuildEventPath <PoolKernelRemovedEvent>("移除了币种内核后刷新矿池内核VM内存", LogEnum.DevConsole,
                                             path: (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());
     BuildEventPath <PoolKernelUpdatedEvent>("更新了矿池内核后刷新VM内存", LogEnum.DevConsole,
                                             path: (message) => {
         if (_dicById.TryGetValue(message.Source.GetId(), out PoolKernelViewModel vm))
         {
             vm.Update(message.Source);
         }
     }, location: this.GetType());
     Init();
 }