-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
313 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
Source/MQTTnet.Extensions.Rpc/Options/IMqttRpcClientOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using MQTTnet.Extensions.Rpc.Options.TopicGeneration; | ||
|
||
namespace MQTTnet.Extensions.Rpc.Options | ||
{ | ||
public interface IMqttRpcClientOptions | ||
{ | ||
IMqttRpcClientTopicGenerationStrategy TopicGenerationStrategy { get; set; } | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Source/MQTTnet.Extensions.Rpc/Options/MqttRpcClientOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using MQTTnet.Extensions.Rpc.Options.TopicGeneration; | ||
|
||
namespace MQTTnet.Extensions.Rpc.Options | ||
{ | ||
public class MqttRpcClientOptions : IMqttRpcClientOptions | ||
{ | ||
public IMqttRpcClientTopicGenerationStrategy TopicGenerationStrategy { get; set; } = new DefaultMqttRpcClientTopicGenerationStrategy(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Source/MQTTnet.Extensions.Rpc/Options/MqttRpcClientOptionsBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using MQTTnet.Extensions.Rpc.Options.TopicGeneration; | ||
using System; | ||
|
||
namespace MQTTnet.Extensions.Rpc.Options | ||
{ | ||
public class MqttRpcClientOptionsBuilder | ||
{ | ||
IMqttRpcClientTopicGenerationStrategy _topicGenerationStrategy = new DefaultMqttRpcClientTopicGenerationStrategy(); | ||
|
||
public MqttRpcClientOptionsBuilder WithTopicGenerationStrategy(IMqttRpcClientTopicGenerationStrategy value) | ||
{ | ||
_topicGenerationStrategy = value ?? throw new ArgumentNullException(nameof(value)); | ||
|
||
return this; | ||
} | ||
|
||
public IMqttRpcClientOptions Build() | ||
{ | ||
return new MqttRpcClientOptions | ||
{ | ||
TopicGenerationStrategy = _topicGenerationStrategy | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace MQTTnet.Extensions.Rpc.Options | ||
{ | ||
public class MqttRpcTopicPair | ||
{ | ||
public string RequestTopic { get; set; } | ||
|
||
public string ResponseTopic { get; set; } | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...net.Extensions.Rpc/Options/TopicGeneration/DefaultMqttRpcClientTopicGenerationStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using MQTTnet.Extensions.Rpc.Options.TopicGeneration; | ||
using System; | ||
|
||
namespace MQTTnet.Extensions.Rpc.Options | ||
{ | ||
public class DefaultMqttRpcClientTopicGenerationStrategy : IMqttRpcClientTopicGenerationStrategy | ||
{ | ||
public MqttRpcTopicPair CreateRpcTopics(TopicGenerationContext context) | ||
{ | ||
var requestTopic = $"MQTTnet.RPC/{Guid.NewGuid():N}/{context.MethodName}"; | ||
var responseTopic = requestTopic + "/response"; | ||
|
||
return new MqttRpcTopicPair | ||
{ | ||
RequestTopic = requestTopic, | ||
ResponseTopic = responseTopic | ||
}; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...e/MQTTnet.Extensions.Rpc/Options/TopicGeneration/IMqttRpcClientTopicGenerationStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace MQTTnet.Extensions.Rpc.Options.TopicGeneration | ||
{ | ||
public interface IMqttRpcClientTopicGenerationStrategy | ||
{ | ||
MqttRpcTopicPair CreateRpcTopics(TopicGenerationContext context); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Source/MQTTnet.Extensions.Rpc/Options/TopicGeneration/TopicGenerationContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using MQTTnet.Client; | ||
using MQTTnet.Protocol; | ||
|
||
namespace MQTTnet.Extensions.Rpc.Options.TopicGeneration | ||
{ | ||
public class TopicGenerationContext | ||
{ | ||
public string MethodName { get; set; } | ||
|
||
public MqttQualityOfServiceLevel QualityOfServiceLevel { get; set; } | ||
|
||
public IMqttClient MqttClient { get; set; } | ||
|
||
public IMqttRpcClientOptions Options { get; set; } | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Source/MQTTnet.Server/Configuration/CertificateSettingsModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.IO; | ||
|
||
namespace MQTTnet.Server.Configuration | ||
{ | ||
public class CertificateSettingsModel | ||
{ | ||
/// <summary> | ||
/// Path to certificate. | ||
/// </summary> | ||
public string Path { get; set; } | ||
|
||
/// <summary> | ||
/// Password of certificate. | ||
/// </summary> | ||
public string Password { get; set; } | ||
|
||
/// <summary> | ||
/// Read certificate file. | ||
/// </summary> | ||
public byte[] ReadCertificate() | ||
{ | ||
if (string.IsNullOrEmpty(Path) || string.IsNullOrWhiteSpace(Path)) | ||
{ | ||
throw new FileNotFoundException("No path set"); | ||
} | ||
|
||
if (!File.Exists(Path)) | ||
{ | ||
throw new FileNotFoundException($"Could not find Certificate in path: {Path}"); | ||
} | ||
|
||
return File.ReadAllBytes(Path); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.