Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Rans4ckeR committed Mar 22, 2024
1 parent 67748c6 commit 86fd1ad
Show file tree
Hide file tree
Showing 91 changed files with 633 additions and 1,642 deletions.
1,567 changes: 398 additions & 1,169 deletions .editorconfig

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion RS.Fritz.Manager.API/Extensions/DeviceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public static class DeviceExtensions
{
public static IEnumerable<ServiceListItem> GetServices(this Device device)
{
IEnumerable<ServiceListItem> serviceListItems = device.ServiceList;
IEnumerable<ServiceListItem> serviceListItems = device.ServiceList ?? [];

foreach (Device deviceListItem in device.DeviceList ?? [])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,12 @@ private static Func<IFritzServiceOperationHandler, InternetGatewayDevice, Task<T
Func<IFritzServiceOperationHandler, InternetGatewayDevice, Task<T>> interface2Operation,
Func<IFritzServiceOperationHandler, InternetGatewayDevice, Task<T>> interface3Operation,
Func<IFritzServiceOperationHandler, InternetGatewayDevice, Task<T>> interface4Operation)
{
return interfaceNumber switch
=> interfaceNumber switch
{
1 => interface1Operation,
2 => interface2Operation,
3 => interface3Operation,
4 => interface4Operation,
_ => throw new ArgumentOutOfRangeException(nameof(interfaceNumber), interfaceNumber, null)
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

public static class ServiceCollectionExtensions
{
public static IServiceCollection AddFritzApi(this IServiceCollection serviceCollection)
{
return serviceCollection.AddSingleton<IDeviceSearchService, DeviceSearchService>()
public static IServiceCollection AddFritzApi(this IServiceCollection serviceCollection) =>
serviceCollection.AddSingleton<IDeviceSearchService, DeviceSearchService>()
.AddSingleton<IDeviceHostsService, DeviceHostsService>()
.AddSingleton<IDeviceMeshService, DeviceMeshService>()
.AddSingleton<IWlanDeviceService, WlanDeviceService>()
Expand Down Expand Up @@ -39,7 +38,6 @@ public static IServiceCollection AddFritzApi(this IServiceCollection serviceColl
.AddSingleton<IClientFactory<IFritzUserInterfaceService>, ClientFactory<IFritzUserInterfaceService>>()
.AddSingleton<IClientFactory<IFritzDeviceConfigService>, ClientFactory<IFritzDeviceConfigService>>()
.ConfigureHttpClients();
}

private static IServiceCollection ConfigureHttpClients(this IServiceCollection serviceCollection)
{
Expand Down
6 changes: 2 additions & 4 deletions RS.Fritz.Manager.API/Properties/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#pragma warning disable IDE0065 // Misplaced using directive
#pragma warning disable SA1200 // Using directives should be placed correctly
#pragma warning disable SA1200 // Using directives should be placed correctly
global using System.ServiceModel;
#pragma warning restore SA1200 // Using directives should be placed correctly
#pragma warning restore IDE0065 // Misplaced using directive
#pragma warning restore SA1200 // Using directives should be placed correctly
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal sealed class CaptureControlService(IHttpClientFactory httpClientFactory
public async ValueTask<IEnumerable<CaptureInterfaceGroup>> GetInterfacesAsync(InternetGatewayDevice internetGatewayDevice, CancellationToken cancellationToken = default)
{
string sid = await GetSidAsync(internetGatewayDevice).ConfigureAwait(false);
Uri captureUri = networkService.FormatUri(Uri.UriSchemeHttps, internetGatewayDevice.PreferredLocation, 443, "/data.lua");
Uri captureUri = networkService.FormatUri(Uri.UriSchemeHttps, internetGatewayDevice.PreferredLocation!, 443, "/data.lua");
HttpClient httpClient = httpClientFactory.CreateClient(Constants.DefaultHttpClientName);
using var content = new FormUrlEncodedContent(new Dictionary<string, string>
{
Expand Down Expand Up @@ -54,7 +54,7 @@ public async ValueTask<IEnumerable<CaptureInterfaceGroup>> GetInterfacesAsync(In
public async ValueTask StartCaptureAsync(InternetGatewayDevice internetGatewayDevice, FileInfo fileInfo, CaptureInterface captureInterface, int packetCaptureSizeLimit = 1600, CancellationToken cancellationToken = default)
{
string sid = await GetSidAsync(internetGatewayDevice).ConfigureAwait(false);
Uri captureUri = networkService.FormatUri(Uri.UriSchemeHttps, internetGatewayDevice.PreferredLocation, 443, FormattableString.Invariant($"/cgi-bin/capture_notimeout?sid={sid}&capture=Start&snaplen={packetCaptureSizeLimit}&ifaceorminor={captureInterface.InterfaceOrMinor}"));
Uri captureUri = networkService.FormatUri(Uri.UriSchemeHttps, internetGatewayDevice.PreferredLocation!, 443, FormattableString.Invariant($"/cgi-bin/capture_notimeout?sid={sid}&capture=Start&snaplen={packetCaptureSizeLimit}&ifaceorminor={captureInterface.InterfaceOrMinor}"));
HttpClient httpClient = httpClientFactory.CreateClient(Constants.DefaultHttpClientName);
using HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(captureUri, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
Stream downloadStream = await httpResponseMessage.EnsureSuccessStatusCode().Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
Expand All @@ -75,7 +75,7 @@ public async ValueTask StopCaptureAsync(InternetGatewayDevice internetGatewayDev
string sid = await GetSidAsync(internetGatewayDevice).ConfigureAwait(false);
string timeString20 = DateTime.UtcNow.Ticks.ToString("D20", CultureInfo.InvariantCulture);
string timeId = FormattableString.Invariant($"t{timeString20[^13..]}");
Uri captureUri = networkService.FormatUri(Uri.UriSchemeHttps, internetGatewayDevice.PreferredLocation, 443, FormattableString.Invariant($"/cgi-bin/capture_notimeout?iface={captureInterface.Interface}&minor={captureInterface.Minor}&type={captureInterface.Type}&capture=Stop&sid={sid}&useajax=1&xhr=1&{timeId}=nocache"));
Uri captureUri = networkService.FormatUri(Uri.UriSchemeHttps, internetGatewayDevice.PreferredLocation!, 443, FormattableString.Invariant($"/cgi-bin/capture_notimeout?iface={captureInterface.Interface}&minor={captureInterface.Minor}&type={captureInterface.Type}&capture=Stop&sid={sid}&useajax=1&xhr=1&{timeId}=nocache"));
HttpClient httpClient = httpClientFactory.CreateClient(Constants.DefaultHttpClientName);
using HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(captureUri, HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public async ValueTask<DeviceHostInfo> GetDeviceHostsAsync(InternetGatewayDevice
{
HostsGetHostListPathResponse hostsGetHostListPathResponse = await internetGatewayDevice.HostsGetHostListPathAsync().ConfigureAwait(false);
string hostListPath = hostsGetHostListPathResponse.HostListPath;
Uri hostListPathUri = networkService.FormatUri(Uri.UriSchemeHttps, internetGatewayDevice.PreferredLocation, internetGatewayDevice.SecurityPort!.Value, hostListPath);
Uri hostListPathUri = networkService.FormatUri(Uri.UriSchemeHttps, internetGatewayDevice.PreferredLocation!, internetGatewayDevice.SecurityPort!.Value, hostListPath);
Stream deviceHostsListXmlStream = await httpClientFactory.CreateClient(Constants.DefaultHttpClientName).GetStreamAsync(hostListPathUri, cancellationToken).ConfigureAwait(false);

await using (deviceHostsListXmlStream.ConfigureAwait(false))
Expand Down
15 changes: 6 additions & 9 deletions RS.Fritz.Manager.API/Services/Discovery/DeviceSearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async ValueTask<IEnumerable<GroupedInternetGatewayDevice>> GetInternetGat
GetRawDeviceResponses(UPnPConstants.InternetGatewayDeviceV1DeviceType, sendCount, timeout, cancellationToken),
GetRawDeviceResponses(UPnPConstants.InternetGatewayDeviceV1AvmDeviceType, sendCount, timeout, cancellationToken)
];
IEnumerable<(IPAddress LocalIpAddress, FrozenSet<(IPAddress IPAddress, string Response)> Responses)>[] responses = await TaskExtensions.WhenAllSafe(tasks);
IEnumerable<(IPAddress LocalIpAddress, FrozenSet<(IPAddress IPAddress, string Response)> Responses)>[] responses = await TaskExtensions.WhenAllSafe(tasks).ConfigureAwait(false);
IEnumerable<ServerDeviceResponse> serverDeviceResponses = GetServerDeviceResponses(responses.SelectMany(q => q));

return await TaskExtensions.WhenAllSafe(serverDeviceResponses.Select(q => ParseInternetGatewayDeviceAsync(q, cancellationToken))).ConfigureAwait(false);
Expand All @@ -33,7 +33,7 @@ public async ValueTask<IEnumerable<ServerDeviceResponse>> GetDevicesAsync(string
return GetServerDeviceResponses(rawDeviceResponses);
}

private static IEnumerable<ServerDeviceResponse> GetServerDeviceResponses(IEnumerable<(IPAddress LocalIpAddress, FrozenSet<(IPAddress IPAddress, string Response)> Responses)> rawDeviceResponses)
private static List<ServerDeviceResponse> GetServerDeviceResponses(IEnumerable<(IPAddress LocalIpAddress, FrozenSet<(IPAddress IPAddress, string Response)> Responses)> rawDeviceResponses)
{
IEnumerable<(IPAddress LocalIpAddress, IEnumerable<(IPAddress IPAddress, FrozenDictionary<string, string> Values)> Responses)> formattedDeviceResponses =
rawDeviceResponses.Select(q => (q.LocalIpAddress, GetFormattedDeviceResponses(q.Responses)));
Expand Down Expand Up @@ -191,13 +191,10 @@ private static Device GetBaseDevice(AvmDeviceListDevice device)
?? locations.FirstOrDefault(q => Socket.OSSupportsIPv6 && q?.HostNameType is UriHostNameType.IPv6 && networkService.IsPrivateIpAddress(IPAddress.Parse(q.IdnHost)))
?? locations.FirstOrDefault(q => Socket.OSSupportsIPv4 && q?.HostNameType is UriHostNameType.IPv4);

private Uri? ParseLocation((IPAddress LocalIpAddress, Uri? Location) location)
{
if (location.Location?.HostNameType is not UriHostNameType.IPv6 || !IPAddress.TryParse(location.Location.IdnHost, out IPAddress? ipAddress) || !networkService.IsPrivateIpAddress(ipAddress))
return location.Location;

return networkService.FormatUri(new(IPAddress.Parse(FormattableString.Invariant($"{location.Location.IdnHost}%{location.LocalIpAddress.ScopeId}")), location.Location.Port), location.Location.Scheme, location.Location.PathAndQuery);
}
private Uri? ParseLocation((IPAddress LocalIpAddress, Uri? Location) location) =>
location.Location?.HostNameType is not UriHostNameType.IPv6 || !IPAddress.TryParse(location.Location.IdnHost, out IPAddress? ipAddress) || !networkService.IsPrivateIpAddress(ipAddress)
? location.Location
: networkService.FormatUri(new(IPAddress.Parse(FormattableString.Invariant($"{location.Location.IdnHost}%{location.LocalIpAddress.ScopeId}")), location.Location.Port), location.Location.Scheme, location.Location.PathAndQuery);

private async Task<(IPAddress IpAddress, FrozenSet<(IPAddress IPAddress, string Response)> Responses)> SearchDevicesAsync(IPAddress localAddress, IPAddress multicastAddress, string deviceType, int sendCount, int receiveTimeout, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public async ValueTask<DeviceMeshInfo> GetDeviceMeshAsync(InternetGatewayDevice
{
HostsGetMeshListPathResponse hostsGetMeshListPathResponse = await internetGatewayDevice.HostsGetMeshListPathAsync().ConfigureAwait(false);
string meshListPath = hostsGetMeshListPathResponse.MeshListPath;
Uri meshListPathUri = networkService.FormatUri(Uri.UriSchemeHttps, internetGatewayDevice.PreferredLocation, internetGatewayDevice.SecurityPort!.Value, meshListPath);
Uri meshListPathUri = networkService.FormatUri(Uri.UriSchemeHttps, internetGatewayDevice.PreferredLocation!, internetGatewayDevice.SecurityPort!.Value, meshListPath);
Stream deviceMeshJsonStream = await httpClientFactory.CreateClient(Constants.DefaultHttpClientName).GetStreamAsync(meshListPathUri, cancellationToken).ConfigureAwait(false);

await using (deviceMeshJsonStream.ConfigureAwait(false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override DeviceMeshStreamConfiguration[] Read(ref Utf8JsonReader reader,
while (reader.Read())
{
if (reader.TokenType is JsonTokenType.EndArray)
return deviceMeshStreamConfigurations.ToArray();
return [.. deviceMeshStreamConfigurations];

if (reader.TokenType is not JsonTokenType.StartArray)
throw new JsonException();
Expand Down
2 changes: 0 additions & 2 deletions RS.Fritz.Manager.API/Services/Shared/NetworkService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public Uri FormatUri(IPEndPoint ipEndPoint, string? scheme = null, string? path
}

public bool IsPrivateIpAddress(IPAddress ipAddress)
#pragma warning disable IDE0072 // Add missing cases
=> ipAddress.AddressFamily switch
{
AddressFamily.InterNetworkV6 => ipAddress.IsIPv6SiteLocal || ipAddress.IsIPv6UniqueLocal || ipAddress.IsIPv6LinkLocal,
Expand All @@ -48,7 +47,6 @@ public bool IsPrivateIpAddress(IPAddress ipAddress)
|| IPNetwork.Parse("0.0.0.0/8").Contains(ipAddress),
_ => throw new ArgumentOutOfRangeException(nameof(ipAddress), ipAddress, null)
};
#pragma warning restore IDE0072 // Add missing cases

public IEnumerable<IPAddress> GetUnicastAddresses()
=> GetIpInterfaces()
Expand Down
6 changes: 2 additions & 4 deletions RS.Fritz.Manager.API/Services/TR-064/FritzServiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ protected FritzServiceClient(FritzServiceEndpointConfiguration endpointConfigura
SetCredentials(networkCredential);
}

private static Binding GetBindingForEndpoint(FritzServiceEndpointConfiguration endpointConfiguration)
{
return endpointConfiguration switch
private static Binding GetBindingForEndpoint(FritzServiceEndpointConfiguration endpointConfiguration) =>
endpointConfiguration switch
{
FritzServiceEndpointConfiguration.BasicHttpBindingIFritzService => new BasicHttpBinding
{
Expand All @@ -46,7 +45,6 @@ private static Binding GetBindingForEndpoint(FritzServiceEndpointConfiguration e
},
_ => throw new ArgumentOutOfRangeException(nameof(endpointConfiguration), endpointConfiguration, null)
};
}

private void SetSslProtocols(SslProtocols sslProtocols)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ public string? Status
if ("DONE_CABLE_OK".Equals(DslDiagnoseState, StringComparison.OrdinalIgnoreCase) && CableNokDistance is -1 && DslLastDiagnoseTime > 0 && DslSignalLossTime > 300 && DslActive && !DslSync)
return "The measurement for cable cut is finished but the distance could not be detected or is too inaccurate.";

#pragma warning disable IDE0046 // Convert to conditional expression
if ("NONE".Equals(DslDiagnoseState, StringComparison.OrdinalIgnoreCase) && CableNokDistance is -1 && DslLastDiagnoseTime > 0 && DslSignalLossTime is 0 && DslActive && DslSync)
return FormattableString.CurrentCulture($"When the DSL signal is sync again, all values will be set to default values. Except the {nameof(DslLastDiagnoseTime)} which remains at the value of time in seconds between the last measurement and the resync.");
#pragma warning restore IDE0046 // Convert to conditional expression

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ internal sealed class SslProtocolCertificateEndpointBehavior : IEndpointBehavior
{
public SslProtocols SslProtocols { get; set; }

public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
{
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) =>
bindingParameters.Add(new Func<HttpClientHandler, HttpMessageHandler>(q =>
{
q.SslProtocols = SslProtocols;
q.ServerCertificateCustomValidationCallback = (_, _, _, _) => true;

return q;
}));
}

public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
Expand Down
2 changes: 1 addition & 1 deletion RS.Fritz.Manager.API/Services/WebUi/WebUiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static byte[] GetHash(byte[] password, byte[] salt, int iterations)
}

private Uri GetLoginUri(InternetGatewayDevice internetGatewayDevice)
=> networkService.FormatUri(Uri.UriSchemeHttps, internetGatewayDevice.PreferredLocation, 443, LoginPath);
=> networkService.FormatUri(Uri.UriSchemeHttps, internetGatewayDevice.PreferredLocation!, 443, LoginPath);

private async ValueTask<WebUiSessionInfo> GetResponseAsync(InternetGatewayDevice internetGatewayDevice, IDictionary<string, string> parameters, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public async ValueTask<WlanDeviceInfo> GetWlanDevicesAsync(InternetGatewayDevice
{
WlanConfigurationGetWlanDeviceListPathResponse wlanConfigurationGetWlanDeviceListPathResponse = await internetGatewayDevice.WlanConfigurationGetWlanDeviceListPathAsync(1).ConfigureAwait(false);
string wlanDeviceListPath = wlanConfigurationGetWlanDeviceListPathResponse.WlanDeviceListPath;
Uri wlanDeviceListPathUri = networkService.FormatUri(Uri.UriSchemeHttps, internetGatewayDevice.PreferredLocation, internetGatewayDevice.SecurityPort!.Value, wlanDeviceListPath);
Uri wlanDeviceListPathUri = networkService.FormatUri(Uri.UriSchemeHttps, internetGatewayDevice.PreferredLocation!, internetGatewayDevice.SecurityPort!.Value, wlanDeviceListPath);
Stream wlanDeviceListXmlStream = await httpClientFactory.CreateClient(Constants.DefaultHttpClientName).GetStreamAsync(wlanDeviceListPathUri, cancellationToken).ConfigureAwait(false);

await using (wlanDeviceListXmlStream.ConfigureAwait(false))
Expand Down
4 changes: 1 addition & 3 deletions RS.Fritz.Manager.UI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ private static void PreventWpfFlashbang(Window window)
window.WindowState = WindowState.Minimized;
}

private static void SetUiCulture()
{
private static void SetUiCulture() =>
FrameworkElement.LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
}

private void AppDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
Expand Down
Loading

0 comments on commit 86fd1ad

Please sign in to comment.