Пример #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 JSGenericObject MappNested(object ifrom, JSObject 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 awesomium: Unable to convert property {0} from {1} exception {2}", pn, ifrom, e));
                    continue;
                }

                IJSCSGlue childres = Map(childvalue);

                resobject[pn] = childres.JSValue;
                gres.Attributes[pn] = childres;
            }

            return gres;
        }      
        private JSGenericObject MappNested(object ifrom, JSObject 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 awesomium: Unable to convert property {0} from {1} exception {2}", pn, ifrom, e));
                    continue;
                }

                IJSCSGlue childres = Map(childvalue);

                resobject[pn]       = childres.JSValue;
                gres.Attributes[pn] = childres;
            }

            return(gres);
        }
        internal IJSCSGlue Map(object ifrom, object iadditional=null)
        {
            if (ifrom == null)
                return new JSGenericObject(_IJSOBuilder.CreateNull(), ifrom);

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

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

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

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

            JSValue value;
            if (_Basic.Solve(ifrom, out value))
            {
                return new JSBasicObject(value, ifrom);
            }

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

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

            JSObject resobject = _IJSOBuilder.CreateJSO();
   
            JSGenericObject gres = new JSGenericObject(new JSValue(resobject), ifrom);
            _Cacher.Cache(ifrom, gres);

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

            return gres;
        }
Пример #5
0
        public void RegisterMapping(JSObject iFather, string att, JSObject iChild)
        {
            JSGenericObject jso = GetFromJavascript(iFather) as JSGenericObject;

            Update(jso.Attributes[att] as IJSObservableBridge, iChild);
        }
        internal IJSCSGlue Map(object ifrom, object iadditional = null)
        {
            if (ifrom == null)
            {
                return(new JSGenericObject(_IJSOBuilder.CreateNull(), ifrom));
            }

            IJSCSGlue res = null;

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

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

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

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

            JSValue value;

            if (_Basic.Solve(ifrom, out value))
            {
                return(new JSBasicObject(value, ifrom));
            }

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

            IEnumerable ienfro = ifrom as IEnumerable;

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

            JSObject resobject = _IJSOBuilder.CreateJSO();

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

            _Cacher.Cache(ifrom, gres);

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

            return(gres);
        }