Skip to content

Commit

Permalink
Merge pull request #6 from seanet7or/warnings
Browse files Browse the repository at this point in the history
fixed .net7 warnings
  • Loading branch information
seanet7or authored Oct 12, 2023
2 parents 11d28a4 + f53e453 commit 5ef8d0a
Show file tree
Hide file tree
Showing 26 changed files with 220 additions and 153 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.25.0",
"commands": [
"dotnet-csharpier"
]
}
}
}
7 changes: 6 additions & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:

jobs:
build:

name: Build
runs-on: windows-latest

steps:
Expand All @@ -32,6 +32,11 @@ jobs:

- name: Restore dependencies
run: dotnet restore

- name: CSharpier
run: |
dotnet tool restore
dotnet csharpier --check .
- name: Build
run: dotnet build --no-restore
Expand Down
26 changes: 13 additions & 13 deletions upnp/Devices/IUpnpDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@ namespace upnp.Devices
{
public interface IUpnpDevice
{
Icon FindIcon(int requestedWidth);
Icon? FindIcon(int requestedWidth);

string FriendlyName { get; }
string? FriendlyName { get; }

IUpnpDeviceType DeviceType { get; }
IUpnpDeviceType? DeviceType { get; }

string SerialNumber { get; }
string? SerialNumber { get; }

string Manufacturer { get; }
string? Manufacturer { get; }

Guid Id { get; }

string GetModelDescription();
string? GetModelDescription();

string ManufacturerUrl { get; }
string? ManufacturerUrl { get; }

IEnumerable<UpnpService> Services { get; }

string ModelNumber { get; }
string? ModelNumber { get; }

string ModelUrl { get; }
string? ModelUrl { get; }

string PresentationUrl { get; }
string? PresentationUrl { get; }

IconList IconList { get; }
IconList? IconList { get; }

IContentDirectory ContentDirectory { get; }
IContentDirectory? ContentDirectory { get; }

Url BaseUrl { get; }
Url? BaseUrl { get; }
}
}
19 changes: 12 additions & 7 deletions upnp/Devices/Icon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Icon : IComparable<Icon>

public override int GetHashCode()
{
return _relativeUrl.GetHashCode();
return _relativeUrl != null ? _relativeUrl.GetHashCode() : 0;
}

public static bool operator <(Icon left, Icon right)
Expand All @@ -31,7 +31,7 @@ public override int GetHashCode()
return false;
}

