From 4e4067606bb7fa2937d18b1508fa18322657b861 Mon Sep 17 00:00:00 2001 From: Ian Clanton-Thuon Date: Sat, 25 Nov 2023 00:15:51 -0800 Subject: [PATCH] Run csharpier. --- .../Api/GetCustomEqualizerSettings.cs | 7 +- .../Api/GetInterfaceInformation.cs | 2 - .../Api/GetPlaybackModeSettings.cs | 3 +- .../Api/GetPlayingContentInfo.cs | 7 +- .../Api/GetVolumeInformation.cs | 1 - .../Api/Util/NotificationManager.cs | 322 ++++++++++++------ SonyAudioControlApi/Api/Util/Request.cs | 22 +- SonyAudioControlApi/EnumConverter.cs | 33 +- .../Exceptions/HttpException.cs | 4 +- .../Exceptions/UnexpectedResponseException.cs | 6 +- .../SingleElementArrayConverter.cs | 20 +- SonyAudioControlApi/TargetType.cs | 1 - SonyAudioControlApiTester/Program.cs | 13 +- 13 files changed, 301 insertions(+), 140 deletions(-) diff --git a/SonyAudioControlApi/Api/GetCustomEqualizerSettings.cs b/SonyAudioControlApi/Api/GetCustomEqualizerSettings.cs index 02231ab..029d3f3 100644 --- a/SonyAudioControlApi/Api/GetCustomEqualizerSettings.cs +++ b/SonyAudioControlApi/Api/GetCustomEqualizerSettings.cs @@ -8,13 +8,16 @@ public sealed partial class Api /// /// Gets information about the current custom equalizer settings. /// - public async Task GetCustomEqualizerSettingsAsync(CustomEqualizerSettingsResult.EqualizerTarget target = CustomEqualizerSettingsResult.EqualizerTarget.AllTargets) + public async Task GetCustomEqualizerSettingsAsync( + CustomEqualizerSettingsResult.EqualizerTarget target = + CustomEqualizerSettingsResult.EqualizerTarget.AllTargets + ) { return await this.makeRequestAsync( ApiLib.Audio, ApiVersion.V10, "getCustomEqualizerSettings", - new CustomEqualizerSettingsProps() { Target = target } + new CustomEqualizerSettingsProps() { Target = target } ); } } diff --git a/SonyAudioControlApi/Api/GetInterfaceInformation.cs b/SonyAudioControlApi/Api/GetInterfaceInformation.cs index 968cdc0..cefdeb0 100644 --- a/SonyAudioControlApi/Api/GetInterfaceInformation.cs +++ b/SonyAudioControlApi/Api/GetInterfaceInformation.cs @@ -98,7 +98,5 @@ public enum DeviceCategory /// [JsonPropertyName("serverName")] public string ServerName { get; set; } - } } - diff --git a/SonyAudioControlApi/Api/GetPlaybackModeSettings.cs b/SonyAudioControlApi/Api/GetPlaybackModeSettings.cs index 4492110..4a46dec 100644 --- a/SonyAudioControlApi/Api/GetPlaybackModeSettings.cs +++ b/SonyAudioControlApi/Api/GetPlaybackModeSettings.cs @@ -19,7 +19,8 @@ public sealed partial class Api /// If this is null or "" is set, it means all sources for the mode. /// public async Task GetPlaybackModeSettingsAsync( - PlaybackModeSettingsResult.PlaybackTarget target = PlaybackModeSettingsResult.PlaybackTarget.AllTargets, + PlaybackModeSettingsResult.PlaybackTarget target = + PlaybackModeSettingsResult.PlaybackTarget.AllTargets, string uri = null ) { diff --git a/SonyAudioControlApi/Api/GetPlayingContentInfo.cs b/SonyAudioControlApi/Api/GetPlayingContentInfo.cs index 4ccaea7..65d8154 100644 --- a/SonyAudioControlApi/Api/GetPlayingContentInfo.cs +++ b/SonyAudioControlApi/Api/GetPlayingContentInfo.cs @@ -17,7 +17,9 @@ public sealed partial class Api /// /// Only extInput:* sources have types implemented. /// - public async Task GetPlayingContentInfoAsync(string output = null) + public async Task GetPlayingContentInfoAsync( + string output = null + ) { return await this.makeRequestAsync( ApiLib.AvContent, @@ -36,7 +38,8 @@ internal sealed class PlayingContentInfoProps public sealed class PlayingContentInfoResult { - public class PlayingContentStateInfo { + public class PlayingContentStateInfo + { [JsonEnumConverter] public enum PlayingContentState { diff --git a/SonyAudioControlApi/Api/GetVolumeInformation.cs b/SonyAudioControlApi/Api/GetVolumeInformation.cs index 3a55059..7412459 100644 --- a/SonyAudioControlApi/Api/GetVolumeInformation.cs +++ b/SonyAudioControlApi/Api/GetVolumeInformation.cs @@ -101,5 +101,4 @@ public enum MuteStatus [JsonPropertyName("volume")] public int Volume { get; set; } } - } diff --git a/SonyAudioControlApi/Api/Util/NotificationManager.cs b/SonyAudioControlApi/Api/Util/NotificationManager.cs index 6a1f6e8..4903553 100644 --- a/SonyAudioControlApi/Api/Util/NotificationManager.cs +++ b/SonyAudioControlApi/Api/Util/NotificationManager.cs @@ -13,7 +13,10 @@ namespace SonyAudioControlApi { public sealed partial class Api { - public delegate void NotificationEventHandler(DeviceDescriptor sender, TResult result); + public delegate void NotificationEventHandler( + DeviceDescriptor sender, + TResult result + ); public event NotificationEventHandler OnExternalTerminalStatusNotification; public event NotificationEventHandler OnPlayingContentInfoNotification; @@ -26,7 +29,10 @@ private class NotificationManager private ApiLibNotificationManager avContentNotificationManager; private ApiLibNotificationManager systemNotificationManager; - private Dictionary>> handlers; + private Dictionary< + ApiLib, + Dictionary> + > handlers; public DeviceDescriptor Device { get; private set; } @@ -39,18 +45,37 @@ public NotificationManager(DeviceDescriptor device, Api api) this.initializeSubscriptions(); - this.audioNotificationManager = new ApiLibNotificationManager(this.Device, ApiLib.Audio, this.getSubscriptionsForLib(ApiLib.Audio)); - this.avContentNotificationManager = new ApiLibNotificationManager(this.Device, ApiLib.AvContent, this.getSubscriptionsForLib(ApiLib.AvContent)); - this.systemNotificationManager = new ApiLibNotificationManager(this.Device, ApiLib.System, this.getSubscriptionsForLib(ApiLib.System)); + this.audioNotificationManager = new ApiLibNotificationManager( + this.Device, + ApiLib.Audio, + this.getSubscriptionsForLib(ApiLib.Audio) + ); + this.avContentNotificationManager = new ApiLibNotificationManager( + this.Device, + ApiLib.AvContent, + this.getSubscriptionsForLib(ApiLib.AvContent) + ); + this.systemNotificationManager = new ApiLibNotificationManager( + this.Device, + ApiLib.System, + this.getSubscriptionsForLib(ApiLib.System) + ); this.audioNotificationManager.OnNotification += this.OnNotification; this.avContentNotificationManager.OnNotification += this.OnNotification; this.systemNotificationManager.OnNotification += this.OnNotification; } - private void OnNotification(ApiLibNotificationManager sender, string method, ApiVersion version, string serializedParams) + private void OnNotification( + ApiLibNotificationManager sender, + string method, + ApiVersion version, + string serializedParams + ) { - Dictionary> libDelegates = this.handlers[sender.Lib]; + Dictionary> libDelegates = this.handlers[ + sender.Lib + ]; if (libDelegates != null) { Dictionary versionDelegates = libDelegates[version]; @@ -60,9 +85,19 @@ private void OnNotification(ApiLibNotificationManager sender, string method, Api if (eventInfo != null) { // We expect this to be the argument in NotificationEventHandler<> - Type genericArgumentType = eventInfo.EventHandlerType.GenericTypeArguments[0]; - dynamic notificationResult = JsonSerializer.Deserialize(serializedParams, genericArgumentType); - FieldInfo eventFieldInfo = eventInfo.DeclaringType.GetField(eventInfo.Name, BindingFlags.Instance | BindingFlags.NonPublic); + Type genericArgumentType = eventInfo + .EventHandlerType + .GenericTypeArguments[0]; + dynamic notificationResult = JsonSerializer.Deserialize( + serializedParams, + genericArgumentType + ); + FieldInfo eventFieldInfo = eventInfo + .DeclaringType + .GetField( + eventInfo.Name, + BindingFlags.Instance | BindingFlags.NonPublic + ); dynamic eventField = eventFieldInfo.GetValue(this.Api); try { @@ -90,39 +125,67 @@ private void initializeSubscriptions() { Type apiType = this.Api.GetType(); - this.handlers = new Dictionary>>() + this.handlers = new Dictionary< + ApiLib, + Dictionary> + >() { [ApiLib.Audio] = new Dictionary>() { [ApiVersion.V10] = new Dictionary() { - ["notifyVolumeInformation"] = apiType.GetEvent(nameof(this.Api.OnVolumeInformationNotification)) + ["notifyVolumeInformation"] = apiType.GetEvent( + nameof(this.Api.OnVolumeInformationNotification) + ) } }, [ApiLib.AvContent] = new Dictionary>() { [ApiVersion.V10] = new Dictionary() { - ["notifyPlayingContentInfo"] = apiType.GetEvent(nameof(this.Api.OnPlayingContentInfoNotification)), - ["notifyExternalTerminalStatus"] = apiType.GetEvent(nameof(this.Api.OnExternalTerminalStatusNotification)) + ["notifyPlayingContentInfo"] = apiType.GetEvent( + nameof(this.Api.OnPlayingContentInfoNotification) + ), + ["notifyExternalTerminalStatus"] = apiType.GetEvent( + nameof(this.Api.OnExternalTerminalStatusNotification) + ) } }, [ApiLib.System] = new Dictionary>() { [ApiVersion.V10] = new Dictionary() { - ["notifyPowerStatus"] = apiType.GetEvent(nameof(this.Api.OnPowerStatusNotification)) + ["notifyPowerStatus"] = apiType.GetEvent( + nameof(this.Api.OnPowerStatusNotification) + ) } } }; } - private IEnumerable getSubscriptionsForLib(ApiLib lib) + private IEnumerable getSubscriptionsForLib( + ApiLib lib + ) { - Dictionary> libDelegates = this.handlers[lib]; + Dictionary> libDelegates = this.handlers[ + lib + ]; if (libDelegates != null) { - return libDelegates.SelectMany((versionElement) => versionElement.Value.Keys.Select((methodElement) => new ApiLibNotificationManager.NotificationSubscription() { Name = methodElement, Version = versionElement.Key })); + return libDelegates.SelectMany( + (versionElement) => + versionElement + .Value + .Keys + .Select( + (methodElement) => + new ApiLibNotificationManager.NotificationSubscription() + { + Name = methodElement, + Version = versionElement.Key + } + ) + ); } else { @@ -135,12 +198,18 @@ private class ApiLibNotificationManager : IDisposable { public class NotificationSubscription { - public static bool operator ==(NotificationSubscription obj1, NotificationSubscription obj2) + public static bool operator ==( + NotificationSubscription obj1, + NotificationSubscription obj2 + ) { return obj1.Equals(obj2); } - public static bool operator !=(NotificationSubscription obj1, NotificationSubscription obj2) + public static bool operator !=( + NotificationSubscription obj1, + NotificationSubscription obj2 + ) { return !obj1.Equals(obj2); } @@ -153,9 +222,9 @@ public class NotificationSubscription public override bool Equals(object obj) { - return obj is NotificationSubscription subscription && - this.Name == subscription.Name && - this.Version == subscription.Version; + return obj is NotificationSubscription subscription + && this.Name == subscription.Name + && this.Version == subscription.Version; } public override int GetHashCode() @@ -178,15 +247,16 @@ private class NotificationRequest : RequestObject public NotificationRequest( NotificationSubscription[] enabled = null, NotificationSubscription[] disabled = null - ) : base( - "switchNotifications", - ApiVersion.V10, - new NotificationParms() - { - Enabled = enabled ?? new NotificationSubscription[0], - Disabled = disabled ?? new NotificationSubscription[0] - } - ) { } + ) + : base( + "switchNotifications", + ApiVersion.V10, + new NotificationParms() + { + Enabled = enabled ?? new NotificationSubscription[0], + Disabled = disabled ?? new NotificationSubscription[0] + } + ) { } } private class NotificationObject @@ -201,20 +271,23 @@ private class NotificationObject public ApiVersion Version { get; set; } } - private WebsocketClient websocket; private HashSet subscriptions; public delegate void InitializedEventHandler(ApiLibNotificationManager sender); - public delegate void MessageEventHandler(ApiLibNotificationManager sender, string method, ApiVersion version, string serializedParams); + public delegate void MessageEventHandler( + ApiLibNotificationManager sender, + string method, + ApiVersion version, + string serializedParams + ); public DeviceDescriptor Device { get; private set; } public ApiLib Lib { get; private set; } - public bool IsInitialized { get; private set; } public event InitializedEventHandler OnInitialized; @@ -225,7 +298,11 @@ public async Task InitializeAsync() await this.initializeWebsocketAsync(); } - public ApiLibNotificationManager(DeviceDescriptor device, ApiLib lib, IEnumerable subscriptions) + public ApiLibNotificationManager( + DeviceDescriptor device, + ApiLib lib, + IEnumerable subscriptions + ) { this.Device = device; this.Lib = lib; @@ -247,7 +324,11 @@ private async Task initializeWebsocketAsync() } } - this.websocket = new WebsocketClient(new Uri($"ws://{this.Device.Hostname}:{this.Device.Port}/sony/{Utilities.GetApiLibName(this.Lib)}")); + this.websocket = new WebsocketClient( + new Uri( + $"ws://{this.Device.Hostname}:{this.Device.Port}/sony/{Utilities.GetApiLibName(this.Lib)}" + ) + ); this.websocket.ReconnectTimeout = TimeSpan.FromSeconds(30); // Send an empty switchNotifications to get the available notification types @@ -263,91 +344,128 @@ private async Task initializeWebsocketAsync() this.websocket.Send(subscriptionsRequest.Serialized); }; - this.websocket.ReconnectionHappened.Subscribe((message) => - { - Debug.WriteLine($"NOTIFY ({this.Lib}): subscription reconnected ({message})"); - //initialSubscribe(); - }); - - this.websocket.MessageReceived.Subscribe(async (message) => - { - await Task.Run(() => - { - Debug.WriteLine($"NOTIFY ({this.Lib}): message received ({message})"); - - SlimResponseObject basicResponse = JsonSerializer.Deserialize(message.Text); - if (basicResponse.Id == subscriptionsRequest?.Id) + this.websocket + .ReconnectionHappened + .Subscribe( + (message) => { - // This is the response to a notification subscription - ResponseObject response = JsonSerializer.Deserialize>(message.Text); + Debug.WriteLine( + $"NOTIFY ({this.Lib}): subscription reconnected ({message})" + ); + //initialSubscribe(); + } + ); - // Let's find out if any subscriptions are missing - bool anySubscriptionsMissing = this.subscriptions.Any((subscription) => + this.websocket + .MessageReceived + .Subscribe( + async (message) => + { + await Task.Run(() => { - bool subscribed = response.Result.Enabled.Contains(subscription); - bool available = !subscribed && response.Result.Disabled.Contains(subscription); - return !subscribed && available; - }); - if (anySubscriptionsMissing) { - HashSet availableSubscriptions = new HashSet(); - availableSubscriptions.UnionWith(response.Result.Disabled); - availableSubscriptions.UnionWith(response.Result.Enabled); - - List enabled = new List(); - List disabled = new List(); - foreach (NotificationSubscription available in availableSubscriptions) + Debug.WriteLine( + $"NOTIFY ({this.Lib}): message received ({message})" + ); + + SlimResponseObject basicResponse = + JsonSerializer.Deserialize(message.Text); + if (basicResponse.Id == subscriptionsRequest?.Id) { - if (this.subscriptions.Contains(available)) + // This is the response to a notification subscription + ResponseObject response = + JsonSerializer.Deserialize< + ResponseObject + >(message.Text); + + // Let's find out if any subscriptions are missing + bool anySubscriptionsMissing = this.subscriptions.Any( + (subscription) => + { + bool subscribed = response + .Result + .Enabled + .Contains(subscription); + bool available = + !subscribed + && response.Result.Disabled.Contains(subscription); + return !subscribed && available; + } + ); + if (anySubscriptionsMissing) { - enabled.Add(available); + HashSet availableSubscriptions = + new HashSet(); + availableSubscriptions.UnionWith(response.Result.Disabled); + availableSubscriptions.UnionWith(response.Result.Enabled); + + List enabled = + new List(); + List disabled = + new List(); + foreach ( + NotificationSubscription available in availableSubscriptions + ) + { + if (this.subscriptions.Contains(available)) + { + enabled.Add(available); + } + else + { + disabled.Add(available); + } + } + + // Subscribe to everything - we don't expect too much traffic + // This may need to change later + subscriptionsRequest = new NotificationRequest( + enabled: enabled.ToArray(), + disabled: disabled.ToArray() + ); + + this.websocket.Send(subscriptionsRequest.Serialized); } else { - disabled.Add(available); + bool newInitialization = !this.IsInitialized; + this.IsInitialized = true; + if (newInitialization) + { + try + { + this.OnInitialized?.Invoke(this); + } + catch + { + // Swallow handler errors + } + } } } - - // Subscribe to everything - we don't expect too much traffic - // This may need to change later - subscriptionsRequest = new NotificationRequest( - enabled: enabled.ToArray(), - disabled: disabled.ToArray() - ); - - this.websocket.Send(subscriptionsRequest.Serialized); - } - else - { - bool newInitialization = !this.IsInitialized; - this.IsInitialized = true; - if (newInitialization) + else { + // This is a notification + NotificationObject notification = + JsonSerializer.Deserialize( + message.Text + ); try { - this.OnInitialized?.Invoke(this); + this.OnNotification?.Invoke( + this, + notification.Method, + notification.Version, + JsonSerializer.Serialize(notification.Params) + ); } catch { // Swallow handler errors } } - } - } - else - { - // This is a notification - NotificationObject notification = JsonSerializer.Deserialize(message.Text); - try - { - this.OnNotification?.Invoke(this, notification.Method, notification.Version, JsonSerializer.Serialize(notification.Params)); - } - catch - { - // Swallow handler errors - } + }); } - }); - }); + ); await this.websocket.Start(); initialSubscribe(); diff --git a/SonyAudioControlApi/Api/Util/Request.cs b/SonyAudioControlApi/Api/Util/Request.cs index bc4167c..d058dec 100644 --- a/SonyAudioControlApi/Api/Util/Request.cs +++ b/SonyAudioControlApi/Api/Util/Request.cs @@ -58,10 +58,7 @@ public RequestObject(string method, ApiVersion version, object @params) [JsonIgnore] public string Serialized { - get - { - return JsonSerializer.Serialize(this); - } + get { return JsonSerializer.Serialize(this); } } } @@ -81,7 +78,12 @@ private class ResponseObject : SlimResponseObject public TResponse Result { get; set; } } - private async Task makeRequestAsync(ApiLib lib, ApiVersion version, string method, object @params = null) + private async Task makeRequestAsync( + ApiLib lib, + ApiVersion version, + string method, + object @params = null + ) { if (this.Device is null) { @@ -98,13 +100,19 @@ private async Task makeRequestAsync(ApiLib lib, ApiVersion ver string libName = Utilities.GetApiLibName(lib); string requestUrl = $"http://{this.Device.Hostname}:{this.Device.Port}/sony/{libName}"; - HttpContent httpContent = new StringContent(requestObject.Serialized, Encoding.UTF8, "application/json"); + HttpContent httpContent = new StringContent( + requestObject.Serialized, + Encoding.UTF8, + "application/json" + ); using (HttpClient httpClient = new HttpClient()) { HttpResponseMessage response = await httpClient.PostAsync(requestUrl, httpContent); if (response.IsSuccessStatusCode) { - ResponseObject responseObject = JsonSerializer.Deserialize>(await response.Content.ReadAsStringAsync()); + ResponseObject responseObject = JsonSerializer.Deserialize< + ResponseObject + >(await response.Content.ReadAsStringAsync()); if (responseObject.Error != null) { // TODO - handle diff --git a/SonyAudioControlApi/EnumConverter.cs b/SonyAudioControlApi/EnumConverter.cs index 916a8ea..bc78e50 100644 --- a/SonyAudioControlApi/EnumConverter.cs +++ b/SonyAudioControlApi/EnumConverter.cs @@ -28,13 +28,16 @@ internal sealed class JsonEnumConverterAttribute : JsonConverterAttribute { public override JsonConverter CreateConverter(Type typeToConvert) { - return Activator.CreateInstance(typeof(EnumConverter<>).MakeGenericType(typeToConvert)) as JsonConverter; + return Activator.CreateInstance(typeof(EnumConverter<>).MakeGenericType(typeToConvert)) + as JsonConverter; } } - internal sealed class EnumConverter : JsonConverter where TEnum : struct + internal sealed class EnumConverter : JsonConverter + where TEnum : struct { - private static Dictionary _mappings = new Dictionary(); + private static Dictionary _mappings = + new Dictionary(); private struct MappingConfiguration { @@ -43,7 +46,6 @@ private struct MappingConfiguration public Dictionary EnumToStringMapping { get; set; } } - private static MappingConfiguration tryGetMappingForType(Type type) { if (!EnumConverter._mappings.ContainsKey(type)) @@ -63,7 +65,8 @@ private static MappingConfiguration tryGetMappingForType(Type type) FieldInfo memberField = member as FieldInfo; if (memberField != null && memberField.IsStatic && memberField.IsPublic) { - EnumJsonStringValueAttribute attribute = member.GetCustomAttribute(); + EnumJsonStringValueAttribute attribute = + member.GetCustomAttribute(); if (attribute == null) { // We've found an element without the attribute @@ -87,7 +90,9 @@ private static MappingConfiguration getMappingForType(Type type) MappingConfiguration mapping = EnumConverter.tryGetMappingForType(type); if (!mapping.MappingIsValid) { - throw new Exception($"Unable to initialize {type} mapping. A member is missing the EnumStringValueAttribute"); + throw new Exception( + $"Unable to initialize {type} mapping. A member is missing the EnumStringValueAttribute" + ); } else { @@ -100,7 +105,11 @@ public override bool CanConvert(Type type) return tryGetMappingForType(type).MappingIsValid; } - public override TEnum Read(ref Utf8JsonReader reader, Type type, JsonSerializerOptions options) + public override TEnum Read( + ref Utf8JsonReader reader, + Type type, + JsonSerializerOptions options + ) { MappingConfiguration mapping = EnumConverter.getMappingForType(type); @@ -118,12 +127,18 @@ public override TEnum Read(ref Utf8JsonReader reader, Type type, JsonSerializerO } } - public override void Write(Utf8JsonWriter writer, TEnum value, JsonSerializerOptions options) + public override void Write( + Utf8JsonWriter writer, + TEnum value, + JsonSerializerOptions options + ) { Type valueType = value.GetType(); if (valueType.IsArray) { - MappingConfiguration mapping = EnumConverter.getMappingForType(valueType.GetElementType()); + MappingConfiguration mapping = EnumConverter.getMappingForType( + valueType.GetElementType() + ); TEnum[] typedValueArray = value as TEnum[]; if (typedValueArray != null) { diff --git a/SonyAudioControlApi/Exceptions/HttpException.cs b/SonyAudioControlApi/Exceptions/HttpException.cs index 6d1b13b..78453ca 100644 --- a/SonyAudioControlApi/Exceptions/HttpException.cs +++ b/SonyAudioControlApi/Exceptions/HttpException.cs @@ -4,7 +4,5 @@ namespace SonyAudioControlApi.Exceptions { - class HttpException : Exception - { - } + class HttpException : Exception { } } diff --git a/SonyAudioControlApi/Exceptions/UnexpectedResponseException.cs b/SonyAudioControlApi/Exceptions/UnexpectedResponseException.cs index ce22d2f..95a5ca7 100644 --- a/SonyAudioControlApi/Exceptions/UnexpectedResponseException.cs +++ b/SonyAudioControlApi/Exceptions/UnexpectedResponseException.cs @@ -6,9 +6,7 @@ namespace SonyAudioControlApi.Exceptions { public class UnexpectedResponseException : Exception { - internal UnexpectedResponseException(string property, string actualValue) : - base($"Recieved unexpected value \"{actualValue}\" for property \"{property}\".") - { - } + internal UnexpectedResponseException(string property, string actualValue) + : base($"Recieved unexpected value \"{actualValue}\" for property \"{property}\".") { } } } diff --git a/SonyAudioControlApi/SingleElementArrayConverter.cs b/SonyAudioControlApi/SingleElementArrayConverter.cs index a1af043..119000e 100644 --- a/SonyAudioControlApi/SingleElementArrayConverter.cs +++ b/SonyAudioControlApi/SingleElementArrayConverter.cs @@ -9,7 +9,9 @@ internal sealed class SingleElementArrayConverterAttribute : JsonConverterAttrib { public override JsonConverter CreateConverter(Type typeToConvert) { - return Activator.CreateInstance(typeof(SingleElementArrayConverter<>).MakeGenericType(typeToConvert)) as JsonConverter; + return Activator.CreateInstance( + typeof(SingleElementArrayConverter<>).MakeGenericType(typeToConvert) + ) as JsonConverter; } } @@ -20,7 +22,11 @@ public override bool CanConvert(Type type) return true; } - public override TElement Read(ref Utf8JsonReader reader, Type type, JsonSerializerOptions options) + public override TElement Read( + ref Utf8JsonReader reader, + Type type, + JsonSerializerOptions options + ) { if (reader.TokenType == JsonTokenType.StartArray) { @@ -29,7 +35,9 @@ public override TElement Read(ref Utf8JsonReader reader, Type type, JsonSerializ reader.Read(); if (reader.TokenType != JsonTokenType.EndArray) { - throw new JsonException($"Expected to find a single-eleemt array, but found an unexpected element: {reader.TokenType}"); + throw new JsonException( + $"Expected to find a single-eleemt array, but found an unexpected element: {reader.TokenType}" + ); } else { @@ -42,7 +50,11 @@ public override TElement Read(ref Utf8JsonReader reader, Type type, JsonSerializ } } - public override void Write(Utf8JsonWriter writer, TElement value, JsonSerializerOptions options) + public override void Write( + Utf8JsonWriter writer, + TElement value, + JsonSerializerOptions options + ) { writer.WriteStartArray(); JsonSerializer.Serialize(value, options); diff --git a/SonyAudioControlApi/TargetType.cs b/SonyAudioControlApi/TargetType.cs index 24b7bca..eeb9783 100644 --- a/SonyAudioControlApi/TargetType.cs +++ b/SonyAudioControlApi/TargetType.cs @@ -4,7 +4,6 @@ namespace SonyAudioControlApi { - [JsonEnumConverter] public enum TargetType { diff --git a/SonyAudioControlApiTester/Program.cs b/SonyAudioControlApiTester/Program.cs index 3c86793..927a081 100644 --- a/SonyAudioControlApiTester/Program.cs +++ b/SonyAudioControlApiTester/Program.cs @@ -8,7 +8,13 @@ class Program { static async Task Main(string[] args) { - Api api = new Api(new DeviceDescriptor() { Hostname = args[0], Type = DeviceDescriptor.DeviceType.SoundbarReceiver }); + Api api = new Api( + new DeviceDescriptor() + { + Hostname = args[0], + Type = DeviceDescriptor.DeviceType.SoundbarReceiver + } + ); var result1 = await api.GetPowerStatusAsync(); var result2 = await api.GetCurrentExternalTerminalsStatusAsync(); var result3 = await api.GetCustomEqualizerSettingsAsync(); @@ -19,7 +25,10 @@ static async Task Main(string[] args) api.InitializeNotifications(); - api.OnVolumeInformationNotification += (DeviceDescriptor sender, VolumeInformationResult[] result) => + api.OnVolumeInformationNotification += ( + DeviceDescriptor sender, + VolumeInformationResult[] result + ) => { foreach (VolumeInformationResult volume in result) {