示例#1
0
        public static int[] GetUseDevices(this IGpuSet gpuSet)
        {
            List <int> list = new List <int>();

            if (VirtualRoot.LocalAppSettingSet.TryGetAppSetting(NTKeyword.UseDevicesAppSettingKey, out IAppSetting setting) && setting.Value != null)
            {
                string[] parts = setting.Value.ToString().Split(',');
                foreach (var part in parts)
                {
                    if (int.TryParse(part, out int index))
                    {
                        list.Add(index);
                    }
                }
            }
            // 全不选等于全选
            if (list.Count == 0)
            {
                foreach (var gpu in gpuSet.AsEnumerable())
                {
                    if (gpu.Index == NTMinerContext.GpuAllId)
                    {
                        continue;
                    }
                    list.Add(gpu.Index);
                }
            }
            return(list.ToArray());
        }
示例#2
0
        public static List <int> GetUseDevices(this IGpuSet gpuSet)
        {
            List <int> list = new List <int>();

            if (NTMinerRoot.Instance.LocalAppSettingSet.TryGetAppSetting("UseDevices", out IAppSetting setting) && setting.Value != null)
            {
                string[] parts = setting.Value.ToString().Split(',');
                foreach (var part in parts)
                {
                    if (int.TryParse(part, out int index))
                    {
                        list.Add(index);
                    }
                }
            }
            if (list.Count == 0)
            {
                foreach (var gpu in gpuSet)
                {
                    if (gpu.Index == NTMinerRoot.GpuAllId)
                    {
                        continue;
                    }
                    list.Add(gpu.Index);
                }
            }
            return(list);
        }
示例#3
0
 public static bool GetIsUseDevice(this IGpuSet gpuSet, int gpuIndex)
 {
     if (gpuIndex < 0 || gpuIndex >= gpuSet.Count)
     {
         return(false);
     }
     int[] devices = GetUseDevices(gpuSet);
     return(devices.Contains(gpuIndex));
 }
示例#4
0
 public static bool Has20NCard(this IGpuSet gpuSet)
 {
     if (gpuSet.GpuType == GpuType.NVIDIA)
     {
         if (gpuSet.Any(a => Is20NCard(a.Name)))
         {
             return(true);
         }
     }
     return(false);
 }
示例#5
0
        private static void SetUseDevices(IGpuSet gpuSet, List <int> gpuIndexes)
        {
            if (gpuIndexes.Count != 0 && gpuIndexes.Count == gpuSet.Count)
            {
                gpuIndexes = new List <int>();
            }
            AppSettingData appSettingData = new AppSettingData()
            {
                Key   = "UseDevices",
                Value = string.Join(",", gpuIndexes)// 存逗号分隔的字符串,因为litedb处理List、Array有问题
            };

            VirtualRoot.Execute(new ChangeLocalAppSettingCommand(appSettingData));
        }
示例#6
0
        private static void SetUseDevices(IGpuSet gpuSet, List <int> gpuIndexes)
        {
            // 全选等于全不选,所以存储空值就可以了,而且可以避免新插显卡问题
            if (gpuIndexes.Count != 0 && gpuIndexes.Count == gpuSet.Count)
            {
                gpuIndexes = new List <int>();
            }
            AppSettingData appSettingData = new AppSettingData()
            {
                Key   = NTKeyword.UseDevicesAppSettingKey,
                Value = string.Join(",", gpuIndexes)// 存逗号分隔的字符串,因为litedb处理List、Array有问题
            };

            VirtualRoot.Execute(new SetLocalAppSettingCommand(appSettingData));
        }
示例#7
0
        public static void SetIsUseDevice(this IGpuSet gpuSet, int gpuIndex, bool isUse)
        {
            List <int> devices = GetUseDevices(gpuSet).ToList();

            if (!isUse)
            {
                devices.Remove(gpuIndex);
            }
            else if (!devices.Contains(gpuIndex))
            {
                devices.Add(gpuIndex);
            }
            devices = devices.OrderBy(a => a).ToList();
            SetUseDevices(gpuSet, devices);
        }