Beispiel #1
0
        /// <summary>
        /// Parse the Command LIne Options
        /// </summary>
        /// <param name="args"></param>
        /// <returns>Options objects</returns>
        public static CLIOptions ParseOptions(string[] args)
        {
            CLIOptions _return = new CLIOptions()
            {
                ShowHelp       = false,
                CreateDemo     = false,
                CKSettingsPath = Path.Combine(AppContext.BaseDirectory, "CKSettings.json")
            };

            foreach (string s in args)
            {
                if (s.Length < 2)
                {
                    _return.ShowHelp = true;
                    Console.WriteLine("Unknown Argument: \"" + s + "\"");
                    break;
                }
                if (s.Length == 2)
                {
                    // support the common help flags in Windows
                    if (s == "-h" || s == "/h" || s == "-?" || s == "/?")
                    {
                        _return.ShowHelp = true;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Unknown Argument: \"" + s + "\"");
                        _return.ShowHelp = true;
                        break;
                    }
                }

                if (s.Length >= 3)
                {
                    if (s.Substring(0, 3) == "-p:" && s.Length > 4)
                    {
                        _return.CKSettingsPath = s.Substring(3, s.Length - 3).Replace("\"", "").Replace("'", "");
                    }
                    else if (s.Substring(0, 3) == "-d:" && s.Length > 4)
                    {
                        _return.CreateDemo     = true;
                        _return.CKSettingsPath = s.Substring(3, s.Length - 3).Replace("\"", "").Replace("'", "");
                    }
                    else
                    {
                        Console.WriteLine("Unknown Argument: \"" + s + "\"");
                        _return.ShowHelp = true;
                        break;
                    }
                }
            }

            return(_return);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            CLIOptions opt       = ParseOptions(args);
            CKSettings _Settings = null;

            if (opt.ShowHelp)
            {
                ShowHelp();
                return;
            }
            else if (opt.CreateDemo)
            {
                _Settings = CreateDemo(opt.CKSettingsPath);
            }
            else
            {
                _Settings = ParseSettings(opt.CKSettingsPath);
            }

            Console.WriteLine("Starting Chrome" + Environment.NewLine +
                              "Using:");
            foreach (string i in _Settings.ChromeOptions)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine("Press \"CTRL+C\" to Exit");

            ChromeOptions chromeOptions = new ChromeOptions();

            chromeOptions.AddArguments(_Settings.ChromeOptions.ToArray());
            // Force add these to remove the automation toolbar in Chrome 77+
            chromeOptions.AddExcludedArgument("enable-automation");
            chromeOptions.AddAdditionalCapability("useAutomationExtension", false);
            IWebDriver _driver = new ChromeDriver(chromeOptions);

            try
            {
                while (true)
                {
                    foreach (var s in _Settings.SiteSettings)
                    {
                        // DEBUG
                        //Console.WriteLine("URL:\t" + s.Uri + (s?.UriSettings ?? ""));
                        if (String.IsNullOrEmpty(s.Uri + (s?.UriSettings ?? "")))
                        {
                            continue;                                                                                           // Skip empty URLs
                        }
                        _driver.Navigate().GoToUrl(s.Uri + (s?.UriSettings ?? ""));                                             // Concat API flags if present
                        Thread.Sleep(new TimeSpan(hours: 0, minutes: (int)s.TimeoutMinutes, seconds: (int)s.TimeoutSeconds));   // Wait for load
                        Thread.Sleep(new TimeSpan(hours: 0, minutes: (int)s.ViewTimeMinutes, seconds: (int)s.ViewTimeSeconds)); // Pause to show site
                    }
                    // Reload from file after each cycle
                    _Settings = ParseSettings(opt.CKSettingsPath);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error with Chrome:\t" + ex.Message);
            }
            finally
            {
                // Required to close out Chrome correctly
                _driver.Quit();
            }

            Console.WriteLine("Program Done; press ENTER");
            Console.ReadLine();
        }