Пример #1
0
        public bool TestDefaultIP()
        {
            string defaultIP = ((MainWindow)this.Owner).ConfigHashtable["CurrentIP"].ToString();

            Communication.Type = CommunicationType.Network;

            System.Net.IPAddress testedIP = System.Net.IPAddress.Parse("0.0.0.0");
            AvailableSocket      tmp      = NetworkCommunication.TestGivenSocket(defaultIP);

            if (testedIP.Equals(tmp.Ip))
            {
                ((MainWindow)(this.Owner)).logWindow.Message = ((MainWindow)(this.Owner)).logMessagesHashTable["logMessage_searchingByIpDefaultNotFound"].ToString();
                //MessageBox.Show("The screen was not found via network default IP address.", "BengiLED - Connection Failure", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Communication.Type = CommunicationType.None;

                return(false);
            }
            else
            {
                NetworkCommunication.SocketsList.Add(tmp);
                ((MainWindow)(this.Owner)).logWindow.Message = string.Format("{0} {1}", ((MainWindow)(this.Owner)).logMessagesHashTable["logMessage_searchingByIpFoundIpIsDefault"].ToString(), NetworkCommunication.SocketsList[0].Ip);
                //MessageBox.Show(string.Format("The screen was found via network connection. IP is default {0}", NetworkCommunication.SocketsList[0].Ip), "BengiLED - Connection Succes", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(true);
            }
        }
Пример #2
0
        // End of added code

        private void connectButton_Click(object sender, EventArgs e)
        {
            if (IpAdressTextBox.Text != null && IpAdressTextBox.Text != "")
            {
                ((MainWindow)(this.Owner)).logWindow.Message = ((MainWindow)(this.Owner)).logMessagesHashTable["logMessage_searchingByIpAttemptingToConnect"].ToString();
                this.Cursor = Cursors.WaitCursor;

                Communication.CardID = 255;
                System.Net.IPAddress testedIP = System.Net.IPAddress.Parse("0.0.0.0");
                AvailableSocket      tmp      = NetworkCommunication.TestGivenSocket(IpAdressTextBox.Text);
                if (testedIP.Equals(tmp.Ip))
                {
                    ((MainWindow)(this.Owner)).logWindow.Message = ((MainWindow)(this.Owner)).logMessagesHashTable["logMessage_searchingByIpUnableToConnect"].ToString();
                    //MessageBox.Show("The screen was not found via network connection.\nProbably given IP was misstyped.", "BengiLED - Connection Failure", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    found = false;
                }
                else
                {
                    NetworkCommunication.SocketsList.Add(tmp);
                    ((MainWindow)(this.Owner)).logWindow.Message = string.Format("{0} {1}", ((MainWindow)(this.Owner)).logMessagesHashTable["logMessage_searchingByIpFoundIpIs"].ToString(), NetworkCommunication.SocketsList[0].Ip);
                    //MessageBox.Show(string.Format("The screen was found via network connection. IP is {0}", NetworkCommunication.SocketsList[0].Ip), "BengiLED - Connection Succes", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    found = true;
                    this.Close();
                }

                this.Cursor = Cursors.Default;
            }
        }
Пример #3
0
        void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            bool      breakWhenFound = true;
            IPAddress ip             = IPAddress.Parse(((object[])(e.Argument))[0].ToString());
            int       minAddressVal  = Int32.Parse(((object[])(e.Argument))[1].ToString());
            int       maxAddressVal  = Int32.Parse(((object[])(e.Argument))[2].ToString());



            NetworkCommunication.SocketsList.Clear();

            byte[] tmpNetIp = ip.GetAddressBytes();
            UInt32 net      = (UInt32)tmpNetIp[0] << 24;

            net += (UInt32)tmpNetIp[1] << 16;
            net += (UInt32)tmpNetIp[2] << 8;

            string NetAddress;

            if (minAddressVal < 1)
            {
                minAddressVal = 1;
            }
            if (maxAddressVal > 254)
            {
                maxAddressVal = 254;
            }

            if (minAddressVal > maxAddressVal)
            {
                int t = minAddressVal;
                minAddressVal = maxAddressVal;
                maxAddressVal = t;
            }
            else if (minAddressVal == maxAddressVal)
            {
                if (minAddressVal > 2)
                {
                    --minAddressVal;
                }
                else if (maxAddressVal < 253)
                {
                    maxAddressVal++;
                }
            }

            System.Net.IPAddress testedIP = System.Net.IPAddress.Parse("0.0.0.0");
            AvailableSocket      tmp;

            for (int i = minAddressVal; i <= maxAddressVal; ++i)
            {
                // added code
                if (bgWorker.CancellationPending == true)
                {
                    e.Cancel = true;
                    break;
                }
                // end of added code

                NetAddress = (net + i).ToString();

                int percentComplete = (int)((float)(i - minAddressVal) / (float)(maxAddressVal - minAddressVal) * 100);
                bgWorker.ReportProgress(percentComplete, NetAddress);

                tmp = NetworkCommunication.TestGivenSocket(NetAddress);

                if (!(tmp.Ip.Equals(testedIP)))
                {
                    NetworkCommunication.SocketsList.Add(tmp);
                    if (breakWhenFound == true)
                    {
                        break;
                    }
                }
            }
        }