chore: initial commit
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Collections;
|
||||
//using BasicData;
|
||||
////using bizFacade;
|
||||
//using SystemFramework;
|
||||
using System.Configuration;
|
||||
//using MesWork;
|
||||
using MQTTnet.Client.Connecting;
|
||||
using MQTTnet.Client.Disconnecting;
|
||||
using MQTTnet.Client.Receiving;
|
||||
using MQTTnet;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MesServerFunctions
|
||||
{
|
||||
public partial class MIS_SendMessage
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static string MqttTargetTopic = ConfigurationManager.AppSettings["MqttTargetTopic"];
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
static new MesWebFun_base.MisWebInterface misWebInterface = new MesWebFun_base.MisWebInterface();
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
static readonly Object locker = new Object();
|
||||
/// <summary>
|
||||
/// 发消息给通讯服务器
|
||||
/// </summary>
|
||||
/// <param name="Message"></param>
|
||||
public static string asyncSendMessage(string Message)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
//"MES|MachinePlan|OpName|Value
|
||||
var array = Message.Split('|');
|
||||
var cmd = array[1];
|
||||
var opName = array[2];
|
||||
var topic = $"{MqttTargetTopic}/{opName}";
|
||||
Task.Run(() => Mqtt.Publish(topic, Message));
|
||||
|
||||
var responseStr = misWebInterface.WebSocket_Function(Message);
|
||||
if (responseStr.Length > 0)
|
||||
{
|
||||
Task.Run(() => Mqtt.Publish(topic, $"MES|{cmd}_Resources|{opName}|{responseStr}"));
|
||||
}
|
||||
return responseStr;
|
||||
}
|
||||
}
|
||||
|
||||
public static string asyncSendMessageDemo(string Message)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
//"MES|MachinePlan|OpName|Value
|
||||
var array = Message.Split('|');
|
||||
var cmd = array[1];
|
||||
var opName = array[2];
|
||||
var topic = $"{MqttTargetTopic}/{opName}";
|
||||
|
||||
//Mqtt.Publish(topic, Message);
|
||||
string responseStr = "";
|
||||
//var responseStr = misWebInterface.WebSocket_Function(Message);
|
||||
//if (responseStr.Length > 0)
|
||||
//{
|
||||
|
||||
// Mqtt.Publish(topic, $"MES|{cmd}_Resources|{opName}|{responseStr}");
|
||||
//}
|
||||
return responseStr;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发消息给通讯服务器
|
||||
/// </summary>
|
||||
/// <param name="Message"></param>
|
||||
public static string asyncSendMessageQos0(string Message)
|
||||
{
|
||||
lock (locker)
|
||||
{
|
||||
//"MES|MachinePlan|OpName|Value
|
||||
var array = Message.Split('|');
|
||||
var cmd = array[1];
|
||||
var opName = array[2];
|
||||
var topic = $"{MqttTargetTopic}/{opName}";
|
||||
Mqtt.PublishQos0(topic, Message);
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user