コード例 #1
0
ファイル: SystemInfo.cs プロジェクト: asm2025/essentialMix
        private static T GetSystemValue <T>([NotNull] string name, T defaultValue = default(T))
        {
            SystemInfoRequest request = new SystemInfoRequest(SystemInfoType.Win32_ComputerSystem)
            {
                Scope = "root\\CIMV2"
            };

            ManagementObject mo = FirstOrDefault(request);

            if (mo == null)
            {
                return(defaultValue);
            }

            object value;

            try
            {
                value = mo[name];
            }
            catch
            {
                value = null;
            }

            return(value.To(defaultValue));
        }
コード例 #2
0
ファイル: SystemInfo.cs プロジェクト: asm2025/essentialMix
        public static IEnumerable <ManagementObject> Get([NotNull] SystemInfoRequest request)
        {
            (ManagementObjectSearcher searcher, ManagementObjectCollection collection) = GetObjects(request);

            try
            {
                return(request.Filter == null
                                        ? collection.OfType <ManagementObject>()
                                        : collection.OfType <ManagementObject>().Where(mo => request.Filter(mo)));
            }
            catch
            {
                ObjectHelper.Dispose(ref collection);
                ObjectHelper.Dispose(ref searcher);
                return(Enumerable.Empty <ManagementObject>());
            }
        }
コード例 #3
0
ファイル: SystemInfo.cs プロジェクト: asm2025/essentialMix
        public static ManagementObject LastOrDefault([NotNull] SystemInfoRequest request)
        {
            (ManagementObjectSearcher searcher, ManagementObjectCollection collection) = GetObjects(request);

            try
            {
                return(request.Filter == null
                                        ? collection.OfType <ManagementObject>().LastOrDefault()
                                        : collection.OfType <ManagementObject>().LastOrDefault(mo => request.Filter(mo)));
            }
            catch
            {
                ObjectHelper.Dispose(ref collection);
                ObjectHelper.Dispose(ref searcher);
                return(null);
            }
        }
コード例 #4
0
ファイル: SystemInfo.cs プロジェクト: asm2025/essentialMix
 public static IEnumerable <T> Get <T>([NotNull] SystemInfoRequest <T> request)
 {
     return(Get((SystemInfoRequest)request).Select(request.Converter));
 }
コード例 #5
0
ファイル: SystemInfo.cs プロジェクト: asm2025/essentialMix
        private static (ManagementObjectSearcher Searcher, ManagementObjectCollection Collection) GetObjects([NotNull] SystemInfoRequest request)
        {
            string search = $"Select {request.SelectExpression} From {request.Type}";

            if (!string.IsNullOrEmpty(request.WhereExpression))
            {
                search += " where " + request.WhereExpression;
            }

            ManagementObjectSearcher   searcher   = null;
            ManagementObjectCollection collection = null;
            ManagementScope            scope      = string.IsNullOrEmpty(request.ScopeRoot)
                                ? null
                                : new ManagementScope(request.ScopeRoot);

            try
            {
                searcher   = new ManagementObjectSearcher(scope, new ObjectQuery(search), request.Options);
                collection = searcher.Get();
            }
            catch
            {
                ObjectHelper.Dispose(ref collection);
                ObjectHelper.Dispose(ref searcher);
            }

            return(searcher, collection);
        }
コード例 #6
0
ファイル: SystemInfo.cs プロジェクト: asm2025/essentialMix
 public static T LastOrDefault <T>([NotNull] SystemInfoRequest <T> request)
 {
     return(request.Converter(LastOrDefault((SystemInfoRequest)request)));
 }
コード例 #7
0
ファイル: SystemInfo.cs プロジェクト: asm2025/essentialMix
 public static T First <T>([NotNull] SystemInfoRequest <T> request)
 {
     return(request.Converter(First((SystemInfoRequest)request)));
 }
コード例 #8
0
ファイル: SystemInfo.cs プロジェクト: asm2025/essentialMix
 public static T Single <T>([NotNull] SystemInfoRequest <T> request)
 {
     return(request.Converter(Single((SystemInfoRequest)request)));
 }