?? contactnotifywindowmanager.cs
字號:
?namespace Imps.Client.Pc.UIContactList
{
using Imps.Client;
using Imps.Client.Core;
using Imps.Client.Pc;
using Imps.Client.Pc.BizControls.NotifyWindows;
using Imps.Client.Pc.BizControls.NotifyWindows.Templates;
using Imps.Client.Pc.UIContactList.AddBuddy;
using Imps.Client.Utils;
using Imps.Common;
using Imps.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
public class ContactNotifyWindowManager
{
private List<AddBuddyRequest> _addBuddyRequestCol;
private List<Contact> _addBuddyRequestProposerCol;
private List<AddBuddyResultEventArgs> _addBuddyResultEventArgsCol;
private List<AddBuddyResultEventArgs> _agreeMobileBuddyEventArgsCol;
private int _currentDisplayAgreeMobileBuddy;
private IFrameworkWindow _iFrameworkWindow;
private User _owner;
private const int MaxDisplayAgreeMobileBuddy = 5;
public ContactNotifyWindowManager(User owner, IFrameworkWindow iFrameworkWnd)
{
this._owner = owner;
this._iFrameworkWindow = iFrameworkWnd;
owner.ContactList.AddBuddyRequest += new EventHandler<AddBuddyApplicationEventArgs>(this.AddBuddyRequestReceived);
}
private void addBuddyApplication_onTick(object sender, EventArgs e)
{
bool flag = true;
try
{
if (this._owner.Status != UserAccountStatus.Logon)
{
this._addBuddyRequestCol = null;
this._addBuddyResultEventArgsCol = null;
}
else if (this._addBuddyRequestCol != null)
{
foreach (AddBuddyRequest request in this.AddBuddyRequestCol)
{
if (request.Contact.PersonalInfo["nickname"] != null)
{
this.showWindows_AddBuddy(request.Contact, request.Desc, request.IsByMobileNo);
this.AddBuddyRequestCol.Remove(request);
return;
}
}
if (this.AddBuddyRequestCol.Count > 0)
{
flag = false;
}
}
}
catch (Exception exception)
{
ClientLogger.WriteException(exception);
}
finally
{
if (flag)
{
GlobalTimer.Unregister(new EventHandler(this.addBuddyApplication_onTick));
}
}
}
public void AddBuddyRequestReceived(object sender, AddBuddyApplicationEventArgs e)
{
AsyncBizOperation op = new AsyncBizOperation();
op.IsImpsErrorHandled = true;
Contact item = this._owner.ContactList.FindOrCreateContact(e.Uri, op, false);
if ((item.Type != ContactType.Buddy) && !this.AddBuddyRequestProposerCol.Contains(item))
{
this.AddBuddyRequestProposerCol.Add(item);
}
else
{
return;
}
this.AddBuddyRequestCol.Add(new AddBuddyRequest(item, e.Desc, e.IsByMobileNo));
this.ShowWindow();
}
public void AddNotifyWnd_AddBuddyResult(AddBuddyResultEventArgs e)
{
this.AddBuddyResultEventArgsCol.Add(e);
this.ShowWindow();
}
public bool AllowPlaySound(Contact c)
{
if (c.IsBlocked)
{
return false;
}
if (this._owner.Configuration.UserSetting.SoundSetting.SoundEnabled == null)
{
return false;
}
return true;
}
public bool AllowPresenceChangedNotifyWindow(Contact c)
{
if ((this._owner.Presence.IsOffline || (this._owner.Presence.MainPresence == MainPresence.DoNotDisturb)) || (this._owner.Presence.MainPresence == MainPresence.Busy))
{
return false;
}
if ((c.RelationStatus != 1) || c.IsBlocked)
{
return false;
}
if (this._owner.Configuration.UserSetting.NotifyWinodwSetting.OnlineNotify.OriginalValue == 1)
{
return false;
}
if ((this._owner.Configuration.UserSetting.NotifyWinodwSetting.OnlineNotify.OriginalValue == 2) && !c.OnlineNotify.Value)
{
return false;
}
return true;
}
public void Clear()
{
this._addBuddyRequestProposerCol = null;
this._addBuddyRequestCol = null;
this._addBuddyResultEventArgsCol = null;
this._agreeMobileBuddyEventArgsCol = null;
this._currentDisplayAgreeMobileBuddy = 0;
}
public void ContactPresenceChanged_NotifyWnd(Contact c, PropertiesChangedEventArgs e)
{
try
{
if ((!c.Presence.IsLogonPresence && c.Presence.IsOnline) && e.ContainsProperty("value"))
{
ChangedValuePair<int> pair = e["value"] as ChangedValuePair<int>;
int oldValue = pair.OldValue;
int newValue = pair.NewValue;
if (!MainPresenceHelper.IsOnline((MainPresence) oldValue) && (newValue != oldValue))
{
if (this.AllowPresenceChangedNotifyWindow(c))
{
ContactOnlineStatusChangedNotify wnd = new ContactOnlineStatusChangedNotify(c);
NotifyWindowManager.Add(wnd);
wnd.ContentClick += delegate {
this._iFrameworkWindow.ConversationManager.StartConversation(this._iFrameworkWindow as Form, ConversationOperation.ImChat, new string[] { c.Uri.Raw });
wnd.Close();
};
}
if (this.AllowPlaySound(c))
{
this.playOnlineNotifySound();
}
}
}
}
catch (Exception exception)
{
ClientLogger.WriteException(exception);
}
}
private void handleArgeeMobileBuddy()
{
if ((this.AgreeMobileBuddyEventArgsCol.Count > 0) && (this._currentDisplayAgreeMobileBuddy <= 5))
{
AddBuddyResultEventArgs e = this.AgreeMobileBuddyEventArgsCol[0];
this.AgreeMobileBuddyEventArgsCol.RemoveAt(0);
this._currentDisplayAgreeMobileBuddy++;
NotifyWindowAddBuddyResult wnd = new NotifyWindowAddBuddyResult(e.Contact, e.IsByMobileNo, null);
wnd.ContentClick += delegate {
this._iFrameworkWindow.ConversationManager.StartConversation(this._iFrameworkWindow as Form, ConversationOperation.ImChat, new string[] { e.Contact.Uri.Raw });
wnd.Close();
};
NotifyWindowManager.Add(wnd);
AddMobileBuddyFeedbackForm flashForm = new AddMobileBuddyFeedbackForm(this._iFrameworkWindow, (MobileBuddy) e.Contact);
flashForm.WindowState = FormWindowState.Minimized;
flashForm.FormClosed += delegate (object sender, FormClosedEventArgs e1) {
this._currentDisplayAgreeMobileBuddy--;
this.handleArgeeMobileBuddy();
};
flashForm.Show(this._iFrameworkWindow as Form);
ControlHelper.FlashWindow(flashForm, 5);
}
}
private void playOnlineNotifySound()
{
try
{
string onlineNotify = (string) this._owner.Configuration.UserSetting.SoundSetting.OnlineNotify;
if (File.Exists(onlineNotify))
{
using (SoundPlayer player = new SoundPlayer(onlineNotify))
{
player.Play();
}
}
}
catch
{
}
}
private void showNotifyWnd_AddBuddyResult(AddBuddyResultEventArgs e)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -