Ejemplo n.º 1
0
        /// Last Modified: 10/24/10
        /// <summary>
        /// Connect the node depending on the hosting state.
        /// Hosting Enabled: Begin running the server.
        /// Hosting Disabled: Connects to the host.
        /// </summary>
        /// -----------------------------------------------------
        /// PRECONDITIONS: NA -- No preconditions exist.
        /// -----------------------------------------------------
        /// Parameters:
        /// -----------------------------------------------------
        /// POSTCONDITIONS:
        /// 1) The host server will be running.
        /// 2) The child node will attempt to connect to the server.
        /// -----------------------------------------------------
        /// Return Value:
        private void Connect()
        {
            try
            {
                NodeSimpleSecurityModel nssm = null;
                if(!String.IsNullOrEmpty(txtPassphrase.Text))
                    nssm = new NodeSimpleSecurityModel(SimpleCryptography.EncryptionScheme.DES, txtPassphrase.Text);

                //The host never generates an asynchronous event and either fails
                // or succeeds immediately.
                SafelyToggleInterfaceState(true);

                //Determine if the node will be a host/parent.
                if (m_IsHosting)
                {
                    //Obtain the port to listen on.
                    int nPort = int.Parse(txtListeningPort.Text);

                    //Create the parent node and start listening.
                    ParentNode pn = new ParentNode(nPort, nssm);
                    pn.NodeEventCallback = ParentNode_OnNodeEvent;
                    pn.Start();

                    //Update the hosting status.
                    lblStatus.Text = "Running...";

                    m_Node = pn;

                    //Update the notification icon to reflect the node's name.
                    cmiNodeType.Text = notificationIcon.Text = "DSChat [Parent]";

                    //Neutral Max means everything is okay.
                    SafelySetIcon(DSChat.Properties.Resources.MAX);

                    IsConnected = ConnectionState.Connected;
                }
                //This would be a child node.
                else
                {
                    //Obtain the port to listen on for responses.
                    int nListeningPort = int.Parse(txtListeningPort.Text);

                    //Obtain the server address & port of the parent\host.
                    int nHostPort = int.Parse(txtHostPort.Text);
                    IPAddress ipAddy = NodeSocket.GetIP4HostAddresses(txtServer.Text);

                    //Create the child node and register it with the parent with the
                    // node name provided.
                    ChildNode cn = new ChildNode(nListeningPort, nssm);
                    cn.NodeName = txtName.Text;
                    cn.NodeEventCallback = ChildNode_OnNodeEvent;
                    cn.Start(ipAddy, nHostPort);

                    m_Node = cn;

                    //Update the notification icon to reflect the node's name.
                    cmiNodeType.Text = notificationIcon.Text = "DSChat [" + txtName.Text + "]";

                    //The connection has not been made and synchornization is not required here
                    // as the thread has not been spun up yet.
                    IsConnected = ConnectionState.IsConnecting;

                    SetStatusLabel("Connecting...");

                    m_connectionWaitingThread = new Thread(ThreadProc_WaitingForConnection);
                    m_connectionWaitingThread.Start((object)this);
                }
            }
            catch (Exception ex)
            {
                SetStatusLog(ex.Message);
                Disconnect();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an instance.
        /// </summary>
        /// <param name="chatform"></param>
        public void Create(string friendsUserId, string currentUserId, ChildNode cn)
        {
            //Set the chatform and dump the offline message into the new chatform.
            if (m_chatform == null)
            {
                m_chatform = new ChatForm(friendsUserId, currentUserId, cn);

                if (m_offlineChat != null)
                    m_chatform.WriteMessageToChatLog(m_offlineChat);
            }
        }
Ejemplo n.º 3
0
        /// Last Modified: 9/21/10
        /// <summary>
        /// A customized constructor that allows for instantiation of the forms primary properties.
        /// </summary>
        /// -----------------------------------------------------
        /// PRECONDITIONS: NA -- No preconditions exist.
        /// -----------------------------------------------------
        /// Parameters:
        /// <param name="friendsUserId">
        /// The UserId of the individual "friend" that this user is chatting with.
        /// </param>
        /// <param name="currentUserId">
        /// The UserId of this user.
        /// </param>
        /// <param name="cn">
        /// The current child node used to communicate with the host.
        /// </param>
        /// -----------------------------------------------------
        /// POSTCONDITIONS: NA -- No postconditions exist.
        /// -----------------------------------------------------
        /// Return Value:
        public ChatForm(string friendsUserId, string currentUserId, ChildNode cn)
            : this()
        {
            //Assign the properties.
            FriendsUserId = friendsUserId;
            YourUserId = currentUserId;
            Node = cn;

            //Update the caption of the form.
            this.Text = FriendsUserId;
        }