Beispiel #1
0
        internal async void RunScript(string code)
        {
            Presenters.SwdMainPresenter.DisplayLoadingIndicator(true);

            Task <string> t = new Task <string>(() =>
            {
                using (var engine = new JScriptEngine())
                {
                    engine.AddHostObject("driver", SwdBrowser.GetDriver());

                    ImportTypes(engine);

                    var uiPageObject = Presenters.PageObjectDefinitionPresenter.GetWebElementDefinitionFromTree();


                    foreach (var element in uiPageObject.Items)
                    {
                        IWebElement proxyElement = SwdBrowser.CreateWebElementProxy(element);
                        string name = element.Name;
                        engine.AddHostObject(name, proxyElement);
                    }

                    var result = engine.Evaluate(code) ?? "(none)";
                    return(result.ToString());
                }
            });


            string logLine = "done";

            try
            {
                t.Start();

                logLine = await t;
            }
            catch (Exception ex)
            {
                MyLog.Exception(ex);
                logLine = "ERROR: " + ex.Message;
                // TODO: FIX message --> Exception has been thrown by the target of invocation
                // \TODO: FIX message --> Exception has been thrown by the target of invocation
            }
            finally
            {
                view.AppendConsole(logLine + "\r\n");
                Presenters.SwdMainPresenter.DisplayLoadingIndicator(false);
            }
        }