@@ -47,8 +47,8 @@ | |||||
<file src="..\Frameworks\MQTTnet.Netstandard\bin\Release\netstandard1.3\MQTTnet.*" target="lib\netstandard1.3\"/> | <file src="..\Frameworks\MQTTnet.Netstandard\bin\Release\netstandard1.3\MQTTnet.*" target="lib\netstandard1.3\"/> | ||||
<!-- Universal Windows --> | <!-- Universal Windows --> | ||||
<file src="..\Frameworks\MQTTnet.UniversalWindows\bin\Release\MQTTnet.Core.*" target="lib\uap10.0\"/> | |||||
<file src="..\Frameworks\MQTTnet.UniversalWindows\bin\Release\MQTTnet.*" target="lib\uap10.0\"/> | |||||
<file src="..\Frameworks\MQTTnet.Netstandard\bin\Release\uap10.0\MQTTnet.Core.*" target="lib\uap10.0\"/> | |||||
<file src="..\Frameworks\MQTTnet.Netstandard\bin\Release\uap10.0\MQTTnet.*" target="lib\uap10.0\"/> | |||||
<!-- .NET Framework --> | <!-- .NET Framework --> | ||||
<file src="..\Frameworks\MQTTnet.Netstandard\bin\Release\net451\MQTTnet.Core.*" target="lib\net451\"/> | <file src="..\Frameworks\MQTTnet.Netstandard\bin\Release\net451\MQTTnet.Core.*" target="lib\net451\"/> | ||||
@@ -2,12 +2,20 @@ param([string]$version) | |||||
if ([string]::IsNullOrEmpty($version)) {$version = "0.0.1"} | if ([string]::IsNullOrEmpty($version)) {$version = "0.0.1"} | ||||
$msbuild = "MSBuild.exe" | |||||
&dotnet build ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj -c="Release" /p:FileVersion=$version /p:AssemblyVersion=$version | |||||
&dotnet build ..\Frameworks\MQTTnet.AspNetCore\MQTTnet.AspNetCore.csproj -c="Release" /p:FileVersion=$version /p:AssemblyVersion=$version | |||||
&$msbuild ..\Frameworks\MQTTnet.UniversalWindows\MQTTnet.UniversalWindows.csproj /t:Build /p:Configuration="Release" | |||||
Remove-Item .\NuGet -Force -Recurse | |||||
New-Item -ItemType Directory -Force -Path .\NuGet | |||||
.\NuGet.exe pack MQTTnet.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $version | |||||
.\NuGet.exe pack MQTTnet.AspNetCore.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $version | |||||
$vswhere = ${Env:\ProgramFiles(x86)} + '\Microsoft Visual Studio\Installer\vswhere' | |||||
$path = &$vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath | |||||
if ($path) { | |||||
$msbuild = join-path $path 'MSBuild\15.0\Bin\MSBuild.exe' | |||||
&$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="net451" /p:FileVersion=$version /p:AssemblyVersion=$version /verbosity:m | |||||
&$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="netstandard1.3" /p:FileVersion=$version /p:AssemblyVersion=$version /verbosity:m | |||||
&$msbuild ..\Frameworks\MQTTnet.Netstandard\MQTTnet.Netstandard.csproj /t:Build /p:Configuration="Release" /p:TargetFramework="uap10.0" /p:FileVersion=$version /p:AssemblyVersion=$version /verbosity:m | |||||
&dotnet build ..\Frameworks\MQTTnet.AspNetCore\MQTTnet.AspNetCore.csproj -c="Release" /p:FileVersion=$version /p:AssemblyVersion=$version | |||||
Remove-Item .\NuGet -Force -Recurse | |||||
New-Item -ItemType Directory -Force -Path .\NuGet | |||||
.\NuGet.exe pack MQTTnet.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $version | |||||
.\NuGet.exe pack MQTTnet.AspNetCore.nuspec -Verbosity detailed -Symbols -OutputDir "NuGet" -Version $version | |||||
} | |||||
@@ -1,4 +1,6 @@ | |||||
using System; | |||||
#if NET451 || NETSTANDARD1_3 | |||||
using System; | |||||
using System.Net; | using System.Net; | ||||
using System.Net.Security; | using System.Net.Security; | ||||
using System.Net.Sockets; | using System.Net.Sockets; | ||||
@@ -143,4 +145,5 @@ namespace MQTTnet.Implementations | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | |||||
} | |||||
#endif |
@@ -1,3 +1,5 @@ | |||||
#if NET451 || NETSTANDARD1_3 | |||||
using System; | using System; | ||||
using System.Net.Security; | using System.Net.Security; | ||||
using System.Net.Sockets; | using System.Net.Sockets; | ||||
@@ -155,4 +157,5 @@ namespace MQTTnet.Implementations | |||||
} | } | ||||
} | } | ||||
} | |||||
} | |||||
#endif |
@@ -1,3 +1,5 @@ | |||||
#if NET451 || NETSTANDARD1_3 | |||||
#else | |||||
using System; | using System; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using MQTTnet.Core.Adapter; | using MQTTnet.Core.Adapter; | ||||
@@ -69,4 +71,5 @@ namespace MQTTnet.Implementations | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | |||||
} | |||||
#endif |
@@ -1,3 +1,5 @@ | |||||
#if NET451 || NETSTANDARD1_3 | |||||
#else | |||||
using System; | using System; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.IO; | using System.IO; | ||||
@@ -133,4 +135,5 @@ namespace MQTTnet.Implementations | |||||
return result; | return result; | ||||
} | } | ||||
} | } | ||||
} | |||||
} | |||||
#endif |
@@ -1,7 +1,7 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk"> | <Project Sdk="Microsoft.NET.Sdk"> | ||||
<PropertyGroup> | <PropertyGroup> | ||||
<TargetFrameworks>netstandard1.3;net451</TargetFrameworks> | |||||
<TargetFrameworks>netstandard1.3;net451;uap10.0</TargetFrameworks> | |||||
<AssemblyName>MQTTnet</AssemblyName> | <AssemblyName>MQTTnet</AssemblyName> | ||||
<RootNamespace>MQTTnet</RootNamespace> | <RootNamespace>MQTTnet</RootNamespace> | ||||
<AssemblyVersion>2.5.0.0</AssemblyVersion> | <AssemblyVersion>2.5.0.0</AssemblyVersion> | ||||
@@ -14,6 +14,19 @@ | |||||
<PackageId /> | <PackageId /> | ||||
</PropertyGroup> | </PropertyGroup> | ||||
<PropertyGroup Condition="'$(TargetFramework)' == 'uap10.0'"> | |||||
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies> | |||||
<NugetTargetMoniker>UAP,Version=v10.0</NugetTargetMoniker> | |||||
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier> | |||||
<TargetPlatformVersion>10.0.15063.0</TargetPlatformVersion> | |||||
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion> | |||||
<TargetFrameworkIdentifier>.NETCore</TargetFrameworkIdentifier> | |||||
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion> | |||||
<DefineConstants>$(DefineConstants);WINDOWS_UWP</DefineConstants> | |||||
<LanguageTargets>$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets</LanguageTargets> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'" /> | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'" /> | ||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> | <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" /> | ||||
@@ -34,4 +47,8 @@ | |||||
<PackageReference Include="System.Threading.Thread" Version="4.3.0" /> | <PackageReference Include="System.Threading.Thread" Version="4.3.0" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup Condition="'$(TargetFramework)'=='uap10.0'"> | |||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="5.4.0" /> | |||||
</ItemGroup> | |||||
</Project> | </Project> |
@@ -1,92 +0,0 @@ | |||||
using MQTTnet.Core.Channel; | |||||
using MQTTnet.Core.Client; | |||||
using System; | |||||
using System.IO; | |||||
using System.Net.WebSockets; | |||||
using System.Security.Cryptography.X509Certificates; | |||||
using System.Threading; | |||||
using System.Threading.Tasks; | |||||
namespace MQTTnet.Implementations | |||||
{ | |||||
public sealed class MqttWebSocketChannel : IMqttCommunicationChannel, IDisposable | |||||
{ | |||||
private readonly MqttClientWebSocketOptions _options; | |||||
private ClientWebSocket _webSocket = new ClientWebSocket(); | |||||
public MqttWebSocketChannel(MqttClientWebSocketOptions options) | |||||
{ | |||||
_options = options ?? throw new ArgumentNullException(nameof(options)); | |||||
} | |||||
public Stream RawReceiveStream { get; private set; } | |||||
public Stream SendStream => RawReceiveStream; | |||||
public Stream ReceiveStream => RawReceiveStream; | |||||
public async Task ConnectAsync() | |||||
{ | |||||
var uri = _options.Uri; | |||||
if (!uri.StartsWith("ws://", StringComparison.OrdinalIgnoreCase)) | |||||
{ | |||||
uri = "ws://" + uri; | |||||
} | |||||
_webSocket = new ClientWebSocket(); | |||||
if (_options.RequestHeaders != null) | |||||
{ | |||||
foreach (var requestHeader in _options.RequestHeaders) | |||||
{ | |||||
_webSocket.Options.SetRequestHeader(requestHeader.Key, requestHeader.Value); | |||||
} | |||||
} | |||||
if (_options.SubProtocols != null) | |||||
{ | |||||
foreach (var subProtocol in _options.SubProtocols) | |||||
{ | |||||
_webSocket.Options.AddSubProtocol(subProtocol); | |||||
} | |||||
} | |||||
if (_options.CookieContainer != null) | |||||
{ | |||||
_webSocket.Options.Cookies = _options.CookieContainer; | |||||
} | |||||
if (_options.TlsOptions?.UseTls == true && _options.TlsOptions?.Certificates != null) | |||||
{ | |||||
_webSocket.Options.ClientCertificates = new X509CertificateCollection(); | |||||
foreach (var certificate in _options.TlsOptions.Certificates) | |||||
{ | |||||
_webSocket.Options.ClientCertificates.Add(new X509Certificate(certificate)); | |||||
} | |||||
} | |||||
await _webSocket.ConnectAsync(new Uri(uri), CancellationToken.None).ConfigureAwait(false); | |||||
RawReceiveStream = new WebSocketStream(_webSocket); | |||||
} | |||||
public async Task DisconnectAsync() | |||||
{ | |||||
RawReceiveStream = null; | |||||
if (_webSocket == null) | |||||
{ | |||||
return; | |||||
} | |||||
if (_webSocket.State == WebSocketState.Open || _webSocket.State == WebSocketState.Connecting) | |||||
{ | |||||
await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None).ConfigureAwait(false); | |||||
} | |||||
} | |||||
public void Dispose() | |||||
{ | |||||
_webSocket?.Dispose(); | |||||
_webSocket = null; | |||||
} | |||||
} | |||||
} |
@@ -1,84 +0,0 @@ | |||||
using System; | |||||
using System.IO; | |||||
using System.Net.WebSockets; | |||||
using System.Threading; | |||||
using System.Threading.Tasks; | |||||
using MQTTnet.Core.Exceptions; | |||||
namespace MQTTnet.Implementations | |||||
{ | |||||
public class WebSocketStream : Stream | |||||
{ | |||||
private readonly WebSocket _webSocket; | |||||
public WebSocketStream(WebSocket webSocket) | |||||
{ | |||||
_webSocket = webSocket ?? throw new ArgumentNullException(nameof(webSocket)); | |||||
} | |||||
public override void Flush() | |||||
{ | |||||
} | |||||
public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) | |||||
{ | |||||
var currentOffset = offset; | |||||
var targetOffset = offset + count; | |||||
while (_webSocket.State == WebSocketState.Open && currentOffset < targetOffset) | |||||
{ | |||||
var response = await _webSocket.ReceiveAsync(new ArraySegment<byte>(buffer, currentOffset, count), cancellationToken).ConfigureAwait(false); | |||||
currentOffset += response.Count; | |||||
count -= response.Count; | |||||
if (response.MessageType == WebSocketMessageType.Close) | |||||
{ | |||||
await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, cancellationToken).ConfigureAwait(false); | |||||
} | |||||
} | |||||
if (_webSocket.State == WebSocketState.Closed) | |||||
{ | |||||
throw new MqttCommunicationException("connection closed"); | |||||
} | |||||
return currentOffset - offset; | |||||
} | |||||
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) | |||||
{ | |||||
return _webSocket.SendAsync(new ArraySegment<byte>(buffer, offset, count), WebSocketMessageType.Binary, true, cancellationToken); | |||||
} | |||||
public override int Read(byte[] buffer, int offset, int count) | |||||
{ | |||||
return ReadAsync(buffer, offset, count).GetAwaiter().GetResult(); | |||||
} | |||||
public override void Write(byte[] buffer, int offset, int count) | |||||
{ | |||||
WriteAsync(buffer, offset, count).GetAwaiter().GetResult(); | |||||
} | |||||
public override bool CanRead => true; | |||||
public override bool CanSeek => false; | |||||
public override bool CanWrite => true; | |||||
public override long Length => throw new NotSupportedException(); | |||||
public override long Position | |||||
{ | |||||
get => throw new NotSupportedException(); | |||||
set => throw new NotSupportedException(); | |||||
} | |||||
public override long Seek(long offset, SeekOrigin origin) | |||||
{ | |||||
throw new NotSupportedException(); | |||||
} | |||||
public override void SetLength(long value) | |||||
{ | |||||
throw new NotSupportedException(); | |||||
} | |||||
} | |||||
} |
@@ -1,200 +0,0 @@ | |||||
<?xml version="1.0" encoding="utf-8"?> | |||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | |||||
<PropertyGroup> | |||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | |||||
<ProjectGuid>{BD60C727-D8E8-40C3-B8E3-C95A864AE611}</ProjectGuid> | |||||
<OutputType>Library</OutputType> | |||||
<AppDesignerFolder>Properties</AppDesignerFolder> | |||||
<RootNamespace>MQTTnet</RootNamespace> | |||||
<AssemblyName>MQTTnet</AssemblyName> | |||||
<DefaultLanguage>en-US</DefaultLanguage> | |||||
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier> | |||||
<TargetPlatformVersion>10.0.15063.0</TargetPlatformVersion> | |||||
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion> | |||||
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion> | |||||
<FileAlignment>512</FileAlignment> | |||||
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | |||||
<RuntimeIdentifiers>win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot</RuntimeIdentifiers> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |||||
<PlatformTarget>AnyCPU</PlatformTarget> | |||||
<DebugSymbols>true</DebugSymbols> | |||||
<DebugType>full</DebugType> | |||||
<Optimize>false</Optimize> | |||||
<OutputPath>bin\Debug\</OutputPath> | |||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | |||||
<ErrorReport>prompt</ErrorReport> | |||||
<WarningLevel>4</WarningLevel> | |||||
<NoWarn>CS1591</NoWarn> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |||||
<PlatformTarget>AnyCPU</PlatformTarget> | |||||
<DebugType>pdbonly</DebugType> | |||||
<Optimize>true</Optimize> | |||||
<OutputPath>bin\Release\</OutputPath> | |||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | |||||
<ErrorReport>prompt</ErrorReport> | |||||
<WarningLevel>4</WarningLevel> | |||||
<NoWarn>CS1591</NoWarn> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> | |||||
<PlatformTarget>x86</PlatformTarget> | |||||
<DebugSymbols>true</DebugSymbols> | |||||
<OutputPath>bin\x86\Debug\</OutputPath> | |||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | |||||
<NoWarn>;2008,CS1591</NoWarn> | |||||
<DebugType>full</DebugType> | |||||
<PlatformTarget>x86</PlatformTarget> | |||||
<UseVSHostingProcess>false</UseVSHostingProcess> | |||||
<ErrorReport>prompt</ErrorReport> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> | |||||
<PlatformTarget>x86</PlatformTarget> | |||||
<OutputPath>bin\x86\Release\</OutputPath> | |||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | |||||
<Optimize>true</Optimize> | |||||
<NoWarn>;2008,CS1591</NoWarn> | |||||
<DebugType>pdbonly</DebugType> | |||||
<PlatformTarget>x86</PlatformTarget> | |||||
<UseVSHostingProcess>false</UseVSHostingProcess> | |||||
<ErrorReport>prompt</ErrorReport> | |||||
<DocumentationFile>bin\x86\Release\MQTTnet.XML</DocumentationFile> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'"> | |||||
<PlatformTarget>ARM</PlatformTarget> | |||||
<DebugSymbols>true</DebugSymbols> | |||||
<OutputPath>bin\ARM\Debug\</OutputPath> | |||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | |||||
<NoWarn>;2008,CS1591</NoWarn> | |||||
<DebugType>full</DebugType> | |||||
<PlatformTarget>ARM</PlatformTarget> | |||||
<UseVSHostingProcess>false</UseVSHostingProcess> | |||||
<ErrorReport>prompt</ErrorReport> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'"> | |||||
<PlatformTarget>ARM</PlatformTarget> | |||||
<OutputPath>bin\ARM\Release\</OutputPath> | |||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | |||||
<Optimize>true</Optimize> | |||||
<NoWarn>;2008,CS1591</NoWarn> | |||||
<DebugType>pdbonly</DebugType> | |||||
<PlatformTarget>ARM</PlatformTarget> | |||||
<UseVSHostingProcess>false</UseVSHostingProcess> | |||||
<ErrorReport>prompt</ErrorReport> | |||||
<DocumentationFile>bin\ARM\Release\MQTTnet.XML</DocumentationFile> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> | |||||
<PlatformTarget>x64</PlatformTarget> | |||||
<DebugSymbols>true</DebugSymbols> | |||||
<OutputPath>bin\x64\Debug\</OutputPath> | |||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | |||||
<NoWarn>;2008,CS1591</NoWarn> | |||||
<DebugType>full</DebugType> | |||||
<PlatformTarget>x64</PlatformTarget> | |||||
<UseVSHostingProcess>false</UseVSHostingProcess> | |||||
<ErrorReport>prompt</ErrorReport> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> | |||||
<PlatformTarget>x64</PlatformTarget> | |||||
<OutputPath>bin\x64\Release\</OutputPath> | |||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | |||||
<Optimize>true</Optimize> | |||||
<NoWarn>;2008,CS1591</NoWarn> | |||||
<DebugType>pdbonly</DebugType> | |||||
<PlatformTarget>x64</PlatformTarget> | |||||
<UseVSHostingProcess>false</UseVSHostingProcess> | |||||
<ErrorReport>prompt</ErrorReport> | |||||
<GenerateLibraryLayout>false</GenerateLibraryLayout> | |||||
<DocumentationFile>bin\x64\Release\MQTTnet.XML</DocumentationFile> | |||||
</PropertyGroup> | |||||
<ItemGroup> | |||||
<Compile Include="Implementations\MqttWebSocketChannel.cs" /> | |||||
<Compile Include="MqttFactory.cs" /> | |||||
<Compile Include="Implementations\MqttServerAdapter.cs" /> | |||||
<Compile Include="Implementations\MqttTcpChannel.cs" /> | |||||
<Compile Include="Properties\AssemblyInfo.cs" /> | |||||
<Compile Include="Implementations\WebSocketStream.cs" /> | |||||
<Compile Include="ServiceCollectionExtensions.cs" /> | |||||
<EmbeddedResource Include="Properties\MQTTnet.Universal.rd.xml" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<ProjectReference Include="..\..\MQTTnet.Core\MQTTnet.Core.csproj"> | |||||
<Project>{2ecb99e4-72d0-4c23-99ba-93d511d3967d}</Project> | |||||
<Name>MQTTnet.Core</Name> | |||||
</ProjectReference> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection"> | |||||
<Version>1.1.1</Version> | |||||
</PackageReference> | |||||
<PackageReference Include="Microsoft.Extensions.Logging"> | |||||
<Version>1.1.2</Version> | |||||
</PackageReference> | |||||
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform"> | |||||
<Version>5.4.0</Version> | |||||
</PackageReference> | |||||
</ItemGroup> | |||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' "> | |||||
<VisualStudioVersion>14.0</VisualStudioVersion> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Any CPU|AnyCPU'"> | |||||
<OutputPath>bin\Any CPU\</OutputPath> | |||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | |||||
<Optimize>true</Optimize> | |||||
<NoStdLib>true</NoStdLib> | |||||
<DebugType>pdbonly</DebugType> | |||||
<PlatformTarget>AnyCPU</PlatformTarget> | |||||
<UseVSHostingProcess>false</UseVSHostingProcess> | |||||
<ErrorReport>prompt</ErrorReport> | |||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Any CPU|x86'"> | |||||
<OutputPath>bin\x86\Any CPU\</OutputPath> | |||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | |||||
<DocumentationFile>bin\x86\Release\MQTTnet.XML</DocumentationFile> | |||||
<Optimize>true</Optimize> | |||||
<NoWarn>;2008</NoWarn> | |||||
<NoStdLib>true</NoStdLib> | |||||
<DebugType>pdbonly</DebugType> | |||||
<PlatformTarget>x86</PlatformTarget> | |||||
<UseVSHostingProcess>false</UseVSHostingProcess> | |||||
<ErrorReport>prompt</ErrorReport> | |||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Any CPU|ARM'"> | |||||
<OutputPath>bin\ARM\Any CPU\</OutputPath> | |||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | |||||
<DocumentationFile>bin\ARM\Release\MQTTnet.XML</DocumentationFile> | |||||
<Optimize>true</Optimize> | |||||
<NoWarn>;2008</NoWarn> | |||||
<NoStdLib>true</NoStdLib> | |||||
<DebugType>pdbonly</DebugType> | |||||
<PlatformTarget>ARM</PlatformTarget> | |||||
<UseVSHostingProcess>false</UseVSHostingProcess> | |||||
<ErrorReport>prompt</ErrorReport> | |||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | |||||
</PropertyGroup> | |||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Any CPU|x64'"> | |||||
<OutputPath>bin\x64\Any CPU\</OutputPath> | |||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants> | |||||
<DocumentationFile>bin\x64\Release\MQTTnet.XML</DocumentationFile> | |||||
<Optimize>true</Optimize> | |||||
<NoWarn>;2008</NoWarn> | |||||
<NoStdLib>true</NoStdLib> | |||||
<DebugType>pdbonly</DebugType> | |||||
<PlatformTarget>x64</PlatformTarget> | |||||
<UseVSHostingProcess>false</UseVSHostingProcess> | |||||
<ErrorReport>prompt</ErrorReport> | |||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> | |||||
</PropertyGroup> | |||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" /> | |||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | |||||
Other similar extension points exist, see Microsoft.Common.targets. | |||||
<Target Name="BeforeBuild"> | |||||
</Target> | |||||
<Target Name="AfterBuild"> | |||||
</Target> | |||||
--> | |||||
</Project> |
@@ -1,125 +0,0 @@ | |||||
using System; | |||||
using Microsoft.Extensions.DependencyInjection; | |||||
using Microsoft.Extensions.Logging; | |||||
using Microsoft.Extensions.Options; | |||||
using MQTTnet.Core.Adapter; | |||||
using MQTTnet.Core.Channel; | |||||
using MQTTnet.Core.Client; | |||||
using MQTTnet.Core.ManagedClient; | |||||
using MQTTnet.Core.Serializer; | |||||
using MQTTnet.Core.Server; | |||||
using MQTTnet.Implementations; | |||||
namespace MQTTnet | |||||
{ | |||||
public class MqttFactory : IMqttCommunicationAdapterFactory, IMqttClientSesssionFactory, IMqttClientFactory, IMqttServerFactory | |||||
{ | |||||
private readonly IServiceProvider _serviceProvider; | |||||
private static IServiceProvider BuildServiceProvider() | |||||
{ | |||||
var serviceProvider = new ServiceCollection() | |||||
.AddMqttClient() | |||||
.AddMqttServer() | |||||
.AddLogging() | |||||
.BuildServiceProvider(); | |||||
serviceProvider.GetRequiredService<ILoggerFactory>() | |||||
.AddMqttTrace(); | |||||
return serviceProvider; | |||||
} | |||||
public MqttFactory() | |||||
: this(BuildServiceProvider()) | |||||
{ | |||||
} | |||||
public MqttFactory(IServiceProvider serviceProvider) | |||||
{ | |||||
_serviceProvider = serviceProvider; | |||||
} | |||||
public IMqttCommunicationAdapter CreateClientMqttCommunicationAdapter(IMqttClientOptions options) | |||||
{ | |||||
var logger = _serviceProvider.GetRequiredService<ILogger<MqttChannelCommunicationAdapter>>(); | |||||
return new MqttChannelCommunicationAdapter(CreateMqttCommunicationChannel(options.ChannelOptions), CreateSerializer(options.ProtocolVersion), logger); | |||||
} | |||||
public IMqttCommunicationAdapter CreateServerMqttCommunicationAdapter(IMqttCommunicationChannel channel) | |||||
{ | |||||
var serializer = _serviceProvider.GetRequiredService<IMqttPacketSerializer>(); | |||||
var logger = _serviceProvider.GetRequiredService<ILogger<MqttChannelCommunicationAdapter>>(); | |||||
return new MqttChannelCommunicationAdapter(channel, serializer, logger); | |||||
} | |||||
public IMqttCommunicationChannel CreateMqttCommunicationChannel(IMqttClientChannelOptions options) | |||||
{ | |||||
if (options == null) throw new ArgumentNullException(nameof(options)); | |||||
switch (options) | |||||
{ | |||||
case MqttClientTcpOptions tcpOptions: | |||||
return CreateTcpChannel(tcpOptions); | |||||
case MqttClientWebSocketOptions webSocketOptions: | |||||
return CreateWebSocketChannel(webSocketOptions); | |||||
default: | |||||
throw new NotSupportedException(); | |||||
} | |||||
} | |||||
public MqttTcpChannel CreateTcpChannel(MqttClientTcpOptions tcpOptions) | |||||
{ | |||||
return new MqttTcpChannel(tcpOptions); | |||||
} | |||||
public MqttWebSocketChannel CreateWebSocketChannel(MqttClientWebSocketOptions webSocketOptions) | |||||
{ | |||||
return new MqttWebSocketChannel(webSocketOptions); | |||||
} | |||||
public MqttPacketSerializer CreateSerializer(MqttProtocolVersion protocolVersion) | |||||
{ | |||||
return new MqttPacketSerializer | |||||
{ | |||||
ProtocolVersion = protocolVersion | |||||
}; | |||||
} | |||||
public MqttClientSession CreateClientSession(string clientId, MqttClientSessionsManager clientSessionsManager) | |||||
{ | |||||
return new MqttClientSession( | |||||
clientId, | |||||
_serviceProvider.GetRequiredService<IOptions<MqttServerOptions>>(), | |||||
clientSessionsManager, | |||||
_serviceProvider.GetRequiredService<MqttClientSubscriptionsManager>(), | |||||
_serviceProvider.GetRequiredService<ILogger<MqttClientSession>>(), | |||||
_serviceProvider.GetRequiredService<ILogger<MqttClientPendingMessagesQueue>>()); | |||||
} | |||||
public IMqttClient CreateMqttClient() | |||||
{ | |||||
return _serviceProvider.GetRequiredService<IMqttClient>(); | |||||
} | |||||
public IManagedMqttClient CreateManagedMqttClient() | |||||
{ | |||||
return _serviceProvider.GetRequiredService<ManagedMqttClient>(); | |||||
} | |||||
public IMqttServer CreateMqttServer() | |||||
{ | |||||
return _serviceProvider.GetRequiredService<IMqttServer>(); | |||||
} | |||||
public IMqttServer CreateMqttServer(Action<MqttServerOptions> configure) | |||||
{ | |||||
if (configure == null) throw new ArgumentNullException(nameof(configure)); | |||||
var options = _serviceProvider.GetRequiredService<IOptions<MqttServerOptions>>(); | |||||
configure(options.Value); | |||||
return _serviceProvider.GetRequiredService<IMqttServer>(); | |||||
} | |||||
} | |||||
} |
@@ -1,14 +0,0 @@ | |||||
using System.Reflection; | |||||
using System.Runtime.InteropServices; | |||||
[assembly: AssemblyTitle("MQTTnet")] | |||||
[assembly: AssemblyDescription("MQTTnet for Universal Windows")] | |||||
[assembly: AssemblyConfiguration("")] | |||||
[assembly: AssemblyCompany("Christian Kratky")] | |||||
[assembly: AssemblyProduct("MQTTnet")] | |||||
[assembly: AssemblyCopyright("Copyright © Christian Kratky 2016-2017")] | |||||
[assembly: AssemblyTrademark("")] | |||||
[assembly: AssemblyCulture("")] | |||||
[assembly: ComVisible(false)] | |||||
[assembly: AssemblyVersion("2.5.0.0")] | |||||
[assembly: AssemblyFileVersion("2.5.0.0")] |
@@ -1,5 +0,0 @@ | |||||
<?xml version="1.0" encoding="utf-8"?> | |||||
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata"> | |||||
<Library Name="MQTTnet.Universal"> | |||||
</Library> | |||||
</Directives> |
@@ -1,70 +0,0 @@ | |||||
using Microsoft.Extensions.DependencyInjection; | |||||
using MQTTnet.Core.Adapter; | |||||
using MQTTnet.Core.Client; | |||||
using MQTTnet.Core.ManagedClient; | |||||
using MQTTnet.Core.Serializer; | |||||
using MQTTnet.Core.Server; | |||||
using MQTTnet.Implementations; | |||||
using System; | |||||
using Microsoft.Extensions.Logging; | |||||
using MQTTnet.Core.Diagnostics; | |||||
namespace MQTTnet | |||||
{ | |||||
public static class ServiceCollectionExtensions | |||||
{ | |||||
public static IServiceCollection AddMqttServer(this IServiceCollection services) | |||||
{ | |||||
services.AddMqttServerServices(); | |||||
services.AddSingleton<IMqttServer>(s => s.GetService<MqttServer>()); | |||||
services.AddSingleton<MqttServer>(); | |||||
return services; | |||||
} | |||||
public static IServiceCollection AddMqttServerServices(this IServiceCollection services) | |||||
{ | |||||
services.AddOptions(); | |||||
services.AddSingleton<MqttFactory>(); | |||||
services.AddSingleton<IMqttCommunicationAdapterFactory>(s => s.GetService<MqttFactory>()); | |||||
services.AddSingleton<IMqttClientSesssionFactory>(s => s.GetService<MqttFactory>()); | |||||
services.AddTransient<IMqttServerAdapter, MqttServerAdapter>(); | |||||
services.AddTransient<IMqttPacketSerializer, MqttPacketSerializer>(); | |||||
services.AddTransient<MqttClientSessionsManager>(); | |||||
services.AddTransient<MqttClientSubscriptionsManager>(); | |||||
services.AddTransient<MqttClientRetainedMessagesManager>(); | |||||
return services; | |||||
} | |||||
public static IServiceCollection AddMqttServer(this IServiceCollection services, Action<MqttServerOptions> configureOptions) | |||||
{ | |||||
return services | |||||
.AddMqttServer() | |||||
.Configure(configureOptions); | |||||
} | |||||
public static IServiceCollection AddMqttClient(this IServiceCollection services) | |||||
{ | |||||
services.AddSingleton<MqttFactory>(); | |||||
services.AddSingleton<IMqttCommunicationAdapterFactory>(s => s.GetService<MqttFactory>()); | |||||
services.AddTransient<IMqttClient, MqttClient>(); | |||||
services.AddTransient<MqttClient>(); | |||||
services.AddTransient<IManagedMqttClient, ManagedMqttClient>(); | |||||
services.AddTransient<ManagedMqttClient>(); | |||||
services.AddTransient<IMqttPacketSerializer, MqttPacketSerializer>(); | |||||
services.AddTransient<MqttPacketDispatcher>(); | |||||
return services; | |||||
} | |||||
public static ILoggerFactory AddMqttTrace(this ILoggerFactory factory) | |||||
{ | |||||
factory.AddProvider(new MqttNetTrace()); | |||||
return factory; | |||||
} | |||||
} | |||||
} |
@@ -1,12 +1,10 @@ | |||||
| | ||||
Microsoft Visual Studio Solution File, Format Version 12.00 | Microsoft Visual Studio Solution File, Format Version 12.00 | ||||
# Visual Studio 15 | # Visual Studio 15 | ||||
VisualStudioVersion = 15.0.27004.2005 | |||||
VisualStudioVersion = 15.0.27004.2002 | |||||
MinimumVisualStudioVersion = 10.0.40219.1 | MinimumVisualStudioVersion = 10.0.40219.1 | ||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Core.Tests", "Tests\MQTTnet.Core.Tests\MQTTnet.Core.Tests.csproj", "{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}" | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Core.Tests", "Tests\MQTTnet.Core.Tests\MQTTnet.Core.Tests.csproj", "{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}" | ||||
EndProject | EndProject | ||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MQTTnet.UniversalWindows", "Frameworks\MQTTnet.UniversalWindows\MQTTnet.UniversalWindows.csproj", "{BD60C727-D8E8-40C3-B8E3-C95A864AE611}" | |||||
EndProject | |||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{9248C2E1-B9D6-40BF-81EC-86004D7765B4}" | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{9248C2E1-B9D6-40BF-81EC-86004D7765B4}" | ||||
EndProject | EndProject | ||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Frameworks", "Frameworks", "{32A630A7-2598-41D7-B625-204CD906F5FB}" | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Frameworks", "Frameworks", "{32A630A7-2598-41D7-B625-204CD906F5FB}" | ||||
@@ -64,22 +62,6 @@ Global | |||||
{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}.Release|x64.Build.0 = Release|Any CPU | {A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}.Release|x64.Build.0 = Release|Any CPU | ||||
{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}.Release|x86.ActiveCfg = Release|Any CPU | {A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}.Release|x86.ActiveCfg = Release|Any CPU | ||||
{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}.Release|x86.Build.0 = Release|Any CPU | {A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC}.Release|x86.Build.0 = Release|Any CPU | ||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Debug|ARM.ActiveCfg = Debug|ARM | |||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Debug|ARM.Build.0 = Debug|ARM | |||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Debug|x64.ActiveCfg = Debug|x64 | |||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Debug|x64.Build.0 = Debug|x64 | |||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Debug|x86.ActiveCfg = Debug|x86 | |||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Debug|x86.Build.0 = Debug|x86 | |||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Release|Any CPU.Build.0 = Release|Any CPU | |||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Release|ARM.ActiveCfg = Release|ARM | |||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Release|ARM.Build.0 = Release|ARM | |||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Release|x64.ActiveCfg = Release|x64 | |||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Release|x64.Build.0 = Release|x64 | |||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Release|x86.ActiveCfg = Release|x86 | |||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611}.Release|x86.Build.0 = Release|x86 | |||||
{2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
{2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Debug|Any CPU.Build.0 = Debug|Any CPU | {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
{2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Debug|ARM.ActiveCfg = Debug|Any CPU | {2ECB99E4-72D0-4C23-99BA-93D511D3967D}.Debug|ARM.ActiveCfg = Debug|Any CPU | ||||
@@ -188,7 +170,6 @@ Global | |||||
EndGlobalSection | EndGlobalSection | ||||
GlobalSection(NestedProjects) = preSolution | GlobalSection(NestedProjects) = preSolution | ||||
{A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4} | {A7FF0C91-25DE-4BA6-B39E-F54E8DADF1CC} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4} | ||||
{BD60C727-D8E8-40C3-B8E3-C95A864AE611} = {32A630A7-2598-41D7-B625-204CD906F5FB} | |||||
{FF1F72D6-9524-4422-9497-3CC0002216ED} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4} | {FF1F72D6-9524-4422-9497-3CC0002216ED} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4} | ||||
{3587E506-55A2-4EB3-99C7-DC01E42D25D2} = {32A630A7-2598-41D7-B625-204CD906F5FB} | {3587E506-55A2-4EB3-99C7-DC01E42D25D2} = {32A630A7-2598-41D7-B625-204CD906F5FB} | ||||
{3D283AAD-AAA8-4339-8394-52F80B6304DB} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4} | {3D283AAD-AAA8-4339-8394-52F80B6304DB} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4} | ||||