less abstract stuff.
This commit is contained in:
2024-01-17 17:59:10 +01:00
parent f89daca90d
commit 7f4232ef54
12 changed files with 47 additions and 69 deletions

View File

@ -1,12 +0,0 @@
using CShocker.Shockers.ShockerSettings;
using Microsoft.Extensions.Logging;
namespace CShocker.Shockers.Abstract;
public abstract class HttpShocker : Shocker
{
public HttpShocker(HttpShockerSettings settings, ILogger? logger = null) : base(settings, logger)
{
}
}

View File

@ -0,0 +1,17 @@
using CShocker.Ranges;
using Microsoft.Extensions.Logging;
namespace CShocker.Shockers.Abstract;
public abstract class HttpShocker : Shocker
{
protected readonly HttpClient HttpClient = new();
protected string Endpoint { get; init; }
protected string ApiKey { get; init; }
protected HttpShocker(List<string> shockerIds, IntensityRange intensityRange, DurationRange durationRange, string endpoint, string apiKey, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, logger)
{
Endpoint = endpoint;
ApiKey = apiKey;
}
}

View File

@ -1,12 +1,11 @@
using CShocker.Shockers.ShockerSettings;
using CShocker.Ranges;
using Microsoft.Extensions.Logging;
namespace CShocker.Shockers.Abstract;
public abstract class SerialShocker : Shocker
{
protected SerialShocker(SerialShockerSettings shockerSettings, ILogger? logger = null) : base(shockerSettings, logger)
protected SerialShocker(List<string> shockerIds, IntensityRange intensityRange, DurationRange durationRange, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, logger)
{
throw new NotImplementedException();
}
}

View File

@ -1,23 +1,24 @@
using CShocker.Shockers.ShockerSettings.Abstract;
using CShocker.Ranges;
using Microsoft.Extensions.Logging;
namespace CShocker.Shockers.Abstract
;
namespace CShocker.Shockers.Abstract;
public abstract class Shocker
{
protected readonly AShockerSettings ShockerSettings;
protected readonly List<string> ShockerIds;
protected readonly IntensityRange IntensityRange;
protected readonly DurationRange DurationRange;
protected readonly ILogger? Logger;
public void Control(ControlAction action, string? shockerId = null, int? intensity = null, int? duration = null)
{
int i = intensity ?? ShockerSettings.Intensity.GetRandomRangeValue();
int d = duration ?? ShockerSettings.Duration.GetRandomRangeValue();
int i = intensity ?? IntensityRange.GetRandomRangeValue();
int d = duration ?? DurationRange.GetRandomRangeValue();
this.Logger?.Log(LogLevel.Information, $"{action} {(intensity is not null ? $"Overwrite {i}" : $"{i}")} {(duration is not null ? $"Overwrite {d}" : $"{d}")}");
if (action is ControlAction.Nothing)
return;
if(shockerId is null)
foreach (string shocker in ShockerSettings.ShockerIds)
foreach (string shocker in ShockerIds)
ControlInternal(action, shocker, i, d);
else
ControlInternal(action, shockerId, i, d);
@ -25,9 +26,11 @@ public abstract class Shocker
protected abstract void ControlInternal(ControlAction action, string shockerId, int intensity, int duration);
protected Shocker(AShockerSettings shockerSettings, ILogger? logger = null)
protected Shocker(List<string> shockerIds, IntensityRange intensityRange, DurationRange durationRange, ILogger? logger = null)
{
this.ShockerSettings = shockerSettings;
this.ShockerIds = shockerIds;
this.IntensityRange = intensityRange;
this.DurationRange = durationRange;
this.Logger = logger;
}
}