修改了一些样式表加了个网络传输函数
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using Microsoft.VisualBasic;
|
||||
using MongoDB.Driver;
|
||||
using MongoDB.Driver.Core.Servers;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using System;
|
||||
@@ -6,6 +8,8 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -49,6 +53,21 @@ namespace Ramitta.lib
|
||||
Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { }));
|
||||
});
|
||||
}
|
||||
public static SolidColorBrush GenerateRandomColor(SolidColorBrush color = null)
|
||||
{
|
||||
// 如果 color 参数为 null,生成一个新的随机颜色
|
||||
if (color == null)
|
||||
{
|
||||
Random random = new Random();
|
||||
byte r = (byte)random.Next(0, 256); // 红色分量 0 - 255
|
||||
byte g = (byte)random.Next(0, 256); // 绿色分量 0 - 255
|
||||
byte b = (byte)random.Next(0, 256); // 蓝色分量 0 - 255
|
||||
|
||||
color = new SolidColorBrush(Color.FromRgb(r, g, b));
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
// 定义自定义异常类
|
||||
public class DebugbarException : Exception
|
||||
@@ -123,7 +142,14 @@ namespace Ramitta.lib
|
||||
}
|
||||
public static string FileRead(string outputPath)
|
||||
{
|
||||
return File.ReadAllText(outputPath);
|
||||
try
|
||||
{
|
||||
return File.ReadAllText(outputPath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取路径下所有文件和文件夹,支持传入判断文件的函数
|
||||
@@ -279,6 +305,43 @@ namespace Ramitta.lib
|
||||
}
|
||||
#endregion
|
||||
|
||||
// 通过 UDP 发送消息
|
||||
public static void SendUdpMessage(string _serverIp, int _serverPort,string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (UdpClient udpClient = new UdpClient())
|
||||
{
|
||||
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(_serverIp), _serverPort);
|
||||
byte[] messageBytes = Encoding.UTF8.GetBytes(message);
|
||||
udpClient.Send(messageBytes, messageBytes.Length, endPoint);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"发送 UDP 消息失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 通过 TCP 发送消息
|
||||
public static void SendTcpMessage(string _serverIp, int _serverPort, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (TcpClient tcpClient = new TcpClient(_serverIp, _serverPort))
|
||||
using (NetworkStream networkStream = tcpClient.GetStream())
|
||||
{
|
||||
byte[] messageBytes = Encoding.UTF8.GetBytes(message);
|
||||
networkStream.Write(messageBytes, 0, messageBytes.Length);
|
||||
networkStream.Flush();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"发送 TCP 消息失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 生成哈希
|
||||
public static string GenerateHash(string input)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user