Пример #1
0
        public void OnChatClosed(FrameworkElement vChat)
        {
            var data = vChat.Tag as Tuple <RatChat.Core.IChatSource, string>;

            data.Item1.OnNewMessagesArrived -= ichat_OnNewMessagesArrived;
            data.Item1.EndWork();


            RatChat.Core.IChatListener iListener = data.Item1 as RatChat.Core.IChatListener;
            if (iListener == null)
            {
                foreach (FrameworkElement fe in Chats)
                {
                    RatChat.Core.IChatSource   i  = ((Tuple <RatChat.Core.IChatSource, string>)fe.Tag).Item1;
                    RatChat.Core.IChatListener il = i as RatChat.Core.IChatListener;
                    if (il != null)
                    {
                        data.Item1.OnNewMessagesArrived -= il.OnNewMessageReceived;
                    }
                    //i.OnNewMessagesArrived += iListener.OnNewMessageReceived;
                }
            }
            else
            {
                foreach (FrameworkElement fe in Chats)
                {
                    RatChat.Core.IChatSource i = ((Tuple <RatChat.Core.IChatSource, string>)fe.Tag).Item1;
                    i.OnNewMessagesArrived -= iListener.OnNewMessageReceived;
                }
            }

            Chats.Remove(vChat);

            ChatConfigStorage.RemoveWithPrefix(data.Item1.ConfigPrefix);
        }
Пример #2
0
        public void CreateChat(string ConfigPrefix, string SourceChatId)
        {
            if (!Sources.ContainsKey(SourceChatId))
            {
                return;
            }

            RatChat.Core.IChatSource ichat = Activator.CreateInstance(Sources[SourceChatId]) as RatChat.Core.IChatSource;
            ichat.ConfigPrefix = ConfigPrefix;
            ichat.OnLoad(ChatConfigStorage);
            ichat.OnNewMessagesArrived += ichat_OnNewMessagesArrived;


            if (ichat.SmilesUri != null)
            {
                foreach (var smile in ichat.SmilesUri)
                {
                    SmilesDataDase.AddSmileTuple(smile.Key, smile.Value);
                }
            }

            UserControl customView = ichat.CreateCustomView();

            if (customView == null)
            {
                RatChat.Controls.VisualChatCtrl vchat = new Controls.VisualChatCtrl();
                vchat.Manager = this;
                vchat.Tag     = new Tuple <RatChat.Core.IChatSource, string>(ichat, SourceChatId);
                Chats.Add(vchat);
                vchat.ConnectToChatSource(ichat);
            }
            else
            {
                RatChat.Controls.CustomControlContainer vchat = new Controls.CustomControlContainer();
                vchat.Manager = this;
                vchat.Tag     = new Tuple <RatChat.Core.IChatSource, string>(ichat, SourceChatId);
                Chats.Add(vchat);
                vchat.ConnectToChatSource(customView, ichat);
            }


            RatChat.Core.IChatListener iListener = ichat as RatChat.Core.IChatListener;
            if (iListener != null)
            {
                // При добавлении Listener, ищу ВСЕ Source и подписываюсь
                foreach (FrameworkElement fe in Chats)
                {
                    RatChat.Core.IChatSource i = ((Tuple <RatChat.Core.IChatSource, string>)fe.Tag).Item1;
                    i.OnNewMessagesArrived += iListener.OnNewMessageReceived;
                }
            }
            else
            {
                // При добавлении Source, ищу ВСЕ Listeners и подписываю
                foreach (FrameworkElement fe in Chats)
                {
                    RatChat.Core.IChatSource   i  = ((Tuple <RatChat.Core.IChatSource, string>)fe.Tag).Item1;
                    RatChat.Core.IChatListener il = i as RatChat.Core.IChatListener;
                    if (il != null)
                    {
                        ichat.OnNewMessagesArrived += il.OnNewMessageReceived;
                    }
                    //i.OnNewMessagesArrived += iListener.OnNewMessageReceived;
                }
            }
        }