Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,22 @@
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.0" />

<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.15.0" />
<PackageVersion Include="Microsoft.Identity.Web" Version="4.1.1" />
<PackageVersion Include="Microsoft.Identity.Web.DownstreamApi" Version="4.1.0" />
<PackageVersion Include="Microsoft.Identity.Web" Version="4.0.0" />
<PackageVersion Include="Microsoft.Identity.Web.DownstreamApi" Version="4.0.0" />

<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />

<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="AutoMapper" Version="14.0.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="8.1.4" />

<PackageVersion Include="Castle.Windsor" Version="6.0.0" />

<!-- Dependencies for drivers and adapters -->
<PackageVersion Include="System.IO.Ports" Version="10.0.0" />
<PackageVersion Include="MQTTnet" Version="4.3.1.873" />
<PackageVersion Include="MQTTnet" Version="5.0.1.1416" />
<PackageVersion Include="OPCFoundation.NetStandard.Opc.Ua.Client" Version="1.5.376.213" />

<PackageVersion Include="InfluxDB.LineProtocol" Version="1.1.1" />
<PackageVersion Include="InfluxDB.LineProtocol" Version="1.1.0" />
<PackageVersion Include="InfluxDB.Client" Version="4.18.0" />
<PackageVersion Include="CsvHelper" Version="33.1.0" />

