Add actions and unit data
1 files changed, 46 insertions, 0 deletions
diff --git a/LibSystemdCli.Models/SystemdServiceData.cs b/LibSystemdCli.Models/SystemdServiceData.cs
new file mode 100644
index 0000000..1efcfd7
--- /dev/null
+++ b/LibSystemdCli.Models/SystemdServiceData.cs
@@ -0,0 +1,46 @@
+using System.Text.Json.Serialization;
+
+namespace LibSystemdCli.Models;
+
+public class SystemdServiceData {
+ [JsonPropertyName("data")]
+ public Dictionary<string, string> SingleData { get; set; } = new();
+
+ [JsonPropertyName("multiData")]
+ public Dictionary<string, List<string>> MultiData { get; set; } = new();
+
+ public bool IsRunning => Status is "active" or "reloading";
+ public string Status => GetSingleData("ActiveState") ?? "unknown";
+ public void AddData(string key, string value) {
+ if (MultiData.ContainsKey(key)) {
+ MultiData[key].Add(value);
+ }
+ else if (SingleData.ContainsKey(key)) {
+ MultiData[key] = new List<string> { SingleData[key], value };
+ SingleData.Remove(key);
+ }
+ else {
+ SingleData[key] = value;
+ }
+ }
+
+ public List<string>? GetData(string key) {
+ if (MultiData.TryGetValue(key, out var data)) {
+ return data;
+ }
+
+ if (SingleData.TryGetValue(key, out var value)) {
+ return new List<string> { value };
+ }
+
+ return null;
+ }
+
+ public string? GetSingleData(string key) {
+ if (SingleData.TryGetValue(key, out var value)) {
+ return value;
+ }
+
+ return null;
+ }
+}
\ No newline at end of file
|