Example #1
0
        /// <summary>
        /// Using current browser session, takes Customer account number and attempts to find ATA IP Address in FOPS.
        /// Then transfers browser control to specific ATA method as described in ATA's config page.
        /// Reboots and "Saves Changes" for ATA's.
        /// Returns: String with ATA's information.
        /// TODO: Error handling
        /// </summary>
        /// <param name="browser"></param>
        /// <param name="AccountNumber"></param>

        public string GetAtaIp(ChromeDriver browser, string AccountNumber)
        {
            //assumes we're logged into FOPS... SHould be if control was transferred from FOPS browser sesh directly...THis should be handled in FOPS browser.
            //logic to search url and verify not on login page.
            //Console.WriteLine(browser.Url);

            string ATAError = "ATA not found in FOPS...try again or use different account number (External ID maybe?)";
            string ATA_Info = "";
            var    GetATA   = new ATA();

            //Verify Logged into FOPS, then Search for ATA
            try
            {
                browser.Navigate().GoToUrl(FOPS_HomeUrl + FOPS_ATAUrl);
                if (browser.Url.ToString().Contains(FOPS_LoginUrl) == true)
                {
                    FOPS_Login(browser, FOPS_HomeUrl + FOPS_ATAUrl);
                }
            }
            catch (TimeoutException)
            {
                return(ATAError += " Timeout Error on FOPS page, try again...");
            }
            catch (StaleElementReferenceException e)
            {
                return(ATAError += $"Stale element ref exception, was not able to get to ATA page, please try again. ref code: {e.ToString()} ");
            }
            catch (Exception e)
            {
                return(ATAError += " " + e.ToString());
            }
            try
            {
                browser.FindElementById("search_foreign_id").SendKeys(AccountNumber);
                browser.FindElementById("voip_search_submit_button").Click();

                //TODO: Handle Multiple ATA's found. Need good way of verifiying we've selected the right customer
                //Selects First ATA found in table
                var ATA_Table = browser.FindElementsByClassName("table_row");
                //assume first row has our ATA
                var ATA_Rows = ATA_Table[0].FindElements(By.TagName("td"));


                //to get ATA Type
                Console.WriteLine($"Found ATA Type: {ATA_Rows[2].Text}");

                string ataType      = ATA_Rows[2].Text;
                var    ataSuspended = ATA_Rows[9]; //checks if ata is suspended. should be yes or no.
                //wowee have to call explicit wait to get this crap site to 'accept' my click, lol headless browser be too quick son!
                Thread.Sleep(100);
                //Stuck here, feel like this isn't the first time either, will need to mitigate this.
                ATA_Table[0].Click();


                //ATA config page opens in new tab. cannot call URL dirctly. returns error
                browser.SwitchTo().Window(browser.WindowHandles[1]);
                string whereAmI = browser.Url;
                Console.WriteLine($"Number of tabs: {browser.WindowHandles.Count}");
                Console.WriteLine($"Browser Location, after searching for ATA... {whereAmI}");

                //Finding ATA's last known IP and rebuild it's config.
                var AtaIP = browser.FindElementsByClassName("small_pad");
                //Should save changes...
                Console.WriteLine($"Saved changes clicked...{AtaIP[1].Text}");
                AtaIP[1].Click();
                //Should have ATA IP
                Console.WriteLine($"Selecting ATA...{AtaIP[0].Text}");
                string ATA_IP = AtaIP[0].Text;
                AtaIP[0].Click();
                //page[0] holds FOPS search, 1 has ATA config, 2 should be ATA
                browser.SwitchTo().Window(browser.WindowHandles[2]);
                Console.WriteLine($"If ata found/ip addr clicked number of tabs is now: {browser.WindowHandles.Count}");

                switch (ataType)
                {
                //Call proper ATA method here...switch statement? will call proper method depending on what ATA type is specified in DOM.

                case "Cambium 200P":
                case "Cambium R201P":
                    Console.WriteLine("Found Cambium ATA, Attempting Login/Reboot...");
                    //Call Cambium logic return to ATA_Info;
                    ATA_Info += PingTest.PingBuilder(browser, "ATA Cambium", ATA_IP);
                    break;

                case "Linksys SPA122":
                    Console.WriteLine("Found SPA122, Attempting Login/Reboot...");
                    //Call Cisco SPA122 logic
                    ATA_Info += PingTest.PingBuilder(browser, "ATA SPA122", ATA_IP);
                    break;

                case "Linksys SPA2102":
                    Console.WriteLine("Found SPA2102, Attempting Login/Reboot but you might be f****d anyway lol it's a POS...");
                    //Call SPA 2102 logic
                    ATA_Info += PingTest.PingBuilder(browser, "ATA SPA2102", ATA_IP);
                    break;

                default:
                    Console.WriteLine(ATAError);
                    ATA_Info = ATAError;
                    break;
                }
            }
            catch (Exception e)
            {
                ATA_Info = $"Some other error: {e.ToString()}";
                throw;
            }

            Console.WriteLine("End ATA...");

            return(ATA_Info);
        }
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);
        }