fixed usings and namespaces

This commit is contained in:
Christopher Willis-Ford 2022-07-07 17:40:49 -07:00
parent 59f00f9992
commit 2c9e4c600a
19 changed files with 74 additions and 40 deletions

View file

@ -4,12 +4,15 @@
namespace ScratchLink.BLE;
using ScratchLink.Extensions;
using ScratchLink.JsonRpc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.WebSockets;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using ScratchLink.Extensions;
using ScratchLink.JsonRpc;
/// <summary>
/// Implements the cross-platform portions of a BLE session.

View file

@ -4,12 +4,12 @@
namespace ScratchLink.BLE;
using ScratchLink.JsonRpc;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.Json;
using System.Text.RegularExpressions;
using ScratchLink.JsonRpc;
/// <summary>
/// Helper methods to deal with GATT names and UUID values.

View file

@ -4,6 +4,10 @@
namespace ScratchLink.BLE;
using System;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Interface representing a GATT "endpoint" -- a characteristic on a service.
/// </summary>

View file

@ -4,6 +4,7 @@
namespace ScratchLink;
using System;
using System.Text;
using System.Text.Json;
using ScratchLink.JsonRpc;

View file

@ -6,7 +6,9 @@ namespace ScratchLink;
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
/// <summary>
/// Adaptor to use "await" with events.

View file

@ -4,6 +4,9 @@
namespace ScratchLink.Extensions;
using System.Collections.Generic;
using System.Linq;
/// <summary>
/// Extensions for use with containers or other enumerables.
/// </summary>

View file

@ -5,9 +5,11 @@
namespace ScratchLink.Extensions;
using System;
using System.IO;
using System.Net.WebSockets;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
/// <summary>

View file

@ -21,7 +21,7 @@ internal class JsonRpc2Exception : Exception
}
/// <summary>
/// Gets the <see cref="JsonRpc2Error"/> object associated with the thrown error.
/// Gets or sets the <see cref="JsonRpc2Error"/> object associated with the thrown error.
/// </summary>
public JsonRpc2Error Error { get; init; }
public JsonRpc2Error Error { get; set; }
}

View file

@ -4,6 +4,7 @@
namespace ScratchLink.JsonRpc;
using System.Collections.Generic;
using System.Text.Json.Serialization;
/// <summary>
@ -20,11 +21,11 @@ internal class JsonRpc2Message
public const string JsonRpcVersion = "2.0";
/// <summary>
/// Gets the JSON RPC version string.
/// Gets or sets the JSON RPC version string.
/// </summary>
[JsonPropertyName("jsonrpc")]
[JsonPropertyOrder(-100)]
public string JsonRPC { get; init; } = JsonRpcVersion;
public string JsonRPC { get; set; } = JsonRpcVersion;
/// <summary>
/// Gets or sets the request / response ID.

View file

@ -4,21 +4,26 @@
namespace ScratchLink;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net.WebSockets;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using ScratchLink.Extensions;
using ScratchLink.JsonRpc;
using ScratchLink.JsonRpc.Converters;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Net.WebSockets;
using System.Text.Json;
using JsonRpcMethodHandler = Func<
using JsonRpcMethodHandler = System.Func<
string, // method name
System.Text.Json.JsonElement?, // params / args
Task<object> // return value - must be JSON-serializable
System.Threading.Tasks.Task<object> // return value - must be JSON-serializable
>;
using RequestId = UInt32;
using RequestId = System.UInt32;
/// <summary>
/// Base class for Scratch Link sessions. One session can search for, connect to, and interact with one peripheral device.

View file

@ -4,8 +4,10 @@
namespace ScratchLink;
using System;
using System.Collections.Concurrent;
using System.Net.WebSockets;
using System.Threading.Tasks;
/// <summary>
/// This class connects a WebSocket to the appropriate session type and tracks the collection of active sessions.

View file

@ -4,8 +4,12 @@
namespace ScratchLink;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// Listen for WebSocket connections and direct them to service handlers.

View file

@ -2,8 +2,11 @@
// Copyright (c) Scratch Foundation. All rights reserved.
// </copyright>
namespace ScratchLink.Platforms.MacCatalyst.BLE;
namespace ScratchLink.Mac.BLE;
using System;
using System.Threading;
using System.Threading.Tasks;
using CoreBluetooth;
using Foundation;
using ScratchLink.BLE;

View file

