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 IWPFWebWindowFactory ResolveJavaScriptEngine(string engineName) { if (_Engines.Count != 1) { return(_Engines.GetOrDefault(engineName)); } var res = _Engines.First().Value; if (!string.IsNullOrEmpty(engineName) && (res.Name != engineName)) { _WebSessionLogger.Info(() => $"Name mismatch in IWPFWebWindowFactory resolution {engineName} vs {res.Name}"); } return(res); }
private void MappNested(JsGenericObject gres, object parentObject, IList <PropertyInfo> properties) { if (parentObject == null) { return; } foreach (var propertyInfo in properties) { var propertyName = propertyInfo.Name; object childvalue; try { childvalue = propertyInfo.GetValue(parentObject, null); } catch (TargetInvocationException e) { _Logger.Info(() => $"Unable to convert property {propertyName} from {parentObject} of type {parentObject.GetType().FullName} exception {e.InnerException}"); continue; } var childres = Map(childvalue); gres.AddGlueProperty(propertyName, childres); } }
private void MappNested(object from, JsGenericObject gres) { if (from == null) { return; } var propertyInfos = from.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.CanRead); foreach (var propertyInfo in propertyInfos) { var propertyName = propertyInfo.Name; object childvalue; try { childvalue = propertyInfo.GetValue(from, null); } catch (Exception e) { _Logger.Info(() => $"Unable to convert property {propertyName} from {@from} exception {e}"); continue; } var childres = InternalMap(childvalue); gres.UpdateCSharpProperty(propertyName, childres); } }
public void Dispose() { try { _Context.Exit(); } catch (Exception ex) { _Logger?.Info($"Problem in exiting chromiumFx context {ex}"); } }
private void PackUriResourceHandler_GetResponseHeaders(object sender, CfxGetResponseHeadersEventArgs responseHeader) { var response = responseHeader.Response; if (IsPrefetch) { _Logger?.Info(Prefetch); responseHeader.ResponseLength = 0; SetSuccess(response); return; } if (_StreamResourceInfo == null) { response.Status = 404; response.StatusText = "Not Found"; return; } responseHeader.ResponseLength = _StreamResourceInfo.Stream.Length; SetSuccess(response); }
private IJavascriptObject GetKo() { if (_Ko != null) { return(_Ko); } _Ko = _WebView.GetGlobal().GetValue("ko"); if ((_Ko == null) || (!_Ko.IsObject)) { throw ExceptionHelper.Get("ko object not found! You should add a link to knockout.js script to the HML document!"); } _Ko.Bind("log", _WebView, (e) => _logger.Info(() => string.Join(" - ", e.Select(s => (s.GetStringValue().Replace("\n", " ")))))); return(_Ko); }
public bool Set(object value) { if (!IsSettable) { return(false); } try { _PropertyInfo.SetValue(_Target, value, null); return(true); } catch (Exception e) { _Logger.Info($"Unable to set C# from javascript object: property: {_PropertyInfo.Name} of {_Target}, javascript value {value}. Exception {e} was thrown."); return(false); } }
public void UpdateProperty(IJavascriptObject father, string propertyName, IJavascriptObject value) { _WebView.RunAsync(() => { var silenter = GetOrCreateSilenter(father); if (silenter.IsUndefined) { _Logger.Info(() => $"UpdateProperty called during an injection process. Property updated {propertyName}"); //may happen if code being call between register and inject //in this case just set attribute value. The value will be register after father.SetValue(propertyName, value); return; } var forProperty = silenter.GetValue(propertyName); forProperty.Invoke("silence", _WebView, value); InjectUnsafe(value); }); }
private Action ToTaskAction <T>(Func <T> perform, TaskCompletionSource <T> taskCompletionSource) { Action result = () => { using (GetContext()) { try { taskCompletionSource.TrySetResult(perform()); } catch (Exception exception) { _Logger?.Info(() => $"Exception encountred during task dispatch: {exception.Message}"); taskCompletionSource.TrySetException(exception); } } }; return(result); }
private void MappNested(JsGenericObject gres, IReadOnlyCollection <Tuple <PropertyInfo, object> > properties) { foreach (var property in properties) { var propertyInfo = property.Item1; var propertyName = propertyInfo.Name; var parentObject = property.Item2; object childvalue; try { childvalue = propertyInfo.GetValue(parentObject, null); } catch (TargetInvocationException e) { _Logger.Info(() => $"Unable to convert property {propertyName} from {parentObject} of type {parentObject.GetType().FullName} exception {e.InnerException}"); continue; } var childres = Map(childvalue); gres.UpdateCSharpProperty(propertyName, childres); } }
private void LogIntrospectionError(string propertyName, object parentObject, Exception exception) { _Logger.Info(() => $"Unable to convert property {propertyName} from {parentObject} of type {parentObject.GetType().FullName} exception {exception.InnerException}"); }
private void LogSetError(string propertyName, Type targetType, object @object, Exception exception) { _Logger.Info($"Unable to set C# from javascript object: property: {propertyName} of {targetType}, javascript value {@object}. Exception {exception} was thrown."); }
private void LogException(Exception exception, string message = "Exception encountered during task dispatch") { _Logger?.Info($"{message}: {exception}"); }
private void LogException(Exception exception) { _Logger?.Info($"Exception encountred during task dispatch: {exception.Message}"); }