Ejemplo n.º 1
0
        public void Init()
        {
            MainUrl = Vs2019.GetSetting("url_main");
            SettingsScreenShotLocation = Vs2019.GetSetting("SettingsScreenShotLocation");
            FullExceptionPath          = SettingsScreenShotLocation;
            if (!Directory.Exists(FullExceptionPath))
            {
                Directory.CreateDirectory(FullExceptionPath);
            }

            Ca          = new ChromeActions();
            Ca.TestName = "Init";
            Ca.Url      = MainUrl;
            Ca.SettingsScreenShotLocation = SettingsScreenShotLocation;
            Ca.DoSleep = true;
            Ca.Initializer();
        }
        public void Load(
            [FileExists]
            [RequiredAttribute]
            string filepath)
        {
            if (this._debug_mode)
            {
                ScreensInformations screens = new ScreensInformations();

                Console.WriteLine(GetVersionAndCopyright());
                console_write_title_color("---- DEBUG Screens informations ----");
                Console.WriteLine("");
                Console.WriteLine("");
                Console.Write(screens.ToString());
                Console.WriteLine("");
                console_write_title_color("---- DEBUG Load json file ----");
                Console.WriteLine(Environment.NewLine + "");
                Console.WriteLine(" > Fichier json chargé = " + filepath);
                Console.WriteLine("");
            }

            string data_load_json = "";

            try
            {
                data_load_json = System.IO.File.ReadAllText(filepath);
                if (this._debug_mode)
                {
                    Console.WriteLine("   | Now the json is stored into a string");
                }
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[ERREUR] Unable to read the data into the loaded json, because : " + e.Message);
                Console.ResetColor();
            }

            try
            {
                ChromeActions chrome_actions           = JsonConvert.DeserializeObject <ChromeActions>(data_load_json);
                bool          p_kill_all_chromes       = chrome_actions.Kill_all_chromes;
                int           p_opt_Delay_milliseconds = chrome_actions.Delay_before_launch;

                if (this._debug_mode)
                {
                    Console.WriteLine("   | Now the json is deserialize into object type ChromeActions");
                    Console.WriteLine("   | Reading the ChromeActions and launch the " + chrome_actions.Actions.Count + " actions.");
                    Console.WriteLine("");

                    Console.WriteLine(" > Options global for all actions");
                    if (p_opt_Delay_milliseconds > 0)
                    {
                        Console.WriteLine("   | -> Delay before the launching = " + p_opt_Delay_milliseconds);
                    }
                    else
                    {
                        Console.WriteLine("   | -> Delay before the launching = disabled");
                    }
                    Console.WriteLine("   | -> Kill all chrome before the launching = " + p_kill_all_chromes);
                    Console.WriteLine("");
                }

                if (p_kill_all_chromes == true)
                {
                    Engine.kill_all_chromes();
                }

                int idx = 1;
                foreach (ChromeAction action in chrome_actions.Actions)
                {
                    if (this._debug_mode)
                    {
                        Console.WriteLine(" > Action " + idx);
                        Console.WriteLine("   | -> Url= " + action.Url);
                        Console.WriteLine("   | -> Arguments = " + action.Arguments);
                        Console.WriteLine("   | -> Fullscreen = " + action.Fullscreen);
                        Console.WriteLine("   | -> Indexscreen = " + action.Indexscreen);
                        Console.WriteLine("   | -> Launch now.");
                    }

                    if (p_opt_Delay_milliseconds > 0)
                    {
                        Thread.Sleep(p_opt_Delay_milliseconds);
                    }
                    Engine chrome_engine = new Engine(action.Url, action.Arguments, action.Fullscreen, action.Indexscreen, this._debug_mode);
                    idx++;
                }
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[ERREUR] Unable to deserialize the load json " + filepath + ", because: " + e.Message);
                Console.ResetColor();
            }

            if (this._debug_mode)
            {
                console_write_title_color("---- END ----");
                Console.WriteLine("");
            }
        }