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; } } }
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; } } }