Browse Source

Cleanup.

release/3.x.x
Christian Kratky 5 years ago
parent
commit
2c927c5995
3 changed files with 11 additions and 54 deletions
  1. +1
    -1
      README.md
  2. +0
    -51
      Source/MQTTnet.AspnetCore/TopicFilterBuilder.cs
  3. +10
    -2
      Source/MQTTnet.Server/Logging/MqttNetLoggerWrapper.cs

+ 1
- 1
README.md View File

@@ -26,7 +26,7 @@ MQTTnet is a high performance .NET library for MQTT based communication. It prov
* Uniform API across all supported versions of the MQTT protocol * Uniform API across all supported versions of the MQTT protocol
* Interfaces included for mocking and testing * Interfaces included for mocking and testing
* Access to internal trace messages * Access to internal trace messages
* Unit tested (~150 tests)
* Unit tested (~200 tests)
* No external dependencies * No external dependencies


\* Tested on local machine (Intel i7 8700K) with MQTTnet client and server running in the same process using the TCP channel. The app for verification is part of this repository and stored in _/Tests/MQTTnet.TestApp.NetCore_. \* Tested on local machine (Intel i7 8700K) with MQTTnet client and server running in the same process using the TCP channel. The app for verification is part of this repository and stored in _/Tests/MQTTnet.TestApp.NetCore_.


+ 0
- 51
Source/MQTTnet.AspnetCore/TopicFilterBuilder.cs View File

@@ -1,51 +0,0 @@
using MQTTnet.Exceptions;
using MQTTnet.Protocol;

namespace MQTTnet
{
public class TopicFilterBuilder
{
private MqttQualityOfServiceLevel _qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce;
private string _topic;

public TopicFilterBuilder WithTopic(string topic)
{
_topic = topic;
return this;
}

public TopicFilterBuilder WithQualityOfServiceLevel(MqttQualityOfServiceLevel qualityOfServiceLevel)
{
_qualityOfServiceLevel = qualityOfServiceLevel;
return this;
}

public TopicFilterBuilder WithAtLeastOnceQoS()
{
_qualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce;
return this;
}

public TopicFilterBuilder WithAtMostOnceQoS()
{
_qualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce;
return this;
}

public TopicFilterBuilder WithExactlyOnceQoS()
{
_qualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce;
return this;
}

public TopicFilter Build()
{
if (string.IsNullOrEmpty(_topic))
{
throw new MqttProtocolViolationException("Topic is not set.");
}

return new TopicFilter { Topic = _topic, QualityOfServiceLevel = _qualityOfServiceLevel };
}
}
}

+ 10
- 2
Source/MQTTnet.Server/Logging/MqttNetLoggerWrapper.cs View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Threading;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using MQTTnet.Diagnostics; using MQTTnet.Diagnostics;


@@ -14,7 +15,7 @@ namespace MQTTnet.Server.Logging
} }


public event EventHandler<MqttNetLogMessagePublishedEventArgs> LogMessagePublished; public event EventHandler<MqttNetLogMessagePublishedEventArgs> LogMessagePublished;
public IMqttNetChildLogger CreateChildLogger(string source = null) public IMqttNetChildLogger CreateChildLogger(string source = null)
{ {
return new MqttNetChildLoggerWrapper(source, this); return new MqttNetChildLoggerWrapper(source, this);
@@ -24,8 +25,15 @@ namespace MQTTnet.Server.Logging
{ {
var convertedLogLevel = ConvertLogLevel(logLevel); var convertedLogLevel = ConvertLogLevel(logLevel);
_logger.Log(convertedLogLevel, exception, message, parameters); _logger.Log(convertedLogLevel, exception, message, parameters);
}


var logMessagePublishedEvent = LogMessagePublished;
if (logMessagePublishedEvent != null)
{
var logMessage = new MqttNetLogMessage(null, DateTime.UtcNow, Thread.CurrentThread.ManagedThreadId, source, logLevel, message, exception);
logMessagePublishedEvent.Invoke(this, new MqttNetLogMessagePublishedEventArgs(logMessage));
}
}
private static LogLevel ConvertLogLevel(MqttNetLogLevel logLevel) private static LogLevel ConvertLogLevel(MqttNetLogLevel logLevel)
{ {
switch (logLevel) switch (logLevel)


Loading…
Cancel
Save