SafeDispatch/AppServerWatchDogService/ConfigHelper.cs

141 lines
4.9 KiB
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AppServerWatchDogService
{
public static class ConfigHelper
{
private static readonly String RESTART_TCP_SERVICE = "restartTCPService";
private static readonly String TCP_SERVICE_NAME = "serviceName";
private static readonly String HOUR = "hour";
private static readonly String RESTART_TYPE = "restartType";
private static readonly String MINUTE = "minute";
private static readonly String APPSERVER_MONITOR = "monitorAppServer";
private static readonly String TIMEOUT_BEFORE_STARTING_TO_MONITOR_IN_SEC = "timeoutBeforeStartingToMonitorSec";
private static readonly String NUMBER_OF_MISSING_PINGS_WITH_APP_SERVER_ALLOWED = "numberOfMissingPingsWithAppServerAllowed";
public static Boolean AppServerMonitor
{
get
{
if (ConfigurationManager.AppSettings.AllKeys.Contains(APPSERVER_MONITOR))
return Convert.ToBoolean(ConfigurationManager.AppSettings[APPSERVER_MONITOR]);
else
return false;
}
}
public static bool HasAppServerMonitor => ConfigurationManager.AppSettings.AllKeys.Contains(APPSERVER_MONITOR);
public static Int32 TimeoutBeforeStartingToMonitorSec
{
get
{
if (ConfigurationManager.AppSettings.AllKeys.Contains(TIMEOUT_BEFORE_STARTING_TO_MONITOR_IN_SEC))
{
int result = 15;
Int32.TryParse(ConfigurationManager.AppSettings[TIMEOUT_BEFORE_STARTING_TO_MONITOR_IN_SEC], out result);
return result;
}
else
return 15;
}
}
public static bool HasTimeoutBeforeStartingToMonitorSecSet => ConfigurationManager.AppSettings.AllKeys.Contains(TIMEOUT_BEFORE_STARTING_TO_MONITOR_IN_SEC);
public static Int32 NumberOfMissingPingsWithAppServerAllowed
{
get
{
if (ConfigurationManager.AppSettings.AllKeys.Contains(NUMBER_OF_MISSING_PINGS_WITH_APP_SERVER_ALLOWED))
{
int result = 3;
Int32.TryParse(ConfigurationManager.AppSettings[NUMBER_OF_MISSING_PINGS_WITH_APP_SERVER_ALLOWED], out result);
return result;
}
else
return 20;
}
}
public static bool HasNumberOfSecondsOfUnresponsiveAppServerAllowedSet
=> ConfigurationManager.AppSettings.AllKeys.Contains(NUMBER_OF_MISSING_PINGS_WITH_APP_SERVER_ALLOWED);
public static Int32 SetHour
{
get
{
if (ConfigurationManager.AppSettings.AllKeys.Contains(HOUR))
return Int32.Parse(ConfigurationManager.AppSettings[HOUR]);
else
return 0;
}
}
public static bool HasHourSet => ConfigurationManager.AppSettings.AllKeys.Contains(HOUR);
public static Int32 SetMinute
{
get
{
if (ConfigurationManager.AppSettings.AllKeys.Contains(MINUTE))
return Int32.Parse(ConfigurationManager.AppSettings[MINUTE]);
else
return 0;
}
}
public static bool HasMinuteSet => ConfigurationManager.AppSettings.AllKeys.Contains(MINUTE);
public static String SetRestartType
{
get
{
if (ConfigurationManager.AppSettings.AllKeys.Contains(RESTART_TYPE))
return ConfigurationManager.AppSettings[RESTART_TYPE];
else
return "fix";
}
}
public static bool HasRestartTypeSet => ConfigurationManager.AppSettings.AllKeys.Contains(RESTART_TYPE);
public static Boolean RestartTCPService
{
get
{
if (ConfigurationManager.AppSettings.AllKeys.Contains(RESTART_TCP_SERVICE))
return Convert.ToBoolean(ConfigurationManager.AppSettings[RESTART_TCP_SERVICE]);
else
return false;
}
}
public static bool HasRestartTCPService => ConfigurationManager.AppSettings.AllKeys.Contains(RESTART_TCP_SERVICE);
public static String TCPServiceName
{
get
{
if (ConfigurationManager.AppSettings.AllKeys.Contains(TCP_SERVICE_NAME))
return Convert.ToString(ConfigurationManager.AppSettings[TCP_SERVICE_NAME]);
else
return "";
}
}
public static bool HasTCPServiceName => ConfigurationManager.AppSettings.AllKeys.Contains(TCP_SERVICE_NAME);
}
}