Expand Down
14 changes: 7 additions & 7 deletions MORYX-Framework.sln
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Drivers", "Drivers", "{93C9
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moryx.Drivers.Mqtt", "src\Moryx.Drivers.Mqtt\Moryx.Drivers.Mqtt.csproj", "{7EDCD56F-EF56-40DF-A25F-5896990D2407}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moryx.Resources.Mqtt.Tests", "src\Tests\Moryx.Recources.Mqtt.Tests\Moryx.Resources.Mqtt.Tests.csproj", "{4C32122A-90B9-4E49-AE3E-985FA5D4AC54}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moryx.Drivers.OpcUa", "src\Moryx.Drivers.OpcUa\Moryx.Drivers.OpcUa.csproj", "{BD3B74DF-9EC2-4A5A-BCFE-1707C83756CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moryx.Drivers.OpcUa.Tests", "src\Tests\Moryx.Drivers.OpcUa.Tests\Moryx.Drivers.OpcUa.Tests.csproj", "{CB5BC342-4952-4419-ABB9-0D240684A3DE}"
Expand Down Expand Up @@ -308,6 +306,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moryx.Shifts.Management.Int
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moryx.Model.SqlServer", "src\Moryx.Model.SqlServer\Moryx.Model.SqlServer.csproj", "{4402EF2E-CBA8-4EEF-B8A6-EC8364960306}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Moryx.Drivers.Mqtt.Tests", "src\Tests\Moryx.Drivers.Mqtt.Tests\Moryx.Drivers.Mqtt.Tests.csproj", "{B2F922C0-F7C3-4C70-9BC5-5B5743BD8D7F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -646,10 +646,6 @@ Global
{7EDCD56F-EF56-40DF-A25F-5896990D2407}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7EDCD56F-EF56-40DF-A25F-5896990D2407}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7EDCD56F-EF56-40DF-A25F-5896990D2407}.Release|Any CPU.Build.0 = Release|Any CPU
{4C32122A-90B9-4E49-AE3E-985FA5D4AC54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C32122A-90B9-4E49-AE3E-985FA5D4AC54}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C32122A-90B9-4E49-AE3E-985FA5D4AC54}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C32122A-90B9-4E49-AE3E-985FA5D4AC54}.Release|Any CPU.Build.0 = Release|Any CPU
{BD3B74DF-9EC2-4A5A-BCFE-1707C83756CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD3B74DF-9EC2-4A5A-BCFE-1707C83756CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD3B74DF-9EC2-4A5A-BCFE-1707C83756CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -810,6 +806,10 @@ Global
{4402EF2E-CBA8-4EEF-B8A6-EC8364960306}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4402EF2E-CBA8-4EEF-B8A6-EC8364960306}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4402EF2E-CBA8-4EEF-B8A6-EC8364960306}.Release|Any CPU.Build.0 = Release|Any CPU
{B2F922C0-F7C3-4C70-9BC5-5B5743BD8D7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B2F922C0-F7C3-4C70-9BC5-5B5743BD8D7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2F922C0-F7C3-4C70-9BC5-5B5743BD8D7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2F922C0-F7C3-4C70-9BC5-5B5743BD8D7F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -893,7 +893,6 @@ Global
{39EDE0BB-F7D8-4E2E-9D1B-36A7A245FA05} = {8BBF84BB-4A8B-49F4-BA74-F25CBEED3F57}
{D473D554-26F3-47EC-AE7D-A9754556C9D9} = {8BBF84BB-4A8B-49F4-BA74-F25CBEED3F57}
{7EDCD56F-EF56-40DF-A25F-5896990D2407} = {93C94C82-873F-4D31-8A9C-0227047BD5A8}
{4C32122A-90B9-4E49-AE3E-985FA5D4AC54} = {0A466330-6ED6-4861-9C94-31B1949CDDB9}
{BD3B74DF-9EC2-4A5A-BCFE-1707C83756CC} = {93C94C82-873F-4D31-8A9C-0227047BD5A8}
{CB5BC342-4952-4419-ABB9-0D240684A3DE} = {0A466330-6ED6-4861-9C94-31B1949CDDB9}
{58CD8D72-1000-479A-B82A-D8C018345239} = {73AFB51B-B1A2-4144-AB4C-9CDE80CBCFBC}
Expand Down Expand Up @@ -934,6 +933,7 @@ Global
{22358E04-0AE4-4ADA-9018-56C881E313F1} = {8DF13E64-63FC-44A9-A54C-ADEFC356CDE8}
{5E02B439-B91F-4297-9AE4-7B92F2AA2AFF} = {8517D209-5BC1-47BD-A7C7-9CF9ADD9F5B6}
{4402EF2E-CBA8-4EEF-B8A6-EC8364960306} = {74112169-6672-4907-A187-F055111940A9}
{B2F922C0-F7C3-4C70-9BC5-5B5743BD8D7F} = {0A466330-6ED6-4861-9C94-31B1949CDDB9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {36EFC961-F4E7-49DC-A36A-99594FFB8243}
Expand Down
11 changes: 7 additions & 4 deletions src/Moryx.Drivers.Mqtt/MqttDriver.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) 2025, Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System.Buffers;
using System.Runtime.Serialization;
using Moryx.AbstractionLayer.Drivers;
using MQTTnet;
using MQTTnet.Client;
using System.ComponentModel;
using System.Text.RegularExpressions;
using Moryx.AbstractionLayer.Drivers.Message;
Expand Down Expand Up @@ -146,7 +146,7 @@ protected override void OnInitialize()
{
base.OnInitialize();

var factory = new MqttFactory();
var factory = new MqttClientFactory();
_mqttClient = factory.CreateMqttClient();

_mqttClient.ApplicationMessageReceivedAsync += OnReceived;
Expand Down Expand Up @@ -339,14 +339,17 @@ public async Task OnSend(MqttMessageTopic messageTopic, byte[] message, Cancella
private Task OnReceived(MqttApplicationMessageReceivedEventArgs args)
{
// Experimental: Dispatch to new thread to prevent exceptions or deadlocks from causing inflight blockage
ParallelOperations.ExecuteParallel(param => Receive(param.Topic, param.Payload), new { args.ApplicationMessage.Topic, args.ApplicationMessage.Payload });
ParallelOperations.ExecuteParallel(param => Receive(param.Topic, param.Payload), new
{
args.ApplicationMessage.Topic,
Payload = args.ApplicationMessage.Payload.ToArray()
});

return Task.CompletedTask;
}

internal void Receive(string topicName, byte[] message)
{

var topic = topicName;
if (Identifier != "")
{
Expand Down
2 changes: 1 addition & 1 deletion src/Moryx.Drivers.Mqtt/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Moryx.Resources.Mqtt.Tests")]
[assembly: InternalsVisibleTo("Moryx.Drivers.Mqtt.Tests")]
2 changes: 1 addition & 1 deletion src/Moryx.Drivers.OpcUa/OpcUaDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ internal List<NodeIdAlias> NodeIdAlias

//TODO: Internal property just for tests, use xml also in tests
internal ApplicationConfigurationFactory ApplicationConfigurationFactory { get; set; } = new();

/// <summary>
/// Convert an OpcUaNode to an entity to be shown on the UI
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion src/Moryx.Model.Sqlite/Moryx.Model.Sqlite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Moryx.Runtime.Kernel\Moryx.Runtime.Kernel.csproj" />
<ProjectReference Include="..\Moryx\Moryx.csproj" />
<ProjectReference Include="..\Moryx.Model\Moryx.Model.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<ProjectReference Include="..\Moryx.Model.PostgreSQL\Moryx.Model.PostgreSQL.csproj"/>
<ProjectReference Include="..\Moryx.Model.Sqlite\Moryx.Model.Sqlite.csproj"/>
<ProjectReference Include="..\Moryx.Operators\Moryx.Operators.csproj"/>
<ProjectReference Include="..\Moryx.Runtime.Kernel\Moryx.Runtime.Kernel.csproj" />
<ProjectReference Include="..\Moryx.Users\Moryx.Users.csproj"/>
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions src/Moryx.Shifts.Management/Moryx.Shifts.Management.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ItemGroup>
<ProjectReference Include="..\Moryx.Model.PostgreSQL\Moryx.Model.PostgreSQL.csproj" />
<ProjectReference Include="..\Moryx.Model.Sqlite\Moryx.Model.Sqlite.csproj" />
<ProjectReference Include="..\Moryx.Runtime.Kernel\Moryx.Runtime.Kernel.csproj" />
<ProjectReference Include="..\Moryx.Shifts\Moryx.Shifts.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net10.0</TargetFramework>
<DebugType>full</DebugType>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Moq" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="coverlet.collector" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Moryx\Moryx.csproj" />
<ProjectReference Include="..\..\Moryx.AbstractionLayer.TestTools\Moryx.AbstractionLayer.TestTools.csproj" />
<ProjectReference Include="..\..\Moryx.Drivers.Mqtt\Moryx.Drivers.Mqtt.csproj" />
<ProjectReference Include="..\..\Moryx.TestTools.UnitTest\Moryx.TestTools.UnitTest.csproj" />
</ItemGroup>
</Project>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@
using Moq;
using Moryx.AbstractionLayer.Products;
using Moryx.AbstractionLayer.TestTools;
using Moryx.Drivers.Mqtt;
using Moryx.Drivers.Mqtt.MqttTopics;
using Moryx.Drivers.Mqtt.Tests.TestMessages;
using Moryx.Logging;
using Moryx.Modules;
using Moryx.Resources.Mqtt.Tests.TestMessages;
using Moryx.TestTools.UnitTest;
using Moryx.Tools;
using MQTTnet;
using MQTTnet.Client;
using MQTTnet.Formatter;
using MQTTnet.Packets;
using MQTTnet.Protocol;
using Newtonsoft.Json;
using NUnit.Framework;

namespace Moryx.Resources.Mqtt.Tests
namespace Moryx.Drivers.Mqtt.Tests
{
[TestFixture(MqttProtocolVersion.V310)]
[TestFixture(MqttProtocolVersion.V311)]
Expand All @@ -50,7 +48,7 @@ public void Setup()
_driver = CreateMqttDriver();
_mockClient = SetupMqttClientMock();

//Initialize MqttDriver
//Initialize MqttDriver
_driver.InitializeForTest(_mockClient.Object);
((IPlugin)_driver).Start();
_driver.OnConnected(new MqttClientConnectedEventArgs(new MqttClientConnectResult())).Wait();
Expand Down Expand Up @@ -88,7 +86,8 @@ private MqttDriver CreateMqttDriver()
Id = 4,
Logger = new ModuleLogger("Dummy", new NullLoggerFactory()),
Channels = new ReferenceCollectionMock<MqttTopic>(),
MqttVersion = _version
MqttVersion = _version,
BrokerUrl = "mock"
};
}

Expand Down Expand Up @@ -122,7 +121,7 @@ public void Channel_FindChannel_TChannel()
Assert.That(c.Identifier.Equals(_topicBoolMqtt.Identifier));
}


[Test(Description = "Return null, if identifier does not exist")]
public void Channel_NotFindChannel_IdentifierDoesNotExist()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@
// Licensed under the Apache License, Version 2.0

using System;
using System.Buffers;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Moryx.AbstractionLayer.TestTools;
using Moryx.Drivers.Mqtt;
using Moryx.Drivers.Mqtt.MqttTopics;
using Moryx.Drivers.Mqtt.Tests.TestMessages;
using Moryx.Logging;
using Moryx.Modules;
using Moryx.Resources.Mqtt.Tests.TestMessages;
using Moryx.Tools;
using MQTTnet;
using MQTTnet.Client;
using MQTTnet.Formatter;
using MQTTnet.Packets;
using MQTTnet.Protocol;
using NUnit.Framework;

namespace Moryx.Resources.Mqtt.Tests
namespace Moryx.Drivers.Mqtt.Tests
{
[TestFixture(MqttProtocolVersion.V310)]
[TestFixture(MqttProtocolVersion.V311)]
Expand Down Expand Up @@ -64,7 +62,8 @@ public void Setup()
Id = 4,
Logger = new ModuleLogger("Dummy", new NullLoggerFactory()),
Channels = new ReferenceCollectionMock<MqttTopic> { _topicBoolMqtt, _topicBoolIByteSerializable },
MqttVersion = _version
MqttVersion = _version,
BrokerUrl = "mock"
};

_mockClient = new Mock<IMqttClient>();
Expand All @@ -84,8 +83,7 @@ public void Setup()
private Expression<Func<MqttClientOptions, bool>> CorrectClientOptions()
{
return o => o.ProtocolVersion == _driver.MqttVersion && o.CleanSession == !_driver.ReconnectWithoutCleanSession
&& o.ClientId == $"{System.Net.Dns.GetHostName()}-{_driver.Id}-{_driver.Name}" && (o.ChannelOptions as MqttClientTcpOptions).Server == _driver.BrokerUrl &&
(o.ChannelOptions as MqttClientTcpOptions).Port == _driver.Port;
&& o.ClientId == $"{System.Net.Dns.GetHostName()}-{_driver.Id}-{_driver.Name}";
}

[Test(Description = "Publish Message using Driver")]
Expand Down Expand Up @@ -129,7 +127,7 @@ private void SendMessageBoolMqttMessage(MqttApplicationMessage mqttMsg, Cancella
Assert.That(mqttMsg.QualityOfServiceLevel, Is.EqualTo(MqttQualityOfServiceLevel.ExactlyOnce),
"Qos should be ExactlyOnce, but is " + mqttMsg.QualityOfServiceLevel);
var msg = new BoolMqttMessage();
msg.FromBytes(mqttMsg.Payload);
msg.FromBytes(mqttMsg.Payload.ToArray());
Assert.That(msg.Message == MESSAGE_VALUE, "Message should be " + MESSAGE_VALUE + ", but is " + msg.Message);
}

Expand Down Expand Up @@ -160,7 +158,7 @@ private void SendMessageBoolIByteSerializableMessage(MqttApplicationMessage sent
Assert.That(sentMsg.QualityOfServiceLevel, Is.EqualTo(MqttQualityOfServiceLevel.ExactlyOnce),
"Qos should be ExactlyOnce, but is " + sentMsg.QualityOfServiceLevel);
var msg = new BoolByteSerializableMessage();
msg.FromBytes(sentMsg.Payload);
msg.FromBytes(sentMsg.Payload.ToArray());
Assert.That(msg.Message == MESSAGE_VALUE, "Message should be " + MESSAGE_VALUE + ", but is " + msg.Message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@
// Licensed under the Apache License, Version 2.0

using System;
using System.Buffers;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Moryx.AbstractionLayer.TestTools;
using Moryx.Drivers.Mqtt;
using Moryx.Drivers.Mqtt.MqttTopics;
using Moryx.Logging;
using Moryx.Modules;
using Moryx.Tools;
using MQTTnet;
using MQTTnet.Client;
using MQTTnet.Formatter;
using MQTTnet.Packets;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using NUnit.Framework;

namespace Moryx.Resources.Mqtt.Tests
namespace Moryx.Drivers.Mqtt.Tests
{
[TestFixture(MqttProtocolVersion.V310)]
[TestFixture(MqttProtocolVersion.V311)]
Expand Down Expand Up @@ -65,7 +64,8 @@ public void Setup()
Id = 4,
Logger = new ModuleLogger("Dummy", new NullLoggerFactory()),
Channels = new ReferenceCollectionMock<MqttTopic> { _mqttTopicCamel, _mqttTopicPascal },
MqttVersion = _version
MqttVersion = _version,
BrokerUrl = "mock"
};

_mockClient = new Mock<IMqttClient>();
Expand All @@ -84,8 +84,7 @@ public void Setup()
private Expression<Func<MqttClientOptions, bool>> CorrectClientOptions()
{
return o => o.ProtocolVersion == _driver.MqttVersion && o.CleanSession == !_driver.ReconnectWithoutCleanSession
&& o.ClientId == $"{System.Net.Dns.GetHostName()}-{_driver.Id}-{_driver.Name}" && (o.ChannelOptions as MqttClientTcpOptions).Server == _driver.BrokerUrl &&
(o.ChannelOptions as MqttClientTcpOptions).Port == _driver.Port;
&& o.ClientId == $"{System.Net.Dns.GetHostName()}-{_driver.Id}-{_driver.Name}";
}

[Test(Description = "Publish Json Message using the MqttTopicJson")]
Expand All @@ -109,7 +108,8 @@ public void Send_UsingMqttTopicJson_Topic_QOS_Message()
private void CheckSentMessage(MqttApplicationMessage sentMsg, CancellationToken token)
{
var msg = new JsonMessageTest();
var payload = Encoding.UTF8.GetString(sentMsg.Payload, 0, sentMsg.Payload.Length);
var payloadArray = sentMsg.Payload.ToArray();
var payload = Encoding.UTF8.GetString(payloadArray, 0, payloadArray.Length);
if (sentMsg.Topic == _driver.Identifier + _mqttTopicCamel.Identifier)
{
Assert.That(payload.Contains(nameof(JsonMessageTest.Age).ToLower()));
Expand Down
Loading
Loading