⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 useraccountmanager.cs

📁 飞信的收发使用csharp进行开发
💻 CS
📖 第 1 页 / 共 3 页
字号:
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.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 ToolStripItem[] _menuItemsOperation;
        private ToolStripItem[] _menuItemsTrayIcon;
        private ToolStripItem[] _menuItemsUser;
        private ContextMenuStrip _miTrayIcon;
        private ToolStripMenuItem _miUser;
        private bool _msgBoxPending;
        private OfflineMsgSettingForm _offlineMsgForm;
        private ProvisionWizard _provsionWizard;
        private MouseKeyboardSensor _sensorMouseKey;
        private BUserInfoControl _userInfoControl;
        private const int BasicPresenceNum = 8;

        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._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
                    {
                        SysLockSensor instance = SysLockSensor.GetInstance(this._frameworkWnd);
                        instance.Priority = 1;
                        instance.Name = "SysLockSensor";
                        list.Add(instance);
                    }
                    catch (Exception exception)
                    {
                        ClientLogger.WriteException("Initialize Sensor", exception);
                    }
                    try
                    {
                        FullScreenSensor item = new FullScreenSensor(this._frameworkWnd);
                        item.Priority = 2;
                        item.Name = "FullScreenSensor";
                        list.Add(item);
                    }
                    catch (Exception exception2)
                    {
                        ClientLogger.WriteException("Initialize Sensor", exception2);
                    }
                    try
                    {
                        ScreenSaverSensor sensor3 = new ScreenSaverSensor(this._frameworkWnd);
                        sensor3.Priority = 3;
                        sensor3.Name = "ScreenSaverSensor";
                        list.Add(sensor3);
                    }
                    catch (Exception exception3)
                    {
                        ClientLogger.WriteException("Initialize Sensor", exception3);
                    }
                    try
                    {
                        MouseKeyboardSensor sensor4 = new MouseKeyboardSensor(this._frameworkWnd);
                        sensor4.Priority = 4;
                        sensor4.Name = "MouseKeyboardSensor";
                        this._sensorMouseKey = sensor4;
                        list.Add(sensor4);
                    }
                    catch (Exception exception4)
                    {
                        ClientLogger.WriteException("Initialize Sensor", exception4);
                    }
                    if (list.Count > 0)
                    {
                        this.CurrentUser.Presence.RegisterSensors(list.ToArray());
                        GlobalTimer.Register(new EventHandler(this.Sensor_Tick), this._frameworkWnd.MainWindow, 10);
                    }
                }
                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].Text = StringTable.Framework.MI_SignOut;
                        this._menuItemsTrayIcon[0].Enabled = true;
                        break;

                    case UserAccountStatus.Logoff:
                    case UserAccountStatus.Disconnected:
                    case UserAccountStatus.None:
                        this._menuItemsTrayIcon[0].Text = StringTable.Framework.MI_SignIn;
                        this._menuItemsTrayIcon[0].Enabled = true;
                        break;

                    default:
                        this._menuItemsTrayIcon[0].Enabled = false;
                        break;
                }
                this._menuItemsTrayIcon[1].Enabled = status == UserAccountStatus.Logon;
                this._menuItemsTrayIcon[4].Enabled = ((status == UserAccountStatus.None) || (status == UserAccountStatus.Logon)) || (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].Click += new EventHandler(this.miMsgHistory_Click);
            }
        }

        private void BuildTrayIconMenu()
        {
            this._miTrayIcon = new menu_widget(this._frameworkWnd.ComponentContainer);
            this._miTrayIcon.Opening += new CancelEventHandler(this._miTrayIcon_Opening);
            ToolStripSeparator separator = new ToolStripSeparator();
            separator.Enabled = false;
            ToolStripSeparator separator2 = new ToolStripSeparator();
            separator2.Enabled = false;
            if (this._menuItemsTrayIcon == null)
            {
                this._menuItemsTrayIcon = new ToolStripItem[8];
                int index = 0;
                this._menuItemsTrayIcon[index] = new ToolStripMenuItem(StringTable.Framework.MI_SignIn);
                this._menuItemsTrayIcon[index].Click += new EventHandler(this.miSignInOrSignOut_Click);
                this._menuItemsTrayIcon[++index] = new ToolStripMenuItem(StringTable.Framework.MI_MyStatus);
                ((ToolStripMenuItem) this._menuItemsTrayIcon[index]).DropDown = new menu_widget(this._frameworkWnd.ComponentContainer);
                ((menu_widget) ((ToolStripMenuItem) this._menuItemsTrayIcon[index]).DropDown).ShowCheckMargin = false;
                ((ToolStripMenuItem) this._menuItemsTrayIcon[index]).DropDownItems.AddRange(this.GetPresenceMenuItems(false));
                ((ToolStripMenuItem) this._menuItemsTrayIcon[index]).DropDownOpening += new EventHandler(this.miMyStatus_DropDownOpening);
                this._menuItemsTrayIcon[++index] = separator;
                this._menuItemsTrayIcon[++index] = new ToolStripMenuItem(StringTable.Framework.MI_ShowMain);
                this._menuItemsTrayIcon[index].Click += new EventHandler(this.miShowMain_Click);
                this._menuItemsTrayIcon[++index] = new ToolStripMenuItem(StringTable.Framework.MI_ToolsOptions);
                this._menuItemsTrayIcon[index].Click += new EventHandler(this.miToolsOptions_Click);
                this._menuItemsTrayIcon[++index] = new ToolStripMenuItem(string.Format(StringTable.Framework.MI_HelpAbout, AppDictionary.CurrentClientName));
                this._menuItemsTrayIcon[index].Click += new EventHandler(this.miHelpAbout_Click);
                this._menuItemsTrayIcon[++index] = separator2;
                this._menuItemsTrayIcon[++index] = new ToolStripMenuItem(string.Format(StringTable.Framework.MI_Exit, AppDictionary.CurrentClientName));
                this._menuItemsTrayIcon[index].Click += new EventHandler(this.miExit_Click);
            }
            this._miTrayIcon.Items.AddRange(this._menuItemsTrayIcon);
        }

        private void BuildUserMenuItems()
        {
            this._miUser = new ToolStripMenuItem();
            this._miUser.DropDown = new menu_widget(this._frameworkWnd.ComponentContainer);
            this._miUser.Text = StringTable.Framework.MI_User;
            this._miUser.DropDownOpening += new EventHandler(this.miUser_DropDownOpening);
            if (this._menuItemsUser == null)
            {
                List<ToolStripItem> list = new List<ToolStripItem>(9);
                ToolStripMenuItem item = new ToolStripMenuItem(StringTable.Framework.MI_Provisioning);
                item.Click += new EventHandler(this.miProvisioning_Click);
                list.Add(item);
                item = new ToolStripMenuItem(StringTable.Framework.MI_SignIn);
                item.Click += new EventHandler(this.miSignIn_Click);
                list.Add(item);
                item = new ToolStripMenuItem(StringTable.Framework.MI_SignOut);
                item.Click += new EventHandler(this.miSignOut_Click);
                list.Add(item);
                ToolStripSeparator separator = new ToolStripSeparator();
                separator.Enabled = false;
                list.Add(separator);
                item = new ToolStripMenuItem(StringTable.Framework.MI_PersonalInfo);
                item.Click += new EventHandler(this.miInfo_Click);
                list.Add(item);
                item = new ToolStripMenuItem(StringTable.Framework.MI_MyStatus);
                item.DropDown = new menu_widget(this._frameworkWnd.ComponentContainer);
                item.DropDownItems.AddRange(this.GetPresenceMenuItems(false));
                item.DropDownOpening += new EventHandler(this.miMyStatus_DropDownOpening);
                list.Add(item);
                item = new ToolStripMenuItem(StringTable.Framework.MI_MyService);
                item.DropDown = new menu_widget(this._frameworkWnd.ComponentContainer);
                foreach (string str in this.CurrentUser.SubscribedServices.Keys)
                {
                    ImpsService service = this.CurrentUser.SubscribedServices[str];
                    if (service.Subscribed)
                    {
                        item.DropDownItems.Add(new TagedToolStripMenuItem(str, string.Format("注销{0}", service.Name), null, new EventHandler(this.SubscribeOrUnSubscribeServiceEventHandler)));
                        continue;
                    }
                    item.DropDownItems.Add(new TagedToolStripMenuItem(str, string.Format("开通{0}", service.Name), null, new EventHandler(this.SubscribeOrUnSubscribeServiceEventHandler)));
                }
                list.Add(item);
                ToolStripSeparator separator2 = new ToolStripSeparator();
                separator2.Enabled = false;
                list.Add(separator2);
                item = new ToolStripMenuItem(string.Format(StringTable.Framework.MI_Exit, AppDictionary.CurrentClientName));
                item.Click += new EventHandler(this.miExit_Click);
                list.Add(item);
                this._menuItemsUser = list.ToArray();
            }
            this._miUser.DropDownItems.AddRange(this._menuItemsUser);
        }

        private void ChangePresence(MainPresence presence, string desc)
        {
            BeforeMainPresenceChangeEventArgs e = new BeforeMainPresenceChangeEventArgs(presence);
            FuncDispatcher.OnEventHandler<BeforeMainPresenceChangeEventArgs>(this, this.BeforeUserMainPresenceChange, e);
            if (this.InnerContinueAfterImpsCancel(e, false))
            {
                this.CurrentUser.Presence.AsyncChangeMainPresence(presence, desc);
            }
        }

        public void DoLogin()
        {
            this.Login();
        }

        internal void DoPresenceMenuItemsOpening(ToolStripItemCollection presenceItems)
        {
            ToolStripItem item;
            UserPresence presence = this.CurrentUser.Presence;
            bool transmitBySmsAfterSingout = this.CurrentUser.Presence.TransmitBySmsAfterSingout;
            int num = 0;
            while ((item = presenceItems[num++]) is menu_radioitem)
            {
                CustomPresence tag = (CustomPresence) item.Tag;
                if (tag != null)
                {
                    ((menu_radioitem) item).Radioed = presence.MainPresence == tag.BasicPresence;
                }
            }
            num = 10;
            item = presenceItems[num++];
            ((menu_radioitem) item).Radioed = transmitBySmsAfterSingout;
            item = presenceItems[num];
            ((menu_radioitem) item).Radioed = !transmitBySmsAfterSingout;
            TimeSpan originalValue = this.CurrentUser.Presence.SmsStatus.OriginalValue;
            if ((!transmitBySmsAfterSingout && (originalValue > TimeSpan.Zero)) && (originalValue.Days < 30))
            {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -