?? messagehistorymanager.cs
字號:
?namespace Imps.Client.Pc
{
using Imps.Client.Base;
using Imps.Client.Core;
using Imps.Client.Resource;
using Imps.Client.Utils;
using Imps.Client.Utils.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
public class MessageHistoryManager : IMessageHistoryManager
{
private IFrameworkWindow _framework;
private MessageHistoryForm _msgForm;
private Dictionary<Imps.Client.Core.Contact, MessageHistoryForm> _msgHisForms;
public MessageHistoryManager(IFrameworkWindow framework)
{
this._framework = framework;
}
public void AsyncDelete(Imps.Client.Core.Contact contact)
{
DeleteXmlContentDelegate deleteCallBack = null;
try
{
string messageHistoryPath = this.GetMessageHistoryPath(contact);
if (System.IO.File.Exists(messageHistoryPath))
{
System.IO.File.Delete(messageHistoryPath);
}
if (deleteCallBack == null)
{
deleteCallBack = delegate {
return string.Format("<contacts><uri>{0}</uri></contacts>", contact.Uri.Raw);
};
}
this.AsyncDeleteServerMessageHistory(deleteCallBack);
}
catch (Exception exception)
{
ClientLogger.WriteException(exception);
}
}
public void AsyncDelete(List<Imps.Client.Core.Contact> contacts)
{
for (int j = 0; j < contacts.Count; j++)
{
string messageHistoryPath = this.GetMessageHistoryPath(contacts[j]);
if (System.IO.File.Exists(messageHistoryPath))
{
System.IO.File.Delete(messageHistoryPath);
}
}
this.AsyncDeleteServerMessageHistory(delegate {
StringBuilder builder = new StringBuilder();
builder.Append("<contacts>");
for (int k = 0; i < contacts.Count; i++)
{
builder.Append(string.Format("<uri>{0}</uri>", contacts[i].Uri.Raw));
}
builder.Append("</contacts>");
return builder.ToString();
});
}
public void AsyncDelete(Imps.Client.Core.Contact contact, IList<string> msgIds)
{
DeleteXmlContentDelegate deleteCallBack = null;
try
{
if (msgIds.Count > 0)
{
string messageHistoryPath = this.GetMessageHistoryPath(contact);
if (System.IO.File.Exists(messageHistoryPath))
{
XmlDocument document = new XmlDocument();
document.Load(messageHistoryPath);
foreach (string str2 in msgIds)
{
XmlNode oldChild = document.DocumentElement.SelectSingleNode("Message[@MessageID='" + str2 + "']");
if (oldChild != null)
{
document.DocumentElement.RemoveChild(oldChild);
}
}
document.Save(messageHistoryPath);
}
if (deleteCallBack == null)
{
deleteCallBack = delegate {
StringBuilder builder = new StringBuilder();
builder.Append("<records>");
foreach (string str in msgIds)
{
builder.Append(string.Format("<record id=\"{0}\"/>", str));
}
builder.Append("</records>");
return builder.ToString();
};
}
this.AsyncDeleteServerMessageHistory(deleteCallBack);
}
}
catch (Exception exception)
{
ClientLogger.WriteException(exception);
}
}
public void AsyncDelete(Imps.Client.Core.Contact contact, DateTime start, DateTime end)
{
}
public void AsyncDeleteMessageHistory(params string[] contactUris)
{
try
{
if ((contactUris != null) && (contactUris.Length > 0))
{
if (contactUris.Length == 1)
{
Imps.Client.Core.Contact contact;
this.CurrentUser.ContactList.TryFindOrCreateContactAndGetContactInfo(contactUris[0], out contact, new AsyncBizOperation(), ConversationManager.ConversationNeedProperty);
if (contact != null)
{
this.AsyncDelete(contact);
}
}
else
{
List<Imps.Client.Core.Contact> contacts = new List<Imps.Client.Core.Contact>();
foreach (string str in contactUris)
{
Imps.Client.Core.Contact item = this.CurrentUser.ContactList.Contacts.FindContact(str);
if (item != null)
{
contacts.Add(item);
}
}
this.AsyncDelete(contacts);
}
}
}
catch (Exception exception)
{
ClientLogger.WriteException(exception);
}
}
private void AsyncDeleteServerMessageHistory(DeleteXmlContentDelegate deleteCallBack)
{
ThreadPool.QueueUserWorkItem(delegate (object context) {
try
{
HttpWebRequest request = ConnectionFactory.CreateHttpWebRequest(this.CurrentUser.Configuration.SystemSetting.MsgHistorySetting.UriDelMsgHistory, this.CurrentUser, true, true);
request.ContentType = "text/xml";
string s = string.Format("<?xml version=\"1.0\" encoding=\"utf-8\" ?><args><owner>{0}</owner>{1}</args>", this.CurrentUser.Uri.ToString(), deleteCallBack());
byte[] buffer = Encoding.UTF8.GetBytes(s);
request.GetRequestStream().Write(bytes, 0, bytes.Length);
(request.GetResponse() as HttpWebResponse).Close();
}
catch (WebException)
{
}
catch (Exception)
{
}
});
}
public void AsyncSynchronize(Imps.Client.Core.Contact contact)
{
throw new NotImplementedException();
}
public bool ClearMessageHistory(IWin32Window owner)
{
DeleteXmlContentDelegate deleteCallBack = null;
try
{
if ((owner != null) && (this._framework.UnifiedMessageBox.ShowConfirmation(owner, StringTable.Conversation.MsgConfirmDeleteAll) != DialogResult.Yes))
{
return false;
}
if (Directory.Exists(this.CurrentUser.PersistentManager.BaseDirForHistory))
{
Directory.Delete(this.CurrentUser.PersistentManager.BaseDirForHistory, true);
}
if (deleteCallBack == null)
{
deleteCallBack = delegate {
StringBuilder builder = new StringBuilder();
builder.Append("<contacts>");
lock (this.CurrentUser.ContactList.Contacts.SyncRoot)
{
foreach (Imps.Client.Core.Contact contact in this.CurrentUser.ContactList.Contacts)
{
builder.Append(string.Format("<uri>{0}</uri>", contact.Uri.Raw));
}
}
builder.Append("</contacts>");
return builder.ToString();
};
}
this.AsyncDeleteServerMessageHistory(deleteCallBack);
return true;
}
catch (Exception exception)
{
ClientLogger.WriteException(exception);
return false;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -