예제 #1
0
        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();
        }
예제 #2
0
 public void SetCoinKernelProfileProperty(Guid workId, Guid coinKernelId, string propertyName, object value)
 {
     if (!CoinKernelProfileProperties.ContainsKey(propertyName))
     {
         return;
     }
     using (var database = CreateDatabase(workId)) {
         var  col   = database.GetCollection <CoinKernelProfileData>();
         var  data  = col.FindById(coinKernelId);
         bool exist = true;
         if (data == null)
         {
             exist = false;
             data  = CoinKernelProfileData.CreateDefaultData(coinKernelId);
         }
         PropertyInfo propertyInfo = CoinKernelProfileProperties[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);
         }
     }
 }
예제 #3
0
                public static CoinKernelProfile Create(INTMinerRoot root, Guid coinKernelId)
                {
                    if (root.CoinKernelSet.TryGetCoinKernel(coinKernelId, out ICoinKernel coinKernel))
                    {
                        var data = GetCoinKernelProfileData(coinKernel.GetId());
                        if (data == null)
                        {
                            data = CoinKernelProfileData.CreateDefaultData(coinKernel.GetId());
                        }
                        CoinKernelProfile coinProfile = new CoinKernelProfile(data);

                        var    defaultInputSegments = coinKernel.InputSegments.Where(a => a.IsDefault && a.TargetGpu.IsSupportedGpu(NTMinerRoot.Instance.GpuSet.GpuType)).ToArray();
                        string touchedArgs          = coinProfile.TouchedArgs;
                        if (coinProfile.CustomArgs == null)
                        {
                            coinProfile.CustomArgs = string.Empty;
                        }
                        if (string.IsNullOrEmpty(touchedArgs))
                        {
                            foreach (var defaultInputSegment in defaultInputSegments)
                            {
                                if (!coinProfile.CustomArgs.Contains(defaultInputSegment.Segment))
                                {
                                    if (coinProfile.CustomArgs.Length == 0)
                                    {
                                        coinProfile.CustomArgs += defaultInputSegment.Segment;
                                    }
                                    else
                                    {
                                        coinProfile.CustomArgs += " " + defaultInputSegment.Segment;
                                    }
                                }
                            }
                        }
                        else
                        {
                            foreach (var defaultInputSegment in defaultInputSegments)
                            {
                                if (!touchedArgs.Contains(defaultInputSegment.Segment) && !coinProfile.CustomArgs.Contains(defaultInputSegment.Segment))
                                {
                                    if (coinProfile.CustomArgs.Length == 0)
                                    {
                                        coinProfile.CustomArgs += defaultInputSegment.Segment;
                                    }
                                    else
                                    {
                                        coinProfile.CustomArgs += " " + defaultInputSegment.Segment;
                                    }
                                }
                            }
                        }
                        return(coinProfile);
                    }
                    else
                    {
                        return(Empty);
                    }
                }
예제 #4
0
 private CoinKernelProfile(INTMinerRoot root, ICoinKernel coinKernel)
 {
     _root = root;
     _data = GetCoinKernelProfileData(coinKernel.GetId());
     if (_data == null)
     {
         throw new ValidationException("未获取到CoinKernelProfileData数据,请重试");
     }
 }
예제 #5
0
                private static CoinKernelProfileData GetCoinKernelProfileData(Guid coinKernelId)
                {
                    IRepository <CoinKernelProfileData> repository = NTMinerRoot.CreateLocalRepository <CoinKernelProfileData>();
                    var result = repository.GetByKey(coinKernelId);

                    if (result == null)
                    {
                        result = CoinKernelProfileData.CreateDefaultData(coinKernelId);
                    }
                    return(result);
                }
예제 #6
0
                private static CoinKernelProfileData GetCoinKernelProfileData(MineWorkData mineWorkData, Guid coinKernelId)
                {
                    bool isUseJson = mineWorkData != null;
                    IRepository <CoinKernelProfileData> repository = NTMinerRoot.CreateLocalRepository <CoinKernelProfileData>(isUseJson);
                    var result = repository.GetByKey(coinKernelId);

                    if (result == null)
                    {
                        result = CoinKernelProfileData.CreateDefaultData(coinKernelId);
                    }
                    return(result);
                }
예제 #7
0
 public CoinKernelProfileData GetCoinKernelProfile(Guid workId, Guid coinKernelId)
 {
     using (var database = CreateDatabase(workId)) {
         var col  = database.GetCollection <CoinKernelProfileData>();
         var data = col.FindById(coinKernelId);
         if (data == null)
         {
             data = CoinKernelProfileData.CreateDefaultData(coinKernelId);
             col.Insert(data);
         }
         return(data);
     }
 }
