Implementation
This commit is contained in:
12
CShocker/Shockers/Abstract/HTTPShocker.cs
Normal file
12
CShocker/Shockers/Abstract/HTTPShocker.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using CShocker.Shockers.ShockerSettings;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CShocker.Shockers.Abstract;
|
||||
|
||||
internal abstract class HttpShocker : Shocker
|
||||
{
|
||||
public HttpShocker(HttpShockerSettings settings, ILogger? logger = null) : base(settings, logger)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
12
CShocker/Shockers/Abstract/SerialShocker.cs
Normal file
12
CShocker/Shockers/Abstract/SerialShocker.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using CShocker.Shockers.ShockerSettings;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CShocker.Shockers.Abstract;
|
||||
|
||||
internal abstract class SerialShocker : Shocker
|
||||
{
|
||||
protected SerialShocker(SerialShockerSettings shockerSettings, ILogger? logger = null) : base(shockerSettings, logger)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
35
CShocker/Shockers/Abstract/Shocker.cs
Normal file
35
CShocker/Shockers/Abstract/Shocker.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using CShocker.Shockers.ShockerSettings.Abstract;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CShocker.Shockers.Abstract
|
||||
;
|
||||
|
||||
internal abstract class Shocker
|
||||
{
|
||||
protected readonly AShockerSettings ShockerSettings;
|
||||
protected readonly ILogger? Logger;
|
||||
|
||||
internal enum ControlAction { Beep, Vibrate, Shock, Nothing }
|
||||
|
||||
internal 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();
|
||||
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)
|
||||
ControlInternal(action, shocker, i, d);
|
||||
else
|
||||
ControlInternal(action, shockerId, i, d);
|
||||
}
|
||||
|
||||
protected abstract void ControlInternal(ControlAction action, string shockerId, int intensity, int duration);
|
||||
|
||||
protected Shocker(AShockerSettings shockerSettings, ILogger? logger = null)
|
||||
{
|
||||
this.ShockerSettings = shockerSettings;
|
||||
this.Logger = logger;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user