// Last Modified: 10/31/10 /// <summary> /// Forces the chatform to show up for debugging purposes. /// </summary> /// ----------------------------------------------------- /// PRECONDITIONS: NA -- No preconditions exist. /// ----------------------------------------------------- /// Parameters: /// <param name="sender"></param> /// <param name="e"></param> /// ----------------------------------------------------- /// POSTCONDITIONS: NA -- No postconditions exist. /// ----------------------------------------------------- /// Return Value: private void showChatFormToolStripMenuItem_Click(object sender, EventArgs e) { string sEntityId = "DEBUG"; ChatIntermediary ci = null; if (!m_Chats.ContainsKey(sEntityId)) { ci = new ChatIntermediary(); m_Chats.Add(sEntityId, ci); } else ci = m_Chats[sEntityId]; //Set common properties. ci.Create(sEntityId, txtName.Text, (ChildNode)m_Node); ci.InFocusOpacity = GlobalInFocusOpacity; ci.OpacityChangedEventCallback = OnOpacityChanged_ChatForm; ci.MessageNoticedEventCallback = OnMessageNoticed_ChatForm; //When a user clicks on this item, restore the original icon. UpdateRegisteredUsersListBox(sEntityId, ListViewArgumentType.ModifyItem, 0); //Show the chat window. ci.Show(); }
/// Last Modified: 9/18/10 /// <summary> /// An event that is triggered when an event occurs on a child node. /// </summary> /// ----------------------------------------------------- /// PRECONDITIONS: NA -- No preconditions exist. /// ----------------------------------------------------- /// Parameters: /// <param name="nodeEvent"> /// The node event that has occcurred. /// </param> /// <param name="sEntityId"> /// The id or name of the entity that spawned the event. /// </param> /// <param name="sData"> /// Associated data with the event. /// </param> /// ----------------------------------------------------- /// POSTCONDITIONS: NA -- No postconditions exist. /// ----------------------------------------------------- /// Return Value: public void ChildNode_OnNodeEvent(RootNode.NodeEvent nodeEvent, string sEntityId, string sData) { switch (nodeEvent) { case RootNode.NodeEvent.REGISTRATION_SUCCESSFUL: { //If the string is empty, don't bother. if (!String.IsNullOrEmpty(sData)) { //Tokenize the string and update the registered users list box // with the current list of active users. string[] sUsersList = sData.Split(new char[] { '~' }); foreach (string s in sUsersList) UpdateRegisteredUsersListBox(s, ListViewArgumentType.AddItem, 0); } SafelyToggleInterfaceState(true); //Notify the form that a successful connection has been made. m_mutexIsConnected.WaitOne(MUTEX_TIMEOUT); IsConnected = ConnectionState.Connected; m_mutexIsConnected.ReleaseMutex(); SetStatusLabel("Connected"); SetStatusLog("Successfully registered with the host."); //Neutral Max means everything is okay. SafelySetIcon(DSChat.Properties.Resources.MAX); } break; case RootNode.NodeEvent.REGISTRATION_FAILURE: { Disconnect(); SetStatusLabel("Not connected"); SetStatusLog(sEntityId + " has already registered. Use a different name."); } break; case RootNode.NodeEvent.NODE_ADDED: { UpdateRegisteredUsersListBox(sData, ListViewArgumentType.AddItem, 0); SetStatusLog("User " + sData + " has joined."); } break; case RootNode.NodeEvent.NODE_REMOVED: { UpdateRegisteredUsersListBox(sData, ListViewArgumentType.RemoveItem, 0); SetStatusLog("User " + sData + " has left."); //Ignore any invalid ChatIntermediaries. ChatIntermediary ci = null; if (m_Chats.ContainsKey(sData)) { ci = m_Chats[sData]; } else { ci = new ChatIntermediary(); m_Chats.Add(sData, ci); } ci.WriteToChatLog("User " + sData + " has left."); } break; case RootNode.NodeEvent.INVALID_NODE: { SetStatusLog(sData + " is not a valid node."); } break; case RootNode.NodeEvent.PARENT_SHUTDOWN: { Disconnect(); SetStatusLabel("Not connected"); SetStatusLog("The server has shutdown."); } break; case RootNode.NodeEvent.NETWORK_ERROR: { SetStatusLog(sData); } break; case RootNode.NodeEvent.MESSAGE: { //Ignore any invalid ChatIntermediaries. ChatIntermediary ci = null; if (m_Chats.ContainsKey(sEntityId)) { ci = m_Chats[sEntityId]; } else { ci = new ChatIntermediary(); m_Chats.Add(sEntityId, ci); } //END OF if (m_Chats.ContainsKey(sEntityId))... ci.WriteToChatLog(sData); UpdateRegisteredUsersListBox(sEntityId, ListViewArgumentType.ModifyItem, (ci.IsVisible ? 0 : 1)); SafelySetIcon(DSChat.Properties.Resources.GreenMax); } break; case RootNode.NodeEvent.SEVERE_NETWORK_ERRROR: { SetStatusLog(sData); //Need synchronization here. Disconnect(); } break; } //END OF switch (nodeEvent)... }
/// Last Modified: 9/21/10 /// <summary> /// An event that is triggered when a user double clicks on the registered /// user's listview. /// The host should ignore these events at this time. /// </summary> /// ----------------------------------------------------- /// PRECONDITIONS: NA -- No preconditions exist. /// ----------------------------------------------------- /// Parameters: /// <param name="sender"></param> /// <param name="e"></param> /// ----------------------------------------------------- /// POSTCONDITIONS: NA -- No postconditions exist. /// ----------------------------------------------------- /// Return Value: private void lvRegisteredUsers_Click(object sender, EventArgs e) { //Ignore messages from the host. if (m_IsHosting) return; string sEntityId = ((ListView)sender).SelectedItems[0].Text; ChatIntermediary ci = null; if (!m_Chats.ContainsKey(sEntityId)) { ci = new ChatIntermediary(); m_Chats.Add(sEntityId, ci); } else ci = m_Chats[sEntityId]; //Set common properties. ci.Create(sEntityId, txtName.Text, (ChildNode)m_Node); ci.InFocusOpacity = GlobalInFocusOpacity; ci.OpacityChangedEventCallback = OnOpacityChanged_ChatForm; ci.MessageNoticedEventCallback = OnMessageNoticed_ChatForm; //When a user clicks on this item, restore the original icon. UpdateRegisteredUsersListBox(sEntityId, ListViewArgumentType.ModifyItem, 0); SafelySetIcon(DSChat.Properties.Resources.MAX); //Show the chat window. ci.Show(); }