mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-17 09:43:05 +08:00
Add new PowerShell project
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Management.Automation;
|
||||
|
||||
namespace MQTTnet.PowerShell.Cmdlets;
|
||||
|
||||
[Cmdlet("Subscribe", "MqttTopic")]
|
||||
[OutputType(typeof(MqttClientSubscribeResult))]
|
||||
public class SubscribeMqttTopicCmdlet : PSCmdlet
|
||||
{
|
||||
[Parameter]
|
||||
public int QoS { get; set; } = 0;
|
||||
|
||||
[Parameter(Mandatory = true, ValueFromPipeline = true)]
|
||||
public required MqttSession Session { get; set; }
|
||||
|
||||
[Parameter(Mandatory = true)]
|
||||
public required string Topic { get; set; }
|
||||
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
var topicFilter = new MqttTopicFilterBuilder().WithTopic(Topic).Build();
|
||||
|
||||
var response = Session.Client.SubscribeAsync(topicFilter).GetAwaiter().GetResult();
|
||||
|
||||
WriteObject(response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user