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 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); } }