V1.1
less abstract stuff.
This commit is contained in:
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
17
CShocker/Shockers/Abstract/HttpShocker.cs
Normal file
17
CShocker/Shockers/Abstract/HttpShocker.cs
Normal 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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user