using MaksIT.UScheduler.Shared.Helpers; namespace MaksIT.UScheduler.Shared; /// /// Base configuration class for scheduled tasks. /// public abstract class TaskConfiguration { /// /// Gets or sets the path to the executable or script. /// public required string Path { get; set; } /// /// Gets or sets whether this task is disabled. Disabled tasks will not be executed. /// public bool Disabled { get; set; } /// /// Gets or sets a short description shown in the UI list. /// public string? Description { get; set; } /// /// Hosts this task may run on ( names). Empty = Windows and Linux. /// public List Platforms { get; set; } = []; } /// /// Configuration for a scheduled PowerShell script. /// public class PowershellScript : TaskConfiguration { /// /// Gets or sets the display name for the script in the UI. /// When set in settings, overrides the name from scriptsettings.json. /// public string? Name { get; set; } /// /// Gets or sets whether the script must be digitally signed. /// When true, only scripts with valid Authenticode signatures will be executed. /// public bool IsSigned { get; set; } = true; } /// /// Configuration for a scheduled process/executable. /// public class ProcessConfiguration : TaskConfiguration { /// /// Gets or sets the command-line arguments to pass to the process. /// public string[]? Args { get; set; } /// /// Gets or sets whether the process should automatically restart on failure. /// public bool RestartOnFailure { get; set; } } /// /// Root configuration class for the UScheduler service. /// Stored in machine-wide settings.json (ProgramData), not next to the exe. /// public class Configuration { /// /// Gets or sets the service name used for Windows SCM / systemd registration. /// public string ServiceName { get; set; } = "MaksIT.UScheduler"; /// /// Gets or sets the directory path for log files. /// Default: C:\MaksIT\Logs on Windows. /// public string LogDir { get; set; } = HostPaths.DefaultLogDirectory; /// /// Gets or sets the directory that contains scheduled scripts. /// Default: C:\MaksIT\Scripts on Windows. Relative script paths resolve against this folder. /// public string ScriptsDir { get; set; } = HostPaths.DefaultScriptsDirectory; /// /// Gets or sets the list of PowerShell scripts to execute. /// public List Powershell { get; set; } = []; /// /// Gets or sets the list of processes/executables to run. /// public List Processes { get; set; } = []; public void EnsureDefaults() { if (string.IsNullOrWhiteSpace(ServiceName)) ServiceName = "MaksIT.UScheduler"; if (string.IsNullOrWhiteSpace(LogDir)) LogDir = HostPaths.DefaultLogDirectory; if (string.IsNullOrWhiteSpace(ScriptsDir)) ScriptsDir = HostPaths.DefaultScriptsDirectory; Powershell ??= []; Processes ??= []; } public string GetEffectiveScriptsDirectory() => HostPaths.ResolveScriptsDirectory(ScriptsDir); public string GetEffectiveLogDirectory(string? baseDirectory = null) { var logDir = string.IsNullOrWhiteSpace(LogDir) ? HostPaths.DefaultLogDirectory : LogDir; return PathHelper.ResolvePath(logDir, baseDirectory ?? AppContext.BaseDirectory); } public string ResolveScriptPath(string path) => PathHelper.ResolvePath(path, GetEffectiveScriptsDirectory()); }