public int CompareTo(Icon other)
public int CompareTo(Icon? other)
{
if (other != null)
{
Expand All @@ -49,7 +49,7 @@ public int CompareTo(Icon other)

#endregion

public override bool Equals(object obj)
public override bool Equals(object? obj)
{
var other = obj as Icon;
if (other != null)
Expand All @@ -59,12 +59,17 @@ public override bool Equals(object obj)
return false;
}

public Url AbsoluteUrl
public Url? AbsoluteUrl
{
get { return device.BaseUrl.ResolveRelativeToThisBaseUrl(_relativeUrl); }
get
{
return _relativeUrl != null
? device.BaseUrl?.ResolveRelativeToThisBaseUrl(_relativeUrl)
: null;
}
}

readonly Url _relativeUrl;
readonly Url? _relativeUrl;

// Required. Number of color bits per pixel. Integer.
[System.Diagnostics.CodeAnalysis.SuppressMessage(
Expand All @@ -85,7 +90,7 @@ public Url AbsoluteUrl
"Microsoft.Performance",
"CA1823:AvoidUnusedPrivateFields"
)]
internal string mimetype;
internal string? mimetype;

readonly UpnpDevice device;

Expand Down
38 changes: 19 additions & 19 deletions upnp/Devices/UpnpDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class UpnpDevice : IUpnpDevice
{
readonly object iconListLock = new object();

public Icon FindIcon(int requestedWidth)
public Icon? FindIcon(int requestedWidth)
{
lock (iconListLock)
{
IconList.Sort();
IconList?.Sort();
if (IconList != null)
{
foreach (var icon in IconList)
Expand All @@ -24,16 +24,16 @@ public Icon FindIcon(int requestedWidth)
}
}
}
return IconList.Last();
return IconList?.Last();
}
}

public IContentDirectory ContentDirectory
public IContentDirectory? ContentDirectory
{
get { return _services.OfType<IContentDirectory>().FirstOrDefault(); }
get { return _services?.OfType<IContentDirectory>().FirstOrDefault(); }
}

public string GetModelDescription()
public string? GetModelDescription()
{
if (!string.IsNullOrEmpty(modelDescription))
{
Expand All @@ -44,47 +44,47 @@ public string GetModelDescription()

// Recommended. Long description for end user. Should be localized (cf. ACCEPT-LANGUAGE and CONTENT-LANGUAGE headers).
// Specified by UPnP vendor. String. Should be < 128 characters.
readonly string modelDescription;
readonly string? modelDescription;

// Required. Model name. May be localized (cf. ACCEPT-LANGUAGE and CONTENT-LANGUAGE headers).
// Specified by UPnP vendor. String. Should be < 32 characters.
readonly string modelName;
readonly string? modelName;

// Recommended. Serial number. May be localized (cf. ACCEPT-LANGUAGE and CONTENT-LANGUAGE headers).
// Specified by UPnP vendor. String. Should be < 64 characters.
public string SerialNumber { get; private set; }
public string? SerialNumber { get; private set; }

// REQUIRED. UPnP device type. Single URI.
public IUpnpDeviceType DeviceType { get; private set; }
public IUpnpDeviceType? DeviceType { get; private set; }

// Required. Short description for end user. Should be localized (cf. ACCEPT-LANGUAGE and CONTENT-LANGUAGE headers).
// Specified by UPnP vendor. String. Should be < 64 characters.
public string FriendlyName { get; private set; }
public string? FriendlyName { get; private set; }

// Required. Manufacturer's name. May be localized (cf. ACCEPT-LANGUAGE and CONTENT-LANGUAGE headers).
// Specified by UPnP vendor. String. Should be < 64 characters.
public string Manufacturer { get; private set; }
public string? Manufacturer { get; private set; }

public Guid Id { get; private set; }

// Optional. Web site for Manufacturer. May be localized (cf. ACCEPT-LANGUAGE and CONTENT-LANGUAGE headers).
// May be relative to base URL. Specified by UPnP vendor. Single URL.
public string ManufacturerUrl { get; private set; }
public string? ManufacturerUrl { get; private set; }

// Recommended. Model number. May be localized (cf. ACCEPT-LANGUAGE and CONTENT-LANGUAGE headers).
// Specified by UPnP vendor. String. Should be < 32 characters.
public string ModelNumber { get; private set; }
public string? ModelNumber { get; private set; }

// Optional. Web site for model. May be localized (cf. ACCEPT-LANGUAGE and CONTENT-LANGUAGE headers).
// May be relative to base URL. Specified by UPnP vendor. Single URL.
public string ModelUrl { get; private set; }
public string? ModelUrl { get; private set; }

// Recommended. URL to presentation for device (cf. section on Presentation). May be relative to base URL.
// Specified by UPnP vendor. Single URL.
public string PresentationUrl { get; private set; }
public string? PresentationUrl { get; private set; }

// Required if and only if device has one or more icons. Specified by UPnP vendor.
public IconList IconList { get; private set; }
public IconList? IconList { get; private set; }

public IEnumerable<UpnpService> Services
{
Expand All @@ -99,9 +99,9 @@ internal void AddService(UpnpService service)
}

// Optional.
internal DeviceServiceList DeviceServiceList { get; private set; }
internal DeviceServiceList? DeviceServiceList { get; private set; }

public Url BaseUrl { get; internal set; }
public Url? BaseUrl { get; internal set; }

internal UpnpDevice(XmlReader reader)
{
Expand Down
24 changes: 16 additions & 8 deletions upnp/Devices/UpnpDeviceDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class UpnpDeviceDescription
"Microsoft.Performance",
"CA1811:AvoidUncalledPrivateCode"
)]
internal SpecVersion SpecVersion { get; private set; }
internal SpecVersion? SpecVersion { get; private set; }

public IUpnpDevice Device
public IUpnpDevice? Device
{
get { return _device; }
}
UpnpDevice _device;
UpnpDevice? _device;

public UpnpDeviceDescription(MSearchResponse searchResponse, IHttpClient httpClient)
{
Expand All @@ -31,7 +31,7 @@ public UpnpDeviceDescription(MSearchResponse searchResponse, IHttpClient httpCli

IHttpClient httpClient;

static string LanguageCode()
static string? LanguageCode()
{
/*var locale = Java.Util.Locale.Default;
if (locale != null)
Expand All @@ -54,6 +54,11 @@ public async Task<bool> ReadDescriptionAsync()
{
try
{
if (searchResponse.Location == null)
{
Log.LogWarning("Can not read UPNP device description: Location is null");
return false;
}
var langCode = LanguageCode();
var xmlStream = await httpClient.GetAsync(langCode, searchResponse.Location);
var xmlReader = XmlReader.Create(xmlStream);
Expand Down Expand Up @@ -87,15 +92,15 @@ public async Task<bool> ReadDescriptionAsync()

async Task ReadServiceDescsAsync()
{
if (_device.DeviceServiceList != null)
if (_device?.DeviceServiceList != null)
{
foreach (var service in _device.DeviceServiceList)
{
var serviceDescription = new UpnpServiceDescription(service, httpClient);
if (await serviceDescription.ReadDescriptionAsync())
{
if (
service.ServiceType.StandardServiceType
service.ServiceType?.StandardServiceType
== StandardServiceType.ContentDirectory
)
{
Expand All @@ -113,7 +118,7 @@ async Task ReadServiceDescsAsync()

void ParseRootNode(XmlReader reader)
{
string urlBase = null;
string? urlBase = null;
while (reader.Read())
{
if (reader.IsStartElement())
Expand Down Expand Up @@ -146,7 +151,10 @@ void ParseRootNode(XmlReader reader)
{
urlBase = searchResponse.Location;
}
_device.BaseUrl = new Url(urlBase);
if (_device != null && !string.IsNullOrEmpty(urlBase))
{
_device.BaseUrl = new Url(urlBase);
}
}
/*
void ParseRootNode(XmlNode root)
Expand Down
2 changes: 1 addition & 1 deletion upnp/IHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public interface IHttpClient
{
Task<Stream> GetAsync(string acceptLanguage, string url);
Task<Stream> GetAsync(string? acceptLanguage, string url);

Task<Stream> PostDataAsync(Dictionary<string, string> headers, byte[] data, string url);
}
Expand Down
6 changes: 3 additions & 3 deletions upnp/Services/AllowedValueRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ class AllowedValueRange
"Microsoft.Performance",
"CA1823:AvoidUnusedPrivateFields"
)]
string minimum;
string? minimum;

[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Performance",
"CA1823:AvoidUnusedPrivateFields"
)]
string maximum;
string? maximum;

[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Performance",
"CA1823:AvoidUnusedPrivateFields"
)]
string step;
string? step;

public AllowedValueRange(XmlReader reader)
{
Expand Down
6 changes: 3 additions & 3 deletions upnp/Services/Argument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ class Argument
"Microsoft.Performance",
"CA1823:AvoidUnusedPrivateFields"
)]
readonly string name;
readonly string? name;

// REQUIRED. Defines whether argument is an input or output parameter. MUST be either “in” or “out” and not both.
// All input arguments MUST be listed before any output arguments.
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Performance",
"CA1823:AvoidUnusedPrivateFields"
)]
readonly string direction;
readonly string? direction;

// OPTIONAL. Identifies at most one output argument as the return value. If included, MUST be included as a
// subelement of the first output argument. (Element only; no value.)
Expand All @@ -37,7 +37,7 @@ class Argument
"Microsoft.Performance",
"CA1823:AvoidUnusedPrivateFields"
)]
readonly string relatedStateVariable;
readonly string? relatedStateVariable;

public Argument(XmlReader reader)
{
Expand Down
Loading

0 comments on commit 5ef8d0a

Please sign in to comment.