📄 customemotionmanager.cs
字号:
{
node.Attributes["shortcut"].Value = emotion.ShortCut;
}
if (emotion.ExpireDate.get_HasValue() && (node.Attributes["expiredate"] != null))
{
node.Attributes["expiredate"].Value = emotion.ExpireDate.get_Value().ToString("yyyy-MM-dd HH:mm:ss");
}
}
this.SaveEmotionConfigXmlDocument(doc);
}
public CustomEmotionStatus UpdateOwnerEmotion(Imps.Client.Core.CustomEmotion.CustomEmotion emotion, string shortCut, string name)
{
if ((emotion.ShortCut != shortCut) || (emotion.Name != name))
{
if (emotion.ShortCut != shortCut)
{
if (!string.IsNullOrEmpty(shortCut))
{
Imps.Client.Core.CustomEmotion.CustomEmotion emotionByShortCut = this.OwnerEmotions.GetEmotionByShortCut(shortCut);
if ((emotionByShortCut != null) && (emotionByShortCut.Id != emotion.Id))
{
return CustomEmotionStatus.ShortCutExist;
}
if (ImpsEmoticons.Instance.ContainsKey(shortCut))
{
return CustomEmotionStatus.ShortCutExistSystemEmotion;
}
if (this.ExistSameStartShortCutInSystemEmotions(shortCut))
{
return CustomEmotionStatus.ExistSameStartShortInSystemEmotions;
}
if (this.ExistSameStartShortCut(shortCut, emotion.Id))
{
return CustomEmotionStatus.ExistSameStartShort;
}
}
this.OwnerEmotions.UpdateEmotionsByShortCut(emotion, shortCut);
emotion.ShortCut = shortCut;
this.OwnerEmotions.Sort();
this.OwnerEmotions.SortShortCuts();
}
if (emotion.Name != name)
{
emotion.Name = name;
}
this.UpdateEmotionConfig(emotion);
}
return CustomEmotionStatus.OK;
}
private void UploadAfterCheckInThread(object data)
{
List<Imps.Client.Core.CustomEmotion.CustomEmotion> list = data as List<Imps.Client.Core.CustomEmotion.CustomEmotion>;
string url = this.CurrentUser.Configuration.SystemSetting.SysConversationSetting.UriCheckEmotion;
if (string.IsNullOrEmpty(url))
{
ClientLogger.WriteGeneral("自定义表情检测失败: uri null");
}
else
{
try
{
HttpWebRequest request = ConnectionFactory.CreateHttpWebRequest(url, null, true, true);
using (Stream w = request.GetRequestStream())
{
using (XmlTextWriter writer = new XmlTextWriter(w, Encoding.UTF8))
{
writer.WriteStartDocument();
writer.WriteStartElement("args");
writer.WriteStartElement("files");
List<Imps.Client.Core.CustomEmotion.CustomEmotion>.Enumerator enumerator = list.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
Imps.Client.Core.CustomEmotion.CustomEmotion emotion = enumerator.get_Current();
writer.WriteStartElement("file");
writer.WriteAttributeString("id", emotion.Id);
writer.WriteEndElement();
}
}
finally
{
enumerator.Dispose();
}
writer.WriteEndElement();
writer.WriteEndElement();
}
}
using (HttpWebResponse response = ((HttpWebResponse) request.GetResponse()))
{
using (Stream stream = response.GetResponseStream())
{
XmlDocument document = new XmlDocument();
using (StreamReader reader = new StreamReader(stream))
{
document.LoadXml(reader.ReadToEnd());
}
foreach (XmlNode node in document.DocumentElement.ChildNodes[0].ChildNodes)
{
if ((node.Attributes["status-code"] == null) || (node.Attributes["status-code"].Value != "200"))
{
continue;
}
for (int i = list.get_Count() - 1; i >= 0; i--)
{
if (list.get_Item(i).Id == node.Attributes["id"].Value)
{
double num2;
if ((node.Attributes["expires"] != null) && double.TryParse(node.Attributes["expires"].Value, ref num2))
{
list.get_Item(i).ExpireDate = new DateTime?(DateTime.Now.AddSeconds(num2));
this.UpdateEmotionConfig(list.get_Item(i));
}
list.Remove(list.get_Item(i));
}
}
}
}
}
}
catch (Exception exception)
{
ClientLogger.WriteException(exception);
}
List<Imps.Client.Core.CustomEmotion.CustomEmotion>.Enumerator enumerator3 = list.GetEnumerator();
try
{
while (enumerator3.MoveNext())
{
Imps.Client.Core.CustomEmotion.CustomEmotion state = enumerator3.get_Current();
ThreadPool.QueueUserWorkItem(new WaitCallback(this.UploadEmotionInThread), state);
}
}
finally
{
enumerator3.Dispose();
}
}
}
private void UploadEmotionInThread(object context)
{
Imps.Client.Core.CustomEmotion.CustomEmotion emotion = context as Imps.Client.Core.CustomEmotion.CustomEmotion;
try
{
string uriSetEmotion = this.CurrentUser.Configuration.SystemSetting.SysConversationSetting.UriSetEmotion;
Image emotionImageById = this.GetEmotionImageById(emotion.Id);
if (string.IsNullOrEmpty(uriSetEmotion))
{
ClientLogger.WriteGeneral("自定义表情上传失败,uri = null");
}
else if (emotionImageById == null)
{
ClientLogger.WriteGeneral("自定义表情上传失败,image = ull");
}
else
{
HttpWebRequest request = null;
try
{
request = ConnectionFactory.CreateHttpWebRequest(string.Format("{0}?id={1}", uriSetEmotion, emotion.Id), null, true, true);
ImageCodecInfo imageCodecInfo = ImageHelper.GetImageCodecInfo(emotionImageById.RawFormat);
request.ContentType = string.Format("image/{0}", (imageCodecInfo == null) ? "jpg" : imageCodecInfo.FormatDescription.ToLower());
using (Stream stream = request.GetRequestStream())
{
using (FileStream stream2 = new FileStream(this.GetOwnerEmotionImagePath(emotion.Id), FileMode.Open, FileAccess.Read))
{
byte[] buffer = new byte[stream2.Length];
stream2.Read(buffer, 0, buffer.Length);
stream.Write(buffer, 0, buffer.Length);
}
}
}
catch (Exception exception)
{
ClientLogger.WriteException(exception);
}
finally
{
if (emotionImageById != null)
{
emotionImageById.Dispose();
emotionImageById = null;
}
}
HttpWebResponse response = null;
try
{
using (response = ((HttpWebResponse) request.GetResponse()))
{
string xml = string.Empty;
using (Stream stream3 = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(stream3))
{
xml = reader.ReadToEnd();
}
}
XmlDocument document = new XmlDocument();
document.LoadXml(xml);
string text4 = "200";
if (document.DocumentElement.Attributes["status"] != null)
{
text4 = document.DocumentElement.Attributes["status"].Value;
}
if (text4 != "200")
{
ClientLogger.WriteGeneral("上传自定义表情失败,status=" + text4);
}
else
{
double num;
XmlNode node = document.DocumentElement.ChildNodes[0];
if ((node.Attributes["expires"] != null) && double.TryParse(node.Attributes["expires"].Value, ref num))
{
emotion.ExpireDate = new DateTime?(DateTime.Now.AddSeconds(num));
this.UpdateEmotionConfig(emotion);
}
}
response.Close();
}
}
catch (Exception exception2)
{
ClientLogger.WriteException("上传自定义表情失败", exception2);
}
}
}
catch (Exception exception3)
{
ClientLogger.WriteException(exception3);
}
}
public Imps.Client.Core.User CurrentUser
{
get
{
return this._currentUser;
}
set
{
this._currentUser = value;
}
}
public string CustomEmotionRecivedPath
{
get
{
return this._customEmotionRecivedPath;
}
}
public string CustomEmotionSavePath
{
get
{
return this._customEmotionSavePath;
}
}
private Dictionary<Imps.Client.Core.CustomEmotion.CustomEmotion, Image> EmotionthumbImages
{
get
{
return this._emotionthumbImages;
}
set
{
this._emotionthumbImages = value;
}
}
private long MaxCustomEmotionLength
{
get
{
return (long) this.CurrentUser.Configuration.SystemSetting.SysConversationSetting.MaxEmotionPicSize;
}
}
private int MaxCustomEmotionLimit
{
get
{
return 0x3e8;
}
}
private Size MaxCustomEmotionSize
{
get
{
if (!this._maxSize.get_HasValue())
{
int width = Convert.ToInt32(this.CurrentUser.Configuration.SystemSetting.SysConversationSetting.MaxEmotionPicRect.Split(new char[] { '*' })[0]);
int height = Convert.ToInt32(this.CurrentUser.Configuration.SystemSetting.SysConversationSetting.MaxEmotionPicRect.Split(new char[] { '*' })[1]);
this._maxSize = new Size(width, height);
}
return this._maxSize.get_Value();
}
}
private int MaxShortCutLength
{
get
{
return 8;
}
}
public CustomEmotionDictionary OwnerEmotions
{
get
{
if (this._ownerEmotions == null)
{
this._ownerEmotions = new CustomEmotionDictionary();
this.LoadLocalCustomEmotions();
}
return this._ownerEmotions;
}
}
private int ShowCountEveryPage
{
get
{
return 20;
}
}
private int ThumbImageSize
{
get
{
return 0x19;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -