Пример #1
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);
        }