Ejemplo n.º 1
0
        public void OnUiContext(ObjectChangesListener off)
        {
            var currentfather = _JsUpdateHelper.GetCached <JsGenericObject>(_Sender);

            if (currentfather == null)
            {
                return;
            }

            var propertyUpdater = currentfather.GetPropertyUpdater(_PropertyName);

            if (!propertyUpdater.IsValid)
            {
                return;
            }

            _NewValue = propertyUpdater.GetCurrentChildValue();
            if (!propertyUpdater.HasChanged(_NewValue))
            {
                return;
            }

            _NewJsValue = _JsUpdateHelper.Map(_NewValue);
            if (_NewJsValue == null)
            {
                return;
            }

            _BridgeUpdater = currentfather.GetUpdater(propertyUpdater, _NewJsValue);
            _JsUpdateHelper.UpdateOnUiContext(_BridgeUpdater, off);
        }
Ejemplo n.º 2
0
        public async void OnJavaScriptCollectionChanges(JavascriptCollectionChanges changes)
        {
            try
            {
                var res = _SessionCache.GetCached(changes.Collection) as JsArray;
                if (res == null)
                {
                    return;
                }

                var collectionChanges = res.GetChanger(changes, this);

                var updater = new BridgeUpdater(_SessionCache);
                await Context.RunOnUiContextAsync(() =>
                {
                    UpdateCollection(res, res.CValue, collectionChanges, updater);
                });

                if (!updater.HasUpdatesOnJavascriptContext)
                {
                    return;
                }

                await Context.RunOnJavascriptContextAsync(() =>
                {
                    updater.UpdateOnJavascriptContext(Context.ViewModelUpdater);
                });
            }
            catch (Exception exception)
            {
                LogJavascriptSetException(exception);
            }
        }
Ejemplo n.º 3
0
        private async Task UpdateOnJavascriptContextWithMapping(BridgeUpdater updater, IJsCsGlue value)
        {
            _BuilderStrategy.UpdateJavascriptValue(value);
            await InjectInHtmlSession(value);

            updater.UpdateOnJavascriptContext(Context.ViewModelUpdater);
        }
Ejemplo n.º 4
0
        private async Task UpdateOnJavascriptContextWithMapping(BridgeUpdater updater, IJsCsGlue value)
        {
            UpdateJavascriptValue(value);
            await _SessionMapper.InjectInHtmlSession(value);

            RunUpdaterOnJsContext(updater);
        }
Ejemplo n.º 5
0
        public async void OnJavaScriptCollectionChanges(JavascriptCollectionChanges changes)
        {
            try
            {
                var res = _SessionCache.GetCached(changes.Collection) as JSArray;
                if (res == null)
                {
                    return;
                }

                var collectionChanges = res.GetChanger(changes, this);

                var updater = new BridgeUpdater();
                await Context.RunOnUIContextAsync(() =>
                {
                    UpdateCollection(res, res.CValue, collectionChanges, updater);
                });

                if (!updater.HasUpdatesOnJavascriptContext)
                {
                    return;
                }

                await Context.RunOnJavascriptContextAsync(() =>
                {
                    updater.UpdateOnJavascriptContext(_Context.ViewModelUpdater);
                });
            }
            catch (Exception e)
            {
                _Logger.Error(() => $"Unable to update ViewModel from View, exception raised: {e.Message}");
            }
        }
 public void UpdateOnJavascriptContext(BridgeUpdater updater, IJsCsGlue value)
 {
     if (value != null)
     {
         UpdateJavascriptValue(value);
     }
     UpdateOnJavascriptContext(updater);
 }
Ejemplo n.º 7
0
 private async Task UpdateOnJavascriptContextWithMapping(BridgeUpdater updater, IList <IJsCsGlue> values)
 {
     values.ForEach(UpdateJavascriptValue);
     foreach (var jsCsGlue in values)
     {
         await _SessionMapper.InjectInHtmlSession(jsCsGlue);
     }
     RunUpdaterOnJsContext(updater);
 }
Ejemplo n.º 8
0
        private void UpdateOnJavascriptContextAllContext(BridgeUpdater updater, IJsCsGlue value)
        {
            if (Context.JavascriptFrameworkIsMappingObject)
            {
                DispatchInJavascriptContext(() => UpdateOnJavascriptContextWithMapping(updater, value));
                return;
            }

            DispatchInJavascriptContext(() => UpdateOnJavascriptContextWithoutMapping(updater, value));
        }
        public void OnUiContext(ObjectChangesListener off)
        {
            var array = _JsUpdateHelper.GetCached <JsArray>(_Sender);

            if (array == null)
            {
                return;
            }

            _BridgeUpdater = GetBridgeUpdater(array);
            _JsUpdateHelper.UpdateOnUiContext(_BridgeUpdater, off);
        }
        public async void UpdateOnJavascriptContext(BridgeUpdater updater, IList <IJsCsGlue> values)
        {
            if (values != null && values.Count > 0)
            {
                values.ForEach(UpdateJavascriptValue);
                foreach (var jsCsGlue in values)
                {
                    await UpdateJavascriptObject(jsCsGlue);
                }
            }

            UpdateOnJavascriptContext(updater);
        }
Ejemplo n.º 11
0
        public void UpdateOnJavascriptContext(BridgeUpdater updater, IJsCsGlue value)
        {
            if (value == null)
            {
                RunUpdaterOnJsContext(updater);
                return;
            }

            if (_Context.JavascriptFrameworkIsMappingObject)
            {
                UpdateOnJavascriptContextWithMapping(updater, value).DoNotWait();
                return;
            }

            UpdateOnJavascriptContextWithoutMapping(updater, value);
        }
Ejemplo n.º 12
0
        public void UpdateOnJavascriptContext(BridgeUpdater updater, IList <IJsCsGlue> values)
        {
            if (values == null || values.Count == 0)
            {
                RunUpdaterOnJsContext(updater);
                return;
            }

            if (_Context.JavascriptFrameworkIsMappingObject)
            {
                UpdateOnJavascriptContextWithMapping(updater, values).DoNotWait();
                return;
            }

            UpdateOnJavascriptContextWithoutMapping(updater, values);
        }
Ejemplo n.º 13
0
        private void OnExit(IJSCSGlue exiting, BridgeUpdater context)
        {
            exiting.ApplyOnListenable(_ListenerRegister.Off);

            if ((context == null) || (exiting.Type != JsCsGlueType.Object))
            {
                return;
            }

            _SessionCache.RemoveFromCSharpToJs(exiting);
            context.RequestJSCacheRemove(exiting);

            if (!exiting.CValue.GetType().HasReadWriteProperties())
            {
                return;
            }

            context.RequestUnlisten(exiting.JSValue);
        }
Ejemplo n.º 14
0
        private Task UpdateFromCSharpChanges(Func <BridgeUpdater> updaterBuilder, bool needToCheckListener)
        {
            CheckUIContext();

            BridgeUpdater updater = null;

            using (var relisten = needToCheckListener ? ReListen(): null)
            {
                updater = Update(updaterBuilder, relisten);
            }

            if (!updater.HasUpdatesOnJavascriptContext)
            {
                return(TaskHelper.Ended());
            }

            return(RunInJavascriptContext(() =>
            {
                updater.UpdateOnJavascriptContext(_Context.ViewModelUpdater);
            }));
        }
Ejemplo n.º 15
0
        private Task <IJSCSGlue> UpdateFromCSharpChanges(object newCSharpObject, Func <IJSCSGlue, BridgeUpdater> updaterBuilder)
        {
            CheckUIContext();

            var value = _JSObjectBuilder.Map(newCSharpObject);

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

            BridgeUpdater updater = null;

            using (var relisten = value.IsBasicNotNull()? null : ReListen())
            {
                updater = Update(() => updaterBuilder(value), relisten);
            }

            if (!_IsLoaded)
            {
                return(Task.FromResult(value));
            }

            return(RunInJavascriptContext(async() =>
            {
                _BuilderStrategy.UpdateJavascriptValue(value);

                if (_Context.JavascriptFrameworkIsMappingObject)
                {
                    await InjectInHTMLSession(value);
                }

                updater.UpdateOnJavascriptContext(_Context.ViewModelUpdater);
                return value;
            }));
        }
Ejemplo n.º 16
0
 private void RunUpdaterOnJsContext(BridgeUpdater updater)
 {
     updater.UpdateOnJavascriptContext(_Context.ViewModelUpdater);
 }
Ejemplo n.º 17
0
 private void UpdateOnJavascriptContextWithoutMapping(BridgeUpdater updater, IJsCsGlue value)
 {
     UpdateJavascriptValue(value);
     RunUpdaterOnJsContext(updater);
 }
Ejemplo n.º 18
0
 public PropertyJsContextUpdater(IJsUpdateHelper jsUpdateHelper, BridgeUpdater bridgeUpdater, IJsCsGlue newJsValue)
 {
     _BridgeUpdater  = bridgeUpdater;
     _NewJsValue     = newJsValue;
     _JsUpdateHelper = jsUpdateHelper;
 }
Ejemplo n.º 19
0
 private void UpdateOnJavascriptContext(BridgeUpdater updater, IJsCsGlue value)
 {
     _BuilderStrategy.UpdateJavascriptValue(value);
     updater.UpdateOnJavascriptContext(Context.ViewModelUpdater);
 }
 private static Tuple <BridgeUpdater, List <IJsCsGlue> > FromBridge(BridgeUpdater bridgeUpdater) => Tuple.Create <BridgeUpdater, List <IJsCsGlue> >(bridgeUpdater, null);
