Commit d3cd7a2e by liulongfei

1. 连接框架更新,支持TCP与UDP

2. 连接框架支持单条消息为JSON的处理
3. 连接框架支持命令行消息的处理
4. 连接框架支持固定长度Buffer消息的处理
parent 727d5eee
......@@ -15,5 +15,10 @@ namespace VIZ.Framework.Connection
/// Udp连接
/// </summary>
public static UdpConnection UdpConnection { get; set; }
/// <summary>
/// TCP连接
/// </summary>
public static TcpConnection TcpConnection { get; set; }
}
}
......@@ -7,23 +7,29 @@ using System.Threading.Tasks;
namespace VIZ.Framework.Connection
{
/// <summary>
/// UDP包信息
/// 连接信息
/// </summary>
public class UdpPackageInfo
public abstract class ConnInfoBase
{
/// <summary>
/// IP
/// 本地IP
/// </summary>
public string IP { get; set; }
public string LocalIP { get; internal set; }
/// <summary>
/// 端口
/// 本地端口
/// </summary>
public int Port { get; set; }
public int LocalPort { get; internal set; }
/// <summary>
/// 消息
/// 远程IP
/// </summary>
public string Message { get; set; }
public string RemoteIP { get; internal set; }
/// <summary>
/// 远程端口
/// </summary>
public int RemotePort { get; internal set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Connection
{
/// <summary>
/// 连接消息基类
/// </summary>
public abstract class ConnMessageBase
{
/// <summary>
/// 本地IP
/// </summary>
public string LocalIP { get; internal set; }
/// <summary>
/// 本地端口
/// </summary>
public int LocalPort { get; internal set; }
/// <summary>
/// 远程IP
/// </summary>
public string RemoteIP { get; internal set; }
/// <summary>
/// 远程端口
/// </summary>
public int RemotePort { get; internal set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Connection
{
/// <summary>
/// 连接数据包信息
/// </summary>
public class ConnPackageInfo
{
/// <summary>
/// 本地IP
/// </summary>
public string LocalIP { get; internal set; }
/// <summary>
/// 本地端口
/// </summary>
public int LocalPort { get; internal set; }
/// <summary>
/// 远程IP
/// </summary>
public string RemoteIP { get; internal set; }
/// <summary>
/// 远程端口
/// </summary>
public int RemotePort { get; internal set; }
/// <summary>
/// 数据
/// </summary>
public byte[] Data { get; set; }
/// <summary>
/// 数据大小
/// </summary>
public int DataSize { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Connection
{
/// <summary>
/// 包解析器类型
/// </summary>
[Flags]
public enum ConnPackageProviderType
{
/// <summary>
/// 一般用作TCP消息,需要考虑连包情况
/// </summary>
TCP,
/// <summary>
/// 一般用作UDP消息,不需要考虑连包情况
/// </summary>
UDP
}
/// <summary>
/// 包解析器推荐使用的协议
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public class ConnPackageProviderAttribute : Attribute
{
/// <summary>
/// 包解析器推荐使用的协议
/// </summary>
/// <param name="type">类型</param>
public ConnPackageProviderAttribute(ConnPackageProviderType type)
{
this.Type = type;
}
/// <summary>
/// 类型
/// </summary>
public ConnPackageProviderType Type { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Connection
{
/// <summary>
/// 连接发送消息
/// </summary>
public class ConnSendMessage : ConnMessageBase
{
/// <summary>
/// 发送的内容
/// </summary>
public byte[] Buffer { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Connection
{
/// <summary>
/// 线程信息
/// </summary>
public class ConnThreadInfo
{
/// <summary>
/// 是否已经取消
/// </summary>
public bool IsCancel { get; set; }
}
}
......@@ -7,14 +7,14 @@ using System.Threading.Tasks;
namespace VIZ.Framework.Connection
{
/// <summary>
/// UDP包处理器
/// 连接包处理器
/// </summary>
public interface IUdpPackageProvider
public interface IConnPackageProvider
{
/// <summary>
/// 执行
/// </summary>
/// <param name="packageInfo">包信息</param>
void Execute(UdpPackageInfo packageInfo);
/// <param name="package">数据包</param>
void Execute(ConnPackageInfo package);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Connection
{
/// <summary>
/// 连接命令行信息
/// </summary>
public class ConnCommandLineInfo : ConnInfoBase
{
/// <summary>
/// 命令字符串
/// </summary>
public string Command { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Connection
{
/// <summary>
/// 命令行消息
/// </summary>
public class ConnCommandLineMessage : ConnMessageBase
{
/// <summary>
/// 命令
/// </summary>
public string Command { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using log4net;
using VIZ.Framework.Domain;
namespace VIZ.Framework.Connection
{
/// <summary>
/// 包处理器 -- 命令行
/// </summary>
[ConnPackageProvider(ConnPackageProviderType.TCP | ConnPackageProviderType.UDP)]
public class ConnCommandLinePackageProvider : IConnPackageProvider
{
/// <summary>
/// 日志
/// </summary>
private static ILog log = LogManager.GetLogger(typeof(ConnCommandLinePackageProvider));
/// <summary>
/// 数据编码
/// </summary>
public Encoding Encoding { get; set; } = Encoding.UTF8;
/// <summary>
/// 最后的命令字符串,用于处理连包数据
/// </summary>
private string lastCommandString;
/// <summary>
/// 执行
/// </summary>
/// <param name="package">数据包</param>
public void Execute(ConnPackageInfo package)
{
string str = this.Encoding.GetString(package.Data, 0, package.DataSize);
if (string.IsNullOrWhiteSpace(str))
return;
str = this.lastCommandString + str;
this.lastCommandString = null;
string[] commands = str.Split(new char[] { '\r', '\n' });
// 最后一个命令是否完整
bool isLastCommandComplete = str.EndsWith("\n") || str.EndsWith("\r");
for (int i = 0; i < commands.Length; i++)
{
if (i == commands.Length - 1 && !isLastCommandComplete)
{
this.lastCommandString = commands[i];
break;
}
// 处理器处理消息
ConnCommandLineInfo info = new ConnCommandLineInfo();
info.RemoteIP = package.RemoteIP;
info.RemotePort = package.RemotePort;
info.LocalIP = package.LocalIP;
info.LocalPort = package.LocalPort;
info.Command = commands[i];
try
{
this.Execute(info);
}
catch (Exception ex)
{
log.Error(ex);
}
// 发送消息
ConnCommandLineMessage msg = new ConnCommandLineMessage();
msg.RemoteIP = package.RemoteIP;
msg.RemotePort = package.RemotePort;
msg.LocalIP = package.LocalIP;
msg.LocalPort = package.LocalPort;
msg.Command = commands[i];
try
{
ApplicationDomain.MessageManager.Send(msg);
}
catch (Exception ex)
{
log.Error(ex);
}
}
}
/// <summary>
/// 执行
/// </summary>
/// <param name="info">信息</param>
protected virtual void Execute(ConnCommandLineInfo info)
{
// nothing to do.
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Connection
{
/// <summary>
/// 固定长度Buffer信息
/// </summary>
public class ConnFixedBufferInfo : ConnInfoBase
{
/// <summary>
/// 数据
/// </summary>
public byte[] Buffer { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Connection
{
/// <summary>
/// 固定Buffer消息
/// </summary>
public class ConnFixedBufferMessage : ConnMessageBase
{
/// <summary>
/// 数据
/// </summary>
public byte[] Buffer { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using log4net;
using VIZ.Framework.Domain;
namespace VIZ.Framework.Connection
{
/// <summary>
/// 固定长度Buffer包解析器
/// </summary>
[ConnPackageProvider(ConnPackageProviderType.TCP | ConnPackageProviderType.UDP)]
public class ConnFixedBufferPackageProvider : IConnPackageProvider
{
/// <summary>
/// 日志
/// </summary>
private static ILog log = LogManager.GetLogger(typeof(ConnFixedBufferPackageProvider));
/// <summary>
/// 固定长度Buffer包解析器
/// </summary>
/// <param name="fixedBufferSize">固定Buffer长度</param>
public ConnFixedBufferPackageProvider(int fixedBufferSize)
{
this.FixedBufferSize = fixedBufferSize;
this.buffer_index = 0;
this.buffer_cache = new byte[fixedBufferSize];
}
/// <summary>
/// 固定Buffer长度
/// </summary>
public int FixedBufferSize { get; private set; }
/// <summary>
/// 数据缓存
/// </summary>
private byte[] buffer_cache;
/// <summary>
/// 数据缓存索引
/// </summary>
private int buffer_index;
/// <summary>
/// 执行
/// </summary>
/// <param name="package">数据包</param>
public void Execute(ConnPackageInfo package)
{
int copy = Math.Min(package.DataSize, (buffer_cache.Length - buffer_index));
Array.Copy(package.Data, 0, this.buffer_cache, buffer_index, copy);
this.buffer_index += copy;
if (this.buffer_index < this.FixedBufferSize)
return;
// 处理器处理消息
ConnFixedBufferInfo info = new ConnFixedBufferInfo();
info.LocalIP = package.LocalIP;
info.LocalPort = package.LocalPort;
info.RemoteIP = package.RemoteIP;
info.RemotePort = package.RemotePort;
info.Buffer = this.buffer_cache;
this.buffer_index = 0;
this.buffer_cache = new byte[this.FixedBufferSize];
try
{
this.Execute(info);
}
catch (Exception ex)
{
log.Error(ex);
}
// 发送消息
ConnFixedBufferMessage msg = new ConnFixedBufferMessage();
msg.LocalIP = package.LocalIP;
msg.LocalPort = package.LocalPort;
msg.RemoteIP = package.RemoteIP;
msg.RemotePort = package.RemotePort;
msg.Buffer = info.Buffer;
try
{
ApplicationDomain.MessageManager.Send(msg);
}
catch (Exception ex)
{
log.Error(ex);
}
}
/// <summary>
/// 执行
/// </summary>
/// <param name="info">信息</param>
protected virtual void Execute(ConnFixedBufferInfo info)
{
// noting to do.
}
}
}
\ No newline at end of file
......@@ -4,21 +4,16 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Domain
namespace VIZ.Framework.Connection
{
/// <summary>
/// UDP控制台消
/// 单条消息为JSON信
/// </summary>
public class UdpConsoleMessage
public class ConnSingleJsonInfo : ConnInfoBase
{
/// <summary>
/// 消息
/// JSON字符串
/// </summary>
public string Message { get; set; }
/// <summary>
/// 该消息是否是发送消息,否则为接收到的消息
/// </summary>
public bool IsSender { get; set; }
public string Json { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Connection
{
/// <summary>
/// 单条消息为JSON字符串的消息
/// </summary>
public class ConnSingleJsonMessage : ConnMessageBase
{
/// <summary>
/// Json字符串
/// </summary>
public string Json { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using log4net;
using VIZ.Framework.Domain;
namespace VIZ.Framework.Connection
{
/// <summary>
/// 单条消息为JSON的处理器
/// </summary>
[ConnPackageProvider(ConnPackageProviderType.UDP)]
public class ConnSingleJsonPackageProvider : IConnPackageProvider
{
/// <summary>
/// 日志
/// </summary>
private static ILog log = LogManager.GetLogger(typeof(ConnSingleJsonPackageProvider));
/// <summary>
/// 数据编码
/// </summary>
public Encoding Encoding { get; set; } = Encoding.UTF8;
/// <summary>
/// 执行
/// </summary>
/// <param name="package">数据包</param>
public void Execute(ConnPackageInfo package)
{
string json = this.Encoding.GetString(package.Data, 0, package.DataSize);
// 处理器处理消息
ConnSingleJsonInfo info = new ConnSingleJsonInfo();
info.LocalIP = package.LocalIP;
info.LocalPort = package.LocalPort;
info.RemoteIP = package.RemoteIP;
info.RemotePort = package.RemotePort;
info.Json = json;
try
{
this.Execute(info);
}
catch (Exception ex)
{
log.Error(ex);
}
// 发送消息
ConnSingleJsonMessage msg = new ConnSingleJsonMessage();
msg.LocalIP = package.LocalIP;
msg.LocalPort = package.LocalPort;
msg.RemoteIP = package.RemoteIP;
msg.RemotePort = package.RemotePort;
msg.Json = json;
try
{
ApplicationDomain.MessageManager.Send(msg);
}
catch (Exception ex)
{
log.Error(ex);
}
}
/// <summary>
/// 执行
/// </summary>
/// <param name="info">信息</param>
protected virtual void Execute(ConnSingleJsonInfo info)
{
// noting to do.
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Connection
{
/// <summary>
/// TCP链接
/// </summary>
public class TcpConnection : IDisposable
{
/// <summary>
/// 终结点管理器集合
/// </summary>
private Dictionary<string, TcpEndpointManager> endpointManagers = new Dictionary<string, TcpEndpointManager>();
/// <summary>
/// 获取TCP终结点管理器
/// </summary>
/// <param name="key">终结点管理器键</param>
/// <returns>终结点管理器</returns>
public TcpEndpointManager GetEndpointManager(string key)
{
this.endpointManagers.TryGetValue(key, out TcpEndpointManager manager);
return manager;
}
/// <summary>
/// 添加TCP终结点管理器
/// </summary>
/// <param name="manager">终结点管理器</param>
public void AddEndpointManager(TcpEndpointManager manager)
{
manager.TcpConnection = this;
lock (this.endpointManagers)
{
this.endpointManagers.Add(manager.Key, manager);
}
}
/// <summary>
/// 移除UDP终结点管理器
/// </summary>
/// <param name="key">终结点管理器键</param>
public void RemoveEndpointManager(string key)
{
lock (this.endpointManagers)
{
if (this.endpointManagers.ContainsKey(key))
{
this.endpointManagers.Remove(key);
}
}
}
/// <summary>
/// 销毁
/// </summary>
public void Dispose()
{
lock (this.endpointManagers)
{
foreach (TcpEndpointManager manager in this.endpointManagers.Values)
{
manager.Dispose();
}
this.endpointManagers.Clear();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using log4net;
namespace VIZ.Framework.Connection
{
/// <summary>
/// TCP终结点管理器
/// </summary>
public class TcpEndpointManager : IDisposable
{
/// <summary>
/// 日志
/// </summary>
private static ILog log = LogManager.GetLogger(typeof(TcpEndpointManager));
/// <summary>
/// 接收数据数组大小
/// </summary>
public const int RECV_BUFFER_SIZE = 1024 * 10;
/// <summary>
/// 接收数据线程间隔
/// </summary>
public const int RECV_THREAD_SLEEP = 10;
/// <summary>
/// TCP终结点管理器
/// </summary>
/// <param name="key">网络终结点键</param>
/// <param name="ip">IP</param>
/// <param name="port">端口</param>
public TcpEndpointManager(string key)
{
this.Key = key;
}
/// <summary>
/// 网络终结点键
/// </summary>
public string Key { get; private set; }
/// <summary>
/// 监听IP
/// </summary>
public string LocalIP { get; private set; }
/// <summary>
/// 监听端口
/// </summary>
public int LocalPort { get; private set; }
/// <summary>
/// 远程IP
/// </summary>
public string RemoteIP { get; private set; }
/// <summary>
/// 远程端口
/// </summary>
public int RemotePort { get; private set; }
/// <summary>
/// TCP客户端
/// </summary>
public TcpClient TcpClient { get; private set; }
/// <summary>
/// TCP流对象
/// </summary>
public NetworkStream NetworkStream { get; private set; }
/// <summary>
/// TCP连接
/// </summary>
public TcpConnection TcpConnection { get; internal set; }
/// <summary>
/// 包处理器
/// </summary>
public IConnPackageProvider PackageProvider { get; set; }
#if DEBUG
/// <summary>
/// 调试消息委托
/// </summary>
/// <param name="msg">消息</param>
public delegate void DebugMessageDelegate(string msg);
/// <summary>
/// 调试消息时触发
/// </summary>
public DebugMessageDelegate OnDebugMessage;
#endif
/// <summary>
/// 锁对象
/// </summary>
private object lock_object = new object();
/// <summary>
/// 消息接收线程
/// </summary>
private Thread recvThread;
/// <summary>
/// 接收线程信息
/// </summary>
private ConnThreadInfo recvThreadInfo;
/// <summary>
/// 连接
/// </summary>
/// <param name="remoteIP">远程IP</param>
/// <param name="remotePort">远程端口</param>
public void Connect(string remoteIP, int remotePort)
{
this.RemoteIP = remoteIP;
this.RemotePort = remotePort;
this.TcpClient = new TcpClient();
this.TcpClient.Connect(IPAddress.Parse(remoteIP), remotePort);
this.LocalIP = this.TcpClient.Client.LocalEndPoint.ToString();
this.NetworkStream = this.TcpClient.GetStream();
}
/// <summary>
/// 启动消息接收
/// </summary>
public void StartRecvMessage()
{
if (this.recvThreadInfo != null)
return;
this.recvThreadInfo = new ConnThreadInfo();
this.recvThread = new Thread(this.executeRecvThread);
this.recvThread.Start();
}
/// <summary>
/// 停止消息接收
/// </summary>
public void StopRecvMessage()
{
this.recvThreadInfo.IsCancel = true;
this.recvThread = null;
this.recvThreadInfo = null;
}
/// <summary>
/// 关闭
/// </summary>
public void Close()
{
this.StopRecvMessage();
this.NetworkStream?.Close();
this.NetworkStream?.Dispose();
this.TcpClient?.Close();
this.TcpClient?.Dispose();
this.TcpClient = null;
this.NetworkStream = null;
this.LocalIP = null;
this.LocalPort = 0;
this.RemoteIP = null;
this.RemotePort = 0;
}
/// <summary>
/// 销毁
/// </summary>
public void Dispose()
{
try
{
this.Close();
}
catch (Exception ex)
{
log.Error(ex);
}
}
/// <summary>
/// 发送消息
/// </summary>
/// <param name="buffer"></param>
public void Send(byte[] buffer)
{
if (this.TcpClient == null || !this.TcpClient.Connected)
throw new Exception("tcp conneection is not ready.");
lock (this.lock_object)
{
this.NetworkStream.Write(buffer, 0, buffer.Length);
this.NetworkStream.Flush();
}
}
/// <summary>
/// 执行消息接收
/// </summary>
private void executeRecvThread()
{
ConnThreadInfo info = this.recvThreadInfo;
if (info == null)
return;
while (!info.IsCancel)
{
Thread.Sleep(RECV_THREAD_SLEEP);
// 是否拥有数据
if (!this.NetworkStream.DataAvailable)
{
continue;
}
byte[] buffer = new byte[RECV_BUFFER_SIZE];
int read = 0;
lock (this.lock_object)
{
read = this.NetworkStream.Read(buffer, 0, RECV_BUFFER_SIZE);
}
// 未读取到数据
if (read <= 0)
{
continue;
}
if (this.PackageProvider == null)
{
continue;
}
// 处理数据包
ConnPackageInfo package = new ConnPackageInfo();
package.LocalIP = this.LocalIP;
package.LocalPort = this.LocalPort;
package.RemoteIP = this.RemoteIP;
package.RemotePort = this.RemotePort;
package.Data = buffer;
package.DataSize = read;
try
{
this.PackageProvider.Execute(package);
}
catch (Exception ex)
{
log.Error(ex);
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace VIZ.Framework.Connection
{
/// <summary>
/// TCP终结点管理器扩展
/// </summary>
public static class TcpEndpointManagerExpand
{
/// <summary>
/// 发送字符串
/// </summary>
/// <param name="manager">TCP终结点管理器</param>
/// <param name="msg">消息</param>
/// <param name="encoding">字符编码方式</param>
public static void SendString(this TcpEndpointManager manager, string msg, Encoding encoding)
{
byte[] buffer = encoding.GetBytes(msg);
manager.Send(buffer);
}
/// <summary>
/// 发送字符串(UDF-8编码)
/// </summary>
/// <param name="manager">TCP终结点管理器</param>
/// <param name="msg">消息</param>
public static void SendString(this TcpEndpointManager manager, string msg)
{
SendString(manager, msg, Encoding.UTF8);
}
/// <summary>
/// 发送JSON字符串
/// </summary>
/// <param name="manager">TCP终结点管理器</param>
/// <param name="obj">对象</param>
/// <param name="encoding">字符编码方式</param>
public static void SendJson(this TcpEndpointManager manager, object obj, Encoding encoding)
{
string msg = obj == null ? string.Empty : JsonConvert.SerializeObject(obj);
SendString(manager, msg, encoding);
}
/// <summary>
/// 发送JSON字符串(UDF-8编码)
/// </summary>
/// <param name="manager">TCP终结点管理器</param>
/// <param name="obj">对象</param>
public static void SendJson(this TcpEndpointManager manager, object obj)
{
string msg = obj == null ? string.Empty : JsonConvert.SerializeObject(obj);
SendString(manager, msg, Encoding.UTF8);
}
}
}
......@@ -43,24 +43,9 @@ namespace VIZ.Framework.Connection
public int Port { get; private set; }
/// <summary>
/// 包处理
/// 包解析
/// </summary>
internal List<IUdpPackageProvider> PackageProviders = new List<IUdpPackageProvider>();
#if DEBUG
/// <summary>
/// 调试消息委托
/// </summary>
/// <param name="msg">消息</param>
public delegate void DebugMessageDelegate(string msg);
/// <summary>
/// 调试消息时触发
/// </summary>
public DebugMessageDelegate OnDebugMessage;
#endif
public IConnPackageProvider PackageProvider { get; set; }
/// <summary>
/// 终结点管理器集合
......@@ -130,15 +115,6 @@ namespace VIZ.Framework.Connection
}
/// <summary>
/// 添加包处理器
/// </summary>
/// <param name="provider">包处理器</param>
public void AddProvider(IUdpPackageProvider provider)
{
this.PackageProviders.Add(provider);
}
/// <summary>
/// 获取UDP终结点管理器
/// </summary>
/// <param name="key">终结点管理器键</param>
......@@ -181,8 +157,7 @@ namespace VIZ.Framework.Connection
/// <summary>
/// 接收数据
/// </summary>
/// <param name="obj"></param>
private void ReceiveMessage(object obj)
private void ReceiveMessage()
{
while (this.IsRecvStart)
{
......@@ -191,26 +166,19 @@ namespace VIZ.Framework.Connection
IPEndPoint endport = new IPEndPoint(IPAddress.Any, 0);
byte[] buffer = this.UdpClient.Receive(ref endport);
UdpPackageInfo info = new UdpPackageInfo();
info.IP = this.IP;
info.Port = this.Port;
info.Message = Encoding.UTF8.GetString(buffer);
foreach (IUdpPackageProvider provider in this.PackageProviders)
{
provider.Execute(info);
}
if (this.PackageProvider == null)
continue;
#if DEBUG
string consoleMsg = $"{DateTime.Now} 【接收】 {info.Message}";
this.OnDebugMessage?.Invoke(consoleMsg);
Debug.WriteLine(consoleMsg);
#endif
// 执行解释器
ConnPackageInfo info = new ConnPackageInfo();
info.LocalIP = this.IP;
info.LocalPort = this.Port;
info.RemoteIP = endport.Address.ToString();
info.RemotePort = endport.Port;
info.Data = buffer;
info.DataSize = buffer.Length;
UdpConsoleMessage msg = new UdpConsoleMessage();
msg.Message = info.Message;
msg.IsSender = false;
ApplicationDomain.MessageManager.Send(msg);
this.PackageProvider.Execute(info);
}
catch (Exception ex)
{
......
......@@ -50,7 +50,7 @@ namespace VIZ.Framework.Connection
/// <summary>
/// UDP终结点管理器
/// </summary>
/// <param name="key">网络终结点键<see cref="UdpEndpointKeys"/></param>
/// <param name="key">网络终结点键></param>
/// <param name="ip">IP地址</param>
/// <param name="port">端口</param>
public UdpEndpointManager(string key, string ip, int port)
......@@ -63,34 +63,19 @@ namespace VIZ.Framework.Connection
/// <summary>
/// 发送数据
/// </summary>
/// <param name="data">数据</param>
public void Send(string data)
/// <param name="buffer">数据</param>
public void Send(byte[] buffer)
{
byte[] buffer = Encoding.UTF8.GetBytes(data);
this.UdpClient.Send(buffer, buffer.Length, this.IP, this.Port);
#if DEBUG
string consoleMsg = $"{DateTime.Now} 【发送】 {data}";
this.UdpConnection.OnDebugMessage?.Invoke(consoleMsg);
Debug.WriteLine(consoleMsg);
#endif
ConnSendMessage msg = new ConnSendMessage();
msg.LocalIP = this.UdpConnection.IP;
msg.LocalPort = this.UdpConnection.Port;
msg.RemoteIP = this.IP;
msg.RemotePort = this.Port;
msg.Buffer = buffer;
UdpConsoleMessage msg = new UdpConsoleMessage();
msg.Message = data;
msg.IsSender = true;
ApplicationDomain.MessageManager.Send(msg);
}
/// <summary>
/// 发送数据
/// </summary>
/// <param name="data">数据</param>
public void Send(object data)
{
string str = Newtonsoft.Json.JsonConvert.SerializeObject(data);
this.Send(str);
}
}
}
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Connection
{
/// <summary>
/// UDP终结点管理器扩展
/// </summary>
public static class UdpEndpointManagerExpand
{
/// <summary>
/// 发送字符串
/// </summary>
/// <param name="manager">UDP终结点管理器</param>
/// <param name="msg">消息</param>
/// <param name="encoding">字符编码方式</param>
public static void SendString(this UdpEndpointManager manager, string msg, Encoding encoding)
{
byte[] buffer = encoding.GetBytes(msg);
manager.Send(buffer);
}
/// <summary>
/// 发送字符串(UDF-8编码)
/// </summary>
/// <param name="manager">UDP终结点管理器</param>
/// <param name="msg">消息</param>
public static void SendString(this UdpEndpointManager manager, string msg)
{
SendString(manager, msg, Encoding.UTF8);
}
/// <summary>
/// 发送JSON字符串
/// </summary>
/// <param name="manager">UDP终结点管理器</param>
/// <param name="obj">对象</param>
/// <param name="encoding">字符编码方式</param>
public static void SendJson(this UdpEndpointManager manager, object obj, Encoding encoding)
{
string msg = obj == null ? string.Empty : JsonConvert.SerializeObject(obj);
SendString(manager, msg, encoding);
}
/// <summary>
/// 发送JSON字符串(UDF-8编码)
/// </summary>
/// <param name="manager">UDP终结点管理器</param>
/// <param name="obj">对象</param>
public static void SendJson(this UdpEndpointManager manager, object obj)
{
string msg = obj == null ? string.Empty : JsonConvert.SerializeObject(obj);
SendString(manager, msg, Encoding.UTF8);
}
}
}
......@@ -68,11 +68,29 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ConnectionManager.cs" />
<Compile Include="Core\ConnMessageBase.cs" />
<Compile Include="Core\ConnInfoBase.cs" />
<Compile Include="Core\ConnPackageInfo.cs" />
<Compile Include="Core\ConnPackageProviderAttribute.cs" />
<Compile Include="Core\ConnSendMessage.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UDP\IUdpPackageProvider.cs" />
<Compile Include="Provider\CommandLine\ConnCommandLineInfo.cs" />
<Compile Include="Provider\CommandLine\ConnCommandLineMessage.cs" />
<Compile Include="Provider\CommandLine\ConnCommandLinePackageProvider.cs" />
<Compile Include="Core\IConnPackageProvider.cs" />
<Compile Include="Provider\FixedBuffer\ConnFixedBufferInfo.cs" />
<Compile Include="Provider\FixedBuffer\ConnFixedBufferMessage.cs" />
<Compile Include="Provider\FixedBuffer\ConnFixedBufferPackageProvider.cs" />
<Compile Include="Provider\SingleJson\ConnSingleJsonInfo.cs" />
<Compile Include="Provider\SingleJson\ConnSingleJsonMessage.cs" />
<Compile Include="Provider\SingleJson\ConnSingleJsonPackageProvider.cs" />
<Compile Include="TCP\TcpConnection.cs" />
<Compile Include="TCP\TcpEndpointManager.cs" />
<Compile Include="TCP\TcpEndpointManagerExpand.cs" />
<Compile Include="Core\ConnThreadInfo.cs" />
<Compile Include="UDP\UdpConnection.cs" />
<Compile Include="UDP\UdpEndpointManager.cs" />
<Compile Include="UDP\UdpPackageInfo.cs" />
<Compile Include="UDP\UdpEndpointManagerExpand.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
......@@ -91,5 +109,6 @@
<Name>VIZ.Framework.Storage</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Core
{
/// <summary>
/// GPI设备管理器
/// </summary>
public static class GPIManager
{
/// <summary>
/// 设备个数
/// </summary>
public static int DevCount { get; private set; }
/// <summary>
/// 设备句柄
/// </summary>
public static IntPtr[] DevHandles { get; private set; } = new IntPtr[20];
/// <summary>
/// 初始化设备
/// </summary>
public static void Initialize()
{
DevCount = GPI_USB_DEVICE.USB_ScanDevice(DevHandles);
}
/// <summary>
/// 打开设备
/// </summary>
/// <param name="DevHandle">设备句柄</param>
/// <returns>执行结果 true:成功,false:失败</returns>
public static bool OpenDevice(IntPtr DevHandle)
{
bool state = GPI_USB_DEVICE.USB_OpenDevice(DevHandle);
if (!state)
{
Console.WriteLine("Open device error!" + DevHandle.ToString("X8"));
}
else
{
//初始化输入 IN0~IN3
GPI_USB2GPI_DEVICE.GPIO_SetInput(DevHandle, 0x03C0, 0);
}
return state;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Core
{
/// <summary>
/// GPI设备 USB到GPI设备驱动 返回值
/// </summary>
public static class GPI_USB2GPI_DEVICE_RESULT
{
/// <summary>
/// 函数执行成功
/// </summary>
public const Int32 GPIO_SUCCESS = 0;
/// <summary>
/// 适配器不支持该函数
/// </summary>
public const Int32 GPIO_ERR_NOT_SUPPORT = -1;
/// <summary>
/// USB写数据失败
/// </summary>
public const Int32 GPIO_ERR_USB_WRITE_FAIL = -2;
/// <summary>
/// USB读数据失败
/// </summary>
public const Int32 GPIO_ERR_USB_READ_FAIL = -3;
/// <summary>
/// 命令执行失败
/// </summary>
public const Int32 GPIO_ERR_CMD_FAIL = -4;
}
/// <summary>
/// GPI设备 USB到GPI设备驱动
/// </summary>
public static class GPI_USB2GPI_DEVICE
{
/// <summary>
/// 将GPIO引脚设置为输入模式
/// </summary>
/// <param name="DevHandle">设备句柄</param>
/// <param name="PinMask">需要设置为输入模式的引脚,每个bit位代表一个引脚,对应bit位为1时改引脚对设置有效,最低位为P0</param>
/// <param name="PuPd">0-浮空输入,无上拉或者下拉,1-上拉输入,2-下拉输入</param>
/// <returns>函数执行状态,小于0函数执行出错<see cref="GPI_USB2GPI_DEVICE_RESULT"/></returns>
[DllImport("USB2XXX.dll")]
public static extern Int32 GPIO_SetInput(IntPtr DevHandle, UInt32 PinMask, Byte PuPd);
/// <summary>
/// 将GPIO引脚设置为输出模式
/// </summary>
/// <param name="DevHandle">设备句柄</param>
/// <param name="PinMask">需要设置为输入模式的引脚,每个bit位代表一个引脚,对应bit位为1时改引脚对设置有效,最低位为P0</param>
/// <param name="PuPd">0-浮空输入,无上拉或者下拉,1-上拉输入,2-下拉输入</param>
/// <returns>函数执行状态,小于0函数执行出错<see cref="GPI_USB2GPI_DEVICE_RESULT"/></returns>
[DllImport("USB2XXX.dll")]
public static extern Int32 GPIO_SetOutput(IntPtr DevHandle, UInt32 PinMask, Byte PuPd);
/// <summary>
/// 将GPIO引脚设置为开漏模式,该模式下可作为双向引脚
/// </summary>
/// <param name="DevHandle">设备句柄</param>
/// <param name="PinMask">需要设置为输入模式的引脚,每个bit位代表一个引脚,对应bit位为1时改引脚对设置有效,最低位为P0</param>
/// <param name="PuPd">0-浮空输入,无上拉或者下拉,1-上拉输入,2-下拉输入</param>
/// <returns>函数执行状态,小于0函数执行出错<see cref="GPI_USB2GPI_DEVICE_RESULT"/></returns>
[DllImport("USB2XXX.dll")]
public static extern Int32 GPIO_SetOpenDrain(IntPtr DevHandle, UInt32 PinMask, Byte PuPd);
/// <summary>
/// 设置GPIO引脚的输出状态
/// </summary>
/// <param name="DevHandle">设备句柄</param>
/// <param name="PinMask">需要设置为输入模式的引脚,每个bit位代表一个引脚,对应bit位为1时改引脚对设置有效,最低位为P0</param>
/// <param name="PinValue">对应引脚的状态,每个bit位代表一个引脚,对应bit位为1输出高电平,为0输出低电平,最低位对应P0</param>
/// <returns>函数执行状态,小于0函数执行出错<see cref="GPI_USB2GPI_DEVICE_RESULT"/></returns>
[DllImport("USB2XXX.dll")]
public static extern Int32 GPIO_Write(IntPtr DevHandle, UInt32 PinMask, UInt32 PinValue);
/// <summary>
/// 设置GPIO引脚的输出状态
/// </summary>
/// <param name="DevHandle">设备句柄</param>
/// <param name="PinMask">需要设置为输入模式的引脚,每个bit位代表一个引脚,对应bit位为1时改引脚对设置有效,最低位为P0</param>
/// <param name="pPinValue">对应引脚的状态,每个bit位代表一个引脚,对应bit位为1引脚为高电平,为0引脚为低电平,最低位对应P0</param>
/// <returns>函数执行状态,小于0函数执行出错<see cref="GPI_USB2GPI_DEVICE_RESULT"/></returns>
[DllImport("USB2XXX.dll")]
public static extern Int32 GPIO_Read(IntPtr DevHandle, UInt32 PinMask, ref UInt32 pPinValue);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Core
{
/// <summary>
/// GPI设备USB驱动 信息
/// </summary>
public struct GPI_USB_DEVICE_INFO
{
/// <summary>
/// 固件名称字符串
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public Byte[] FirmwareName;
/// <summary>
/// 固件编译时间字符串
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public Byte[] BuildDate;
/// <summary>
/// 硬件版本号
/// </summary>
public UInt32 HardwareVersion;
/// <summary>
/// 固件版本号
/// </summary>
public UInt32 FirmwareVersion;
/// <summary>
/// 适配器序列号
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public UInt32[] SerialNumber;
/// <summary>
/// 适配器当前具备的功能
/// </summary>
public UInt32 Functions;
}
/// <summary>
/// GPI设备USB驱动
/// </summary>
public static class GPI_USB_DEVICE
{
/// <summary>
/// 定义电压输出值 -- 不输出
/// </summary>
public const Byte POWER_LEVEL_NONE = 0;
/// <summary>
/// 定义电压输出值 -- 输出1.8V
/// </summary>
public const Byte POWER_LEVEL_1V8 = 1;
/// <summary>
/// 定义电压输出值 -- 输出2.5V
/// </summary>
public const Byte POWER_LEVEL_2V5 = 2;
/// <summary>
/// 定义电压输出值 -- 输出3.3V
/// </summary>
public const Byte POWER_LEVEL_3V3 = 3;
/// <summary>
/// 定义电压输出值 -- 输出5.0V
/// </summary>
public const Byte POWER_LEVEL_5V0 = 4;
/// <summary>
/// 初始化USB设备,并扫描设备连接数,必须调用
/// </summary>
/// <param name="pDevHandle">每个设备的设备号存储地址</param>
/// <returns>扫描到的设备数量</returns>
[DllImport("USB2XXX.dll")]
public static extern Int32 USB_ScanDevice(IntPtr[] pDevHandle);
/// <summary>
/// 打开设备,必须调用
/// </summary>
/// <param name="DevHandle">设备索引号</param>
/// <returns>打开设备的状态</returns>
[DllImport("USB2XXX.dll")]
public static extern bool USB_OpenDevice(IntPtr DevHandle);
/// <summary>
/// 关闭设备,必须调用
/// </summary>
/// <param name="DevHandle">设备索引号</param>
/// <returns>打开设备的状态</returns>
[DllImport("USB2XXX.dll")]
public static extern bool USB_CloseDevice(IntPtr DevHandle);
/// <summary>
/// 复位设备程序,复位后需要重新调用USB_ScanDevice,USB_OpenDevice函数
/// </summary>
/// <param name="DevHandle">设备索引号</param>
/// <returns>复位设备的状态</returns>
[DllImport("USB2XXX.dll")]
public static extern bool USB_ResetDevice(IntPtr DevHandle);
/// <summary>
/// 获取设备信息,比如设备名称,固件版本号,设备序号,设备功能说明字符串等
/// </summary>
/// <param name="DevHandle">设备索引号</param>
/// <param name="pDevInfo">设备信息存储结构体指针</param>
/// <param name="pFunctionStr">设备功能说明字符串</param>
/// <returns>获取设备信息的状态</returns>
[DllImport("USB2XXX.dll")]
public static extern bool DEV_GetDeviceInfo(IntPtr DevHandle, ref GPI_USB_DEVICE_INFO pDevInfo, StringBuilder pFunctionStr);
/// <summary>
/// 设置可变电压输出引脚输出电压值
/// </summary>
/// <param name="DevHandle">设备索引号</param>
/// <param name="PowerLevel">输出电压值</param>
/// <returns>设置输出电压状态</returns>
[DllImport("USB2XXX.dll")]
public static extern bool DEV_SetPowerLevel(IntPtr DevHandle, byte PowerLevel);
}
}
......@@ -87,57 +87,60 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Converter\Bool2BoolConverter.cs" />
<Compile Include="Converter\ByteSizeConverter.cs" />
<Compile Include="Enum\EnumHelper.cs" />
<Compile Include="Image\ImageHelperExpand.cs" />
<Compile Include="Image\ImageHelper.cs" />
<Compile Include="Converter\Bitmap2ImageSourceConverter.cs" />
<Compile Include="Converter\Bool2VisibilityConverter.cs" />
<Compile Include="Converter\Double2TimeSpanConverter.cs" />
<Compile Include="Converter\TimeSpan2DoubleConverter.cs" />
<Compile Include="Delay\IDelayManager.cs" />
<Compile Include="Delay\DelayInfo.cs" />
<Compile Include="Delay\DelayManager.cs" />
<Compile Include="Loop\ILoopManager.cs" />
<Compile Include="Loop\LoopInfo.cs" />
<Compile Include="Loop\LoopManager.cs" />
<Compile Include="Loop\LoopThreadInfo.cs" />
<Compile Include="Math\MathHelper.cs" />
<Compile Include="Message\IMessageInfo.cs" />
<Compile Include="Message\IMessageManager.cs" />
<Compile Include="Message\MessageInfo.cs" />
<Compile Include="Message\MessageManager.cs" />
<Compile Include="Monitor\IMonitorManager.cs" />
<Compile Include="Monitor\IMonitorProvider.cs" />
<Compile Include="Monitor\IMonitorTrigger.cs" />
<Compile Include="Monitor\MonitorManager.cs" />
<Compile Include="Monitor\MonitorInfolBase.cs" />
<Compile Include="Monitor\MonitorTaskBase.cs" />
<Compile Include="Monitor\MonitorTaskInfo.cs" />
<Compile Include="Monitor\System\Info\SystemMonitorGpuInfo.cs" />
<Compile Include="Monitor\System\Provider\SystemMonitorProvider_GPU.cs" />
<Compile Include="Monitor\System\Provider\SystemMonitorProvider_CPU.cs" />
<Compile Include="Monitor\System\Provider\SystemMonitorProvider_Memory.cs" />
<Compile Include="Monitor\System\Info\SystemMonitorInfo.cs" />
<Compile Include="Monitor\System\SystemMonitorTask.cs" />
<Compile Include="Net\NetHelper.cs" />
<Compile Include="Core\Converter\Bool2BoolConverter.cs" />
<Compile Include="Core\Converter\ByteSizeConverter.cs" />
<Compile Include="Core\Enum\EnumHelper.cs" />
<Compile Include="Expand\GPI\GPIManager.cs" />
<Compile Include="Expand\GPI\GPI_USB2GPI_DEVICE.cs" />
<Compile Include="Expand\GPI\GPI_USB_DEVICE.cs" />
<Compile Include="Core\Image\ImageHelperExpand.cs" />
<Compile Include="Core\Image\ImageHelper.cs" />
<Compile Include="Core\Converter\Bitmap2ImageSourceConverter.cs" />
<Compile Include="Core\Converter\Bool2VisibilityConverter.cs" />
<Compile Include="Core\Converter\Double2TimeSpanConverter.cs" />
<Compile Include="Core\Converter\TimeSpan2DoubleConverter.cs" />
<Compile Include="Core\Delay\IDelayManager.cs" />
<Compile Include="Core\Delay\DelayInfo.cs" />
<Compile Include="Core\Delay\DelayManager.cs" />
<Compile Include="Core\Loop\ILoopManager.cs" />
<Compile Include="Core\Loop\LoopInfo.cs" />
<Compile Include="Core\Loop\LoopManager.cs" />
<Compile Include="Core\Loop\LoopThreadInfo.cs" />
<Compile Include="Core\Math\MathHelper.cs" />
<Compile Include="Core\Message\IMessageInfo.cs" />
<Compile Include="Core\Message\IMessageManager.cs" />
<Compile Include="Core\Message\MessageInfo.cs" />
<Compile Include="Core\Message\MessageManager.cs" />
<Compile Include="Expand\Monitor\IMonitorManager.cs" />
<Compile Include="Expand\Monitor\IMonitorProvider.cs" />
<Compile Include="Expand\Monitor\IMonitorTrigger.cs" />
<Compile Include="Expand\Monitor\MonitorManager.cs" />
<Compile Include="Expand\Monitor\MonitorInfolBase.cs" />
<Compile Include="Expand\Monitor\MonitorTaskBase.cs" />
<Compile Include="Expand\Monitor\MonitorTaskInfo.cs" />
<Compile Include="Expand\Monitor\System\Info\SystemMonitorGpuInfo.cs" />
<Compile Include="Expand\Monitor\System\Provider\SystemMonitorProvider_GPU.cs" />
<Compile Include="Expand\Monitor\System\Provider\SystemMonitorProvider_CPU.cs" />
<Compile Include="Expand\Monitor\System\Provider\SystemMonitorProvider_Memory.cs" />
<Compile Include="Expand\Monitor\System\Info\SystemMonitorInfo.cs" />
<Compile Include="Expand\Monitor\System\SystemMonitorTask.cs" />
<Compile Include="Core\Net\NetHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SharpDx\RawRectangleFExpand.cs" />
<Compile Include="SharpDx\SharpDxColorHelper.cs" />
<Compile Include="ThreeDMouse\Navigation3DCamera.cs" />
<Compile Include="ThreeDMouse\Navigation3DManager.cs" />
<Compile Include="ThreeDMouse\Navigation3DModel.cs" />
<Compile Include="ThreeDMouse\Navigation3DModel.INavigation.cs" />
<Compile Include="ThreeDMouse\Navigation3DSmooth.cs" />
<Compile Include="Winform\WinformHelper.cs" />
<Compile Include="WPF\IService.cs" />
<Compile Include="WPF\IServiceManager.cs" />
<Compile Include="WPF\ModelBase.cs" />
<Compile Include="WPF\VCommand.cs" />
<Compile Include="WPF\ViewModelBase.cs" />
<Compile Include="WPF\ServiceManager.cs" />
<Compile Include="WPF\WPFHelper.cs" />
<Compile Include="Expand\SharpDx\RawRectangleFExpand.cs" />
<Compile Include="Expand\SharpDx\SharpDxColorHelper.cs" />
<Compile Include="Expand\ThreeDMouse\Navigation3DCamera.cs" />
<Compile Include="Expand\ThreeDMouse\Navigation3DManager.cs" />
<Compile Include="Expand\ThreeDMouse\Navigation3DModel.cs" />
<Compile Include="Expand\ThreeDMouse\Navigation3DModel.INavigation.cs" />
<Compile Include="Expand\ThreeDMouse\Navigation3DSmooth.cs" />
<Compile Include="Core\Winform\WinformHelper.cs" />
<Compile Include="Core\WPF\IService.cs" />
<Compile Include="Core\WPF\IServiceManager.cs" />
<Compile Include="Core\WPF\ModelBase.cs" />
<Compile Include="Core\WPF\VCommand.cs" />
<Compile Include="Core\WPF\ViewModelBase.cs" />
<Compile Include="Core\WPF\ServiceManager.cs" />
<Compile Include="Core\WPF\WPFHelper.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
......
......@@ -60,13 +60,13 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ApplicationDomain.cs" />
<Compile Include="Message\UDP\UdpConsoleMessage.cs" />
<Compile Include="Model\Monitor\System\SystemMonitorGpuModel.cs" />
<Compile Include="Model\Monitor\System\SystemMonitorModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Initialize\" />
<Folder Include="Message\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VIZ.Framework.Core\VIZ.Framework.Core.csproj">
......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
\ No newline at end of file
<Application x:Class="VIZ.Framework.UDPTestTool.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:VIZ.Framework.UDPTestTool"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace VIZ.Framework.UDPTestTool
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
using VIZ.Framework.Domain;
namespace VIZ.Framework.UDPTestTool
{
/// <summary>
/// 应用程序域
/// </summary>
public class ApplicationDomainEx : ApplicationDomain
{
protected ApplicationDomainEx() { }
/// <summary>
/// Excel数据上下文
/// </summary>
public static ExcelContext ExcelContext { get; private set; } = new ExcelContext();
}
}
<Window x:Class="VIZ.Framework.UDPTestTool.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VIZ.Framework.UDPTestTool"
mc:Ignorable="d"
Title="UDP调试工具" Height="900" Width="1200">
<Grid>
<local:MainView Margin="20"></local:MainView>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace VIZ.Framework.UDPTestTool
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("VIZ.Framework.UDPTestTool")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VIZ.Framework.UDPTestTool")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
//若要开始生成可本地化的应用程序,请设置
//.csproj 文件中的 <UICulture>CultureYouAreCodingWith</UICulture>
//例如,如果您在源文件中使用的是美国英语,
//使用的是美国英语,请将 <UICulture> 设置为 en-US。 然后取消
//对以下 NeutralResourceLanguage 特性的注释。 更新
//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //主题特定资源词典所处位置
//(未在页面中找到资源时使用,
//或应用程序资源字典中找到时使用)
ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
//(未在页面中找到资源时使用,
//、应用程序或任何主题专用资源字典中找到时使用)
)]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本: 4.0.30319.42000
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace VIZ.Framework.UDPTestTool.Properties
{
/// <summary>
/// 强类型资源类,用于查找本地化字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// 返回此类使用的缓存 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("VIZ.Framework.UDPTestTool.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性,对
/// 使用此强类型资源类的所有资源查找执行重写。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace VIZ.Framework.UDPTestTool.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using VIZ.Framework.Module;
using log4net;
namespace VIZ.Framework.UDPTestTool
{
/// <summary>
/// 应用程序启动 -- 初始化Excel
/// </summary>
public class AppSetup_InitExcel : AppSetupBase
{
/// <summary>
/// 日志
/// </summary>
private static ILog log = LogManager.GetLogger(typeof(AppSetup_InitExcel));
/// <summary>
/// 描述
/// </summary>
public override string Detail { get; } = "应用程序启动 -- 初始化Excel";
/// <summary>
/// 执行启动
/// </summary>
/// <param name="context">应用程序启动上下文</param>
/// <returns>是否成功执行</returns>
public override bool Setup(AppSetupContext context)
{
string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config", "udp_info.xls");
ApplicationDomainEx.ExcelContext.LoadUdpSignalInfos(path);
return true;
}
/// <summary>
/// 执行关闭
/// </summary>
/// <param name="context">应用程序启动上下文</param>
public override void Shutdown(AppSetupContext context)
{
}
}
}
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.UDPTestTool
{
/// <summary>
/// Excel 数据上下文
/// </summary>
public class ExcelContext
{
/// <summary>
/// UDP信号信息
/// </summary>
public List<UdpSignalInfo> UdpSignalInfos { get; private set; }
/// <summary>
/// 加载UDP信号信息
/// </summary>
/// <param name="path">文件路径</param>
public void LoadUdpSignalInfos(string path)
{
List<UdpSignalInfo> result = new List<UdpSignalInfo>();
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
{
IWorkbook workbook = new HSSFWorkbook(fs);
ISheet sheet = workbook.GetSheet("Sheet1");
for (int i = 1; i <= sheet.LastRowNum; i++)
{
IRow row = sheet.GetRow(i);
UdpSignalInfo item = new UdpSignalInfo();
item.Label = row.GetCell(0)?.StringCellValue;
item.Json = row.GetCell(1)?.StringCellValue;
result.Add(item);
}
}
this.UdpSignalInfos = result;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
namespace VIZ.Framework.UDPTestTool
{
/// <summary>
/// UDP信号信息
/// </summary>
public class UdpSignalInfo : ModelBase
{
#region Label -- 标签
private string label;
/// <summary>
/// 标签
/// </summary>
public string Label
{
get { return label; }
set { label = value; this.RaisePropertyChanged(nameof(Label)); }
}
#endregion
#region Json -- Json字符串
private string json;
/// <summary>
/// Json字符串
/// </summary>
public string Json
{
get { return json; }
set { json = value; this.RaisePropertyChanged(nameof(Json)); }
}
#endregion
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6DDCBD19-6E92-4363-A509-9820562FC048}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>VIZ.Framework.UDPTestTool</RootNamespace>
<AssemblyName>VIZ.Framework.UDPTestTool</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.8.9.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
<HintPath>..\packages\Portable.BouncyCastle.1.8.9\lib\net40\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.SharpZipLib, Version=1.3.3.11, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<HintPath>..\packages\SharpZipLib.1.3.3\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.14.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.14\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="NPOI, Version=2.5.6.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<HintPath>..\packages\NPOI.2.5.6\lib\net45\NPOI.dll</HintPath>
</Reference>
<Reference Include="NPOI.OOXML, Version=2.5.6.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<HintPath>..\packages\NPOI.2.5.6\lib\net45\NPOI.OOXML.dll</HintPath>
</Reference>
<Reference Include="NPOI.OpenXml4Net, Version=2.5.6.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<HintPath>..\packages\NPOI.2.5.6\lib\net45\NPOI.OpenXml4Net.dll</HintPath>
</Reference>
<Reference Include="NPOI.OpenXmlFormats, Version=2.5.6.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<HintPath>..\packages\NPOI.2.5.6\lib\net45\NPOI.OpenXmlFormats.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Domain\ApplicationDomainEx.cs" />
<Compile Include="Setup\AppSetup_InitExcel.cs" />
<Compile Include="Storage\Excel\ExcelContext.cs" />
<Compile Include="Storage\Excel\UdpSignalInfo.cs" />
<Compile Include="ViewModel\MainViewModel.cs" />
<Compile Include="View\MainView.xaml.cs">
<DependentUpon>MainView.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="View\MainView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="config\config.ini" />
<None Include="config\log.config" />
<None Include="config\udp_info.xls" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VIZ.Framework.Common.Resource\VIZ.Framework.Common.Resource.csproj">
<Project>{76ef480a-e486-41b7-b7a5-2a849fc8d5bf}</Project>
<Name>VIZ.Framework.Common.Resource</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.Framework.Connection\VIZ.Framework.Connection.csproj">
<Project>{e07528dd-9dee-47c2-b79d-235ecfa6b003}</Project>
<Name>VIZ.Framework.Connection</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.Framework.Core\VIZ.Framework.Core.csproj">
<Project>{75b39591-4bc3-4b09-bd7d-ec9f67efa96e}</Project>
<Name>VIZ.Framework.Core</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.Framework.Domain\VIZ.Framework.Domain.csproj">
<Project>{28661e82-c86a-4611-a028-c34f6ac85c97}</Project>
<Name>VIZ.Framework.Domain</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.Framework.Module\VIZ.Framework.Module.csproj">
<Project>{47cf6fb0-e37d-4ef1-afc7-03db2bca8892}</Project>
<Name>VIZ.Framework.Module</Name>
</ProjectReference>
<ProjectReference Include="..\VIZ.Framework.Storage\VIZ.Framework.Storage.csproj">
<Project>{06b80c09-343d-4bb2-aeb1-61cfbfbf5cad}</Project>
<Name>VIZ.Framework.Storage</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Model\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
<UserControl x:Class="VIZ.Framework.UDPTestTool.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:VIZ.Framework.UDPTestTool"
d:DataContext="{d:DesignInstance Type=local:MainViewModel}"
x:Name="uc" Background="White"
mc:Ignorable="d"
d:DesignHeight="800" d:DesignWidth="1000">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/VIZ.Framework.Common.Resource;component/Style/TextBox/TextBox_None.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"></RowDefinition>
<RowDefinition Height="105"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="300"></RowDefinition>
</Grid.RowDefinitions>
<!-- 启动参数 -->
<GroupBox Padding="10">
<GroupBox.Header>
<TextBlock Text="信息" FontSize="16" Foreground="#aa000000"></TextBlock>
</GroupBox.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="启动参数:" FontSize="14" VerticalAlignment="Top" Foreground="#bb000000"></TextBlock>
<TextBox Grid.Column="1" AcceptsReturn="True" TextWrapping="Wrap" FontSize="14" IsReadOnly="True" Style="{StaticResource TextBox_None}"
Text="123123123"></TextBox>
</Grid>
</GroupBox>
<!-- 设置 -->
<GroupBox Padding="10" Grid.Row="1">
<GroupBox.Header>
<TextBlock Text="UDP设置" FontSize="16" Foreground="#aa000000"></TextBlock>
</GroupBox.Header>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="110"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="80"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="110"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!-- 监听IP -->
<TextBlock Text="监听IP:" Grid.Row="0" VerticalAlignment="Center" FontSize="14" Foreground="#bb000000"></TextBlock>
<TextBox Grid.Column="1" Height="24" VerticalContentAlignment="Center" FontSize="14"
ToolTip="监听IP"></TextBox>
<CheckBox Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center"
VerticalContentAlignment="Center" Content="采用启动参数" Foreground="#bb000000"></CheckBox>
<TextBox Grid.Column="3" Height="24" VerticalContentAlignment="Center"
ToolTip="启动参数名" Margin="0,0,10,0"></TextBox>
<!-- 监听端口 -->
<TextBlock Text="监听端口:" Grid.Row="1" VerticalAlignment="Center" FontSize="14" Foreground="#bb000000"></TextBlock>
<TextBox Grid.Row="1" Grid.Column="1" Height="24" VerticalContentAlignment="Center"></TextBox>
<CheckBox Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center"
VerticalContentAlignment="Center" Content="采用启动参数" Foreground="#bb000000"></CheckBox>
<TextBox Grid.Row="1" Grid.Column="3" Height="24" VerticalContentAlignment="Center"
ToolTip="启动参数名" Margin="0,0,10,0"></TextBox>
<!-- 发送IP -->
<TextBlock Text="发送IP:" Grid.Row="0" VerticalAlignment="Center" FontSize="14" Grid.Column="4" Foreground="#bb000000"></TextBlock>
<TextBox Grid.Row="0" Grid.Column="5" Height="24" VerticalContentAlignment="Center"></TextBox>
<CheckBox Grid.Row="0" Grid.Column="6" VerticalAlignment="Center" HorizontalAlignment="Center"
VerticalContentAlignment="Center" Content="采用启动参数" Foreground="#bb000000"></CheckBox>
<TextBox Grid.Row="0" Grid.Column="7" Height="24" VerticalContentAlignment="Center"
ToolTip="启动参数名" Margin="0,0,10,0"></TextBox>
<!-- 发送端口 -->
<TextBlock Text="发送端口:" Grid.Row="1" VerticalAlignment="Center" FontSize="14" Grid.Column="4" Foreground="#bb000000"></TextBlock>
<TextBox Grid.Row="1" Grid.Column="5" Height="24" VerticalContentAlignment="Center"></TextBox>
<CheckBox Grid.Row="1" Grid.Column="6" VerticalAlignment="Center" HorizontalAlignment="Center"
VerticalContentAlignment="Center" Content="采用启动参数" Foreground="#bb000000"></CheckBox>
<TextBox Grid.Row="1" Grid.Column="7" Height="24" VerticalContentAlignment="Center"
ToolTip="启动参数名" Margin="0,0,10,0"></TextBox>
</Grid>
</GroupBox>
<!-- 发送预设 -->
<GroupBox Padding="10" Grid.Row="2">
<GroupBox.Header>
<TextBlock Text="发送预设" FontSize="16" Foreground="#aa000000"></TextBlock>
</GroupBox.Header>
</GroupBox>
<!-- 日志输出 -->
<GroupBox Padding="10" Grid.Row="3">
<GroupBox.Header>
<TextBlock Text="日志" FontSize="16" Foreground="#aa000000"></TextBlock>
</GroupBox.Header>
<TextBox x:Name="tbLog" Grid.Row="3" Grid.ColumnSpan="2" AcceptsReturn="True" TextWrapping="Wrap" IsReadOnly="True" VerticalScrollBarVisibility="Visible"
FontSize="14" Text="123123123123"></TextBox>
</GroupBox>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace VIZ.Framework.UDPTestTool
{
/// <summary>
/// MainView.xaml 的交互逻辑
/// </summary>
public partial class MainView : UserControl
{
public MainView()
{
InitializeComponent();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
namespace VIZ.Framework.UDPTestTool
{
/// <summary>
/// 主视图模型
/// </summary>
public class MainViewModel : ViewModelBase
{
}
}
; ============================================================
; === Application ===
; ============================================================
[Application]
;是否是调试模式
APPLICATION_IS_DEBUG=true
; ============================================================
; === UDP ===
; ============================================================
[UDP]
;UDP本机绑定IP
UDP_BINDING_IP=127.0.0.1
;UDP本机绑定端口
UDP_BINDING_PORT=8101
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="errorAppender" type="log4net.Appender.RollingFileAppender">
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="ERROR" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
<file value="Logs\err.log" />
<encoding value="utf-8"/>
<preserveLogFileNameExtension value="true" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<appender name="infoAppender" type="log4net.Appender.RollingFileAppender">
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="INFO" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
<file value="Logs\info.log" />
<encoding value="utf-8"/>
<preserveLogFileNameExtension value="true" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<appender name="debugAppender" type="log4net.Appender.RollingFileAppender">
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="DEBUG" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
<file value="Logs\debug.log" />
<encoding value="utf-8"/>
<preserveLogFileNameExtension value="true" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<appender name="perfAppender" type="log4net.Appender.RollingFileAppender">
<filter type="log4net.Filter.LevelMatchFilter">
<levelToMatch value="INFO" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
<file value="Logs\perf.log" />
<encoding value="utf-8"/>
<preserveLogFileNameExtension value="true" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="errorAppender" />
<appender-ref ref="infoAppender" />
<appender-ref ref="debugAppender" />
</root>
<logger name="Performance" additivity="false">
<level value="ALL" />
<appender-ref ref="perfAppender" />
</logger>
</log4net>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment