private void SetStatus(ScanData item, PingReply pingReply)
        {
            if (pingReply != null && pingReply.Status == IPStatus.Success)
            {
                currentCell = int.Parse(item.ID);

                // online
                dataGridView.CurrentCell = dataGridView.Rows[currentCell - 1].Cells[dataGridView.ColumnCount - 2];

                dataGridView.CurrentCell.Value = statusResult.Online;

                DataGridViewCell cell = dataGridView.Rows[currentCell - 1].Cells[3];
                cell.Style.BackColor = Color.Green;


                SetPingResponse(item, pingReply);
            }
            else if (pingReply == null || pingReply.Status == IPStatus.TimedOut) // offline
            {
                currentCell = int.Parse(item.ID);

                dataGridView.CurrentCell = dataGridView.Rows[currentCell - 1].Cells[dataGridView.ColumnCount - 2];

                dataGridView.CurrentCell.Value = statusResult.Offline;

                DataGridViewCell cell = dataGridView.Rows[currentCell - 1].Cells[3];
                cell.Style.BackColor = Color.Red;


                SetPingResponse(item, pingReply);
            }
            else
            {
                currentCell = int.Parse(item.ID);

                DataGridViewCell cell = dataGridView.Rows[currentCell - 1].Cells[3];
                cell.Style.BackColor = Color.FromArgb(0, 192, 192);

                dataGridView.CurrentCell = dataGridView.Rows[currentCell - 1].Cells[dataGridView.ColumnCount - 2];

                currentCell = -1;

                SetPingResponse(item, pingReply);
            }


            SelectClear();
        }
        private void SetPingResponse(ScanData item, PingReply pingReply)//, Ping ping)
        {
            if (pingReply != null && pingReply.Status == IPStatus.Success)
            {
                currentCell    = int.Parse(item.ID);
                item.PingDelay = Convert.ToString(pingReply.RoundtripTime);

                dataGridView.CurrentCell = dataGridView.Rows[currentCell - 1].Cells[dataGridView.ColumnCount - 1];

                DataGridViewCell cell = dataGridView.Rows[currentCell - 1].Cells[4];
                cell.Value = item.PingDelay;
            }
            else
            {
                dataGridView.CurrentCell = dataGridView.Rows[currentCell - 1].Cells[dataGridView.ColumnCount - 1];

                DataGridViewCell cell = dataGridView.Rows[currentCell - 1].Cells[4];
                cell.Value = "9999";
            }
        }
        private void LoadPingList(int id)
        {
            if (File.Exists(filePath) is false)
            {
                try
                {
                    LogHelper.Log(LogTarget.File, "Creating config file. " + DateTime.Now);


                    // create file, if it failes catch will get it.
                    using (File.Create(filePath));


                    // add header to file.
                    // using (FileStream fileStream = new FileStream(filePath, FileMode.Append, FileAccess.Write))
                    using (var writeFile = new StreamWriter(filePath, true))
                    {
                        writeFile.WriteLine("# Format like this per Line (NO SPACES or EMPTY LINES): Room #,IP Address,");
                        writeFile.WriteLine("#--------------------------------------------------");
                        writeFile.WriteLine("# This will load the default state of the debug logging: 0 = true, Default is 1 = false");
                        writeFile.WriteLine("@,1");
                        writeFile.WriteLine("#--------------------------------------------------");

                        /*
                         * writeFile.WriteLine("P107,10.11.0.7");
                         * writeFile.WriteLine("P110,10.11.0.10");
                         * writeFile.WriteLine("P134,10.11.0.34");
                         * writeFile.WriteLine("P155,10.11.0.55");
                         * writeFile.WriteLine("P156,10.11.0.56");
                         * writeFile.WriteLine("120,10.11.1.20");
                         * writeFile.WriteLine("138,10.11.1.38");
                         * writeFile.WriteLine("200,10.11.2.0");
                         * writeFile.WriteLine("233,10.11.2.33");
                         * writeFile.WriteLine("280,10.11.2.80");
                         * writeFile.WriteLine("329,10.11.3.29");
                         * writeFile.WriteLine("363,10.11.3.63");
                         * writeFile.WriteLine("380,10.11.3.80");
                         * writeFile.WriteLine("400,10.11.4.0");
                         * writeFile.WriteLine("431,10.11.4.31");
                         * writeFile.WriteLine("461,10.11.4.61");
                         * writeFile.WriteLine("490,10.11.4.90");
                         * writeFile.WriteLine("506,10.11.5.6");
                         * writeFile.WriteLine("539,10.11.5.39");
                         * writeFile.WriteLine("564,10.11.5.64");
                         * writeFile.WriteLine("600,10.11.6.0");
                         * writeFile.WriteLine("634,10.11.6.34");
                         * writeFile.WriteLine("671,10.11.6.71");
                         */

                        writeFile.Close();


                        LogHelper.Log(LogTarget.File, "Config File Successfully Created. " + DateTime.Now);
                    }
                }
                catch (IOException e)
                {
                    MessageBox.Show($"{GetErrorMessage("WritingFile - IOException Error ==> Creating Config File")}, could not create file...\nmaybe you lack permission to do so. check with your admin.\n\nError MSG:\n\n" + e.Message);
                    //LogHelper.Log(LogTarget.ErrorFile, "IOException Error ==>  Creating Config File");
                    LogHelper.Log(LogTarget.ErrorFile, GetErrorMessage("WritingFile - IOException Error ==>  Creating Config File"));

                    Environment.Exit(-1);
                }
                catch (Exception e)
                {
                    MessageBox.Show($"{GetErrorMessage("Exception error ==> Cant Create Config File")}, check your premissions and try again. Error MSG: " + e.Message);
                    LogHelper.Log(LogTarget.ErrorFile, GetErrorMessage("Exception error ==>  Cant Create Config File"));

                    Environment.Exit(-1);
                }
            }

            int linesCounter = 0;

            try
            {
                LogHelper.Log(LogTarget.File, "Loading from Config file. " + DateTime.Now);

                using (StreamReader readFile = new StreamReader(filePath))
                {
                    while (!readFile.EndOfStream)
                    {
                        string[] token = readFile.ReadLine().Split(',');

                        if (token[0].Contains("#") || token[0].Contains("@"))
                        {
                            linesCounter++;

                            continue;
                        }
                        //else if(currentReadLine == debugStateLine - 1)
                        //{
                        //    // update debug log state
                        //    if (token[0].Contains("0"))
                        //        this.checkBoxDebugLogging.Checked = true;
                        //    else
                        //        this.checkBoxDebugLogging.Checked = false;

                        //    continue;
                        //}


                        idCounter++;



                        // "1", "P107", "10.11.0.7", statusResult.UnChecked.ToString(), "-1"
                        scanData = new ScanData();

                        scanData.ID         = idCounter.ToString();
                        scanData.RoomNumber = token[0]; // ID
                        scanData.IPAddress  = token[1]; // IP Address
                        scanData.Status     = statusResult.UnChecked.ToString();
                        scanData.PingDelay  = "-1";

                        dataList.Add(scanData);

                        linesCounter++;
                    }
                }

                LogHelper.Log(LogTarget.File, "Config file successfully loaded. " + DateTime.Now);
            }
            catch (Exception e)
            {
                // failed to load file information to list
                MessageBox.Show(GetErrorMessage($"Lines Counted = {linesCounter}, Error adding file information to Application loader, check formatting and try again."));
                LogHelper.Log(LogTarget.ErrorFile, GetErrorMessage($"Lines Counted = {linesCounter}, Exception Error ==> Format Error loading Data from config file to Application. Check \"config file \" Formatting"));

                Environment.Exit(-1);
            }



            //   return true;
        }