📄 useraccountmanager.cs
字号:
namespace Imps.Client.Pc
{
using Imps.Client;
using Imps.Client.Core;
using Imps.Client.Pc.BizControls;
using Imps.Client.Pc.BizControls.NotifyWindows;
using Imps.Client.Pc.IPI.UI;
using Imps.Client.Pc.Provsion2;
using Imps.Client.Pc.Sensor;
using Imps.Client.Resource;
using Imps.Client.Utils;
using Imps.Common;
using Imps.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
public class UserAccountManager : IUserAccountManager, IInitializable
{
private Imps.Client.Core.User _currentUser;
private Imps.Client.Pc.EntryPointControl _entryControl;
private IFrameworkWindow _frameworkWnd;
private bool _loginOnPC = true;
private ToolStripItem[] _menuItemsOperation;
private ToolStripItem[] _menuItemsTrayIcon;
private ToolStripItem[] _menuItemsUser;
private ToolStripMenuItem _miLogout;
private ToolStripMenuItem _miOfflineLogin;
private ContextMenuStrip _miTrayIcon;
private ToolStripMenuItem _miUser;
private bool _msgBoxPending;
private OfflineMsgSettingForm _offlineMsgForm;
private ProvisionWizard _provsionWizard;
private MouseKeyboardSensor _sensorMouseKey;
private MainPresence _switchTarget;
private BUserInfoControl _userInfoControl;
private const int MenuTextLength = 30;
private int statusChangedEventCount;
private string switchPassword;
public event EventHandler<ImpsCancelEventArgs> BeforeUserLogOut;
public event EventHandler<BeforeMainPresenceChangeEventArgs> BeforeUserMainPresenceChange;
public UserAccountManager(IFrameworkWindow framework)
{
this._frameworkWnd = framework;
this._currentUser = new Imps.Client.Core.User(framework.PersistentManager);
this._currentUser.RegistrationNotifyReceived += new EventHandler<ImpsNotifyEventArgs>(this, (IntPtr) this._currentUser_RegistrationNotifyReceived);
this._entryControl = new Imps.Client.Pc.EntryPointControl(this);
this._frameworkWnd.MainWindow.Closing += new CancelEventHandler(this._frameworkWnd_Closing);
this._frameworkWnd.MainWindowLoaded += new EventHandler(this._frameworkWnd_Loaded);
FunctionHelper.CurrentUser = this._currentUser;
}
private void _currentUser_RegistrationNotifyReceived(object sender, ImpsNotifyEventArgs e)
{
try
{
string title = e.Title ?? string.Empty;
if (title.Length <= 0)
{
title = AppDictionary.CurrentClientName;
}
SystemInfoNotify notifyWindow = new SystemInfoNotify(title, e.Text);
notifyWindow.TimeToStay = 0x7fffffff;
notifyWindow.Click += new EventHandler(this.notifyWnd_Click);
NotifyWindowManager.Add(notifyWindow);
}
catch (Exception exception)
{
this._frameworkWnd.UnifiedMessageBox.ShowError(exception.ToString());
}
}
private void _frameworkWnd_Closing(object sender, CancelEventArgs e)
{
try
{
bool cancel = false;
this.Logout(ref cancel);
if (cancel)
{
e.Cancel = true;
}
}
catch
{
}
}
private void _frameworkWnd_Loaded(object sender, EventArgs e)
{
if (!Imps.Client.Core.Configuration.FixedClientSetting.DuringDebug)
{
try
{
SysLockSensor.PrepareEnvironment();
List<IPresenceSensor> list = new List<IPresenceSensor>(4);
try
{
BossKeySensor instance = BossKeySensor.GetInstance(this._frameworkWnd);
instance.Priority = 1;
instance.Name = "BossKeySensor";
list.Add(instance);
}
catch (Exception exception)
{
ClientLogger.WriteException("Initialize Sensor", exception);
}
try
{
SysLockSensor sensor2 = SysLockSensor.GetInstance(this._frameworkWnd);
sensor2.Priority = 2;
sensor2.Name = "SysLockSensor";
list.Add(sensor2);
}
catch (Exception exception2)
{
ClientLogger.WriteException("Initialize Sensor", exception2);
}
try
{
FullScreenSensor sensor3 = new FullScreenSensor(this._frameworkWnd);
sensor3.Priority = 3;
sensor3.Name = "FullScreenSensor";
list.Add(sensor3);
}
catch (Exception exception3)
{
ClientLogger.WriteException("Initialize Sensor", exception3);
}
try
{
ScreenSaverSensor sensor4 = new ScreenSaverSensor(this._frameworkWnd);
sensor4.Priority = 4;
sensor4.Name = "ScreenSaverSensor";
list.Add(sensor4);
}
catch (Exception exception4)
{
ClientLogger.WriteException("Initialize Sensor", exception4);
}
try
{
MouseKeyboardSensor sensor5 = new MouseKeyboardSensor(this._frameworkWnd);
sensor5.Priority = 5;
sensor5.Name = "MouseKeyboardSensor";
this._sensorMouseKey = sensor5;
list.Add(sensor5);
}
catch (Exception exception5)
{
ClientLogger.WriteException("Initialize Sensor", exception5);
}
if (list.get_Count() > 0)
{
this.CurrentUser.Presence.RegisterSensors(list.ToArray());
}
}
catch
{
}
}
}
private void _miTrayIcon_Opening(object sender, CancelEventArgs e)
{
UiErrorHelper.HandEventSafely(this._frameworkWnd, delegate {
UserAccountStatus status = this.CurrentUser.Status;
switch (status)
{
case UserAccountStatus.Logon:
this._menuItemsTrayIcon[0].set_Text(StringTable.Framework.MI_SignOut);
this._menuItemsTrayIcon[0].set_Enabled(true);
break;
case UserAccountStatus.Logoff:
case UserAccountStatus.Disconnected:
case UserAccountStatus.None:
this._menuItemsTrayIcon[0].set_Text(StringTable.Framework.MI_SignIn);
this._menuItemsTrayIcon[0].set_Enabled(true);
break;
case UserAccountStatus.OfflineLogon:
this._menuItemsTrayIcon[0].set_Text(StringTable.Framework.MI_TranUser);
this._menuItemsTrayIcon[0].set_Enabled(true);
break;
default:
this._menuItemsTrayIcon[0].set_Enabled(false);
break;
}
this._menuItemsTrayIcon[1].set_Enabled(this.CurrentUser.AsLogon);
this._menuItemsTrayIcon[2].set_Enabled(status == UserAccountStatus.Logon);
if (status == UserAccountStatus.Logon)
{
((ToolStripMenuItem) this._menuItemsTrayIcon[2]).get_DropDownItems().Clear();
((ToolStripMenuItem) this._menuItemsTrayIcon[2]).get_DropDownItems().AddRange(this.GetRecentBuddiesMenuItems());
}
this._menuItemsTrayIcon[5].set_Enabled(((status == UserAccountStatus.None) || this.CurrentUser.AsLogon) || (status == UserAccountStatus.Logoff));
});
}
private void _offlineMsgForm_FormClosed(object sender, FormClosedEventArgs e)
{
}
private void BuildOperationMenuItems()
{
if (this._menuItemsOperation == null)
{
this._menuItemsOperation = new ToolStripItem[] { new ToolStripMenuItem(StringTable.Framework.MI_MsgHistory) };
this._menuItemsOperation[0].add_Click(new EventHandler(this.miMsgHistory_Click));
}
}
private void BuildTrayIconMenu()
{
this._miTrayIcon = new menu_widget(this._frameworkWnd.ComponentContainer);
this._miTrayIcon.add_Opening(new CancelEventHandler(this._miTrayIcon_Opening));
ToolStripSeparator separator = new ToolStripSeparator();
separator.set_Enabled(false);
ToolStripSeparator separator2 = new ToolStripSeparator();
separator2.set_Enabled(false);
if (this._menuItemsTrayIcon == null)
{
this._menuItemsTrayIcon = new ToolStripItem[9];
int index = 0;
this._menuItemsTrayIcon[index] = new ToolStripMenuItem(StringTable.Framework.MI_SignIn);
this._menuItemsTrayIcon[index].add_Click(new EventHandler(this.miSignInOrSignOut_Click));
this._menuItemsTrayIcon[++index] = new ToolStripMenuItem(StringTable.Framework.MI_MyStatus);
((ToolStripMenuItem) this._menuItemsTrayIcon[index]).set_DropDown(new menu_widget(this._frameworkWnd.ComponentContainer));
((menu_widget) ((ToolStripMenuItem) this._menuItemsTrayIcon[index]).get_DropDown()).set_ShowCheckMargin(false);
((ToolStripMenuItem) this._menuItemsTrayIcon[index]).get_DropDownItems().AddRange(this.GetPresenceMenuItems(false, true));
((ToolStripMenuItem) this._menuItemsTrayIcon[index]).add_DropDownOpening(new EventHandler(this.miMyStatus_DropDownOpening));
this._menuItemsTrayIcon[++index] = new ToolStripMenuItem(StringTable.Framework.MI_RecentBuddies);
((ToolStripMenuItem) this._menuItemsTrayIcon[index]).set_DropDown(new menu_widget(this._frameworkWnd.ComponentContainer));
((menu_widget) ((ToolStripMenuItem) this._menuItemsTrayIcon[index]).get_DropDown()).set_ShowCheckMargin(false);
((ToolStripMenuItem) this._menuItemsTrayIcon[index]).add_DropDownOpening(new EventHandler(this.RecentBuddies_DropDownOpening));
this._menuItemsTrayIcon[++index] = separator;
this._menuItemsTrayIcon[++index] = new ToolStripMenuItem(StringTable.Framework.MI_ShowMain);
this._menuItemsTrayIcon[index].add_Click(new EventHandler(this.miShowMain_Click));
this._menuItemsTrayIcon[++index] = new ToolStripMenuItem(StringTable.Framework.MI_ToolsOptions);
this._menuItemsTrayIcon[index].add_Click(new EventHandler(this.miToolsOptions_Click));
this._menuItemsTrayIcon[++index] = new ToolStripMenuItem(string.Format(StringTable.Framework.MI_HelpAbout, AppDictionary.CurrentClientName));
this._menuItemsTrayIcon[index].add_Click(new EventHandler(this.miHelpAbout_Click));
this._menuItemsTrayIcon[index].set_Visible(false);
this._menuItemsTrayIcon[++index] = separator2;
this._menuItemsTrayIcon[++index] = new ToolStripMenuItem(string.Format(StringTable.Framework.MI_Exit, AppDictionary.CurrentClientName));
this._menuItemsTrayIcon[index].add_Click(new EventHandler(this.miExit_Click));
}
this._miTrayIcon.get_Items().AddRange(this._menuItemsTrayIcon);
}
private void BuildUserMenuItems()
{
this._miUser = new ToolStripMenuItem();
this._miUser.set_DropDown(new menu_widget(this._frameworkWnd.ComponentContainer));
this._miUser.set_Text(StringTable.Framework.MI_User);
this._miUser.add_DropDownOpening(new EventHandler(this.miUser_DropDownOpening));
if (this._menuItemsUser == null)
{
List<ToolStripItem> list = new List<ToolStripItem>(7);
ToolStripMenuItem item = new ToolStripMenuItem(StringTable.Framework.MI_PersonalInfo);
item.add_Click(new EventHandler(this.miInfo_Click));
list.Add(item);
item = new ToolStripMenuItem(StringTable.Framework.MI_MyStatus);
item.set_DropDown(new menu_widget(this._frameworkWnd.ComponentContainer));
item.get_DropDownItems().AddRange(this.GetPresenceMenuItems(false, true));
item.add_DropDownOpening(new EventHandler(this.miMyStatus_DropDownOpening));
list.Add(item);
item = new ToolStripMenuItem(StringTable.Framework.MI_MyService);
item.set_DropDown(new menu_widget(this._frameworkWnd.ComponentContainer));
item.add_DropDownOpening(new EventHandler(this.miMyServic_DropDownOpening));
Dictionary<string, ImpsService>.KeyCollection.Enumerator enumerator = this.CurrentUser.SubscribedServices.get_Keys().GetEnumerator();
try
{
while (enumerator.MoveNext())
{
string tag = enumerator.get_Current();
ImpsService service = this.CurrentUser.SubscribedServices.get_Item(tag);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -