public void ReceiveMessage(CommunitySession session, Message message)
 {
     try
     {
         if (message.Type == MessageType.CommunityMessage)
         {
             CommunityMessage message2 = message as CommunityMessage;
             SessionTabItem   item     = this.FindIMSession(session);
             Buddy            sender   = ComponentManager.GetBuddyListBuilder().FindOrCreateBuddy(message2.Uin, true);
             if ((sender != null) && (item != null))
             {
                 item.AddMsg(sender, message2.Time, message2.MessagePack);
             }
         }
         else if (message.Type == MessageType.InfoMessage)
         {
             InfoMessage    message3 = message as InfoMessage;
             SessionTabItem item2    = this.FindIMSession(session);
             if (item2 != null)
             {
                 item2.AddMsg(null, message3.Time, message3.MessagePack);
             }
         }
     }
     catch (Exception)
     {
     }
 }
 public void ReleaseSession(SessionTabItem sessionTabItem, bool close)
 {
     if (sessionTabItem == null)
     {
         throw new ArgumentNullException("sessionTabItem");
     }
     if (close)
     {
         sessionTabItem.Close();
     }
     sessionTabItem.MessageAdded -= new EventHandler <EventArgs>(this.OnMessageAdded);
     if (this.sessionTabItems.Contains(sessionTabItem))
     {
         this.sessionTabItems.Remove(sessionTabItem);
         if (this.sessionTabItems.Count > 0)
         {
             this.CurrentSessionTabItem = this.sessionTabItems[0];
         }
         else
         {
             this.CurrentSessionTabItem = null;
             base.Close();
         }
     }
 }
 public static void CloseCommunityWindowByID(uint communityID)
 {
     for (int i = 0; i < CommunitySessionWindows.Count; i++)
     {
         SessionTabItem sessionTabItem = CommunitySessionWindows[i].FindIMSession(communityID);
         CommunitySessionWindows[i].ReleaseSession(sessionTabItem, true);
     }
 }
 public void StopDropPreview()
 {
     //this.sessionsControl.StopDropPreview();
     if ((this.draggingBuddy != null) && this.sessionTabItems.Contains(this.draggingBuddy))
     {
         this.sessionTabItems.Remove(this.draggingBuddy);
     }
     this.draggingBuddy = null;
 }
 public void ShowDropPreview(Buddy buddy)
 {
     base.Activate();
     //this.sessionsControl.ShowDropPreview();
     if ((this.draggingBuddy == null) || (this.draggingBuddy.Buddy != buddy))
     {
         this.draggingBuddy = new SessionTabItem(buddy);
         this.sessionTabItems.Add(this.draggingBuddy);
     }
 }
 public static bool CloseSessionWhenExist(uint uin)
 {
     for (int i = 0; i < ContactSessionWindows.Count; i++)
     {
         SessionTabItem sessionTabItem = ContactSessionWindows[i].FindIMSession(uin);
         if (sessionTabItem != null)
         {
             ContactSessionWindows[i].ReleaseSession(sessionTabItem, true);
             return(true);
         }
     }
     return(false);
 }
        public void OnMessageAdded(object sender, EventArgs args)
        {
            SessionTabItem item = (SessionTabItem)sender;

            if (item == this.CurrentSessionTabItem)
            {
                this.RefreshOutputBox();
            }
            else
            {
                item.HasNewMessage = true;
            }
        }
 public void AddSession(SessionTabItem sessionTabItem)
 {
     sessionTabItem.MessageIndex  = 0;
     sessionTabItem.MessageAdded += new EventHandler <EventArgs>(this.OnMessageAdded);
     if (sessionTabItem.InputBoxDocument == null)
     {
         sessionTabItem.InputBoxDocument = new FlowDocument();
     }
     this.sessionTabItems.Add(sessionTabItem);
     this.CurrentIMSession = sessionTabItem;
     this.NotifyAIOSessionEvent("AIO_AddSession", (this.CurrentIMSession != null) ? this.CurrentIMSession.Buddy : null);
     ComponentManager.GetBuddyManager().Info.Refresh(this.CurrentIMSession.Buddy.Uin, IMContactInfoCat.QQInfo);
 }
 public void AddSession(SessionTabItem sessionTabItem)
 {
     sessionTabItem.MessageIndex  = 0;
     sessionTabItem.MessageAdded += new EventHandler <EventArgs>(this.OnMessageAdded);
     if (sessionTabItem.InputBoxDocument == null)
     {
         sessionTabItem.InputBoxDocument = new FlowDocument();
     }
     this.sessionTabItems.Add(sessionTabItem);
     this.CurrentSessionTabItem = sessionTabItem;
     this.CurrentSessionTabItem.CommunitySession.Community.CommunityManager.RefreshCommunityFromServer();
     this.CurrentSessionTabItem.CommunitySession.Community.CommunityManager.UpdateMemberStatus(true);
     this.CurrentSessionTabItem.CommunitySession.Community.CommunityManager.UpdateMemCardInfo(Util_Buddy.GetCurrentBuddy().Uin);
 }
 internal void OnTabItemDeleted(object sender, RoutedEventArgs e)
 {
     if (this.sessionsControl.ItemsSource != null)
     {
         Bama.Controls.TabItem originalSource = e.OriginalSource as Bama.Controls.TabItem;
         if (originalSource != null)
         {
             SessionTabItem sessionTabItem = (SessionTabItem)this.sessionsControl.ItemContainerGenerator.ItemFromContainer(originalSource);
             if (sessionTabItem != null)
             {
                 this.ReleaseSession(sessionTabItem, true);
             }
         }
     }
 }
        internal void OnSelectedTabItemChanged(object sender, RoutedEventArgs e)
        {
            SessionTabItem selectedItem = this.sessionsControl.SelectedItem as SessionTabItem;

            if (selectedItem != null)
            {
                base.Title                = string.Format("{0} - 群窗口", selectedItem.CommunitySession.Community.CombineRemarkName);
                this.InputBox.Document    = selectedItem.InputBoxDocument;
                selectedItem.MessageIndex = 0;
                this.OutputBox.Document.Blocks.Clear();
                this.RefreshOutputBox();
            }
            else
            {
                this.InputBox.Document = new FlowDocument();
            }
        }
 public static bool ActiveSessionWhenExist(CommunitySession communitySession)
 {
     for (int i = 0; i < CommunitySessionWindows.Count; i++)
     {
         SessionTabItem item = CommunitySessionWindows[i].FindIMSession(communitySession);
         if (item != null)
         {
             if (CommunitySessionWindows[i].WindowState == WindowState.Minimized)
             {
                 CommunitySessionWindows[i].WindowState = WindowState.Normal;
             }
             CommunitySessionWindows[i].Show();
             CommunitySessionWindows[i].Activate();
             CommunitySessionWindows[i].CurrentSessionTabItem = item;
             return(true);
         }
     }
     return(false);
 }
 public static bool ActiveSessionWhenExist(uint uin, Point?mousePosition)
 {
     for (int i = 0; i < ContactSessionWindows.Count; i++)
     {
         SessionTabItem item = ContactSessionWindows[i].FindIMSession(uin);
         if (item != null)
         {
             ContactSessionWindow window = ContactSessionWindows[i];
             if (window.WindowState == WindowState.Minimized)
             {
                 window.WindowState = WindowState.Normal;
             }
             ContactSessionWindows[i].Activate();
             ContactSessionWindows[i].CurrentIMSession = item;
             return(true);
         }
     }
     return(false);
 }
 public ContactSessionWindow(SessionTabItem sessionTabItem)
 {
     RoutedEventHandler handler = null;
     this.sessionTabItems = new ObservableCollection<SessionTabItem>();
     this._buddyWhenWindowCreated = sessionTabItem.Buddy;
     base.Unloaded += new RoutedEventHandler(this.ContactSessionWindow_Unloaded);
     this.InitializeComponent();
     ContactSessionWindows.Add(this);
     CoreMessenger.Instance.MessageCenter.AddMessageProcessor(this);
     this.AddSession(sessionTabItem);
     if (handler == null)
     {
         handler = delegate
         {
             //if (this.sessionsControl.ShouldLoseFocus)
             //{
             //    this.SetFocusOnInputBoxWithDelay();
             //}
             //this.sessionsControl.ShouldLoseFocus = false;
         };
     }
     // this.sessionsControl.AddHandler(UIElement.GotFocusEvent, handler);
 }
 public CommunitySessionWindow(SessionTabItem sessionTabItem)
 {
     this.sessionTabItems = new ObservableCollection<SessionTabItem>();
     //WindowHelper.Hook(this, "headerBackground", new string[] { "controlBox", "toolBar" });
     this.InitializeComponent();
     Util_UserSettings_ContactSessionWindow.SettingsChanged += new PropertyChangedEventHandler(this.Util_UserSettings_CommunitySessionWindow_SettingsChanged);
     this.SetSendButtonToolTip();
     this.AddSession(sessionTabItem);
     if (_icon == null)
     {
         _icon = BitmapFrame.Create(new Uri(EnvironmentPath.Startup + @"res\community16.ico", UriKind.Absolute));
     }
     base.Icon = _icon;
     this.BindWindowTitleAndIcon();
     this.communityManager = this.CurrentSessionTabItem.CommunitySession.Community.CommunityManager;
     this.communityManager.RefreshAllMemberInfo();
     this.communityManager.SortManager.SortEvent += new EventHandler<EventArgs>(this.CommunityMemberSortManager_Sort);
     this.communityManager.SortManager.RequestSorting();
     this.CurrentSessionTabItem.CommunitySession.Community.PropertyChanged += new PropertyChangedEventHandler(this.CommunitySessionWindow_PropertyChanged);
     Buddy.BuddyPropertyChanged += new PropertyChangedEventHandler(this.Buddy_BuddyPropertyChanged);
     this.communityManager.MemberChanged += new EventHandler(this.communityManager_MemberChanged);
     this.CalcMemberCount();
     this.SetMsgSetImage();
 }
        public ContactSessionWindow(SessionTabItem sessionTabItem)
        {
            RoutedEventHandler handler = null;

            this.sessionTabItems         = new ObservableCollection <SessionTabItem>();
            this._buddyWhenWindowCreated = sessionTabItem.Buddy;
            base.Unloaded += new RoutedEventHandler(this.ContactSessionWindow_Unloaded);
            this.InitializeComponent();
            ContactSessionWindows.Add(this);
            CoreMessenger.Instance.MessageCenter.AddMessageProcessor(this);
            this.AddSession(sessionTabItem);
            if (handler == null)
            {
                handler = delegate
                {
                    //if (this.sessionsControl.ShouldLoseFocus)
                    //{
                    //    this.SetFocusOnInputBoxWithDelay();
                    //}
                    //this.sessionsControl.ShouldLoseFocus = false;
                };
            }
            // this.sessionsControl.AddHandler(UIElement.GotFocusEvent, handler);
        }
 public CommunitySessionWindow(SessionTabItem sessionTabItem)
 {
     this.sessionTabItems = new ObservableCollection <SessionTabItem>();
     //WindowHelper.Hook(this, "headerBackground", new string[] { "controlBox", "toolBar" });
     this.InitializeComponent();
     Util_UserSettings_ContactSessionWindow.SettingsChanged += new PropertyChangedEventHandler(this.Util_UserSettings_CommunitySessionWindow_SettingsChanged);
     this.SetSendButtonToolTip();
     this.AddSession(sessionTabItem);
     if (_icon == null)
     {
         _icon = BitmapFrame.Create(new Uri(EnvironmentPath.Startup + @"res\community16.ico", UriKind.Absolute));
     }
     base.Icon = _icon;
     this.BindWindowTitleAndIcon();
     this.communityManager = this.CurrentSessionTabItem.CommunitySession.Community.CommunityManager;
     this.communityManager.RefreshAllMemberInfo();
     this.communityManager.SortManager.SortEvent += new EventHandler <EventArgs>(this.CommunityMemberSortManager_Sort);
     this.communityManager.SortManager.RequestSorting();
     this.CurrentSessionTabItem.CommunitySession.Community.PropertyChanged += new PropertyChangedEventHandler(this.CommunitySessionWindow_PropertyChanged);
     Buddy.BuddyPropertyChanged          += new PropertyChangedEventHandler(this.Buddy_BuddyPropertyChanged);
     this.communityManager.MemberChanged += new EventHandler(this.communityManager_MemberChanged);
     this.CalcMemberCount();
     this.SetMsgSetImage();
 }
 public void ReleaseSession(SessionTabItem sessionTabItem, bool close)
 {
     if (sessionTabItem == null)
     {
         throw new ArgumentNullException("sessionTabItem");
     }
     if (close)
     {
         sessionTabItem.Close();
     }
     sessionTabItem.MessageAdded -= new EventHandler<EventArgs>(this.OnMessageAdded);
     if (this.sessionTabItems.Contains(sessionTabItem))
     {
         this.sessionTabItems.Remove(sessionTabItem);
         if (this.sessionTabItems.Count > 0)
         {
             this.CurrentSessionTabItem = this.sessionTabItems[0];
         }
         else
         {
             this.CurrentSessionTabItem = null;
             base.Close();
         }
     }
 }
 public void AddSession(SessionTabItem sessionTabItem)
 {
     sessionTabItem.MessageIndex = 0;
     sessionTabItem.MessageAdded += new EventHandler<EventArgs>(this.OnMessageAdded);
     if (sessionTabItem.InputBoxDocument == null)
     {
         sessionTabItem.InputBoxDocument = new FlowDocument();
     }
     this.sessionTabItems.Add(sessionTabItem);
     this.CurrentSessionTabItem = sessionTabItem;
     this.CurrentSessionTabItem.CommunitySession.Community.CommunityManager.RefreshCommunityFromServer();
     this.CurrentSessionTabItem.CommunitySession.Community.CommunityManager.UpdateMemberStatus(true);
     this.CurrentSessionTabItem.CommunitySession.Community.CommunityManager.UpdateMemCardInfo(Util_Buddy.GetCurrentBuddy().Uin);
 }
 public void StopDropPreview()
 {
     //this.sessionsControl.StopDropPreview();
     if ((this.draggingBuddy != null) && this.sessionTabItems.Contains(this.draggingBuddy))
     {
         this.sessionTabItems.Remove(this.draggingBuddy);
     }
     this.draggingBuddy = null;
 }
 public void ShowDropPreview(Buddy buddy)
 {
     base.Activate();
     //this.sessionsControl.ShowDropPreview();
     if ((this.draggingBuddy == null) || (this.draggingBuddy.Buddy != buddy))
     {
         this.draggingBuddy = new SessionTabItem(buddy);
         this.sessionTabItems.Add(this.draggingBuddy);
     }
 }
 public void AddSession(SessionTabItem sessionTabItem)
 {
     sessionTabItem.MessageIndex = 0;
     sessionTabItem.MessageAdded += new EventHandler<EventArgs>(this.OnMessageAdded);
     if (sessionTabItem.InputBoxDocument == null)
     {
         sessionTabItem.InputBoxDocument = new FlowDocument();
     }
     this.sessionTabItems.Add(sessionTabItem);
     this.CurrentIMSession = sessionTabItem;
     this.NotifyAIOSessionEvent("AIO_AddSession", (this.CurrentIMSession != null) ? this.CurrentIMSession.Buddy : null);
     ComponentManager.GetBuddyManager().Info.Refresh(this.CurrentIMSession.Buddy.Uin, IMContactInfoCat.QQInfo);
 }