예제 #8
0
 private CoinKernelProfileData GetCoinKernelProfileData(Guid coinKernelId)
 {
     if (CommandLineArgs.IsWorker)
     {
         return(Server.ProfileService.GetCoinKernelProfile(CommandLineArgs.WorkId, coinKernelId));
     }
     else
     {
         IRepository <CoinKernelProfileData> repository = NTMinerRoot.CreateLocalRepository <CoinKernelProfileData>();
         var result = repository.GetByKey(coinKernelId);
         if (result == null)
         {
             result = CoinKernelProfileData.CreateDefaultData(coinKernelId);
         }
         return(result);
     }
 }
예제 #9
0
                public static CoinKernelProfile Create(INTMinerRoot root, MineWorkData mineWorkData, Guid coinKernelId)
                {
                    if (root.CoinKernelSet.TryGetCoinKernel(coinKernelId, out ICoinKernel coinKernel))
                    {
                        var data = GetCoinKernelProfileData(mineWorkData, coinKernel.GetId());
                        if (data == null)
                        {
                            data = CoinKernelProfileData.CreateDefaultData(coinKernel.GetId());
                        }
                        CoinKernelProfile coinProfile = new CoinKernelProfile(mineWorkData, data);

                        return(coinProfile);
                    }
                    else
                    {
                        return(Empty);
                    }
                }
                public static CoinKernelProfile Create(INTMinerRoot root, Guid coinKernelId)
                {
                    if (root.ServerContext.CoinKernelSet.TryGetCoinKernel(coinKernelId, out ICoinKernel coinKernel))
                    {
                        var repository             = NTMinerRoot.CreateLocalRepository <CoinKernelProfileData>();
                        CoinKernelProfileData data = repository.GetByKey(coinKernelId);
                        if (data == null)
                        {
                            double dualCoinWeight = GetDualCoinWeight(root, coinKernel.KernelId);
                            data = CoinKernelProfileData.CreateDefaultData(coinKernel.GetId(), dualCoinWeight);
                        }
                        if (root.ServerContext.GroupSet.TryGetGroup(coinKernel.DualCoinGroupId, out IGroup group))
                        {
                            var coinIds = root.ServerContext.CoinGroupSet.GetGroupCoinIds(coinKernel.DualCoinGroupId);
                            if (!coinIds.Contains(data.DualCoinId))
                            {
                                data.DualCoinId = coinIds.FirstOrDefault();
                            }
                        }
                        CoinKernelProfile coinProfile = new CoinKernelProfile(data);

                        var    defaultInputSegments = coinKernel.InputSegments.Where(a => a.IsDefault && a.TargetGpu.IsSupportedGpu(NTMinerRoot.Instance.GpuSet.GpuType)).ToArray();
                        string touchedArgs          = coinProfile.TouchedArgs;
                        if (coinProfile.CustomArgs == null)
                        {
                            coinProfile.CustomArgs = string.Empty;
                        }
                        if (string.IsNullOrEmpty(touchedArgs))
                        {
                            foreach (var defaultInputSegment in defaultInputSegments)
                            {
                                if (!coinProfile.CustomArgs.Contains(defaultInputSegment.Segment))
                                {
                                    if (coinProfile.CustomArgs.Length == 0)
                                    {
                                        coinProfile.CustomArgs += defaultInputSegment.Segment;
                                    }
                                    else
                                    {
                                        coinProfile.CustomArgs += " " + defaultInputSegment.Segment;
                                    }
                                }
                            }
                        }
                        else
                        {
                            foreach (var defaultInputSegment in defaultInputSegments)
                            {
                                if (!touchedArgs.Contains(defaultInputSegment.Segment) && !coinProfile.CustomArgs.Contains(defaultInputSegment.Segment))
                                {
                                    if (coinProfile.CustomArgs.Length == 0)
                                    {
                                        coinProfile.CustomArgs += defaultInputSegment.Segment;
                                    }
                                    else
                                    {
                                        coinProfile.CustomArgs += " " + defaultInputSegment.Segment;
                                    }
                                }
                            }
                        }
                        return(coinProfile);
                    }
                    else
                    {
                        return(Empty);
                    }
                }
 private CoinKernelProfile(CoinKernelProfileData data)
 {
     _data = data ?? throw new ArgumentNullException(nameof(data));
 }
예제 #12
0
 private CoinKernelProfile(MineWorkData mineWorkData, CoinKernelProfileData data)
 {
     _mineWorkData = mineWorkData;
     _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);
     }
 }