init: 北航大学BH-DAS项目首次入库
This commit is contained in:
83
GlobalVar/GlobalVar.cs
Normal file
83
GlobalVar/GlobalVar.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
//using MQTTnet;
|
||||
//using MQTTnet.Extensions.ManagedClient;
|
||||
//using DatabaseClient;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace DNC_CSharp_Demo
|
||||
{
|
||||
public class GlobalVar
|
||||
{
|
||||
// public static SafeMqttClient mqttClient = null;
|
||||
public static AppConfig appConfig = new AppConfig();
|
||||
|
||||
//public static IManagedMqttClient mqttClient = null;
|
||||
|
||||
//public static DBClient dbClient = null;
|
||||
|
||||
public static bool enableLog = false;
|
||||
public static string DatabaseConnectStr = "";
|
||||
|
||||
public static bool saveHistory = true;
|
||||
public static int isFirstConnect = 0;
|
||||
|
||||
public static string OpName = "F56AE937-A27E-40A3-A4E1-1217CD71C9BC";
|
||||
|
||||
public static void Init(bool isEnableLog)
|
||||
{
|
||||
enableLog = isEnableLog;
|
||||
//mqttClient = new MqttFactory().CreateManagedMqttClient();
|
||||
}
|
||||
|
||||
public static void InitDatabase(string connStr)
|
||||
{
|
||||
DatabaseConnectStr = connStr;
|
||||
//dbClient = new DBClientFactory("Mysql").Create();
|
||||
//dbClient.Connect(connStr);
|
||||
}
|
||||
|
||||
public static void SendMessage(string topic, string msg)
|
||||
{
|
||||
//if (mqttClient != null)
|
||||
//{
|
||||
// mqttClient.EnqueueAsync(topic, msg);
|
||||
//}
|
||||
|
||||
//if (saveHistory)
|
||||
//{
|
||||
// ThreadPool.QueueUserWorkItem((object obj) =>
|
||||
// {
|
||||
// var opName = topic;
|
||||
|
||||
|
||||
// var now = DateTime.Now;
|
||||
// var currentDay = now.ToString("yyyyMMdd");
|
||||
|
||||
// string sql = " INSERT INTO z_save_position_" + currentDay + "(ID, OpName, Value, OperationTime, ProjectCode) VALUES('" +
|
||||
|
||||
// Guid.NewGuid() + "', '" + opName + "', '" + msg + "', '" + now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "', '" + "PLC" + "');\n";
|
||||
|
||||
// MysqlClient.ExecQuerySQL(sql, DatabaseConnectStr, out string error);
|
||||
// });
|
||||
//}
|
||||
|
||||
if (enableLog)
|
||||
{
|
||||
MyLog4Net.MyLogHelper.Info("MQTT", "【TOPIC】" + topic + "【MESSAGE】" + msg);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class Tools
|
||||
{
|
||||
public static string GetMd5(string str)
|
||||
{
|
||||
MD5 md5 = new MD5CryptoServiceProvider();
|
||||
var bytes = Encoding.UTF8.GetBytes(str);
|
||||
return Encoding.UTF8.GetString(md5.ComputeHash(bytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user