@ -2,19 +2,22 @@
// Copyright (c) Scratch Foundation. All rights reserved.
// </copyright>
namespace ScratchLink.Platforms.MacCatalyst.BLE;
namespace ScratchLink.Mac.BLE;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.WebSockets;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using CoreBluetooth;
using Foundation;
using ScratchLink.BLE;
using ScratchLink.Extensions;
using ScratchLink.JsonRpc;
using ScratchLink.Platforms.MacCatalyst.Extensions;
using ScratchLink.Mac.Extensions;
/// <summary>
/// Implements a BLE session on MacOS.
@ -75,15 +78,15 @@ internal class MacBLESession : BLESession<CBUUID>
{
get => this.cbManager.State switch
{
CBManagerState.Unsupported => BluetoothState.Unavailable,
CBManagerState.Unauthorized => BluetoothState.Unavailable,
CBManagerState.PoweredOff => BluetoothState.Unavailable,
CBCentralManagerState.Unsupported => BluetoothState.Unavailable,
CBCentralManagerState.Unauthorized => BluetoothState.Unavailable,
CBCentralManagerState.PoweredOff => BluetoothState.Unavailable,
CBManagerState.PoweredOn => BluetoothState.Available,
CBCentralManagerState.PoweredOn => BluetoothState.Available,
// Resetting probably means the OS Bluetooth stack crashed and will "power on" again soon
CBManagerState.Resetting => BluetoothState.Unknown,
CBManagerState.Unknown => BluetoothState.Unknown,
CBCentralManagerState.Resetting => BluetoothState.Unknown,
CBCentralManagerState.Unknown => BluetoothState.Unknown,
_ => BluetoothState.Unknown
};
}
@ -173,7 +176,7 @@ internal class MacBLESession : BLESession<CBUUID>
#if DEBUG
this.connectedPeripheral.DidOpenL2CapChannel += (o, e) => Debug.Print("DidOpenL2CapChannel");
this.connectedPeripheral.DiscoveredCharacteristics += (o, e) => Debug.Print("DiscoveredCharacteristics");
this.connectedPeripheral.DiscoveredCharacteristic += (o, e) => Debug.Print("DiscoveredCharacteristic");
this.connectedPeripheral.DiscoveredDescriptor += (o, e) => Debug.Print("DiscoveredDescriptor");
this.connectedPeripheral.DiscoveredIncludedService += (o, e) => Debug.Print("DiscoveredIncludedService");
this.connectedPeripheral.DiscoveredService += (o, e) => Debug.Print("DiscoveredService");
@ -265,8 +268,8 @@ internal class MacBLESession : BLESession<CBUUID>
if (service.Characteristics == null)
{
using var characteristicDiscoveryAwaiter = new EventAwaiter<CBServiceEventArgs>(
h => service.Peripheral.DiscoveredCharacteristics += h,
h => service.Peripheral.DiscoveredCharacteristics -= h);
h => service.Peripheral.DiscoveredCharacteristic += h,
h => service.Peripheral.DiscoveredCharacteristic -= h);
while (service.Characteristics == null)
{
@ -311,22 +314,22 @@ internal class MacBLESession : BLESession<CBUUID>
{
switch (this.cbManager.State)
{
case CBManagerState.Resetting:
case CBCentralManagerState.Resetting:
Debug.Print("Bluetooth is resetting");
break;
case CBManagerState.Unsupported:
case CBCentralManagerState.Unsupported:
Debug.Print("Bluetooth is unsupported");
break;
case CBManagerState.Unauthorized:
case CBCentralManagerState.Unauthorized:
Debug.Print("Bluetooth is unauthorized");
break;
case CBManagerState.PoweredOff:
case CBCentralManagerState.PoweredOff:
Debug.Print("Bluetooth is now powered off");
break;
case CBManagerState.PoweredOn:
case CBCentralManagerState.PoweredOn:
Debug.Print("Bluetooth is now powered on");
break;
case CBManagerState.Unknown:
case CBCentralManagerState.Unknown:
default:
Debug.Print($"Bluetooth transitioned to unknown state: {this.cbManager.State}");
break;

View file

@ -2,7 +2,7 @@
// Copyright (c) Scratch Foundation. All rights reserved.
// </copyright>
namespace ScratchLink.Platforms.MacCatalyst.BLE;
namespace ScratchLink.Mac.BLE;
using CoreBluetooth;
using ScratchLink.BLE;

View file

@ -2,7 +2,7 @@
// Copyright (c) Scratch Foundation. All rights reserved.
// </copyright>
namespace ScratchLink.Platforms.MacCatalyst.Extensions;
namespace ScratchLink.Mac.Extensions;
using Foundation;

View file

@ -2,10 +2,10 @@
// Copyright (c) Scratch Foundation. All rights reserved.
// </copyright>
namespace ScratchLink.Platforms.MacCatalyst;
namespace ScratchLink.Mac;
using System.Net.WebSockets;
using ScratchLink.Platforms.MacCatalyst.BLE;
using ScratchLink.Mac.BLE;
/// <summary>
/// Implements the Mac-specific functionality of the SessionManager.

View file

@ -5,7 +5,6 @@
namespace ScratchLink.Mac;
using System;
using AppKit;
using Foundation;

View file

@ -105,14 +105,16 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<AdditionalFiles Include="$(SolutionDir)stylecop.json" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
<Version>6.0.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Text.Json">
<Version>6.0.5</Version>
</PackageReference>
<PackageReference Include="System.Threading.Channels">
<Version>6.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection">
<Version>6.0.0</Version>
</PackageReference>
</ItemGroup>
</Project>