This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unique Id generator for computer based
- Loading branch information
Showing
6 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/DynamicTranslator/Configuration/UniqueIdentifier/CpuBasedIdentifierProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Management; | ||
|
||
using Abp.Extensions; | ||
|
||
namespace DynamicTranslator.Configuration.UniqueIdentifier | ||
{ | ||
public class CpuBasedIdentifierProvider : IUniqueIdentifierProvider | ||
{ | ||
public string Get() | ||
{ | ||
var cpuInfo = string.Empty; | ||
var mc = new ManagementClass("win32_processor"); | ||
var moc = mc.GetInstances(); | ||
|
||
foreach (var o in moc) | ||
{ | ||
var mo = o.As<ManagementObject>(); | ||
cpuInfo = mo.Properties["processorID"].Value.ToString(); | ||
break; | ||
} | ||
|
||
return cpuInfo; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/DynamicTranslator/Configuration/UniqueIdentifier/HddBasedIdentifierProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Management; | ||
|
||
namespace DynamicTranslator.Configuration.UniqueIdentifier | ||
{ | ||
public class HddBasedIdentifierProvider : IUniqueIdentifierProvider | ||
{ | ||
public string Get() | ||
{ | ||
const string Drive = "C"; | ||
var dsk = new ManagementObject(@"win32_logicaldisk.deviceid=""" + Drive + @":"""); | ||
dsk.Get(); | ||
var volumeSerial = dsk["VolumeSerialNumber"].ToString(); | ||
|
||
return volumeSerial; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/DynamicTranslator/Configuration/UniqueIdentifier/IUniqueIdentifierProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace DynamicTranslator.Configuration.UniqueIdentifier | ||
{ | ||
public interface IUniqueIdentifierProvider | ||
{ | ||
string Get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/DynamicTranslator/Extensions/UniqueIdProviderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Collections.Generic; | ||
|
||
using Castle.Core.Internal; | ||
|
||
using DynamicTranslator.Configuration.UniqueIdentifier; | ||
|
||
namespace DynamicTranslator.Extensions | ||
{ | ||
public static class UniqueIdProviderExtensions | ||
{ | ||
public static string BuildForAll(this IEnumerable<IUniqueIdentifierProvider> providers) | ||
{ | ||
var uniqueId = string.Empty; | ||
|
||
providers.ForEach(provider => { uniqueId += provider.Get(); }); | ||
|
||
return uniqueId; | ||
} | ||
} | ||
} |