sc 1 year ago
parent
commit
e18e3f8447
  1. 1
      DyeingComputer.csproj
  2. 14
      UserClass/AsyncTcpServer.cs
  3. 66
      UserClass/Json.cs
  4. 42
      UserClass/LogGing.cs

1
DyeingComputer.csproj

@ -135,6 +135,7 @@
<Compile Include="UserClass\get_local_ip_address.cs" /> <Compile Include="UserClass\get_local_ip_address.cs" />
<Compile Include="UserClass\HardwareSN.cs" /> <Compile Include="UserClass\HardwareSN.cs" />
<Compile Include="UserClass\IniFile.cs" /> <Compile Include="UserClass\IniFile.cs" />
<Compile Include="UserClass\Json.cs" />
<Compile Include="UserClass\LogDataRead.cs" /> <Compile Include="UserClass\LogDataRead.cs" />
<Compile Include="UserClass\LogGing.cs" /> <Compile Include="UserClass\LogGing.cs" />
<Compile Include="UserClass\MD5check.cs" /> <Compile Include="UserClass\MD5check.cs" />

14
UserClass/AsyncTcpServer.cs

@ -14,19 +14,20 @@ using System.Diagnostics;
using TouchSocket.Core; using TouchSocket.Core;
using TouchSocket.Sockets; using TouchSocket.Sockets;
using DyeingComputer.ViewModel; using DyeingComputer.ViewModel;
using System.Runtime.InteropServices;
namespace DyeingComputer.UserClass namespace DyeingComputer.UserClass
{/// <summary> {/// <summary>
/// 异步TCP服务器 /// 异步TCP服务器
/// </summary> /// </summary>
public class AsyncTcpServer public class AsyncTcpServer
{ {
public static async Task Main() public static async Task Main()
{ {
var service = new TcpService(); TcpService service = new TcpService();
service.Received = (client, e) => service.Received = (client, e) =>
{ {
LogGing.LogGingDATA("800API:"+e.ByteBlock.Span.ToString(Encoding.ASCII)); LogGing.LogSQLDATA("800", "TcpServer", "API:"+e.ByteBlock.Span.ToString(Encoding.ASCII));
if (e.ByteBlock.Span.ToString(Encoding.ASCII) == "SC800") client.SendAsync(MainWindowViewModel.S01); if (e.ByteBlock.Span.ToString(Encoding.ASCII) == "SC800") client.SendAsync(MainWindowViewModel.S01);
if (e.ByteBlock.Span.ToString(Encoding.ASCII) == "SC801") client.SendAsync(MainWindowViewModel.S16.ToString()); if (e.ByteBlock.Span.ToString(Encoding.ASCII) == "SC801") client.SendAsync(MainWindowViewModel.S16.ToString());
if (e.ByteBlock.Span.ToString(Encoding.ASCII) == "SC802") client.SendAsync(MainWindowViewModel.S03); if (e.ByteBlock.Span.ToString(Encoding.ASCII) == "SC802") client.SendAsync(MainWindowViewModel.S03);
@ -43,15 +44,14 @@ namespace DyeingComputer.UserClass
}) })
.ConfigurePlugins(a => .ConfigurePlugins(a =>
{ {
a.Add<DifferentProtocolPlugin>(); //a.Add<DifferentProtocolPlugin>();
})); }));
await service.StartAsync();//启动 await service.StartAsync();//启动
LogGing.LogGingDATA("800SREVER:START"); LogGing.LogGingDATA("800SREVER:START");
//service.Logger.Info("服务器成功启动");
//Console.ReadKey();
} }
} }
class MyTcpService : TcpService<MyTcpSessionClient> class MyTcpService : TcpService<MyTcpSessionClient>
{ {
protected override MyTcpSessionClient NewClient() protected override MyTcpSessionClient NewClient()

66
UserClass/Json.cs

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace DyeingComputer.UserClass
{
public class Json
{
}
public class ProgramSteps_
{
public string Program { get; set; }
public int Step { get; set; }
public string StepID { get; set; }
public string StepName { get; set; }
public string ParameterName { get; set; }
public double Parameter1 { get; set; }
public double Parameter2 { get; set; }
public double Parameter3 { get; set; }
public double Parameter4 { get; set; }
public double Parameter5 { get; set; }
public double Parameter6 { get; set; }
public double Parameter7 { get; set; }
public double Parameter8 { get; set; }
public double Parameter9 { get; set; }
public double Parameter10 { get; set; }
public string Remark { get; set; }
}
public class WorkorderSteps_
{
public string Program { get; set; }
public int Step { get; set; }
public string StepID { get; set; }
public string StepName { get; set; }
public string ParameterName { get; set; }
public double Parameter1 { get; set; }
public double Parameter2 { get; set; }
public double Parameter3 { get; set; }
public double Parameter4 { get; set; }
public double Parameter5 { get; set; }
public string Remark { get; set; }
}
public class WorkOrder_
{
public string WorkOrder { get; set; }
public string ProcessName { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public DateTime Time { get; set; }
public string Remark { get; set; }
public string ProcessID { get; set; }
public int State { get; set; }
public int _lock { get; set; }
}
}

42
UserClass/LogGing.cs

@ -1,10 +1,18 @@
using System; using DyeingComputer.ViewModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO; using System.IO;
using static DyeingComputer.UserClass.SqliteHelper;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
namespace DyeingComputer.UserClass namespace DyeingComputer.UserClass
{ {
public class LogGing public class LogGing
{ {
private static SQLiteHelper SQLiteHelpers = null; //定义数据库
private readonly static string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
public static bool sqld=false;
public static void LogGingDATA(string dat) public static void LogGingDATA(string dat)
{ {
string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录 string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录
@ -19,13 +27,19 @@ namespace DyeingComputer.UserClass
StreamWriter wr = new StreamWriter(fs);//创建文件 StreamWriter wr = new StreamWriter(fs);//创建文件
wr.WriteLine(Log_time + dat); wr.WriteLine(Log_time + dat);
wr.Close(); wr.Close();
} }
else else
{ {
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write); try
StreamWriter wr = new StreamWriter(fs);//创建文件 {
wr.WriteLine(Log_time + dat); FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
wr.Close(); } StreamWriter wr = new StreamWriter(fs);//创建文件
wr.WriteLine(Log_time + dat);
wr.Close();
}
catch (Exception ex) { }
}
} }
else else
{ {
@ -33,5 +47,23 @@ namespace DyeingComputer.UserClass
directoryInfo.Create();//创建日志路径 directoryInfo.Create();//创建日志路径
} }
} }
public static void LogSQLDATA(string NAME, string api, string dat)
{if (!sqld)
{
sqld = true;
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
string Log_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
Dictionary<string, object> logsql = new Dictionary<string, object>();
// 添加元素
logsql.Add("NAME", NAME);
logsql.Add("API", api);
logsql.Add("MESSAGE", dat);
logsql.Add("TIME", Log_time);
SQLiteHelpers.Open(); //打开数据库
SQLiteHelpers.InsertData("SERVER", logsql);//行插入
SQLiteHelpers.Close(); //关闭连接
sqld = false;
}
}
} }
} }

Loading…
Cancel
Save