// Module defining this command // Optional custom code for this activity /// <summary> /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run. /// </summary> /// <param name="context">The NativeActivityContext for the currently running activity.</param> /// <returns>A populated instance of System.Management.Automation.PowerShell</returns> /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks> protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context) { System.Management.Automation.PowerShell invoker = global::System.Management.Automation.PowerShell.Create(); System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName); // Initialize the arguments if (NoElement.Expression != null) { targetCommand.AddParameter("NoElement", NoElement.Get(context)); } if (AsHashTable.Expression != null) { targetCommand.AddParameter("AsHashTable", AsHashTable.Get(context)); } if (AsString.Expression != null) { targetCommand.AddParameter("AsString", AsString.Get(context)); } if (InputObject.Expression != null) { targetCommand.AddParameter("InputObject", InputObject.Get(context)); } if (Property.Expression != null) { targetCommand.AddParameter("Property", Property.Get(context)); } if (Culture.Expression != null) { targetCommand.AddParameter("Culture", Culture.Get(context)); } if (CaseSensitive.Expression != null) { targetCommand.AddParameter("CaseSensitive", CaseSensitive.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
// ePMP Radio Scraping Logic: public string Scrape_ePMP(ChromeDriver browser) { string RadioStats = null; var userId = browser.FindElementByName("username"); var pwd = browser.FindElementByName("password"); var login = browser.FindElementById("loginBtn"); userId.SendKeys("admin"); pwd.SendKeys("amatech1"); login.Click(); /****************************************************************************************** * Note for Error handling: * Max # of users: <span class="error-text">Maximum number of users reached.</span> * Wrong Username/Password: <span class="error-text">Wrong username or password</span> ******************************************************************************************/ //Have to set explicit waits for ePMP DOM to load...wireless connections be slow Thread.Sleep(500); try { var ePMPRssi = browser.FindElementById("dl_rssi").GetAttribute("title"); var ePMPSNR = browser.FindElementById("dl_snr").GetAttribute("title"); //var ePMP_EthernetStatus = browser.FindElementsById("alert-success").GetAttribute("title"); var ePMPUptime = browser.FindElementById("sys_uptime").GetAttribute("title"); var ePMP_DlMod = browser.FindElementById("dl_mcs_mode").GetAttribute("title"); var ePMP_ULMod = browser.FindElementById("ul_mcs_mode").GetAttribute("title"); RadioStats = $"{ePMPUptime.ToString()}\n"; RadioStats += $"{ePMPRssi.ToString()}\n"; RadioStats += $"{ePMPSNR.ToString()}\n"; RadioStats += $"{ePMP_DlMod.ToString()}\n"; RadioStats += $"{ePMP_ULMod.ToString()}\n"; } catch (NoSuchElementException NoElement) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"ePMP elements not found ref: {NoElement.ToString()}"); Console.ResetColor(); } catch (ElementNotVisibleException NoSee) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Cannot see elements on Webpage: {NoSee.ToString()}"); Console.ResetColor(); } // reboot req handling popup // ref stackoverflow: https://stackoverflow.com/questions/12744576/selenium-c-sharp-accept-confirm-box //string pageSrc = browser.PageSource; //find & click reboot button, currently not visible in DOM browser.FindElementByClassName("navbar-toggle").Click(); Thread.Sleep(500); browser.FindElementById("reboot_device").Click(); //Handle pop up asking us if we're sure we want to reboot, yes we are. BrowserHelper.HandleAlerts(browser); //Title's in ePMP radio are "preformated", will concantenate strings together and display. Console.WriteLine(RadioStats); Console.WriteLine("ePMP Complete..."); return(RadioStats); // return scrapedData; }