/// <summary>
/// Loop through all the modules until an update or shutdown is pending
/// </summary>
protected virtual void ModuleLooper()
{
Log.NewLine();
// Only run the service if there isn't a shutdown or update pending
// However, keep looping if a power operation is only Requested as
// the request may be aborted
while (!Power.ShuttingDown && !Power.Updating)
{
LoopData = GetLoopData() ?? new Response();
// Stop looping as soon as a shutdown or update pending
foreach (var module in GetModules().TakeWhile(module => !Power.ShuttingDown && !Power.Updating))
{
// Entry file formatting
Log.NewLine();
Log.PaddedHeader(module.GetName());
Log.Entry("Client-Info", $"Client Version: {Settings.Get("Version")}");
Log.Entry("Client-Info", $"Client OS: {Settings.OS}");
Log.Entry("Client-Info", $"Server Version: {Settings.Get("ServerVersion")}");
try
{
var subResponse = LoopData.GetSubResponse(module.GetName().ToLower());
if (subResponse == null)
continue;
module.Start(subResponse);
}
catch (Exception ex)
{
Log.Error(Name, "Unable to run module");
Log.Error(Name, ex);
}
// Entry file formatting
Log.Divider();
Log.NewLine();
}
// Skip checking for sleep time if there is a shutdown or update pending
if (Power.ShuttingDown || Power.Updating) break;
// Once all modules have been run, sleep for the set time
var sleepTime = GetSleepTime() ?? DEFAULT_SLEEP_TIME;
Log.Entry(Name, $"Sleeping for {sleepTime} seconds");
Thread.Sleep(sleepTime * 1000);
}
}