notifier mini lib

This commit is contained in:
mightypanders 2022-12-17 00:31:05 +01:00
parent 9deaba4736
commit f2a338a855
4 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MQTTProcessNotifierLib
{
public class MonitoredProcess
{
private string processName;
private string topicID;
private bool running;
public MonitoredProcess(string processName, string topicID, bool running = false)
{
this.processName = processName;
this.topicID = topicID;
this.running = running;
}
public string TopicID { get => topicID; set => topicID = value; }
public bool Running { get => running; set => running = value; }
public string ProcessName { get => processName; set => processName = value; }
public override string ToString() => $"{ProcessName}|{TopicID}|{Running}";
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MQTTProcessNotifierLib
{
public class MonitoringConfig
{
public MonitoringConfig(string systemName, List<string> processNames, string mQTTHostName, string mQTTUserName, string mQTTPassword, string mQTTEntityName, uint timeoutSeconds)
{
SystemName = systemName;
ProcessNames = processNames;
MQTTHostName = mQTTHostName;
MQTTUserName = mQTTUserName;
MQTTPassword = mQTTPassword;
MQTTEntityName = mQTTEntityName;
TimeoutSeconds = timeoutSeconds;
}
public string SystemName { get; set; }
public List<string> ProcessNames { get; set; }
public string MQTTHostName { get; set; }
public string MQTTUserName { get; set; }
public string MQTTPassword { get; set; }
public string MQTTEntityName { get; set; }
public uint TimeoutSeconds { get; set; }
}
}

View File

@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Text.Json;
namespace MQTTnet.Samples.Helpers;
public static class ObjectExtensions
{
public static TObject DumpToConsole<TObject>(this TObject @object)
{
var output = "NULL";
if (@object != null)
{
output = JsonSerializer.Serialize(@object, new JsonSerializerOptions
{
WriteIndented = true
});
}
Console.WriteLine($"[{@object?.GetType().Name}]:\r\n{output}");
return @object;
}
}