diff --git a/CShocker/CShocker.csproj b/CShocker/CShocker.csproj
index 26dc168..8b998f4 100644
--- a/CShocker/CShocker.csproj
+++ b/CShocker/CShocker.csproj
@@ -7,7 +7,7 @@
Glax
https://github.com/C9Glax/CShocker
git
- 1.0.5
+ 1.1
diff --git a/CShocker/Shockers/Abstract/HTTPShocker.cs b/CShocker/Shockers/Abstract/HTTPShocker.cs
deleted file mode 100644
index e5b2db9..0000000
--- a/CShocker/Shockers/Abstract/HTTPShocker.cs
+++ /dev/null
@@ -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)
- {
-
- }
-}
\ No newline at end of file
diff --git a/CShocker/Shockers/Abstract/HttpShocker.cs b/CShocker/Shockers/Abstract/HttpShocker.cs
new file mode 100644
index 0000000..d3a026e
--- /dev/null
+++ b/CShocker/Shockers/Abstract/HttpShocker.cs
@@ -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 shockerIds, IntensityRange intensityRange, DurationRange durationRange, string endpoint, string apiKey, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, logger)
+ {
+ Endpoint = endpoint;
+ ApiKey = apiKey;
+ }
+}
\ No newline at end of file
diff --git a/CShocker/Shockers/Abstract/SerialShocker.cs b/CShocker/Shockers/Abstract/SerialShocker.cs
index 29bdd5d..ccb3e2a 100644
--- a/CShocker/Shockers/Abstract/SerialShocker.cs
+++ b/CShocker/Shockers/Abstract/SerialShocker.cs
@@ -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 shockerIds, IntensityRange intensityRange, DurationRange durationRange, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, logger)
{
- throw new NotImplementedException();
}
}
\ No newline at end of file
diff --git a/CShocker/Shockers/Abstract/Shocker.cs b/CShocker/Shockers/Abstract/Shocker.cs
index b01b6f4..673e3dc 100644
--- a/CShocker/Shockers/Abstract/Shocker.cs
+++ b/CShocker/Shockers/Abstract/Shocker.cs
@@ -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 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 shockerIds, IntensityRange intensityRange, DurationRange durationRange, ILogger? logger = null)
{
- this.ShockerSettings = shockerSettings;
+ this.ShockerIds = shockerIds;
+ this.IntensityRange = intensityRange;
+ this.DurationRange = durationRange;
this.Logger = logger;
}
}
\ No newline at end of file
diff --git a/CShocker/Shockers/OpenShockHttp.cs b/CShocker/Shockers/OpenShockHttp.cs
index 8415a34..244a70a 100644
--- a/CShocker/Shockers/OpenShockHttp.cs
+++ b/CShocker/Shockers/OpenShockHttp.cs
@@ -1,16 +1,17 @@
using System.Net.Http.Headers;
using System.Text;
+using CShocker.Ranges;
using CShocker.Shockers.Abstract;
-using CShocker.Shockers.ShockerSettings;
using Microsoft.Extensions.Logging;
namespace CShocker.Shockers;
public class OpenShockHttp : HttpShocker
{
+
protected override void ControlInternal(ControlAction action, string shockerId, int intensity, int duration)
{
- HttpRequestMessage request = new (HttpMethod.Post, $"{((HttpShockerSettings)ShockerSettings).Endpoint}/1/shockers/control")
+ HttpRequestMessage request = new (HttpMethod.Post, $"{Endpoint}/1/shockers/control")
{
Headers =
{
@@ -24,8 +25,8 @@ public class OpenShockHttp : HttpShocker
$"\"duration\": {duration}"+
"}]", Encoding.UTF8, new MediaTypeHeaderValue("application/json"))
};
- request.Headers.Add("OpenShockToken", ((HttpShockerSettings)ShockerSettings).ApiKey);
- HttpResponseMessage response = ((HttpShockerSettings)ShockerSettings).HttpClient.Send(request);
+ request.Headers.Add("OpenShockToken", ApiKey);
+ HttpResponseMessage response = (HttpClient.Send(request));
this.Logger?.Log(LogLevel.Debug, $"{request.RequestUri} response: {response.StatusCode}");
}
@@ -40,8 +41,7 @@ public class OpenShockHttp : HttpShocker
};
}
- internal OpenShockHttp(HttpShockerSettings settings, ILogger? logger = null) : base(settings, logger)
+ public OpenShockHttp(List shockerIds, IntensityRange intensityRange, DurationRange durationRange, string endpoint, string apiKey, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, endpoint, apiKey, logger)
{
-
}
}
\ No newline at end of file
diff --git a/CShocker/Shockers/OpenShockSerial.cs b/CShocker/Shockers/OpenShockSerial.cs
index 1418f45..563980b 100644
--- a/CShocker/Shockers/OpenShockSerial.cs
+++ b/CShocker/Shockers/OpenShockSerial.cs
@@ -1,12 +1,12 @@
-using CShocker.Shockers.Abstract;
-using CShocker.Shockers.ShockerSettings;
+using CShocker.Ranges;
+using CShocker.Shockers.Abstract;
using Microsoft.Extensions.Logging;
namespace CShocker.Shockers;
public class OpenShockSerial : SerialShocker
{
- public OpenShockSerial(SerialShockerSettings shockerSettings, ILogger? logger = null) : base(shockerSettings, logger)
+ public OpenShockSerial(List shockerIds, IntensityRange intensityRange, DurationRange durationRange, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, logger)
{
throw new NotImplementedException();
}
diff --git a/CShocker/Shockers/PiShockHttp.cs b/CShocker/Shockers/PiShockHttp.cs
index 8c9403c..e84d02f 100644
--- a/CShocker/Shockers/PiShockHttp.cs
+++ b/CShocker/Shockers/PiShockHttp.cs
@@ -1,12 +1,12 @@
-using CShocker.Shockers.Abstract;
-using CShocker.Shockers.ShockerSettings;
+using CShocker.Ranges;
+using CShocker.Shockers.Abstract;
using Microsoft.Extensions.Logging;
namespace CShocker.Shockers;
public class PiShockHttp : HttpShocker
{
- public PiShockHttp(HttpShockerSettings settings, ILogger? logger = null) : base(settings, logger)
+ public PiShockHttp(List shockerIds, IntensityRange intensityRange, DurationRange durationRange, string endpoint, string apiKey, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, endpoint, apiKey, logger)
{
throw new NotImplementedException();
}
diff --git a/CShocker/Shockers/PiShockSerial.cs b/CShocker/Shockers/PiShockSerial.cs
index db4181d..84c5d76 100644
--- a/CShocker/Shockers/PiShockSerial.cs
+++ b/CShocker/Shockers/PiShockSerial.cs
@@ -1,12 +1,12 @@
-using CShocker.Shockers.Abstract;
-using CShocker.Shockers.ShockerSettings;
+using CShocker.Ranges;
+using CShocker.Shockers.Abstract;
using Microsoft.Extensions.Logging;
namespace CShocker.Shockers;
public class PiShockSerial : SerialShocker
{
- public PiShockSerial(SerialShockerSettings shockerSettings, ILogger? logger = null) : base(shockerSettings, logger)
+ public PiShockSerial(List shockerIds, IntensityRange intensityRange, DurationRange durationRange, ILogger? logger = null) : base(shockerIds, intensityRange, durationRange, logger)
{
throw new NotImplementedException();
}
diff --git a/CShocker/Shockers/ShockerSettings/Abstract/AShockerSettings.cs b/CShocker/Shockers/ShockerSettings/Abstract/AShockerSettings.cs
deleted file mode 100644
index d3d6193..0000000
--- a/CShocker/Shockers/ShockerSettings/Abstract/AShockerSettings.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using CShocker.Ranges;
-
-namespace CShocker.Shockers.ShockerSettings.Abstract;
-
-public abstract record AShockerSettings(string[] ShockerIds, IntensityRange Intensity, DurationRange Duration)
-{
- internal readonly string[] ShockerIds = ShockerIds;
- internal readonly IntensityRange Intensity = Intensity;
- internal readonly DurationRange Duration = Duration;
-}
\ No newline at end of file
diff --git a/CShocker/Shockers/ShockerSettings/HttpShockerSettings.cs b/CShocker/Shockers/ShockerSettings/HttpShockerSettings.cs
deleted file mode 100644
index 31a08ee..0000000
--- a/CShocker/Shockers/ShockerSettings/HttpShockerSettings.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using CShocker.Ranges;
-using CShocker.Shockers.ShockerSettings.Abstract;
-
-namespace CShocker.Shockers.ShockerSettings;
-
-public record HttpShockerSettings(string[] ShockerIds, IntensityRange Intensity, DurationRange Duration, string ApiKey, string Endpoint) : AShockerSettings(ShockerIds, Intensity, Duration)
-{
- internal readonly HttpClient HttpClient = new ();
- internal readonly string ApiKey = ApiKey, Endpoint = Endpoint;
-}
\ No newline at end of file
diff --git a/CShocker/Shockers/ShockerSettings/SerialShockerSettings.cs b/CShocker/Shockers/ShockerSettings/SerialShockerSettings.cs
deleted file mode 100644
index 399fae9..0000000
--- a/CShocker/Shockers/ShockerSettings/SerialShockerSettings.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using CShocker.Ranges;
-using CShocker.Shockers.ShockerSettings.Abstract;
-
-namespace CShocker.Shockers.ShockerSettings;
-
-public record SerialShockerSettings(string[] ShockerIds, IntensityRange Intensity, DurationRange Duration) : AShockerSettings(ShockerIds, Intensity, Duration)
-{
-
-}
\ No newline at end of file