瀏覽代碼

硬件信息

懒得勤快 6 年之前
父節點
當前提交
353d621905

+ 20 - 4
Masuit.Tools.Core/Extensions.cs

@@ -1078,7 +1078,11 @@ namespace Masuit.Tools
         /// <returns>int类型的数字</returns>
         public static int ToInt32(this string s)
         {
-            int.TryParse(s, out int result);
+            bool b = int.TryParse(s, out int result);
+            if (!b)
+            {
+                Console.WriteLine($"未能将字符串【{s}】转换为数字!");
+            }
             return result;
         }
 
@@ -1089,7 +1093,11 @@ namespace Masuit.Tools
         /// <returns>int类型的数字</returns>
         public static long ToInt64(this string s)
         {
-            long.TryParse(s, out var result);
+            bool b = long.TryParse(s, out var result);
+            if (!b)
+            {
+                Console.WriteLine($"未能将字符串【{s}】转换为数字!");
+            }
             return result;
         }
 
@@ -1100,7 +1108,11 @@ namespace Masuit.Tools
         /// <returns>double类型的数据</returns>
         public static double ToDouble(this string s)
         {
-            double.TryParse(s, out var result);
+            bool b = double.TryParse(s, out var result);
+            if (!b)
+            {
+                Console.WriteLine($"未能将字符串【{s}】转换为数字!");
+            }
             return result;
         }
 
@@ -1111,7 +1123,11 @@ namespace Masuit.Tools
         /// <returns>int类型的数字</returns>
         public static decimal ToDecimal(this string s)
         {
-            decimal.TryParse(s, out var result);
+            var b = decimal.TryParse(s, out var result);
+            if (!b)
+            {
+                Console.WriteLine($"未能将字符串【{s}】转换为数字!");
+            }
             return result;
         }
 

+ 18 - 16
Masuit.Tools.Core/Hardware/SystemInfo.cs

@@ -246,15 +246,17 @@ namespace Masuit.Tools.Hardware
         /// 获取内存信息
         /// </summary>
         /// <returns>内存信息</returns>
-        public static RamInfo GetRamInfo() => new RamInfo
+        public static RamInfo GetRamInfo()
         {
-            MemoryAvailable = GetFreePhysicalMemory(),
-            PhysicalMemory = GetTotalPhysicalMemory(),
-            TotalPageFile = GetTotalVirtualMemory(),
-            AvailablePageFile = GetTotalVirtualMemory() - GetUsedVirtualMemory(),
-            AvailableVirtual = 1 - GetUsageVirtualMemory(),
-            TotalVirtual = 1 - GetUsedPhysicalMemory()
-        };
+            var info = new RamInfo();
+            info.MemoryAvailable = GetFreePhysicalMemory();
+            info.PhysicalMemory = GetTotalPhysicalMemory();
+            info.TotalPageFile = GetTotalVirtualMemory();
+            info.AvailablePageFile = GetTotalVirtualMemory() - GetUsedVirtualMemory();
+            info.AvailableVirtual = 1 - GetUsageVirtualMemory();
+            info.TotalVirtual = 1 - GetUsedPhysicalMemory();
+            return info;
+        }
 
         #endregion
 
@@ -375,7 +377,7 @@ namespace Masuit.Tools.Hardware
         public static double GetTotalPhysicalMemory()
         {
             string s = QueryComputerSystem("totalphysicalmemory");
-            return Convert.ToDouble(s);
+            return s.ToDouble();
         }
 
         /// <summary>
@@ -496,7 +498,7 @@ namespace Masuit.Tools.Hardware
             {
                 return new List<string>()
                 {
-                    "未能获取到操作系统版本,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。"
+                    "未能获取到当前计算机的IP地址,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。"
                 };
             }
         }
@@ -524,7 +526,7 @@ namespace Masuit.Tools.Hardware
             }
             catch (Exception)
             {
-                return "未能获取到操作系统版本,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。";
+                return "未能获取当前使用的IP,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。";
             }
         }
 
@@ -652,9 +654,9 @@ namespace Masuit.Tools.Hardware
                 foreach (ManagementObject objMgmt in objCS.Get()) str = objMgmt[type].ToString();
                 return str;
             }
-            catch (Exception)
+            catch (Exception e)
             {
-                return "未能获取到操作系统版本,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。";
+                return "未能获取到当前计算机系统信息,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。异常信息:" + e.Message;
             }
         }
 
@@ -702,7 +704,7 @@ namespace Masuit.Tools.Hardware
             {
                 return new Dictionary<string, string>()
                 {
-                    { "null", "未能获取到操作系统版本,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。" }
+                    { "null", "未能获取到当前计算机的磁盘信息,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。" }
                 };
             }
         }
