private CoinProfileViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif On <CoinKernelProfilePropertyChangedEvent>("币种内核设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { if (_coinKernelProfileDicById.ContainsKey(message.CoinKernelId)) { _coinKernelProfileDicById[message.CoinKernelId].OnPropertyChanged(message.PropertyName); } }); On <CoinProfilePropertyChangedEvent>("币种设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { if (_coinProfileDicById.ContainsKey(message.CoinId)) { _coinProfileDicById[message.CoinId].OnPropertyChanged(message.PropertyName); } }); On <LocalContextReInitedEvent>("MinerProfile刷新后刷新VM内存", LogEnum.DevConsole, action: message => { _coinKernelProfileDicById.Clear(); _coinProfileDicById.Clear(); }); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private VirtualMemorySetViewModel() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif foreach (var item in GetPagingFiles()) { _initialVms.Add(item.DriveName, item); } foreach (var drive in AppContext.Instance.DriveSetVm.Drives) { _dic.Add(drive.Name, new VirtualMemory(drive.Name, 0)); } foreach (var item in _initialVms.Values) { if (_dic.TryGetValue(item.DriveName, out VirtualMemory vm)) { vm.MaxSizeMb = item.MaxSizeMb; } } NTMinerRoot.OSVirtualMemoryMb = _dic.Values.Sum(a => a.MaxSizeMb); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private CoinGroupViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif On <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById.Clear(); _listByGroupId.Clear(); Init(); }); On <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); } }); On <CoinGroupUpdatedEvent>("更新了币组后调整VM内存", LogEnum.DevConsole, action: (message) => { if (_dicById.ContainsKey(message.Source.GetId())) { CoinGroupViewModel entity = _dicById[message.Source.GetId()]; int sortNumber = entity.SortNumber; entity.Update(message.Source); if (sortNumber != entity.SortNumber) { GroupViewModel groupVm; if (AppContext.Instance.GroupVms.TryGetGroupVm(entity.GroupId, out groupVm)) { groupVm.OnPropertyChanged(nameof(groupVm.CoinGroupVms)); } } } }); On <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 Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private MinerProfileViewModel() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif if (Design.IsInDesignMode) { return; } NTMinerRoot.RefreshArgsAssembly = () => { if (CoinVm != null && CoinVm.CoinKernel != null && CoinVm.CoinKernel.Kernel != null) { var coinKernelProfile = CoinVm.CoinKernel.CoinKernelProfile; var kernelInput = CoinVm.CoinKernel.Kernel.KernelInputVm; if (coinKernelProfile != null && kernelInput != null) { if (coinKernelProfile.IsDualCoinEnabled && !kernelInput.IsAutoDualWeight) { if (coinKernelProfile.DualCoinWeight > kernelInput.DualWeightMax) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMax; } else if (coinKernelProfile.DualCoinWeight < kernelInput.DualWeightMin) { coinKernelProfile.DualCoinWeight = kernelInput.DualWeightMin; } NTMinerRoot.Instance.MinerProfile.SetCoinKernelProfileProperty(coinKernelProfile.CoinKernelId, nameof(coinKernelProfile.DualCoinWeight), coinKernelProfile.DualCoinWeight); } } } this.ArgsAssembly = NTMinerRoot.Instance.BuildAssembleArgs(); }; On <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(CoinVm)); }); Window <RefreshAutoBootStartCommand>("刷新开机启动和自动挖矿的展示", LogEnum.UserConsole, action: message => { OnPropertyChanged(nameof(IsAutoBoot)); OnPropertyChanged(nameof(IsAutoStart)); }); On <MinerProfilePropertyChangedEvent>("MinerProfile设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }); On <MineWorkPropertyChangedEvent>("MineWork设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { OnPropertyChanged(message.PropertyName); }); On <LocalContextVmsReInitedEvent>("本地上下文视图模型集刷新后刷新界面", LogEnum.DevConsole, action: message => { AllPropertyChanged(); }); NTMinerRoot.RefreshArgsAssembly.Invoke(); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private KernelViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif VirtualRoot.On <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById.Clear(); Init(); }); VirtualRoot.On <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(AllKernels)); }); On <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)); } }); On <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)); } }); On <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.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private GpuStatusBarViewModel() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif this.GpuAllVm = AppContext.Instance.GpuVms.FirstOrDefault(a => a.Index == NTMinerRoot.GpuAllId); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private SysDicViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif On <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole, action: message => { _dicByCode.Clear(); _dicById.Clear(); Init(); }); On <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChangeds(); }); this.Add = new DelegateCommand(() => { new SysDicViewModel(Guid.NewGuid()).Edit.Execute(null); }); On <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(); } }); On <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)); } } }); On <SysDicRemovedEvent>("删除了系统字典后调整VM内存", LogEnum.DevConsole, action: (message) => { _dicById.Remove(message.Source.GetId()); _dicByCode.Remove(message.Source.Code); OnPropertyChangeds(); }); Init(); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
public static Guid GetBrandId(string fileFullName, string keyword) { #if DEBUG Stopwatch.Restart(); #endif Guid guid = Guid.Empty; int LEN = keyword.Length; if (fileFullName == AppFileFullName) { Assembly assembly = Assembly.GetEntryAssembly(); string name = $"NTMiner.Brand.{keyword}"; using (var stream = assembly.GetManifestResourceStream(name)) { if (stream == null) { return(guid); } byte[] data = new byte[stream.Length]; stream.Read(data, 0, data.Length); string rawBrand = Encoding.UTF8.GetString(data); string guidString = rawBrand.Substring(LEN, rawBrand.Length - 2 * LEN); Guid.TryParse(guidString, out guid); } } else { string rawBrand = $"{keyword}{Guid.Empty}{keyword}"; byte[] rawData = Encoding.UTF8.GetBytes(rawBrand); int len = rawData.Length; byte[] source = File.ReadAllBytes(fileFullName); int index = 0; for (int i = 0; i < source.Length - len; i++) { int j = 0; for (; j < len; j++) { if ((j < LEN || j > len - LEN) && source[i + j] != rawData[j]) { break; } } if (j == rawData.Length) { index = i; break; } } string guidString = Encoding.UTF8.GetString(source, index + LEN, len - 2 * LEN); Guid.TryParse(guidString, out guid); } #if DEBUG Write.DevWarn($"耗时{Stopwatch.ElapsedMilliseconds}毫秒 {typeof(VirtualRoot).Name}.GetBrandId"); #endif return(guid); }
private KernelOutputFilterViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif On <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById.Clear(); _dicByKernelOutputId.Clear(); Init(); }); On <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)); } } }); On <KernelOutputFilterUpdatedEvent>("更新了内核输出过滤器后刷新VM内存", LogEnum.DevConsole, action: message => { if (_dicById.TryGetValue(message.Source.GetId(), out KernelOutputFilterViewModel vm)) { vm.Update(message.Source); } }); On <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.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private GroupViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif this.Add = new DelegateCommand(() => { new GroupViewModel(Guid.NewGuid()) { SortNumber = Count + 1 }.Edit.Execute(FormType.Add); }); On <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById.Clear(); Init(); }); On <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChangeds(); }); On <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(); } }); On <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)); } } }); On <GroupRemovedEvent>("删除了组后调整VM内存", LogEnum.DevConsole, action: (message) => { _dicById.Remove(message.Source.GetId()); OnPropertyChangeds(); }); Init(); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private StartStopMineButtonViewModel() { if (Design.IsInDesignMode) { return; } #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif this.StartMine = new DelegateCommand(() => { this.MinerProfile.IsMining = true; NTMinerRoot.Instance.StartMine(); BtnStopText = "正在挖矿"; }); this.StopMine = new DelegateCommand(() => { if (!NTMinerRoot.Instance.IsMining) { this.MinerProfile.IsMining = false; } NTMinerRoot.IsAutoStartCanceled = true; NTMinerRoot.Instance.StopMineAsync(() => { if (!NTMinerRoot.Instance.IsMining) { this.MinerProfile.IsMining = false; } }); }); if (NTMinerRoot.IsAutoStart && !this.MinerProfile.IsMining && VirtualRoot.SecondCount < MinerProfile.AutoStartDelaySeconds) { this.MinerProfile.IsMining = true; int n = MinerProfile.AutoStartDelaySeconds; Bus.IDelegateHandler handler = null; handler = On <Per1SecondEvent>("挖矿倒计时", LogEnum.None, action: message => { BtnStopText = $"倒计时({--n})"; if (n <= 0) { BtnStopText = "正在挖矿"; VirtualRoot.UnPath(handler); if (!NTMinerRoot.IsAutoStartCanceled) { NTMinerRoot.Instance.StartMine(); } } }); } #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private PoolViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif On <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById.Clear(); Init(); }); On <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(AllPools)); }); On <PoolAddedEvent>("添加矿池后刷新VM内存", LogEnum.DevConsole, action: (message) => { _dicById.Add(message.Source.GetId(), new PoolViewModel(message.Source)); OnPropertyChanged(nameof(AllPools)); CoinViewModel coinVm; if (AppContext.Instance.CoinVms.TryGetCoinVm((Guid)message.Source.CoinId, out 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)); } }); On <PoolRemovedEvent>("删除矿池后刷新VM内存", LogEnum.DevConsole, action: (message) => { _dicById.Remove(message.Source.GetId()); OnPropertyChanged(nameof(AllPools)); CoinViewModel coinVm; if (AppContext.Instance.CoinVms.TryGetCoinVm(message.Source.CoinId, out coinVm)) { coinVm.CoinProfile.OnPropertyChanged(nameof(CoinProfileViewModel.MainCoinPool)); coinVm.CoinProfile.OnPropertyChanged(nameof(CoinProfileViewModel.DualCoinPool)); coinVm.OnPropertyChanged(nameof(CoinViewModel.Pools)); coinVm.OnPropertyChanged(nameof(CoinViewModel.OptionPools)); } }); On <PoolUpdatedEvent>("更新矿池后刷新VM内存", LogEnum.DevConsole, action: (message) => { _dicById[message.Source.GetId()].Update(message.Source); }); Init(); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private DriveSetViewModel() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif foreach (var item in DriveInfo.GetDrives().Where(a => a.DriveType == DriveType.Fixed)) { _drives.Add(new DriveViewModel(item)); } this.Apply = new DelegateCommand(() => { AppContext.Instance.VirtualMemorySetVm.SetVirtualMemoryOfDrive(); }); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
protected override void OnMessage(MessageEventArgs e) { if (string.IsNullOrEmpty(e.Data)) { return; } if (e.Data[0] != '{' || e.Data[e.Data.Length - 1] != '}') { base.Send(e.Data); } else { JsonRequest request = VirtualRoot.JsonSerializer.Deserialize <JsonRequest>(e.Data); if (request == null) { return; } switch (request.action) { case "getSpeed": Dictionary <string, object> data = request.Parse(); string messageId = string.Empty; if (data != null) { messageId = data["messageId"]?.ToString(); } base.Send(new JsonResponse { messageId = messageId, code = 200, phrase = "Ok", des = "成功", res = "getSpeed", data = new Dictionary <string, object> { { "str", "hello" }, { "num", 111 }, { "date", DateTime.Now } } }.ToJson()); break; default: base.Send(e.Data); break; } } Write.DevWarn("ConnCount " + Sessions.Count); }
private MineWorkViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif if (Design.IsInDesignMode) { return; } foreach (var item in NTMinerRoot.Instance.MineWorkSet) { _dicById.Add(item.GetId(), new MineWorkViewModel(item)); } this.Add = new DelegateCommand(() => { new MineWorkViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add); }); On <MineWorkAddedEvent>("添加作业后刷新VM内存", LogEnum.DevConsole, action: message => { if (!_dicById.ContainsKey(message.Source.GetId())) { _dicById.Add(message.Source.GetId(), new MineWorkViewModel(message.Source)); OnPropertyChanged(nameof(List)); OnPropertyChanged(nameof(MineWorkVmItems)); if (message.Source.GetId() == AppContext.Instance.MinerClientsWindowVm.SelectedMineWork.GetId()) { AppContext.Instance.MinerClientsWindowVm.SelectedMineWork = MineWorkViewModel.PleaseSelect; } } }); On <MineWorkUpdatedEvent>("更新作业后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById[message.Source.GetId()].Update(message.Source); }); On <MineWorkRemovedEvent>("删除作业后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById.Remove(message.Source.GetId()); OnPropertyChanged(nameof(List)); OnPropertyChanged(nameof(MineWorkVmItems)); if (message.Source.GetId() == AppContext.Instance.MinerClientsWindowVm.SelectedMineWork.GetId()) { AppContext.Instance.MinerClientsWindowVm.SelectedMineWork = MineWorkViewModel.PleaseSelect; } }); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private PackageViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif VirtualRoot.On <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById.Clear(); Init(); }); VirtualRoot.On <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChanged(nameof(AllPackages)); }); On <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)); } }); On <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)); } }); On <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 Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private KernelOutputViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif VirtualRoot.On <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById.Clear(); Init(); }); VirtualRoot.On <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { AllPropertyChanged(); }); On <KernelOutputAddedEvent>("添加了内核输出组后刷新VM内存", LogEnum.DevConsole, action: message => { var vm = new KernelOutputViewModel(message.Source); _dicById.Add(message.Source.GetId(), vm); OnPropertyChanged(nameof(AllKernelOutputVms)); OnPropertyChanged(nameof(PleaseSelectVms)); }); On <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); } } }); On <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 Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private ShareViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif On <ShareChangedEvent>("收益变更后调整VM内存", LogEnum.DevConsole, action: message => { ShareViewModel shareVm; if (_dicByCoinId.TryGetValue(message.Source.CoinId, out shareVm)) { shareVm.Update(message.Source); } }); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private UserViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif if (Design.IsInDesignMode) { return; } this.Add = new DelegateCommand(() => { if (!VirtualRoot.IsMinerStudio) { return; } new UserViewModel().Edit.Execute(FormType.Add); }); On <UserAddedEvent>("添加了用户后", LogEnum.DevConsole, action: message => { if (!_dicByLoginName.ContainsKey(message.Source.LoginName)) { _dicByLoginName.Add(message.Source.LoginName, new UserViewModel(message.Source)); OnPropertyChanged(nameof(List)); } }); On <UserUpdatedEvent>("更新了用户后", LogEnum.DevConsole, action: message => { UserViewModel vm; if (_dicByLoginName.TryGetValue(message.Source.LoginName, out vm)) { vm.Update(message.Source); } }); On <UserRemovedEvent>("移除了用户后", LogEnum.DevConsole, action: message => { _dicByLoginName.Remove(message.Source.LoginName); OnPropertyChanged(nameof(List)); }); foreach (var item in NTMinerRoot.Instance.UserSet) { _dicByLoginName.Add(item.LoginName, new UserViewModel(item)); } #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private OverClockDataViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif if (Design.IsInDesignMode) { return; } Init(refresh: false); On <OverClockDataSetInitedEvent>("超频建议集初始化后", LogEnum.DevConsole, action: message => { Init(refresh: true); }); On <OverClockDataAddedEvent>("添加超频建议后刷新VM内存", LogEnum.DevConsole, action: message => { if (!_dicById.ContainsKey(message.Source.GetId())) { _dicById.Add(message.Source.GetId(), new OverClockDataViewModel(message.Source)); OnPropertyChanged(nameof(List)); CoinViewModel coinVm; if (AppContext.Instance.CoinVms.TryGetCoinVm(message.Source.CoinId, out coinVm)) { coinVm.OnPropertyChanged(nameof(coinVm.OverClockDatas)); } } }); On <OverClockDataUpdatedEvent>("更新超频建议后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById[message.Source.GetId()].Update(message.Source); }); On <OverClockDataRemovedEvent>("删除超频建议后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById.Remove(message.Source.GetId()); OnPropertyChanged(nameof(List)); CoinViewModel coinVm; if (AppContext.Instance.CoinVms.TryGetCoinVm(message.Source.CoinId, out coinVm)) { coinVm.OnPropertyChanged(nameof(coinVm.OverClockDatas)); } }); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private WalletViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif VirtualRoot.On <LocalContextReInitedEvent>("LocalContext刷新后刷新钱包Vm内存", LogEnum.None, action: message => { _dicById.Clear(); Init(); }); On <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)); } }); On <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)); } }); On <WalletUpdatedEvent>("更新了钱包后调整VM内存", LogEnum.DevConsole, action: (message) => { _dicById[message.Source.GetId()].Update(message.Source); }); Init(); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private FragmentWriterViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif this.Add = new DelegateCommand(() => { new FragmentWriterViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add); }); VirtualRoot.On <ServerContextReInitedEvent>("ServerContext刷新后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById.Clear(); Init(); }); VirtualRoot.On <ServerContextVmsReInitedEvent>("ServerContext的VM集刷新后刷新视图界面", LogEnum.DevConsole, action: message => { OnPropertyChangeds(); }); On <FragmentWriterAddedEvent>("添加了命令行片段书写器后调整VM内存", LogEnum.DevConsole, action: (message) => { if (!_dicById.ContainsKey(message.Source.GetId())) { FragmentWriterViewModel groupVm = new FragmentWriterViewModel(message.Source); _dicById.Add(message.Source.GetId(), groupVm); OnPropertyChangeds(); } }); On <FragmentWriterUpdatedEvent>("更新了命令行片段书写器后调整VM内存", LogEnum.DevConsole, action: (message) => { if (_dicById.ContainsKey(message.Source.GetId())) { FragmentWriterViewModel entity = _dicById[message.Source.GetId()]; entity.Update(message.Source); } }); On <FragmentWriterRemovedEvent>("删除了命令行片段书写器后调整VM内存", LogEnum.DevConsole, action: (message) => { _dicById.Remove(message.Source.GetId()); OnPropertyChangeds(); }); Init(); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private PoolKernelViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif On <PoolKernelAddedEvent>("新添了矿池内核后刷新矿池内核VM内存", LogEnum.DevConsole, action: (message) => { if (!_dicById.ContainsKey(message.Source.GetId())) { PoolViewModel poolVm; if (AppContext.Instance.PoolVms.TryGetPoolVm(message.Source.PoolId, out poolVm)) { _dicById.Add(message.Source.GetId(), new PoolKernelViewModel(message.Source)); poolVm.OnPropertyChanged(nameof(poolVm.PoolKernels)); } } }); On <PoolKernelRemovedEvent>("移除了币种内核后刷新矿池内核VM内存", LogEnum.DevConsole, action: (message) => { if (_dicById.ContainsKey(message.Source.GetId())) { var vm = _dicById[message.Source.GetId()]; _dicById.Remove(message.Source.GetId()); PoolViewModel poolVm; if (AppContext.Instance.PoolVms.TryGetPoolVm(vm.PoolId, out poolVm)) { poolVm.OnPropertyChanged(nameof(poolVm.PoolKernels)); } } }); On <PoolKernelUpdatedEvent>("更新了矿池内核后刷新VM内存", LogEnum.DevConsole, action: (message) => { if (_dicById.ContainsKey(message.Source.GetId())) { _dicById[message.Source.GetId()].Update(message.Source); } }); Init(); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private PoolProfileViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif On <PoolProfilePropertyChangedEvent>("矿池设置变更后刷新VM内存", LogEnum.DevConsole, action: message => { if (_dicById.TryGetValue(message.PoolId, out PoolProfileViewModel vm)) { vm.OnPropertyChanged(message.PropertyName); } }); VirtualRoot.On <LocalContextReInitedEvent>("MinerProfile刷新后刷新VM内存", LogEnum.DevConsole, action: message => { _dicById.Clear(); }); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
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); }
private ColumnsShowViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif this.Add = new DelegateCommand(() => { new ColumnsShowViewModel(Guid.NewGuid()).Edit.Execute(FormType.Add); }); On <ColumnsShowAddedEvent>("添加了列显后刷新VM内存", LogEnum.DevConsole, action: message => { if (!_dicById.ContainsKey(message.Source.GetId())) { ColumnsShowViewModel vm = new ColumnsShowViewModel(message.Source); _dicById.Add(message.Source.GetId(), vm); OnPropertyChanged(nameof(List)); AppContext.Instance.MinerClientsWindowVm.ColumnsShow = vm; } }); On <ColumnsShowUpdatedEvent>("更新了列显后刷新VM内存", LogEnum.DevConsole, action: message => { if (_dicById.ContainsKey(message.Source.GetId())) { ColumnsShowViewModel entity = _dicById[message.Source.GetId()]; entity.Update(message.Source); } }); On <ColumnsShowRemovedEvent>("移除了列显后刷新VM内存", LogEnum.DevConsole, action: message => { AppContext.Instance.MinerClientsWindowVm.ColumnsShow = _dicById.Values.FirstOrDefault(); _dicById.Remove(message.Source.GetId()); OnPropertyChanged(nameof(List)); }); foreach (var item in NTMinerRoot.Instance.ColumnsShowSet) { _dicById.Add(item.GetId(), new ColumnsShowViewModel(item)); } #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
private CoinSnapshotDataViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif foreach (var coinVm in AppContext.Instance.CoinVms.AllCoins) { _dicByCoinCode.Add(coinVm.Code, new CoinSnapshotDataViewModel(new MinerServer.CoinSnapshotData { CoinCode = coinVm.Code, MainCoinMiningCount = 0, MainCoinOnlineCount = 0, DualCoinMiningCount = 0, DualCoinOnlineCount = 0, ShareDelta = 0, RejectShareDelta = 0, Speed = 0, Timestamp = DateTime.MinValue })); } #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
protected override void OnMessage(MessageEventArgs e) { if (string.IsNullOrEmpty(e.Data) || e.Data[0] != '{' || e.Data[e.Data.Length - 1] != '}') { return; } WsMessage message = VirtualRoot.JsonSerializer.Deserialize <WsMessage>(e.Data); if (message == null) { return; } switch (message.GetType()) { case WsMessageType.Speed: Write.DevDebug(e.Data); break; default: base.Send(new WsMessage().SetType(message.GetType()).SetCode(400).SetDes("invalid action").SetPhrase("invalid action").ToJson()); break; } Write.DevWarn("Sessions Count: " + base.Sessions.Count); }
private GpuViewModels() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif if (Design.IsInDesignMode) { return; } foreach (var gpu in NTMinerRoot.Instance.GpuSet) { _gpuVms.Add(gpu.Index, new GpuViewModel(gpu)); } if (_gpuVms.ContainsKey(NTMinerRoot.GpuAllId)) { _gpuAllVm = _gpuVms[NTMinerRoot.GpuAllId]; } else { _gpuAllVm = new GpuViewModel(Gpu.GpuAll); } On <EPriceChangedEvent>("电价变更后更新电费显示", LogEnum.DevConsole, action: message => { foreach (var gpuVm in _gpuVms.Values) { gpuVm.OnPropertyChanged(nameof(GpuViewModel.EChargeText)); } AppContext.Instance.GpuSpeedVms.OnPropertyChanged(nameof(GpuSpeedViewModels.ProfitCnyPerDayText)); }); On <PowerAppendChangedEvent>("功耗补偿变更后更新功耗显示", LogEnum.DevConsole, action: message => { foreach (var gpuVm in _gpuVms.Values) { gpuVm.OnPropertyChanged(nameof(GpuViewModel.PowerUsageWText)); } AppContext.Instance.GpuSpeedVms.OnPropertyChanged(nameof(GpuSpeedViewModels.ProfitCnyPerDayText)); }); On <Per5SecondEvent>("周期刷新显卡状态", LogEnum.None, action: message => { // 因为遇到显卡系统状态变更时可能费时 Task.Factory.StartNew(() => { NTMinerRoot.Instance.GpuSet.LoadGpuState(); }); }); On <GpuStateChangedEvent>("显卡状态变更后刷新VM内存", LogEnum.None, action: message => { if (_gpuVms.ContainsKey(message.Source.Index)) { GpuViewModel vm = _gpuVms[message.Source.Index]; vm.Temperature = message.Source.Temperature; vm.FanSpeed = message.Source.FanSpeed; vm.PowerUsage = message.Source.PowerUsage; vm.CoreClockDelta = message.Source.CoreClockDelta; vm.MemoryClockDelta = message.Source.MemoryClockDelta; vm.CoreClockDeltaMin = message.Source.CoreClockDeltaMin; vm.CoreClockDeltaMax = message.Source.CoreClockDeltaMax; vm.MemoryClockDeltaMin = message.Source.MemoryClockDeltaMin; vm.MemoryClockDeltaMax = message.Source.MemoryClockDeltaMax; vm.Cool = message.Source.Cool; vm.CoolMin = message.Source.CoolMin; vm.CoolMax = message.Source.CoolMax; vm.PowerCapacity = message.Source.PowerCapacity; vm.PowerMin = message.Source.PowerMin; vm.PowerMax = message.Source.PowerMax; vm.TempLimit = message.Source.TempLimit; vm.TempLimitDefault = message.Source.TempLimitDefault; vm.TempLimitMax = message.Source.TempLimitMax; vm.TempLimitMin = message.Source.TempLimitMin; if (_gpuAllVm != null) { _gpuAllVm.OnPropertyChanged(nameof(_gpuAllVm.TemperatureText)); _gpuAllVm.OnPropertyChanged(nameof(_gpuAllVm.TemperatureSumText)); _gpuAllVm.OnPropertyChanged(nameof(_gpuAllVm.FanSpeedText)); _gpuAllVm.OnPropertyChanged(nameof(_gpuAllVm.PowerUsageWText)); _gpuAllVm.OnPropertyChanged(nameof(_gpuAllVm.CoreClockDeltaMText)); _gpuAllVm.OnPropertyChanged(nameof(_gpuAllVm.MemoryClockDeltaMText)); _gpuAllVm.OnPropertyChanged(nameof(_gpuAllVm.CoreClockDeltaMinMaxMText)); _gpuAllVm.OnPropertyChanged(nameof(_gpuAllVm.MemoryClockDeltaMinMaxMText)); _gpuAllVm.OnPropertyChanged(nameof(_gpuAllVm.CoolMinMaxText)); _gpuAllVm.OnPropertyChanged(nameof(_gpuAllVm.PowerMinMaxText)); _gpuAllVm.OnPropertyChanged(nameof(_gpuAllVm.TempLimitMinMaxText)); _gpuAllVm.OnPropertyChanged(nameof(_gpuAllVm.EChargeText)); AppContext.Instance.GpuSpeedVms.OnPropertyChanged(nameof(GpuSpeedViewModels.ProfitCnyPerDayText)); } UpdateMinMax(); } }); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
public static void CreateProcessAsync(IMineContext mineContext) { Task.Factory.StartNew(() => { lock (_locker) { try { Write.UserInfo("清理内核进程"); #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif // 清理除当前外的Temp/Kernel Cleaner.Clear(); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {nameof(MinerProcess)}.{nameof(CreateProcessAsync)}[{nameof(Cleaner)}.{nameof(Cleaner.Clear)}]"); #endif Write.UserOk("内核进程清理完毕"); Thread.Sleep(1000); Write.UserInfo($"解压内核包{mineContext.Kernel.Package}"); // 解压内核包 if (!mineContext.Kernel.ExtractPackage()) { VirtualRoot.Happened(new StartingMineFailedEvent("内核解压失败,请卸载内核重试。")); } else { Write.UserOk("内核包解压成功"); } // 执行文件书写器 mineContext.ExecuteFileWriters(); Write.UserInfo("总成命令"); // 组装命令 BuildCmdLine(mineContext, out string kernelExeFileFullName, out string arguments); bool isLogFile = arguments.Contains("{logfile}"); // 这是不应该发生的,如果发生很可能是填写命令的时候拼写错误了 if (!File.Exists(kernelExeFileFullName)) { Write.UserError(kernelExeFileFullName + "文件不存在,可能是小编拼写错误导致,请QQ群联系小编。"); } if (isLogFile) { Logger.InfoDebugLine("创建日志文件型进程"); // 如果内核支持日志文件 // 推迟打印cmdLine,因为{logfile}变量尚未求值 CreateLogfileProcess(mineContext, kernelExeFileFullName, arguments); } else { Logger.InfoDebugLine("创建管道型进程"); // 如果内核不支持日志文件 CreatePipProcess(mineContext, kernelExeFileFullName, arguments); } VirtualRoot.Happened(new MineStartedEvent(mineContext)); } catch (Exception e) { Logger.ErrorDebugLine(e); Write.UserFail("挖矿内核启动失败,请联系开发人员解决"); } } }); }