SRO.Platform.Operations 1.0.1
SRO.Platform.Operations Framework
SRO.Platform.Operations is a cross-platform .NET library that provides a unified API for monitoring and managing a host — whether that is a physical compute server, a virtual machine, or a container. It abstracts Windows and Linux OS APIs behind consistent interfaces so that consuming applications can inspect host identity, memory, running processes, and system services without writing platform-specific code.
Table of Contents
- Supported Platforms & Target Frameworks
- Installation
- Namespace Overview
- Module Reference
- Privilege Requirements
- Building from Source
Supported Platforms & Target Frameworks
| Target Framework | Windows | Linux |
|---|---|---|
.NET Framework 4.8 (net48) |
✅ | ❌ |
.NET 8.0 (net8.0) |
✅ | ✅ |
.NET 9.0 (net9.0) |
✅ | ✅ |
macOS is not currently supported. APIs that have no cross-platform implementation throw PlatformNotSupportedException or NotImplementedException at runtime.
Installation
Install the package from NuGet:
dotnet add package SRO.Platform.Operations
Or reference it directly in your project file:
<PackageReference Include="SRO.Platform.Operations" Version="1.0.0" />
Namespace Overview
| Namespace | Purpose |
|---|---|
SRO.Platform.Operations.Host |
Hostname, domain, IP addresses, OS identity |
SRO.Platform.Operations.Memory |
Physical and swap memory usage snapshots |
SRO.Platform.Operations.Process |
Enumeration and termination of running processes |
SRO.Platform.Operations.Service |
Enumeration and lifecycle control of OS services |
SRO.Platform.Operations.Common |
Formatting helpers and privilege checking utilities |
All data retrieval entry points follow the naming pattern *DetailsSource with a single public Get*() method. No constructor calls are needed on the source classes.
Module Reference
Host Information
Namespace: SRO.Platform.Operations.Host
HostDetailsSource.GetHostDetails() returns a HostDetails snapshot describing the current machine.
using SRO.Platform.Operations.Host;
HostDetails host = HostDetailsSource.GetHostDetails();
Console.WriteLine(host.Hostname); // e.g. "MYSERVER"
Console.WriteLine(host.DomainName); // e.g. "corp.example.com"
Console.WriteLine(host.OperatingSystem); // "Windows" | "Linux" | "MacOS"
Console.WriteLine(host.OSVersion); // e.g. "10.0.22631.0"
Console.WriteLine(host.OSVendor); // "Microsoft" | "Ubuntu" | "Red Hat" …
Console.WriteLine(host.DistributionVersion);// e.g. "22.04" (Linux) or full version string (Windows)
foreach (string ip in host.IP4Addresses)
Console.WriteLine("IPv4: " + ip);
foreach (string ip in host.IP6Addresses)
Console.WriteLine("IPv6: " + ip);
HostDetails properties
| Property | Type | Description |
|---|---|---|
Hostname |
string |
Network-assigned machine name |
DomainName |
string |
Network domain the host belongs to |
OperatingSystem |
string |
OS platform name |
OSVersion |
string |
OS kernel/build version string |
OSVendor |
string |
Organisation that produced the OS |
DistributionVersion |
string |
Distribution release identifier (e.g. 22.04) |
IP4Addresses |
List<string> |
All bound IPv4 addresses |
IP6Addresses |
List<string> |
All bound IPv6 addresses |
Memory Details
Namespace: SRO.Platform.Operations.Memory
OSMemoryDetailsSource.GetCurrentMemoryDetails() returns an immutable HostMemoryDetails snapshot. Each call refreshes the underlying data from the OS.
using SRO.Platform.Operations.Memory;
using SRO.Platform.Operations.Common;
HostMemoryDetails mem = OSMemoryDetailsSource.GetCurrentMemoryDetails();
Console.WriteLine("Total RAM : " + FormatUtility.AutoFormatMemory(mem.TotalPhysicalMemory));
Console.WriteLine("Used RAM : " + FormatUtility.AutoFormatMemory(mem.CurrentUsedMemory));
Console.WriteLine("Free RAM : " + FormatUtility.AutoFormatMemory(mem.CurrentFreeMemory));
Console.WriteLine("RAM usage : " + FormatUtility.UsedPercentage(mem.CurrentUsedMemory, mem.TotalPhysicalMemory));
Console.WriteLine("Total Swap : " + FormatUtility.AutoFormatMemory(mem.TotalSwapMemory));
Console.WriteLine("Used Swap : " + FormatUtility.AutoFormatMemory(mem.CurrentUsedSwapMemory));
HostMemoryDetails properties (all ulong, values in bytes)
| Property | Description |
|---|---|
TotalPhysicalMemory |
Total installed physical RAM |
CurrentUsedMemory |
Physical RAM currently in use |
CurrentFreeMemory |
Physical RAM currently available |
TotalSwapMemory |
Total swap / page-file space |
CurrentUsedSwapMemory |
Swap space currently in use |
CurrentFreeSwapMemory |
Swap space currently available |
Note: Windows uses
GlobalMemoryStatusEx; Linux reads/proc/meminfo. ThrowsPlatformNotSupportedExceptionon unsupported platforms.
Process Details
Namespace: SRO.Platform.Operations.Process
OSProcessDetailsSource.GetProcessDetails() returns IEnumerable<OSProcess> — one entry per running process.
using SRO.Platform.Operations.Process;
using SRO.Platform.Operations.Common;
foreach (OSProcess p in OSProcessDetailsSource.GetProcessDetails())
{
Console.WriteLine($"PID {p.Id} {p.ProcessName,-40} " +
$"RAM: {FormatUtility.AutoFormatMemory(p.CurrentMemoryUsed),-12} " +
$"User: {p.Username}");
}
To terminate a process (requires elevated privileges):
OSProcess target = OSProcessDetailsSource.GetProcessDetails()
.FirstOrDefault(p => p.ProcessName == "myapp");
target?.Kill();
OSProcess members
| Member | Kind | Description |
|---|---|---|
Id |
uint |
OS-assigned process ID (PID) |
ProcessName |
string |
Executable name without extension |
CurrentMemoryUsed |
ulong |
Working-set memory in bytes |
TotalProcessorTime |
TimeSpan |
Cumulative CPU time; TimeSpan.MinValue if inaccessible |
Username |
string |
Owner account name; "N/A" if indeterminate |
NETProcess |
System.Diagnostics.Process |
Underlying .NET process object for advanced use |
Kill() |
method | Forcefully terminates the process |
ToString() |
method | Human-readable summary (PID, name, RAM, CPU time, user) |
Service Details
Namespace: SRO.Platform.Operations.Service
OSServiceDetailsSource.GetServiceDetails() returns List<OSServiceDetails> — one entry per registered OS service (Windows services or Linux systemd units).
using SRO.Platform.Operations.Service;
foreach (OSServiceDetails svc in OSServiceDetailsSource.GetServiceDetails())
{
Console.WriteLine($"{svc.ServiceName,-40} [{svc.Status}]");
}
Inspecting and controlling a specific service
OSServiceDetails svc = OSServiceDetailsSource.GetServiceDetails()
.FirstOrDefault(s => s.ServiceName == "wuauserv"); // Windows Update
if (svc != null)
{
Console.WriteLine($"Status : {svc.Status}");
Console.WriteLine($"CanStop : {svc.CanStop}");
if (svc.Status == ServiceStatus.Running && svc.CanStop)
{
svc.Stop();
svc.WaitForStatus(ServiceStatus.Stopped, TimeSpan.FromSeconds(30));
}
else if (svc.Status == ServiceStatus.Stopped)
{
svc.Start();
svc.WaitForStatus(ServiceStatus.Running, TimeSpan.FromSeconds(30));
}
}
OSServiceDetails members
| Member | Kind | Description |
|---|---|---|
ServiceName |
string |
Internal OS service name (e.g. wuauserv) |
DisplayName |
string |
Human-readable name (e.g. Windows Update) |
Status |
ServiceStatus |
Current execution state |
CanStop |
bool |
Whether Stop() is supported |
CanPauseAndContinue |
bool |
Whether Pause() / Continue() are supported |
CanShutdown |
bool |
Whether the service receives system shutdown notification |
Start() / Start(string[]) |
method | Start the service, optionally with arguments |
Stop() |
method | Stop the service |
Pause() / Continue() |
method | Pause or resume the service |
Refresh() |
method | Re-read service state from the OS |
WaitForStatus(status) |
method | Block until the service reaches the desired status |
WaitForStatus(status, timeout) |
method | Block with a timeout |
Close() |
method | Release the underlying service handle |
Note: Service control operations (start, stop, pause) require elevated privileges. Check
PrivilegeChecker.HasElevatedPrivileged()before attempting them.
Common Utilities
Namespace: SRO.Platform.Operations.Common
FormatUtility — display-ready formatting
using SRO.Platform.Operations.Common;
FormatUtility.AutoFormatMemory(1_073_741_824UL); // → "1.00 GB"
FormatUtility.AutoFormatMemory(512_000UL); // → "500.00 KB"
FormatUtility.UsedPercentage(3UL, 8UL); // → "37.50%"
FormatUtility.UsagePercentage(3.0, 8.0); // → "37.50%"
FormatUtility.AutoFormatPercentage(0.375); // → "37.50%"
var items = new List<string> { "alpha", "beta" };
FormatUtility.AutoFormatCollection(items); // → {"alpha", "beta"}
PrivilegeChecker — elevation detection
using SRO.Platform.Operations.Common;
if (PrivilegeChecker.HasElevatedPrivileged())
{
// Safe to perform administrative operations
}
// Alternatively, throw UnauthorizedAccessException if not elevated:
PrivilegeChecker.AssertAdministratorPrivileges();
On Windows, elevation is determined by both the built-in Administrator role and the UAC token elevation flag. On Linux/macOS, it checks for UID 0 (root).
Privilege Requirements
| Operation | Elevated Required |
|---|---|
HostDetailsSource.GetHostDetails() |
No |
OSMemoryDetailsSource.GetCurrentMemoryDetails() |
No |
OSProcessDetailsSource.GetProcessDetails() |
No (some process properties return "N/A" for processes owned by other users without elevation) |
OSProcess.Kill() |
Yes — for processes not owned by the current user |
OSServiceDetailsSource.GetServiceDetails() |
No |
OSServiceDetails.Start() / Stop() / Pause() |
Yes |
Use PrivilegeChecker.HasElevatedPrivileged() to gate administrative operations at runtime.
Building from Source
cd SRO.Platform.Operations
dotnet build SRO.Platform.Operations.slnx
The OSAccess project in this repository is a console test harness demonstrating all four modules. It is not shipped as part of the NuGet package.
To run the test harness on Linux you may need elevated privileges for the service control demonstration:
sudo dotnet run --project OSAccess
On Windows, launch the terminal as Administrator before running.
No packages depend on SRO.Platform.Operations.
.NET Framework 4.8
- System.ServiceProcess.ServiceController (>= 10.0.9)
- Tmds.DBus.Protocol (>= 0.94.1)
.NET 8.0
- System.ServiceProcess.ServiceController (>= 10.0.9)
- Tmds.DBus.Protocol (>= 0.94.1)
.NET 9.0
- System.ServiceProcess.ServiceController (>= 10.0.9)
- Tmds.DBus.Protocol (>= 0.94.1)
| Version | Downloads | Last updated |
|---|---|---|
| 1.0.1 | 5 | 09/02/2026 |