3using Dreamine.Communication.Abstractions.Enums;
4using Dreamine.Communication.Abstractions.Interfaces;
5using Dreamine.Communication.Abstractions.Models;
6using Dreamine.Communication.Abstractions.Options;
7using Dreamine.Communication.Core.Framing;
8using Dreamine.Communication.Core.Protocols;
9using Dreamine.Communication.Core.Resilience;
10using Dreamine.Communication.RabbitMQ.Buses;
11using Dreamine.Communication.RabbitMQ.Options;
12using Dreamine.Communication.Serial.Options;
13using Dreamine.Communication.Serial.Ports;
14using Dreamine.Communication.Sockets.Clients;
15using Dreamine.Communication.Sockets.Enums;
16using Dreamine.Communication.Sockets.Options;
17using Dreamine.Communication.Sockets.Servers;
18using Dreamine.Communication.Sockets.Udp;
19using Dreamine.Communication.Wpf.ViewModels;
474 _messageBus = messageBus ??
throw new ArgumentNullException(nameof(messageBus));
475 Monitor =
new CommunicationMonitorViewModel();
488 public CommunicationMonitorViewModel
Monitor {
get; }
547 PlainTextProtocolOptions.Utf8EncodingName,
548 PlainTextProtocolOptions.KoreanCodePage949EncodingName
561 nameof(TcpServerSendTargetMode.Broadcast),
562 nameof(TcpServerSendTargetMode.FirstClient),
563 nameof(TcpServerSendTargetMode.LastClient)
593 TransportKind.InMemory,
594 "SampleSmart in-memory communication channel.");
621 ConnectionState.Connected);
648 ConnectionState.Disconnected);
679 if (
_messageBus.State != ConnectionState.Connected)
684 if (
string.IsNullOrWhiteSpace(text))
686 text =
"Hello from SampleSmart InMemory";
697 TransportKind.InMemory,
723 if (
string.IsNullOrWhiteSpace(text))
725 text =
"Hello from SampleSmart manual receive";
730 "sample.communication.manual-receive",
736 TransportKind.InMemory,
790 string encodingName = PlainTextProtocolOptions.Utf8EncodingName,
791 string sendTargetMode = nameof(TcpServerSendTargetMode.Broadcast),
792 bool echoEnabled =
false)
799 _tcpServer.State == ConnectionState.Listening &&
808 _rawTcpServer.SendTargetMode = targetMode;
835 new TcpServerTransportOptions
839 SendTargetMode = targetMode
873 Monitor.UpdateChannelState(channelName, ConnectionState.Connecting);
924 string encodingName = PlainTextProtocolOptions.Utf8EncodingName,
925 string sendTargetMode = nameof(TcpServerSendTargetMode.Broadcast),
926 bool echoEnabled =
false)
942 _rawTcpServer.SendTargetMode = targetMode;
976 if (
Monitor.Channels.Any(x => x.Name == channelName))
978 Monitor.UpdateChannelState(channelName, ConnectionState.Disconnected);
991 if (
Monitor.Channels.Any(x => x.Name == channelName))
993 Monitor.UpdateChannelState(channelName, ConnectionState.Disconnected);
1048 string encodingName = PlainTextProtocolOptions.Utf8EncodingName,
1049 string sendTargetMode = nameof(TcpServerSendTargetMode.Broadcast))
1058 _rawTcpServer.SendTargetMode = targetMode;
1067 if (
string.IsNullOrWhiteSpace(text))
1069 text =
"Hello from Dreamine TCP Server";
1073 _tcpServer.State != ConnectionState.Listening ||
1087 $
"Server.Send.{targetMode}",
1135 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
1141 _tcpClient.State == ConnectionState.Connected &&
1157 Monitor.UpdateChannelState(channelName, ConnectionState.Connecting);
1171 Monitor.UpdateChannelState(channelName, ConnectionState.Connecting);
1209 string encodingName)
1233 var rawTcpClient =
new TcpClientTransport(
1234 new TcpClientTransportOptions
1294 if (
Monitor.Channels.Any(x => x.Name == channelName))
1296 Monitor.UpdateChannelState(channelName, ConnectionState.Disconnected);
1308 if (
Monitor.Channels.Any(x => x.Name == channelName))
1310 Monitor.UpdateChannelState(channelName, ConnectionState.Disconnected);
1357 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
1362 if (
string.IsNullOrWhiteSpace(text))
1364 text =
"Hello from Dreamine TCP Client";
1389 if (
_tcpClient is ResilientMessageTransport resilientTransport)
1393 "Client.QueueStatus",
1394 $
"QueueCount={resilientTransport.QueuedMessageCount}, State={_tcpClient.State}",
1400 queueStatusMessage);
1464 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
1504 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
1510 _udpPeerA.State == ConnectionState.Connected &&
1528 new UdpTransportOptions
1530 LocalHost =
"127.0.0.1",
1532 RemoteHost =
"127.0.0.1",
1548 ConnectionState.Connected);
1585 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
1591 _udpPeerB.State == ConnectionState.Connected &&
1609 new UdpTransportOptions
1611 LocalHost =
"127.0.0.1",
1613 RemoteHost =
"127.0.0.1",
1629 ConnectionState.Connected);
1656 if (
Monitor.Channels.Any(x => x.Name == channelName))
1658 Monitor.UpdateChannelState(channelName, ConnectionState.Disconnected);
1670 if (
Monitor.Channels.Any(x => x.Name == channelName))
1672 Monitor.UpdateChannelState(channelName, ConnectionState.Disconnected);
1700 if (
Monitor.Channels.Any(x => x.Name == channelName))
1702 Monitor.UpdateChannelState(channelName, ConnectionState.Disconnected);
1714 if (
Monitor.Channels.Any(x => x.Name == channelName))
1716 Monitor.UpdateChannelState(channelName, ConnectionState.Disconnected);
1785 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
1790 if (
string.IsNullOrWhiteSpace(text))
1792 text =
"Hello from Dreamine UDP Peer A";
1796 _udpPeerA.State != ConnectionState.Connected ||
1867 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
1872 if (
string.IsNullOrWhiteSpace(text))
1874 text =
"Hello from Dreamine UDP Peer B";
1878 _udpPeerB.State != ConnectionState.Connected ||
1958 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
1960 if (
string.IsNullOrWhiteSpace(portName))
1991 new SerialPortTransportOptions
1993 PortName = portName,
2009 ConnectionState.Connected);
2034 if (
Monitor.Channels.Any(x => x.Name == channelName))
2036 Monitor.UpdateChannelState(channelName, ConnectionState.Disconnected);
2048 if (
Monitor.Channels.Any(x => x.Name == channelName))
2050 Monitor.UpdateChannelState(channelName, ConnectionState.Disconnected);
2097 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
2102 if (
string.IsNullOrWhiteSpace(text))
2123 TransportKind.Serial,
2215 string exchangeName,
2223 exchangeName =
NormalizeText(exchangeName,
"dreamine.sample.exchange");
2224 queueName =
NormalizeText(queueName,
"dreamine.sample.queue");
2225 routingKey =
NormalizeText(routingKey,
"dreamine.sample.route");
2227 if (port <= 0 || port > 65535)
2260 new RabbitMqMessageBusOptions
2264 VirtualHost = virtualHost,
2265 UserName = userName,
2266 Password = password,
2267 ExchangeName = exchangeName,
2268 QueueName = queueName,
2269 RoutingKey = routingKey
2278 ConnectionState.Connected);
2280 catch (Exception ex)
2284 ConnectionState.Faulted);
2331 string exchangeName,
2342 "RabbitMQ.Subscribe.Skipped",
2343 "RabbitMQ is not connected.");
2350 "RabbitMQ.Subscribe.Skipped",
2351 $
"RabbitMQ state is {_rabbitMqBus.State}.");
2374 TransportKind.RabbitMq,
2378 return Task.CompletedTask;
2383 catch (Exception ex)
2430 string exchangeName,
2437 if (
string.IsNullOrWhiteSpace(text))
2445 "RabbitMQ.Publish.Skipped",
2446 "RabbitMQ is not connected.");
2453 "RabbitMQ.Publish.Skipped",
2454 $
"RabbitMQ state is {_rabbitMqBus.State}.");
2468 TransportKind.RabbitMq,
2475 catch (Exception ex)
2505 ConnectionState.Disconnected);
2520 ConnectionState.Disconnected);
2582 TransportKind.InMemory,
2586 return Task.CompletedTask;
2629 _tcpServer.State != ConnectionState.Listening ||
2635 var receiveText = Encoding.UTF8.GetString(message.Payload);
2639 $
"Server.Echo.{_currentServerSendTargetMode}",
2640 $
"Echo from Dreamine TCP Server - {receiveText}",
2672 return new ReconnectPolicy
2675 InitialDelay = TimeSpan.FromSeconds(1),
2676 MaxDelay = TimeSpan.FromSeconds(5),
2677 BackoffFactor = 1.5,
2678 MaxRetryCount =
null,
2679 WatchInterval = TimeSpan.FromMilliseconds(500)
2701 return new OutboundQueueOptions
2703 DisconnectedSendPolicy = DisconnectedSendPolicy.Queue,
2704 MaxQueueSize = 10_000,
2705 DropOldestWhenFull =
true,
2706 MaxMessageAge =
null,
2707 FlushOnReconnect =
true
2729 return new OutboundQueueOptions
2731 DisconnectedSendPolicy = DisconnectedSendPolicy.Fail,
2732 MaxQueueSize = 1_000,
2733 DropOldestWhenFull =
true,
2734 MaxMessageAge =
null,
2735 FlushOnReconnect =
false
2764 IMessageTransport transport,
2767 if (transport is not ResilientMessageTransport resilientTransport)
2772 resilientTransport.StateChanged += (_, state) =>
2816 TcpServerTransport tcpServerTransport,
2818 string encodingName)
2820 tcpServerTransport.ConnectedClientCountChanged += (_, clientCount) =>
2884 string encodingName,
2886 TcpServerSendTargetMode targetMode,
2892 Monitor.UpdateChannelDescription(
2963 string encodingName,
2966 TcpServerSendTargetMode targetMode,
2969 var echoText = echoEnabled ?
"On" :
"Off";
2971 return $
"TCP server [{protocol}/{NormalizeTextEncodingName(encodingName)}] on 127.0.0.1:{port}. Clients={clientCount}. Target={targetMode}. Echo={echoText}.";
3015 IMessageTransport transport,
3017 string encodingName,
3020 if (transport is not ResilientMessageTransport resilientTransport)
3025 resilientTransport.QueueCountChanged += (_, queueCount) =>
3029 "Client.QueueStatus",
3030 $
"QueueCount={queueCount}, State={resilientTransport.State}",
3038 queueStatusMessage);
3042 resilientTransport.State);
3196 TransportKind.Serial,
3227 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
3232 if (
Monitor.Channels.Any(x => x.Name == channelName))
3275 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
3280 if (
Monitor.Channels.Any(x => x.Name == channelName))
3288 $
"TCP client [{protocol}/{NormalizeTextEncodingName(encodingName)}] to 127.0.0.1:{port}.");
3326 string encodingName)
3334 if (
Monitor.Channels.Any(x => x.Name == channelName))
3342 $
"UDP peer {peerName} [{protocol}/{encodingName}] 127.0.0.1:{localPort} -> 127.0.0.1:{remotePort}.");
3357 if (
Monitor.Channels.Any(x => x.Name == channelName))
3364 TransportKind.Serial,
3365 $
"Serial [{_currentSerialProtocol}/{_currentSerialEncoding}] on {_currentSerialPortName}:{_currentSerialBaudRate}.");
3385 TransportKind.RabbitMq,
3386 $
"RabbitMQ on {_currentRabbitMqHost}:{_currentRabbitMqPort}, vhost={_currentRabbitMqVirtualHost}, exchange={_currentRabbitMqExchangeName}, queue={_currentRabbitMqQueueName}, route={_currentRabbitMqRoutingKey}.");
3409 return "Serial-Port";
3412 return $
"Serial-{_currentSerialPortName}";
3465 string routePrefix =
"tcp",
3466 string namePrefix =
"Tcp",
3467 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
3470 var textEncoding = PlainTextProtocolOptions.CreateEncoding(encodingName);
3472 return normalizedProtocol
switch
3478 $
"{routePrefix}.plaintext",
3479 $
"{namePrefix}.PlainText"),
3483 $
"{routePrefix}.raw.available",
3484 $
"{namePrefix}.RawAvailable"),
3488 $
"{routePrefix}.rawjson",
3489 $
"{namePrefix}.RawJson"),
3491 _ =>
new PlainTextProtocolAdapter(
3493 $
"{routePrefix}.plaintext",
3494 $
"{namePrefix}.PlainText")
3532 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
3534 var delimiterEncoding = PlainTextProtocolOptions.CreateEncoding(encodingName);
3552 _ =>
new DelimiterMessageFrameCodec(
3629 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
3639 _ => $
"TCP-Server-PlainText-{normalizedEncodingName}"
3677 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
3687 _ => $
"TCP-Client-PlainText-{normalizedEncodingName}"
3734 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
3742 PlainTextProtocol => $
"UDP-Peer{normalizedPeerName}-PlainText-{normalizedEncodingName}",
3745 _ => $
"UDP-Peer{normalizedPeerName}-PlainText-{normalizedEncodingName}"
3774 if (
string.Equals(encodingName, PlainTextProtocolOptions.KoreanCodePage949EncodingName, StringComparison.OrdinalIgnoreCase) ||
3775 string.Equals(encodingName,
"949", StringComparison.OrdinalIgnoreCase))
3777 return PlainTextProtocolOptions.KoreanCodePage949EncodingName;
3780 return PlainTextProtocolOptions.Utf8EncodingName;
3872 return string.Equals(peerName,
"B", StringComparison.OrdinalIgnoreCase)
3929 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
3933 var payload = Encoding.UTF8.GetBytes(text);
3935 return normalizedProtocol
switch
3939 Name = $
"Tcp.{direction}.DreamineEnvelope",
3940 Route =
"sample.communication.tcp",
3942 Headers =
new Dictionary<string, string>
3950 Name = $
"Tcp.{direction}.PlainText",
3951 Route =
"tcp.plaintext",
3953 Headers =
new Dictionary<string, string>
3955 [
"ContentType"] =
"text/plain",
3957 [
"ExternalEncoding"] = normalizedEncodingName
3963 Name = $
"Tcp.{direction}.RawAvailable",
3964 Route =
"tcp.raw.available",
3966 Headers =
new Dictionary<string, string>
3968 [
"ContentType"] =
"text/plain",
3970 [
"ExternalEncoding"] = normalizedEncodingName
3976 Name = $
"Tcp.{direction}.RawJson",
3977 Route =
"tcp.rawjson",
3979 Headers =
new Dictionary<string, string>
3981 [
"ContentType"] =
"application/json",
3986 _ =>
new MessageEnvelope
3988 Name = $
"Tcp.{direction}.PlainText",
3989 Route =
"tcp.plaintext",
3991 Headers =
new Dictionary<string, string>
3993 [
"ContentType"] =
"text/plain",
3995 [
"ExternalEncoding"] = normalizedEncodingName
4053 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
4057 var payload = Encoding.UTF8.GetBytes(text);
4059 return normalizedProtocol
switch
4063 Name = $
"Udp.{direction}.DreamineEnvelope",
4064 Route =
"sample.communication.udp",
4066 Headers =
new Dictionary<string, string>
4074 Name = $
"Udp.{direction}.PlainText",
4075 Route =
"udp.plaintext",
4077 Headers =
new Dictionary<string, string>
4079 [
"ContentType"] =
"text/plain",
4081 [
"ExternalEncoding"] = normalizedEncodingName
4087 Name = $
"Udp.{direction}.RawAvailable",
4088 Route =
"udp.raw.available",
4090 Headers =
new Dictionary<string, string>
4092 [
"ContentType"] =
"text/plain",
4094 [
"ExternalEncoding"] = normalizedEncodingName
4100 Name = $
"Udp.{direction}.RawJson",
4101 Route =
"udp.rawjson",
4103 Headers =
new Dictionary<string, string>
4105 [
"ContentType"] =
"application/json",
4110 _ =>
new MessageEnvelope
4112 Name = $
"Udp.{direction}.PlainText",
4113 Route =
"udp.plaintext",
4115 Headers =
new Dictionary<string, string>
4117 [
"ContentType"] =
"text/plain",
4119 [
"ExternalEncoding"] = normalizedEncodingName
4177 string encodingName = PlainTextProtocolOptions.Utf8EncodingName)
4181 var payload = Encoding.UTF8.GetBytes(text);
4183 return normalizedProtocol
switch
4187 Name = $
"Serial.{direction}.DreamineEnvelope",
4188 Route =
"sample.communication.serial",
4190 Headers =
new Dictionary<string, string>
4198 Name = $
"Serial.{direction}.PlainText",
4199 Route =
"serial.plaintext",
4201 Headers =
new Dictionary<string, string>
4203 [
"ContentType"] =
"text/plain",
4205 [
"ExternalEncoding"] = normalizedEncodingName
4211 Name = $
"Serial.{direction}.RawAvailable",
4212 Route =
"serial.raw.available",
4214 Headers =
new Dictionary<string, string>
4216 [
"ContentType"] =
"text/plain",
4218 [
"ExternalEncoding"] = normalizedEncodingName
4224 Name = $
"Serial.{direction}.RawJson",
4225 Route =
"serial.rawjson",
4227 Headers =
new Dictionary<string, string>
4229 [
"ContentType"] =
"application/json",
4234 _ =>
new MessageEnvelope
4236 Name = $
"Serial.{direction}.PlainText",
4237 Route =
"serial.plaintext",
4239 Headers =
new Dictionary<string, string>
4241 [
"ContentType"] =
"text/plain",
4243 [
"ExternalEncoding"] = normalizedEncodingName
4294 return new MessageEnvelope
4296 Name = $
"RabbitMQ.{direction}",
4298 Payload = Encoding.UTF8.GetBytes(text),
4299 Headers =
new Dictionary<string, string>
4301 [
"ContentType"] =
"text/plain",
4361 return new MessageEnvelope
4365 Payload = Encoding.UTF8.GetBytes(text),
4366 Headers =
new Dictionary<string, string>
4368 [
"ContentType"] =
"text/plain",
4369 [
"Protocol"] = protocol
4410 TransportKind.RabbitMq,
4440 if (
string.IsNullOrWhiteSpace(text))
4442 text =
"{\"cmd\":\"PING\"}";
4445 var trimmed = text.Trim();
4447 if (trimmed.StartsWith(
"{", StringComparison.Ordinal) ||
4448 trimmed.StartsWith(
"[", StringComparison.Ordinal))
4450 return Encoding.UTF8.GetBytes(trimmed);
4457 return Encoding.UTF8.GetBytes(json);
4487 .Replace(
"\\",
"\\\\", StringComparison.Ordinal)
4488 .Replace(
"\"",
"\\\"", StringComparison.Ordinal)
4489 .Replace(
"\r",
"\\r", StringComparison.Ordinal)
4490 .Replace(
"\n",
"\\n", StringComparison.Ordinal);
4519 if (Enum.TryParse<TcpServerSendTargetMode>(
4527 return TcpServerSendTargetMode.Broadcast;
4556 if (
string.IsNullOrWhiteSpace(protocol))
4561 return protocol.Trim()
switch
4605 string defaultValue)
4607 return string.IsNullOrWhiteSpace(value)
4630 ArgumentNullException.ThrowIfNull(action);
4632 var dispatcher = Application.Current?.Dispatcher;
4634 if (dispatcher is
null || dispatcher.CheckAccess())
4640 dispatcher.Invoke(action);
const int RawAvailableProtocolPort
void AttachTcpResilientStateMonitor(IMessageTransport transport, string channelName)
async Task ConnectUdpPeerAAsync(string protocol, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
async void OnTcpServerMessageReceived(object? sender, MessageEnvelope message)
IReadOnlyList< string > TcpProtocols
static IMessageFrameCodec CreateFrameCodec(string protocol, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
static int GetUdpLocalPort(string peerName)
string _currentSerialProtocol
CommunicationMonitorViewModel Monitor
string _currentClientEncoding
TcpServerSendTargetMode _currentServerSendTargetMode
async Task SubscribeRabbitMqAsync(string exchangeName, string queueName, string routingKey)
async Task SendUdpPeerBAsync(string protocol, string text, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
string GetSerialChannelName()
string _currentServerEncoding
async Task PublishRabbitMqAsync(string exchangeName, string routingKey, string text)
async Task PrepareTcpClientTransportAsync(string protocol, string encodingName)
string _currentRabbitMqVirtualHost
async Task ConnectTcpClientAsync(string protocol, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
string _currentRabbitMqHost
static string NormalizeProtocol(string? protocol)
string _currentRabbitMqExchangeName
const int UdpPeerALocalPort
string _currentUdpPeerBProtocol
void AttachTcpClientQueueMonitor(IMessageTransport transport, string protocol, string encodingName, string channelName)
const string RabbitMqProtocol
async Task StopAllTcpAsync()
string _currentRabbitMqRoutingKey
void AttachTcpServerClientCountMonitor(TcpServerTransport tcpServerTransport, string protocol, string encodingName)
void EnsureUdpPeerChannel(string peerName, string protocol, string encodingName)
const int PlainTextProtocolPort
static TcpServerSendTargetMode NormalizeTcpServerSendTargetMode(string? sendTargetMode)
string _currentRabbitMqQueueName
async Task StartTcpServerAsync(string protocol, string encodingName=PlainTextProtocolOptions.Utf8EncodingName, string sendTargetMode=nameof(TcpServerSendTargetMode.Broadcast), bool echoEnabled=false)
string _currentClientProtocol
static string NormalizeTextEncodingName(string encodingName)
const string InMemoryRouteName
async Task DisconnectUdpPeerBAsync()
static string GetTcpServerChannelName(string protocol, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
int _currentSerialBaudRate
async Task SubscribeInMemoryAsync()
static string GetTcpClientChannelName(string protocol, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
static string GetUdpPeerChannelName(string peerName, string protocol, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
static IMessageProtocolAdapter CreateProtocolAdapter(string protocol, string routePrefix="tcp", string namePrefix="Tcp", string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
static MessageEnvelope CreateRabbitMqMessage(string direction, string route, string text)
bool _currentServerEchoEnabled
void UpdateTcpServerDescription(string protocol, string encodingName, int clientCount, TcpServerSendTargetMode targetMode, bool echoEnabled)
async Task SendSerialAsync(string protocol, string text, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
IMessageTransport? _tcpClient
async Task SendInMemoryAsync(string text)
string _currentSerialEncoding
bool _isInMemorySubscribed
string _currentUdpPeerAProtocol
async Task DisconnectInMemoryAsync()
const int RawJsonProtocolPort
static int GetTcpPort(string protocol)
void AddRabbitMqErrorLog(string name, string text)
static MessageEnvelope CreateTextMessage(string name, string route, string text, string protocol)
SerialPortTransport? _serialTransport
async Task SendTcpServerAsync(string protocol, string text, string encodingName=PlainTextProtocolOptions.Utf8EncodingName, string sendTargetMode=nameof(TcpServerSendTargetMode.Broadcast))
IReadOnlyList< string > SerialProtocols
async Task SendTcpClientAsync(string protocol, string text, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
IReadOnlyList< string > TextEncodings
static OutboundQueueOptions CreateSampleServerOutboundQueueOptions()
async Task ConnectRabbitMqAsync(string host, int port, string virtualHost, string userName, string password, string exchangeName, string queueName, string routingKey)
static string CreateTcpServerDescription(string protocol, string encodingName, int port, int clientCount, TcpServerSendTargetMode targetMode, bool echoEnabled)
void EnsureSerialChannel()
async Task DisconnectRabbitMqAsync()
void EnsureRabbitMqChannel()
void UpdateTcpServerOptions(string protocol, string encodingName=PlainTextProtocolOptions.Utf8EncodingName, string sendTargetMode=nameof(TcpServerSendTargetMode.Broadcast), bool echoEnabled=false)
void OnSerialMessageReceived(object? sender, MessageEnvelope message)
async Task DisconnectTcpClientAsync()
void OnUdpPeerBMessageReceived(object? sender, MessageEnvelope message)
async Task StopAllUdpAsync()
IReadOnlyList< string > UdpProtocols
async Task ConnectInMemoryAsync()
void EnsureTcpServerChannel(string protocol, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
static MessageEnvelope CreateTcpMessageByProtocol(string protocol, string direction, string text, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
void ReceiveInMemory(string text)
async Task DisconnectUdpPeerAAsync()
async Task DisconnectSerialAsync()
IReadOnlyList< string > TcpServerSendTargetModes
async Task StopAllAsync()
static MessageEnvelope CreateUdpMessageByProtocol(string protocol, string direction, string text, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
static string EscapeJsonString(string value)
static ReconnectPolicy CreateSampleReconnectPolicy()
static string NormalizeUdpPeerName(string peerName)
const int UdpPeerBLocalPort
void OnUdpPeerAMessageReceived(object? sender, MessageEnvelope message)
static MessageEnvelope CreateSerialMessageByProtocol(string protocol, string direction, string text, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
const string RabbitMqChannelName
void OnTcpClientMessageReceived(object? sender, MessageEnvelope message)
async Task StartUdpLoopbackAsync(string protocol, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
string _currentUdpPeerBEncoding
async Task ConnectUdpPeerBAsync(string protocol, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
static byte[] EnsureJsonPayload(string text)
static int GetUdpRemotePort(string peerName)
string _currentUdpPeerAEncoding
const int DreamineProtocolPort
string _currentServerProtocol
const string RawJsonProtocol
const string DreamineEnvelopeProtocol
TcpServerTransport? _rawTcpServer
const string PlainTextProtocol
async Task ConnectSerialAsync(string portName, int baudRate, string protocol, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
const string RawAvailableProtocol
bool _isRabbitMqSubscribed
void AddInMemoryChannel()
static string NormalizeText(string? value, string defaultValue)
static void RunOnUiThread(Action action)
void EnsureTcpClientChannel(string protocol, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
async Task StopTcpServerAsync()
static OutboundQueueOptions CreateSampleOutboundQueueOptions()
CommunicationSampleRuntime(IMessageBus messageBus)
IReadOnlyList< string > UdpTextEncodings
IMessageTransport? _tcpServer
string _currentSerialPortName
const string InMemoryChannelName
async Task SendUdpPeerAAsync(string protocol, string text, string encodingName=PlainTextProtocolOptions.Utf8EncodingName)
readonly IMessageBus _messageBus
RabbitMqMessageBus? _rabbitMqBus