From ad2ff8a4dc0f8902a06c30d72d77d44121d977d8 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Tue, 14 Apr 2026 16:54:01 +0330 Subject: [PATCH] last ... --- Helpers/XOsHelper.cs | 168 ------------------------------------------- 1 file changed, 168 deletions(-) delete mode 100644 Helpers/XOsHelper.cs diff --git a/Helpers/XOsHelper.cs b/Helpers/XOsHelper.cs deleted file mode 100644 index 900903c..0000000 --- a/Helpers/XOsHelper.cs +++ /dev/null @@ -1,168 +0,0 @@ -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Threading.Tasks; -using xCommons.Extensions; -using xExceptions.Attributes; -using xExceptions.Constants; - -namespace xAiApi.Helpers -{ - /// - /// Several OS Type ... - /// - public enum XOSType - { - [StringValue("Unknown")] - XUnknown, - - [StringValue("Mac")] - XMacOs, - - [StringValue("Linux")] - XLinux, - - [StringValue("Windows")] - XWindows, - - [StringValue("FreeBSD")] - XFreeBSD, - } - - /// - /// OS Command Execution Result ... - /// - public class XOSCMDResult - { - /// - /// Execution Result ... - /// - /// - public string Result { get; set; } - - /// - /// Execution Error ... - /// - /// - public string Error { get; set; } - } - - public static class XOsHelper - { - /// - /// Retrieve OS Type ... - /// - /// - public static XOSType GetOSType() - { - // - XOSType result = XOSType.XUnknown; - - // - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - result = XOSType.XMacOs; - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - result = XOSType.XLinux; - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - result = XOSType.XWindows; - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) - { - result = XOSType.XFreeBSD; - } - - // - return result; - } - - /// - /// Retrieve OS Description ... - /// - /// - public static string GetOSDescription() - { - // - var result = RuntimeInformation.OSDescription; - return result; - } - - /// - /// Execute an Specified Command ... - /// - /// Specified Command - /// Command Arguments - /// - public static async Task Execute( - string cmd, - string args - ) - { - // - var result = new XOSCMDResult - { - Error = "Unknown", - }; - - // - try - { - // - // Validate CMD ... - var isValid = !cmd.IsNullOrEmpty(); - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - // Validate OS Type ... - XOSType osType = GetOSType(); - isValid = osType != XOSType.XUnknown; - if (!isValid) - { - XException.InvalidArgs.Throw(); - } - - // - ProcessStartInfo psi = new ProcessStartInfo(); - - // - psi.FileName = cmd; - psi.Arguments = args; - psi.UseShellExecute = false; - psi.RedirectStandardError = true; - psi.RedirectStandardOutput = true; - - // - Process process = Process.Start(psi); - - // - // Read the output - string output = process.StandardOutput.ReadToEnd(); - string error = process.StandardError.ReadToEnd(); - - // - await process.WaitForExitAsync(); - - // - result = new XOSCMDResult - { - Error = error, - Result = output, - }; - } - catch (Exception ex) - { - result.Error = ex.Message; - } - - // - return result; - } - } -} \ No newline at end of file