Ejemplo n.º 1
0
        protected override bool LocalComputeJavascriptValue(IJavascriptObjectFactory factory)
        {
            if (JSValue != null)
                return false;

            JSValue = factory.CreateObject(true);
            JSValue.SetValue("CanExecuteValue", factory.CreateBool(_InitialCanExecute));
            JSValue.SetValue("CanExecuteCount", factory.CreateInt(_Count));
            return true;
        }
Ejemplo n.º 2
0
        protected override bool LocalComputeJavascriptValue(IJavascriptObjectFactory factory)
        {
            if (JSValue != null)
            {
                return(false);
            }

            JSValue = factory.CreateObject(true);
            JSValue.SetValue("CanExecuteValue", factory.CreateBool(_InitialCanExecute));
            JSValue.SetValue("CanExecuteCount", factory.CreateInt(_Count));
            return(true);
        }
        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);
        }
Ejemplo n.º 4
0
        private void MappNested(object from, IJavascriptObject resobject, 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 = UnsafelMap(childvalue);
                _Context.WebView.Run(() => resobject.SetValue(propertyName, childres.JSValue));
                gres.UpdateCSharpProperty(propertyName, childres);
            }
        }
Ejemplo n.º 5
0
        public JSCommand(IWebView iCefV8Context, IDispatcher iUIDispatcher, ICommand icValue)
        {
            _UIDispatcher = iUIDispatcher;
            _IWebView     = iCefV8Context;
            _Command      = icValue;

            bool canexecute = true;

            try
            {
                canexecute = _Command.CanExecute(null);
            }
            catch { }

            JSValue = _IWebView.Evaluate(() =>
            {
                IJavascriptObject res = _IWebView.Factory.CreateObject(true);
                res.SetValue("CanExecuteValue", _IWebView.Factory.CreateBool(canexecute));
                res.SetValue("CanExecuteCount", _IWebView.Factory.CreateInt(_Count));
                return(res);
            });
        }
 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);
     });
 }
 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);
     });
 }
Ejemplo n.º 8
0
 public void SetAttribute(IJavascriptObject father, string attibutename, IJavascriptObject value)
 {
     _WebView.Run(() => father.SetValue(attibutename, value));
 }
        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;
        }      
Ejemplo n.º 10
0
 public Task SetAttributeAsync(IJavascriptObject father, string attributeName, IJavascriptObject value)
 {
     return(_WebView.RunAsync(() => father.SetValue(attributeName, value)));
 }
        private void MappNested(object from, IJavascriptObject resobject, 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 = UnsafelMap(childvalue);          
                _Context.WebView.Run(() => resobject.SetValue(propertyName, childres.JSValue));
                gres.UpdateCSharpProperty(propertyName, childres);
            }
        }
Ejemplo n.º 12
0
 public void SetAttribute(IJavascriptObject father, string attibutename, IJavascriptObject value)
 {
     _WebView.Run(() => father.SetValue(attibutename, value));
 }