Files
ironlicensing-dotnet/MachineIdentifier.cs
logikonline 811fb6ceec Add net9.0 support for server/console applications
- Add net9.0 to TargetFrameworks for non-MAUI apps
- Create FileSystemLicenseCache for file-based license storage
- Create Platforms/Net9/MachineIdentifier using Environment APIs
- Add conditional compilation for MAUI vs non-MAUI platforms
- Update ServiceCollectionExtensions for conditional DI registration
- Bump version to 1.2.0

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-03 20:52:08 -05:00

61 lines
1.8 KiB
C#

using System.Security.Cryptography;
using System.Text;
using System.Runtime.InteropServices;
namespace IronLicensing.Client;
public partial class MachineIdentifier : IMachineIdentifier
{
public string GetMachineId()
{
var components = GetMachineComponents();
var combined = string.Join("|", components.Where(c => !string.IsNullOrEmpty(c)));
if (string.IsNullOrEmpty(combined))
{
#if MAUI
// Fallback to a device-specific identifier (MAUI platforms)
combined = DeviceInfo.Current.Idiom.ToString() + "|" +
DeviceInfo.Current.Manufacturer + "|" +
DeviceInfo.Current.Model;
#else
// Fallback for server/console apps
combined = Environment.MachineName + "|" +
Environment.UserName + "|" +
RuntimeInformation.OSDescription;
#endif
}
using var sha256 = SHA256.Create();
var hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(combined));
return Convert.ToBase64String(hash)[..32];
}
public string GetMachineName()
{
#if MAUI
return DeviceInfo.Current.Name ?? Environment.MachineName ?? "Unknown";
#else
return Environment.MachineName ?? "Unknown";
#endif
}
public string GetPlatform()
{
#if MAUI
return DeviceInfo.Current.Platform.ToString();
#else
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return "Windows";
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
return "macOS";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
return "Linux";
return RuntimeInformation.OSDescription;
#endif
}
// Platform-specific implementation
private partial List<string> GetMachineComponents();
}