Example #1
0
        /// <summary>
        /// Navigates browser to Radio search page. Verifies FOPS login via URL check.
        /// Attmepts login if not already there. Redirects back to Radio page if not logged in.
        /// </summary>
        /// <param name="browser"></param>
        /// <returns type='string'></returns>
        public string GetRadioIP(ChromeDriver browser, string customerNumber)
        {
            Console.WriteLine("Searching for Radio...");
            var    GetRadio   = new Radio();
            string Radio_Info = "";

            try
            {
                browser.Navigate().GoToUrl(FOPS_HomeUrl + FOPS_RadioUrl);
            }
            catch (TimeoutException e)
            {
                Console.WriteLine($"Timed out getting to SU Config...ref:\n{e.ToString()}");
                return(Radio_Info);
            }
            catch (Exception e)
            {
                return(Radio_Info = $"Some other error: {e.ToString()}");
            }
            if (browser.Url.ToString().Contains(FOPS_LoginUrl) == true)
            {
                FOPS_Login(browser, FOPS_HomeUrl + FOPS_RadioUrl);
            }
            try
            {
                var custNumber = browser.FindElementByName("customer_number");
                var RadioForm  = browser.FindElementsByName("B1");
                //var RadioForm = browser.FindElementByXPath(@"//*[@id='div_3_contents']/form");
                custNumber.SendKeys(customerNumber);
                RadioForm[2].Submit();

                Console.WriteLine(browser.Url);


                //Radio IP should always be first item in td for given table...will need to handle if multiple radios are presented.
                //again need to test via ping if radio is up or not.
                //need to determine radio type via webpage DOM
                var RadioTable = browser.FindElementByTagName("td");
                Console.WriteLine($"Found Radio IP: {RadioTable.Text}");
                //created to avoid stale refrence exception on later call.
                string radioIP = RadioTable.Text;
                //Uri RadioIP = RadioTable.Text;
                //logic to ping radio goes here.

                if (RadioTable.Text.Contains("Nothing"))
                {
                    return(Radio_Info += "No IP found for radio");
                }
                browser.Navigate().GoToUrl($"http://{RadioTable.Text}");
                Console.WriteLine(browser.Url);
                //go to ping/crawl radio.
                Radio_Info += PingTest.PingBuilder(browser, "radio", radioIP);


                return(Radio_Info);
            }
            catch (Exception e)
            {
                return(Radio_Info = $"error: {e.ToString()}");
            }
        }
Example #2
0
        /// <summary>
        /// Test to see if equipment is responding via ping. To get specific ATA, must specify what type it is.
        /// Example call for ATA is PingBuilder(IP, "ATA Cambium");
        /// If pinging radio, only need to specify "radio" as the equipType Parameter.
        /// </summary>
        /// <param name="IP"></param>
        /// <param name="equipType"></param>
        /// <returns></returns>
        public string PingBuilder(ChromeDriver browser, string equipType, string IP)
        {
            ATA         GetATA      = new ATA();
            Radio       GetRadio    = new Radio();
            string      PingReplies = string.Empty;
            Ping        Pinger      = new Ping();
            PingOptions opt         = new PingOptions();

            opt.DontFragment = true;
            int successPacket = 0;
            int failedPacket  = 0;
            //create packet as per https://docs.microsoft.com/en-us/dotnet/api/system.net.networkinformation.ping?view=netframework-4.7.2
            string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

            byte[] buffer  = Encoding.ASCII.GetBytes(data);
            int    timeout = 10000;

            Console.WriteLine($"Passed to RegEx: {IP}");

            //Tested this regex string in calculator and appears to work on IP's with stuffs before and after actuall address.
            Regex ip     = new Regex(@"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b");
            Match result = ip.Match(IP);

            Console.WriteLine($"{equipType} IP: {result}");
            try
            {
                for (int counter = 1; counter <= 10; counter++)
                {
                    PingReply reply = Pinger.Send(result.Value, timeout, buffer, opt);
                    if (reply.Status == IPStatus.Success)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine($"Ping to {reply.Address.ToString()} received in: {reply.RoundtripTime}ms");
                        successPacket++;
                    }
                    if (reply.Status == IPStatus.Success && counter == 10)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine($"Ping to {reply.Address.ToString()} received in: {reply.RoundtripTime}ms");
                        PingReplies += $"Ping to {reply.Address.ToString()} received in: {reply.RoundtripTime}ms \n";
                        Console.ResetColor();
                        successPacket++;
                        switch (equipType)
                        {
                        case "ATA Cambium":
                            Console.WriteLine("Launching Cambium logic...");
                            PingReplies += GetATA.Cambium(browser);
                            break;

                        case "ATA SPA122":
                            Console.WriteLine("Launching SPA122 logic...");
                            PingReplies += GetATA.Spa122(browser);
                            break;

                        case "ATA SPA2102":
                            Console.WriteLine("Launching SPA2102 logic...");
                            PingReplies += GetATA.Spa2102(browser);
                            break;

                        case "radio":
                            Console.WriteLine("Launching Radio logic...");
                            PingReplies += GetRadio.GetRadioType(browser);
                            break;

                        default:
                            PingReplies += "Unable to determine Equipment type";
                            break;
                        }
                    }
                    //if ping fails then RoundtripTime will be 0
                    else if (reply.RoundtripTime == 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"Failed to receive reply from {result.Value}");
                        Console.ResetColor();
                        //return PingReplies += $"Failed to receive reply from {result.Value}";

                        failedPacket++;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Ping Error: {e.ToString()}");
                return(PingReplies);
            }
            Console.WriteLine($"Received: {successPacket.ToString()}\nFailed Responses: {failedPacket.ToString()}");
            return(PingReplies);
        }