コード例 #1
0
 public void SetPoolProfileProperty(Guid workId, Guid poolId, string propertyName, object value)
 {
     if (!PoolProfileProperties.ContainsKey(propertyName))
     {
         return;
     }
     using (var database = CreateDatabase(workId)) {
         var  col   = database.GetCollection <PoolProfileData>();
         var  data  = col.FindById(poolId);
         bool exist = true;
         if (data == null)
         {
             exist = false;
             data  = PoolProfileData.CreateDefaultData(poolId);
         }
         PropertyInfo propertyInfo = PoolProfileProperties[propertyName];
         if (propertyInfo.PropertyType == typeof(Guid))
         {
             value = DictionaryExtensions.ConvertToGuid(value);
         }
         propertyInfo.SetValue(data, value, null);
         if (exist)
         {
             col.Update(data);
         }
         else
         {
             col.Insert(data);
         }
     }
 }
コード例 #2
0
ファイル: LocalJsonDb.cs プロジェクト: UcAspNet/ntminer
        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();
        }
コード例 #3
0
 private PoolProfile(INTMinerRoot root, IPool pool)
 {
     _root = root;
     _data = GetPoolProfileData(pool.GetId());
     if (_data == null)
     {
         throw new ValidationException("未获取到PoolProfileData数据,请重试");
     }
 }
コード例 #4
0
        public void ObjectJsonSerializerTest()
        {
            PoolProfileData data = new PoolProfileData {
                Password = "******",
                PoolId   = Guid.NewGuid(),
                UserName = "******"
            };

            Console.WriteLine(new ObjectJsonSerializer().Serialize(data));
        }
コード例 #5
0
 public PoolProfileData GetPoolProfile(Guid workId, Guid poolId)
 {
     using (var database = CreateDatabase(workId)) {
         var col  = database.GetCollection <PoolProfileData>();
         var data = col.FindById(poolId);
         if (data == null)
         {
             data = PoolProfileData.CreateDefaultData(poolId);
             col.Insert(data);
         }
         return(data);
     }
 }
コード例 #6
0
                private static PoolProfileData GetPoolProfileData(INTMinerContext root, Guid poolId)
                {
                    var repository = root.ServerContext.CreateLocalRepository <PoolProfileData>();
                    var result     = repository.GetByKey(poolId);

                    if (result == null)
                    {
                        if (root.ServerContext.PoolSet.TryGetPool(poolId, out IPool pool))
                        {
                            // 如果本地未设置用户名密码则使用默认的测试用户名密码
                            result = PoolProfileData.CreateDefaultData(pool);
                        }
                    }
                    return(result);
                }
コード例 #7
0
                private static PoolProfileData GetPoolProfileData(INTMinerRoot root, MineWorkData mineWorkData, Guid poolId)
                {
                    bool isUseJson = mineWorkData != null;
                    IRepository <PoolProfileData> repository = NTMinerRoot.CreateLocalRepository <PoolProfileData>(isUseJson);
                    var result = repository.GetByKey(poolId);

                    if (result == null)
                    {
                        if (root.PoolSet.TryGetPool(poolId, out IPool pool))
                        {
                            // 如果本地未设置用户名密码则使用默认的测试用户名密码
                            result = PoolProfileData.CreateDefaultData(pool);
                        }
                    }
                    return(result);
                }
コード例 #8
0
                public static PoolProfile Create(INTMinerRoot root, MineWorkData mineWorkData, Guid poolIdId)
                {
                    if (root.PoolSet.TryGetPool(poolIdId, out IPool pool))
                    {
                        var data = GetPoolProfileData(root, mineWorkData, pool.GetId());
                        if (data == null)
                        {
                            data = PoolProfileData.CreateDefaultData(pool);
                        }
                        PoolProfile coinProfile = new PoolProfile(mineWorkData, data);

                        return(coinProfile);
                    }
                    else
                    {
                        return(Empty);
                    }
                }
コード例 #9
0
                public static PoolProfile Create(INTMinerContext ntminerContext, Guid poolIdId)
                {
                    if (ntminerContext.ServerContext.PoolSet.TryGetPool(poolIdId, out IPool pool))
                    {
                        var data = GetPoolProfileData(ntminerContext, pool.GetId());
                        if (data == null)
                        {
                            data = PoolProfileData.CreateDefaultData(pool);
                        }
                        PoolProfile coinProfile = new PoolProfile(data);

                        return(coinProfile);
                    }
                    else
                    {
                        return(Empty);
                    }
                }
コード例 #10
0
 private PoolProfileData GetPoolProfileData(Guid poolId)
 {
     if (CommandLineArgs.IsWorker)
     {
         return(Server.ProfileService.GetPoolProfile(CommandLineArgs.WorkId, poolId));
     }
     else
     {
         IRepository <PoolProfileData> repository = NTMinerRoot.CreateLocalRepository <PoolProfileData>();
         var result = repository.GetByKey(poolId);
         if (result == null)
         {
             string userName = string.Empty;
             string password = string.Empty;
             if (_root.PoolSet.TryGetPool(poolId, out IPool pool))
             {
                 userName = pool.UserName;
                 password = pool.Password;
             }
             result = PoolProfileData.CreateDefaultData(poolId);
         }
         return(result);
     }
 }
コード例 #11
0
 private PoolProfile(MineWorkData mineWorkData, PoolProfileData data)
 {
     _mineWorkData = mineWorkData;
     _data         = data ?? throw new ArgumentNullException(nameof(data));
 }
コード例 #12
0
 private PoolProfile(PoolProfileData data)
 {
     _data = data ?? throw new ArgumentNullException(nameof(data));
 }
コード例 #13
0
 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);
     }
 }