From e4fb4c91ea3a64496c7e32ae1e03abced856525b Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Wed, 19 Feb 2020 09:55:51 +0800 Subject: [PATCH] =?UTF-8?q?1.0.0-alpha.219=201.=E4=BD=BF=E7=94=A8=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96config=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9A=84mac?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E4=BD=9C=E4=B8=BA=E8=8A=82=E7=82=B9=E7=BC=96?= =?UTF-8?q?=E5=8F=B7=202.=E6=9B=B4=E6=8D=A2=E7=BD=91=E5=8D=A1=E6=97=B6?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E6=A0=B9=E6=8D=AE=E6=96=B0=E7=BD=91=E5=8D=A1?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=BA=8F=E5=88=97=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: f9f3d908b7332831c2d7dc1e7d2b66f84d0c6bf2 --- labs/IdTest/.gitignore | 16 +++++++++++++++ labs/IdTest/IdTest.csproj | 12 +++++++++++ labs/IdTest/IdTest.sln | 25 +++++++++++++++++++++++ labs/IdTest/Program.cs | 40 +++++++++++++++++++++++++++++++++++++ projects/IoTNode/Startup.cs | 10 +++++----- 5 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 labs/IdTest/.gitignore create mode 100644 labs/IdTest/IdTest.csproj create mode 100644 labs/IdTest/IdTest.sln create mode 100644 labs/IdTest/Program.cs diff --git a/labs/IdTest/.gitignore b/labs/IdTest/.gitignore new file mode 100644 index 00000000..988994ff --- /dev/null +++ b/labs/IdTest/.gitignore @@ -0,0 +1,16 @@ +*.bak +*.suo +*.db +*.user +.vs +obj +Obj +bin +Bin +debug +Debug +release +Release +Logs +logs +node_modules \ No newline at end of file diff --git a/labs/IdTest/IdTest.csproj b/labs/IdTest/IdTest.csproj new file mode 100644 index 00000000..1f36f2b0 --- /dev/null +++ b/labs/IdTest/IdTest.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp3.1 + + + + + + + diff --git a/labs/IdTest/IdTest.sln b/labs/IdTest/IdTest.sln new file mode 100644 index 00000000..8d016228 --- /dev/null +++ b/labs/IdTest/IdTest.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29806.167 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IdTest", "IdTest.csproj", "{600B4FE6-FE66-4D0B-B8EB-61642AC0A595}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {600B4FE6-FE66-4D0B-B8EB-61642AC0A595}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {600B4FE6-FE66-4D0B-B8EB-61642AC0A595}.Debug|Any CPU.Build.0 = Debug|Any CPU + {600B4FE6-FE66-4D0B-B8EB-61642AC0A595}.Release|Any CPU.ActiveCfg = Release|Any CPU + {600B4FE6-FE66-4D0B-B8EB-61642AC0A595}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {79316E84-1766-4980-B4FE-09AA33D9C00C} + EndGlobalSection +EndGlobal diff --git a/labs/IdTest/Program.cs b/labs/IdTest/Program.cs new file mode 100644 index 00000000..cbb5bb39 --- /dev/null +++ b/labs/IdTest/Program.cs @@ -0,0 +1,40 @@ +using System; +using System.IO; +using System.Management; +using System.Runtime.InteropServices; +using System.Text.RegularExpressions; + +namespace IdTest +{ + internal class Program + { + private static void Main(string[] args) + { + Console.WriteLine(GetCPUNumber()); + } + + public static string GetCPUNumber() + { + var result = string.Empty; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + result = Regex.Match(File.ReadAllText("/proc/cpuinfo"), @"Serial\s*:\s*([^\s]+)").Groups[1].Value; + } + else + { + var mc = new ManagementClass("win32_processor"); + var moc = mc.GetInstances(); + + foreach (ManagementObject mo in moc) + { + if (result == "") + { + result = mo.Properties["processorID"].Value.ToString(); + break; + } + } + } + return result.ToLower(); + } + } +} \ No newline at end of file diff --git a/projects/IoTNode/Startup.cs b/projects/IoTNode/Startup.cs index 9ecdda3d..0771da76 100644 --- a/projects/IoTNode/Startup.cs +++ b/projects/IoTNode/Startup.cs @@ -66,18 +66,18 @@ namespace IoTNode }); } - public override void Seed(DbContext dbContext, IServiceProvider serviceProvider, IConfiguration configuration) + public override void Seed(DbContext dbContext, IServiceProvider serviceProvider, IConfiguration cfg) { - var id = Helper.Instance.GetMacAddress(); + var sn = cfg["sn"]; dbContext.Set().Add(new Node { - Id = $"nodeid-{id}".ToGuid(), + Id = $"nodeid-{sn}".ToGuid(), Name = "½Úµã", - Number = id, + Number = sn, Image = "/images/classroom.png" }); dbContext.SaveChanges(); - base.Seed(dbContext, serviceProvider, configuration); + base.Seed(dbContext, serviceProvider, cfg); } } } \ No newline at end of file