Exemplo n.º 1
0
        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));
        }
        private IJSCSGlue InternalMap(object ifrom, object iadditional=null)
        {
            if (ifrom == null)
                return JSGenericObject.CreateNull(_IWebView);

            IJSCSGlue res = null;
            res = _Cacher.GetCached(ifrom);
            if (res != null)
            {
                return res;
            }

            if (ifrom is ICommand)
                return new JSCommand(_IWebView, _UIDispatcher, ifrom as ICommand);

            if (ifrom is ISimpleCommand)
                return new JSSimpleCommand(_IWebView, ifrom as ISimpleCommand);

            if (ifrom is IResultCommand)
                return new JSResultCommand(_IWebView, ifrom as IResultCommand);

            IJavascriptObject value;
            if (_IWebView.Factory.SolveBasic(ifrom, out value))
            {
                return new JSBasicObject(value, ifrom);
            }

            if (ifrom.GetType().IsEnum)
            {
                var trueres = new JSBasicObject(_IWebView.Factory.CreateEnum((Enum)ifrom), ifrom);
                _Cacher.CacheLocal(ifrom, trueres);
                return trueres;
            }

            IEnumerable ienfro = ifrom as IEnumerable;
            if ((ienfro!=null) && Convert(ienfro, out res))
            {
                return res;
            }

            IJavascriptObject resobject = _IWebView.Factory.CreateObject(true);

            JSGenericObject gres = new JSGenericObject(_IWebView,resobject, ifrom);
            _Cacher.Cache(ifrom, gres);

            MappNested(ifrom, resobject,gres);
            MappNested(iadditional, resobject, gres);

            return gres;
        }
Exemplo n.º 3
0
        public void RegisterMapping(IJavascriptObject iFather, string att, IJavascriptObject iChild)
        {
            JSGenericObject jso = GetFromJavascript(iFather) as JSGenericObject;

            Update(jso.Attributes[att] as IJSObservableBridge, iChild);
        }
        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 IJSCSGlue InternalMap(object ifrom, object iadditional = null)
        {
            if (ifrom == null)
            {
                return(JSGenericObject.CreateNull(_IWebView));
            }

            IJSCSGlue res = null;

            res = _Cacher.GetCached(ifrom);
            if (res != null)
            {
                return(res);
            }

            if (ifrom is ICommand)
            {
                return(new JSCommand(_IWebView, _UIDispatcher, ifrom as ICommand));
            }

            if (ifrom is ISimpleCommand)
            {
                return(new JSSimpleCommand(_IWebView, ifrom as ISimpleCommand));
            }

            if (ifrom is IResultCommand)
            {
                return(new JSResultCommand(_IWebView, ifrom as IResultCommand));
            }

            IJavascriptObject value;

            if (_IWebView.Factory.SolveBasic(ifrom, out value))
            {
                return(new JSBasicObject(value, ifrom));
            }

            if (ifrom.GetType().IsEnum)
            {
                var trueres = new JSBasicObject(_IWebView.Factory.CreateEnum((Enum)ifrom), ifrom);
                _Cacher.CacheLocal(ifrom, trueres);
                return(trueres);
            }

            IEnumerable ienfro = ifrom as IEnumerable;

            if ((ienfro != null) && Convert(ienfro, out res))
            {
                return(res);
            }

            IJavascriptObject resobject = _IWebView.Factory.CreateObject(true);

            JSGenericObject gres = new JSGenericObject(_IWebView, resobject, ifrom);

            _Cacher.Cache(ifrom, gres);

            MappNested(ifrom, resobject, gres);
            MappNested(iadditional, resobject, gres);

            return(gres);
        }
        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;
        }