@@ -769,7 +771,7 @@ namespace Masuit.Tools.Hardware
             {
                 return new Dictionary<string, string>()
                 {
-                    { "null", "未能获取到操作系统版本,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。" }
+                    { "null", "未能获取到当前计算机的磁盘信息,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。" }
                 };
             }
         }
@@ -804,7 +806,7 @@ namespace Masuit.Tools.Hardware
             {
                 return new Dictionary<string, double>()
                 {
-                    { "未能获取到操作系统版本,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。", 0 }
+                    { "未能获取到当前计算机的磁盘信息,可能是当前程序无管理员权限,如果是web应用程序,请将应用程序池的高级设置中的进程模型下的标识设置为:LocalSystem;如果是普通桌面应用程序,请提升管理员权限后再操作。", 0 }
                 };
             }
         }

+ 7 - 1
Masuit.Tools.sln

@@ -27,7 +27,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCoreTest", "NetCoreTest\
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masuit.Tools.AspNetCore.ResumeFileResults.WebTest", "Masuit.Tools.AspNetCore.ResumeFileResults.WebTest\Masuit.Tools.AspNetCore.ResumeFileResults.WebTest.csproj", "{49E16577-01CD-4104-B73E-449B2960D956}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masuit.Tools.ExpressionMapperBenchmark", "Masuit.Tools.ExpressionMapperBenchmark\Masuit.Tools.ExpressionMapperBenchmark.csproj", "{1D51DC49-6626-41AF-B1B5-085C83307FF2}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masuit.Tools.ExpressionMapperBenchmark", "Masuit.Tools.ExpressionMapperBenchmark\Masuit.Tools.ExpressionMapperBenchmark.csproj", "{1D51DC49-6626-41AF-B1B5-085C83307FF2}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{921E4274-9D0A-4C0F-914F-953743AE3859}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -83,6 +85,10 @@ Global
 		{1D51DC49-6626-41AF-B1B5-085C83307FF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{1D51DC49-6626-41AF-B1B5-085C83307FF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{1D51DC49-6626-41AF-B1B5-085C83307FF2}.Release|Any CPU.Build.0 = Release|Any CPU
+		{921E4274-9D0A-4C0F-914F-953743AE3859}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{921E4274-9D0A-4C0F-914F-953743AE3859}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{921E4274-9D0A-4C0F-914F-953743AE3859}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{921E4274-9D0A-4C0F-914F-953743AE3859}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 0 - 43
MasuitToolsNugetPackage/MasuitToolsNugetPackage.nuproj

@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|AnyCPU">
-      <Configuration>Debug</Configuration>
-      <Platform>AnyCPU</Platform>
-    </ProjectConfiguration>
-    <ProjectConfiguration Include="Release|AnyCPU">
-      <Configuration>Release</Configuration>
-      <Platform>AnyCPU</Platform>
-    </ProjectConfiguration>
-  </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\Masuit.Tools\Masuit.Tools.csproj" />
-  </ItemGroup>
-  <PropertyGroup Label="Globals">
-    <ProjectGuid>eb6cc774-090e-4102-a8b2-d8e11ebebdd7</ProjectGuid>
-  </PropertyGroup>
-  <PropertyGroup>
-    <NuProjPath Condition=" '$(NuProjPath)' == '' ">$(MSBuildExtensionsPath)\NuProj\</NuProjPath>
-  </PropertyGroup>
-  <Import Project="$(NuProjPath)\NuProj.props" Condition="Exists('$(NuProjPath)\NuProj.props')" />
-  <PropertyGroup Label="Configuration">
-    <Id>Masuit.Tools</Id>
-    <Version>1.2.3</Version>
-    <Title>Masuit.Tools</Title>
-    <Authors>懒得勤快</Authors>
-    <Owners>QQ:1170397736</Owners>
-    <Summary>包含一些常用的操作类,加密解密,大文件拷贝,图像裁剪,验证码</Summary>
-    <Description>包含一些常用的操作类,大都是静态类,加密解密,反射操作,硬件信息,文档转换,字符串扩展方法,日期时间扩展操作,大文件拷贝,图像裁剪,验证码等常用封装。</Description>
-    <ReleaseNotes>如有问题请联系QQ:1170397736,或者到项目的github反馈问题,详细的API文档在github上:https://github.com/ldqk/Masuit.Tools</ReleaseNotes>
-    <ProjectUrl>https://github.com/ldqk/Masuit.Tools</ProjectUrl>
-    <LicenseUrl>
-    </LicenseUrl>
-    <Copyright>Copyright © 懒得勤快</Copyright>
-    <Tags>Masuit.Tools</Tags>
-    <RequireLicenseAcceptance>false</RequireLicenseAcceptance>
-    <DevelopmentDependency>true</DevelopmentDependency>
-    <EmbedSourceFiles>true</EmbedSourceFiles>
-    <OutputPath>E:\packages</OutputPath>
-  </PropertyGroup>
-  <Import Project="$(NuProjPath)\NuProj.targets" />
-</Project>