代码整理重构,修复个人文件下载失败的BUG,发布版本1.4.0

This commit is contained in:
dathlin
2017-09-19 10:37:17 +08:00
parent 379d38d0eb
commit de13c87afe
14 changed files with 129 additions and 139 deletions

View File

@@ -45,7 +45,7 @@ namespace ClientsLibrary
textBox_UserName.Text = UserClient.UserAccount.UserName;
// 加载头像
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadPoolLoadPortrait), null);
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadPoolLoadLargePortrait), null);
// 加载文件列表
DownloadUserFileNames();
@@ -95,15 +95,14 @@ namespace ClientsLibrary
}
private void ThreadPoolLoadPortrait(object obj)
{
UserPortrait.LoadUserLargePortraint(LoadPortraitByFileName);
}
private void pictureBox_UserPortrait_Click(object sender, EventArgs e)
{
UserPortrait.ChangePortrait();
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadPoolLoadLargePortrait), null);
}
private void ThreadPoolLoadLargePortrait(object obj)
{
UserPortrait.LoadUserLargePortraint(LoadPortraitByFileName);
}
@@ -185,7 +184,7 @@ namespace ClientsLibrary
"Files",
"Personal",
UserClient.UserAccount.UserName,
folderBrowserDialog.SelectedPath + "\\" + treeNode.Text
folderBrowserDialog.SelectedPath
);
download.ShowDialog();
}
@@ -197,7 +196,7 @@ namespace ClientsLibrary
{
// 删除选中文件
TreeNode treeNode = treeView1.SelectedNode;
if (treeNode.Name != "file_root")
if (treeNode.Name != "files_root")
{
using (FormPasswordCheck passwordCheck = new FormPasswordCheck(UserClient.UserAccount.Password))
{

View File

@@ -85,9 +85,23 @@ namespace ClientsLibrary
ffo.ShowDialog();
}
ThreadPool.QueueUserWorkItem(new WaitCallback(obj =>
{
// 上传文件MD5码
string SmallPortraitMD5 = SoftBasic.CalculateFileMD5(path32);
string LargePortraitMD5 = SoftBasic.CalculateFileMD5(path300);
string SmallPortraitMD5 = ""; SoftBasic.CalculateFileMD5(path32);
string LargePortraitMD5 = ""; SoftBasic.CalculateFileMD5(path300);
try
{
SmallPortraitMD5 = SoftBasic.CalculateFileMD5(path32);
LargePortraitMD5 = SoftBasic.CalculateFileMD5(path300);
}
catch(Exception ex)
{
UserClient.LogNet.WriteException("获取文件MD5码失败", ex);
MessageBox.Show("文件信息确认失败,请重新上传!");
return;
}
JObject json = new JObject
{
@@ -96,6 +110,7 @@ namespace ClientsLibrary
{ UserAccount.LargePortraitText, new JValue(LargePortraitMD5) }
};
OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(
CommonHeadCode.SimplifyHeadCode.MD5,
json.ToString());
@@ -119,7 +134,10 @@ namespace ClientsLibrary
MessageBox.Show("上传头像失败!原因:" + result.Message);
}
}), null);
}
}
}

View File

@@ -6,6 +6,7 @@ using HslCommunication.Enthernet;
using HslCommunication.BasicFramework;
using CommonLibrary;
using System.Net;
using CommonLibrary;
namespace ClientsLibrary
{
@@ -37,9 +38,10 @@ namespace ClientsLibrary
/// <summary>
/// 服务器的IP地址默认为127.0.0.1,可用于单机调试,云服务器端117.48.203.204
/// 服务器的IP地址默认为127.0.0.1,可用于单机调试,
/// 云服务器端117.48.203.204,注意,云端为最新版,客户端版本比较旧会调试失败
/// </summary>
public static string ServerIp { get; } = "117.48.203.204";//用于测试的云服务器地址
public static string ServerIp { get; } = "127.0.0.1";//用于测试的云服务器地址
/// <summary>
@@ -88,9 +90,9 @@ namespace ClientsLibrary
/// </summary>
public static NetSimplifyClient Net_simplify_client { get; set; } = new NetSimplifyClient(
new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ServerIp),
CommonLibrary.CommonLibrary.Port_Second_Net))
CommonLibrary.CommonProtocol.Port_Second_Net))
{
KeyToken = CommonHeadCode.KeyToken,
KeyToken = CommonLibrary.CommonProtocol.KeyToken,
ConnectTimeout = 5000,
};
@@ -99,9 +101,9 @@ namespace ClientsLibrary
/// </summary>
public static NetUdpClient Net_Udp_Client { get; set; } = new NetUdpClient(
new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ServerIp),
CommonLibrary.CommonLibrary.Port_Udp_Server))
CommonLibrary.CommonProtocol.Port_Udp_Server))
{
KeyToken = CommonHeadCode.KeyToken,
KeyToken = CommonLibrary.CommonProtocol.KeyToken,
};
@@ -110,9 +112,9 @@ namespace ClientsLibrary
/// </summary>
public static AdvancedFileClient Net_File_Client { get; set; } = new AdvancedFileClient()
{
KeyToken = CommonHeadCode.KeyToken,
KeyToken = CommonLibrary.CommonProtocol.KeyToken,
LogNet = LogNet,
ServerIpEndPoint = new IPEndPoint(IPAddress.Parse(ServerIp), CommonLibrary.CommonLibrary.Port_Advanced_File_Server)
ServerIpEndPoint = new IPEndPoint(IPAddress.Parse(ServerIp), CommonLibrary.CommonProtocol.Port_Advanced_File_Server)
};
/// <summary>

View File

@@ -72,7 +72,7 @@ namespace CommonLibrary
{
all_list_accounts[i].SmallPortraitMD5 = smallPortraitMD5;
all_list_accounts[i].LargePortraitMD5 = largePortraitMD5;
ILogNet?.WriteInfo(Resource.StringResouce.AccountModifyPassword + name);
ILogNet?.WriteInfo(Resource.StringResouce.AccountUploadPortrait + name);
break;
}
}

View File

@@ -274,14 +274,14 @@ namespace CommonLibrary
/// </summary>
public override void LoadByFile()
{
LoadByFile(m => SoftSecurity.MD5Decrypt(m, CommonLibrary.Security));
LoadByFile(m => SoftSecurity.MD5Decrypt(m, CommonProtocol.Security));
}
/// <summary>
/// 使用指定的加密实现数据加密
/// </summary>
public override void SaveToFile()
{
SaveToFile(m => SoftSecurity.MD5Encrypt(m, CommonLibrary.Security));
SaveToFile(m => SoftSecurity.MD5Encrypt(m, CommonProtocol.Security));
}

View File

@@ -86,8 +86,8 @@
<DependentUpon>FormVersionControl.cs</DependentUpon>
</Compile>
<Compile Include="BasicSupport\SoftSettings.cs" />
<Compile Include="Common.cs" />
<Compile Include="HeadCode.cs" />
<Compile Include="ProtocolSupport\Common.cs" />
<Compile Include="ProtocolSupport\HeadCode.cs" />
<Compile Include="OrderSupport\ClassGoods.cs" />
<Compile Include="OrderSupport\ClassOrder.cs" />
<Compile Include="PortraitSupport\PortraitSupport.cs" />

View File

@@ -6,9 +6,21 @@ using HslCommunication.BasicFramework;
namespace CommonLibrary
{
public class CommonLibrary
/*****************************************************************************************
*
*
*
*
*
*****************************************************************************************/
public class CommonProtocol
{
static CommonLibrary()
static CommonProtocol()
{
/**************************************************************************
*
@@ -39,7 +51,7 @@ namespace CommonLibrary
/**************************************************************************
*
* 2017914 22:06:27 1.4.0
* 2017919 22:06:27 1.4.0
*
**************************************************************************/
@@ -48,7 +60,20 @@ namespace CommonLibrary
}
#region
/************************************************************************************************
*
* GUID码
*
**************************************************************************************************/
/// <summary>
/// 用于整个网络服务交互的身份令牌,可有效的防止来自网络的攻击,重新生成令牌后就无法更改,否则不支持自动升级
/// </summary>
public static Guid KeyToken { get; set; } = new Guid("1275BB9A-14B2-4A96-9673-B0AF0463D474");
//======================================================================================
// 此处的所有的网络端口应该重新指定,防止其他人的项目连接到你的程序上
@@ -82,71 +107,13 @@ namespace CommonLibrary
/// 文件管理的服务器端口
/// </summary>
public static int Port_Advanced_File_Server { get; } = 24672;
#endregion
/// <summary>
/// 整个系统的加密解密密码
/// </summary>
public const string Security = "qwertyui";
}
/// <summary>
/// 选项类,包含了所有的标识和文本的对应关系
/// </summary>
public class BasicOptions
{
/// <summary>
/// 测试,用于生成数据状态的信息存储
/// </summary>
public static readonly List<BasicOptions> test = new List<BasicOptions>()
{
new BasicOptions(0,"测试一"),
new BasicOptions(1,"测试二"),
new BasicOptions(2,"测试三"),
};
/// <summary>
/// 实例化一个对象
/// </summary>
public BasicOptions()
{
}
/// <summary>
/// 根据信息实例化一个选项对象
/// </summary>
/// <param name="code"></param>
/// <param name="des"></param>
public BasicOptions(int code, string des)
{
IntegerCode = code;
Description = des;
}
/// <summary>
/// 整数的代号
/// </summary>
public int IntegerCode { get; set; } = 0;
/// <summary>
/// 代号描述的文本
/// </summary>
public string Description { get; set; } = string.Empty;
/// <summary>
/// 过去描述
/// </summary>
/// <returns></returns>
public override string ToString()
{
return Description;
}
public static string Security { get; } = "qwertyui";
}
}

View File

@@ -398,10 +398,10 @@ namespace 软件系统客户端Wpf
{
try
{
net_socket_client.KeyToken = CommonHeadCode.KeyToken;//新增的身份令牌
net_socket_client.KeyToken = CommonLibrary.CommonProtocol.KeyToken;//新增的身份令牌
net_socket_client.EndPointServer = new System.Net.IPEndPoint(
System.Net.IPAddress.Parse(UserClient.ServerIp),
CommonLibrary.CommonLibrary.Port_Main_Net);
CommonLibrary.CommonProtocol.Port_Main_Net);
net_socket_client.ClientAlias = $"{UserClient.UserAccount.UserName} ({UserClient.UserAccount.Factory})";//标记客户端在线的名称
net_socket_client.ClientStart();
}
@@ -608,8 +608,9 @@ namespace 软件系统客户端Wpf
#endregion
#region Udp发送示例
/// <summary>
/// 调用该方法并指定参数即可,最长字符串不得
/// 调用该方法并指定参数即可,最长字符串不得超过服务器定义的数据
/// </summary>
/// <param name="data"></param>
private void SendServerUdpData(int customer, string data)
@@ -760,6 +761,8 @@ namespace 软件系统客户端Wpf
#endregion
private void Button_BackMain_Click(object sender, RoutedEventArgs e)
{
//点击了主页

View File

@@ -57,10 +57,10 @@ namespace 软件系统客户端Wpf.Views
}
using (FormSimplyFileUpload upload = new FormSimplyFileUpload(
CommonHeadCode.KeyToken,
CommonLibrary.CommonProtocol.KeyToken,
UserClient.LogNet,
UserClient.ServerIp,
CommonLibrary.CommonLibrary.Port_Share_File,
CommonLibrary.CommonProtocol.Port_Share_File,
UserClient.UserAccount.UserName))
{
upload.ShowDialog();

View File

@@ -32,9 +32,9 @@ namespace 软件系统客户端Wpf.Views
fileClient = new SimpleFileClient()
{
KeyToken = CommonLibrary.CommonHeadCode.KeyToken,
KeyToken = CommonLibrary.CommonProtocol.KeyToken,
LogNet = UserClient.LogNet,
ServerIpEndPoint =new IPEndPoint(IPAddress.Parse(UserClient.ServerIp),CommonLibrary.CommonLibrary.Port_Advanced_File_Server)
ServerIpEndPoint =new IPEndPoint(IPAddress.Parse(UserClient.ServerIp),CommonLibrary.CommonProtocol.Port_Advanced_File_Server)
};
}

View File

@@ -337,10 +337,11 @@ namespace 软件系统客户端模版
{
try
{
net_socket_client.KeyToken = CommonHeadCode.KeyToken;//新增的身份令牌
net_socket_client.KeyToken = CommonLibrary.CommonProtocol.KeyToken;// 新增的身份令牌
net_socket_client.LogNet = UserClient.LogNet;
net_socket_client.EndPointServer = new System.Net.IPEndPoint(
System.Net.IPAddress.Parse(UserClient.ServerIp),
CommonLibrary.CommonLibrary.Port_Main_Net);
CommonLibrary.CommonProtocol.Port_Main_Net);
net_socket_client.ClientAlias = $"{UserClient.UserAccount.UserName} ({UserClient.UserAccount.Factory})";//标记客户端在线的名称
net_socket_client.ClientStart();
}

View File

@@ -34,10 +34,10 @@ namespace 软件系统客户端模版.UIControls
// 上传文件
using (FormSimplyFileUpload upload = new FormSimplyFileUpload(
CommonHeadCode.KeyToken,
CommonLibrary.CommonProtocol.KeyToken,
UserClient.LogNet,
UserClient.ServerIp,
CommonLibrary.CommonLibrary.Port_Share_File,
CommonLibrary.CommonProtocol.Port_Share_File,
UserClient.UserAccount.UserName))
{
upload.ShowDialog();
@@ -71,9 +71,9 @@ namespace 软件系统客户端模版.UIControls
foreach(var m in files)
{
FileItemShow item = new FileItemShow(
CommonHeadCode.KeyToken,
CommonLibrary.CommonProtocol.KeyToken,
UserClient.LogNet, UserClient.ServerIp,
CommonLibrary.CommonLibrary.Port_Share_File,
CommonLibrary.CommonProtocol.Port_Share_File,
() =>
{
if (m.UploadName != UserClient.UserAccount.UserName)

View File

@@ -344,9 +344,9 @@ namespace 软件系统服务端模版
net_soft_update_Server.LogNet = new LogNetSingle(LogSavePath + @"\update_log.txt");
//在服务器的这个路径下放置客户端运行的所有文件不要包含settings文件不要从此处运行
//只放置exe和dll组件必须放置软件自动更新.exe
net_soft_update_Server.KeyToken = CommonHeadCode.KeyToken;
net_soft_update_Server.KeyToken = CommonLibrary.CommonProtocol.KeyToken;
net_soft_update_Server.FileUpdatePath = Application.StartupPath + @"\ClientFiles";//客户端文件路径
net_soft_update_Server.ServerStart(CommonLibrary.CommonLibrary.Port_Update_Net);
net_soft_update_Server.ServerStart(CommonLibrary.CommonProtocol.Port_Update_Net);
}
catch (Exception ex)
{
@@ -384,8 +384,8 @@ namespace 软件系统服务端模版
net_file_Advanced.FilesDirectoryPath = Application.StartupPath;
net_file_Advanced.FilesDirectoryPathTemp = Application.StartupPath + @"\Temp";
net_file_Advanced.LogNet = new LogNetSingle(LogSavePath + @"\Advanced_file_log.txt");
net_file_Advanced.KeyToken = CommonHeadCode.KeyToken;
net_file_Advanced.ServerStart(CommonLibrary.CommonLibrary.Port_Advanced_File_Server);
net_file_Advanced.KeyToken = CommonLibrary.CommonProtocol.KeyToken;
net_file_Advanced.ServerStart(CommonLibrary.CommonProtocol.Port_Advanced_File_Server);
}
catch (Exception ex)
{
@@ -408,12 +408,12 @@ namespace 软件系统服务端模版
{
try
{
net_simplify_server.KeyToken = CommonHeadCode.KeyToken;//设置身份令牌
net_simplify_server.KeyToken = CommonLibrary.CommonProtocol.KeyToken;//设置身份令牌
net_simplify_server.LogNet = new LogNetSingle(LogSavePath + @"\simplify_log.txt");//日志路径
net_simplify_server.LogNet.SetMessageDegree(HslMessageDegree.DEBUG);//默认debug及以上级别日志均进行存储根据需要自行选择
net_simplify_server.ReceiveStringEvent += Net_simplify_server_ReceiveStringEvent;//接收到字符串触发
net_simplify_server.ReceivedBytesEvent += Net_simplify_server_ReceivedBytesEvent;//接收到字节触发
net_simplify_server.ServerStart(CommonLibrary.CommonLibrary.Port_Second_Net);
net_simplify_server.ServerStart(CommonLibrary.CommonProtocol.Port_Second_Net);
net_simplify_server.ConnectTimeout = 5200;
}
catch (Exception ex)
@@ -815,7 +815,7 @@ namespace 软件系统服务端模版
{
try
{
net_socket_server.KeyToken = CommonHeadCode.KeyToken;//设置身份令牌
net_socket_server.KeyToken = CommonLibrary.CommonProtocol.KeyToken;//设置身份令牌
net_socket_server.LogNet =new LogNetSingle(LogSavePath + @"\net_log.txt");
net_socket_server.LogNet.SetMessageDegree(HslMessageDegree.DEBUG);//默认debug及以上级别日志均进行存储根据需要自行选择
net_socket_server.FormatClientOnline = "#IP:{0} Name:{1}";//必须为#开头,具体格式可由自身需求确定
@@ -826,7 +826,7 @@ namespace 软件系统服务端模版
net_socket_server.MessageAlerts += new HslCommunication.NetBase.IEDelegate<string>(Net_socket_server_MessageAlerts);//服务器产生提示消息触发
net_socket_server.AcceptByte += new HslCommunication.NetBase.IEDelegate<AsyncStateOne, int, byte[]>(Net_socket_server_AcceptByte);//服务器接收到字节数据触发
net_socket_server.AcceptString += new HslCommunication.NetBase.IEDelegate<AsyncStateOne, int, string>(Net_socket_server_AcceptString);//服务器接收到字符串数据触发
net_socket_server.ServerStart(CommonLibrary.CommonLibrary.Port_Main_Net);
net_socket_server.ServerStart(CommonLibrary.CommonProtocol.Port_Main_Net);
}
catch (Exception ex)
{
@@ -1075,7 +1075,7 @@ namespace 软件系统服务端模版
//文件信息存储路径
FileListName = Application.StartupPath + @"\files.txt"
};
net_simple_file_server.KeyToken = CommonHeadCode.KeyToken;
net_simple_file_server.KeyToken = CommonLibrary.CommonProtocol.KeyToken;
net_simple_file_server.ReadFromFile();
net_simple_file_server.LogNet =new LogNetSingle(LogSavePath + @"\share_file_log.txt");
net_simple_file_server.LogNet.SetMessageDegree(HslMessageDegree.DEBUG);//默认debug及以上级别日志均进行存储根据需要自行选择
@@ -1083,7 +1083,7 @@ namespace 软件系统服务端模版
net_simple_file_server.FilesDirectoryPath = Application.StartupPath + @"\Files";
net_simple_file_server.FilesDirectoryPathTemp = Application.StartupPath + @"\Temp";
net_simple_file_server.FileChange += Net_simple_file_server_FileChange;
net_simple_file_server.ServerStart(CommonLibrary.CommonLibrary.Port_Share_File);
net_simple_file_server.ServerStart(CommonLibrary.CommonProtocol.Port_Share_File);
}
catch (Exception ex)
{
@@ -1144,11 +1144,11 @@ namespace 软件系统服务端模版
net_udp_server = new NetUdpServer();
net_udp_server.LogNet =new LogNetSingle(LogSavePath + @"\udp_log.txt");//日志路径
net_udp_server.LogNet.SetMessageDegree(HslMessageDegree.DEBUG);//默认debug及以上级别日志均进行存储根据需要自行选择
net_udp_server.KeyToken = CommonHeadCode.KeyToken;
net_udp_server.KeyToken = CommonLibrary.CommonProtocol.KeyToken;
net_udp_server.ReceiveCacheLength = 1024;//单次接收数据的缓冲长度
net_udp_server.AcceptByte += Net_udp_server_AcceptByte;//接收到字节数据的时候触发事件
net_udp_server.AcceptString += Net_udp_server_AcceptString;//接收到字符串数据的时候触发事件
net_udp_server.ServerStart(CommonLibrary.CommonLibrary.Port_Udp_Server);
net_udp_server.ServerStart(CommonLibrary.CommonProtocol.Port_Udp_Server);
}
catch (Exception ex)
{