2017-07-12 11:08:30 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using HslCommunication.Enthernet;
|
|
|
|
|
|
using HslCommunication.BasicFramework;
|
|
|
|
|
|
using CommonLibrary;
|
2017-09-17 21:59:45 +08:00
|
|
|
|
using System.Net;
|
2017-09-24 12:42:45 +08:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Windows.Forms;
|
2017-10-06 13:30:28 +08:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
2017-07-12 11:08:30 +08:00
|
|
|
|
|
|
|
|
|
|
namespace ClientsLibrary
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2017-09-03 11:29:48 +08:00
|
|
|
|
|
|
|
|
|
|
/***********************************************************************************
|
|
|
|
|
|
*
|
|
|
|
|
|
* 说明:用来存储客户端全局的变量数据,好在任何界面都可以直达数据
|
2017-10-15 16:04:28 +08:00
|
|
|
|
* 专门放在这下面的数据是需要支持winform和wpf共同访问的
|
2017-09-03 11:29:48 +08:00
|
|
|
|
*
|
|
|
|
|
|
*
|
|
|
|
|
|
***********************************************************************************/
|
|
|
|
|
|
|
2017-07-12 11:08:30 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-09-15 22:41:53 +08:00
|
|
|
|
/// 一个通用的用户客户端类, 包含了一些静态的资源
|
2017-07-12 11:08:30 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class UserClient
|
|
|
|
|
|
{
|
2017-09-15 22:41:53 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 客户端需要进行本地存储的信息日志
|
|
|
|
|
|
/// </summary>
|
2017-07-12 11:08:30 +08:00
|
|
|
|
public static JsonSettings JsonSettings = new JsonSettings();
|
2017-09-19 22:16:44 +08:00
|
|
|
|
|
2017-09-03 11:29:48 +08:00
|
|
|
|
|
2017-07-12 11:08:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 本软件的当前版本,用来验证更新的关键依据
|
|
|
|
|
|
/// </summary>
|
2017-10-26 09:58:44 +08:00
|
|
|
|
public static SystemVersion CurrentVersion { get; } = new SystemVersion("1.0.0.171026");
|
2017-09-19 22:16:44 +08:00
|
|
|
|
|
2017-09-03 11:29:48 +08:00
|
|
|
|
|
2017-07-12 11:08:30 +08:00
|
|
|
|
/// <summary>
|
2017-09-19 10:37:17 +08:00
|
|
|
|
/// 服务器的IP地址,默认为127.0.0.1,可用于单机调试,
|
|
|
|
|
|
/// 云服务器端:117.48.203.204,注意,云端为最新版,客户端版本比较旧会调试失败
|
2017-07-12 11:08:30 +08:00
|
|
|
|
/// </summary>
|
2017-10-09 22:18:51 +08:00
|
|
|
|
public static string ServerIp { get; } = "117.48.203.204"; // 用于测试的云服务器地址
|
2017-09-19 22:16:44 +08:00
|
|
|
|
|
2017-09-03 11:29:48 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 系统的分厂信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static List<string> SystemFactories { get; set; } = new List<string>();
|
2017-09-19 22:16:44 +08:00
|
|
|
|
|
2017-09-03 11:29:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
2017-09-17 21:59:45 +08:00
|
|
|
|
|
2017-07-12 11:08:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 所有版本更新信息的对象
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static List<VersionInfo> HistoryVersions { get; } = new List<VersionInfo>
|
|
|
|
|
|
{
|
2017-09-15 22:41:53 +08:00
|
|
|
|
// 写入所有的历史版本信息,这样就能在更新日志的界面查看到信息
|
2017-07-12 11:08:30 +08:00
|
|
|
|
new VersionInfo()
|
|
|
|
|
|
{
|
2017-10-01 15:59:37 +08:00
|
|
|
|
VersionNum = new SystemVersion("1.0.0"),
|
2017-10-09 22:18:51 +08:00
|
|
|
|
ReleaseDate = new DateTime(2017, 10, 1), // 该版本发布的日期
|
2017-10-01 15:59:37 +08:00
|
|
|
|
UpdateDetails = new StringBuilder(
|
2017-09-03 11:29:48 +08:00
|
|
|
|
"1.本系统第一版本正式发布使用。"+Environment.NewLine+
|
2017-07-12 11:08:30 +08:00
|
|
|
|
"2.提供了多客户端用时在线的功能。"+Environment.NewLine+
|
2017-10-01 15:59:37 +08:00
|
|
|
|
"3.支持个人的文件管理功能。"),
|
2017-07-12 11:08:30 +08:00
|
|
|
|
},
|
|
|
|
|
|
};
|
2017-09-19 22:16:44 +08:00
|
|
|
|
|
2017-07-12 11:08:30 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置或获取系统的公告
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static string Announcement { get; set; } = "";
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 当前系统的登录账户
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static UserAccount UserAccount { get; set; } = new UserAccount();
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 服务器的时间,该时间与服务器同步,每隔10秒钟,防止客户端串改单机时间,可以作为各种时间条件判定
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static DateTime DateTimeServer { get; set; } = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用于访问服务器数据的网络对象类,必须修改这个端口参数,否则运行失败
|
|
|
|
|
|
/// </summary>
|
2017-09-17 21:59:45 +08:00
|
|
|
|
public static NetSimplifyClient Net_simplify_client { get; set; } = new NetSimplifyClient(
|
2017-10-15 16:04:28 +08:00
|
|
|
|
new IPEndPoint(IPAddress.Parse(ServerIp), UserSystem.Port_Second_Net))
|
2017-07-12 11:08:30 +08:00
|
|
|
|
{
|
2017-10-15 16:04:28 +08:00
|
|
|
|
KeyToken = UserSystem.KeyToken,
|
2017-07-12 11:08:30 +08:00
|
|
|
|
ConnectTimeout = 5000,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用于使用udp向服务器进行发送即时可丢失数据的对象
|
|
|
|
|
|
/// </summary>
|
2017-09-17 21:59:45 +08:00
|
|
|
|
public static NetUdpClient Net_Udp_Client { get; set; } = new NetUdpClient(
|
2017-10-15 16:04:28 +08:00
|
|
|
|
new IPEndPoint(IPAddress.Parse(ServerIp), UserSystem.Port_Udp_Server))
|
2017-07-12 11:08:30 +08:00
|
|
|
|
{
|
2017-10-15 16:04:28 +08:00
|
|
|
|
KeyToken = UserSystem.KeyToken,
|
2017-07-12 11:08:30 +08:00
|
|
|
|
};
|
2017-07-12 13:13:43 +08:00
|
|
|
|
|
2017-09-17 21:59:45 +08:00
|
|
|
|
|
2017-10-06 13:30:28 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 检查当前账户是否有role角色的权限
|
|
|
|
|
|
/// </summary>
|
2017-10-07 21:32:23 +08:00
|
|
|
|
/// <param name="roleCode">角色名称</param>
|
2017-10-06 13:30:28 +08:00
|
|
|
|
/// <returns></returns>
|
2017-10-07 21:32:23 +08:00
|
|
|
|
public static bool CheckUserAccountRole(string roleCode)
|
2017-10-06 13:30:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
JObject json = new JObject
|
|
|
|
|
|
{
|
|
|
|
|
|
{ "Name", UserAccount.UserName },
|
2017-10-07 21:32:23 +08:00
|
|
|
|
{ "Role", roleCode }
|
2017-10-06 13:30:28 +08:00
|
|
|
|
};
|
2017-11-22 14:18:35 +08:00
|
|
|
|
HslCommunication.OperateResult<string> result = Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode.检查角色权限,
|
2017-10-06 13:30:28 +08:00
|
|
|
|
json.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
if(result.IsSuccess)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(result.Content.ToUpper() == "TRUE")
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-14 21:21:33 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 头像管理器
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static UserPortrait PortraitManager { get; set; }
|
2017-10-01 15:59:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用于绝大部分用途的文件上传下载操作
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static IntegrationFileClient Net_File_Client { get; set; } = new IntegrationFileClient()
|
|
|
|
|
|
{
|
2017-10-15 16:04:28 +08:00
|
|
|
|
KeyToken = UserSystem.KeyToken,
|
2017-10-01 15:59:37 +08:00
|
|
|
|
LogNet = LogNet,
|
2017-10-15 16:04:28 +08:00
|
|
|
|
ServerIpEndPoint = new IPEndPoint(IPAddress.Parse(ServerIp), UserSystem.Port_Ultimate_File_Server)
|
2017-10-01 15:59:37 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2017-09-17 21:59:45 +08:00
|
|
|
|
/// <summary>
|
2017-10-01 15:59:37 +08:00
|
|
|
|
/// 目前仅仅用于上传客户端更新文件操作
|
2017-09-17 21:59:45 +08:00
|
|
|
|
/// </summary>
|
2017-10-01 15:59:37 +08:00
|
|
|
|
public static IntegrationFileClient Net_Update_Client { get; set; } = new IntegrationFileClient()
|
2017-09-17 21:59:45 +08:00
|
|
|
|
{
|
2017-10-15 16:04:28 +08:00
|
|
|
|
KeyToken = UserSystem.KeyToken,
|
2017-09-17 21:59:45 +08:00
|
|
|
|
LogNet = LogNet,
|
2017-10-15 16:04:28 +08:00
|
|
|
|
ServerIpEndPoint = new IPEndPoint(IPAddress.Parse(ServerIp), UserSystem.Port_Advanced_File_Server)
|
2017-09-17 21:59:45 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
|
2017-09-13 21:08:18 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 客户端的日志纪录对象
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static HslCommunication.LogNet.ILogNet LogNet { get; set; }
|
2017-07-12 13:13:43 +08:00
|
|
|
|
|
2017-09-03 11:29:48 +08:00
|
|
|
|
|
2017-10-01 15:59:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
2017-09-03 11:29:48 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用来处理客户端发生的未捕获的异常,将通过网络组件发送至服务器存储,用于更好的跟踪错误
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
2017-07-12 13:13:43 +08:00
|
|
|
|
public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.ExceptionObject is Exception ex)
|
|
|
|
|
|
{
|
2017-10-01 15:59:37 +08:00
|
|
|
|
// 使用TCP方法传送回服务器
|
2017-09-02 22:35:02 +08:00
|
|
|
|
string info = HslCommunication.LogNet.LogNetManagment.GetSaveStringFromException(null, ex);
|
|
|
|
|
|
Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode.异常消息, info);
|
2017-07-12 13:13:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-10-15 16:04:28 +08:00
|
|
|
|
|
2017-09-24 12:42:45 +08:00
|
|
|
|
|
2017-07-12 11:08:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|