private DotMSN.Messenger messenger = new Messenger();
if (Universal.ConvertNullToEmpty(Request["MsnAccount"]).Equals("") || Universal.ConvertNullToEmpty(Request["MsnPassword"]).Equals("")) {
throw new UserException("您没有输入MSN帐户或密码!");
}
messenger = new Messenger();
try{
messenger.Connect(Request["MsnAccount"], Request["MsnPassword"]);
if (!messenger.Connected) {
throw new UserException("MSN无法连接!");
}
messenger.SynchronizeList();
int count = 0;
while (!messenger.GetListEnumerator(MSNList.ForwardList).MoveNext() && count < 5) {
//while (!messenger.Connected && count < 10) {
System.Threading.Thread.Sleep(2000);
count++;
}
if (!messenger.GetListEnumerator(MSNList.ForwardList).MoveNext() && count == 5) {
throw new UserException("MSN无法连接!");
}
messenger.SetStatus(MSNStatus.Online); // 设置上线
System.Threading.Thread.Sleep(1000);
ArrayList GroupList = new ArrayList();
Hashtable Grouptable = new Hashtable();
foreach (object o in messenger.ContactGroups.Keys) {
ContactGroup contactGroup = messenger.ContactGroups[o] as ContactGroup;
GroupList.Add(contactGroup);
Grouptable.Add("Group"+contactGroup.ID, new ArrayList());
}
foreach (Contact contact in messenger.GetListEnumerator(MSNList.ForwardList)) {
ArrayList contactList = Grouptable["Group"+contact.ContactGroup.ID] as ArrayList;
contactList.Add(contact);
}
StringBuilder ListHtml = new StringBuilder();
ListHtml.Append("<tr height=20 bgcolor=#BECFDC align=\"left\">");
ListHtml.Append("<td width=6% align=center><b>展开</b></td>");
ListHtml.Append("<td width=34%><b>电子邮件地址</b></td>");
ListHtml.Append("<td width=60%><b>称呼</b></td></tr>");
bool flag = false;
for (int i=0; i<GroupList.Count; i++) {
ContactGroup contactGroup = GroupList[i] as ContactGroup;
ArrayList contactList = Grouptable["Group"+contactGroup.ID] as ArrayList;
ListHtml.Append("<tr>");
ListHtml.Append("<td align=center><img src=\"../images/plus.gif\" title=\"合并\" style=\"cursor:hand\" onClick=\"ClickImg(this,'Group"+contactGroup.ID+"')\"></td>");
ListHtml.Append("<td colspan=2 bgcolor=#BEBEDE><input type=\"checkbox\" name=\"Group\" value=\"group"+contactGroup.ID+"\" onClick=\"ClickGroup(this)\" checked>"+(contactGroup.Name.Equals("Individuals")?"未分组":contactGroup.Name)+"("+contactList.Count+")</td>");
ListHtml.Append("</tr>");
ListHtml.Append("<tr id=\"Group"+contactGroup.ID+"\" style=\"display:none\"><td></td><td colspan=2>");
// 得到分组中的好友列表
ListHtml.Append("<table width=100%>");
for (int j=0; j<contactList.Count; j++) {
Contact contact = contactList[j] as Contact;
ListHtml.Append("<tr bgcolor="+(flag?"#E6E6E5":"#FFFFFF")+">");
ListHtml.Append("<td width=36%><input type=\"checkbox\" name=\"FriendEmail\" value=\""+contact.Mail+"\" group=\"group"+contactGroup.ID+"\" onClick=\"ClickContact(this)\" checked>"+contact.Mail+"</td>");
ListHtml.Append("<td width=64%>"+contact.Name+"</td>");
ListHtml.Append("</tr>");
flag = !flag;
}
ListHtml.Append("</table></td></tr>");
}
lbFriendList.Text = ListHtml.ToString();
}
catch (MSNException ex) {
throw new UserException("连接失败:"+ex.Message);
}
if (Universal.ConvertNullToEmpty(Request["MsnAccount"]).Equals("") || Universal.ConvertNullToEmpty(Request["MsnPassword"]).Equals("")) {
throw new UserException("您没有输入MSN帐户或密码!");
}
messenger = new Messenger();
try{
messenger.Connect(Request["MsnAccount"], Request["MsnPassword"]);
if (!messenger.Connected) {
throw new UserException("MSN无法连接!");
}
messenger.SynchronizeList();
int count = 0;
while (!messenger.GetListEnumerator(MSNList.ForwardList).MoveNext() && count < 5) {
//while (!messenger.Connected && count < 10) {
System.Threading.Thread.Sleep(2000);
count++;
}
if (!messenger.GetListEnumerator(MSNList.ForwardList).MoveNext() && count == 5) {
throw new UserException("MSN无法连接!");
}
messenger.SetStatus(MSNStatus.Online); // 设置上线
System.Threading.Thread.Sleep(1000);
ArrayList GroupList = new ArrayList();
Hashtable Grouptable = new Hashtable();
foreach (object o in messenger.ContactGroups.Keys) {
ContactGroup contactGroup = messenger.ContactGroups[o] as ContactGroup;
GroupList.Add(contactGroup);
Grouptable.Add("Group"+contactGroup.ID, new ArrayList());
}
foreach (Contact contact in messenger.GetListEnumerator(MSNList.ForwardList)) {
ArrayList contactList = Grouptable["Group"+contact.ContactGroup.ID] as ArrayList;
contactList.Add(contact);
}
StringBuilder ListHtml = new StringBuilder();
ListHtml.Append("<tr height=20 bgcolor=#BECFDC align=\"left\">");
ListHtml.Append("<td width=6% align=center><b>展开</b></td>");
ListHtml.Append("<td width=34%><b>电子邮件地址</b></td>");
ListHtml.Append("<td width=60%><b>称呼</b></td></tr>");
bool flag = false;
for (int i=0; i<GroupList.Count; i++) {
ContactGroup contactGroup = GroupList[i] as ContactGroup;
ArrayList contactList = Grouptable["Group"+contactGroup.ID] as ArrayList;
ListHtml.Append("<tr>");
ListHtml.Append("<td align=center><img src=\"../images/plus.gif\" title=\"合并\" style=\"cursor:hand\" onClick=\"ClickImg(this,'Group"+contactGroup.ID+"')\"></td>");
ListHtml.Append("<td colspan=2 bgcolor=#BEBEDE><input type=\"checkbox\" name=\"Group\" value=\"group"+contactGroup.ID+"\" onClick=\"ClickGroup(this)\" checked>"+(contactGroup.Name.Equals("Individuals")?"未分组":contactGroup.Name)+"("+contactList.Count+")</td>");
ListHtml.Append("</tr>");
ListHtml.Append("<tr id=\"Group"+contactGroup.ID+"\" style=\"display:none\"><td></td><td colspan=2>");
// 得到分组中的好友列表
ListHtml.Append("<table width=100%>");
for (int j=0; j<contactList.Count; j++) {
Contact contact = contactList[j] as Contact;
ListHtml.Append("<tr bgcolor="+(flag?"#E6E6E5":"#FFFFFF")+">");
ListHtml.Append("<td width=36%><input type=\"checkbox\" name=\"FriendEmail\" value=\""+contact.Mail+"\" group=\"group"+contactGroup.ID+"\" onClick=\"ClickContact(this)\" checked>"+contact.Mail+"</td>");
ListHtml.Append("<td width=64%>"+contact.Name+"</td>");
ListHtml.Append("</tr>");
flag = !flag;
}
ListHtml.Append("</table></td></tr>");
}
lbFriendList.Text = ListHtml.ToString();
}
catch (MSNException ex) {
throw new UserException("连接失败:"+ex.Message);
}