private void Join() { var task = Task.Factory.StartNew(() => { Thread.Sleep(JoinWait); // wait for 5 seconds foreach (var roomName in roomNames) { ChatRoom chatRoom = new ChatRoom(roomName, new MockLogger()); chatRoom.AddMember(new Member { UserName = "******", PrivClass = "Owners" }); chatRoom.AddMember(new Member { UserName = "******", PrivClass = "Owners" }); chatRoom.AddMember(new Member { UserName = "******", PrivClass = "Operator" }); chatRoom.AddMember(new Member { UserName = "******", PrivClass = "Member" }); chatRoom.AddMember(new Member { UserName = "******", PrivClass = "Guest" }); chatRoom.AddMember(new Member { UserName = "******", PrivClass = "Guest" }); chatRoom.AddMember(new Member { UserName = "******", PrivClass = "Guest" }); chatRoom.AddMember(new Member { UserName = "******", PrivClass = "Guest" }); chatrooms.Add(chatRoom); Module.DispatchToApp(() => { MainWindowHandle.Handle.JoinChatroom(chatRoom, client); }); } }); task.Wait(); Thread.Sleep(AfterJoinWait); }
/// <summary> /// Initializes a new instance of the <see cref="ChatroomControl"/> class. /// </summary> /// <param name="chatroom">The chatroom.</param> /// <param name="client">The client.</param> public ChatroomControl(ChatRoom chatroom, Client client) { // save the chatroom and tie into events this.chatroom = chatroom; this.chatroom.CollectionChanged += new EventHandler<MultipleNotifyCollectionChangedEventArgs>(chatroom_CollectionChanged); this.chatroom.Logger.OnPacketReceived += new PacketReceived(Logger_OnPacketReceived); // save the client this.client = client; // init the UI from chatroom InitializeMembers(); InitializeComponent(); InitializeChatWindow(); }
/// <summary> /// Joins the chatroom. /// </summary> /// <param name="chatroom">The chatroom.</param> /// <param name="client">The client.</param> public void JoinChatroom(ChatRoom chatroom, Client client) { if (excludedRooms.Contains(chatroom.Name)) return; IsBusy = false; ChatroomControl chatControl = new ChatroomControl(chatroom, client); TabItem tabItem = new TabItem(); tabItem.Header = "#" + chatroom.Name; tabItem.Content = chatControl; tabControl1.Items.Add(tabItem); // if we only have one chatroom select that one if (tabControl1.Items.Count == 1) tabItem.IsSelected = true; }
/// <summary> /// Creates a new chat view model. /// </summary> /// <param name="chatRoom">Chatroom.</param> /// <returns></returns> public ChatViewModel Create(ChatRoom chatRoom) { var viewModel = kernel.Resolve<ChatViewModel>(new { chatRoom = chatRoom }); return viewModels[viewModel.Title] = viewModel; }
/// <summary> /// Parts the chatroom. /// </summary> /// <param name="chatroom">The chatroom.</param> public void PartChatroom(ChatRoom chatroom) { var tabItems = tabControl1.Items.OfType<TabItem>(); foreach (var tabItem in tabItems) { string header = tabItem.Header.ToString().Trim('#').ToLower(); if (header == chatroom.Name.Trim('#').ToLower()) { tabControl1.Items.Remove(tabItem); break; } } // if we only have one chatroom select that one if (tabControl1.Items.Count == 1) tabItem1.IsSelected = true; }
/// <summary> /// Initializes a new instance of the <see cref="ChatViewModel"/> class. /// </summary> /// <param name="chatRoom">The chat room.</param> /// <param name="settings">Bot Settings.</param> public ChatViewModel(ChatRoom chatRoom, IBotSettings settings) { this.chatRoom = chatRoom; this.userName = settings.UserName; }
/// <summary> /// Adds the specified chatroom to the collection.. /// </summary> /// <param name="chatRoomName">Name of the chatroom.</param> public void Add(string chatRoomName) { chatRoomName = AdjustName(chatRoomName); if (!this.chatrooms.ContainsKey(chatRoomName)) { var chatRoom = new ChatRoom(chatRoomName, logFactory.Create(chatRoomName)); this.chatrooms.Add(chatRoomName, chatRoom); FireCollectionChanged(new NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction.Add, chatRoom)); } }