2017-02-22 14:30:10 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Windows.Forms;
|
2017-04-23 18:05:12 +08:00
|
|
|
|
using HslCommunication.Enthernet;
|
2017-02-22 14:30:10 +08:00
|
|
|
|
using System.Threading;
|
|
|
|
|
|
using CommonLibrary;
|
2017-04-06 16:18:46 +08:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
2017-05-04 11:43:50 +08:00
|
|
|
|
using HslCommunication.BasicFramework;
|
2017-06-28 21:59:46 +08:00
|
|
|
|
using System.Diagnostics;
|
2017-09-02 22:35:02 +08:00
|
|
|
|
using HslCommunication.LogNet;
|
2017-09-19 22:16:44 +08:00
|
|
|
|
using HslCommunication;
|
2017-10-16 21:22:34 +08:00
|
|
|
|
using 软件系统服务端模版.BasicSupport;
|
2017-02-22 14:30:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
/********************************************************************************************
|
2017-05-30 16:33:14 +08:00
|
|
|
|
*
|
2017-10-06 13:30:28 +08:00
|
|
|
|
* 模版日期 2017-10-06
|
2017-10-01 15:59:37 +08:00
|
|
|
|
* 创建人 Richard.Hu
|
|
|
|
|
|
* 版权所有 Richard.Hu
|
|
|
|
|
|
* 授权说明 模版仅授权个人研究学习使用,如需商用,请联系hsl200909@163.com洽谈
|
|
|
|
|
|
* 说明 JSON组件引用自james newton-king,遵循MIT授权协议
|
|
|
|
|
|
* 网络组件 网络组件的版权由Richard.Hu所有
|
2017-10-06 13:30:28 +08:00
|
|
|
|
* 免责声明 项目许可证为MIT,由于二次开发带来的经济损失,概不负责。
|
2017-05-30 16:33:14 +08:00
|
|
|
|
*
|
|
|
|
|
|
********************************************************************************************/
|
2017-02-22 14:30:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
/********************************************************************************************
|
2017-05-30 16:33:14 +08:00
|
|
|
|
*
|
|
|
|
|
|
* 注意:本代码的相关操作未作密码验证,如有需要,请自行完成
|
|
|
|
|
|
* 示例:具体示例参照本页面Form1_FormClosing(object sender, FormClosingEventArgs e)方法
|
2017-06-16 10:56:21 +08:00
|
|
|
|
* 账号:默认一个超级管理员账号:admin 密码123456
|
2017-05-30 16:33:14 +08:00
|
|
|
|
*
|
|
|
|
|
|
********************************************************************************************/
|
2017-02-22 14:30:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
/********************************************************************************************
|
2017-05-30 16:33:14 +08:00
|
|
|
|
*
|
|
|
|
|
|
* 本项目模版不包含 《软件自动更新.exe》
|
|
|
|
|
|
* 如需支持部署环境的自动升级 请联系hsl200909@163.com获取
|
|
|
|
|
|
* 软件自动更新.exe 将绑定IP,端口和软件名称后授权销售,30元人民币一组,永久使用
|
2017-10-06 13:30:28 +08:00
|
|
|
|
* 软件自动更新的部署提供长期的技术支持
|
2017-05-30 16:33:14 +08:00
|
|
|
|
*
|
|
|
|
|
|
********************************************************************************************/
|
2017-02-22 14:30:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
/********************************************************************************************
|
2017-06-29 11:01:14 +08:00
|
|
|
|
*
|
|
|
|
|
|
* 关于邮件系统:如果你服务器端的程序部署在可上网的计算机上时,可以使用
|
|
|
|
|
|
* 先进行邮件系统的初始化,指定接收邮件的地址
|
|
|
|
|
|
* 如果需要使用,请参照下面的邮件功能块说明
|
|
|
|
|
|
*
|
|
|
|
|
|
********************************************************************************************/
|
|
|
|
|
|
|
2017-02-22 14:30:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace 软件系统服务端模版
|
|
|
|
|
|
{
|
2017-06-16 16:22:12 +08:00
|
|
|
|
public partial class FormServerWindow : Form
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-09-17 21:59:45 +08:00
|
|
|
|
#region Constructor
|
|
|
|
|
|
|
2017-06-16 16:22:12 +08:00
|
|
|
|
public FormServerWindow()
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2017-06-17 23:32:02 +08:00
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
|
2017-06-29 11:01:14 +08:00
|
|
|
|
//捕获所有未处理的异常并进行预处理
|
2017-06-29 08:10:53 +08:00
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
|
|
|
|
|
|
2017-06-17 23:32:02 +08:00
|
|
|
|
//检测日志路径是否存储
|
|
|
|
|
|
LogSavePath = Application.StartupPath + @"\Logs";
|
2017-06-29 11:01:14 +08:00
|
|
|
|
if (!System.IO.Directory.Exists(LogSavePath))
|
2017-06-17 23:32:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
System.IO.Directory.CreateDirectory(LogSavePath);
|
|
|
|
|
|
}
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-17 21:59:45 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
#region Load Show Close
|
2017-02-22 14:30:10 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 指示窗口是否处于显示中
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private bool IsWindowShow { get; set; } = false;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 指示系统是否启动
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private bool IsSystemStart { get; set; } = false;
|
|
|
|
|
|
|
2017-06-17 23:32:02 +08:00
|
|
|
|
private string LogSavePath { get; set; }
|
|
|
|
|
|
|
2017-02-22 14:30:10 +08:00
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2017-10-06 13:30:28 +08:00
|
|
|
|
// 初始化默认的委托对象
|
2017-06-28 22:27:53 +08:00
|
|
|
|
ActionInitialization();
|
2017-10-06 13:30:28 +08:00
|
|
|
|
// 邮件系统初始化
|
2017-06-29 11:01:14 +08:00
|
|
|
|
SoftMailInitialization();
|
2017-10-06 13:30:28 +08:00
|
|
|
|
// 初始化日志工具
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper = new LogNetSingle(LogSavePath + @"\log.txt");
|
2017-10-06 13:30:28 +08:00
|
|
|
|
// 初始化反馈信息工具
|
2017-09-02 22:35:02 +08:00
|
|
|
|
AdviceLogHelper = new LogNetSingle(LogSavePath + @"\advice_log.txt");
|
2017-10-06 13:30:28 +08:00
|
|
|
|
// 初始化客户端异常日志工具
|
2017-09-02 22:35:02 +08:00
|
|
|
|
ClientsLogHelper = new LogNetSingle(LogSavePath + @"\clients_log.txt");
|
2017-10-06 13:30:28 +08:00
|
|
|
|
// 初始化并加载账户信息
|
2017-02-22 14:30:10 +08:00
|
|
|
|
UserServer.ServerSettings.FileSavePath = Application.StartupPath + @"\settings.txt";
|
|
|
|
|
|
UserServer.ServerSettings.LoadByFile();
|
2017-10-06 13:30:28 +08:00
|
|
|
|
|
|
|
|
|
|
// 初始化并加载角色规则
|
|
|
|
|
|
UserServer.ServerRoles.FileSavePath = Application.StartupPath + @"\roles.txt";
|
|
|
|
|
|
UserServer.ServerRoles.LoadByFile();
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化版权信息
|
2017-02-22 14:30:10 +08:00
|
|
|
|
toolStripStatusLabel_version.Text = UserServer.ServerSettings.SystemVersion.ToString();
|
2017-09-19 22:16:44 +08:00
|
|
|
|
toolStripStatusLabel1.Text = $"本软件著作权归{SoftResources.StringResouce.SoftCopyRight}所有";
|
|
|
|
|
|
label5.Text = SoftResources.StringResouce.SoftName;
|
2017-10-06 13:30:28 +08:00
|
|
|
|
// 加载账户信息
|
2017-03-06 21:10:38 +08:00
|
|
|
|
UserServer.ServerAccounts.FileSavePath = Application.StartupPath + @"\accounts.txt";
|
2017-02-22 14:30:10 +08:00
|
|
|
|
UserServer.ServerAccounts.LoadByFile();
|
2017-09-02 22:35:02 +08:00
|
|
|
|
UserServer.ServerAccounts.ILogNet = RuntimeLogHelper;
|
2017-10-06 13:30:28 +08:00
|
|
|
|
// 初始化聊天信息
|
2017-06-20 11:26:40 +08:00
|
|
|
|
ChatInitialization();
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
|
|
{
|
2017-10-06 13:30:28 +08:00
|
|
|
|
// 密码验证的示例,此处关闭窗口验证
|
2017-05-04 15:27:14 +08:00
|
|
|
|
using (FormPasswordCheck fpc = new FormPasswordCheck("123456"))
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-05-04 15:27:14 +08:00
|
|
|
|
if (fpc.ShowDialog() == DialogResult.OK)
|
|
|
|
|
|
{
|
|
|
|
|
|
IsWindowShow = false;
|
|
|
|
|
|
Thread.Sleep(20);
|
2017-10-06 13:30:28 +08:00
|
|
|
|
// 关闭网络引擎
|
2017-05-05 23:07:44 +08:00
|
|
|
|
net_socket_server.ServerClose();
|
2017-05-06 12:54:57 +08:00
|
|
|
|
net_simplify_server.ServerClose();
|
2017-06-07 16:59:17 +08:00
|
|
|
|
net_udp_server.ServerClose();
|
2017-05-04 15:27:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-10-06 13:30:28 +08:00
|
|
|
|
// 取消关闭
|
2017-05-04 15:27:14 +08:00
|
|
|
|
e.Cancel = true;
|
|
|
|
|
|
}
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
//紧急数据的保存已经放置到dispose方法中,即时发生BUG或直接关机,也能存储数据
|
|
|
|
|
|
}
|
|
|
|
|
|
private void Form1_Shown(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
IsWindowShow = true;
|
2017-03-06 21:10:38 +08:00
|
|
|
|
//维护初始化
|
2017-02-22 14:30:10 +08:00
|
|
|
|
MaintenanceInitialization();
|
2017-03-06 21:10:38 +08:00
|
|
|
|
//时间引擎初始化
|
|
|
|
|
|
TimeTickInitilization();
|
2017-02-22 14:30:10 +08:00
|
|
|
|
Refresh();
|
|
|
|
|
|
启动服务器ToolStripMenuItem.PerformClick();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
#region UI Message Add
|
|
|
|
|
|
|
2017-06-28 22:27:53 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 初始化委托
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void ActionInitialization()
|
|
|
|
|
|
{
|
|
|
|
|
|
ActionUserInterfaceMessageRender = new Action<string>(m =>
|
|
|
|
|
|
{
|
|
|
|
|
|
UserInterfaceMessageRender(m);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Action<string> ActionUserInterfaceMessageRender = null;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 往界面添加消息的方法,此方法是线程安全的,无论处于哪个线程都可以调用该方法
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="msg">新增的数据内容</param>
|
|
|
|
|
|
private void UserInterfaceMessageRender(string msg)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsWindowShow)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (textBox1.InvokeRequired)
|
|
|
|
|
|
{
|
|
|
|
|
|
textBox1.BeginInvoke(ActionUserInterfaceMessageRender, msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
textBox1.AppendText(msg + Environment.NewLine);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-06-29 08:10:53 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 一个处理服务器未处理异常的方法,对该方法进行记录,方便以后的分析
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
|
|
|
|
{
|
2017-06-29 11:01:14 +08:00
|
|
|
|
if (e.ExceptionObject is Exception ex)
|
2017-06-29 08:10:53 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteException("UnhandledException:", ex);
|
2017-06-29 11:01:14 +08:00
|
|
|
|
//发送到自己的EMAIL
|
|
|
|
|
|
SendUserMail(ex);
|
2017-06-29 08:10:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-06-28 22:27:53 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
#region Menu Click Event
|
2017-02-22 14:30:10 +08:00
|
|
|
|
private void 启动服务器ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!IsSystemStart)
|
|
|
|
|
|
{
|
2017-05-30 16:33:14 +08:00
|
|
|
|
Net_Simplify_Server_Initialization();//同步网络初始化
|
|
|
|
|
|
Net_Socket_Server_Initialization();//异步网络初始化
|
|
|
|
|
|
Net_SoftUpdate_Server_Initialization();//软件更新引擎初始化
|
2017-10-01 15:59:37 +08:00
|
|
|
|
Ultimate_File_Initiaization();//共享文件引擎初始化
|
2017-07-06 22:04:52 +08:00
|
|
|
|
Net_File_Portrait_Initialization();//头像文件管理服务
|
2017-06-07 16:20:40 +08:00
|
|
|
|
Net_Udp_Server_Initialization();//UDP引擎服务初始化
|
2017-02-22 14:30:10 +08:00
|
|
|
|
启动服务器ToolStripMenuItem.Text = "已启动";
|
|
|
|
|
|
启动服务器ToolStripMenuItem.BackColor = Color.LimeGreen;
|
|
|
|
|
|
IsSystemStart = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void 版本控制ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2017-05-04 15:27:14 +08:00
|
|
|
|
using (FormVersionControl fvc = new FormVersionControl(UserServer.ServerSettings))
|
|
|
|
|
|
{
|
|
|
|
|
|
fvc.ShowDialog();
|
|
|
|
|
|
toolStripStatusLabel_version.Text = UserServer.ServerSettings.SystemVersion.ToString();
|
|
|
|
|
|
}
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void 维护切换ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2017-05-04 15:27:14 +08:00
|
|
|
|
using (FormMaintenance fm = new FormMaintenance(UserServer.ServerSettings))
|
|
|
|
|
|
{
|
|
|
|
|
|
fm.ShowDialog();
|
|
|
|
|
|
MaintenanceInitialization();
|
|
|
|
|
|
}
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-03-06 21:10:38 +08:00
|
|
|
|
|
2017-02-22 14:30:10 +08:00
|
|
|
|
|
|
|
|
|
|
private void 消息发送ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2017-03-04 17:07:26 +08:00
|
|
|
|
//测试发送字节数据
|
|
|
|
|
|
//net_socket_server.SendAllClients(BitConverter.GetBytes(12345678));
|
2017-02-22 14:30:10 +08:00
|
|
|
|
//将消息群发给所有的客户端,并使用消息弹窗的方式显示
|
2017-05-04 15:27:14 +08:00
|
|
|
|
using (FormInputAndAction fiaa = new FormInputAndAction(
|
|
|
|
|
|
m =>
|
|
|
|
|
|
{
|
2017-06-29 11:01:14 +08:00
|
|
|
|
net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.弹窗新消息, m); return true;
|
2017-05-04 15:27:14 +08:00
|
|
|
|
}))
|
2017-03-04 17:07:26 +08:00
|
|
|
|
{
|
2017-05-04 15:27:14 +08:00
|
|
|
|
fiaa.ShowDialog();
|
|
|
|
|
|
}
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void 一键断开ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
//关闭信号发送至所有在线客户端
|
2017-06-16 09:52:58 +08:00
|
|
|
|
net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.关闭客户端, "");
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void 关于软件ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2017-05-04 15:27:14 +08:00
|
|
|
|
using (FormAbout fm = new FormAbout(
|
2017-10-06 19:28:44 +08:00
|
|
|
|
SoftResources.StringResouce.SoftName,
|
|
|
|
|
|
UserServer.ServerSettings.SystemVersion,
|
|
|
|
|
|
2017,
|
|
|
|
|
|
SoftResources.StringResouce.SoftCopyRight
|
|
|
|
|
|
))
|
2017-05-04 15:27:14 +08:00
|
|
|
|
{
|
|
|
|
|
|
fm.ShowDialog();
|
|
|
|
|
|
}
|
2017-05-20 09:41:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
private void 框架作者ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (FormAuthorAdvertisement faa = new FormAuthorAdvertisement())
|
|
|
|
|
|
{
|
|
|
|
|
|
faa.ShowDialog();
|
|
|
|
|
|
}
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
private void 账户管理ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
//该部分比较复杂,需要对委托,匿名委托概念比较清晰
|
2017-05-04 15:27:14 +08:00
|
|
|
|
using (FormAccountManage fam = new FormAccountManage(() => UserServer.ServerAccounts.GetAllAccountsJson(),
|
|
|
|
|
|
m => { UserServer.ServerAccounts.LoadAllAccountsJson(m); return true; }))
|
|
|
|
|
|
{
|
|
|
|
|
|
fam.ShowDialog();
|
|
|
|
|
|
}
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void 版本号说明ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2017-05-04 15:27:14 +08:00
|
|
|
|
using (FormAboutVersion fav = new FormAboutVersion(UserServer.ServerSettings.SystemVersion))
|
|
|
|
|
|
{
|
|
|
|
|
|
fav.ShowDialog();
|
|
|
|
|
|
}
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
private void MaintenanceInitialization()
|
|
|
|
|
|
{
|
|
|
|
|
|
//维护状态变更
|
|
|
|
|
|
if (UserServer.ServerSettings.Can_Account_Login)
|
|
|
|
|
|
{
|
|
|
|
|
|
label3.Text = "可登录";
|
|
|
|
|
|
label3.BackColor = Color.LimeGreen;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
label3.Text = "维护中";
|
|
|
|
|
|
label3.BackColor = Color.Tomato;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-02 18:48:35 +08:00
|
|
|
|
private void label_GC_Memery_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
//点击了性能组件
|
|
|
|
|
|
using (FormSuper fs = new FormSuper(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
return SoftCachePerfomance.GetIntArray();
|
|
|
|
|
|
}))
|
|
|
|
|
|
{
|
|
|
|
|
|
fs.ShowDialog();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-03 09:03:42 +08:00
|
|
|
|
private void 日志查看ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (FormLogNetView fln = new FormLogNetView())
|
|
|
|
|
|
{
|
|
|
|
|
|
fln.ShowDialog();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-22 14:30:10 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 软件更新服务引擎
|
2017-10-01 15:59:37 +08:00
|
|
|
|
|
2017-02-22 14:30:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 支持软件自动更新的后台服务引擎
|
|
|
|
|
|
/// </summary>
|
2017-09-02 22:35:02 +08:00
|
|
|
|
private NetSoftUpdateServer net_soft_update_Server = new NetSoftUpdateServer();
|
2017-02-22 14:30:10 +08:00
|
|
|
|
private void Net_SoftUpdate_Server_Initialization()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
net_soft_update_Server.LogNet = new LogNetSingle(LogSavePath + @"\update_log.txt");
|
2017-02-22 14:30:10 +08:00
|
|
|
|
//在服务器的这个路径下,放置客户端运行的所有文件,不要包含settings文件,不要从此处运行
|
|
|
|
|
|
//只放置exe和dll组件,必须放置:软件自动更新.exe
|
2017-10-15 16:04:28 +08:00
|
|
|
|
net_soft_update_Server.KeyToken = UserSystem.KeyToken;
|
2017-10-04 20:39:56 +08:00
|
|
|
|
net_soft_update_Server.FileUpdatePath = Application.StartupPath + @"\AdvancedFiles\ClientFiles";//客户端文件路径
|
2017-10-15 16:04:28 +08:00
|
|
|
|
net_soft_update_Server.ServerStart(UserSystem.Port_Update_Net);
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2017-05-04 11:43:50 +08:00
|
|
|
|
SoftBasic.ShowExceptionMessage(ex);
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 同步数据传送引擎
|
2017-10-01 15:59:37 +08:00
|
|
|
|
|
2017-02-22 14:30:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用户同步数据传送的引擎
|
|
|
|
|
|
/// </summary>
|
2017-09-02 22:35:02 +08:00
|
|
|
|
private NetSimplifyServer net_simplify_server = new NetSimplifyServer();
|
2017-02-22 14:30:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 同步传送数据的初始化
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void Net_Simplify_Server_Initialization()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2017-10-15 16:04:28 +08:00
|
|
|
|
net_simplify_server.KeyToken = UserSystem.KeyToken;//设置身份令牌
|
2017-09-02 22:35:02 +08:00
|
|
|
|
net_simplify_server.LogNet = new LogNetSingle(LogSavePath + @"\simplify_log.txt");//日志路径
|
2017-10-09 22:18:51 +08:00
|
|
|
|
net_simplify_server.LogNet.SetMessageDegree(HslMessageDegree.INFO);//默认debug及以上级别日志均进行存储,根据需要自行选择
|
2017-05-30 16:33:14 +08:00
|
|
|
|
net_simplify_server.ReceiveStringEvent += Net_simplify_server_ReceiveStringEvent;//接收到字符串触发
|
|
|
|
|
|
net_simplify_server.ReceivedBytesEvent += Net_simplify_server_ReceivedBytesEvent;//接收到字节触发
|
2017-10-15 16:04:28 +08:00
|
|
|
|
net_simplify_server.ServerStart(UserSystem.Port_Second_Net);
|
2017-07-14 15:31:37 +08:00
|
|
|
|
net_simplify_server.ConnectTimeout = 5200;
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2017-05-04 11:43:50 +08:00
|
|
|
|
SoftBasic.ShowExceptionMessage(ex);
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 接收来自客户端的字节数据
|
|
|
|
|
|
/// </summary>
|
2017-06-16 09:52:58 +08:00
|
|
|
|
/// <param name="state">网络状态</param>
|
|
|
|
|
|
/// <param name="customer">字节数据,根据实际情况选择是否使用</param>
|
|
|
|
|
|
/// <param name="data">来自客户端的字节数据</param>
|
2017-09-19 22:16:44 +08:00
|
|
|
|
private void Net_simplify_server_ReceivedBytesEvent(AsyncStateOne state, NetHandle customer, byte[] data)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-07-02 10:29:48 +08:00
|
|
|
|
if(customer==CommonHeadCode.SimplifyHeadCode.性能计数)
|
|
|
|
|
|
{
|
|
|
|
|
|
net_simplify_server.SendMessage(state, customer, GetPerfomace());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
net_simplify_server.SendMessage(state, customer, data);
|
|
|
|
|
|
}
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-06-16 09:52:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************************************************
|
|
|
|
|
|
*
|
|
|
|
|
|
* 方法说明: 当接收到来自客户端的数据的时候触发的方法
|
|
|
|
|
|
* 特别注意: 如果你的数据处理中引发了异常,应用程序将会奔溃,SendMessage异常系统将会自动处理
|
|
|
|
|
|
*
|
|
|
|
|
|
******************************************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-22 14:30:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 接收到来自客户端的数据,此处需要放置维护验证,更新验证等等操作
|
|
|
|
|
|
/// </summary>
|
2017-06-16 09:52:58 +08:00
|
|
|
|
/// <param name="state">客户端的地址</param>
|
2017-09-20 12:20:37 +08:00
|
|
|
|
/// <param name="handle">用于自定义的指令头,可不用,转而使用data来区分</param>
|
2017-06-16 09:52:58 +08:00
|
|
|
|
/// <param name="data">接收到的服务器的数据</param>
|
2017-09-20 12:20:37 +08:00
|
|
|
|
private void Net_simplify_server_ReceiveStringEvent(AsyncStateOne state, NetHandle handle, string data)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-09-20 12:20:37 +08:00
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************************
|
|
|
|
|
|
*
|
|
|
|
|
|
* 说明:同步消息处理总站,应该根据不同的消息设置分流到不同的处理方法
|
|
|
|
|
|
*
|
|
|
|
|
|
* 注意:处理完成后必须调用 net_simplify_server.SendMessage(state, customer, "处理结果字符串,可以为空");
|
|
|
|
|
|
*
|
|
|
|
|
|
*******************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
if (handle.CodeMajor == 1 && handle.CodeMinor == 1)
|
2017-05-05 23:07:44 +08:00
|
|
|
|
{
|
2017-09-20 12:20:37 +08:00
|
|
|
|
DataProcessingWithStartA(state, handle, data);
|
2017-05-05 23:07:44 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle.CodeMajor == 1 && handle.CodeMinor == 2)
|
2017-05-05 23:07:44 +08:00
|
|
|
|
{
|
2017-09-20 12:20:37 +08:00
|
|
|
|
DataProcessingWithStartB(state, handle, data);
|
2017-05-05 23:07:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, data);
|
2017-05-05 23:07:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************************************
|
|
|
|
|
|
*
|
|
|
|
|
|
* 数据处理中心,同步信息中的所有的细节处理均要到此处来处理
|
|
|
|
|
|
*
|
|
|
|
|
|
****************************************************************************************************/
|
2017-09-20 12:20:37 +08:00
|
|
|
|
|
|
|
|
|
|
#region 1.1.X 系统指令块
|
|
|
|
|
|
|
2017-05-05 23:07:44 +08:00
|
|
|
|
/// <summary>
|
2017-09-20 12:20:37 +08:00
|
|
|
|
/// 1.1.x指令块,处理系统基础运行的消息
|
2017-05-05 23:07:44 +08:00
|
|
|
|
/// </summary>
|
2017-06-16 09:52:58 +08:00
|
|
|
|
/// <param name="state">网络状态对象</param>
|
2017-09-20 12:20:37 +08:00
|
|
|
|
/// <param name="handle">用户自定义的指令头</param>
|
2017-06-16 09:52:58 +08:00
|
|
|
|
/// <param name="data">实际的数据</param>
|
2017-09-20 12:20:37 +08:00
|
|
|
|
private void DataProcessingWithStartA(AsyncStateOne state, NetHandle handle, string data)
|
2017-05-05 23:07:44 +08:00
|
|
|
|
{
|
2017-09-20 12:20:37 +08:00
|
|
|
|
if (handle == CommonHeadCode.SimplifyHeadCode.维护检查)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle,
|
2017-07-11 17:32:58 +08:00
|
|
|
|
UserServer.ServerSettings.Can_Account_Login ? "1" : "0" +
|
|
|
|
|
|
UserServer.ServerSettings.Account_Forbidden_Reason);
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.更新检查)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, UserServer.ServerSettings.SystemVersion.ToString());
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.参数下载)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-06-20 11:26:40 +08:00
|
|
|
|
JObject json = new JObject
|
|
|
|
|
|
{
|
2017-09-03 11:29:48 +08:00
|
|
|
|
{ nameof(UserServer.ServerSettings.Announcement), new JValue(UserServer.ServerSettings.Announcement) },
|
|
|
|
|
|
{ nameof(UserServer.ServerSettings.SystemFactories), new JArray(UserServer.ServerSettings.SystemFactories) },
|
2017-06-20 11:26:40 +08:00
|
|
|
|
};
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, json.ToString());
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.账户检查)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
|
|
|
|
|
//此处使用的是组件自带的验证的方式,如果使用SQL数据库,另行验证
|
2017-06-16 09:52:58 +08:00
|
|
|
|
JObject json = JObject.Parse(data);
|
2017-02-22 14:30:10 +08:00
|
|
|
|
//提取账户,密码
|
|
|
|
|
|
string name = SoftBasic.GetValueFromJsonObject(json, UserAccount.UserNameText, "");
|
2017-03-06 21:10:38 +08:00
|
|
|
|
string password = SoftBasic.GetValueFromJsonObject(json, UserAccount.PasswordText, "");
|
2017-07-24 20:54:40 +08:00
|
|
|
|
string way = SoftBasic.GetValueFromJsonObject(json, UserAccount.LoginWayText, "winform");
|
2017-10-01 15:59:37 +08:00
|
|
|
|
string machineId = SoftBasic.GetValueFromJsonObject(json, UserAccount.DeviceUniqueID, "ABCDEFHIGKLMN");
|
|
|
|
|
|
string frameworkVersion = SoftBasic.GetValueFromJsonObject(json, UserAccount.FrameworkVersion, "1.0.0");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UserAccount account = UserServer.ServerAccounts.CheckAccount(name, password, state.GetRemoteEndPoint().Address.ToString(), way);
|
2017-07-07 14:08:33 +08:00
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
|
|
|
|
|
|
// 先判定框架版本是否正确
|
2017-10-10 21:58:53 +08:00
|
|
|
|
//if (!UserServer.ServerSettings.AllowLoginWhenFramewordVersionNotCheck)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// SystemVersion sv = new SystemVersion(frameworkVersion);
|
|
|
|
|
|
// if (sv < SoftBasic.FrameworkVersion)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// account.LoginEnable = false;
|
|
|
|
|
|
// account.ForbidMessage = "框架版本检测失败,请更新";
|
|
|
|
|
|
// RuntimeLogHelper?.WriteWarn("框架版本验证失败,version:" + frameworkVersion);
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
2017-10-01 15:59:37 +08:00
|
|
|
|
|
|
|
|
|
|
// 检测是否重复登录
|
2017-09-03 11:29:48 +08:00
|
|
|
|
if (account.LoginEnable)
|
2017-07-07 14:08:33 +08:00
|
|
|
|
{
|
2017-09-24 12:42:45 +08:00
|
|
|
|
if (!UserServer.ServerSettings.AllowUserMultiOnline)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsClinetOnline(account.UserName))
|
|
|
|
|
|
{
|
|
|
|
|
|
account.LoginEnable = false;
|
|
|
|
|
|
account.ForbidMessage = "该账户已经登录";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检测客户端id是否被授权
|
|
|
|
|
|
if(UserServer.ServerSettings.WhetherToEnableTrustedClientAuthentication)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!UserServer.ServerSettings.CanClientLogin(machineId))
|
2017-07-07 14:08:33 +08:00
|
|
|
|
{
|
|
|
|
|
|
account.LoginEnable = false;
|
2017-09-24 12:42:45 +08:00
|
|
|
|
account.ForbidMessage = "该客户端不再服务器信任列表";
|
2017-07-07 14:08:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-09-24 12:42:45 +08:00
|
|
|
|
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, JObject.FromObject(account).ToString());
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.更新公告)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-06-16 09:52:58 +08:00
|
|
|
|
UserServer.ServerSettings.Announcement = data;
|
2017-02-22 14:30:10 +08:00
|
|
|
|
//通知所有客户端更新公告
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_socket_server.SendAllClients(handle, data);
|
|
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.获取账户)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
|
|
|
|
|
//返回服务器的账户信息
|
2017-10-15 16:04:28 +08:00
|
|
|
|
if (string.IsNullOrEmpty(data))
|
|
|
|
|
|
{
|
|
|
|
|
|
// 获取所有账户
|
|
|
|
|
|
net_simplify_server.SendMessage(state, handle, UserServer.ServerAccounts.GetAllAccountsJson());
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (data.Length < 16)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 获取所有分厂器的账户
|
|
|
|
|
|
net_simplify_server.SendMessage(state, handle, UserServer.ServerAccounts.GetAllAccountsJson(data));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 获取一个角色的所有关联账户
|
|
|
|
|
|
string[] names = UserServer.ServerRoles.GetUsernamesByRolename(data);
|
|
|
|
|
|
net_simplify_server.SendMessage(state, handle, UserServer.ServerAccounts.GetAllAccountsJson(names));
|
|
|
|
|
|
}
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.更细账户)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
|
|
|
|
|
//更新服务器的账户信息
|
2017-06-16 09:52:58 +08:00
|
|
|
|
UserServer.ServerAccounts.LoadAllAccountsJson(data);
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.密码修改)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-05-18 17:13:42 +08:00
|
|
|
|
//更新服务器的账户密码,此处使用的是组件自带的验证的方式,如果使用SQL数据库,另行验证
|
2017-06-16 09:52:58 +08:00
|
|
|
|
JObject json = JObject.Parse(data);
|
2017-02-22 14:30:10 +08:00
|
|
|
|
//提取账户,密码
|
|
|
|
|
|
string name = SoftBasic.GetValueFromJsonObject(json, UserAccount.UserNameText, "");
|
|
|
|
|
|
string password = SoftBasic.GetValueFromJsonObject(json, UserAccount.PasswordText, "");
|
|
|
|
|
|
UserServer.ServerAccounts.UpdatePassword(name, password);
|
2017-10-06 13:30:28 +08:00
|
|
|
|
UserServer.ServerAccounts.SaveToFile();
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.更新版本)
|
2017-03-22 19:50:11 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2017-06-16 09:52:58 +08:00
|
|
|
|
UserServer.ServerSettings.SystemVersion = new SystemVersion(data);
|
2017-03-22 19:50:11 +08:00
|
|
|
|
UserServer.ServerSettings.SaveToFile();
|
2017-03-25 10:25:17 +08:00
|
|
|
|
toolStripStatusLabel_version.Text = UserServer.ServerSettings.SystemVersion.ToString();
|
2017-06-16 10:38:30 +08:00
|
|
|
|
//记录数据
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteInfo($"更改了版本号:{data}");
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "1");
|
2017-03-22 19:50:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "0");
|
2017-03-22 19:50:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.注册账号)
|
2017-05-05 23:07:44 +08:00
|
|
|
|
{
|
2017-06-16 09:52:58 +08:00
|
|
|
|
bool result = UserServer.ServerAccounts.AddNewAccount(data);
|
2017-10-06 13:30:28 +08:00
|
|
|
|
if (result) UserServer.ServerAccounts.SaveToFile();
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, result ? "1" : "0");
|
2017-05-05 23:07:44 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.请求文件)
|
2017-05-05 23:07:44 +08:00
|
|
|
|
{
|
2017-10-01 15:59:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, ShareFileContainer.JsonArrayContent);
|
2017-05-05 23:07:44 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.意见反馈)
|
2017-06-05 17:32:46 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
AdviceLogHelper.WriteInfo(data);
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-06-17 18:36:29 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.群发消息)
|
2017-06-17 18:36:29 +08:00
|
|
|
|
{
|
|
|
|
|
|
net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.弹窗新消息, data);
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-06-05 17:32:46 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.异常消息)
|
2017-06-27 15:08:32 +08:00
|
|
|
|
{
|
2017-09-03 11:29:48 +08:00
|
|
|
|
ClientsLogHelper.WriteFatal(data);
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-06-29 11:01:14 +08:00
|
|
|
|
//发送到邮箱
|
|
|
|
|
|
SendUserMail("异常记录", "时间:" + DateTime.Now.ToString("O") + Environment.NewLine + data);
|
2017-06-27 15:08:32 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.上传头像MD5)
|
2017-07-07 10:18:28 +08:00
|
|
|
|
{
|
2017-09-18 17:35:59 +08:00
|
|
|
|
try
|
2017-07-07 10:18:28 +08:00
|
|
|
|
{
|
2017-09-18 17:35:59 +08:00
|
|
|
|
// 此处上传两个头像的MD5数据
|
|
|
|
|
|
JObject json = JObject.Parse(data);
|
|
|
|
|
|
|
|
|
|
|
|
string SmallPortraitMD5 = SoftBasic.GetValueFromJsonObject(json, UserAccount.SmallPortraitText, "");
|
|
|
|
|
|
string LargePortraitMD5 = SoftBasic.GetValueFromJsonObject(json, UserAccount.LargePortraitText, "");
|
|
|
|
|
|
string UserName = SoftBasic.GetValueFromJsonObject(json, UserAccount.UserNameText, "");
|
|
|
|
|
|
|
|
|
|
|
|
UserServer.ServerAccounts.UpdatePortraitMD5(UserName, SmallPortraitMD5, LargePortraitMD5);
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-10-10 21:58:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 推送头像更新消息
|
|
|
|
|
|
net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.新头像更新, UserName);
|
2017-07-07 10:18:28 +08:00
|
|
|
|
}
|
2017-09-18 17:35:59 +08:00
|
|
|
|
catch(Exception ex)
|
2017-07-07 10:18:28 +08:00
|
|
|
|
{
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "失败,原因是:" + ex.Message);
|
2017-07-07 10:18:28 +08:00
|
|
|
|
}
|
2017-10-10 21:58:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
2017-07-07 10:18:28 +08:00
|
|
|
|
}
|
2017-09-24 12:42:45 +08:00
|
|
|
|
else if(handle==CommonHeadCode.SimplifyHeadCode.请求分厂)
|
|
|
|
|
|
{
|
|
|
|
|
|
net_simplify_server.SendMessage(state, handle, JArray.FromObject(UserServer.ServerSettings.SystemFactories).ToString());
|
|
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.上传分厂)
|
2017-09-03 11:29:48 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
UserServer.ServerSettings.SystemFactories = JArray.Parse(data).ToObject<List<string>>();
|
2017-09-17 08:47:24 +08:00
|
|
|
|
RuntimeLogHelper?.WriteInfo("上传了分厂信息:" + data);
|
2017-09-03 11:29:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
RuntimeLogHelper?.WriteException(null, ex);
|
|
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "1");
|
2017-09-03 11:29:48 +08:00
|
|
|
|
}
|
2017-09-24 12:42:45 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.请求信任客户端)
|
|
|
|
|
|
{
|
|
|
|
|
|
JObject json = new JObject
|
|
|
|
|
|
{
|
|
|
|
|
|
{ "TrustEnable", new JValue(UserServer.ServerSettings.WhetherToEnableTrustedClientAuthentication) },
|
|
|
|
|
|
{ "TrustList", new JArray(UserServer.ServerSettings.TrustedClientList) }
|
|
|
|
|
|
};
|
|
|
|
|
|
net_simplify_server.SendMessage(state, handle, json.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.上传信任客户端)
|
|
|
|
|
|
{
|
|
|
|
|
|
JObject json = JObject.Parse(data);
|
|
|
|
|
|
UserServer.ServerSettings.WhetherToEnableTrustedClientAuthentication = json["TrustEnable"].ToObject<bool>();
|
|
|
|
|
|
UserServer.ServerSettings.TrustedClientList = json["TrustList"].ToObject<List<string>>();
|
2017-10-06 13:30:28 +08:00
|
|
|
|
UserServer.ServerSettings.SaveToFile();
|
2017-09-24 12:42:45 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.请求一般配置)
|
|
|
|
|
|
{
|
|
|
|
|
|
JObject json = new JObject
|
|
|
|
|
|
{
|
|
|
|
|
|
{ "AllowUserMulti", new JValue(UserServer.ServerSettings.AllowUserMultiOnline) },
|
2017-10-01 15:59:37 +08:00
|
|
|
|
{ "AllowFrameLogin", new JValue(UserServer.ServerSettings.AllowLoginWhenFramewordVersionNotCheck) },
|
2017-09-24 12:42:45 +08:00
|
|
|
|
};
|
|
|
|
|
|
net_simplify_server.SendMessage(state, handle, json.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.上传一般配置)
|
|
|
|
|
|
{
|
|
|
|
|
|
JObject json = JObject.Parse(data);
|
|
|
|
|
|
UserServer.ServerSettings.AllowUserMultiOnline = SoftBasic.GetValueFromJsonObject(json, "AllowUserMulti", false);
|
2017-10-01 15:59:37 +08:00
|
|
|
|
UserServer.ServerSettings.AllowLoginWhenFramewordVersionNotCheck = SoftBasic.GetValueFromJsonObject(json, "AllowFrameLogin", false);
|
2017-09-24 12:42:45 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, json.ToString());
|
|
|
|
|
|
}
|
2017-10-06 13:30:28 +08:00
|
|
|
|
else if(handle == CommonHeadCode.SimplifyHeadCode.请求角色配置)
|
|
|
|
|
|
{
|
|
|
|
|
|
net_simplify_server.SendMessage(state, handle, UserServer.ServerRoles.ToSaveString());
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(handle == CommonHeadCode.SimplifyHeadCode.上传角色配置)
|
|
|
|
|
|
{
|
|
|
|
|
|
UserServer.ServerRoles.LoadByString(data);
|
|
|
|
|
|
UserServer.ServerRoles.SaveToFile();
|
|
|
|
|
|
net_simplify_server.SendMessage(state, handle, "1");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.检查角色权限)
|
|
|
|
|
|
{
|
|
|
|
|
|
JObject json = JObject.Parse(data);
|
|
|
|
|
|
string name = SoftBasic.GetValueFromJsonObject(json, "Name", "");
|
2017-10-07 21:32:23 +08:00
|
|
|
|
string roleCode = SoftBasic.GetValueFromJsonObject(json, "Role", "");
|
|
|
|
|
|
net_simplify_server.SendMessage(state, handle, UserServer.ServerRoles.IsAllowAccountOperate(roleCode, name).ToString());
|
2017-10-06 13:30:28 +08:00
|
|
|
|
}
|
2017-05-05 23:07:44 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, data);
|
2017-05-05 23:07:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-20 12:20:37 +08:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 1.2.X 系统日志块
|
|
|
|
|
|
|
2017-05-05 23:07:44 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// B指令块,处理日志相关的消息
|
|
|
|
|
|
/// </summary>
|
2017-06-21 18:00:00 +08:00
|
|
|
|
/// <param name="state">网络状态对象</param>
|
2017-09-20 12:20:37 +08:00
|
|
|
|
/// <param name="handle">用户自定义的命令头</param>
|
2017-06-21 18:00:00 +08:00
|
|
|
|
/// <param name="data">实际的数据</param>
|
2017-09-20 12:20:37 +08:00
|
|
|
|
private void DataProcessingWithStartB(AsyncStateOne state, NetHandle handle, string data)
|
2017-05-05 23:07:44 +08:00
|
|
|
|
{
|
2017-09-20 12:20:37 +08:00
|
|
|
|
if (handle == CommonHeadCode.SimplifyHeadCode.网络日志查看)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
LogNetSingle logNet = (LogNetSingle)net_socket_server.LogNet;
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, logNet.GetAllSavedLog());
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteInfo("网络日志查看");
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.网络日志清空)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
if (net_socket_server.LogNet is LogNetSingle logNet)
|
|
|
|
|
|
{
|
|
|
|
|
|
logNet.ClearLog();
|
|
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteWarn("网络日志清空");
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.同步日志查看)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
LogNetSingle logNet = (LogNetSingle)net_simplify_server.LogNet;
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, logNet.GetAllSavedLog());
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteInfo("同步日志查看");
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.同步日志清空)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
if (net_simplify_server.LogNet is LogNetSingle logNet)
|
|
|
|
|
|
{
|
|
|
|
|
|
logNet.ClearLog();
|
|
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteWarn("同步日志清空");
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.更新日志查看)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
LogNetSingle logNet = (LogNetSingle)net_soft_update_Server.LogNet;
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, logNet.GetAllSavedLog());
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteInfo("更新日志查看");
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.更新日志清空)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
if (net_soft_update_Server.LogNet is LogNetSingle logNet)
|
|
|
|
|
|
{
|
|
|
|
|
|
logNet.ClearLog();
|
|
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteWarn("更新日志清空");
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.运行日志查看)
|
2017-05-19 10:20:10 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
LogNetSingle logNet = (LogNetSingle)RuntimeLogHelper;
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, logNet.GetAllSavedLog());
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteInfo("运行日志查看");
|
2017-05-19 10:20:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.运行日志清空)
|
2017-05-19 10:20:10 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
if (RuntimeLogHelper is LogNetSingle logNet)
|
|
|
|
|
|
{
|
|
|
|
|
|
logNet.ClearLog();
|
|
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteWarn("运行日志清空");
|
2017-05-19 10:20:10 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.文件日志查看)
|
2017-06-04 19:13:26 +08:00
|
|
|
|
{
|
2017-10-01 15:59:37 +08:00
|
|
|
|
LogNetSingle logNet = (LogNetSingle)net_ultimate_file_server.LogNet;
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, logNet.GetAllSavedLog());
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteInfo("共享文件日志查看");
|
2017-06-04 19:13:26 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.文件日志清空)
|
2017-06-04 19:13:26 +08:00
|
|
|
|
{
|
2017-10-01 15:59:37 +08:00
|
|
|
|
if (net_ultimate_file_server.LogNet is LogNetSingle logNet)
|
2017-09-02 22:35:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
logNet.ClearLog();
|
|
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteWarn("共享文件日志清空");
|
2017-06-04 19:13:26 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.反馈日志查看)
|
2017-06-05 17:32:46 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
LogNetSingle logNet = (LogNetSingle)AdviceLogHelper;
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, logNet.GetAllSavedLog());
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteInfo("建议反馈日志查看");
|
2017-06-05 17:32:46 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.反馈日志清空)
|
2017-06-05 17:32:46 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
if (AdviceLogHelper is LogNetSingle logNet)
|
|
|
|
|
|
{
|
|
|
|
|
|
logNet.ClearLog();
|
|
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteWarn("建议反馈日志清空");
|
2017-06-05 17:32:46 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.UDP日志查看)
|
2017-06-07 16:20:40 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
LogNetSingle logNet = (LogNetSingle)net_udp_server.LogNet;
|
|
|
|
|
|
net_simplify_server.SendMessage(state, 0, logNet.GetAllSavedLog());
|
|
|
|
|
|
RuntimeLogHelper.WriteInfo("UDP日志查看");
|
2017-06-07 16:20:40 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.UDP日志清空)
|
2017-06-07 16:20:40 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
if (net_udp_server.LogNet is LogNetSingle logNet)
|
|
|
|
|
|
{
|
|
|
|
|
|
logNet.ClearLog();
|
|
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteWarn("UDP日志清空");
|
2017-06-07 16:20:40 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.客户端日志查看)
|
2017-06-27 15:08:32 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
LogNetSingle logNet = ClientsLogHelper as LogNetSingle;
|
|
|
|
|
|
net_simplify_server.SendMessage(state, 0, logNet.GetAllSavedLog());
|
|
|
|
|
|
RuntimeLogHelper.WriteInfo("客户端日志查看");
|
2017-06-27 15:08:32 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.客户端日志清空)
|
2017-06-27 15:08:32 +08:00
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
if (ClientsLogHelper is LogNetSingle logNet)
|
|
|
|
|
|
{
|
|
|
|
|
|
logNet.ClearLog();
|
|
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteWarn("客户端日志清空");
|
2017-06-27 15:08:32 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.头像日志查看)
|
2017-07-07 10:42:02 +08:00
|
|
|
|
{
|
2017-09-17 21:59:45 +08:00
|
|
|
|
LogNetSingle logNet = (LogNetSingle)net_file_Advanced.LogNet;
|
2017-09-02 22:35:02 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, 0, logNet.GetAllSavedLog());
|
|
|
|
|
|
RuntimeLogHelper.WriteInfo("头像日志查看");
|
2017-07-07 10:42:02 +08:00
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
else if (handle == CommonHeadCode.SimplifyHeadCode.头像日志清空)
|
2017-07-07 10:42:02 +08:00
|
|
|
|
{
|
2017-09-17 21:59:45 +08:00
|
|
|
|
if (net_file_Advanced.LogNet is LogNetSingle logNet)
|
2017-09-02 22:35:02 +08:00
|
|
|
|
{
|
|
|
|
|
|
logNet.ClearLog();
|
|
|
|
|
|
}
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, "成功");
|
2017-09-02 22:35:02 +08:00
|
|
|
|
RuntimeLogHelper.WriteWarn("头像日志清空");
|
2017-07-07 10:42:02 +08:00
|
|
|
|
}
|
2017-02-22 14:30:10 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-09-20 12:20:37 +08:00
|
|
|
|
net_simplify_server.SendMessage(state, handle, data);
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-05-05 23:07:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
2017-09-20 12:20:37 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 1.3.X 自行扩充块
|
|
|
|
|
|
|
2017-05-17 22:20:52 +08:00
|
|
|
|
/****************************************************************************************************
|
|
|
|
|
|
*
|
|
|
|
|
|
* 您在下面可以自己扩展数据处理的方法,设计原则为运行速度尽可能的快,不要长时间阻塞
|
|
|
|
|
|
*
|
|
|
|
|
|
****************************************************************************************************/
|
|
|
|
|
|
|
2017-09-20 12:20:37 +08:00
|
|
|
|
private void DataProcessingWithStartC(AsyncStateOne state, NetHandle handle, string data)
|
2017-09-18 17:35:59 +08:00
|
|
|
|
{
|
2017-05-05 23:07:44 +08:00
|
|
|
|
|
2017-09-20 12:20:37 +08:00
|
|
|
|
}
|
2017-10-01 15:59:37 +08:00
|
|
|
|
|
2017-09-20 12:20:37 +08:00
|
|
|
|
#endregion
|
2017-05-05 23:07:44 +08:00
|
|
|
|
|
2017-02-22 14:30:10 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 异步数据传送引擎
|
2017-10-01 15:59:37 +08:00
|
|
|
|
|
|
|
|
|
|
/******************************************************************************************************************
|
|
|
|
|
|
*
|
|
|
|
|
|
* 说明: 异步网络主要显示的功能是对所有在线客户端的管理能力,并允许群发所有在线客户端消息
|
|
|
|
|
|
* 注意: 如果客户端需要向服务器请求数据并明确的需要返回消息,则必须选择同步网络通信
|
|
|
|
|
|
*
|
|
|
|
|
|
******************************************************************************************************************/
|
|
|
|
|
|
|
2017-05-30 16:33:14 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 异步客户端管理引擎,维护所有的客户端在线情况,支持主动发数据到所有的客户端
|
|
|
|
|
|
/// </summary>
|
2017-09-02 22:35:02 +08:00
|
|
|
|
private NetComplexServer net_socket_server = new NetComplexServer();
|
2017-02-22 14:30:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 异步传送数据的初始化
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void Net_Socket_Server_Initialization()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2017-10-15 16:04:28 +08:00
|
|
|
|
net_socket_server.KeyToken = UserSystem.KeyToken; // 设置身份令牌
|
2017-10-11 09:59:58 +08:00
|
|
|
|
net_socket_server.LogNet =new LogNetSingle(LogSavePath + @"\net_log.txt"); // 设置日志存储路径
|
2017-10-15 16:04:28 +08:00
|
|
|
|
net_socket_server.LogNet.SetMessageDegree(HslMessageDegree.INFO); // 默认debug及以上级别日志均进行存储,根据需要自行选择
|
2017-10-11 09:59:58 +08:00
|
|
|
|
net_socket_server.FormatClientOnline = "#IP:{0} Name:{1}"; // 必须为#开头,具体格式可由自身需求确定
|
|
|
|
|
|
net_socket_server.IsSaveLogClientLineChange = true; // 设置客户端上下线是否记录到日志
|
|
|
|
|
|
net_socket_server.ClientOnline += new NetBase.IEDelegate<AsyncStateOne>(Net_socket_server_ClientOnline);// 客户端上线触发
|
|
|
|
|
|
net_socket_server.ClientOffline += new NetBase.IEDelegate<AsyncStateOne, string>(Net_socket_server_ClientOffline);// 客户端下线触发,包括异常掉线
|
|
|
|
|
|
net_socket_server.AllClientsStatusChange += new NetBase.IEDelegate<string>(Net_socket_server_AllClientsStatusChange);// 客户端上下线变化时触发
|
|
|
|
|
|
net_socket_server.MessageAlerts += new NetBase.IEDelegate<string>(Net_socket_server_MessageAlerts);// 服务器产生提示消息触发
|
|
|
|
|
|
net_socket_server.AcceptByte += new NetBase.IEDelegate<AsyncStateOne, NetHandle, byte[]>(Net_socket_server_AcceptByte);// 服务器接收到字节数据触发
|
|
|
|
|
|
net_socket_server.AcceptString += new NetBase.IEDelegate<AsyncStateOne, NetHandle, string>(Net_socket_server_AcceptString);// 服务器接收到字符串数据触发
|
2017-10-15 16:04:28 +08:00
|
|
|
|
net_socket_server.ServerStart(UserSystem.Port_Main_Net);
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2017-05-04 11:43:50 +08:00
|
|
|
|
SoftBasic.ShowExceptionMessage(ex);
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-01 15:59:37 +08:00
|
|
|
|
|
2017-06-16 09:52:58 +08:00
|
|
|
|
|
|
|
|
|
|
/******************************************************************************************************************
|
|
|
|
|
|
*
|
|
|
|
|
|
* 方法说明: 当接收到来自客户端的数据的时候触发的方法
|
|
|
|
|
|
* 特别注意: 如果你的数据处理中引发了异常,应用程序将会继续运行,该异常将会记录在网络日志中,
|
|
|
|
|
|
* 所以有必要的话,对可能发生的异常需要提前处理。
|
|
|
|
|
|
*
|
|
|
|
|
|
******************************************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-20 12:20:37 +08:00
|
|
|
|
private void Net_socket_server_AcceptString(AsyncStateOne object1, NetHandle handle, string data)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-09-20 12:20:37 +08:00
|
|
|
|
if (handle.CodeMajor == 2 && handle.CodeMinor == 1)
|
2017-05-17 22:20:52 +08:00
|
|
|
|
{
|
2017-09-20 12:20:37 +08:00
|
|
|
|
DataProcessingWithStartH(object1, handle, data);
|
2017-05-17 22:20:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2017-03-06 21:10:38 +08:00
|
|
|
|
|
2017-09-20 12:20:37 +08:00
|
|
|
|
|
|
|
|
|
|
#region 2.1.X 指令处理块
|
|
|
|
|
|
|
2017-05-17 22:20:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// H开头的处理块
|
|
|
|
|
|
/// </summary>
|
2017-06-16 09:52:58 +08:00
|
|
|
|
/// <param name="state">网络状态</param>
|
2017-06-21 18:00:00 +08:00
|
|
|
|
/// <param name="customer">用户自定义的指令头</param>
|
2017-06-16 09:52:58 +08:00
|
|
|
|
/// <param name="data">字符串数据</param>
|
2017-09-19 22:16:44 +08:00
|
|
|
|
private void DataProcessingWithStartH(AsyncStateOne state, NetHandle customer, string data)
|
2017-05-17 22:20:52 +08:00
|
|
|
|
{
|
2017-06-16 09:52:58 +08:00
|
|
|
|
if (customer == CommonHeadCode.MultiNetHeadCode.留言版消息)
|
2017-05-17 22:20:52 +08:00
|
|
|
|
{
|
2017-06-20 11:26:40 +08:00
|
|
|
|
ChatAddMessage(state.LoginAlias, data);
|
2017-05-17 22:20:52 +08:00
|
|
|
|
}
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-20 12:20:37 +08:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2017-05-17 22:20:52 +08:00
|
|
|
|
|
2017-09-19 22:16:44 +08:00
|
|
|
|
private void Net_socket_server_AcceptByte(AsyncStateOne state, NetHandle customer, byte[] data)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
|
|
|
|
|
//如果此处充斥大量if语句,影响观感,则考虑进行指令头分类操作,客户端异步发送的字节数组都会到此处处理
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Net_socket_server_MessageAlerts(string object1)
|
|
|
|
|
|
{
|
2017-06-28 22:27:53 +08:00
|
|
|
|
UserInterfaceMessageRender(object1 + Environment.NewLine);
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-18 22:44:07 +08:00
|
|
|
|
private void Net_socket_server_ClientOffline(AsyncStateOne object1, string object2)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-10-16 21:22:34 +08:00
|
|
|
|
netAccountManager.RemoveOnlineClient(object1.ClientUniqueID);
|
2017-10-10 21:58:53 +08:00
|
|
|
|
net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.用户下线, object1.ClientUniqueID);
|
2017-10-09 22:18:51 +08:00
|
|
|
|
|
2017-10-10 21:58:53 +08:00
|
|
|
|
UserInterfaceMessageRender(DateTime.Now.ToString("MM-dd HH:mm:ss ") + object1.IpAddress + ":" + object1.LoginAlias + " " + object2);
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-18 22:44:07 +08:00
|
|
|
|
private void Net_socket_server_ClientOnline(AsyncStateOne object1)
|
2017-02-22 14:30:10 +08:00
|
|
|
|
{
|
2017-10-11 09:59:58 +08:00
|
|
|
|
NetAccount account = new NetAccount
|
|
|
|
|
|
{
|
|
|
|
|
|
UserName = object1.LoginAlias,
|
|
|
|
|
|
Roles = UserServer.ServerRoles.GetRolesByUserName(object1.LoginAlias),
|
|
|
|
|
|
IpAddress = object1.IpAddress,
|
|
|
|
|
|
Alias = UserServer.ServerAccounts.GetAccountAlias(object1.LoginAlias),
|
|
|
|
|
|
Factory = UserServer.ServerAccounts.GetAccountFactory(object1.LoginAlias),
|
|
|
|
|
|
LoginTime = DateTime.Now,
|
|
|
|
|
|
UniqueId = object1.ClientUniqueID
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.新用户上线, JObject.FromObject(account).ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
// 上线后回发一条数据初始化信息
|
2017-04-06 16:18:46 +08:00
|
|
|
|
JObject json = new JObject
|
|
|
|
|
|
{
|
|
|
|
|
|
{ "Time", new JValue(DateTime.Now) },
|
2017-10-01 15:59:37 +08:00
|
|
|
|
{ "FileCount", new JValue(ShareFileContainer.FileCount) },
|
2017-10-10 21:58:53 +08:00
|
|
|
|
{ "chats", new JValue(Chats_Managment.ToSaveString())},
|
2017-10-16 21:22:34 +08:00
|
|
|
|
{ "ClientsOnline", new JValue(netAccountManager.ClientsOnlineCache) }
|
2017-04-06 16:18:46 +08:00
|
|
|
|
};
|
2017-10-15 16:04:28 +08:00
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
// 发送客户端的初始化数据
|
2017-06-29 11:01:14 +08:00
|
|
|
|
net_socket_server.Send(object1, CommonHeadCode.MultiNetHeadCode.初始化数据, json.ToString());
|
2017-10-15 16:04:28 +08:00
|
|
|
|
// 新增到在线客户端的队列中
|
2017-10-16 21:22:34 +08:00
|
|
|
|
netAccountManager.AddOnlineClient(account);
|
2017-10-01 15:59:37 +08:00
|
|
|
|
// 触发上下线功能
|
2017-10-10 21:58:53 +08:00
|
|
|
|
UserInterfaceMessageRender(DateTime.Now.ToString("MM-dd HH:mm:ss ") + object1.IpAddress + ":" + object1.LoginAlias + " 上线");
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-06-16 17:20:52 +08:00
|
|
|
|
|
|
|
|
|
|
private void Net_socket_server_AllClientsStatusChange(string data)
|
|
|
|
|
|
{
|
2017-10-01 15:59:37 +08:00
|
|
|
|
// 此处决定要不要将在线客户端的数据发送所有客户端
|
2017-10-09 22:18:51 +08:00
|
|
|
|
// net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.总在线信息, data);
|
2017-07-07 14:08:33 +08:00
|
|
|
|
Net_Socket_All_Clients = data;
|
2017-06-16 17:20:52 +08:00
|
|
|
|
if (IsWindowShow && IsHandleCreated)
|
|
|
|
|
|
{
|
|
|
|
|
|
BeginInvoke(new Action(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
listBox1.DataSource = data.Split('#');
|
2017-02-22 14:30:10 +08:00
|
|
|
|
label4.Text = net_socket_server.ClientCount.ToString();
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-07-07 14:08:33 +08:00
|
|
|
|
/// <summary>
|
2017-10-01 15:59:37 +08:00
|
|
|
|
/// 所有在线客户端的信息,此处做了一个缓存
|
2017-07-07 14:08:33 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
private string Net_Socket_All_Clients = string.Empty;
|
2017-09-24 12:42:45 +08:00
|
|
|
|
|
2017-07-07 14:08:33 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用来判断客户端是否已经在线,除了超级管理员,其他的账户不允许重复在线,重复登录的账户予以特殊标记
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>该客户端是否在线</returns>
|
|
|
|
|
|
private bool IsClinetOnline(string userName)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (userName == "admin") return false;
|
|
|
|
|
|
if(Net_Socket_All_Clients.Contains($"Name:{userName}#"))
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(Net_Socket_All_Clients.EndsWith($"Name:{userName}"))
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-06-16 17:20:52 +08:00
|
|
|
|
|
2017-10-16 21:22:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 发送数据给在线的指定角色客户端
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="handle">信息句柄</param>
|
|
|
|
|
|
/// <param name="message">消息</param>
|
|
|
|
|
|
/// <param name="roleCode">角色代码</param>
|
|
|
|
|
|
private void SendToClientsByRoleCode(NetHandle handle, string message, string roleCode)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var m in UserServer.ServerRoles.GetUsernamesByRolename(roleCode))
|
|
|
|
|
|
{
|
|
|
|
|
|
net_socket_server.SendClientByAlias(m, handle, roleCode);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 在线客户端管理器
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 所有在线客户端的管理器
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private NetAccountManager netAccountManager { get; set; } = new NetAccountManager();
|
|
|
|
|
|
|
2017-02-22 14:30:10 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2017-03-06 21:10:38 +08:00
|
|
|
|
#region 后台计数线程
|
2017-05-30 17:38:35 +08:00
|
|
|
|
|
2017-05-30 16:33:14 +08:00
|
|
|
|
/*********************************************************************************************
|
|
|
|
|
|
*
|
|
|
|
|
|
* 说明 一个后台线程,用来执行一些周期执行的东西
|
|
|
|
|
|
* 注意 它不仅执行每秒触发的代码,也支持每分钟,每天,每月,每年等等
|
|
|
|
|
|
*
|
|
|
|
|
|
********************************************************************************************/
|
|
|
|
|
|
|
2017-03-06 21:10:38 +08:00
|
|
|
|
|
2017-05-30 16:33:14 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 初始化后台的计数线程
|
|
|
|
|
|
/// </summary>
|
2017-03-06 21:10:38 +08:00
|
|
|
|
public void TimeTickInitilization()
|
|
|
|
|
|
{
|
|
|
|
|
|
toolStripStatusLabel_time.Alignment = ToolStripItemAlignment.Right;
|
|
|
|
|
|
statusStrip1.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow;
|
|
|
|
|
|
toolStripStatusLabel_time.ForeColor = Color.Purple;//紫色
|
2017-06-29 11:01:14 +08:00
|
|
|
|
|
2017-03-06 21:10:38 +08:00
|
|
|
|
|
|
|
|
|
|
Thread thread = new Thread(new ThreadStart(ThreadTimeTick));
|
|
|
|
|
|
thread.IsBackground = true;
|
|
|
|
|
|
thread.Start();
|
|
|
|
|
|
}
|
2017-06-28 18:41:37 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 缓存的上次内存占用
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private long GC_Memery { get; set; }
|
2017-06-28 21:59:46 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 程序的内存对象
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private long Pm_Memery { get; set; }
|
2017-06-28 18:41:37 +08:00
|
|
|
|
|
|
|
|
|
|
private void MethodOccurEverySecond()
|
|
|
|
|
|
{
|
2017-06-28 21:59:46 +08:00
|
|
|
|
long current1 = GC.GetTotalMemory(false);
|
2017-07-02 10:29:48 +08:00
|
|
|
|
//增加到性能计数
|
|
|
|
|
|
AddPerfomace(current1);
|
|
|
|
|
|
|
2017-06-28 21:59:46 +08:00
|
|
|
|
long current2 = 0;
|
2017-06-28 18:41:37 +08:00
|
|
|
|
toolStripStatusLabel_time.Text = DateTime.Now.ToString();
|
2017-06-28 21:59:46 +08:00
|
|
|
|
label_GC_Memery.Text = current1.ToString();
|
|
|
|
|
|
label_Pm_Memery.Text = "备用";//current2.ToString();
|
|
|
|
|
|
label_GC_Memery.BackColor = current1 < GC_Memery ? Color.Tomato : SystemColors.Control;
|
|
|
|
|
|
label_Pm_Memery.BackColor = current2 < Pm_Memery ? Color.Tomato : SystemColors.Control;
|
|
|
|
|
|
GC_Memery = current1;
|
|
|
|
|
|
Pm_Memery = current2;
|
2017-06-28 18:41:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-03-06 21:10:38 +08:00
|
|
|
|
|
|
|
|
|
|
public void ThreadTimeTick()
|
|
|
|
|
|
{
|
|
|
|
|
|
Thread.Sleep(300);//加一个微小的延时
|
|
|
|
|
|
int second = DateTime.Now.Second - 1;
|
2017-05-30 16:33:14 +08:00
|
|
|
|
int minute = -1;
|
|
|
|
|
|
int hour = -1;
|
|
|
|
|
|
int day = -1;
|
2017-06-28 18:41:37 +08:00
|
|
|
|
Action DTimeShow = MethodOccurEverySecond;
|
2017-03-06 21:10:38 +08:00
|
|
|
|
|
|
|
|
|
|
while (IsWindowShow)
|
|
|
|
|
|
{
|
|
|
|
|
|
while (DateTime.Now.Second == second)
|
|
|
|
|
|
{
|
|
|
|
|
|
Thread.Sleep(20);
|
|
|
|
|
|
}
|
|
|
|
|
|
second = DateTime.Now.Second;
|
|
|
|
|
|
if (IsWindowShow && IsHandleCreated) Invoke(DTimeShow);
|
2017-10-01 15:59:37 +08:00
|
|
|
|
// 每秒钟执行的代码
|
2017-06-29 11:01:14 +08:00
|
|
|
|
|
2017-03-06 21:10:38 +08:00
|
|
|
|
if (second == 0)
|
|
|
|
|
|
{
|
2017-10-01 15:59:37 +08:00
|
|
|
|
// 每个0秒执行的代码
|
|
|
|
|
|
// net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.时间的推送, DateTime.Now.ToString("O"));
|
2017-03-06 21:10:38 +08:00
|
|
|
|
}
|
2017-05-30 16:33:14 +08:00
|
|
|
|
if (minute != DateTime.Now.Minute)
|
|
|
|
|
|
{
|
|
|
|
|
|
minute = DateTime.Now.Minute;
|
2017-10-01 15:59:37 +08:00
|
|
|
|
// 每分钟执行的代码
|
2017-05-30 16:33:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (hour != DateTime.Now.Hour)
|
|
|
|
|
|
{
|
|
|
|
|
|
hour = DateTime.Now.Hour;
|
2017-10-01 15:59:37 +08:00
|
|
|
|
// 每小时执行的代码
|
2017-05-30 16:33:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (day != DateTime.Now.Day)
|
|
|
|
|
|
{
|
|
|
|
|
|
day = DateTime.Now.Day;
|
2017-10-01 15:59:37 +08:00
|
|
|
|
// 每天执行的代码
|
2017-05-30 16:33:14 +08:00
|
|
|
|
}
|
2017-03-06 21:10:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-02 10:29:48 +08:00
|
|
|
|
#region 服务器内存性能缓存小模块
|
|
|
|
|
|
|
2017-07-02 18:48:35 +08:00
|
|
|
|
private SoftCacheArrayInt SoftCachePerfomance = new SoftCacheArrayInt(500, 0);
|
2017-07-02 10:29:48 +08:00
|
|
|
|
|
|
|
|
|
|
private void AddPerfomace(long value)
|
|
|
|
|
|
{
|
|
|
|
|
|
SoftCachePerfomance.AddValue((int)value);//虽然存在不安全隐患,但是几乎不可能大于20亿
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private byte[] GetPerfomace()
|
|
|
|
|
|
{
|
|
|
|
|
|
return SoftCachePerfomance.GetAllData();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-10-04 20:39:56 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Advanced File Server
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************************
|
|
|
|
|
|
*
|
|
|
|
|
|
* 本文件管理器引擎目前主要实现1个功能
|
|
|
|
|
|
* 1. 允许客户端上传服务器的客户端文件,用来提供软件自动更新使用的
|
|
|
|
|
|
*
|
|
|
|
|
|
**************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 一个高级的文件管理服务器引擎
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private AdvancedFileServer net_file_Advanced = new AdvancedFileServer();
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 初始化高级的文件管理引擎
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void Net_File_Portrait_Initialization()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
net_file_Advanced.FilesDirectoryPath = Application.StartupPath + @"\AdvancedFiles";
|
|
|
|
|
|
net_file_Advanced.FilesDirectoryPathTemp = Application.StartupPath + @"\AdvancedFiles\Temp";
|
|
|
|
|
|
net_file_Advanced.LogNet = new LogNetSingle(LogSavePath + @"\Advanced_file_log.txt");
|
2017-10-15 16:04:28 +08:00
|
|
|
|
net_file_Advanced.KeyToken = UserSystem.KeyToken;
|
|
|
|
|
|
net_file_Advanced.ServerStart(UserSystem.Port_Advanced_File_Server);
|
2017-10-04 20:39:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
SoftBasic.ShowExceptionMessage(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-03-06 21:10:38 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
#region Ultimate File Server
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************************
|
|
|
|
|
|
*
|
|
|
|
|
|
* 本文件管理器引擎目前主要实现3个大功能
|
|
|
|
|
|
* 1. 用于管理客户端的头像文件存储服务
|
|
|
|
|
|
* 2. 用于管理每个账户的私有文件存储服务
|
|
|
|
|
|
* 3. 用于主界面的共享文件管理
|
|
|
|
|
|
*
|
|
|
|
|
|
**************************************************************************************/
|
|
|
|
|
|
|
2017-05-30 16:33:14 +08:00
|
|
|
|
/// <summary>
|
2017-10-01 15:59:37 +08:00
|
|
|
|
/// 终极文件管理服务器
|
2017-05-30 16:33:14 +08:00
|
|
|
|
/// </summary>
|
2017-10-01 15:59:37 +08:00
|
|
|
|
private UltimateFileServer net_ultimate_file_server { get; set; } = null;
|
2017-05-30 16:33:14 +08:00
|
|
|
|
/// <summary>
|
2017-10-01 15:59:37 +08:00
|
|
|
|
/// 终极文件管理服务器
|
2017-05-30 16:33:14 +08:00
|
|
|
|
/// </summary>
|
2017-10-01 15:59:37 +08:00
|
|
|
|
private void Ultimate_File_Initiaization()
|
2017-04-06 16:18:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2017-10-01 15:59:37 +08:00
|
|
|
|
net_ultimate_file_server = new UltimateFileServer();
|
2017-10-15 16:04:28 +08:00
|
|
|
|
net_ultimate_file_server.KeyToken = UserSystem.KeyToken;
|
2017-10-02 09:36:00 +08:00
|
|
|
|
net_ultimate_file_server.LogNet = new LogNetSingle(LogSavePath + @"\ultimate_file_log.txt");
|
2017-10-01 15:59:37 +08:00
|
|
|
|
net_ultimate_file_server.LogNet.SetMessageDegree(HslMessageDegree.DEBUG);//默认debug及以上级别日志均进行存储,根据需要自行选择
|
2017-10-04 20:39:56 +08:00
|
|
|
|
net_ultimate_file_server.FilesDirectoryPath = Application.StartupPath + @"\UltimateFiles";
|
2017-10-15 16:04:28 +08:00
|
|
|
|
net_ultimate_file_server.ServerStart(UserSystem.Port_Ultimate_File_Server);
|
2017-10-01 15:59:37 +08:00
|
|
|
|
|
|
|
|
|
|
// 共享文件管理器只是终极文件管理器的一个子容器
|
2017-10-04 20:39:56 +08:00
|
|
|
|
ShareFileContainer = net_ultimate_file_server.GetGroupFromFilePath(Application.StartupPath + @"\UltimateFiles\ShareFiles");
|
2017-10-01 15:59:37 +08:00
|
|
|
|
ShareFileContainer.FileCountChanged += ShareFileContainer_FileCountChanged;
|
2017-04-06 16:18:46 +08:00
|
|
|
|
}
|
2017-05-30 17:38:35 +08:00
|
|
|
|
catch (Exception ex)
|
2017-04-06 16:18:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
SoftBasic.ShowExceptionMessage(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
|
|
|
|
|
|
// 以下是共享文件的功能
|
|
|
|
|
|
|
2017-10-02 09:36:00 +08:00
|
|
|
|
private void ShareFileContainer_FileCountChanged(int fileCount)
|
2017-04-06 16:18:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
//将文件数据发送给客户端
|
2017-10-02 09:36:00 +08:00
|
|
|
|
net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.文件总数量, fileCount.ToString());
|
2017-04-06 16:18:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
private GroupFileContainer ShareFileContainer;
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-04-06 16:18:46 +08:00
|
|
|
|
|
2017-06-05 17:32:46 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 意见反馈块
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************************************************
|
|
|
|
|
|
*
|
|
|
|
|
|
* 说明: 用来记录意见反馈的数据
|
|
|
|
|
|
* 举例: AdviceLogHelper.SaveInformation("张三:主界面的颜色稍微调整一下");
|
|
|
|
|
|
*
|
|
|
|
|
|
**********************************************************************************************************/
|
2017-10-01 15:59:37 +08:00
|
|
|
|
|
2017-06-05 17:32:46 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用来记录一般的事物日志
|
|
|
|
|
|
/// </summary>
|
2017-09-02 22:35:02 +08:00
|
|
|
|
private ILogNet AdviceLogHelper { get; set; }
|
2017-06-05 17:32:46 +08:00
|
|
|
|
|
2017-04-06 16:18:46 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2017-06-07 16:20:40 +08:00
|
|
|
|
#region Udp网络通信块
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************************************************
|
|
|
|
|
|
*
|
2017-06-07 22:29:47 +08:00
|
|
|
|
* 说明 一个用于网络间通信的UDP服务引擎,客户端调用UserClient.Net_Udp_Client.SendMessage(data);
|
|
|
|
|
|
* 发送详细请参考客户端FormMainWindow中的udp发送说明
|
2017-06-07 16:20:40 +08:00
|
|
|
|
* 特点 该Udp引擎非常健壮,接收失败了会抛弃本次接收,自动进入下一轮接收。
|
2017-06-07 22:29:47 +08:00
|
|
|
|
* 安全 本引擎含有数据长度校验机制,确保服务器接收到的数据是正确的,没有丢失的,发送的数据是经过加密的
|
2017-06-07 16:20:40 +08:00
|
|
|
|
* 注意 如果服务器配置了ReceiveCacheLength = 1024,那么客户端发送的字符串数据长度不能超过1000,否则服务器会自动丢弃,可在日志中查看
|
|
|
|
|
|
* 警告 如果想要你自己的软件支持向本引擎访问,必须使用该网络组件实现,参考客户端定义,否则发送失败
|
|
|
|
|
|
*
|
|
|
|
|
|
**********************************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 服务器的UDP核心引擎
|
|
|
|
|
|
/// </summary>
|
2017-09-02 22:35:02 +08:00
|
|
|
|
private NetUdpServer net_udp_server { get; set; }
|
2017-06-07 16:20:40 +08:00
|
|
|
|
|
|
|
|
|
|
private void Net_Udp_Server_Initialization()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2017-09-02 22:35:02 +08:00
|
|
|
|
net_udp_server = new NetUdpServer();
|
|
|
|
|
|
net_udp_server.LogNet =new LogNetSingle(LogSavePath + @"\udp_log.txt");//日志路径
|
|
|
|
|
|
net_udp_server.LogNet.SetMessageDegree(HslMessageDegree.DEBUG);//默认debug及以上级别日志均进行存储,根据需要自行选择
|
2017-10-15 16:04:28 +08:00
|
|
|
|
net_udp_server.KeyToken = CommonLibrary.UserSystem.KeyToken;
|
2017-06-07 16:20:40 +08:00
|
|
|
|
net_udp_server.ReceiveCacheLength = 1024;//单次接收数据的缓冲长度
|
|
|
|
|
|
net_udp_server.AcceptByte += Net_udp_server_AcceptByte;//接收到字节数据的时候触发事件
|
|
|
|
|
|
net_udp_server.AcceptString += Net_udp_server_AcceptString;//接收到字符串数据的时候触发事件
|
2017-10-15 16:04:28 +08:00
|
|
|
|
net_udp_server.ServerStart(UserSystem.Port_Udp_Server);
|
2017-06-07 16:20:40 +08:00
|
|
|
|
}
|
2017-06-16 09:52:58 +08:00
|
|
|
|
catch (Exception ex)
|
2017-06-07 16:20:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
SoftBasic.ShowExceptionMessage(ex);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-19 22:16:44 +08:00
|
|
|
|
private void Net_udp_server_AcceptString(AsyncStateOne state, NetHandle customer, string data)
|
2017-06-07 16:20:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
//此处为测试
|
|
|
|
|
|
Invoke(new Action(() =>
|
|
|
|
|
|
{
|
2017-10-10 21:58:53 +08:00
|
|
|
|
textBox1.AppendText($"{DateTime.Now.ToString("MM-dd HH:mm:ss ")}来自IP:{state.IpEndPoint.Address.ToString()} 内容:{data}{Environment.NewLine}");
|
2017-06-07 16:20:40 +08:00
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-19 22:16:44 +08:00
|
|
|
|
private void Net_udp_server_AcceptByte(AsyncStateOne state, NetHandle customer, byte[] data)
|
2017-06-07 16:20:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
//具体用法参考上面字符串方法
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2017-04-06 16:18:46 +08:00
|
|
|
|
|
2017-05-19 18:28:04 +08:00
|
|
|
|
#region 访问PLC块示例代码
|
2017-05-18 18:32:45 +08:00
|
|
|
|
|
|
|
|
|
|
/*************************************************************************************************
|
|
|
|
|
|
*
|
|
|
|
|
|
* 以下展示一个高性能访问多台PLC数据的类,即使同时访问100台设备,性能也是非常高
|
|
|
|
|
|
*
|
|
|
|
|
|
* 该类没有仔细的在现场环境测试过,不保证完全可用
|
|
|
|
|
|
*
|
|
|
|
|
|
*************************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
HslCommunication.Profinet.MelsecNetMultiAsync MelsecMulti { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
private void MelsecNetMultiInnitialization()
|
|
|
|
|
|
{
|
2017-05-22 21:08:37 +08:00
|
|
|
|
List<System.Net.IPAddress> IpEndPoints = new List<System.Net.IPAddress>();
|
2017-05-18 18:32:45 +08:00
|
|
|
|
//增加100台需要访问的三菱设备,指定所有设备IP和端口,注意:顺序很重要
|
|
|
|
|
|
for (int i = 1; i < 100; i++)
|
|
|
|
|
|
{
|
2017-05-22 21:08:37 +08:00
|
|
|
|
IpEndPoints.Add(System.Net.IPAddress.Parse("192.168.10." + i));
|
2017-05-18 18:32:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-05-28 22:29:29 +08:00
|
|
|
|
//每隔1秒钟访问一次,读取的地址为D6000-D6019,超时时间为700毫秒,主端口为6000,备用端口为6001
|
2017-05-22 21:08:37 +08:00
|
|
|
|
MelsecMulti = new HslCommunication.Profinet.MelsecNetMultiAsync(0, 0, HslCommunication.Profinet.MelsecDataType.D, 6000, 20, 700, 1000, IpEndPoints.ToArray(), 6000, 6001);
|
2017-05-19 10:20:10 +08:00
|
|
|
|
MelsecMulti.OnReceivedData += MelsecMulti_OnReceivedData;//所有机台的数据都返回时触发
|
2017-05-18 18:32:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void MelsecMulti_OnReceivedData(byte[] object1)
|
|
|
|
|
|
{
|
|
|
|
|
|
/*********************************************************************************************
|
|
|
|
|
|
*
|
|
|
|
|
|
* 正常情况下,一秒触发一次,object1包含了所有机台读取到的数据
|
|
|
|
|
|
* 比如每台设备读取D6000开始20个D,如上述指令所示
|
|
|
|
|
|
* 那么每台设备数据长度为20*2+2=42个byte,100台设备就是4200字节长度
|
|
|
|
|
|
* 也就是说,object1的0-41字节是第一台设备的,以此类推
|
|
|
|
|
|
* 每台设备的前两个字节都为0才说明本次数据访问正常,为0x00,0x01说明连接失败,其他说明说明三菱本身的异常
|
|
|
|
|
|
*
|
|
|
|
|
|
********************************************************************************************/
|
2017-05-19 10:20:10 +08:00
|
|
|
|
for (int i = 0; i < 100; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int startIndex = i * 42;
|
2017-10-01 15:59:37 +08:00
|
|
|
|
ushort netState = BitConverter.ToUInt16(object1, startIndex);// 为0,说明数据正常,不为0说明网络访问失败或是指令出错
|
2017-05-18 18:32:45 +08:00
|
|
|
|
|
2017-05-19 10:20:10 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
2017-05-18 18:32:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2017-05-19 18:28:04 +08:00
|
|
|
|
#region 流水号生成示例代码
|
2017-05-18 18:32:45 +08:00
|
|
|
|
|
2017-05-19 18:28:04 +08:00
|
|
|
|
private SoftNumericalOrder OrderAutoCreate { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 流水号初始化方法,如果需要可以放到窗口的load方法中
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void OrderInitialization()
|
|
|
|
|
|
{
|
|
|
|
|
|
/*********************************************************************************************************
|
|
|
|
|
|
*
|
|
|
|
|
|
* 说明 此处的时间格式是年月日,7是指跟在时间后面的序号的位数,不够补零
|
|
|
|
|
|
* 示例1 调用 string str = OrderAutoCreate.GetNumericalOrder();//str为 AB201705190000001
|
|
|
|
|
|
* 示例2 调用 string str = OrderAutoCreate.GetNumericalOrder("KN");//str为 KN201705190000002
|
|
|
|
|
|
* 注意 默认计数不清空,后面的1,2会一值累加,可以调用900亿亿次,如果需要定期清空,请自行周期调用OrderAutoCreate.ClearNumericalOrder();
|
|
|
|
|
|
* 提示 如果需要定期清空,在本页面的ThreadTimeTick()方法中清空即可
|
2017-10-01 15:59:37 +08:00
|
|
|
|
* 性能 一秒钟可以响应请求100万次以上,具体值依据电脑的性能而定,并成功存储当前计数值
|
2017-05-19 18:28:04 +08:00
|
|
|
|
*
|
|
|
|
|
|
**********************************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
OrderAutoCreate = new SoftNumericalOrder("AB", "yyyyMMdd", 7, Application.StartupPath + @"\order.txt");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-06-19 21:57:25 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 服务器临时聊天消息存储块
|
|
|
|
|
|
|
|
|
|
|
|
private SoftMsgQueue<string> Chats_Managment { get; set; }
|
|
|
|
|
|
|
2017-06-21 18:00:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 聊天消息块的初始化
|
|
|
|
|
|
/// </summary>
|
2017-06-19 21:57:25 +08:00
|
|
|
|
private void ChatInitialization()
|
|
|
|
|
|
{
|
|
|
|
|
|
Chats_Managment = new SoftMsgQueue<string>()
|
|
|
|
|
|
{
|
|
|
|
|
|
MaxCache = 200,//记录200条临时消息
|
|
|
|
|
|
FileSavePath = Application.StartupPath + @"\chats.txt"//设置保存的路径
|
|
|
|
|
|
};
|
|
|
|
|
|
Chats_Managment.LoadByFile();//加载以前的数据
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-06-21 18:00:00 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 新增一个消息,需要指明发送人和消息内容
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="user">消息发送人</param>
|
|
|
|
|
|
/// <param name="message">内容</param>
|
2017-06-29 11:01:14 +08:00
|
|
|
|
private void ChatAddMessage(string user, string message)
|
2017-06-20 11:26:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
string content = "\u0002" + user + DateTime.Now.ToString(" yyyy-MM-dd HH:mm:ss") + Environment.NewLine + " " + message;
|
|
|
|
|
|
//转发所有的客户端,包括发送者
|
|
|
|
|
|
net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.留言版消息, content);
|
|
|
|
|
|
//添加缓存
|
|
|
|
|
|
Chats_Managment.AddNewItem(content);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 如果需要发送一些系统自己的消息,请调用这个方法。
|
|
|
|
|
|
/// 一般来说将系统消息和用户聊天消息进行区分
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="message">消息</param>
|
|
|
|
|
|
private void ChatAddMessage(string message)
|
|
|
|
|
|
{
|
|
|
|
|
|
ChatAddMessage("[系统]", message);
|
|
|
|
|
|
}
|
2017-06-19 21:57:25 +08:00
|
|
|
|
|
2017-05-19 18:28:04 +08:00
|
|
|
|
#endregion
|
2017-05-18 18:32:45 +08:00
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
#region System Log Function
|
2017-06-27 15:08:32 +08:00
|
|
|
|
|
2017-05-18 18:32:45 +08:00
|
|
|
|
|
2017-05-30 14:29:19 +08:00
|
|
|
|
/*********************************************************************************************************
|
|
|
|
|
|
*
|
2017-10-01 15:59:37 +08:00
|
|
|
|
* 说明 日志的使用方式分为6个等级,1.DEBUG 2.INFO 3.WARN 4.ERROR 5.FATAL 6.None 对应的调用方法不一致
|
2017-09-02 22:35:02 +08:00
|
|
|
|
* 具体 如果想要调用存储[信息]等级日志,调用 RuntimeLogHelper.WriteInfo("等待存储的信息")
|
2017-05-30 14:29:19 +08:00
|
|
|
|
* 大小 调用10000次存储信息后,日志文件大小在200K左右,需要手动进行情况日志
|
2017-06-17 17:32:55 +08:00
|
|
|
|
* 注意 在存储信息时不要带有一个特殊字符,[\u0002]不可见的标识文本开始字符,会影响日志筛选时的准确性
|
2017-06-21 18:00:00 +08:00
|
|
|
|
* 性能 该类使用了乐观并发模型技术,支持高并发的数据存储,可以安全的在线程间调用
|
2017-05-30 14:29:19 +08:00
|
|
|
|
*
|
|
|
|
|
|
**********************************************************************************************************/
|
2017-05-18 18:32:45 +08:00
|
|
|
|
|
2017-03-22 19:50:11 +08:00
|
|
|
|
/// <summary>
|
2017-05-05 23:07:44 +08:00
|
|
|
|
/// 用来记录一般的事物日志
|
2017-03-22 19:50:11 +08:00
|
|
|
|
/// </summary>
|
2017-09-02 22:35:02 +08:00
|
|
|
|
private ILogNet RuntimeLogHelper { get; set; }
|
2017-06-27 15:08:32 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用来记录客户端的异常日志
|
|
|
|
|
|
/// </summary>
|
2017-09-02 22:35:02 +08:00
|
|
|
|
private ILogNet ClientsLogHelper { get; set; }
|
2017-06-27 15:08:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
2017-06-29 11:01:14 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
#region Mail Send Function
|
2017-06-29 11:01:14 +08:00
|
|
|
|
|
|
|
|
|
|
/******************************************************************************************
|
|
|
|
|
|
*
|
2017-10-01 15:59:37 +08:00
|
|
|
|
* 本邮件系统使用了组件中预设好的中间发送地址,已经内置了两个邮件地址,一个163邮箱,另一个是QQ邮箱
|
2017-06-29 11:01:14 +08:00
|
|
|
|
* 本处仅仅使用了163网易的邮箱发送
|
|
|
|
|
|
* 下面提供了两个方法,实现了方便的发送,可以在程序的其他地方进行调用
|
|
|
|
|
|
*
|
|
|
|
|
|
********************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 控制系统是否真的发送邮件到指定地址
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private bool IsSendMailEnable { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 邮件发送系统的初始方式,所有的参数将在下面进行
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void SoftMailInitialization()
|
|
|
|
|
|
{
|
2017-09-18 17:35:59 +08:00
|
|
|
|
IsSendMailEnable = false;// 先进行关闭
|
|
|
|
|
|
SoftMail.MailSystem163.MailSendAddress = "hsl200909@163.com";// 作者测试的邮箱地址,实际需要换成你自己的
|
2017-06-29 11:01:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 调用该方法可以直接将异常发送到你的邮箱里,如果服务器连接网络的话
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="ex">异常</param>
|
2017-06-29 11:01:14 +08:00
|
|
|
|
private void SendUserMail(Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(IsSendMailEnable) SoftMail.MailSystem163.SendMail(ex);
|
|
|
|
|
|
}
|
2017-10-01 15:59:37 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 发送指定的主题和内容到指定的邮箱
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="subject">主题</param>
|
|
|
|
|
|
/// <param name="body">内容</param>
|
2017-06-29 11:01:14 +08:00
|
|
|
|
private void SendUserMail(string subject, string body)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsSendMailEnable) SoftMail.MailSystem163.SendMail(subject, body);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-06-27 15:08:32 +08:00
|
|
|
|
#endregion
|
2017-07-02 18:48:35 +08:00
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
|
2017-02-22 14:30:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|