Esempio n. 1
0
 public LocalSetting()
 {
     fileName  = string.Format("{0}\\LocalSetting.txt", XMLDirectory);
     IpAddress = All.Class.HardInfo.GetIpAddress("192.168.1");
     if (IpAddress != "")
     {
         TestNo = (All.Class.Num.ToInt(IpAddress.Split('.')[3]) % 100);
     }
     PrintName    = "ZDesigner 105SLPlus-300dpi ZPL";
     YinXiangFile = "E:\\Photo\\";
 }
Esempio n. 2
0
        bool IsPrivateNetwork()
        {
            bool isPN = false;

            string[] ips = IpAddress.Split('.');
            int      w   = int.Parse(ips[0]);
            int      x   = int.Parse(ips[1]);
            int      y   = int.Parse(ips[2]);
            int      z   = int.Parse(ips[3]);

            // Private Network
            // http://en.wikipedia.org/wiki/Private_network

            if (w == 127 && x == 0 && y == 0 && z == 1) // 127.0.0.1
            {
                isPN = true;

                _countryName = "Localhost";
                _regionName  = "Localhost";
                _cityName    = "Localhost";
            }
            else if (w == 10) // 10.0.0.0 - 10.255.255.255
            {
                isPN = true;

                _countryName = "Private Network";
                _regionName  = "Private Network";
                _cityName    = "Private Network";
            }
            else if (w == 172 && (x >= 16 || x <= 31)) // 172.16.0.0 - 172.31.255.255
            {
                isPN = true;

                _countryName = "Private Network";
                _regionName  = "Private Network";
                _cityName    = "Private Network";
            }
            else if (w == 192 && x == 168) // 192.168.0.0 - 192.168.255.255
            {
                isPN = true;

                _countryName = "Private Network";
                _regionName  = "Private Network";
                _cityName    = "Private Network";
            }

            return(isPN);
        }
Esempio n. 3
0
        public string GetIP() //Gets the IP address from the user. Returns error if incorrect IP
        {
            Console.WriteLine("Entered IP Address");


            IPOctet = IpAddress.Split('.');
            if (IPOctet.Length != 4)
            {
                IpAddress = "Error";
                return("Error");
            }
            IPOctet0 = Convert.ToInt32(IPOctet[0]);
            if (IPOctet0.CompareTo(254) > 0 ||
                Convert.ToInt32(IPOctet[1]).CompareTo(254) > 0 ||
                Convert.ToInt32(IPOctet[2]).CompareTo(254) > 0 ||
                Convert.ToInt32(IPOctet[3]).CompareTo(254) > 0)
            {
                IpAddress = "Error";
                return("Error");
            }
            return(IpAddress);
        }
        /******************
        * PUBLIC METHODS *
        ******************/

        // Connect the Client with the Server.
        public void ConnectToServer()
        {
            // Check that the Ip Address is in the right and expected form.
            if (IpAddress != null)
            {
                if (Regex.IsMatch(IpAddress, @"^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$"))
                {
                    // Set a flag to check that the address in within the boundaries.
                    bool wrongIpAddress = false;
                    // Split the address in the numbers.
                    string[] ipNumbers = IpAddress.Split('.');
                    foreach (string num in ipNumbers)
                    {
                        if (Int32.Parse(num) > 255)
                        {
                            // If a number is too big (can not be smaller than zero, checked in the regex) change the flag value.
                            wrongIpAddress = true;
                        }
                    }

                    // If the address is correct
                    if (!wrongIpAddress)
                    {
                        IPAddress serverIpAddress = IPAddress.Parse(IpAddress);

                        if (!ListOfConnectionThreads.ContainsKey(serverIpAddress))
                        {
                            // Clean the Input string
                            IpAddress = "";

                            // Create the thread passing a parameter, the serverIpAddress I want to connect with.
                            Thread myNewThread = new Thread(() => ServerThreadRoutine(serverIpAddress));

                            // Add the thread to the data structure.
                            ListOfConnectionThreads.Add(serverIpAddress, myNewThread);

                            // Start the thread.
                            myNewThread.Start();
                        }
                        else // The address is already inserted in the IpConnections
                        {
                            // Open the Error Window
                            Views.ErrorWindowView errView          = new Views.ErrorWindowView();
                            ErrorWindowViewModel  errWindViewModel = new ErrorWindowViewModel("La connessione con questo server già è presente.");
                            errWindViewModel.ClosingRequest += errView.Close;
                            errView.DataContext              = errWindViewModel;
                            errView.Show();
                        }
                    }
                    else // The address is not in the proper form, show the ErrorWindow.
                    {
                        // Open the Error Window
                        Views.ErrorWindowView errView          = new Views.ErrorWindowView();
                        ErrorWindowViewModel  errWindViewModel = new ErrorWindowViewModel("Formato indirizzo Ip sbagliato.");
                        errWindViewModel.ClosingRequest += errView.Close;
                        errView.DataContext              = errWindViewModel;
                        errView.Show();
                    }
                }
                else // The address is not in the proper form, show the ErrorWindow.
                {
                    // Open the Error Window
                    Views.ErrorWindowView errView          = new Views.ErrorWindowView();
                    ErrorWindowViewModel  errWindViewModel = new ErrorWindowViewModel("Formato indirizzo Ip sbagliato.");
                    errWindViewModel.ClosingRequest += errView.Close;
                    errView.DataContext              = errWindViewModel;
                    errView.Show();
                }
            }
            else // The IpAddress is null, show the Error Window.
            {
                // Open the Error Window
                Views.ErrorWindowView errView          = new Views.ErrorWindowView();
                ErrorWindowViewModel  errWindViewModel = new ErrorWindowViewModel("Indirizzo Ip assente.");
                errWindViewModel.ClosingRequest += errView.Close;
                errView.DataContext              = errWindViewModel;
                errView.Show();
            }
        }