diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9491a2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,363 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Oo]ut/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd \ No newline at end of file diff --git a/App.xaml b/App.xaml new file mode 100644 index 0000000..2d2275f --- /dev/null +++ b/App.xaml @@ -0,0 +1,9 @@ + + + ./Fonts/Barcode.ttf#IDAHC39M Code 39 Barcode + + \ No newline at end of file diff --git a/App.xaml.cs b/App.xaml.cs new file mode 100644 index 0000000..f63fbaa --- /dev/null +++ b/App.xaml.cs @@ -0,0 +1,11 @@ +using System.Windows; + +namespace powerLabel +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/Bios.cs b/Bios.cs new file mode 100644 index 0000000..6820e82 --- /dev/null +++ b/Bios.cs @@ -0,0 +1,39 @@ +using System; +using System.Management; + +namespace powerLabel +{ + public class Bios + { + public int id { get; set; } + public string version { get; set; } + public DateTime date { get; set; } + + public static Bios GetBios() + { + Bios bios = new Bios(); + + foreach (ManagementObject item in PSInterface.RunPowershell("SELECT * FROM Win32_Bios")) + { + bios.version = (string)item["SMBIOSBIOSVersion"]; + bios.date = DateTime.ParseExact(((string)item["ReleaseDate"]).Substring(0, ((string)item["ReleaseDate"]).Length - 4), "yyyyMMddHHmmss.FFFFFF", null); + } + + return bios; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) return false; + + Bios bios = (Bios)obj; + if (this.version.Trim() == bios.version.Trim() && + this.date == bios.date + ) + { + return true; + } + return false; + } + } +} diff --git a/ComputerSystem.cs b/ComputerSystem.cs new file mode 100644 index 0000000..3c3ba86 --- /dev/null +++ b/ComputerSystem.cs @@ -0,0 +1,184 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; + +namespace powerLabel +{ + public class ComputerSystem + { + public int id { get; set; } + public Motherboard motherboard { get; set; } + public Bios bios { get; set; } + public int processorAmount { get; set; } + public Processor processor { get; set; } + public List memoryModules { get; set; } + public List diskConfigs { get; set; } + public List videoControllerConfigs { get; set; } + public OS operatingSystem { get; set; } + + public static ComputerSystem system { get; set; } + + public static ComputerSystem GetSystem() + { + system = new ComputerSystem(); + system.motherboard = Motherboard.GetMotherboard(); + system.bios = Bios.GetBios(); + system.processor = Processor.GetProcessor(system); + system.memoryModules = MemoryConfig.GetMemory(system); + system.diskConfigs = DiskConfig.GetDisks(system); + system.videoControllerConfigs = VideoControllerConfig.GetVideoControllers(system); + system.operatingSystem = OS.GetOS(); + + using (var db = new ComputerSystemContext()) + { + if (db.ComputerSystems + .Include(a => a.motherboard) + .Include(a => a.bios) + .Include(a => a.processor) + .Include(a => a.memoryModules).ThenInclude(a => a.module) + .Include(a => a.diskConfigs).ThenInclude(a => a.disk) + .Include(a => a.videoControllerConfigs).ThenInclude(a => a.videoController) + .Include(a => a.operatingSystem) + .ToList() + .Any(a => a.Equals(system))) + { + //This system config has been scanned before + + //List of all the events with this motherboard ordered by date + List events = db.Events.ToList().Where(a => a.computerSystem.motherboard.id == db.Motherboards.ToList().Where(b => b.Equals(system.motherboard)).First().id).ToList().OrderBy(a => a.date).ToList(); + + //The last config this motherboard had + ComputerSystem lastConfig = db.ComputerSystems.ToList().Where(a => a.id == events.Last().computerSystem.id).Single(); + + if (system.Equals(lastConfig)) + { + //The config hasn't changed since the last system scan, so set the system to the last config (in order to have the correct id's) + system = lastConfig; + } + } + } + ComputerSystem.system = system; + return system; + } + + public string getString() + { + if (system == null) + { + return ""; + } + + // Model Label string processing + string modelString = motherboard.model; + modelString = getShortString(modelString, new string[] { + @"HP Z\w+( \d{2}\w? G\d)?", // HP Systems (HP Z840, HP ZBook 15 G3, HP ZBook 14U G5) + @"Precision \w* \w*" // DELL Systems (Precision WorkStation T3500, Precision Tower 3620) + }); + + // CPU Label string processing + string cpuString = processor.name; + cpuString = getShortString(cpuString, new string[] { + @"(((Platinum)|(Gold)|(Silver)|(Bronze)) \w*-*\d+\w*)|(\w+-*\d{3,}\w*( v\d)*)" // regex voor vrijwel alle core i en xeon processoren vanaf 2006 + }); + if (processorAmount > 1) + { + cpuString = cpuString.Insert(0, "2x "); + } + + // RAM Label string processing + string ramString = memoryModules.Sum(item => Convert.ToInt64(item.module.capacity)) / 1073741824 + "GB " + MemoryModule.memoryTypeLookup[memoryModules.First().module.memoryType]; + + // Disk Label string processing + string diskString = ""; + List disks = new List(); + List doneDisks = new List(); + foreach (DiskConfig disk in system.diskConfigs) + { + disks.Add(disk.ToString()); + } + foreach (string disk in disks) + { + if (!doneDisks.Any(a => a == disk)) + { + if (disks.Where(a => a == disk).Count() > 1) + { + int multiplier = disks.Where(a => a == disk).Count(); + diskString += $"{multiplier}x {disk}."; + doneDisks.Add(disk); + } + else + { + diskString += disk + "."; + doneDisks.Add(disk); + } + } + + } + + + // GPU Label string processing + string gpuString = ""; + foreach (VideoControllerConfig gpu in videoControllerConfigs) + { + gpuString += getShortString(gpu.videoController.name, new string[] { + @"\w{2,3} Graphics \w+", // Intel intergrated graphics (HD Graphics 405, Pro Graphics 600) + @"Quadro (RTX )*\w+", // Quadro's (Quadro RTX 4000, Quadro K2200, Quadro M2000M) + @"GeForce \wTX \d{3,}( \w+)*" // Nvidia GeForce GTX / RTX 3060 Ti + }) + "\r\n"; + } + + // Final string formatting + // '.' will be replaced by zero width space + // spaces will be replaced with a non brakeable space + return modelString + "\r\n." + cpuString + " | " + ramString + "\r\n." + diskString + " ." + gpuString; + } + + public static string getShortString(string input, string[] regexes) + { + Regex[] regex = new Regex[regexes.Length]; + int i = 0; + foreach (string str in regexes) + { + regex[i] = new Regex(@str); + i++; + } + foreach (Regex item in regex) + { + if (item.IsMatch(input)) + { + return item.Match(input).Groups[0].Value; + } + } + return input; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) return false; + + ComputerSystem sys = (ComputerSystem)obj; + try + { + if (((this.motherboard == null && sys.motherboard == null) || this.motherboard.Equals(sys.motherboard)) && + ((this.bios == null && sys.bios == null) || this.bios.Equals(sys.bios)) && + (this.processorAmount == sys.processorAmount) && + ((this.processor == null && sys.processor == null) || this.processor.Equals(sys.processor)) && + ((this.memoryModules == null && sys.memoryModules == null) || this.memoryModules.SequenceEqual(sys.memoryModules)) && + ((this.diskConfigs == null && sys.diskConfigs == null) || this.diskConfigs.SequenceEqual(sys.diskConfigs)) && + ((this.videoControllerConfigs == null && sys.videoControllerConfigs == null) || this.videoControllerConfigs.SequenceEqual(sys.videoControllerConfigs)) && + ((this.operatingSystem == null && sys.operatingSystem == null) || this.operatingSystem.Equals(sys.operatingSystem)) + ) + { + return true; + } + return false; + } + catch (Exception) + { + return false; + } + } + } +} diff --git a/ComputerSystemContext.cs b/ComputerSystemContext.cs new file mode 100644 index 0000000..6df66b1 --- /dev/null +++ b/ComputerSystemContext.cs @@ -0,0 +1,35 @@ +using Microsoft.EntityFrameworkCore; + +namespace powerLabel +{ + public class ComputerSystemContext : DbContext + { + static SettingsHandler.Settings settings = SettingsHandler.ReadSettings(); + + string ip = settings.databaseIP; + string database = settings.databaseName; + string user = settings.databaseUser; + string password = settings.databasePass; + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseMySql($"server={ip};database={database};user={user};password={password};"); + + // Connection strings for updating the database + //optionsBuilder.UseMySql($"server=localhost;database=powerlabeldb;user=root;password=;"); + } + + public DbSet Events { get; set; } + public DbSet ComputerSystems { get; set; } + public DbSet Motherboards { get; set; } + public DbSet Bioses { get; set; } + public DbSet Processors { get; set; } + public DbSet MemoryModules { get; set; } + public DbSet MemoryConfigs { get; set; } + public DbSet Disks { get; set; } + public DbSet DiskConfigs { get; set; } + public DbSet VideoControllers { get; set; } + public DbSet VideoControllerConfigs { get; set; } + public DbSet OSes { get; set; } + } +} diff --git a/Database.cs b/Database.cs new file mode 100644 index 0000000..3f3b3a7 --- /dev/null +++ b/Database.cs @@ -0,0 +1,137 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using System.Windows; + +namespace powerLabel +{ + public static class Database + { + public static void AddSystem(ComputerSystem system) + { + try + { + using (var db = new ComputerSystemContext()) + { + if (system.id != 0) + { + return; + } + + ComputerSystem sysToInsert = new ComputerSystem(); + + db.ComputerSystems.Add(sysToInsert); + db.SaveChanges(); + db.ComputerSystems.Attach(sysToInsert); + + + if (!db.Motherboards.ToList().Any(a => a.Equals(system.motherboard))) + { + db.Motherboards.Add(system.motherboard); + db.SaveChanges(); + } + + Motherboard mobo = db.Motherboards.ToList().Where(a => a.Equals(system.motherboard)).First(); + + sysToInsert.motherboard = mobo; + + if (!db.Bioses.ToList().Any(a => a.Equals(system.bios))) + { + db.Bioses.Add(system.bios); + db.SaveChanges(); + } + + Bios bios = db.Bioses.ToList().Where(a => a.Equals(system.bios)).First(); + + sysToInsert.bios = bios; + + if (!db.OSes.ToList().Any(a => a.Equals(system.operatingSystem))) + { + db.OSes.Add(system.operatingSystem); + db.SaveChanges(); + } + + OS os = db.OSes.ToList().Where(a => a.Equals(system.operatingSystem)).First(); + + sysToInsert.operatingSystem = os; + + // Add processor if it doesnt exist in the database + if (!db.Processors.ToList().Any(a => a.Equals(system.processor))) + { + db.Processors.Add(system.processor); + db.SaveChanges(); + } + + Processor processor = db.Processors.ToList().Where(a => a.Equals(system.processor)).First(); + + sysToInsert.processorAmount = system.processorAmount; + sysToInsert.processor = processor; + + foreach (MemoryConfig memoryConfig in system.memoryModules) + { + if (!db.MemoryModules.ToList().Any(a => a.Equals(memoryConfig.module))) + { + db.MemoryModules.Add(memoryConfig.module); + db.SaveChanges(); + } + MemoryModule module = db.MemoryModules.ToList().Where(a => a.Equals(memoryConfig.module)).First(); + + db.MemoryConfigs.Add(new MemoryConfig() { module = module, currentClockspeed = memoryConfig.currentClockspeed, system = sysToInsert }); + } + + + foreach (DiskConfig diskConfig in system.diskConfigs) + { + if (!db.Disks.ToList().Any(a => a.Equals(diskConfig.disk))) + { + db.Disks.Add(diskConfig.disk); + db.SaveChanges(); + } + Disk disk = db.Disks.ToList().Where(a => a.Equals(diskConfig.disk)).First(); + + db.DiskConfigs.Add(new DiskConfig() { disk = disk, busType = diskConfig.busType, systemDisk = diskConfig.systemDisk, computerSystem = sysToInsert }); + } + + foreach (VideoControllerConfig videoControllerConfig in system.videoControllerConfigs) + { + if (!db.VideoControllerConfigs.Include(a => a.videoController).ToList().Any(a => a.videoController.Equals(videoControllerConfig.videoController))) + { + db.VideoControllers.Add(videoControllerConfig.videoController); + db.SaveChanges(); + } + VideoController videoController = db.VideoControllers.ToList().Where(a => a.Equals(videoControllerConfig.videoController)).First(); + + db.VideoControllerConfigs.Add(new VideoControllerConfig() { videoController = videoController, computerSystem = sysToInsert }); + } + + db.ComputerSystems.Update(sysToInsert); + + db.SaveChanges(); + + string employee = ""; + foreach (Window window in Application.Current.Windows) + { + if (window.GetType() == typeof(MainWindow)) + { + employee = (window as MainWindow).employeeDropdown.Text; + } + } + if (employee == "") + { + MessageBox.Show("No employee selected"); + return; + } + db.Events.Add(Event.NewScanEvent(employee, DateTime.Now, db, sysToInsert)); + db.SaveChanges(); + + } + } + catch (Exception ex) + { + MessageBox.Show("Database Error: " + ex.Message); + } + + } + + } +} diff --git a/Database/Database Model.mwb b/Database/Database Model.mwb new file mode 100644 index 0000000..a36d473 Binary files /dev/null and b/Database/Database Model.mwb differ diff --git a/Database/Database Model.mwb.bak b/Database/Database Model.mwb.bak new file mode 100644 index 0000000..c228854 Binary files /dev/null and b/Database/Database Model.mwb.bak differ diff --git a/Disk.cs b/Disk.cs new file mode 100644 index 0000000..1f539a7 --- /dev/null +++ b/Disk.cs @@ -0,0 +1,27 @@ +namespace powerLabel +{ + public class Disk + { + public int id { get; set; } + public string model { get; set; } + public ulong size { get; set; } + public string mediaType { get; set; } + public string serialNumber { get; set; } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) return false; + + Disk disk = (Disk)obj; + if (this.model.Trim() == disk.model.Trim() && + this.size == disk.size && + this.mediaType.Trim() == disk.mediaType.Trim() && + this.serialNumber.Trim() == disk.serialNumber.Trim() + ) + { + return true; + } + return false; + } + } +} \ No newline at end of file diff --git a/DiskConfig.cs b/DiskConfig.cs new file mode 100644 index 0000000..a221f3d --- /dev/null +++ b/DiskConfig.cs @@ -0,0 +1,180 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Management; + +namespace powerLabel +{ + public class DiskConfig + { + public DiskConfig() + { + + } + public DiskConfig(ComputerSystem computerSystem) + { + disk = new Disk(); + this.computerSystem = computerSystem; + } + public DiskConfig(Disk disk, ComputerSystem computerSystem, int busType) + { + this.disk = disk; + this.computerSystem = computerSystem; + this.busType = busTypeEncoding[busType]; + } + public int id { get; set; } + public Disk disk { get; set; } + public ComputerSystem computerSystem { get; set; } + public bool systemDisk { get; set; } + public string busType { get; set; } + + private static string[] busTypeEncoding = { + "Unknown", + "SCSI", + "ATAPI", + "ATA", + "IEEE 1394", + "SSA", + "Fibre Channel", + "USB", + "", //RAID + "iSCSI", + "SAS", + "SATA", + "SD", + "MMC", + "MAX", + "File Backed Virtual", + "Storage Spaces", + "NVMe" + }; + + public static List GetDisks(ComputerSystem system) + { + List list = new List(); + + uint osDiskId = 255; + ManagementObjectCollection partitions = PSInterface.RunPowershell("SELECT * FROM Win32_DiskPartition"); + foreach (ManagementObject item in partitions) + { + if ((bool)item["BootPartition"]) + { + osDiskId = (uint)item["DiskIndex"]; + } + } + + ManagementScope scope = new ManagementScope("root\\Microsoft\\Windows\\Storage"); + scope.Connect(); + + ObjectQuery query = new ObjectQuery("SELECT * FROM MSFT_PhysicalDisk"); + ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); + + ManagementObjectCollection returned = searcher.Get(); + foreach (ManagementObject item in returned) + { + DiskConfig diskConfig = new DiskConfig(system); + + diskConfig.disk.model = (string)item["Model"]; + diskConfig.disk.size = (ulong)item["Size"]; + diskConfig.busType = busTypeEncoding[(UInt16)item["busType"]]; + + switch ((ushort)item["MediaType"]) + { + case 0: + diskConfig.disk.mediaType = "Unspecified"; + break; + case 3: + diskConfig.disk.mediaType = "HDD"; + break; + case 4: + diskConfig.disk.mediaType = "SSD"; + break; + case 5: + diskConfig.disk.mediaType = "SCM"; + break; + default: + break; + } + + diskConfig.disk.serialNumber = (string)item["SerialNumber"]; + + if (UInt32.Parse((string)item["DeviceId"]) == osDiskId) + { + diskConfig.systemDisk = true; + } + + if (diskConfig.busType == "USB") + { + continue; + } + + list.Add(diskConfig); + } + + return list.OrderByDescending(disk => disk.systemDisk).ThenByDescending(disk => disk.disk.mediaType).ThenBy(disk => disk.disk.size).ToList(); + } + + public override string ToString() + { + ulong shortSize = disk.size / 1000000000; + string unit; + string os = ""; + + if (shortSize.ToString().Length == 3) + { + unit = "GB"; + } + else + { + unit = "TB"; + shortSize = shortSize / 1000; + } + + if (systemDisk) + { + if (computerSystem.operatingSystem.caption.Contains("10")) + { + os = "+ W10P"; + } + else if (computerSystem.operatingSystem.caption.Contains("11")) + { + os = "+ W11P"; + } + + if (computerSystem.operatingSystem.language != "NL") + { + os += " " + computerSystem.operatingSystem.language; + } + } + + if (disk.mediaType == "SSD") + { + if (busType == "NVMe") + { + return $"{shortSize}{unit} {busType} {os} "; + } + return $"{shortSize}{unit} {busType} {disk.mediaType} {os} "; + } + if (disk.mediaType == "HDD") + { + return $"{shortSize}{unit} {disk.mediaType} {os} "; + } + return $"{shortSize}{unit} {disk.mediaType} {os} "; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) return false; + + DiskConfig diskConfig = (DiskConfig)obj; + if (this.disk.Equals(diskConfig.disk) && + this.busType.Trim() == diskConfig.busType.Trim() && + this.systemDisk == diskConfig.systemDisk + ) + { + return true; + } + return false; + } + } +} \ No newline at end of file diff --git a/Event.cs b/Event.cs new file mode 100644 index 0000000..452b9d3 --- /dev/null +++ b/Event.cs @@ -0,0 +1,71 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq; +using System.Windows; + +namespace powerLabel +{ + public class Event + { + public int id { get; set; } + public string employee { get; set; } + public string name { get; set; } + public string description { get; set; } + public string note { get; set; } + public ComputerSystem computerSystem { get; set; } + public DateTime date { get; set; } + + public Event() + { + + } + public Event(string employee, string eventName, string description, DateTime date, ComputerSystemContext db, ComputerSystem cs, string note = "") + { + + try + { + this.computerSystem = cs; + } + catch (Exception) + { + MessageBox.Show("Cannot make event when there is no system scanned."); + throw; + } + + this.employee = employee; + this.name = eventName; + this.description = description; + this.note = note; + this.date = date; + + } + + public static Event NewPrintEvent(string employee, DateTime date, ComputerSystemContext db, ComputerSystem cs, string note = "") + { + string name = "Printed Label"; + string description = "A label with the specs of this system has been printed."; + return new Event(employee, name, description, date, db, cs, note); + } + public static Event NewScanEvent(string employee, DateTime date, ComputerSystemContext db, ComputerSystem cs, string note = "") + { + string name = "System Scanned"; + string description = "The specifications of the system have been scanned and recorded in the database."; + return new Event(employee, name, description, date, db, cs, note); + } + public static Event NewMarkedAsOrderEvent(string employee, DateTime date, ComputerSystemContext db, ComputerSystem cs, string note = "") + { + string name = "Marked As Order"; + string description = ""; + foreach (Window window in Application.Current.Windows) + { + if (window.GetType() == typeof(MainWindow)) + { + description = (window as MainWindow).orderNr.Text; + } + } + return new Event(employee, name, description, date, db, cs, note); + } + + + } +} diff --git a/FodyWeavers.xml b/FodyWeavers.xml new file mode 100644 index 0000000..5029e70 --- /dev/null +++ b/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Fonts/Barcode.ttf b/Fonts/Barcode.ttf new file mode 100644 index 0000000..f132522 Binary files /dev/null and b/Fonts/Barcode.ttf differ diff --git a/Images/isometrix pixel art pc high res.png b/Images/isometrix pixel art pc high res.png new file mode 100644 index 0000000..633b218 Binary files /dev/null and b/Images/isometrix pixel art pc high res.png differ diff --git a/Images/isometrix pixel art pc.png b/Images/isometrix pixel art pc.png new file mode 100644 index 0000000..8fc231b Binary files /dev/null and b/Images/isometrix pixel art pc.png differ diff --git a/Images/isometrix pixel art printer.png b/Images/isometrix pixel art printer.png new file mode 100644 index 0000000..706ff03 Binary files /dev/null and b/Images/isometrix pixel art printer.png differ diff --git a/Images/save-icon.png b/Images/save-icon.png new file mode 100644 index 0000000..bfce3aa Binary files /dev/null and b/Images/save-icon.png differ diff --git a/Images/settings.png b/Images/settings.png new file mode 100644 index 0000000..647bbaf Binary files /dev/null and b/Images/settings.png differ diff --git a/Images/tower-pc.png b/Images/tower-pc.png new file mode 100644 index 0000000..b08a380 Binary files /dev/null and b/Images/tower-pc.png differ diff --git a/LabelPrinting.cs b/LabelPrinting.cs new file mode 100644 index 0000000..8ec0f6f --- /dev/null +++ b/LabelPrinting.cs @@ -0,0 +1,145 @@ +using System; +using System.Management; +using System.Printing; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; + +namespace powerLabel +{ + public class LabelPrinting + { + public static void printLabel(Grid grid) + { + try + { + // Add printer event + using (var db = new ComputerSystemContext()) + { + string employee = ""; + foreach (Window window in Application.Current.Windows) + { + if (window.GetType() == typeof(MainWindow)) + { + employee = (window as MainWindow).employeeDropdown.Text; + } + } + if (employee == "") + { + MessageBox.Show("No employee selected"); + return; + } + db.Attach(ComputerSystem.system); + db.Events.Add(Event.NewPrintEvent(employee, DateTime.Now, db, ComputerSystem.system)); + db.SaveChanges(); + } + + // Add printer + using (ManagementClass win32Printer = new ManagementClass("Win32_Printer")) + { + using (ManagementBaseObject inputParam = + win32Printer.GetMethodParameters("AddPrinterConnection")) + { + inputParam.SetPropertyValue("Name", $"\\\\{SettingsHandler.ReadSettings().printerHost}\\{SettingsHandler.ReadSettings().printerShareName}"); + + using (ManagementBaseObject result = + (ManagementBaseObject)win32Printer.InvokeMethod("AddPrinterConnection", inputParam, null)) + { + uint errorCode = (uint)result.Properties["returnValue"].Value; + + switch (errorCode) + { + case 0: + Console.Out.WriteLine("Successfully connected printer."); + break; + case 5: + Console.Out.WriteLine("Access Denied."); + break; + case 123: + Console.Out.WriteLine("The filename, directory name, or volume label syntax is incorrect."); + break; + case 1801: + Console.Out.WriteLine("Invalid Printer Name."); + break; + case 1930: + Console.Out.WriteLine("Incompatible Printer Driver."); + break; + case 3019: + Console.Out.WriteLine("The specified printer driver was not found on the system and needs to be downloaded."); + break; + } + } + } + } + + FrameworkElement e = grid as System.Windows.FrameworkElement; + if (e == null) + return; + + PrintDialog pd = new PrintDialog(); + PrintServer myPrintServer = new PrintServer($"\\\\{SettingsHandler.ReadSettings().printerHost}"); + + // List the print server's queues + PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues(); + foreach (PrintQueue pq in myPrintQueues) + { + pd.PrintQueue = pq; + } + pd.PrintTicket.PageMediaSize = new PageMediaSize(216, 120); + + + //store original scale + Transform originalScale = e.LayoutTransform; + //get selected printer capabilities + PrintCapabilities capabilities = pd.PrintQueue.GetPrintCapabilities(pd.PrintTicket); + + //get scale of the print wrt to screen of WPF visual + double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / e.ActualWidth, capabilities.PageImageableArea.ExtentHeight / + e.ActualHeight); + + //Transform the Visual to scale + e.LayoutTransform = new ScaleTransform(scale, scale); + + //get the size of the printer page + System.Windows.Size sz = new System.Windows.Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight); + + //update the layout of the visual to the printer page size. + e.Measure(sz); + e.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz)); + + //now print the visual to printer to fit on the one page. + pd.PrintVisual(grid, "My Print"); + + //apply the original transform. + e.LayoutTransform = originalScale; + + // Remove printer + ConnectionOptions options = new ConnectionOptions(); + options.EnablePrivileges = true; + ManagementScope scope = new ManagementScope(ManagementPath.DefaultPath, options); + scope.Connect(); + ManagementClass printerClass = new ManagementClass("Win32_Printer"); + ManagementObjectCollection printers = printerClass.GetInstances(); + foreach (ManagementObject printer in printers) + { + if ((string)printer["ShareName"] == SettingsHandler.ReadSettings().printerShareName) + { + printer.Delete(); + } + } + } + catch (Exception ex) + { + MessageBox.Show("Printing process returned an error: " + ex.Message); + } +} + + public static string formatString(string str) + { + // Replaces spaces with non braking spaces and periods with zerowidth spaces + str = str.Replace(" ", "\u00a0").Replace(".", "\u200B"); + return str; + } + + } +} diff --git a/MainWindow.xaml b/MainWindow.xaml new file mode 100644 index 0000000..f5fd0a2 --- /dev/null +++ b/MainWindow.xaml @@ -0,0 +1,334 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs new file mode 100644 index 0000000..2bfeb35 --- /dev/null +++ b/MainWindow.xaml.cs @@ -0,0 +1,525 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text.RegularExpressions; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows.Shapes; + +namespace powerLabel +{ + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + refreshSettings(); + } + + private void refreshSettings() + { + SettingsHandler.Settings settings = SettingsHandler.ReadSettings(); + employeeDropdown.Items.Clear(); + foreach (string item in settings.employees) + { + ListViewItem listViewItem = new ListViewItem(); + listViewItem.Content = item; + employeeDropdown.Items.Add(listViewItem); + } + + } + + private void scanSystem(object sender, RoutedEventArgs e) + { + ComputerSystem.GetSystem(); + ComputerSystem system = ComputerSystem.system; + + // Model Label string processing + string modelString = system.motherboard.model; + modelString = ComputerSystem.getShortString(modelString, new string[] { + @"HP Z\w+( \d{2}\w? G\d)?", // HP Systems (HP Z840, HP ZBook 15 G3, HP ZBook 14U G5) + @"Precision \w* \w*" // DELL Systems (Precision WorkStation T3500, Precision Tower 3620) + }); + + // CPU Label string processing + string cpuString = system.processor.name; + cpuString = ComputerSystem.getShortString(cpuString, new string[] { + @"(((Platinum)|(Gold)|(Silver)|(Bronze)) \w*-*\d+\w*)|(\w+-*\d{3,}\w*( v\d)*)" // regex voor vrijwel alle core i en xeon processoren vanaf 2006 + }); + if (system.processorAmount > 1) + { + cpuString = cpuString.Insert(0, "2x "); + } + + // RAM Label string processing + string ramString = system.memoryModules.Sum(item => Convert.ToInt64(item.module.capacity)) / 1073741824 + "GB " + MemoryModule.memoryTypeLookup[system.memoryModules.First().module.memoryType]; + + // Disk Label string processing + string diskString = ""; + List disks = new List(); + List doneDisks = new List(); + foreach (DiskConfig disk in system.diskConfigs) + { + disks.Add(disk.ToString()); + } + foreach (string disk in disks) + { + if (!doneDisks.Any(a => a == disk)) + { + if (disks.Where(a => a == disk).Count() > 1) + { + int multiplier = disks.Where(a => a == disk).Count(); + diskString += $"{multiplier}x {disk}\r\n"; + doneDisks.Add(disk); + } + else + { + diskString += disk + "\r\n"; + doneDisks.Add(disk); + } + } + + } + + + // GPU Label string processing + string gpuString = ""; + foreach (VideoControllerConfig gpu in system.videoControllerConfigs) + { + gpuString += ComputerSystem.getShortString(gpu.videoController.name, new string[] { + @"\w{2,3} Graphics \w+", // Intel intergrated graphics (HD Graphics 405, Pro Graphics 600) + @"Quadro (RTX )*\w+", // Quadro's (Quadro RTX 4000, Quadro K2200, Quadro M2000M) + @"GeForce \wTX \d{3,}( \w+)*" // Nvidia GeForce GTX / RTX 3060 Ti + }) + "\r\n"; + } + + + + modelField.Content = modelString; + cpuField.Content = cpuString; + ramField.Content = ramString; + disksField.Content = diskString; + gpuField.Content = gpuString; + + int fontsize = 18; + cpuField.FontSize = fontsize; + ramField.FontSize = fontsize; + disksField.FontSize = fontsize; + gpuField.FontSize = fontsize; + Database.AddSystem(system); + ComputerSystem.GetSystem(); + + using (var db = new ComputerSystemContext()) + { + db.ComputerSystems.Attach(ComputerSystem.system); + + eventsStackpanel.Children.Clear(); + foreach (Event evnt in db.Events.Where(a => a.computerSystem.id == ComputerSystem.system.id)) + { + StackPanel stackPanel = new StackPanel(); + stackPanel.Children.Add(new Label { Content = evnt.name }); + stackPanel.Children.Add(new Label { Content = evnt.employee }); + stackPanel.Children.Add(new Label { Content = evnt.date.ToShortDateString() }); + Border border = new Border { Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffe6cc")), + CornerRadius = new CornerRadius(8), + BorderThickness = new Thickness(2), + Margin = new Thickness(5, 0, 10, 5)}; + border.Child = stackPanel; + eventsStackpanel.Children.Add(border); + } + + configHistoryStackPanel.Children.Clear(); + foreach (ComputerSystem config in db.ComputerSystems.Where(a => a.motherboard.id == ComputerSystem.system.motherboard.id)) + { + Ellipse ellipse = new Ellipse + { + Width = 10, + Height = 10, + StrokeThickness = 2, + Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0)), + Fill = new SolidColorBrush(Color.FromRgb(255, 255, 255)), + HorizontalAlignment = HorizontalAlignment.Left, + VerticalAlignment = VerticalAlignment.Top, + Margin = new Thickness(5 ,30 ,5, 50) + }; + + configHistoryStackPanel.Children.Add(ellipse); + + } + } + } + + private void settingsBtn_Click(object sender, RoutedEventArgs e) + { + SettingsWindow settWindow = new SettingsWindow(); + settWindow.ShowDialog(); + refreshSettings(); + } + + private void printBtn_Click(object sender, RoutedEventArgs e) + { + LabelPrinting.printLabel(labelGrid); + updateEvents(); + } + + + private void drawLabelPreview() + { + labelText.Text = LabelPrinting.formatString(ComputerSystem.system.getString()); + } + + + private void partSelector_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + componentGrid.Children.Clear(); + componentGrid.RowDefinitions.Clear(); + componentListBox.Items.Clear(); + object component = null; + if (ComputerSystem.system == null) + { + return; + } + switch (partSelector.SelectedIndex) + { + case 0: + //Motherboard + component = ComputerSystem.system.motherboard; + break; + + case 1: + //Bios + component = ComputerSystem.system.bios; + break; + + case 2: + //Processor + component = ComputerSystem.system.processor; + break; + + case 3: + //Memory + component = ComputerSystem.system.memoryModules; + break; + + case 4: + //Disks + component = ComputerSystem.system.diskConfigs; + break; + + case 5: + //VideoControllers + component = ComputerSystem.system.videoControllerConfigs; + break; + + case 6: + //OperatingSystem + component = ComputerSystem.system.operatingSystem; + break; + + default: + return; + + } + + var enumerable = component as System.Collections.IEnumerable; + int propertyIndex = 0; + int itemIndex = 0; + if (enumerable != null) + { + foreach (var item in enumerable) + { + ListBoxItem listItem = new ListBoxItem(); + listItem.Content = itemIndex; + componentListBox.Items.Add(listItem); + itemIndex++; + + } + } + else + { + foreach (PropertyInfo propertyInfo in component.GetType().GetProperties()) + { + componentGrid.RowDefinitions.Add(new RowDefinition()); + Label label = new Label(); + label.Content = propertyInfo.Name; + componentGrid.Children.Add(label); + Grid.SetRow(label, propertyIndex); + Grid.SetColumn(label, 0); + + Label value = new Label(); + value.Content = propertyInfo.GetValue(component); + componentGrid.Children.Add(value); + Grid.SetRow(value, propertyIndex); + Grid.SetColumn(value, 1); + + propertyIndex++; + } + } + } + + private void componentListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + componentGrid.Children.Clear(); + componentGrid.RowDefinitions.Clear(); + + if (componentListBox.SelectedItem == null) + { + return; + } + + if (ComputerSystem.system == null) + { + return; + } + + int selectedIndex = (int)((ListBoxItem)componentListBox.SelectedItem).Content; + object component = null; + + switch (partSelector.SelectedIndex) + { + case 0: + //Motherboard + component = ComputerSystem.system.motherboard; + break; + + case 1: + //Bios + component = ComputerSystem.system.bios; + break; + + case 2: + //Processor + component = ComputerSystem.system.processor; + break; + + case 3: + //Memory + component = ComputerSystem.system.memoryModules; + break; + + case 4: + //Disks + component = ComputerSystem.system.diskConfigs; + break; + + case 5: + //VideoControllers + component = ComputerSystem.system.videoControllerConfigs; + break; + + case 6: + //OperatingSystem + component = ComputerSystem.system.operatingSystem; + break; + default: + break; + } + + var enumerable = component as System.Collections.IList; + int propertyIndex = 0; + + foreach (PropertyInfo propertyInfo in enumerable[selectedIndex].GetType().GetProperties()) + { + componentGrid.RowDefinitions.Add(new RowDefinition()); + Label label = new Label(); + label.Content = propertyInfo.Name; + componentGrid.Children.Add(label); + Grid.SetRow(label, propertyIndex); + Grid.SetColumn(label, 0); + + Label value = new Label(); + value.Content = propertyInfo.GetValue(enumerable[selectedIndex]); + componentGrid.Children.Add(value); + Grid.SetRow(value, propertyIndex); + Grid.SetColumn(value, 1); + + propertyIndex++; + } + } + + private void scanButton_Click(object sender, RoutedEventArgs e) + { + try + { + scanSystem(sender, e); + leftPanelGrid.Visibility = Visibility.Visible; + drawLabelPreview(); + } + catch (Exception ex) + { + MessageBox.Show("error: " + ex.Message); + } + + } + + private void employeeDropdown_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + if (employeeDropdown.Text == "") + { + scanButton.IsEnabled = false; + printBtn.IsEnabled = false; + OrderSave.IsEnabled = false; + } + else + { + scanButton.IsEnabled = true; + printBtn.IsEnabled = true; + OrderSave.IsEnabled = true; + } + } + + private void employeeDropdown_DropDownClosed(object sender, EventArgs e) + { + if (employeeDropdown.Text == "") + { + scanButton.IsEnabled = false; + printBtn.IsEnabled = false; + OrderSave.IsEnabled = false; + } + else + { + scanButton.IsEnabled = true; + printBtn.IsEnabled = true; + OrderSave.IsEnabled = true; + } + } + + private void OrderSave_Click(object sender, RoutedEventArgs e) + { + try + { + using (var db = new ComputerSystemContext()) + { + string employee = ""; + employee = employeeDropdown.Text; + if (employee == "") + { + MessageBox.Show("No employee selected"); + return; + } + db.Attach(ComputerSystem.system); + db.Events.Add(Event.NewMarkedAsOrderEvent(employee, DateTime.Now, db, ComputerSystem.system, orderNote.Text)); + db.SaveChanges(); + } + + MessageBox.Show("Saved Order"); + } + catch (Exception ex) + { + MessageBox.Show($"An exeption was encountered while saving the order.\r\n{ex}"); + } + updateEvents(); + + } + + private void updateEvents() + { + using (var db = new ComputerSystemContext()) + { + db.ComputerSystems.Attach(ComputerSystem.system); + + eventsStackpanel.Children.Clear(); + foreach (Event evnt in db.Events.Where(a => a.computerSystem.id == ComputerSystem.system.id)) + { + StackPanel stackPanel = new StackPanel(); + stackPanel.Children.Add(new Label { Content = evnt.name }); + stackPanel.Children.Add(new Label { Content = evnt.employee }); + stackPanel.Children.Add(new Label { Content = evnt.date.ToShortDateString() }); + Border border = new Border + { + Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffe6cc")), + CornerRadius = new CornerRadius(8), + BorderThickness = new Thickness(2), + Margin = new Thickness(5, 0, 10, 5) + }; + border.Child = stackPanel; + eventsStackpanel.Children.Add(border); + } + } + } + + private void reload_Click(object sender, RoutedEventArgs e) + { + recentSystemsPanel.Children.Clear(); + using (var db = new ComputerSystemContext()) + { + List events = db.Events.Where(a => Regex.IsMatch(a.name, ".*scan.*")).OrderByDescending(b => b.date).Include(c => c.computerSystem).ToList(); + Event prevEvent = new Event { date = DateTime.Parse("1990-01-01")}; + + foreach (Event evnt in events) + { + ComputerSystem system = db.ComputerSystems.Where(a => a.id == evnt.computerSystem.id).Include(a => a.motherboard) + .Include(a => a.bios) + .Include(a => a.processor) + .Include(a => a.memoryModules).ThenInclude(a => a.module) + .Include(a => a.diskConfigs).ThenInclude(a => a.disk) + .Include(a => a.videoControllerConfigs).ThenInclude(a => a.videoController) + .Include(a => a.operatingSystem) + .ToList().First(); + string time = evnt.date.ToShortTimeString(); + + if (evnt.date.ToShortDateString() != prevEvent.date.ToShortDateString()) + { + StackPanel dayMarker = new StackPanel { Orientation = Orientation.Horizontal }; + dayMarker.Children.Add(new Separator { Width = 300 }); + dayMarker.Children.Add(new TextBlock { Text = evnt.date.ToShortDateString(), HorizontalAlignment = HorizontalAlignment.Right}); + + recentSystemsPanel.Children.Add(dayMarker); + /* + + + + + */ + } + + StackPanel stackPanel = new StackPanel { Margin = new Thickness(5)}; + stackPanel.Children.Add(new TextBlock { Text = $"{time} - {evnt.employee}", + FontSize = 9, + Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF4C4C4C")) + }); + stackPanel.Children.Add(new TextBlock { Text = system.motherboard.model }); + stackPanel.Children.Add(new TextBlock { Text = $"{system.processorAmount}x {system.processor.name}" }); + stackPanel.Children.Add(new TextBlock { Text = $"{system.memoryModules.Sum(a => Convert.ToInt64(a.module.capacity)) / 1073741824}GB {MemoryModule.memoryTypeLookup[system.memoryModules.First().module.memoryType]} {system.memoryModules.First().currentClockspeed}MT/s ({system.memoryModules.Count()})" }); + foreach (DiskConfig disk in system.diskConfigs) + { + stackPanel.Children.Add(new TextBlock { Text = $"{disk.ToString()}" }); + } + foreach (VideoControllerConfig video in system.videoControllerConfigs) + { + stackPanel.Children.Add(new TextBlock { Text = $"{video.videoController.name}" }); + } + stackPanel.Children.Add(new TextBlock { Text = system.motherboard.serialNumber }); + + if (db.Events.Where(a => a.computerSystem.id == system.id).Any(b => Regex.IsMatch(b.name, ".*order.*"))) + { + stackPanel.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#90EE90")); + } + + recentSystemsPanel.Children.Add(stackPanel); + + prevEvent = evnt; + } + + + } + + /* + + + + + + + + + + + + */ + } + } +} diff --git a/MemoryConfig.cs b/MemoryConfig.cs new file mode 100644 index 0000000..92c29e0 --- /dev/null +++ b/MemoryConfig.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Management; + +namespace powerLabel +{ + public class MemoryConfig + { + public MemoryConfig() + { + + } + public MemoryConfig(ComputerSystem system) + { + module = new MemoryModule(); + } + public int id { get; set; } + public MemoryModule module { get; set; } + public ComputerSystem system { get; set; } + public uint currentClockspeed { get; set; } + + public static List GetMemory(ComputerSystem system) + { + List list = new List(); + + ManagementObjectCollection returned = PSInterface.RunPowershell("SELECT * FROM Win32_PhysicalMemory"); + foreach (ManagementObject item in returned) + { + MemoryConfig module = new MemoryConfig(system); + + if (!MemoryModule.memoryTypeLookup.ContainsKey((uint)item["SMBIOSMemoryType"])) + { + continue; + } + + module.module.capacity = (ulong)item["Capacity"]; + module.currentClockspeed = (item["ConfiguredClockSpeed"] == null) ? 0 : (uint)item["ConfiguredClockSpeed"]; + module.module.maxClockspeed = (uint)item["Speed"]; + module.module.formFactor = (UInt16)item["FormFactor"]; + module.module.memoryType = (uint)item["SMBIOSMemoryType"]; + + module.module.partNubmer = (string)item["PartNumber"]; + module.module.serialNubmer = (string)item["SerialNumber"]; + + list.Add(module); + } + return list; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) return false; + + MemoryConfig memoryConfig = (MemoryConfig)obj; + if (this.module.Equals(memoryConfig.module) && + this.currentClockspeed == memoryConfig.currentClockspeed + ) + { + return true; + } + return false; + } + } +} \ No newline at end of file diff --git a/MemoryModule.cs b/MemoryModule.cs new file mode 100644 index 0000000..abfc34a --- /dev/null +++ b/MemoryModule.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; + +namespace powerLabel +{ + public class MemoryModule + { + public int id { get; set; } + public ulong capacity { get; set; } + + public uint maxClockspeed { get; set; } + + public uint formFactor { get; set; } // 8 -> DIMM 12 -> SODIMM https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/cim-chip + + public uint memoryType { get; set; } // https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.2.0.pdf Table 76 + + public static Dictionary memoryTypeLookup = new Dictionary() + { + [18] = "DDR", + [19] = "DDR2", + [20] = "DDR2 FB-DIMM", + [24] = "DDR3", + [26] = "DDR4", + [27] = "LPDDR", + [28] = "LPDDR2", + [29] = "LPDDR3", + [30] = "LPDDR4" + }; + + public string partNubmer { get; set; } + public string serialNubmer { get; set; } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) return false; + + MemoryModule memory = (MemoryModule)obj; + if (this.capacity == memory.capacity && + this.maxClockspeed == memory.maxClockspeed && + this.formFactor == memory.formFactor && + this.memoryType == memory.memoryType && + this.partNubmer.Trim() == memory.partNubmer.Trim() && + this.serialNubmer.Trim() == memory.serialNubmer.Trim() + ) + { + return true; + } + return false; + } + } +} diff --git a/Migrations/20220611123749_Createpowerlabeldb.Designer.cs b/Migrations/20220611123749_Createpowerlabeldb.Designer.cs new file mode 100644 index 0000000..837486d --- /dev/null +++ b/Migrations/20220611123749_Createpowerlabeldb.Designer.cs @@ -0,0 +1,328 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using powerLabel; + +namespace powerLabel.Migrations +{ + [DbContext(typeof(ComputerSystemContext))] + [Migration("20220611123749_Createpowerlabeldb")] + partial class Createpowerlabeldb + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.25") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("powerLabel.Bios", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("date") + .HasColumnType("datetime(6)"); + + b.Property("version") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("id"); + + b.ToTable("Bioses"); + }); + + modelBuilder.Entity("powerLabel.ComputerSystem", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("biosid") + .HasColumnType("int"); + + b.Property("motherboardid") + .HasColumnType("int"); + + b.Property("operatingSystemid") + .HasColumnType("int"); + + b.Property("processorAmount") + .HasColumnType("int"); + + b.Property("processorid") + .HasColumnType("int"); + + b.HasKey("id"); + + b.HasIndex("biosid"); + + b.HasIndex("motherboardid"); + + b.HasIndex("operatingSystemid"); + + b.HasIndex("processorid"); + + b.ToTable("ComputerSystems"); + }); + + modelBuilder.Entity("powerLabel.Disk", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("mediaType") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("model") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("serialNumber") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("size") + .HasColumnType("bigint unsigned"); + + b.HasKey("id"); + + b.ToTable("Disks"); + }); + + modelBuilder.Entity("powerLabel.DiskConfig", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("busType") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("computerSystemid") + .HasColumnType("int"); + + b.Property("diskid") + .HasColumnType("int"); + + b.Property("systemDisk") + .HasColumnType("tinyint(1)"); + + b.HasKey("id"); + + b.HasIndex("computerSystemid"); + + b.HasIndex("diskid"); + + b.ToTable("DiskConfigs"); + }); + + modelBuilder.Entity("powerLabel.MemoryConfig", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("currentClockspeed") + .HasColumnType("int unsigned"); + + b.Property("moduleid") + .HasColumnType("int"); + + b.Property("systemid") + .HasColumnType("int"); + + b.HasKey("id"); + + b.HasIndex("moduleid"); + + b.HasIndex("systemid"); + + b.ToTable("MemoryConfigs"); + }); + + modelBuilder.Entity("powerLabel.MemoryModule", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("capacity") + .HasColumnType("bigint unsigned"); + + b.Property("formFactor") + .HasColumnType("int unsigned"); + + b.Property("maxClockspeed") + .HasColumnType("int unsigned"); + + b.Property("memoryType") + .HasColumnType("int unsigned"); + + b.Property("partNubmer") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("serialNubmer") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("id"); + + b.ToTable("MemoryModules"); + }); + + modelBuilder.Entity("powerLabel.Motherboard", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("manufacturer") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("model") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("serialNumber") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("id"); + + b.ToTable("Motherboards"); + }); + + modelBuilder.Entity("powerLabel.OS", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("caption") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("language") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("id"); + + b.ToTable("OSes"); + }); + + modelBuilder.Entity("powerLabel.Processor", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("cores") + .HasColumnType("int unsigned"); + + b.Property("name") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("threads") + .HasColumnType("int unsigned"); + + b.HasKey("id"); + + b.ToTable("Processors"); + }); + + modelBuilder.Entity("powerLabel.VideoController", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("manufacturer") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("name") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("vram") + .HasColumnType("int unsigned"); + + b.HasKey("id"); + + b.ToTable("VideoControllers"); + }); + + modelBuilder.Entity("powerLabel.VideoControllerConfig", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("computerSystemid") + .HasColumnType("int"); + + b.Property("videoControllerid") + .HasColumnType("int"); + + b.HasKey("id"); + + b.HasIndex("computerSystemid"); + + b.HasIndex("videoControllerid"); + + b.ToTable("VideoControllerConfigs"); + }); + + modelBuilder.Entity("powerLabel.ComputerSystem", b => + { + b.HasOne("powerLabel.Bios", "bios") + .WithMany() + .HasForeignKey("biosid"); + + b.HasOne("powerLabel.Motherboard", "motherboard") + .WithMany() + .HasForeignKey("motherboardid"); + + b.HasOne("powerLabel.OS", "operatingSystem") + .WithMany() + .HasForeignKey("operatingSystemid"); + + b.HasOne("powerLabel.Processor", "processor") + .WithMany() + .HasForeignKey("processorid"); + }); + + modelBuilder.Entity("powerLabel.DiskConfig", b => + { + b.HasOne("powerLabel.ComputerSystem", "computerSystem") + .WithMany("diskConfigs") + .HasForeignKey("computerSystemid"); + + b.HasOne("powerLabel.Disk", "disk") + .WithMany() + .HasForeignKey("diskid"); + }); + + modelBuilder.Entity("powerLabel.MemoryConfig", b => + { + b.HasOne("powerLabel.MemoryModule", "module") + .WithMany() + .HasForeignKey("moduleid"); + + b.HasOne("powerLabel.ComputerSystem", "system") + .WithMany("memoryModules") + .HasForeignKey("systemid"); + }); + + modelBuilder.Entity("powerLabel.VideoControllerConfig", b => + { + b.HasOne("powerLabel.ComputerSystem", "computerSystem") + .WithMany("videoControllerConfigs") + .HasForeignKey("computerSystemid"); + + b.HasOne("powerLabel.VideoController", "videoController") + .WithMany() + .HasForeignKey("videoControllerid"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20220611123749_Createpowerlabeldb.cs b/Migrations/20220611123749_Createpowerlabeldb.cs new file mode 100644 index 0000000..e5b58c0 --- /dev/null +++ b/Migrations/20220611123749_Createpowerlabeldb.cs @@ -0,0 +1,327 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace powerLabel.Migrations +{ + public partial class Createpowerlabeldb : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Bioses", + columns: table => new + { + id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + version = table.Column(nullable: true), + date = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Bioses", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "Disks", + columns: table => new + { + id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + model = table.Column(nullable: true), + size = table.Column(nullable: false), + mediaType = table.Column(nullable: true), + serialNumber = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Disks", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "MemoryModules", + columns: table => new + { + id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + capacity = table.Column(nullable: false), + maxClockspeed = table.Column(nullable: false), + formFactor = table.Column(nullable: false), + memoryType = table.Column(nullable: false), + partNubmer = table.Column(nullable: true), + serialNubmer = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_MemoryModules", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "Motherboards", + columns: table => new + { + id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + model = table.Column(nullable: true), + manufacturer = table.Column(nullable: true), + serialNumber = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Motherboards", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "OSes", + columns: table => new + { + id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + caption = table.Column(nullable: true), + language = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_OSes", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "Processors", + columns: table => new + { + id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + name = table.Column(nullable: true), + cores = table.Column(nullable: false), + threads = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Processors", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "VideoControllers", + columns: table => new + { + id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + manufacturer = table.Column(nullable: true), + name = table.Column(nullable: true), + vram = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_VideoControllers", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "ComputerSystems", + columns: table => new + { + id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + motherboardid = table.Column(nullable: true), + biosid = table.Column(nullable: true), + processorAmount = table.Column(nullable: false), + processorid = table.Column(nullable: true), + operatingSystemid = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ComputerSystems", x => x.id); + table.ForeignKey( + name: "FK_ComputerSystems_Bioses_biosid", + column: x => x.biosid, + principalTable: "Bioses", + principalColumn: "id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_ComputerSystems_Motherboards_motherboardid", + column: x => x.motherboardid, + principalTable: "Motherboards", + principalColumn: "id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_ComputerSystems_OSes_operatingSystemid", + column: x => x.operatingSystemid, + principalTable: "OSes", + principalColumn: "id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_ComputerSystems_Processors_processorid", + column: x => x.processorid, + principalTable: "Processors", + principalColumn: "id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "DiskConfigs", + columns: table => new + { + id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + diskid = table.Column(nullable: true), + computerSystemid = table.Column(nullable: true), + systemDisk = table.Column(nullable: false), + busType = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_DiskConfigs", x => x.id); + table.ForeignKey( + name: "FK_DiskConfigs_ComputerSystems_computerSystemid", + column: x => x.computerSystemid, + principalTable: "ComputerSystems", + principalColumn: "id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_DiskConfigs_Disks_diskid", + column: x => x.diskid, + principalTable: "Disks", + principalColumn: "id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "MemoryConfigs", + columns: table => new + { + id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + moduleid = table.Column(nullable: true), + systemid = table.Column(nullable: true), + currentClockspeed = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MemoryConfigs", x => x.id); + table.ForeignKey( + name: "FK_MemoryConfigs_MemoryModules_moduleid", + column: x => x.moduleid, + principalTable: "MemoryModules", + principalColumn: "id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_MemoryConfigs_ComputerSystems_systemid", + column: x => x.systemid, + principalTable: "ComputerSystems", + principalColumn: "id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "VideoControllerConfigs", + columns: table => new + { + id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + videoControllerid = table.Column(nullable: true), + computerSystemid = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_VideoControllerConfigs", x => x.id); + table.ForeignKey( + name: "FK_VideoControllerConfigs_ComputerSystems_computerSystemid", + column: x => x.computerSystemid, + principalTable: "ComputerSystems", + principalColumn: "id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_VideoControllerConfigs_VideoControllers_videoControllerid", + column: x => x.videoControllerid, + principalTable: "VideoControllers", + principalColumn: "id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "IX_ComputerSystems_biosid", + table: "ComputerSystems", + column: "biosid"); + + migrationBuilder.CreateIndex( + name: "IX_ComputerSystems_motherboardid", + table: "ComputerSystems", + column: "motherboardid"); + + migrationBuilder.CreateIndex( + name: "IX_ComputerSystems_operatingSystemid", + table: "ComputerSystems", + column: "operatingSystemid"); + + migrationBuilder.CreateIndex( + name: "IX_ComputerSystems_processorid", + table: "ComputerSystems", + column: "processorid"); + + migrationBuilder.CreateIndex( + name: "IX_DiskConfigs_computerSystemid", + table: "DiskConfigs", + column: "computerSystemid"); + + migrationBuilder.CreateIndex( + name: "IX_DiskConfigs_diskid", + table: "DiskConfigs", + column: "diskid"); + + migrationBuilder.CreateIndex( + name: "IX_MemoryConfigs_moduleid", + table: "MemoryConfigs", + column: "moduleid"); + + migrationBuilder.CreateIndex( + name: "IX_MemoryConfigs_systemid", + table: "MemoryConfigs", + column: "systemid"); + + migrationBuilder.CreateIndex( + name: "IX_VideoControllerConfigs_computerSystemid", + table: "VideoControllerConfigs", + column: "computerSystemid"); + + migrationBuilder.CreateIndex( + name: "IX_VideoControllerConfigs_videoControllerid", + table: "VideoControllerConfigs", + column: "videoControllerid"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "DiskConfigs"); + + migrationBuilder.DropTable( + name: "MemoryConfigs"); + + migrationBuilder.DropTable( + name: "VideoControllerConfigs"); + + migrationBuilder.DropTable( + name: "Disks"); + + migrationBuilder.DropTable( + name: "MemoryModules"); + + migrationBuilder.DropTable( + name: "ComputerSystems"); + + migrationBuilder.DropTable( + name: "VideoControllers"); + + migrationBuilder.DropTable( + name: "Bioses"); + + migrationBuilder.DropTable( + name: "Motherboards"); + + migrationBuilder.DropTable( + name: "OSes"); + + migrationBuilder.DropTable( + name: "Processors"); + } + } +} diff --git a/Migrations/20220613080041_AddEvents.Designer.cs b/Migrations/20220613080041_AddEvents.Designer.cs new file mode 100644 index 0000000..15de6e3 --- /dev/null +++ b/Migrations/20220613080041_AddEvents.Designer.cs @@ -0,0 +1,366 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using powerLabel; + +namespace powerLabel.Migrations +{ + [DbContext(typeof(ComputerSystemContext))] + [Migration("20220613080041_AddEvents")] + partial class AddEvents + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.25") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("powerLabel.Bios", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("date") + .HasColumnType("datetime(6)"); + + b.Property("version") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("id"); + + b.ToTable("Bioses"); + }); + + modelBuilder.Entity("powerLabel.ComputerSystem", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("biosid") + .HasColumnType("int"); + + b.Property("motherboardid") + .HasColumnType("int"); + + b.Property("operatingSystemid") + .HasColumnType("int"); + + b.Property("processorAmount") + .HasColumnType("int"); + + b.Property("processorid") + .HasColumnType("int"); + + b.HasKey("id"); + + b.HasIndex("biosid"); + + b.HasIndex("motherboardid"); + + b.HasIndex("operatingSystemid"); + + b.HasIndex("processorid"); + + b.ToTable("ComputerSystems"); + }); + + modelBuilder.Entity("powerLabel.Disk", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("mediaType") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("model") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("serialNumber") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("size") + .HasColumnType("bigint unsigned"); + + b.HasKey("id"); + + b.ToTable("Disks"); + }); + + modelBuilder.Entity("powerLabel.DiskConfig", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("busType") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("computerSystemid") + .HasColumnType("int"); + + b.Property("diskid") + .HasColumnType("int"); + + b.Property("systemDisk") + .HasColumnType("tinyint(1)"); + + b.HasKey("id"); + + b.HasIndex("computerSystemid"); + + b.HasIndex("diskid"); + + b.ToTable("DiskConfigs"); + }); + + modelBuilder.Entity("powerLabel.Event", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("computerSystemid") + .HasColumnType("int"); + + b.Property("date") + .HasColumnType("datetime(6)"); + + b.Property("description") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("employee") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("name") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("note") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("id"); + + b.HasIndex("computerSystemid"); + + b.ToTable("Events"); + }); + + modelBuilder.Entity("powerLabel.MemoryConfig", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("currentClockspeed") + .HasColumnType("int unsigned"); + + b.Property("moduleid") + .HasColumnType("int"); + + b.Property("systemid") + .HasColumnType("int"); + + b.HasKey("id"); + + b.HasIndex("moduleid"); + + b.HasIndex("systemid"); + + b.ToTable("MemoryConfigs"); + }); + + modelBuilder.Entity("powerLabel.MemoryModule", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("capacity") + .HasColumnType("bigint unsigned"); + + b.Property("formFactor") + .HasColumnType("int unsigned"); + + b.Property("maxClockspeed") + .HasColumnType("int unsigned"); + + b.Property("memoryType") + .HasColumnType("int unsigned"); + + b.Property("partNubmer") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("serialNubmer") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("id"); + + b.ToTable("MemoryModules"); + }); + + modelBuilder.Entity("powerLabel.Motherboard", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("manufacturer") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("model") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("serialNumber") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("id"); + + b.ToTable("Motherboards"); + }); + + modelBuilder.Entity("powerLabel.OS", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("caption") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("language") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("id"); + + b.ToTable("OSes"); + }); + + modelBuilder.Entity("powerLabel.Processor", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("cores") + .HasColumnType("int unsigned"); + + b.Property("name") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("threads") + .HasColumnType("int unsigned"); + + b.HasKey("id"); + + b.ToTable("Processors"); + }); + + modelBuilder.Entity("powerLabel.VideoController", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("manufacturer") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("name") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("vram") + .HasColumnType("int unsigned"); + + b.HasKey("id"); + + b.ToTable("VideoControllers"); + }); + + modelBuilder.Entity("powerLabel.VideoControllerConfig", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("computerSystemid") + .HasColumnType("int"); + + b.Property("videoControllerid") + .HasColumnType("int"); + + b.HasKey("id"); + + b.HasIndex("computerSystemid"); + + b.HasIndex("videoControllerid"); + + b.ToTable("VideoControllerConfigs"); + }); + + modelBuilder.Entity("powerLabel.ComputerSystem", b => + { + b.HasOne("powerLabel.Bios", "bios") + .WithMany() + .HasForeignKey("biosid"); + + b.HasOne("powerLabel.Motherboard", "motherboard") + .WithMany() + .HasForeignKey("motherboardid"); + + b.HasOne("powerLabel.OS", "operatingSystem") + .WithMany() + .HasForeignKey("operatingSystemid"); + + b.HasOne("powerLabel.Processor", "processor") + .WithMany() + .HasForeignKey("processorid"); + }); + + modelBuilder.Entity("powerLabel.DiskConfig", b => + { + b.HasOne("powerLabel.ComputerSystem", "computerSystem") + .WithMany("diskConfigs") + .HasForeignKey("computerSystemid"); + + b.HasOne("powerLabel.Disk", "disk") + .WithMany() + .HasForeignKey("diskid"); + }); + + modelBuilder.Entity("powerLabel.Event", b => + { + b.HasOne("powerLabel.ComputerSystem", "computerSystem") + .WithMany() + .HasForeignKey("computerSystemid"); + }); + + modelBuilder.Entity("powerLabel.MemoryConfig", b => + { + b.HasOne("powerLabel.MemoryModule", "module") + .WithMany() + .HasForeignKey("moduleid"); + + b.HasOne("powerLabel.ComputerSystem", "system") + .WithMany("memoryModules") + .HasForeignKey("systemid"); + }); + + modelBuilder.Entity("powerLabel.VideoControllerConfig", b => + { + b.HasOne("powerLabel.ComputerSystem", "computerSystem") + .WithMany("videoControllerConfigs") + .HasForeignKey("computerSystemid"); + + b.HasOne("powerLabel.VideoController", "videoController") + .WithMany() + .HasForeignKey("videoControllerid"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Migrations/20220613080041_AddEvents.cs b/Migrations/20220613080041_AddEvents.cs new file mode 100644 index 0000000..a6f9ccd --- /dev/null +++ b/Migrations/20220613080041_AddEvents.cs @@ -0,0 +1,47 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace powerLabel.Migrations +{ + public partial class AddEvents : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Events", + columns: table => new + { + id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + employee = table.Column(nullable: true), + name = table.Column(nullable: true), + description = table.Column(nullable: true), + note = table.Column(nullable: true), + computerSystemid = table.Column(nullable: true), + date = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Events", x => x.id); + table.ForeignKey( + name: "FK_Events_ComputerSystems_computerSystemid", + column: x => x.computerSystemid, + principalTable: "ComputerSystems", + principalColumn: "id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "IX_Events_computerSystemid", + table: "Events", + column: "computerSystemid"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Events"); + } + } +} diff --git a/Migrations/ComputerSystemContextModelSnapshot.cs b/Migrations/ComputerSystemContextModelSnapshot.cs new file mode 100644 index 0000000..ea69b65 --- /dev/null +++ b/Migrations/ComputerSystemContextModelSnapshot.cs @@ -0,0 +1,364 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using powerLabel; + +namespace powerLabel.Migrations +{ + [DbContext(typeof(ComputerSystemContext))] + partial class ComputerSystemContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.25") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("powerLabel.Bios", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("date") + .HasColumnType("datetime(6)"); + + b.Property("version") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("id"); + + b.ToTable("Bioses"); + }); + + modelBuilder.Entity("powerLabel.ComputerSystem", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("biosid") + .HasColumnType("int"); + + b.Property("motherboardid") + .HasColumnType("int"); + + b.Property("operatingSystemid") + .HasColumnType("int"); + + b.Property("processorAmount") + .HasColumnType("int"); + + b.Property("processorid") + .HasColumnType("int"); + + b.HasKey("id"); + + b.HasIndex("biosid"); + + b.HasIndex("motherboardid"); + + b.HasIndex("operatingSystemid"); + + b.HasIndex("processorid"); + + b.ToTable("ComputerSystems"); + }); + + modelBuilder.Entity("powerLabel.Disk", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("mediaType") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("model") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("serialNumber") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("size") + .HasColumnType("bigint unsigned"); + + b.HasKey("id"); + + b.ToTable("Disks"); + }); + + modelBuilder.Entity("powerLabel.DiskConfig", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("busType") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("computerSystemid") + .HasColumnType("int"); + + b.Property("diskid") + .HasColumnType("int"); + + b.Property("systemDisk") + .HasColumnType("tinyint(1)"); + + b.HasKey("id"); + + b.HasIndex("computerSystemid"); + + b.HasIndex("diskid"); + + b.ToTable("DiskConfigs"); + }); + + modelBuilder.Entity("powerLabel.Event", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("computerSystemid") + .HasColumnType("int"); + + b.Property("date") + .HasColumnType("datetime(6)"); + + b.Property("description") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("employee") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("name") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("note") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("id"); + + b.HasIndex("computerSystemid"); + + b.ToTable("Events"); + }); + + modelBuilder.Entity("powerLabel.MemoryConfig", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("currentClockspeed") + .HasColumnType("int unsigned"); + + b.Property("moduleid") + .HasColumnType("int"); + + b.Property("systemid") + .HasColumnType("int"); + + b.HasKey("id"); + + b.HasIndex("moduleid"); + + b.HasIndex("systemid"); + + b.ToTable("MemoryConfigs"); + }); + + modelBuilder.Entity("powerLabel.MemoryModule", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("capacity") + .HasColumnType("bigint unsigned"); + + b.Property("formFactor") + .HasColumnType("int unsigned"); + + b.Property("maxClockspeed") + .HasColumnType("int unsigned"); + + b.Property("memoryType") + .HasColumnType("int unsigned"); + + b.Property("partNubmer") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("serialNubmer") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("id"); + + b.ToTable("MemoryModules"); + }); + + modelBuilder.Entity("powerLabel.Motherboard", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("manufacturer") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("model") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("serialNumber") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("id"); + + b.ToTable("Motherboards"); + }); + + modelBuilder.Entity("powerLabel.OS", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("caption") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("language") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("id"); + + b.ToTable("OSes"); + }); + + modelBuilder.Entity("powerLabel.Processor", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("cores") + .HasColumnType("int unsigned"); + + b.Property("name") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("threads") + .HasColumnType("int unsigned"); + + b.HasKey("id"); + + b.ToTable("Processors"); + }); + + modelBuilder.Entity("powerLabel.VideoController", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("manufacturer") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("name") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("vram") + .HasColumnType("int unsigned"); + + b.HasKey("id"); + + b.ToTable("VideoControllers"); + }); + + modelBuilder.Entity("powerLabel.VideoControllerConfig", b => + { + b.Property("id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("computerSystemid") + .HasColumnType("int"); + + b.Property("videoControllerid") + .HasColumnType("int"); + + b.HasKey("id"); + + b.HasIndex("computerSystemid"); + + b.HasIndex("videoControllerid"); + + b.ToTable("VideoControllerConfigs"); + }); + + modelBuilder.Entity("powerLabel.ComputerSystem", b => + { + b.HasOne("powerLabel.Bios", "bios") + .WithMany() + .HasForeignKey("biosid"); + + b.HasOne("powerLabel.Motherboard", "motherboard") + .WithMany() + .HasForeignKey("motherboardid"); + + b.HasOne("powerLabel.OS", "operatingSystem") + .WithMany() + .HasForeignKey("operatingSystemid"); + + b.HasOne("powerLabel.Processor", "processor") + .WithMany() + .HasForeignKey("processorid"); + }); + + modelBuilder.Entity("powerLabel.DiskConfig", b => + { + b.HasOne("powerLabel.ComputerSystem", "computerSystem") + .WithMany("diskConfigs") + .HasForeignKey("computerSystemid"); + + b.HasOne("powerLabel.Disk", "disk") + .WithMany() + .HasForeignKey("diskid"); + }); + + modelBuilder.Entity("powerLabel.Event", b => + { + b.HasOne("powerLabel.ComputerSystem", "computerSystem") + .WithMany() + .HasForeignKey("computerSystemid"); + }); + + modelBuilder.Entity("powerLabel.MemoryConfig", b => + { + b.HasOne("powerLabel.MemoryModule", "module") + .WithMany() + .HasForeignKey("moduleid"); + + b.HasOne("powerLabel.ComputerSystem", "system") + .WithMany("memoryModules") + .HasForeignKey("systemid"); + }); + + modelBuilder.Entity("powerLabel.VideoControllerConfig", b => + { + b.HasOne("powerLabel.ComputerSystem", "computerSystem") + .WithMany("videoControllerConfigs") + .HasForeignKey("computerSystemid"); + + b.HasOne("powerLabel.VideoController", "videoController") + .WithMany() + .HasForeignKey("videoControllerid"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Motherboard.cs b/Motherboard.cs new file mode 100644 index 0000000..3699fee --- /dev/null +++ b/Motherboard.cs @@ -0,0 +1,47 @@ +using System.Management; + +namespace powerLabel +{ + public class Motherboard + { + public int id { get; set; } + public string model { get; set; } + public string manufacturer { get; set; } + public string serialNumber { get; set; } + + public static Motherboard GetMotherboard() + { + Motherboard motherboard = new Motherboard(); + + foreach (ManagementObject system in PSInterface.RunPowershell("SELECT * FROM Win32_ComputerSystem")) + { + motherboard.model = (string)system["Model"]; + motherboard.manufacturer = (string)system["Manufacturer"]; + } + + foreach (ManagementObject bios in PSInterface.RunPowershell("SELECT * FROM Win32_Bios")) + { + motherboard.serialNumber = (string)bios["SerialNumber"]; + } + + return motherboard; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) return false; + + Motherboard mobo = (Motherboard)obj; + if (this.model.Trim() == mobo.model.Trim() && + this.manufacturer.Trim() == mobo.manufacturer.Trim() && + this.serialNumber.Trim() == mobo.serialNumber.Trim() + ) + { + return true; + } + return false; + } + } + + +} diff --git a/OS.cs b/OS.cs new file mode 100644 index 0000000..a3f69b3 --- /dev/null +++ b/OS.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using System.Management; + +namespace powerLabel +{ + public class OS + { + public int id { get; set; } + public string caption { get; set; } + public string language { get; set; } + + public static Dictionary languageTable = new Dictionary() + { + {9, "EN" }, + {1031, "DE" }, + {1033, "US" }, + {1043, "NL" } + }; + + public static OS GetOS() + { + OS os = new OS(); + foreach (ManagementObject item in PSInterface.RunPowershell("SELECT * FROM Win32_OperatingSystem")) + { + os.caption = (string)item["Caption"]; + os.language = languageTable[(uint)item["OSLanguage"]]; + } + + return os; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) return false; + + OS os = (OS)obj; + if (this.caption.Trim() == os.caption.Trim() && + this.language.Trim() == os.language.Trim() + ) + { + return true; + } + return false; + } + } +} diff --git a/PSInterface.cs b/PSInterface.cs new file mode 100644 index 0000000..5cee265 --- /dev/null +++ b/PSInterface.cs @@ -0,0 +1,20 @@ +using System.Management; + +namespace powerLabel +{ + public class PSInterface + { + public static ManagementObjectCollection RunPowershell(string command) + { + ManagementScope scope = new ManagementScope(); + scope.Connect(); + + //Query system for Operating System information + ObjectQuery query = new ObjectQuery(command); + ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query); + + ManagementObjectCollection queryCollection = searcher.Get(); + return queryCollection; + } + } +} diff --git a/Processor.cs b/Processor.cs new file mode 100644 index 0000000..8c32dde --- /dev/null +++ b/Processor.cs @@ -0,0 +1,47 @@ +using System.Management; + +namespace powerLabel +{ + public class Processor + { + public int id { get; set; } + public string name { get; set; } + public uint cores { get; set; } + public uint threads { get; set; } + + public static Processor GetProcessor(ComputerSystem system) + { + Processor processor = new Processor(); + + ManagementObjectCollection returned = PSInterface.RunPowershell("SELECT * FROM Win32_Processor"); + + ManagementObject item = null; + + foreach (ManagementObject obj in returned) + { + item = obj; + break; + } + + system.processorAmount = (returned.Count > 1) ? 2 : 1; + processor.name = (string)item["Name"]; + processor.cores = (uint)item["NumberOfCores"]; + processor.threads = (uint)item["NumberOfLogicalProcessors"]; + + return processor; + } + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) return false; + + Processor processor = (Processor)obj; + if (this.name.Trim() == processor.name.Trim() + ) + { + return true; + } + return false; + } + + } +} diff --git a/ProcessorConfig.cs b/ProcessorConfig.cs new file mode 100644 index 0000000..30a4ca3 --- /dev/null +++ b/ProcessorConfig.cs @@ -0,0 +1,51 @@ +using System.Management; + +namespace powerLabel +{ + public class ProcessorConfig + { + public int id { get; set; } + public Processor processor { get; set; } + public int amount { get; set; } + public ComputerSystem computerSystem { get; set; } + + public static ProcessorConfig GetProcessors(ComputerSystem system) + { + ProcessorConfig processorConfig = new ProcessorConfig(); + + ManagementObjectCollection returned = PSInterface.RunPowershell("SELECT * FROM Win32_Processor"); + + ManagementObject item = null; + + foreach (ManagementObject obj in returned) + { + item = obj; + break; + } + + processorConfig.amount = (returned.Count > 1) ? 2 : 1; + processorConfig.processor = new Processor(); + processorConfig.processor.name = (string)item["Name"]; + processorConfig.processor.cores = (uint)item["NumberOfCores"]; + processorConfig.processor.threads = (uint)item["NumberOfLogicalProcessors"]; + processorConfig.computerSystem = system; + + return processorConfig; + } + + public override bool Equals(object obj) + { + if (obj == null || GetType() != obj.GetType()) return false; + + ProcessorConfig processorConfig = (ProcessorConfig)obj; + if (this.processor.Equals(processorConfig.processor) && + this.amount == processorConfig.amount && + this.computerSystem.motherboard.Equals(processorConfig.computerSystem.motherboard) + ) + { + return true; + } + return false; + } + } +} \ No newline at end of file diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs new file mode 100644 index 0000000..d5513b4 --- /dev/null +++ b/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace powerLabel.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("powerLabel.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Properties/Resources.resx b/Properties/Resources.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/Properties/Resources.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SettingsHandler.cs b/SettingsHandler.cs new file mode 100644 index 0000000..6cc7891 --- /dev/null +++ b/SettingsHandler.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text.Json; + +namespace powerLabel +{ + public class SettingsHandler + { + + public class Settings + { + public List employees { get; set; } + public string printerHost { get; set; } + public string printerShareName { get; set; } + + public string databaseIP { get; set; } + public string databaseName { get; set; } + public string databaseUser { get; set; } + public string databasePass { get; set; } + + public Settings() + { + employees = new List(); + } + + } + + public static void WriteSettings(Settings settings) + { + string fileName = "settings.json"; + + var options = new JsonSerializerOptions { WriteIndented = true }; + string jsonString = JsonSerializer.Serialize(settings, options); + + File.WriteAllText(fileName, jsonString); + } + + public static Settings ReadSettings() + { + string fileName = "settings.json"; + + string jsonString = File.ReadAllText(fileName); + try + { + Settings output = JsonSerializer.Deserialize(jsonString); + return output; + } + catch (Exception) + { + WriteSettings(new Settings()); + return (new Settings()); + } + } + } + +} + diff --git a/SettingsWindow.xaml b/SettingsWindow.xaml new file mode 100644 index 0000000..dcf132c --- /dev/null +++ b/SettingsWindow.xaml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + +