Beispiel #1
0
        private async Task <IJSCSGlue> RegisterAndDo(Func <IJSCSGlue> valueBuilder, Action <IJSCSGlue> Do)
        {
            IJSCSGlue value = null;

            await RunInJavascriptContext(async() =>
            {
                value = valueBuilder();
                if (value != null)
                {
                    await InjectInHTMLSession(value);
                }
            });

            if (value == null)
            {
                return(null);
            }

            await RunInJavascriptContext(() =>
            {
                using (ReListen())
                {
                    Do(value);
                }
            });

            return(value);
        }
Beispiel #2
0
 public JavascriptObjectSynchroneousBuilder(IJavascriptObjectFactory factory, IJavascriptSessionCache cache, IJSCSGlue root, bool mapping)
 {
     _Mapping = mapping;
     _Factory = factory;
     _Cache   = cache;
     _Root    = root;
 }
Beispiel #3
0
        public void Reroot(string PropertyName, IJSCSGlue newValue)
        {
            _Attributes[PropertyName] = newValue;

            JSObject silenter = null;

            if (_Silenters.TryGetValue(PropertyName, out silenter))
            {
                silenter.InvokeAsync("silent", newValue.GetJSSessionValue());
            }
            else
            {
                WebCore.QueueWork(() =>
                {
                    var jso = (JSObject)_MappedJSValue;
                    if (!_Silenters.TryGetValue(PropertyName, out silenter))
                    {
                        silenter = (JSObject)jso[PropertyName];
                        _Silenters.Add(PropertyName, silenter);
                    }

                    silenter.Invoke("silent", newValue.GetJSSessionValue());
                });
            }
        }
        private JSGenericObject MappNested(object ifrom, IJavascriptObject resobject, JSGenericObject gres)
        {
            if (ifrom == null)
            {
                return(gres);
            }

            IEnumerable <PropertyInfo> propertyInfos = ifrom.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (PropertyInfo propertyInfo in propertyInfos.Where(p => p.CanRead))
            {
                string pn         = propertyInfo.Name;
                object childvalue = null;
                try
                {
                    childvalue = propertyInfo.GetValue(ifrom, null);
                }
                catch (Exception e)
                {
                    Trace.WriteLine(string.Format("MVVM for HTML: Unable to convert property {0} from {1} exception {2}", pn, ifrom, e));
                    continue;
                }

                IJSCSGlue childres = InternalMap(childvalue);

                _IWebView.Run(() => resobject.SetValue(pn, childres.JSValue));

                gres.Attributes[pn] = childres;
            }

            return(gres);
        }
        private void Object_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            string pn = e.PropertyName;

            PropertyInfo propertyInfo = sender.GetType().GetProperty(pn, BindingFlags.Public | BindingFlags.Instance);

            if (propertyInfo == null)
            {
                return;
            }

            JSGenericObject currentfather = _FromCSharp[sender] as JSGenericObject;

            object    nv = propertyInfo.GetValue(sender, null);
            IJSCSGlue oldbridgedchild = currentfather.Attributes[pn];

            if (Object.Equals(nv, oldbridgedchild.CValue))
            {
                return;
            }

            IJSCSGlue newbridgedchild = _JSObjectBuilder.Map(nv);

            RegisterAndDo(newbridgedchild, () => currentfather.Reroot(pn, newbridgedchild));
        }
        IJSCSGlue IJSCBridgeCache.GetCached(object key)
        {
            IJSCSGlue res = null;

            _FromCSharp.TryGetValue(key, out res);
            return(res);
        }
Beispiel #7
0
        public static IEnumerable <IJSCSGlue> GetAllChildren(this IJSCSGlue @this, bool includeMySelf = false)
        {
            var res = new HashSet <IJSCSGlue>();

            @this.GetAllChildren(includeMySelf, res);
            return(res);
        }
Beispiel #8
0
        private async Task <IJavascriptObject> InjectInHTMLSession(IJSCSGlue iroot)
        {
            if (iroot == null)
            {
                return(null);
            }

            switch (iroot.Type)
            {
            case JsCsGlueType.Basic:
                return(null);

            case JsCsGlueType.Object:
                if ((iroot.JSValue.IsNull))
                {
                    return(null);
                }
                break;
            }

            var jvm = _SessionCache.GetMapper(iroot as IJSObservableBridge);
            var res = _sessionInjector.Inject(iroot.JSValue, jvm);

            if ((iroot.CValue != null) && (res == null))
            {
                throw ExceptionHelper.GetUnexpected();
            }

            await jvm.UpdateTask;

            return(res);
        }
 public JavascriptObjectSynchroneousBuilderAdapter(IJavascriptObjectFactory factory, IJavascriptSessionCache cache, IJSCSGlue @object, bool mapping)
 {
     _Mapping = mapping;
     _Factory = factory;
     _Cache   = cache;
     _Object  = @object;
 }
Beispiel #10
0
 public void Add(IJSCSGlue iIJSCBridge, int Index)
 {
     MappedJSValue.InvokeAsync("silentsplice", _IWebView, _IWebView.Factory.CreateInt(Index), _IWebView.Factory.CreateInt(0), iIJSCBridge.GetJSSessionValue());
     if (Index > Items.Count - 1)
         Items.Add(iIJSCBridge);
     else
         Items.Insert(Index, iIJSCBridge);
 }
Beispiel #11
0
 public void Add(IJSCSGlue iIJSCBridge, int Index)
 {
     ((JSObject)MappedJSValue).InvokeAsync("silentsplice", new JSValue(Index), new JSValue(0), iIJSCBridge.GetJSSessionValue());
     if (Index > Items.Count - 1)
         Items.Add(iIJSCBridge);
     else
         Items.Insert(Index, iIJSCBridge);
 }
Beispiel #12
0
 public void Add(IJSCSGlue iIJSCBridge, int Index)
 {
     MappedJSValue.InvokeAsync("silentsplice", _CefV8Context, CefV8Value.CreateInt(Index), CefV8Value.CreateInt(0), iIJSCBridge.GetJSSessionValue());
     if (Index > Items.Count - 1)
         Items.Add(iIJSCBridge);
     else
         Items.Insert(Index, iIJSCBridge);
 }
Beispiel #13
0
 public JavascriptObjectBulkBuilder(IJavascriptObjectFactory factory, IJavascriptSessionCache cache, IBulkUpdater bulkPropertyUpdater,
                                    IJSCSGlue root, bool mapping)
 {
     _Mapping     = mapping;
     _Factory     = factory;
     _Cache       = cache;
     _Root        = root;
     _BulkUpdater = bulkPropertyUpdater;
 }
Beispiel #14
0
        public void RemoveFromJsToCSharp(IJSCSGlue value)
        {
            var id = value.JsId;

            if (id == 0)
            {
                return;
            }

            _FromJavascript_Global.Remove(id);
        }
Beispiel #15
0
        public void RemoveFromCSharpToJs(IJSCSGlue value)
        {
            var key = value.CValue;

            if (key == null)
            {
                return;
            }

            _FromCSharp.Remove(key);
        }
Beispiel #16
0
 public void AddRequest(IJSCSGlue commandGlue, bool canExecute)
 {
     if (canExecute)
     {
         CommandExecutableBuildingRequested.Add(commandGlue);
     }
     else
     {
         CommandNotExecutableBuildingRequested.Add(commandGlue);
     }
 }
Beispiel #17
0
        internal void RequestExecutableCreation(IJSCSGlue glueObject)
        {
            if (!_Mapping)
            {
                _ExecutableObjectsToCreate.Add(glueObject);
                return;
            }

            var command = _Factory.CreateObject(true);

            glueObject.SetJSValue(command);
        }
        private IJSCSGlue GetCachedLocal(IJavascriptObject localkey)
        {
            if (!localkey.HasRelevantId())
            {
                return(null);
            }

            IJSCSGlue res = null;

            _FromJavascript_Local.TryGetValue(localkey.GetID(), out res);
            return(res);
        }
Beispiel #19
0
        private static void GetAllChildren(this IJSCSGlue @this, bool includeMySelf, ISet <IJSCSGlue> res)
        {
            if (includeMySelf)
            {
                res.Add(@this);
            }

            foreach (var direct in @this.GetChildren().Where(res.Add))
            {
                direct.GetAllChildren(false, res);
            }
        }
Beispiel #20
0
 public void Add(IJSCSGlue iIJSCBridge, int Index)
 {
     MappedJSValue.InvokeAsync("silentsplice", _IWebView, _IWebView.Factory.CreateInt(Index), _IWebView.Factory.CreateInt(0), iIJSCBridge.GetJSSessionValue());
     if (Index > Items.Count - 1)
     {
         Items.Add(iIJSCBridge);
     }
     else
     {
         Items.Insert(Index, iIJSCBridge);
     }
 }
Beispiel #21
0
        public static ISet <IJSCSGlue> GetAllChildren(this IJSCSGlue @this, bool includeMySelf = false)
        {
            var res = new HashSet <IJSCSGlue>();

            if (includeMySelf)
            {
                res.Add(@this);
            }

            @this.GetAllChildren(res);
            return(res);
        }
 public void Add(IJSCSGlue iIJSCBridge, int Index)
 {
     ((JSObject)MappedJSValue).InvokeAsync("silentsplice", new JSValue(Index), new JSValue(0), iIJSCBridge.GetJSSessionValue());
     if (Index > Items.Count - 1)
     {
         Items.Add(iIJSCBridge);
     }
     else
     {
         Items.Insert(Index, iIJSCBridge);
     }
 }
Beispiel #23
0
        public IJSCSGlue GetCached(JSObject globalkey)
        {
            if (!_GlobalBuilder.HasRelevantId(globalkey))
            {
                return(null);
            }

            IJSCSGlue res = null;

            _FromJavascript_Global.TryGetValue(_GlobalBuilder.GetID(globalkey), out res);
            return(res);
        }
Beispiel #24
0
        private async Task SetResult(IJavascriptObject promise, IJSCSGlue bridgevalue)
        {
            if (promise == null)
            {
                return;
            }

            await WebView.RunAsync(async() =>
            {
                await promise.InvokeAsync("fullfill", WebView, bridgevalue.GetJSSessionValue());
            });
        }
Beispiel #25
0
        private IJSCSGlue GetCachedLocal(JSObject localkey)
        {
            if (!_LocalBuilder.HasRelevantId(localkey))
            {
                return(null);
            }

            IJSCSGlue res = null;

            _FromJavascript_Local.TryGetValue(_LocalBuilder.GetID(localkey), out res);
            return(res);
        }
        private IDisposable ReListen(IJSCSGlue ivalue)
        {
            if (_ReListen != null)
            {
                _ReListen.AddRef();
            }
            else
            {
                _ReListen = new ReListener(this);
            }

            return(_ReListen);
        }
Beispiel #27
0
        private void VisitUpdate(IJSCSGlue glue)
        {
            if (glue.JSValue != null)
            {
                return;
            }

            var updater = new JavascriptObjectSynchroneousBuilderAdapter(_Factory, _Cache, glue, _Mapping);

            updater.ApplyLocalChanges();
            glue.GetChildren().ForEach(VisitUpdate);
            updater.AfterChildrenUpdates();
        }
Beispiel #28
0
        public void Cache(IJSCSGlue value)
        {
            var cashable = value as IJSCSCachableGlue;

            if (cashable != null)
            {
                Cache(cashable);
            }
            else
            {
                _FromJavascript_Global.Add(value.JSValue.GetID(), value);
            }
        }
Beispiel #29
0
        private void RegisterAndDo(IJSCSGlue ivalue, Action Do)
        {
            var idisp = ReListen(ivalue);

            InjectInHTLMSession(ivalue).ContinueWith(_ =>
                                                     WebCore.QueueWork(() =>
            {
                using (idisp)
                {
                    Do();
                }
            }
                                                                       ));
        }
Beispiel #30
0
        internal async Task IntrospectVm(object addicionalObject)
        {
            await _Context.RunOnUIContextAsync(() =>
            {
                _Root = _JSObjectBuilder.Map(_RootObject, addicionalObject);

                if (ListenToCSharp)
                {
                    ListenToCSharpChanges();
                }

                _IsListening = true;
            });
        }
Beispiel #31
0
        internal void RequestCommandCreation(IJSCSGlue glueObject, bool canExecute)
        {
            if (!_Mapping)
            {
                _CommandCreationRequest.AddRequest(glueObject, canExecute);
                return;
            }

            var command = _Factory.CreateObject(true);

            command.SetValue("CanExecuteValue", _Factory.CreateBool(canExecute));
            command.SetValue("CanExecuteCount", _Factory.CreateInt(1));
            glueObject.SetJSValue(command);
        }
        public IJSCSGlue GetCached(IJavascriptObject globalkey)
        {
            return(_IWebView.Evaluate(() =>
            {
                if (!globalkey.HasRelevantId())
                {
                    return null;
                }

                IJSCSGlue res = null;
                _FromJavascript_Global.TryGetValue(globalkey.GetID(), out res);
                return res;
            }));
        }
        internal BidirectionalMapper(object iRoot, IWebView iwebview, IDispatcher UIDispatcher, JavascriptBindingMode iMode, object iadd)
        {
            _IWebView = iwebview;
            _JSObjectBuilder = new CSharpToJavascriptMapper(iwebview,UIDispatcher, this);
            _Root = _JSObjectBuilder.Map(iRoot, iadd);
            _UnrootedEntities = new List<IJSCSGlue>();
            _BindingMode = iMode;

            IJavascriptListener JavascriptObjecChanges = null;
            if (iMode == JavascriptBindingMode.TwoWay)
                JavascriptObjecChanges = this;


            _SessionInjector = new JavascriptSessionInjector(iwebview, JavascriptObjecChanges);
        }
        private async void RegisterAndDo(IJSCSGlue ivalue, Action Do)
        {
            var idisp = ReListen(ivalue);

            await InjectInHTLMSession(ivalue);

            await _IWebView.RunAsync(() =>
            {
                using (idisp)
                {
                    Do();
                }
            }
                                     );
        }
        internal BidirectionalMapper(object iRoot, CefV8CompleteContext iwebview, JavascriptBindingMode iMode, object iadd)
        {
            _V8Context = iwebview;
            _LocalBuilder = new LocalBuilder(iwebview);
            _JSObjectBuilder = new CSharpToJavascriptMapper(iwebview, _LocalBuilder, this);
            _JavascriptToCSharpMapper = new JavascriptToCSharpMapper();
            _Root = _JSObjectBuilder.Map(iRoot, iadd);
            _UnrootedEntities = new List<IJSCSGlue>();
            _BindingMode = iMode;

            IJavascriptListener JavascriptObjecChanges = null;
            if (iMode == JavascriptBindingMode.TwoWay)
                JavascriptObjecChanges = this;

            _GlobalBuilder = new GlobalBuilder(_V8Context, "MVVMGlue");

            _SessionInjector = new JavascriptSessionInjector(iwebview, _GlobalBuilder, JavascriptObjecChanges);
        }
 internal BidirectionalMapper(object iRoot, HTMLViewEngine contextBuilder, JavascriptBindingMode iMode, object addicionalObject, IWebSessionLogger logger)
 {        
     _BindingMode = iMode;
     _Logger = logger;
     var javascriptObjecChanges = (iMode == JavascriptBindingMode.TwoWay) ? (IJavascriptChangesObserver)this : null;
     _Context = contextBuilder.GetMainContext(javascriptObjecChanges);
     _sessionInjector = _Context.JavascriptSessionInjector;  
     _SessionCache = new SessionCacher();
     _ListenerRegister = new FullListenerRegister(
                                 (n) => n.PropertyChanged += CSharpPropertyChanged,
                                 (n) => n.PropertyChanged -= CSharpPropertyChanged,
                                 (n) => n.CollectionChanged += CSharpCollectionChanged,
                                 (n) => n.CollectionChanged -= CSharpCollectionChanged,
                                 (c) => c.ListenChanges(),
                                 (c) => c.UnListenChanges());
     var commandFactory = new CommandFactory(_Context, this);
     RegisterJavascriptHelper();
     _JSObjectBuilder = new CSharpToJavascriptConverter(_Context, _SessionCache, commandFactory, _Logger) ;
     _Root = _JSObjectBuilder.Map(iRoot, addicionalObject); 
 }
        public void Reroot(string PropertyName, IJSCSGlue newValue)
        { 
            _Attributes[PropertyName]=newValue;

            JSObject silenter = null;
            if ( _Silenters.TryGetValue(PropertyName,out silenter))
            {
                silenter.InvokeAsync("silent", newValue.GetJSSessionValue());      
            }
            else
            {
                WebCore.QueueWork(() =>
                    {
                        var jso = (JSObject)_MappedJSValue;
                        if (!_Silenters.TryGetValue(PropertyName, out silenter))
                        {
                            silenter = (JSObject)jso[PropertyName];
                            _Silenters.Add(PropertyName, silenter);
                        }
              
                        silenter.Invoke("silent", newValue.GetJSSessionValue());
                    });
            }
        }     
        private IDisposable ReListen(IJSCSGlue ivalue)
        {
            if (_ReListen != null)
                _ReListen.AddRef();
            else
                _ReListen = new ReListener(this);

            return _ReListen;
        }
        private async Task InjectInHTLMSession(IJSCSGlue iroot, bool isroot = false)
        {
            if ((iroot == null) || (iroot.Type == JSCSGlueType.Basic))
                return;

            if ((iroot.Type == JSCSGlueType.Object) && (iroot.JSValue.IsNull))
                return;

            var jvm = new JavascriptMapper(iroot as IJSObservableBridge, this);
            var res = _SessionInjector.Map(iroot.JSValue, jvm, (iroot.CValue != null));

            await jvm.UpdateTask;

            if (isroot)
                await _SessionInjector.RegisterInSession(res);
        }
 private bool Convert(IEnumerable source, out IJSCSGlue res)
 {
     res = new JSArray(this._IWebView, _UIDispatcher, source.Cast<object>().Select(s => Map(s)), source);
     _Cacher.Cache(source, res);
     return true;
 }
 private void Splice(int index, int number, IJSCSGlue glue)
 {
     ViewModelUpdater.SpliceCollection(MappedJSValue, index, number, glue.GetJSSessionValue());
 }
 public void Replace(IJSCSGlue jscBridge, int index)
 {
     Splice(index, 1, jscBridge);
     Items[index] = jscBridge;
 }
Beispiel #43
0
 public void Insert(IJSCSGlue iIJSCBridge, int Index)
 {
     MappedJSValue.InvokeAsync("silentsplice", _IWebView, _IWebView.Factory.CreateInt(Index), _IWebView.Factory.CreateInt(1), iIJSCBridge.GetJSSessionValue());
     Items[Index] = iIJSCBridge;
 }
        private async Task<IJavascriptObject> InjectInHTMLSession(IJSCSGlue iroot)
        {
            if (iroot == null)
                return null;

            switch (iroot.Type)
            {
                case JsCsGlueType.Basic:
                    return null;

                case JsCsGlueType.Object:
                    if ((iroot.JSValue.IsNull))
                        return null;
                    break;
            }

            var jvm = _SessionCache.GetMapper(iroot as IJSObservableBridge);
            var res = _sessionInjector.Inject(iroot.JSValue, jvm);

            if ((iroot.CValue != null) && (res==null))
            {
                throw ExceptionHelper.GetUnexpected();
            }

            await jvm.UpdateTask;
            return res;
        }
 void IJSCBridgeCache.Cache(object key, IJSCSGlue value)
 {
     _FromCSharp.Add(key, value);
 }
        private void RegisterAndDo(IJSCSGlue ivalue, Action Do)
        {
            var idisp = ReListen(ivalue);

            InjectInHTLMSession(ivalue).ContinueWith(_ =>
                WebCore.QueueWork(() =>
                    {
                        using (idisp)
                        {
                            Do();
                        }
                    }
                ));
        }
        private Task InjectInHTLMSession(IJSCSGlue iroot, bool isroot = false)
        {
            if ((iroot == null) || (iroot.Type == JSCSGlueType.Basic))
            {
                return TaskHelper.Ended();
            }

            var jvm = new JavascriptMapper(iroot as IJSObservableBridge, this);
            var res = _SessionInjector.Map(iroot.JSValue, jvm,(iroot.CValue!=null));
            if (!isroot)
                return jvm.UpdateTask;
            else
                return jvm.UpdateTask.ContinueWith(_ => _SessionInjector.RegisterInSession(res),
                            TaskScheduler.FromCurrentSynchronizationContext());
        }
 private bool Convert(IEnumerable source, out IJSCSGlue res)
 {
     res = new JSArray(this._CefV8Context, source.Cast<object>().Select(s => Map(s)), source, _Basic.GetElementType(source));
     _Cacher.Cache(source, res);
     return true;
 }
 public void CacheLocal(object key, IJSCSGlue value)
 {
     _FromJavascript_Local.Add(value.JSValue.GetID(), value);
 }
        private async void RegisterAndDo(IJSCSGlue ivalue, Action Do)
        {
            var idisp = ReListen(ivalue);

            await InjectInHTLMSession(ivalue);
            await _V8Context.RunAsync(() =>
                    {
                        using (idisp)
                        {
                            Do();
                        }
                    }
               );
        }
Beispiel #51
0
 public void Insert(IJSCSGlue iIJSCBridge, int Index)
 {
     ((JSObject)MappedJSValue).InvokeAsync("silentsplice", new JSValue(Index), new JSValue(1), iIJSCBridge.GetJSSessionValue());
     Items[Index] = iIJSCBridge;
 }
 public IndividualCollectionChange(CollectionChangeType iCollectionChange, int iIndex, IJSCSGlue iObject)
 {
     CollectionChangeType=iCollectionChange;
      Index=   iIndex;
      Object = iObject;
 }
 public void ReRoot(string propertyName, IJSCSGlue glue)
 {
     UpdateCSharpProperty(propertyName, glue);
     ViewModelUpdater.UpdateProperty(_MappedJSValue, propertyName, glue.GetJSSessionValue());
 }    
 void IJSCBridgeCache.CacheLocal(object key, IJSCSGlue value)
 {
     _FromCSharp.Add(key, value);
     _FromJavascript_Local.Add(_LocalBuilder.GetID(value.JSValue), value);
 }
Beispiel #55
0
 public void Insert(IJSCSGlue iIJSCBridge, int Index)
 {
     MappedJSValue.InvokeAsync("silentsplice", _CefV8Context, CefV8Value.CreateInt(Index), CefV8Value.CreateInt(1), iIJSCBridge.GetJSSessionValue());
     Items[Index] = iIJSCBridge;
 }
 public void Add(IJSCSGlue jscBridge, int index)
 {
     Splice(index, 0, jscBridge);
     Items.Insert(index, jscBridge);
 }
 public void Cache(object key, IJSCSGlue value)
 {
     _FromCSharp.Add(key, value);
 }
        public void Reroot(string PropertyName, IJSCSGlue newValue)
        { 
            _Attributes[PropertyName]=newValue;

            CefV8Value silenter = null;
            if ( _Silenters.TryGetValue(PropertyName,out silenter))
            {
                silenter.InvokeAsync("silent", _CefV8Context, newValue.GetJSSessionValue());      
            }
            else
            {
                //WebCore.QueueWork(() =>
                //    {

                _CefV8Context.RunAsync( ()=>
                    {
                        var jso = _MappedJSValue;
                        if (!_Silenters.TryGetValue(PropertyName, out silenter))
                        {
                            silenter = jso.GetValue(PropertyName);
                            _Silenters.Add(PropertyName, silenter);
                        }
                        silenter.Invoke("silent", _CefV8Context, newValue.GetJSSessionValue());
                    });
            }
        }     
 public void UpdateCSharpProperty(string propertyName, IJSCSGlue glue)
 {
     _Attributes[propertyName] = glue;
 }