public static CoinProfile Create(INTMinerRoot root, MineWorkData mineWorkData, Guid coinId) { if (root.CoinSet.TryGetCoin(coinId, out ICoin coin)) { var data = GetCoinProfileData(mineWorkData, coin.GetId()); if (data == null) { Guid poolId = Guid.Empty; IPool pool = root.PoolSet.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.CoinId == coinId); if (pool != null) { poolId = pool.GetId(); } string wallet = coin.TestWallet; Guid coinKernelId = Guid.Empty; ICoinKernel coinKernel = root.CoinKernelSet.OrderBy(a => a.SortNumber).FirstOrDefault(a => a.CoinId == coinId); if (coinKernel != null) { coinKernelId = coinKernel.GetId(); } data = CoinProfileData.CreateDefaultData(coinId, poolId, wallet, coinKernelId); } CoinProfile coinProfile = new CoinProfile(mineWorkData, data); return(coinProfile); } else { return(Empty); } }
public static CoinProfile Create(INTMinerRoot root, Guid coinId) { if (root.ServerContext.CoinSet.TryGetCoin(coinId, out ICoin coin)) { var data = GetCoinProfileData(coin.GetId()); if (data == null) { Guid poolId = Guid.Empty; IPool pool = root.ServerContext.PoolSet.AsEnumerable().OrderBy(a => a.SortNumber).FirstOrDefault(a => a.CoinId == coinId); if (pool != null) { poolId = pool.GetId(); } string wallet = coin.TestWallet; Guid coinKernelId = GetDefaultCoinKernelId(coin); data = CoinProfileData.CreateDefaultData(coinId, poolId, wallet, coinKernelId); } else { if (!root.ServerContext.CoinKernelSet.TryGetCoinKernel(data.CoinKernelId, out ICoinKernel coinKernel)) { data.CoinKernelId = GetDefaultCoinKernelId(coin); } } CoinProfile coinProfile = new CoinProfile(data); return(coinProfile); } else { return(Empty); } }
public void SetCoinProfileProperty(Guid workId, Guid coinId, string propertyName, object value) { if (!CoinProfileProperties.ContainsKey(propertyName)) { return; } using (var database = CreateDatabase(workId)) { var col = database.GetCollection <CoinProfileData>(); var data = col.FindById(coinId); bool exist = true; if (data == null) { exist = false; data = CoinProfileData.CreateDefaultData(coinId); } PropertyInfo propertyInfo = CoinProfileProperties[propertyName]; if (propertyInfo.PropertyType == typeof(Guid)) { value = DictionaryExtensions.ConvertToGuid(value); } propertyInfo.SetValue(data, value, null); if (exist) { data.ModifiedOn = DateTime.Now; col.Update(data); } else { col.Insert(data); } } }
public LocalJsonDb(INTMinerRoot root, MineWorkData mineWorkData) { var minerProfile = root.MinerProfile; CoinProfileData mainCoinProfile = new CoinProfileData(minerProfile.GetCoinProfile(minerProfile.CoinId)); List <CoinProfileData> coinProfiles = new List <CoinProfileData> { mainCoinProfile }; List <PoolProfileData> poolProfiles = new List <PoolProfileData>(); CoinKernelProfileData coinKernelProfile = new CoinKernelProfileData(minerProfile.GetCoinKernelProfile(mainCoinProfile.CoinKernelId)); PoolProfileData mainCoinPoolProfile = new PoolProfileData(minerProfile.GetPoolProfile(mainCoinProfile.PoolId)); poolProfiles.Add(mainCoinPoolProfile); if (mainCoinProfile.PoolId1 != Guid.Empty) { mainCoinPoolProfile = new PoolProfileData(minerProfile.GetPoolProfile(mainCoinProfile.PoolId1)); poolProfiles.Add(mainCoinPoolProfile); } if (coinKernelProfile.IsDualCoinEnabled) { CoinProfileData dualCoinProfile = new CoinProfileData(minerProfile.GetCoinProfile(coinKernelProfile.DualCoinId)); coinProfiles.Add(dualCoinProfile); PoolProfileData dualCoinPoolProfile = new PoolProfileData(minerProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId)); poolProfiles.Add(dualCoinPoolProfile); } MinerProfile = MinerProfileData.Create(minerProfile); MinerProfile.MinerName = "{{MinerName}}"; MineWork = mineWorkData; CoinProfiles = coinProfiles.ToArray(); CoinKernelProfiles = new CoinKernelProfileData[] { coinKernelProfile }; PoolProfiles = poolProfiles.ToArray(); Pools = root.ServerContext.PoolSet.AsEnumerable().Where(a => poolProfiles.Any(b => b.PoolId == a.GetId())).Select(a => new PoolData(a)).ToArray(); Wallets = minerProfile.GetWallets().Select(a => new WalletData(a)).ToArray(); TimeStamp = Timestamp.GetTimestamp(); }
private CoinProfile(INTMinerRoot root, ICoin coin) { _root = root; _data = GetCoinProfileData(coin.GetId()); if (_data == null) { throw new ValidationException("未获取到CoinProfileData数据,请重试"); } }
public CoinProfileData GetCoinProfile(Guid workId, Guid coinId) { using (var database = CreateDatabase(workId)) { var col = database.GetCollection <CoinProfileData>(); var data = col.FindById(coinId); if (data == null) { data = CoinProfileData.CreateDefaultData(coinId); col.Insert(data); } return(data); } }
private CoinProfileData GetCoinProfileData(Guid coinId) { if (CommandLineArgs.IsWorker) { return(Server.ProfileService.GetCoinProfile(CommandLineArgs.WorkId, coinId)); } else { IRepository <CoinProfileData> repository = NTMinerRoot.CreateLocalRepository <CoinProfileData>(); var result = repository.GetByKey(coinId); if (result == null) { result = CoinProfileData.CreateDefaultData(coinId); } return(result); } }
private CoinProfile(MineWorkData mineWorkData, CoinProfileData data) { _mineWorkData = mineWorkData; _data = data ?? throw new ArgumentNullException(nameof(data)); }
private CoinProfile(CoinProfileData data) { _data = data ?? throw new ArgumentNullException(nameof(data)); }
public static void ExportWorkJson(MineWorkData mineWorkData, out string localJson, out string serverJson) { localJson = string.Empty; serverJson = string.Empty; try { var root = Current; var minerProfile = root.MinerProfile; CoinProfileData mainCoinProfile = new CoinProfileData(minerProfile.GetCoinProfile(minerProfile.CoinId)); List <CoinProfileData> coinProfiles = new List <CoinProfileData> { mainCoinProfile }; List <PoolProfileData> poolProfiles = new List <PoolProfileData>(); CoinKernelProfileData coinKernelProfile = new CoinKernelProfileData(minerProfile.GetCoinKernelProfile(mainCoinProfile.CoinKernelId)); PoolProfileData mainCoinPoolProfile = new PoolProfileData(minerProfile.GetPoolProfile(mainCoinProfile.PoolId)); poolProfiles.Add(mainCoinPoolProfile); if (coinKernelProfile.IsDualCoinEnabled) { CoinProfileData dualCoinProfile = new CoinProfileData(minerProfile.GetCoinProfile(coinKernelProfile.DualCoinId)); coinProfiles.Add(dualCoinProfile); PoolProfileData dualCoinPoolProfile = new PoolProfileData(minerProfile.GetPoolProfile(dualCoinProfile.DualCoinPoolId)); poolProfiles.Add(dualCoinPoolProfile); } LocalJsonDb localJsonObj = new LocalJsonDb { MinerProfile = new MinerProfileData(minerProfile) { MinerName = "{{MinerName}}" }, MineWork = mineWorkData, CoinProfiles = coinProfiles.ToArray(), CoinKernelProfiles = new CoinKernelProfileData[] { coinKernelProfile }, PoolProfiles = poolProfiles.ToArray(), TimeStamp = Timestamp.GetTimestamp(), Pools = root.PoolSet.Where(a => poolProfiles.Any(b => b.PoolId == a.GetId())).Select(a => new PoolData(a)).ToArray(), Wallets = minerProfile.GetWallets().Select(a => new WalletData(a)).ToArray() }; localJson = VirtualRoot.JsonSerializer.Serialize(localJsonObj); root.CoinKernelSet.TryGetCoinKernel(coinKernelProfile.CoinKernelId, out ICoinKernel coinKernel); root.KernelSet.TryGetKernel(coinKernel.KernelId, out IKernel kernel); var coins = root.CoinSet.Cast <CoinData>().Where(a => localJsonObj.CoinProfiles.Any(b => b.CoinId == a.Id)).ToArray(); var coinGroups = root.CoinGroupSet.Cast <CoinGroupData>().Where(a => coins.Any(b => b.Id == a.CoinId)).ToArray(); var pools = root.PoolSet.Cast <PoolData>().Where(a => localJsonObj.PoolProfiles.Any(b => b.PoolId == a.Id)).ToArray(); ServerJsonDb serverJsonObj = new ServerJsonDb { Coins = coins, CoinGroups = coinGroups, Pools = pools, TimeStamp = Timestamp.GetTimestamp(), Groups = root.GroupSet.Cast <GroupData>().Where(a => coinGroups.Any(b => b.GroupId == a.Id)).ToArray(), KernelInputs = root.KernelInputSet.Cast <KernelInputData>().Where(a => a.Id == kernel.KernelInputId).ToArray(), KernelOutputs = root.KernelOutputSet.Cast <KernelOutputData>().Where(a => a.Id == kernel.KernelOutputId).ToArray(), KernelOutputFilters = root.KernelOutputFilterSet.Cast <KernelOutputFilterData>().Where(a => a.KernelOutputId == kernel.KernelOutputId).ToArray(), KernelOutputTranslaters = root.KernelOutputTranslaterSet.Cast <KernelOutputTranslaterData>().Where(a => a.KernelOutputId == kernel.KernelOutputId).ToArray(), Kernels = new List <KernelData> { (KernelData)kernel }, CoinKernels = root.CoinKernelSet.Cast <CoinKernelData>().Where(a => localJsonObj.CoinKernelProfiles.Any(b => b.CoinKernelId == a.Id)).ToList(), PoolKernels = root.PoolKernelSet.Cast <PoolKernelData>().Where(a => !string.IsNullOrEmpty(a.Args) && pools.Any(b => b.Id == a.PoolId)).ToList(), SysDicItems = root.SysDicItemSet.Cast <SysDicItemData>().ToArray(), SysDics = root.SysDicSet.Cast <SysDicData>().ToArray() }; serverJson = VirtualRoot.JsonSerializer.Serialize(serverJsonObj); } catch (Exception e) { Logger.ErrorDebugLine(e.Message, e); } }