mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2026-11-10 20:46:24 +00:00
Changed all namespaces to file-scope
This commit is contained in:
1 parent
a0c6ccebea
commit
30624035f1
353 files changed
+35775
-36129
No files matched your search
@@ -1,10 +1,9 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace RGB.NET.Devices.SteelSeries.API.Model
|
||||
namespace RGB.NET.Devices.SteelSeries.API.Model;
|
||||
|
||||
internal class CoreProps
|
||||
{
|
||||
internal class CoreProps
|
||||
{
|
||||
[JsonPropertyName("address")]
|
||||
public string? Address { get; set; }
|
||||
}
|
||||
}
|
||||
[JsonPropertyName("address")]
|
||||
public string? Address { get; set; }
|
||||
}
|
||||
@@ -1,35 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace RGB.NET.Devices.SteelSeries.API.Model
|
||||
namespace RGB.NET.Devices.SteelSeries.API.Model;
|
||||
|
||||
internal class Event
|
||||
{
|
||||
internal class Event
|
||||
#region Properties & Fields
|
||||
|
||||
[JsonPropertyName("game")]
|
||||
public string? Game { get; set; }
|
||||
|
||||
[JsonPropertyName("event")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
// ReSharper disable once CollectionNeverQueried.Global
|
||||
[JsonPropertyName("data")]
|
||||
public Dictionary<string, object> Data { get; } = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public Event()
|
||||
{ }
|
||||
|
||||
public Event(Game game, string name)
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
[JsonPropertyName("game")]
|
||||
public string? Game { get; set; }
|
||||
|
||||
[JsonPropertyName("event")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
// ReSharper disable once CollectionNeverQueried.Global
|
||||
[JsonPropertyName("data")]
|
||||
public Dictionary<string, object> Data { get; } = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public Event()
|
||||
{ }
|
||||
|
||||
public Event(Game game, string name)
|
||||
{
|
||||
this.Name = name;
|
||||
Game = game.Name;
|
||||
}
|
||||
|
||||
#endregion
|
||||
this.Name = name;
|
||||
Game = game.Name;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,30 +1,29 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace RGB.NET.Devices.SteelSeries.API.Model
|
||||
namespace RGB.NET.Devices.SteelSeries.API.Model;
|
||||
|
||||
internal class Game
|
||||
{
|
||||
internal class Game
|
||||
#region Properties & Fields
|
||||
|
||||
[JsonPropertyName("game")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("game_display_name")]
|
||||
public string? DisplayName { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public Game()
|
||||
{ }
|
||||
|
||||
public Game(string name, string displayName)
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
[JsonPropertyName("game")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("game_display_name")]
|
||||
public string? DisplayName { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public Game()
|
||||
{ }
|
||||
|
||||
public Game(string name, string displayName)
|
||||
{
|
||||
Name = name;
|
||||
DisplayName = displayName;
|
||||
}
|
||||
|
||||
#endregion
|
||||
Name = name;
|
||||
DisplayName = displayName;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,30 +1,29 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace RGB.NET.Devices.SteelSeries.API.Model
|
||||
namespace RGB.NET.Devices.SteelSeries.API.Model;
|
||||
|
||||
internal class GoLispHandler
|
||||
{
|
||||
internal class GoLispHandler
|
||||
#region Properties & Fields
|
||||
|
||||
[JsonPropertyName("game")]
|
||||
public string? Game { get; set; }
|
||||
|
||||
[JsonPropertyName("golisp")]
|
||||
public string? Handler { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public GoLispHandler()
|
||||
{ }
|
||||
|
||||
public GoLispHandler(Game game, string handler)
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
[JsonPropertyName("game")]
|
||||
public string? Game { get; set; }
|
||||
|
||||
[JsonPropertyName("golisp")]
|
||||
public string? Handler { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public GoLispHandler()
|
||||
{ }
|
||||
|
||||
public GoLispHandler(Game game, string handler)
|
||||
{
|
||||
this.Handler = handler;
|
||||
Game = game.Name;
|
||||
}
|
||||
|
||||
#endregion
|
||||
this.Handler = handler;
|
||||
Game = game.Name;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -8,16 +8,16 @@ using System.Text;
|
||||
using System.Text.Json;
|
||||
using RGB.NET.Devices.SteelSeries.API.Model;
|
||||
|
||||
namespace RGB.NET.Devices.SteelSeries.API
|
||||
{
|
||||
internal static class SteelSeriesSDK
|
||||
{
|
||||
#region Constants
|
||||
namespace RGB.NET.Devices.SteelSeries.API;
|
||||
|
||||
private const string GAME_NAME = "RGBNET";
|
||||
private const string GAME_DISPLAYNAME = "RGB.NET";
|
||||
private const string EVENT_NAME = "UPDATELEDS";
|
||||
private static readonly string HANDLER = $@"(define (getZone x)
|
||||
internal static class SteelSeriesSDK
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const string GAME_NAME = "RGBNET";
|
||||
private const string GAME_DISPLAYNAME = "RGB.NET";
|
||||
private const string EVENT_NAME = "UPDATELEDS";
|
||||
private static readonly string HANDLER = $@"(define (getZone x)
|
||||
(case x
|
||||
{string.Join(Environment.NewLine, Enum.GetValues(typeof(SteelSeriesLedId))
|
||||
.Cast<SteelSeriesLedId>()
|
||||
@@ -48,106 +48,105 @@ namespace RGB.NET.Devices.SteelSeries.API
|
||||
|
||||
(add-custom-zone '(""num-5"" 93))"; //HACK DarthAffe 07.10.2021: Custom zone to workaround a SDK-issue (https://github.com/SteelSeries/gamesense-sdk/issues/85)
|
||||
|
||||
private const string CORE_PROPS_WINDOWS = "%PROGRAMDATA%/SteelSeries/SteelSeries Engine 3/coreProps.json";
|
||||
private const string CORE_PROPS_OSX = "/Library/Application Support/SteelSeries Engine 3/coreProps.json";
|
||||
private const string CORE_PROPS_WINDOWS = "%PROGRAMDATA%/SteelSeries/SteelSeries Engine 3/coreProps.json";
|
||||
private const string CORE_PROPS_OSX = "/Library/Application Support/SteelSeries Engine 3/coreProps.json";
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
// ReSharper disable InconsistentNaming
|
||||
#region Properties & Fields
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
private static readonly HttpClient _client = new();
|
||||
private static readonly Game _game = new(GAME_NAME, GAME_DISPLAYNAME);
|
||||
private static readonly Event _event = new(_game, EVENT_NAME);
|
||||
private static string? _baseUrl;
|
||||
private static readonly HttpClient _client = new();
|
||||
private static readonly Game _game = new(GAME_NAME, GAME_DISPLAYNAME);
|
||||
private static readonly Event _event = new(_game, EVENT_NAME);
|
||||
private static string? _baseUrl;
|
||||
|
||||
internal static bool IsInitialized => !string.IsNullOrWhiteSpace(_baseUrl);
|
||||
internal static bool IsInitialized => !string.IsNullOrWhiteSpace(_baseUrl);
|
||||
|
||||
// ReSharper restore InconsistentNaming
|
||||
#endregion
|
||||
// ReSharper restore InconsistentNaming
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
#region Methods
|
||||
|
||||
internal static bool Initialize()
|
||||
internal static bool Initialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
string corePropsPath = GetCorePropsPath();
|
||||
if (!string.IsNullOrWhiteSpace(corePropsPath) && File.Exists(corePropsPath))
|
||||
{
|
||||
string corePropsPath = GetCorePropsPath();
|
||||
if (!string.IsNullOrWhiteSpace(corePropsPath) && File.Exists(corePropsPath))
|
||||
CoreProps? coreProps = JsonSerializer.Deserialize<CoreProps>(File.ReadAllText(corePropsPath));
|
||||
_baseUrl = coreProps?.Address;
|
||||
if (_baseUrl != null)
|
||||
{
|
||||
CoreProps? coreProps = JsonSerializer.Deserialize<CoreProps>(File.ReadAllText(corePropsPath));
|
||||
_baseUrl = coreProps?.Address;
|
||||
if (_baseUrl != null)
|
||||
{
|
||||
if (!_baseUrl.StartsWith("http://", StringComparison.Ordinal))
|
||||
_baseUrl = "http://" + _baseUrl;
|
||||
if (!_baseUrl.StartsWith("http://", StringComparison.Ordinal))
|
||||
_baseUrl = "http://" + _baseUrl;
|
||||
|
||||
RegisterGame(_game);
|
||||
RegisterGoLispHandler(new GoLispHandler(_game, HANDLER));
|
||||
}
|
||||
RegisterGame(_game);
|
||||
RegisterGoLispHandler(new GoLispHandler(_game, HANDLER));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
_baseUrl = null;
|
||||
}
|
||||
return IsInitialized;
|
||||
}
|
||||
|
||||
internal static void UpdateLeds(string device, IList<(string zone, int[] color)> data)
|
||||
catch
|
||||
{
|
||||
_event.Data.Clear();
|
||||
_event.Data.Add("value", device);
|
||||
_event.Data.Add("colors", data.Select(x => x.color).ToList());
|
||||
_event.Data.Add("zones", data.Select(x => x.zone).ToList());
|
||||
|
||||
TriggerEvent(_event);
|
||||
_baseUrl = null;
|
||||
}
|
||||
return IsInitialized;
|
||||
}
|
||||
|
||||
internal static void SendHeartbeat() => SendHeartbeat(_game);
|
||||
internal static void UpdateLeds(string device, IList<(string zone, int[] color)> data)
|
||||
{
|
||||
_event.Data.Clear();
|
||||
_event.Data.Add("value", device);
|
||||
_event.Data.Add("colors", data.Select(x => x.color).ToList());
|
||||
_event.Data.Add("zones", data.Select(x => x.zone).ToList());
|
||||
|
||||
internal static void ResetLeds() => StopGame(_game);
|
||||
TriggerEvent(_event);
|
||||
}
|
||||
|
||||
internal static void Dispose()
|
||||
{
|
||||
if (IsInitialized)
|
||||
ResetLeds();
|
||||
internal static void SendHeartbeat() => SendHeartbeat(_game);
|
||||
|
||||
_client.Dispose();
|
||||
}
|
||||
internal static void ResetLeds() => StopGame(_game);
|
||||
|
||||
internal static void Dispose()
|
||||
{
|
||||
if (IsInitialized)
|
||||
ResetLeds();
|
||||
|
||||
_client.Dispose();
|
||||
}
|
||||
|
||||
#pragma warning disable IDE0051 // Remove unused private members
|
||||
// ReSharper disable UnusedMethodReturnValue.Local
|
||||
// ReSharper disable UnusedMember.Local
|
||||
private static string TriggerEvent(Event e) => PostJson("/game_event", e);
|
||||
private static string RegisterGoLispHandler(GoLispHandler handler) => PostJson("/load_golisp_handlers", handler);
|
||||
private static string RegisterEvent(Event e) => PostJson("/register_game_event", e);
|
||||
private static string UnregisterEvent(Event e) => PostJson("/remove_game_event", e);
|
||||
private static string RegisterGame(Game game) => PostJson("/game_metadata", game);
|
||||
private static string UnregisterGame(Game game) => PostJson("/remove_game", game);
|
||||
private static string StopGame(Game game) => PostJson("/stop_game", game);
|
||||
private static string SendHeartbeat(Game game) => PostJson("/game_heartbeat", game);
|
||||
// ReSharper restore UnusedMember.Local
|
||||
// ReSharper restore UnusedMethodReturnValue.Local
|
||||
// ReSharper disable UnusedMethodReturnValue.Local
|
||||
// ReSharper disable UnusedMember.Local
|
||||
private static string TriggerEvent(Event e) => PostJson("/game_event", e);
|
||||
private static string RegisterGoLispHandler(GoLispHandler handler) => PostJson("/load_golisp_handlers", handler);
|
||||
private static string RegisterEvent(Event e) => PostJson("/register_game_event", e);
|
||||
private static string UnregisterEvent(Event e) => PostJson("/remove_game_event", e);
|
||||
private static string RegisterGame(Game game) => PostJson("/game_metadata", game);
|
||||
private static string UnregisterGame(Game game) => PostJson("/remove_game", game);
|
||||
private static string StopGame(Game game) => PostJson("/stop_game", game);
|
||||
private static string SendHeartbeat(Game game) => PostJson("/game_heartbeat", game);
|
||||
// ReSharper restore UnusedMember.Local
|
||||
// ReSharper restore UnusedMethodReturnValue.Local
|
||||
#pragma warning restore IDE0051 // Remove unused private members
|
||||
|
||||
private static string PostJson(string urlSuffix, object o)
|
||||
{
|
||||
string payload = JsonSerializer.Serialize(o);
|
||||
return _client.PostAsync(_baseUrl + urlSuffix, new StringContent(payload, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result;
|
||||
}
|
||||
|
||||
private static string GetCorePropsPath()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
return Environment.ExpandEnvironmentVariables(CORE_PROPS_WINDOWS);
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
return CORE_PROPS_OSX;
|
||||
|
||||
throw new InvalidOperationException("Unknown operating system.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
private static string PostJson(string urlSuffix, object o)
|
||||
{
|
||||
string payload = JsonSerializer.Serialize(o);
|
||||
return _client.PostAsync(_baseUrl + urlSuffix, new StringContent(payload, Encoding.UTF8, "application/json")).Result.Content.ReadAsStringAsync().Result;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetCorePropsPath()
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
return Environment.ExpandEnvironmentVariables(CORE_PROPS_WINDOWS);
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||
return CORE_PROPS_OSX;
|
||||
|
||||
throw new InvalidOperationException("Unknown operating system.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user