Ejemplo n.º 21
0
 private void UpdateOnJavascriptContextWithoutMapping(BridgeUpdater updater, IEnumerable <IJsCsGlue> values)
 {
     values.ForEach(UpdateJavascriptValue);
     RunUpdaterOnJsContext(updater);
 }
Ejemplo n.º 22
0
        public async void OnJavaScriptObjectChanges(IJavascriptObject objectchanged, string propertyName, IJavascriptObject newValue)
        {
            try
            {
                var currentfather = _SessionCache.GetCached(objectchanged) as JsGenericObject;
                if (currentfather == null)
                {
                    return;
                }

                var propertyUpdater = currentfather.GetPropertyUpdater(propertyName);
                if (!propertyUpdater.IsSettable)
                {
                    LogReadOnlyProperty(propertyName);
                    return;
                }

                var targetType    = propertyUpdater.TargetType;
                var glue          = GetCachedOrCreateBasic(newValue, targetType);
                var bridgeUpdater = new BridgeUpdater(_SessionCache);

                await Context.RunOnUiContextAsync(() =>
                {
                    using (_ListenerRegister.GetPropertySilenter(currentfather.CValue, propertyName))
                    {
                        var oldValue = propertyUpdater.GetCurrentChildValue();

                        try
                        {
                            propertyUpdater.Set(glue.CValue);
                        }
                        catch (Exception exception)
                        {
                            LogSetError(propertyName, targetType, glue.CValue, exception);
                        }

                        var actualValue = propertyUpdater.GetCurrentChildValue();

                        if (Object.Equals(actualValue, glue.CValue))
                        {
                            var old = currentfather.UpdateGlueProperty(propertyUpdater, glue);
                            bridgeUpdater.Remove(old);
                            bridgeUpdater.CleanAfterChangesOnUiThread(_ListenerRegister.Off);
                            return;
                        }

                        if (!Object.Equals(oldValue, actualValue))
                        {
                            OnCSharpPropertyChanged(currentfather.CValue, new PropertyChangedEventArgs(propertyName));
                        }
                    }
                });

                if (!bridgeUpdater.HasUpdatesOnJavascriptContext)
                {
                    return;
                }

                await Context.RunOnJavascriptContextAsync(() =>
                {
                    bridgeUpdater.UpdateOnJavascriptContext(Context.ViewModelUpdater);
                });
            }
            catch (Exception exception)
            {
                LogJavascriptSetException(exception);
            }
        }
 public void UpdateOnJavascriptContext(BridgeUpdater updater)
 {
     updater.UpdateOnJavascriptContext(_Context.ViewModelUpdater, _SessionCache);
 }
Ejemplo n.º 24
0
 public ReListener(IUpdatableJSCSGlueCollection updatableGlueCollection, BridgeUpdater updater)
 {
     _UpdatableGlueCollection = updatableGlueCollection;
     _Old           = _UpdatableGlueCollection.GetAllChildren();
     _BridgeUpdater = updater;
 }
 public void UpdateOnJavascriptContext(BridgeUpdater updater, IList <IJsCsGlue> values)
 {
     values?.ForEach(UpdateJavascriptValue);
     UpdateOnJavascriptContext(updater);
 }
 public CollectionsContextUpdater(IJsUpdateHelper jsUpdateHelper, BridgeUpdater bridgeUpdater, List <IJsCsGlue> newJsValues)
 {
     _BridgeUpdater  = bridgeUpdater;
     _NewJsValues    = newJsValues;
     _JsUpdateHelper = jsUpdateHelper;
 }
Ejemplo n.º 27
0
 public void UpdateOnUiContext(BridgeUpdater updater, ObjectChangesListener off)
 {
     updater.CleanAfterChangesOnUiThread(off, _SessionCache);
 }
Ejemplo n.º 28
0
 private void UpdateCollection(JsArray array, object collection, CollectionChanges.CollectionChanges change, BridgeUpdater updater)
 {
     try
     {
         using (_ListenerRegister.GetColllectionSilenter(collection))
         {
             array.UpdateEventArgsFromJavascript(change, updater);
         }
         updater.CleanAfterChangesOnUiThread(_ListenerRegister.Off);
     }
     catch (Exception exception)
     {
         LogJavascriptSetException(exception);
     }
 }
Ejemplo n.º 29
0
 private IExitContext ReListen(BridgeUpdater updater = null) => new ReListener(this, updater);
Ejemplo n.º 30
0
 public void SetBridgeUpdater(BridgeUpdater bridgeUpdater)
 {
     _BridgeUpdater = bridgeUpdater;
 }