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

📄 conversationmanagerimp.cs

📁 飞信的收发使用csharp进行开发
💻 CS
📖 第 1 页 / 共 3 页
字号:
namespace Imps.Client.Pc
{
    using Imps.Client;
    using Imps.Client.Core;
    using Imps.Client.Pc.BizControls.NotifyWindows;
    using Imps.Client.Pc.BizControls.NotifyWindows.Templates;
    using Imps.Client.Resource;
    using Imps.Client.Utils;
    using Imps.Client.Utils.Win32;
    using Imps.Common;
    using Imps.Utils;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.IO;
    using System.Media;
    using System.Threading;
    using System.Windows.Forms;

    public class ConversationManagerImp : IConversationManager
    {
        private List<ConversationWindow> _allConversatonWindows;
        private bool _forceToCloseWindow;
        private IFrameworkWindow _frameworkWnd;
        private GroupSMSForm _smsForm;

        public ConversationManagerImp(IFrameworkWindow framework)
        {
            try
            {
                this._frameworkWnd = framework;
                this.CurrentUser.ConversationManager.FindConversationForm += new EventHandler<FindConversationFormEventArgs>(this.ConversationManager_FindConversationWindow);
                ((Form) framework).FormClosed += new FormClosedEventHandler(this.mainFormclosed);
                framework.AccountManager.BeforeUserLogOut += new EventHandler<ImpsCancelEventArgs>(this.AccountManager_BeforeUserLogOut);
            }
            catch (Exception exception)
            {
                ClientLogger.WriteException(exception);
            }
        }

        private void AccountManager_BeforeUserLogOut(object sender, ImpsCancelEventArgs e)
        {
            ImpsCancelOperationDelegate item = null;
            bool flag = this.AllConversatonWindows.Count > 0;
            bool flag2 = (this._smsForm != null) && !this._smsForm.IsDisposed;
            if (flag || flag2)
            {
                string msgWarnWhenLogOut;
                e.Cancel = true;
                if (flag)
                {
                    msgWarnWhenLogOut = StringTable.Conversation.MsgWarnWhenLogOut;
                    if (flag2)
                    {
                        msgWarnWhenLogOut = msgWarnWhenLogOut + "群发短信窗口也将会关闭!";
                    }
                }
                else
                {
                    msgWarnWhenLogOut = "确认要注销吗?注销后群发短信的窗口将会关闭!";
                }
                e.CancelQuestions.Add(msgWarnWhenLogOut);
                if (item == null)
                {
                    item = delegate (bool realCancelled) {
                        if (!realCancelled)
                        {
                            this._forceToCloseWindow = true;
                            this.CloseAllConversationWindow();
                            if ((this._smsForm != null) && !this._smsForm.IsDisposed)
                            {
                                this._smsForm.Close();
                            }
                        }
                    };
                }
                e.CancelOperations.Add(item);
            }
        }

        public void CloseAllConversationWindow()
        {
            try
            {
                for (int i = this.AllConversatonWindows.Count - 1; i >= 0; i--)
                {
                    this.AllConversatonWindows[i].Close();
                }
            }
            catch (Exception exception)
            {
                ClientLogger.WriteGeneral(exception.ToString());
            }
        }

        private void ConversationManager_FindConversationWindow(object sender, FindConversationFormEventArgs e)
        {
            try
            {
                lock (this.AllConversatonWindows)
                {
                    foreach (ConversationWindow window in this.AllConversatonWindows)
                    {
                        if ((window.CurrentConversation != null) && (window.CurrentConversation.CallId == e.Conversation.CallId))
                        {
                            this.DoFindForm(window, e.Conversation);
                            return;
                        }
                    }
                    foreach (ConversationWindow window2 in this.AllConversatonWindows)
                    {
                        if (window2.Uri == e.Conversation.CurrentDialog.To)
                        {
                            this.DoFindForm(window2, e.Conversation);
                            return;
                        }
                    }
                    foreach (ConversationWindow window3 in this.AllConversatonWindows)
                    {
                        if (!string.IsNullOrEmpty(window3.MobileNo) && (e.Conversation.CurrentDialog.Participants.Count == 1))
                        {
                            Imps.Client.Core.Contact contact = e.Conversation.CurrentDialog.Participants[0].Contact;
                            if ((contact is NonFederationContact) && ((contact as NonFederationContact).MobileNo == window3.MobileNo))
                            {
                                this.DoFindForm(window3, e.Conversation);
                                return;
                            }
                        }
                    }
                }
                ConversationWindow newForm = this.CreateConversationWindow(e.Conversation);
                newForm.WindowState = FormWindowState.Minimized;
                newForm.Show();
                if (((this.CurrentUser.Configuration.UserSetting.NotifyWinodwSetting.NewMessageNotify != null) && (this.CurrentUser.Presence.MainPresence != MainPresence.Busy)) && (this.CurrentUser.Presence.MainPresence != MainPresence.DoNotDisturb))
                {
                    ShowMessageReceiveNotifyWindow(newForm, e.Contact, e.Message);
                }
            }
            catch (Exception exception)
            {
                ClientLogger.WriteException(exception);
            }
            finally
            {
                e.AutoEvent.Set();
            }
        }

        private ConversationWindow CreateConversationWindow(Imps.Client.Core.Conversation conv)
        {
            ConversationWindow item = new ConversationWindow(this, conv);
            item.LoadWindowSetting();
            this.AllConversatonWindows.Add(item);
            item.FormClosed += new FormClosedEventHandler(this.form_FormClosed);
            item.Activated += new EventHandler(this.form_Activated);
            item.Deactivate += new EventHandler(this.form_Deactivate);
            return item;
        }

        private void DoFindForm(ConversationWindow form, Imps.Client.Core.Conversation conv)
        {
            if (form.CurrentConversation != conv)
            {
                form.CurrentConversation = conv;
            }
        }

        public static void ExecuteFile(IWin32Window owner, string filePath)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(ConversationManagerImp.ExecuteFileInThread), filePath);
        }

        private static void ExecuteFileInThread(object obj)
        {
            string url = obj as string;
            try
            {
                if (url.ToLower().StartsWith("http://") || url.ToLower().StartsWith("www."))
                {
                    ShellHelper.StartUrl(url);
                }
                else
                {
                    Process.Start(url);
                }
            }
            catch (Win32Exception exception)
            {
                if (File.Exists(url))
                {
                    try
                    {
                        Imps.Client.Utils.Win32.NativeMethods.ShellExecute(IntPtr.Zero, null, "RUNDLL32.EXE", "shell32.dll,OpenAs_RunDLL " + url, null, 5);
                    }
                    catch (Exception exception2)
                    {
                        ClientLogger.WriteException(exception2);
                    }
                }
                else
                {
                    ClientLogger.WriteException(exception);
                }
            }
            catch (Exception exception3)
            {
                ClientLogger.WriteGeneral(exception3.ToString());
            }
        }

        private void form_Activated(object sender, EventArgs e)
        {
            (sender as ConversationWindow).BeActivated = true;
        }

        private void form_Deactivate(object sender, EventArgs e)
        {
            (sender as ConversationWindow).BeActivated = false;
        }

        private void form_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.AllConversatonWindows.Remove(sender as ConversationWindow);
            if (this.AllConversatonWindows.Count == 0)
            {
                this.AllConversatonWindows = null;
            }
        }

⌨️ 快捷键说明

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