完成小头像管理器,优化我的信息头像加载器,v1.6.13
This commit is contained in:
@@ -13,6 +13,7 @@ using HslCommunication;
|
|||||||
using HslCommunication.BasicFramework;
|
using HslCommunication.BasicFramework;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using ClientsLibrary.FileSupport;
|
using ClientsLibrary.FileSupport;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace ClientsLibrary
|
namespace ClientsLibrary
|
||||||
{
|
{
|
||||||
@@ -21,11 +22,10 @@ namespace ClientsLibrary
|
|||||||
|
|
||||||
#region Constructor
|
#region Constructor
|
||||||
|
|
||||||
public FormAccountDetails(UserPortrait userPortrait)
|
public FormAccountDetails()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
Icon = UserClient.GetFormWindowIcon();
|
Icon = UserClient.GetFormWindowIcon();
|
||||||
UserPortrait = userPortrait;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -107,47 +107,202 @@ namespace ClientsLibrary
|
|||||||
|
|
||||||
#region Load Portrait
|
#region Load Portrait
|
||||||
|
|
||||||
public UserPortrait UserPortrait { get; }
|
|
||||||
|
|
||||||
|
|
||||||
private void pictureBox_UserPortrait_Click(object sender, EventArgs e)
|
private void pictureBox_UserPortrait_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
UserPortrait.ChangePortrait(LoadLargeProtrait,UnloadLargeProtrait);
|
// UserPortrait.ChangePortrait(LoadLargeProtrait,UnloadLargeProtrait);
|
||||||
|
using (FormPortraitSelect fps = new FormPortraitSelect())
|
||||||
|
{
|
||||||
|
if (fps.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
string FileSavePath = Application.StartupPath + @"\Portrait\" + UserClient.UserAccount.UserName;
|
||||||
|
|
||||||
|
string path300 = FileSavePath + @"\" + PortraitSupport.LargePortrait;
|
||||||
|
string path32 = FileSavePath + @"\" + PortraitSupport.SmallPortrait;
|
||||||
|
|
||||||
|
|
||||||
|
Bitmap bitmap300 = fps.GetSpecifiedSizeImage(300);
|
||||||
|
Bitmap bitmap32 = fps.GetSpecifiedSizeImage(32);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bitmap300.Save(path300, System.Drawing.Imaging.ImageFormat.Png);
|
||||||
|
bitmap32.Save(path32, System.Drawing.Imaging.ImageFormat.Png);
|
||||||
|
bitmap32.Dispose();
|
||||||
|
bitmap300.Dispose();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// 文件被占用的时候无法进行覆盖
|
||||||
|
UserClient.LogNet?.WriteException("头像保存失败!", ex);
|
||||||
|
MessageBox.Show("头像保存失败,原因:" + ex.Message);
|
||||||
|
|
||||||
|
// 加载回旧的文件
|
||||||
|
pictureBox_UserPortrait.Load(path300);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 传送服务器
|
||||||
|
using (FormFileOperate ffo = new FormFileOperate(
|
||||||
|
UserClient.Net_File_Client,
|
||||||
|
new string[]
|
||||||
|
{
|
||||||
|
path300,
|
||||||
|
path32
|
||||||
|
}, "Files", "Portrait", UserClient.UserAccount.UserName))
|
||||||
|
{
|
||||||
|
ffo.ShowDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadPool.QueueUserWorkItem(new WaitCallback(obj =>
|
||||||
|
{
|
||||||
|
// 上传文件MD5码
|
||||||
|
string SmallPortraitMD5 = "";
|
||||||
|
string LargePortraitMD5 = "";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SmallPortraitMD5 = SoftBasic.CalculateFileMD5(path32);
|
||||||
|
LargePortraitMD5 = SoftBasic.CalculateFileMD5(path300);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
UserClient.LogNet.WriteException("获取文件MD5码失败:", ex);
|
||||||
|
MessageBox.Show("文件信息确认失败,请重新上传!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JObject json = new JObject
|
||||||
|
{
|
||||||
|
{ UserAccount.UserNameText, new JValue(UserClient.UserAccount.UserName) },
|
||||||
|
{ UserAccount.SmallPortraitText, new JValue(SmallPortraitMD5) },
|
||||||
|
{ UserAccount.LargePortraitText, new JValue(LargePortraitMD5) }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(
|
||||||
|
CommonHeadCode.SimplifyHeadCode.上传头像MD5,
|
||||||
|
json.ToString());
|
||||||
|
|
||||||
|
if (result.IsSuccess)
|
||||||
|
{
|
||||||
|
if (result.Content.Substring(0, 2) == "成功")
|
||||||
|
{
|
||||||
|
UserClient.UserAccount.SmallPortraitMD5 = SmallPortraitMD5;
|
||||||
|
UserClient.UserAccount.LargePortraitMD5 = LargePortraitMD5;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("上传头像失败!原因:" + result.Content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("上传头像失败!原因:" + result.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 先显示信息
|
||||||
|
try
|
||||||
|
{
|
||||||
|
pictureBox_UserPortrait.Image = new Bitmap(new System.IO.MemoryStream(File.ReadAllBytes(path300)));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ThreadPoolLoadLargePortrait(object obj)
|
private void ThreadPoolLoadLargePortrait(object obj)
|
||||||
{
|
{
|
||||||
Thread.Sleep(200);
|
// 先获取服务器端的MD5码
|
||||||
UserPortrait.LoadUserLargePortraint(LoadLargeProtrait, UnloadLargeProtrait);
|
string fileServerMd5 = UserClient.UserAccount.LargePortraitMD5;
|
||||||
}
|
if (string.IsNullOrEmpty(fileServerMd5))
|
||||||
|
|
||||||
private void UnloadLargeProtrait()
|
|
||||||
{
|
|
||||||
if (IsHandleCreated && InvokeRequired)
|
|
||||||
{
|
{
|
||||||
BeginInvoke(new Action(() =>
|
return; // 没有文件
|
||||||
{
|
|
||||||
UnloadLargeProtrait();
|
|
||||||
}));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pictureBox_UserPortrait.Image = null;
|
string fileName = Application.StartupPath + @"\Portrait\" + UserClient.UserAccount.UserName + @"\" + PortraitSupport.LargePortrait;
|
||||||
}
|
if(File.Exists(fileName))
|
||||||
|
|
||||||
private void LoadLargeProtrait(string fileName)
|
|
||||||
{
|
|
||||||
if (IsHandleCreated && InvokeRequired)
|
|
||||||
{
|
{
|
||||||
BeginInvoke(new Action(() =>
|
bool loadSuccess = false;
|
||||||
|
Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
LoadLargeProtrait(fileName);
|
try
|
||||||
|
{
|
||||||
|
pictureBox_UserPortrait.Image = new Bitmap(new MemoryStream(File.ReadAllBytes(fileName)));
|
||||||
|
loadSuccess = true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
return;
|
|
||||||
|
if (!loadSuccess) goto P1; // 加载不成功,直接重新下载
|
||||||
|
|
||||||
|
// 计算md5
|
||||||
|
string md5 = string.Empty;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
md5 = SoftBasic.CalculateFileMD5(fileName);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(md5 == UserClient.UserAccount.LargePortraitMD5)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
P1:
|
||||||
|
MemoryStream ms = new MemoryStream();
|
||||||
|
OperateResult result = UserClient.Net_File_Client.DownloadFile(
|
||||||
|
PortraitSupport.LargePortrait,
|
||||||
|
"Files",
|
||||||
|
"Portrait",
|
||||||
|
UserClient.UserAccount.UserName,
|
||||||
|
null,
|
||||||
|
ms
|
||||||
|
);
|
||||||
|
|
||||||
|
if(result.IsSuccess)
|
||||||
|
{
|
||||||
|
if(IsHandleCreated) Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
// 下载完成
|
||||||
|
Bitmap bitmap = new Bitmap(ms);
|
||||||
|
pictureBox_UserPortrait.Image = bitmap;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bitmap.Save(fileName);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 下载异常,丢弃
|
||||||
}
|
}
|
||||||
|
|
||||||
pictureBox_UserPortrait.ImageLocation = fileName;
|
ms.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace ClientsLibrary
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 头像管理类
|
/// 头像管理器,负责所有小头像数据的缓存
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UserPortrait
|
public class UserPortrait
|
||||||
{
|
{
|
||||||
@@ -37,7 +37,7 @@ namespace ClientsLibrary
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filePath">头像存储的文件夹路径</param>
|
/// <param name="filePath">头像存储的文件夹路径</param>
|
||||||
/// <param name="loadPicSmall">加载头像的委托</param>
|
/// <param name="loadPicSmall">加载头像的委托</param>
|
||||||
public UserPortrait(string filePath, Action<Bitmap> loadPicSmall)
|
public UserPortrait(string filePath)
|
||||||
{
|
{
|
||||||
if (!System.IO.Directory.Exists(filePath))
|
if (!System.IO.Directory.Exists(filePath))
|
||||||
{
|
{
|
||||||
@@ -45,229 +45,10 @@ namespace ClientsLibrary
|
|||||||
}
|
}
|
||||||
FileSavePath = filePath;
|
FileSavePath = filePath;
|
||||||
|
|
||||||
m_LoadPicSmall = loadPicSmall;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Change Portrait
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 点击更改头像后的操作,打开头像选择对话框,获取到2种分辨率的头像,然后进行上传
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="loadPic">加载大头像的委托</param>
|
|
||||||
/// <param name="unloadPic">卸载大头像的委托</param>
|
|
||||||
public void ChangePortrait(Action<string> loadPic, Action unloadPic)
|
|
||||||
{
|
|
||||||
using (FormPortraitSelect fps = new FormPortraitSelect())
|
|
||||||
{
|
|
||||||
if (fps.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
string path300 = FileSavePath + @"\" + PortraitSupport.LargePortrait;
|
|
||||||
string path32 = FileSavePath + @"\" + PortraitSupport.SmallPortrait;
|
|
||||||
|
|
||||||
// 先卸载图片
|
|
||||||
unloadPic?.Invoke();
|
|
||||||
|
|
||||||
Bitmap bitmap300 = fps.GetSpecifiedSizeImage(300);
|
|
||||||
Bitmap bitmap32 = fps.GetSpecifiedSizeImage(32);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
bitmap300.Save(path300);
|
|
||||||
bitmap32.Save(path32);
|
|
||||||
bitmap32.Dispose();
|
|
||||||
bitmap300.Dispose();
|
|
||||||
}
|
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
// 文件被占用的时候无法进行覆盖
|
|
||||||
UserClient.LogNet?.WriteException("头像保存失败!", ex);
|
|
||||||
MessageBox.Show("头像保存失败,原因:" + ex.Message);
|
|
||||||
|
|
||||||
// 加载回旧的文件
|
|
||||||
loadPic?.Invoke(path300);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 传送服务器
|
|
||||||
|
|
||||||
using (FormFileOperate ffo = new FormFileOperate(
|
|
||||||
UserClient.Net_File_Client,
|
|
||||||
new string[]
|
|
||||||
{
|
|
||||||
path300,
|
|
||||||
path32
|
|
||||||
}, "Files", "Portrait", UserClient.UserAccount.UserName))
|
|
||||||
{
|
|
||||||
ffo.ShowDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
ThreadPool.QueueUserWorkItem(new WaitCallback(obj =>
|
|
||||||
{
|
|
||||||
// 上传文件MD5码
|
|
||||||
string SmallPortraitMD5 = "";
|
|
||||||
string LargePortraitMD5 = "";
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SmallPortraitMD5 = SoftBasic.CalculateFileMD5(path32);
|
|
||||||
LargePortraitMD5 = SoftBasic.CalculateFileMD5(path300);
|
|
||||||
}
|
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
UserClient.LogNet.WriteException("获取文件MD5码失败:", ex);
|
|
||||||
MessageBox.Show("文件信息确认失败,请重新上传!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
JObject json = new JObject
|
|
||||||
{
|
|
||||||
{ UserAccount.UserNameText, new JValue(UserClient.UserAccount.UserName) },
|
|
||||||
{ UserAccount.SmallPortraitText, new JValue(SmallPortraitMD5) },
|
|
||||||
{ UserAccount.LargePortraitText, new JValue(LargePortraitMD5) }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(
|
|
||||||
CommonHeadCode.SimplifyHeadCode.上传头像MD5,
|
|
||||||
json.ToString());
|
|
||||||
|
|
||||||
if (result.IsSuccess)
|
|
||||||
{
|
|
||||||
if (result.Content.Substring(0, 2) == "成功")
|
|
||||||
{
|
|
||||||
UserClient.UserAccount.SmallPortraitMD5 = SmallPortraitMD5;
|
|
||||||
UserClient.UserAccount.LargePortraitMD5 = LargePortraitMD5;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("上传头像失败!原因:" + result.Content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("上传头像失败!原因:" + result.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 先显示信息
|
|
||||||
loadPic?.Invoke(path300);
|
|
||||||
LoadUserSmallPortraint();
|
|
||||||
}), null);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Load Portraint
|
|
||||||
|
|
||||||
public static Bitmap DownloadSmallPortraint(string userName)
|
|
||||||
{
|
|
||||||
Bitmap bitmap = null;
|
|
||||||
|
|
||||||
System.IO.MemoryStream ms = new System.IO.MemoryStream();
|
|
||||||
|
|
||||||
OperateResult result = UserClient.Net_File_Client.DownloadFile(
|
|
||||||
PortraitSupport.SmallPortrait,
|
|
||||||
"Files",
|
|
||||||
"Portrait",
|
|
||||||
userName,
|
|
||||||
null,
|
|
||||||
ms
|
|
||||||
);
|
|
||||||
if (result.IsSuccess)
|
|
||||||
{
|
|
||||||
bitmap = new Bitmap(ms);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bitmap = Properties.Resources.person_1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ms.Dispose();
|
|
||||||
|
|
||||||
return bitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 加载小尺寸的头像操作,需要放置到线程池中
|
|
||||||
/// </summary>
|
|
||||||
public void LoadUserSmallPortraint()
|
|
||||||
{
|
|
||||||
m_LoadPicSmall?.Invoke(DownloadSmallPortraint(UserClient.UserAccount.UserName));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 加载大尺寸的头像方法,需要放到线程池中操作
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="largeLoadAction"></param>
|
|
||||||
public void LoadUserLargePortraint(Action<string> largeLoadAction, Action largeUnloadAction)
|
|
||||||
{
|
|
||||||
// 先获取服务器端的MD5码
|
|
||||||
string fileMd5 = UserClient.UserAccount.LargePortraitMD5;
|
|
||||||
if (string.IsNullOrEmpty(fileMd5))
|
|
||||||
{
|
|
||||||
// 服务器端没有文件,加载结束
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取本地MD5
|
|
||||||
string fileName = FileSavePath + @"\" + PortraitSupport.LargePortrait;
|
|
||||||
if (System.IO.File.Exists(fileName))
|
|
||||||
{
|
|
||||||
// 本地存在文件,先进行加载,如果运算不一致,再重新加载
|
|
||||||
largeLoadAction?.Invoke(fileName);
|
|
||||||
string currentMd5 = null;
|
|
||||||
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
currentMd5 = SoftBasic.CalculateFileMD5(fileName);
|
|
||||||
}
|
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show("计算文件MD5码错误:" + ex.Message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 对比验证
|
|
||||||
if (fileMd5 == currentMd5)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
largeUnloadAction?.Invoke();
|
|
||||||
|
|
||||||
// 本地不存在文件或校验失败,需要重新下载
|
|
||||||
OperateResult result = UserClient.Net_File_Client.DownloadFile(PortraitSupport.LargePortrait,
|
|
||||||
"Files",
|
|
||||||
"Portrait",
|
|
||||||
UserClient.UserAccount.UserName,
|
|
||||||
null,
|
|
||||||
fileName);
|
|
||||||
|
|
||||||
if (result.IsSuccess)
|
|
||||||
{
|
|
||||||
// 下载成功
|
|
||||||
largeLoadAction?.Invoke(fileName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("头像从服务器下载失败,错误原因:" + result.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Download Portraint
|
#region Download Portraint
|
||||||
|
|
||||||
|
|
||||||
@@ -323,19 +104,62 @@ namespace ClientsLibrary
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Method
|
#region Pricvate Method
|
||||||
/// <summary>
|
|
||||||
///
|
private void SetSmallPortrait(string name,Bitmap bitmap)
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public string GetLargePortraitFileName()
|
|
||||||
{
|
{
|
||||||
return FileSavePath + @"\" + PortraitSupport.LargePortrait;
|
hybirdLock.Enter();
|
||||||
|
|
||||||
|
if(dictSmallPortrait.ContainsKey(name))
|
||||||
|
{
|
||||||
|
dictSmallPortrait[name] = bitmap;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dictSmallPortrait.Add(name, bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
hybirdLock.Leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetSmallPortraitFileName()
|
private Bitmap DownloadSmallPortraitByName(string name)
|
||||||
{
|
{
|
||||||
return FileSavePath + @"\" + PortraitSupport.SmallPortrait;
|
OperateResult result = UserClient.Net_File_Client.DownloadFile(
|
||||||
|
PortraitSupport.SmallPortrait,
|
||||||
|
"Files",
|
||||||
|
"Portrait",
|
||||||
|
name,
|
||||||
|
null,
|
||||||
|
out Bitmap bitmap);
|
||||||
|
if (result.IsSuccess)
|
||||||
|
{
|
||||||
|
SetSmallPortrait(name, bitmap);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Properties.Resources.person_1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateSmallPortraitByName(string name)
|
||||||
|
{
|
||||||
|
DownloadSmallPortraitByName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap GetSmallPortraitByUserName(string name)
|
||||||
|
{
|
||||||
|
Bitmap bitmap = null;
|
||||||
|
hybirdLock.Enter();
|
||||||
|
if (dictSmallPortrait.ContainsKey(name))
|
||||||
|
{
|
||||||
|
bitmap = dictSmallPortrait[name];
|
||||||
|
}
|
||||||
|
hybirdLock.Leave();
|
||||||
|
|
||||||
|
if (bitmap != null) return bitmap;
|
||||||
|
|
||||||
|
return DownloadSmallPortraitByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -346,11 +170,9 @@ namespace ClientsLibrary
|
|||||||
/// 文件的路径
|
/// 文件的路径
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private string FileSavePath { get; set; }
|
private string FileSavePath { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
private Dictionary<string, Bitmap> dictSmallPortrait = new Dictionary<string, Bitmap>();
|
||||||
/// 加载小头像的委托
|
private SimpleHybirdLock hybirdLock = new SimpleHybirdLock();
|
||||||
/// </summary>
|
|
||||||
private Action<Bitmap> m_LoadPicSmall { get; set; }
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,33 +77,14 @@ namespace ClientsLibrary.BasicSupport
|
|||||||
// 向服务器请求小头像
|
// 向服务器请求小头像
|
||||||
if (m_NetAccount != null)
|
if (m_NetAccount != null)
|
||||||
{
|
{
|
||||||
try
|
Bitmap bitmap = UserClient.PortraitManager.GetSmallPortraitByUserName(m_NetAccount.UserName);
|
||||||
{
|
|
||||||
System.IO.MemoryStream ms = new System.IO.MemoryStream();
|
|
||||||
|
|
||||||
HslCommunication.OperateResult result = UserClient.Net_File_Client.DownloadFile(
|
if(IsHandleCreated)
|
||||||
PortraitSupport.SmallPortrait,
|
|
||||||
"Files",
|
|
||||||
"Portrait",
|
|
||||||
m_NetAccount.UserName,
|
|
||||||
null,
|
|
||||||
ms
|
|
||||||
);
|
|
||||||
if (result.IsSuccess)
|
|
||||||
{
|
|
||||||
Bitmap bitmap = new Bitmap(ms);
|
|
||||||
pictureBox1.Image = bitmap;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 可能网络错误,也可能因为服务器没有头像
|
|
||||||
// MessageBox.Show(result.Message);
|
|
||||||
pictureBox1.Image = Properties.Resources.person_1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message);
|
Invoke(new Action(() =>
|
||||||
|
{
|
||||||
|
pictureBox1.Image = bitmap;
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace ClientsLibrary
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 本软件的当前版本,用来验证更新的关键依据
|
/// 本软件的当前版本,用来验证更新的关键依据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static SystemVersion CurrentVersion { get; } = new SystemVersion("1.0.0.171013");
|
public static SystemVersion CurrentVersion { get; } = new SystemVersion("1.0.0.171014");
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -133,8 +133,10 @@ namespace ClientsLibrary
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 头像管理器
|
||||||
|
/// </summary>
|
||||||
|
public static UserPortrait PortraitManager { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace CommonLibrary
|
|||||||
*
|
*
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
SoftBasic.FrameworkVersion = new SystemVersion("1.6.12");
|
SoftBasic.FrameworkVersion = new SystemVersion("1.6.13");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -706,6 +706,20 @@
|
|||||||
<param name="filePath"></param>
|
<param name="filePath"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:HslCommunication.BasicFramework.SoftBasic.CalculateStreamMD5(System.IO.Stream)">
|
||||||
|
<summary>
|
||||||
|
获取数据流的md5码
|
||||||
|
</summary>
|
||||||
|
<param name="stream">数据流,可以是内存流,也可以是文件流</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:HslCommunication.BasicFramework.SoftBasic.CalculateStreamMD5(System.Drawing.Bitmap)">
|
||||||
|
<summary>
|
||||||
|
获取内存图片的md5码
|
||||||
|
</summary>
|
||||||
|
<param name="bitmap">内存图片</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:HslCommunication.BasicFramework.SoftBasic.GetSizeDescription(System.Int64)">
|
<member name="M:HslCommunication.BasicFramework.SoftBasic.GetSizeDescription(System.Int64)">
|
||||||
<summary>
|
<summary>
|
||||||
从一个字节大小返回带单位的描述
|
从一个字节大小返回带单位的描述
|
||||||
@@ -2147,23 +2161,23 @@
|
|||||||
<param name="id"></param>
|
<param name="id"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:HslCommunication.Enthernet.FileClientBase.DownloadFileBase(System.String,System.String,System.String,System.String,System.Action{System.Int64,System.Int64},System.String)">
|
<member name="M:HslCommunication.Enthernet.FileClientBase.DownloadFileBase(System.String,System.String,System.String,System.String,System.Action{System.Int64,System.Int64},System.Object)">
|
||||||
<summary>
|
<summary>
|
||||||
基础下载文件信息
|
基础下载信息
|
||||||
</summary>
|
</summary>
|
||||||
<param name="factory"></param>
|
<param name="factory"></param>
|
||||||
<param name="group"></param>
|
<param name="group"></param>
|
||||||
<param name="id"></param>
|
<param name="id"></param>
|
||||||
<param name="fileName">服务器的文件名称</param>
|
<param name="fileName">服务器的文件名称</param>
|
||||||
<param name="processReport">下载的进度报告</param>
|
<param name="processReport">下载的进度报告</param>
|
||||||
<param name="fileSaveName">本地保存的文件名称,包含完整路径名</param>
|
<param name="source">数据源信息,决定最终存储到哪里去</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:HslCommunication.Enthernet.FileClientBase.UploadFileBase(System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.Action{System.Int64,System.Int64})">
|
<member name="M:HslCommunication.Enthernet.FileClientBase.UploadFileBase(System.Object,System.String,System.String,System.String,System.String,System.String,System.String,System.Action{System.Int64,System.Int64})">
|
||||||
<summary>
|
<summary>
|
||||||
上传文件给服务器
|
上传文件给服务器
|
||||||
</summary>
|
</summary>
|
||||||
<param name="fileName">本地完整路径的文件名</param>
|
<param name="source">数据源,可以是文件名,也可以是数据流</param>
|
||||||
<param name="serverName">在服务器保存的文件名,不包含驱动器路径</param>
|
<param name="serverName">在服务器保存的文件名,不包含驱动器路径</param>
|
||||||
<param name="factory"></param>
|
<param name="factory"></param>
|
||||||
<param name="group"></param>
|
<param name="group"></param>
|
||||||
@@ -2212,6 +2226,18 @@
|
|||||||
<param name="stream">流数据</param>
|
<param name="stream">流数据</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:HslCommunication.Enthernet.IntegrationFileClient.DownloadFile(System.String,System.String,System.String,System.String,System.Action{System.Int64,System.Int64},System.Drawing.Bitmap@)">
|
||||||
|
<summary>
|
||||||
|
下载服务器的文件到本地的数据流中
|
||||||
|
</summary>
|
||||||
|
<param name="fileName">文件名称,带后缀</param>
|
||||||
|
<param name="factory">第一大类</param>
|
||||||
|
<param name="group">第二大类</param>
|
||||||
|
<param name="id">第三大类</param>
|
||||||
|
<param name="processReport">下载的进度报告</param>
|
||||||
|
<param name="bitmap">内存文件</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:HslCommunication.Enthernet.IntegrationFileClient.UploadFile(System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.Action{System.Int64,System.Int64})">
|
<member name="M:HslCommunication.Enthernet.IntegrationFileClient.UploadFile(System.String,System.String,System.String,System.String,System.String,System.String,System.String,System.Action{System.Int64,System.Int64})">
|
||||||
<summary>
|
<summary>
|
||||||
上传本地的文件到服务器操作
|
上传本地的文件到服务器操作
|
||||||
@@ -2226,6 +2252,35 @@
|
|||||||
<param name="processReport">上传的进度报告</param>
|
<param name="processReport">上传的进度报告</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:HslCommunication.Enthernet.IntegrationFileClient.UploadFile(System.IO.Stream,System.String,System.String,System.String,System.String,System.String,System.String,System.Action{System.Int64,System.Int64})">
|
||||||
|
<summary>
|
||||||
|
上传数据流到服务器操作
|
||||||
|
</summary>
|
||||||
|
<param name="stream">数据流内容</param>
|
||||||
|
<param name="serverName">服务器存储的文件名称,带后缀</param>
|
||||||
|
<param name="factory">第一大类</param>
|
||||||
|
<param name="group">第二大类</param>
|
||||||
|
<param name="id">第三大类</param>
|
||||||
|
<param name="fileTag">文件的额外描述</param>
|
||||||
|
<param name="fileUpload">文件的上传人</param>
|
||||||
|
<param name="processReport">上传的进度报告</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:HslCommunication.Enthernet.IntegrationFileClient.UploadFile(System.Drawing.Bitmap,System.String,System.String,System.String,System.String,System.String,System.String,System.Action{System.Int64,System.Int64})">
|
||||||
|
<summary>
|
||||||
|
上传内存图片到服务器操作
|
||||||
|
</summary>
|
||||||
|
<param name="bitmap">内存图片,不能为空</param>
|
||||||
|
<param name="serverName">服务器存储的文件名称,带后缀</param>
|
||||||
|
<param name="factory">第一大类</param>
|
||||||
|
<param name="group">第二大类</param>
|
||||||
|
<param name="id">第三大类</param>
|
||||||
|
<param name="fileTag">文件的额外描述</param>
|
||||||
|
<param name="fileUpload">文件的上传人</param>
|
||||||
|
<param name="processReport">上传的进度报告</param>
|
||||||
|
<returns></returns>
|
||||||
|
<exception cref="T:System.ArgumentNullException"></exception>
|
||||||
|
</member>
|
||||||
<member name="M:HslCommunication.Enthernet.IntegrationFileClient.TranslateFileName(System.String,System.String,System.String,System.String)">
|
<member name="M:HslCommunication.Enthernet.IntegrationFileClient.TranslateFileName(System.String,System.String,System.String,System.String)">
|
||||||
<summary>
|
<summary>
|
||||||
根据三种分类信息,还原成在服务器的相对路径,包含文件
|
根据三种分类信息,还原成在服务器的相对路径,包含文件
|
||||||
@@ -3900,6 +3955,20 @@
|
|||||||
<param name="failedString"></param>
|
<param name="failedString"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:HslCommunication.NetShareBase.SendFileAndCheckReceive(System.Net.Sockets.Socket,System.IO.Stream,System.String,System.String,System.String,HslCommunication.OperateResult,System.Action{System.Int64,System.Int64},System.String)">
|
||||||
|
<summary>
|
||||||
|
[自校验] 将流数据发送至套接字,具体发送细节将在继承类中实现,如果结果异常,则结束通讯
|
||||||
|
</summary>
|
||||||
|
<param name="socket">套接字</param>
|
||||||
|
<param name="stream">文件名称,文件必须存在</param>
|
||||||
|
<param name="servername">远程端的文件名称</param>
|
||||||
|
<param name="filetag">文件的额外标签</param>
|
||||||
|
<param name="fileupload">文件的上传人</param>
|
||||||
|
<param name="result">操作结果对象</param>
|
||||||
|
<param name="sendReport">发送进度报告</param>
|
||||||
|
<param name="failedString"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:HslCommunication.NetShareBase.ReceiveAndCheckBytes(System.Net.Sockets.Socket,System.Byte[]@,System.Byte[]@,HslCommunication.OperateResult,System.Action{System.Int64,System.Int64},System.String)">
|
<member name="M:HslCommunication.NetShareBase.ReceiveAndCheckBytes(System.Net.Sockets.Socket,System.Byte[]@,System.Byte[]@,HslCommunication.OperateResult,System.Action{System.Int64,System.Int64},System.String)">
|
||||||
<summary>
|
<summary>
|
||||||
[自校验] 接收一条完整的同步数据,包含头子节和内容字节,基础的数据,如果结果异常,则结束通讯
|
[自校验] 接收一条完整的同步数据,包含头子节和内容字节,基础的数据,如果结果异常,则结束通讯
|
||||||
|
|||||||
35
软件系统客户端Wpf/AppWpfHelper.cs
Normal file
35
软件系统客户端Wpf/AppWpfHelper.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
|
namespace 软件系统客户端Wpf
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************************
|
||||||
|
*
|
||||||
|
* 说明:用于开发一些wpf专有的方法,一些转换方法
|
||||||
|
*
|
||||||
|
***********************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class AppWpfHelper
|
||||||
|
{
|
||||||
|
public static BitmapImage TranslateImageToBitmapImage(System.Drawing.Bitmap bitmap)
|
||||||
|
{
|
||||||
|
System.IO.MemoryStream ms = new System.IO.MemoryStream();
|
||||||
|
if(bitmap.RawFormat != null) bitmap.Save(ms, bitmap.RawFormat);
|
||||||
|
else bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
|
||||||
|
BitmapImage bi = new BitmapImage();
|
||||||
|
bi.BeginInit();
|
||||||
|
bi.StreamSource = ms;
|
||||||
|
bi.EndInit();
|
||||||
|
return bi;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -70,6 +70,8 @@ namespace 软件系统客户端Wpf
|
|||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
UserClient.PortraitManager = new UserPortrait(AppDomain.CurrentDomain.BaseDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -112,10 +114,10 @@ namespace 软件系统客户端Wpf
|
|||||||
//窗口显示
|
//窗口显示
|
||||||
IsWindowShow = true;
|
IsWindowShow = true;
|
||||||
|
|
||||||
//udp测试
|
// udp测试
|
||||||
//SendServerUdpData(0, "显示了窗体");
|
// SendServerUdpData(0, "显示了窗体");
|
||||||
|
|
||||||
//是否显示更新日志,显示前进行判断该版本是否已经显示过了
|
// 是否显示更新日志,显示前进行判断该版本是否已经显示过了
|
||||||
if (!UserClient.JsonSettings.IsNewVersionRunning)
|
if (!UserClient.JsonSettings.IsNewVersionRunning)
|
||||||
{
|
{
|
||||||
UserClient.JsonSettings.IsNewVersionRunning = false;
|
UserClient.JsonSettings.IsNewVersionRunning = false;
|
||||||
@@ -126,7 +128,7 @@ namespace 软件系统客户端Wpf
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//根据权限使能菜单
|
// 根据权限使能菜单
|
||||||
if(UserClient.UserAccount.Grade < AccountGrade.Admin)
|
if(UserClient.UserAccount.Grade < AccountGrade.Admin)
|
||||||
{
|
{
|
||||||
MenuItem公告管理.IsEnabled = false;
|
MenuItem公告管理.IsEnabled = false;
|
||||||
@@ -145,15 +147,15 @@ namespace 软件系统客户端Wpf
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//启动网络服务
|
// 启动网络服务
|
||||||
Net_Socket_Client_Initialization();
|
Net_Socket_Client_Initialization();
|
||||||
//启动定时器
|
// 启动定时器
|
||||||
TimeTickInitilization();
|
TimeTickInitilization();
|
||||||
//显示头像
|
|
||||||
SoftUserPortraitInitialization();
|
|
||||||
SoftUserPortrait.LoadUserSmallPortraint();
|
|
||||||
|
|
||||||
|
// 显示名称和加载头像
|
||||||
AccountChip.Content = UserClient.UserAccount.UserName;
|
AccountChip.Content = UserClient.UserAccount.UserName;
|
||||||
|
AccountPortrait.Source = AppWpfHelper.TranslateImageToBitmapImage(
|
||||||
|
UserClient.PortraitManager.GetSmallPortraitByUserName(UserClient.UserAccount.UserName));
|
||||||
|
|
||||||
SetShowRenderControl(UIControl_Home);
|
SetShowRenderControl(UIControl_Home);
|
||||||
}
|
}
|
||||||
@@ -328,7 +330,7 @@ namespace 软件系统客户端Wpf
|
|||||||
|
|
||||||
private void MenuItem我的信息_Click(object sender, RoutedEventArgs e)
|
private void MenuItem我的信息_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
using (FormAccountDetails form = new FormAccountDetails(SoftUserPortrait))
|
using (FormAccountDetails form = new FormAccountDetails())
|
||||||
{
|
{
|
||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
}
|
}
|
||||||
@@ -403,8 +405,17 @@ namespace 软件系统客户端Wpf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AccountChip_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
// 点击了头像,请求查看高清版本头像
|
||||||
|
using (FormMatterRemind fmr = new FormMatterRemind("正在下载图片", UserClient.PortraitManager.ThreadPoolDownloadSizeLarge))
|
||||||
|
{
|
||||||
|
fmr.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 异步网络块
|
#region 异步网络块
|
||||||
|
|
||||||
private NetComplexClient net_socket_client = new NetComplexClient();
|
private NetComplexClient net_socket_client = new NetComplexClient();
|
||||||
@@ -544,8 +555,14 @@ namespace 软件系统客户端Wpf
|
|||||||
}
|
}
|
||||||
else if(customer == CommonHeadCode.MultiNetHeadCode.新头像更新)
|
else if(customer == CommonHeadCode.MultiNetHeadCode.新头像更新)
|
||||||
{
|
{
|
||||||
|
UserClient.PortraitManager.UpdateSmallPortraitByName(data);
|
||||||
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
|
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
|
if (data == UserClient.UserAccount.UserName)
|
||||||
|
{
|
||||||
|
AccountPortrait.Source = AppWpfHelper.TranslateImageToBitmapImage(
|
||||||
|
UserClient.PortraitManager.GetSmallPortraitByUserName(data));
|
||||||
|
}
|
||||||
foreach (Views.Controls.UserClientRenderItem m in ClientsOnline.Children)
|
foreach (Views.Controls.UserClientRenderItem m in ClientsOnline.Children)
|
||||||
{
|
{
|
||||||
m.UpdatePortrait(data);
|
m.UpdatePortrait(data);
|
||||||
@@ -694,50 +711,7 @@ namespace 软件系统客户端Wpf
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 头像图片上传下载块
|
|
||||||
|
|
||||||
|
|
||||||
private UserPortrait SoftUserPortrait { get; set; }
|
|
||||||
|
|
||||||
private void SoftUserPortraitInitialization()
|
|
||||||
{
|
|
||||||
SoftUserPortrait = new UserPortrait(AppDomain.CurrentDomain.BaseDirectory +
|
|
||||||
@"Portrait\" + UserClient.UserAccount.UserName, ShowSmallPortrait);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ShowSmallPortrait(System.Drawing.Bitmap bitmap)
|
|
||||||
{
|
|
||||||
if (IsWindowShow) Dispatcher.Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
MemoryStream ms = new MemoryStream();
|
|
||||||
bitmap.Save(ms, bitmap.RawFormat);
|
|
||||||
bitmap.Dispose();
|
|
||||||
|
|
||||||
BitmapImage bi = new BitmapImage();
|
|
||||||
bi.BeginInit();
|
|
||||||
bi.StreamSource = ms;
|
|
||||||
bi.EndInit();
|
|
||||||
|
|
||||||
AccountPortrait.Source = bi;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void AccountChip_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
// 点击了头像,请求查看高清版本头像
|
|
||||||
using (FormMatterRemind fmr = new FormMatterRemind("正在下载图片", SoftUserPortrait.ThreadPoolDownloadSizeLarge))
|
|
||||||
{
|
|
||||||
fmr.ShowDialog();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 多界面管理块
|
#region 多界面管理块
|
||||||
|
|
||||||
private List<UserControl> all_main_render = new List<UserControl>();
|
private List<UserControl> all_main_render = new List<UserControl>();
|
||||||
|
|||||||
@@ -100,26 +100,11 @@ namespace 软件系统客户端Wpf.Views.Controls
|
|||||||
// 向服务器请求小头像
|
// 向服务器请求小头像
|
||||||
if (obj is NetAccount m_NetAccount)
|
if (obj is NetAccount m_NetAccount)
|
||||||
{
|
{
|
||||||
try
|
System.Drawing.Bitmap bitmap = UserClient.PortraitManager.GetSmallPortraitByUserName(m_NetAccount.UserName);
|
||||||
|
Dispatcher.Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
System.Drawing.Bitmap bitmap = UserPortrait.DownloadSmallPortraint(m_NetAccount.UserName);
|
Image1.Source = AppWpfHelper.TranslateImageToBitmapImage(bitmap);
|
||||||
MemoryStream ms = new MemoryStream();
|
}));
|
||||||
bitmap.Save(ms, bitmap.RawFormat);
|
|
||||||
bitmap.Dispose();
|
|
||||||
|
|
||||||
Dispatcher.Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
BitmapImage bi = new BitmapImage();
|
|
||||||
bi.BeginInit();
|
|
||||||
bi.StreamSource = ms;
|
|
||||||
bi.EndInit();
|
|
||||||
Image1.Source = bi;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
UserClient.LogNet?.WriteException("Thread Download Portrait Failed", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,7 @@
|
|||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</ApplicationDefinition>
|
</ApplicationDefinition>
|
||||||
|
<Compile Include="AppWpfHelper.cs" />
|
||||||
<Compile Include="Views\AnotherCommandImplementation.cs" />
|
<Compile Include="Views\AnotherCommandImplementation.cs" />
|
||||||
<Compile Include="Views\Controls\UserClientRenderItem.xaml.cs">
|
<Compile Include="Views\Controls\UserClientRenderItem.xaml.cs">
|
||||||
<DependentUpon>UserClientRenderItem.xaml</DependentUpon>
|
<DependentUpon>UserClientRenderItem.xaml</DependentUpon>
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ namespace 软件系统客户端模版
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
Icon = UserClient.GetFormWindowIcon();
|
Icon = UserClient.GetFormWindowIcon();
|
||||||
|
|
||||||
|
// 初始化头像管理器
|
||||||
|
UserClient.PortraitManager = new UserPortrait(Application.StartupPath + @"\Portrait\" + UserClient.UserAccount.UserName);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -139,12 +142,12 @@ namespace 软件系统客户端模版
|
|||||||
|
|
||||||
// 启动网络服务
|
// 启动网络服务
|
||||||
Net_Socket_Client_Initialization();
|
Net_Socket_Client_Initialization();
|
||||||
// 启动头像
|
|
||||||
SoftUserPortraitInitialization();
|
|
||||||
// 启动定时器
|
// 启动定时器
|
||||||
TimeTickInitilization();
|
TimeTickInitilization();
|
||||||
|
|
||||||
|
|
||||||
// 显示头像
|
// 显示头像
|
||||||
SoftUserPortrait.LoadUserSmallPortraint();
|
pictureBox1.Image = UserClient.PortraitManager.GetSmallPortraitByUserName(UserClient.UserAccount.UserName);
|
||||||
}
|
}
|
||||||
private void FormMainWindow_FormClosing(object sender, FormClosingEventArgs e)
|
private void FormMainWindow_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
{
|
{
|
||||||
@@ -327,7 +330,7 @@ namespace 软件系统客户端模版
|
|||||||
|
|
||||||
private void 我的信息ToolStripMenuItem_Click(object sender, EventArgs e)
|
private void 我的信息ToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
using (FormAccountDetails form = new FormAccountDetails(SoftUserPortrait))
|
using (FormAccountDetails form = new FormAccountDetails())
|
||||||
{
|
{
|
||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
}
|
}
|
||||||
@@ -349,6 +352,15 @@ namespace 软件系统客户端模版
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void pictureBox1_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
//点击了头像,请求下载高清版本头像
|
||||||
|
using (FormMatterRemind fmr = new FormMatterRemind("正在下载图片", UserClient.PortraitManager.ThreadPoolDownloadSizeLarge))
|
||||||
|
{
|
||||||
|
fmr.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 异步网络块
|
#region 异步网络块
|
||||||
@@ -468,8 +480,13 @@ namespace 软件系统客户端模版
|
|||||||
}
|
}
|
||||||
else if(customer == CommonHeadCode.MultiNetHeadCode.新头像更新)
|
else if(customer == CommonHeadCode.MultiNetHeadCode.新头像更新)
|
||||||
{
|
{
|
||||||
|
UserClient.PortraitManager.UpdateSmallPortraitByName(data);
|
||||||
if (IsHandleCreated) Invoke(new Action(() =>
|
if (IsHandleCreated) Invoke(new Action(() =>
|
||||||
{
|
{
|
||||||
|
if(data == UserClient.UserAccount.UserName)
|
||||||
|
{
|
||||||
|
pictureBox1.Image = UserClient.PortraitManager.GetSmallPortraitByUserName(data);
|
||||||
|
}
|
||||||
netClientOnline1.ClientUpdatePortrait(data);
|
netClientOnline1.ClientUpdatePortrait(data);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -724,59 +741,6 @@ namespace 软件系统客户端模版
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 头像图片上传下载块
|
|
||||||
|
|
||||||
|
|
||||||
private UserPortrait SoftUserPortrait { get; set; }
|
|
||||||
|
|
||||||
private void SoftUserPortraitInitialization()
|
|
||||||
{
|
|
||||||
SoftUserPortrait = new UserPortrait(Application.StartupPath +
|
|
||||||
@"\Portrait\" + UserClient.UserAccount.UserName, LoadSmallProtraitAsync);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void LoadSmallProtraitAsync(Bitmap bitmap)
|
|
||||||
{
|
|
||||||
if (IsHandleCreated && InvokeRequired)
|
|
||||||
{
|
|
||||||
Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
LoadSmallProtraitAsync(bitmap);
|
|
||||||
}));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pictureBox1.Image = bitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UnloadSmallProtrait()
|
|
||||||
{
|
|
||||||
if (IsHandleCreated && InvokeRequired)
|
|
||||||
{
|
|
||||||
Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
UnloadSmallProtrait();
|
|
||||||
}));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pictureBox1.Image = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void pictureBox1_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
//点击了头像,请求下载高清版本头像
|
|
||||||
using (FormMatterRemind fmr = new FormMatterRemind("正在下载图片", SoftUserPortrait.ThreadPoolDownloadSizeLarge))
|
|
||||||
{
|
|
||||||
fmr.ShowDialog();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user