Ejemplo n.º 1
0
        /// <summary>
        /// Execute a chunk of JavaScript, wait for completion & return response
        /// </summary>
        /// <param name="script"></param>

        public static object ExecuteScript(
            KekuleJsWinFormsBrowserMsft KekuleJsBrowser,
            string script)
        {
            //if (DebugMx.True) return new JavascriptResponse(); // disable - debug

            Stopwatch sw = Stopwatch.StartNew();

            if (KekuleJsBrowser?.Browser?.Document == null)
            {
                AssertMx.IsNotNull(KekuleJsBrowser?.Browser?.Document, "KekuleJsBrowser?.Browser?.Document");
            }

            WebBrowser browser = KekuleJsBrowser.Browser;

            if (Debug)
            {
                DebugLog.Message("Script: " + script + KekuleJsBrowser.IdText);
            }

            object result = browser.Document.InvokeScript("execScript", new Object[] { script, "JavaScript" });

            if (Debug)
            {
                DebugLog.StopwatchMessage("Script complete, Time: ", sw);
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Call a function in a script
        /// </summary>
        /// <param name="jsMethodName"></param>
        /// <param name="args">Itemized list of args, not an array</param>
        /// <returns>Function result</returns>

        public static string CallFunction(
            KekuleJsWinFormsBrowserMsft KekuleJsBrowser,
            string jsMethodName,
            params string[] args)
        {
            object resultObj = null;

            Stopwatch sw = Stopwatch.StartNew();

            WebBrowser browser = KekuleJsBrowser.Browser;

            if (browser == null || browser.IsDisposed || browser.Document == null)
            {
                return(null);
            }

            string funcCallString = jsMethodName + "(" + Lex.ArrayToCsvString(args) + ")";

            if (Debug)
            {
                DebugLog.Message("Script function call: " + funcCallString + KekuleJsBrowser.IdText);
            }

            if (args == null || args.Length == 0)             // no args
            {
                resultObj = browser.Document.InvokeScript(jsMethodName);
            }

            else             // convert args string array to object array
            {
                object[] oArgs = new object[args.Length];
                args.CopyTo(oArgs, 0);
                resultObj = browser.Document.InvokeScript(jsMethodName, args);
            }

            string resultString = (resultObj != null ? resultObj.ToString() : null);

            if (Debug)
            {
                DebugLog.StopwatchMessage("Script function call complete, Time: ", sw);
            }

            return(resultString);
        }
Ejemplo n.º 3
0
 public JavaScriptManager(KekuleJsWinFormsBrowserMsft KekuleJsBrowser) // create a script manager and reference it back to us
 {
     return;                                                           // KekuleJsBrowser = KekuleJsBrowser;
 }