Files
Artur Laksberg 4dab326ce1 Abstract platform-specific parts & demo UWP support (#183)
Motivation:
DotNetty is already working under .NET Core and full .NET Framework but support for other platforms (like UWP) is missing. It is important to have reach in that space as well.

Modifications:
- Thread-based functionality is modeled with Tasks (as threads are not part of supported .NET Standard 1.3).
- IPlatform / DefaultPlatform are added to abstract platform-dependent functionality not available across the board.
- UWP platform implementation is demonstrated in an example along StreamSocket-based Channel.

Result:
UWP support for DotNetty is easy to implement now. Basics for platform-dependent code are added making further development easier.
2017-01-19 12:58:01 -08:00

52 lines
2.0 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace UWPEcho.Client
{
using Windows.Storage.Streams;
using Windows.System.Diagnostics;
using Windows.System.Profile;
using DotNetty.Common.Internal;
class UWPPlatform : IPlatform
{
int IPlatform.GetCurrentProcessId() => (int)ProcessDiagnosticInfo.GetForCurrentProcess().ProcessId;
byte[] IPlatform.GetDefaultDeviceId()
{
var signature = new byte[8];
int index = 0;
HardwareToken hardwareToken = HardwareIdentification.GetPackageSpecificToken(null);
using (DataReader dataReader = DataReader.FromBuffer(hardwareToken.Id))
{
int offset = 0;
while (offset < hardwareToken.Id.Length && index < 7)
{
var hardwareEntry = new byte[4];
dataReader.ReadBytes(hardwareEntry);
byte componentID = hardwareEntry[0];
byte componentIDReserved = hardwareEntry[1];
if (componentIDReserved == 0)
{
switch (componentID)
{
// Per guidance in http://msdn.microsoft.com/en-us/library/windows/apps/jj553431
case 1: // CPU
case 2: // Memory
case 4: // Network Adapter
case 9: // Bios
signature[index++] = hardwareEntry[2];
signature[index++] = hardwareEntry[3];
break;
default:
break;
}
}
offset += 4;
}
}
return signature;
}
}
}