public void OnJavaScriptObjectChanges(IJavascriptObject objectchanged, string propertyName, IJavascriptObject newValue) { try { var res = _SessionCache.GetGlobalCached(objectchanged) as JsGenericObject; if (res == null) { return; } var propertyAccessor = new PropertyAccessor(res.CValue, propertyName, _Logger); if (!propertyAccessor.IsSettable) { _Logger.Info(() => $"Unable to set C# from javascript object: property: {propertyName} is readonly."); return; } var targetType = propertyAccessor.GetTargetType(); var glue = GetCachedOrCreateBasic(newValue, targetType); Context.RunOnUIContextAsync(() => { using (_IsListening ? _ListenerRegister.GetPropertySilenter(res.CValue) : null) { propertyAccessor.Set(glue.CValue); res.UpdateCSharpProperty(propertyName, glue); } }); } catch (Exception e) { _Logger.Error(() => $"Unable to update ViewModel from View, exception raised: {e.Message}"); } }
public async void OnJavaScriptObjectChanges(IJavascriptObject objectchanged, string propertyName, IJavascriptObject newValue) { try { var res = _SessionCache.GetCached(objectchanged) as JsGenericObject; if (res == null) { return; } var propertyAccessor = new PropertyAccessor(res.CValue, propertyName, _Logger); if (!propertyAccessor.IsSettable) { _Logger.Info(() => $"Unable to set C# from javascript object: property: {propertyName} is readonly."); return; } var targetType = propertyAccessor.GetTargetType(); var glue = GetCachedOrCreateBasic(newValue, targetType); var bridgeUpdater = glue.IsBasicNotNull() ? null : new BridgeUpdater(); await Context.RunOnUIContextAsync(() => { using (var relisten = glue.IsBasicNotNull() ? null : ReListen(bridgeUpdater)) using (_IsListening ? _ListenerRegister.GetPropertySilenter(res.CValue) : null) { var oldValue = propertyAccessor.Get(); propertyAccessor.Set(glue.CValue); var actualValue = propertyAccessor.Get(); if (Object.Equals(actualValue, glue.CValue)) { res.UpdateGlueProperty(propertyName, glue); return; } if (!Object.Equals(oldValue, actualValue)) { CSharpPropertyChanged(res.CValue, new PropertyChangedEventArgs(propertyName)); } } }); if (!(bridgeUpdater?.HasUpdatesOnJavascriptContext == true)) { return; } await Context.RunOnJavascriptContextAsync(() => { bridgeUpdater.UpdateOnJavascriptContext(Context.ViewModelUpdater); }); } catch (Exception e) { _Logger.Error(() => $"Unable to update ViewModel from View, exception raised: {e.Message}"); } }
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); } }