Skip to content

Commit

Permalink
Update v0.2.0
Browse files Browse the repository at this point in the history
- Added Example projects
- Updated to support "/" base path for pattern matching
  • Loading branch information
PatrickRitchie committed Feb 23, 2024
1 parent 7f84036 commit 8d48cd5
Show file tree
Hide file tree
Showing 33 changed files with 801 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# Nuget
```
dotnet add package Uns.NET --version 0.1.0-beta
dotnet add package Uns.NET
```

# UnsClient
Expand Down
4 changes: 2 additions & 2 deletions build/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Reflection;

[assembly: AssemblyVersion("0.1.1")]
[assembly: AssemblyFileVersion("0.1.1")]
[assembly: AssemblyVersion("0.2.0")]
[assembly: AssemblyFileVersion("0.2.0")]
[assembly: AssemblyCompany("TrakHound Inc.")]
[assembly: AssemblyCopyright("Copyright (c) 2024 TrakHound Inc., All Rights Reserved.")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Example_Middleware_DeadbandPeriodFilter</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Uns.NET\Uns.NET.csproj" />
</ItemGroup>

</Project>
38 changes: 38 additions & 0 deletions examples/Example-Middleware-DeadbandPeriodFilter/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Uns;


// Declare a new UnsClient
var client = new UnsClient();


// Add Period Deadband Filter Middleware for 10 seconds
client.AddMiddleware(new UnsDeadbandPeriodMiddleware(TimeSpan.FromSeconds(10)));


// Add MQTT (Plain) Connection
var mqttConnection = new UnsMqttConnection("localhost", 1883);
mqttConnection.AddSubscription("#");
client.AddConnection(mqttConnection);


// Subscribe to any Path
var consumer = client.Subscribe("#");
consumer.Received += (c, o) =>
{
Console.WriteLine("-------------------------");
Console.WriteLine($"Path = {o.Path}");
Console.WriteLine($"Connection.Id = {o.Connection?.Id}");
Console.WriteLine($"Connection.Type = {o.Connection?.Type}");
Console.WriteLine($"ContentType = {o.ContentType}");
Console.WriteLine($"Content = {System.Text.Encoding.UTF8.GetString(o.Content)}");
Console.WriteLine($"Timestamp = {o.Timestamp.ToString("o")}");
};

// Start Client
await client.Start();

Console.WriteLine("Press a key to stop..");
Console.ReadLine();

// Stop Client
await client.Stop();
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Example_Middleware_DeadbandValueFilter</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Uns.NET\Uns.NET.csproj" />
</ItemGroup>

</Project>
38 changes: 38 additions & 0 deletions examples/Example-Middleware-DeadbandValueFilter/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Uns;


// Declare a new UnsClient
var client = new UnsClient();


// Add Period Deadband Filter Middleware for 10 seconds
client.AddMiddleware(new UnsDeadbandValueMiddleware(5));


// Add MQTT (Plain) Connection
var mqttConnection = new UnsMqttConnection("localhost", 1883);
mqttConnection.AddSubscription("#");
client.AddConnection(mqttConnection);


// Subscribe to any Path
var consumer = client.Subscribe("#");
consumer.Received += (c, o) =>
{
Console.WriteLine("-------------------------");
Console.WriteLine($"Path = {o.Path}");
Console.WriteLine($"Connection.Id = {o.Connection?.Id}");
Console.WriteLine($"Connection.Type = {o.Connection?.Type}");
Console.WriteLine($"ContentType = {o.ContentType}");
Console.WriteLine($"Content = {System.Text.Encoding.UTF8.GetString(o.Content)}");
Console.WriteLine($"Timestamp = {o.Timestamp.ToString("o")}");
};

// Start Client
await client.Start();

Console.WriteLine("Press a key to stop..");
Console.ReadLine();

// Stop Client
await client.Stop();
15 changes: 15 additions & 0 deletions examples/Example-Middleware-RBE/Example-Middleware-RBE.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Example_RBE</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Uns.NET\Uns.NET.csproj" />
</ItemGroup>

</Project>
38 changes: 38 additions & 0 deletions examples/Example-Middleware-RBE/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Uns;


// Declare a new UnsClient
var client = new UnsClient();


// Add RBE Middleware
client.AddMiddleware(new UnsReportByExceptionMiddleware());


// Add MQTT (Plain) Connection
var mqttConnection = new UnsMqttConnection("localhost", 1883);
mqttConnection.AddSubscription("#");
client.AddConnection(mqttConnection);


// Subscribe to any Path
var consumer = client.Subscribe("#");
consumer.Received += (c, o) =>
{
Console.WriteLine("-------------------------");
Console.WriteLine($"Path = {o.Path}");
Console.WriteLine($"Connection.Id = {o.Connection?.Id}");
Console.WriteLine($"Connection.Type = {o.Connection?.Type}");
Console.WriteLine($"ContentType = {o.ContentType}");
Console.WriteLine($"Content = {System.Text.Encoding.UTF8.GetString(o.Content)}");
Console.WriteLine($"Timestamp = {o.Timestamp.ToString("o")}");
};

// Start Client
await client.Start();

Console.WriteLine("Press a key to stop..");
Console.ReadLine();

// Stop Client
await client.Stop();
15 changes: 15 additions & 0 deletions examples/Example-Mqtt-Publish/Example-Mqtt-Publish.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Example_Mqtt_Publish</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Uns.NET\Uns.NET.csproj" />
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions examples/Example-Mqtt-Publish/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Uns;


// Declare a new UnsClient
var client = new UnsClient();


// Add MQTT (Plain) Connection
var mqttConnection = new UnsMqttConnection("localhost", 1883);
mqttConnection.AddDestination();
client.AddConnection(mqttConnection);


// Start Client
await client.Start();

while (true)
{
Console.WriteLine("Enter Event Path (ex. Site/Cell/PLC/Temperature)..");
var eventPath = Console.ReadLine();

Console.WriteLine("Enter Event Content (ex. 45.2)..");
var eventContent = Console.ReadLine();

await client.Publish(eventPath, eventContent);
}
15 changes: 15 additions & 0 deletions examples/Example-Mqtt-Subscribe/Example-Mqtt-Subscribe.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Example_Plain_Mqtt</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Uns.NET\Uns.NET.csproj" />
</ItemGroup>

</Project>
34 changes: 34 additions & 0 deletions examples/Example-Mqtt-Subscribe/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Uns;


// Declare a new UnsClient
var client = new UnsClient();


// Add MQTT (Plain) Connection
var mqttConnection = new UnsMqttConnection("localhost", 1883);
mqttConnection.AddSubscription("Site/#");
client.AddConnection(mqttConnection);


// Subscribe to any Path
var consumer = client.Subscribe("#");
consumer.Received += (c, o) =>
{
Console.WriteLine("-------------------------");
Console.WriteLine($"Path = {o.Path}");
Console.WriteLine($"Connection.Id = {o.Connection?.Id}");
Console.WriteLine($"Connection.Type = {o.Connection?.Type}");
Console.WriteLine($"ContentType = {o.ContentType}");
Console.WriteLine($"Content = {System.Text.Encoding.UTF8.GetString(o.Content)}");
Console.WriteLine($"Timestamp = {o.Timestamp.ToString("o")}");
};

// Start Client
await client.Start();

Console.WriteLine("Press a key to stop..");
Console.ReadLine();

// Stop Client
await client.Stop();
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Example_Multiple_Connections</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Uns.NET\Uns.NET.csproj" />
</ItemGroup>

</Project>
32 changes: 32 additions & 0 deletions examples/Example-Multiple-Connections-Publish/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Uns;


// Declare a new UnsClient
var client = new UnsClient();


// Add MQTT (Plain) Connection
var mqttConnection = new UnsMqttConnection("localhost", 1883);
mqttConnection.AddDestination("Site/ERP");
mqttConnection.AddDestination("Site/Cell/MES");
client.AddConnection(mqttConnection);


// Add Sparkplug Connection
var spBConnection = new UnsSparkplugConnection("localhost", 1883, "test-publish");
spBConnection.AddDevice("Site/Cell/PLC");
client.AddConnection(spBConnection);


await client.Start();

while (true)
{
Console.WriteLine("Enter Event Path (ex. Site/Cell/PLC/Temperature)..");
var eventPath = Console.ReadLine();

Console.WriteLine("Enter Event Content (ex. 45.2)..");
var eventContent = Console.ReadLine();

await client.Publish(eventPath, eventContent);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Example_Multiple_Connections_Subscribe</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Uns.NET\Uns.NET.csproj" />
</ItemGroup>

</Project>
41 changes: 41 additions & 0 deletions examples/Example-Multiple-Connections-Subscribe/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Uns;


// Declare a new UnsClient
var client = new UnsClient();


// Add MQTT (Plain) Connection
var mqttConnection = new UnsMqttConnection("localhost", 1883);
mqttConnection.AddSubscription("Site/ERP/#");
mqttConnection.AddSubscription("Site/Cell/MES/#");
client.AddConnection(mqttConnection);


// Add Sparkplug Connection
var spBConnection = new UnsSparkplugConnection("localhost", 1883, "test-subscribe");
spBConnection.AddApplication("Site/Cell/PLC");
client.AddConnection(spBConnection);


// Subscribe to any Path
var consumer = client.Subscribe("#");
consumer.Received += (c, o) =>
{
Console.WriteLine("-------------------------");
Console.WriteLine($"Path = {o.Path}");
Console.WriteLine($"Connection.Id = {o.Connection?.Id}");
Console.WriteLine($"Connection.Type = {o.Connection?.Type}");
Console.WriteLine($"ContentType = {o.ContentType}");
Console.WriteLine($"Content = {System.Text.Encoding.UTF8.GetString(o.Content)}");
Console.WriteLine($"Timestamp = {o.Timestamp.ToString("o")}");
};

// Start Client
await client.Start();

Console.WriteLine("Press a key to stop..");
Console.ReadLine();

// Stop Client
await client.Stop();
Loading

0 comments on commit 8d48cd5

Please sign in to comment.