Пример #1
0
        private CefV8Value Eval(string code)
        {
            IJavascriptObject res;

            _CefV8_WebView.Eval(code, out res);
            return(res.Convert());
        }
Пример #2
0
        private BulkJsHelper FactoryBuilder()
        {
            var script =
                @"(function(){
                    function Command(id, canExecute){
                        Object.defineProperty(this, '{{NeutroniumConstants.ObjectId}}', {value: id});
                        Object.defineProperty(this, '{{NeutroniumConstants.ReadOnlyFlag}}', {value: true});
                        this.CanExecuteCount = 1;
                        this.CanExecuteValue = canExecute;
                    }
                    Command.prototype.Execute = function() {
                        this.privateExecute(this.{{NeutroniumConstants.ObjectId}}, ...arguments)
                    }
                    Command.prototype.CanExecute = function() {
                        this.privateCanExecute(this.{{NeutroniumConstants.ObjectId}}, ...arguments)
                    }
                    function Executable(id){
                        Object.defineProperty(this, '{{NeutroniumConstants.ObjectId}}', {value: id});
                        Object.defineProperty(this, '{{NeutroniumConstants.ReadOnlyFlag}}', {value: true});
                    }
                    Executable.prototype.Execute = function() {
                        this.privateExecute(this.{{NeutroniumConstants.ObjectId}}, ...arguments)
                    }
                    function bulkCreate(prop){
                        const propss = JSON.parse(prop)
                        const count = propss.count
		                const args = Array.from(arguments)
		                const objs = args.slice(1, count + 1)
		                const values = args.slice(1 + count, args.length + 1)
                        var valueCount = 0
                        var elementCount = 0
                        var innerCount = 0
                        const elements = propss.elements
                        var element = null
		                for(var i=0; i< count; i ++){
                            if (!element || innerCount > element.c) {
                                element = elements[elementCount++]
                                innerCount = 0;
                            }
                            var props = element.a
                            for (var j = 0, len = props.length; j < len; j++) {
                                objs[i][props[j]] = values[valueCount++]
                            }
                            innerCount++
		                }
                    }
                    return {
                        bulkCreate,
                        Command,
                        Executable
                    }
                })()";

            IJavascriptObject helper;

            script = script.Replace("{{NeutroniumConstants.ObjectId}}", NeutroniumConstants.ObjectId)
                     .Replace("{{NeutroniumConstants.ReadOnlyFlag}}", NeutroniumConstants.ReadOnlyFlag);
            _WebView.Eval(script, out helper);
            return(new BulkJsHelper(_Cache, _WebView, helper));
        }
Пример #3
0
        public IJavascriptObject CreateObject(string iCreationCode)
        {
            return(_CefV8_WebView.Evaluate(() =>
            {
                IJavascriptObject res;

                _CefV8_WebView.Eval(iCreationCode, out res);

                return UpdateObject(res as CefV8_JavascriptObject);
            }));
        }
Пример #4
0
 /// <summary>
 ///     Attempts to asynchronously evaluate the <paramref name="script" /> in the <paramref name="webView" /> without
 ///     waiting for return.
 /// </summary>
 /// <param name="webView">A <see cref="IWebView" /> instance.</param>
 /// <param name="script">The script to evaluate.</param>
 public static void TryEvalAsync(this IWebView webView, string script)
 {
     if (webView != null)
     {
         try
         {
             webView.Eval(script);
         }
         catch (Exception e)
         {
             // Best effort
             Debug.WriteLine("Error executing command: " + script);
             Debug.WriteLine(e.Message);
         }
     }
 }
Пример #5
0
 private CefV8Value Eval(string code)
 {
     _CefV8WebView.Eval(code, out var res);
     return(res.Convert());
 }
        private BulkJsHelper FactoryBuilder()
        {
            var script =
                @"(function(){
                    function Command(id, canExecute){
                        Object.defineProperty(this, '{{NeutroniumConstants.ObjectId}}', {value: id});
                        Object.defineProperty(this, '{{NeutroniumConstants.ReadOnlyFlag}}', {value: {{ReadOnlyObservable}}});
                        this.CanExecuteCount = 1;
                        this.CanExecuteValue = canExecute;
                    }
                    Command.prototype.Execute = function() {
                        this.privateExecute(this.{{NeutroniumConstants.ObjectId}}, ...arguments)
                    }
                    Command.prototype.CanExecute = function() {
                        this.privateCanExecute(this.{{NeutroniumConstants.ObjectId}}, ...arguments)
                    }
                    function Executable(id){
                        Object.defineProperty(this, '{{NeutroniumConstants.ObjectId}}', {value: id});
                        Object.defineProperty(this, '{{NeutroniumConstants.ReadOnlyFlag}}', {value: {{ReadOnly}}});
                    }
                    Executable.prototype.Execute = function() {
                        this.privateExecute(this.{{NeutroniumConstants.ObjectId}}, ...arguments)
                    }
                    function bulkUpdateObjects(prop){
						const propsArrays = eval( prop )
						var objectCount = 1
						var propsArrayLength = propsArrays.length;
						var propIndex = 0
						
						while(propsArrayLength--){
							const propArray = propsArrays[propIndex++]
							var repetition = propArray.c
							var properties = propArray.a
							while(repetition--){
								const objectToUpdate = arguments[objectCount++]
								var propertiesLength = properties.length
								var index = 0
								while(propertiesLength--){
									objectToUpdate[properties[index++]] = arguments[objectCount++]
								}
							}
						}
                    }
                    function bulkUpdateArrays(prop){
						const propsArrays = eval( prop )
						var objectCount = 1
						var propsArrayLength = propsArrays.length;
						var propIndex = 0
						
						while(propsArrayLength--){
							const propArray = propsArrays[propIndex++]
							var repetition = propArray.c
                            var description = propArray.a
							var arrayStart = description.b
                            var arrayEnd = description.e
							while(repetition--){
                                const objectToUpdate = arguments[objectCount++]
                                for(var index = arrayStart; index< arrayEnd; index++){					
                                    objectToUpdate[index] = arguments[objectCount++]
                                }
							}
						}
                    }
                    return {
                        bulkUpdateArrays,
                        bulkUpdateObjects,
                        Command,
                        Executable
                    }
                })()";

            script = script.Replace(NeutroniumConstants.ObjectIdTemplate, NeutroniumConstants.ObjectId)
                     .Replace(NeutroniumConstants.ReadOnlyFlagTemplate, NeutroniumConstants.ReadOnlyFlag)
                     .Replace("{{ReadOnly}}", ((int)ObjectObservability.ReadOnly).ToString())
                     .Replace("{{ReadOnlyObservable}}", ((int)ObjectObservability.ReadOnlyObservable).ToString());
            _WebView.Eval(script, out var helper);
            return(new BulkJsHelper(_Cache, _WebView, helper));
        }