using Salmon.Core.Cliff; using System.Diagnostics; using Salmon.Core; namespace Salmon.Model.Monitor; public class Software : Element { [PersistentField] public DateTime? LastStart { get; set; } = DateTime.Now; [PersistentField] public bool? Online { get; set;} = true; [PersistentField] public int? ProcessId { get; set; } [PersistentField] public string? ProcessArguments { get; set; } [PersistentField] public string? ProcessUser { get; set; } [PersistentField] public string? MachineName { get; set; } [PersistentField] public string? ExecutablePath { get; set; } [PersistentField] public string? WorkingPath { get; set; } protected Software() { } public Software(string identifier) : base(identifier) { } public static IEnumerable FromPath(string path) { throw new NotImplementedException(); } public static Software FromLocal() { if (Environment.ProcessPath == null) throw new Exception($"Cannot create process for local non-pathed process."); return FromLocal(Helper.CreateIdFrom(Helper.GetMachineId(), Environment.ProcessPath)); } public static Software FromLocal(string id) { var currentProcess = Process.GetCurrentProcess(); var processPath = Environment.ProcessPath; var soft = new Software(id) { ShortName = System.AppDomain.CurrentDomain.FriendlyName, LongName = $"{Environment.MachineName}:{processPath}", MachineName = System.Environment.MachineName, ProcessId = currentProcess.Id, ExecutablePath = processPath, WorkingPath = Directory.GetCurrentDirectory(), LastStart = currentProcess.StartTime }; return soft; } }