private IList <SettingKey> SaveSettings(IEnumerable <KeyValuePair <SettingKey, SettingItem> > values)
        {
            List <SettingKey> keys = new List <SettingKey>();

            using (IUnitOfWork work = ServiceProvider.GetService <IDataContextFactory>().Get().Create())
            {
                IRepository <SettingData> repository = work.For <SettingData>();

                foreach (var pair in values)
                {
                    SettingKey          key   = pair.Key;
                    IProxyType <string> value = pair.Value;

                    try
                    {
                        if (AddOrUpdateSetting(repository, key, value))
                        {
                            keys.Add(key);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.SettingAddOrUpdateError, key);
                        Logger.Instance.LogException(this, ex);
                    }
                }

                work.Commit();
            }

            return(keys);
        }
 public static IProxyPropertyInfo AsProxy(this PropertyInfo info)
 {
     IProxyType proxyType = factory.Get(info.DeclaringType);
     if (info.GetGetMethod().IsPublic)
         return proxyType.GetProperty(info.Name);
     return proxyType.GetProperty(info.Name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static);
 }
        public static IProxyInvoker AsProxy(this MethodInfo info, object target)
        {
            IProxyType       proxyType       = factory.Create(info.DeclaringType);
            IProxyMethodInfo proxyMethodInfo = proxyType.GetMethod(info);

            return(new ProxyInvoker(target, proxyMethodInfo));
        }
Ejemplo n.º 4
0
        public IProxyEventInfo GetEvent(string name)
        {
            IProxyEventInfo info;

            if (this.events.TryGetValue(name, out info))
            {
                return(info);
            }

            EventInfo eventInfo = this.type.GetEvent(name);

            if (eventInfo != null && eventInfo.DeclaringType.Equals(type))
            {
                return(this.CreateProxyEventInfo(eventInfo));
            }

            IProxyType baseTypeInfo = this.GetBase();

            if (baseTypeInfo == null)
            {
                return(null);
            }

            return(baseTypeInfo.GetEvent(name));
        }
Ejemplo n.º 5
0
        public IProxyPropertyInfo GetProperty(string name, BindingFlags flags)
        {
            IProxyPropertyInfo info;

            if (this.properties.TryGetValue(name, out info))
            {
                return(info);
            }

            PropertyInfo propertyInfo = this.type.GetProperty(name, flags);

            if (propertyInfo != null && propertyInfo.DeclaringType.Equals(type))
            {
                return(this.CreateProxyPropertyInfo(propertyInfo));
            }

            IProxyType baseTypeInfo = this.GetBase();

            if (baseTypeInfo == null)
            {
                return(null);
            }

            return(baseTypeInfo.GetProperty(name, flags));
        }
Ejemplo n.º 6
0
        public IProxyFieldInfo GetField(string name, BindingFlags flags)
        {
            IProxyFieldInfo info;

            if (this.fields.TryGetValue(name, out info))
            {
                return(info);
            }

            FieldInfo fieldInfo = this.type.GetField(name, flags);

            if (fieldInfo != null && fieldInfo.DeclaringType.Equals(type))
            {
                return(this.CreateProxyFieldInfo(fieldInfo));
            }

            IProxyType baseTypeInfo = this.GetBase();

            if (baseTypeInfo == null)
            {
                return(null);
            }

            return(baseTypeInfo.GetField(name, flags));
        }
Ejemplo n.º 7
0
        public IProxyItemInfo GetItem()
        {
            if (this.itemInfo != null)
            {
                return(this.itemInfo);
            }

            if (type.IsArray)
            {
                return(this.CreateArrayProxyItemInfo(type));
            }
            else
            {
                PropertyInfo propertyInfo = this.type.GetProperty("Item");
                if (propertyInfo != null && propertyInfo.DeclaringType.Equals(type))
                {
                    return(this.CreateProxyItemInfo(propertyInfo));
                }

                IProxyType baseTypeInfo = this.GetBase();
                if (baseTypeInfo == null)
                {
                    return(null);
                }

                return(baseTypeInfo.GetItem());
            }
        }
Ejemplo n.º 8
0
        public virtual IProxyMethodInfo GetMethod(string name, Type[] parameterTypes)
        {
            IProxyMethodInfo info = this.GetMethodInfo(name, parameterTypes);

            if (info != null)
            {
                return(info);
            }

            MethodInfo methodInfo = this.type.GetMethod(name, parameterTypes);

            if (methodInfo != null && methodInfo.DeclaringType.Equals(type))
            {
                return(this.CreateProxyMethodInfo(methodInfo));
            }

            IProxyType baseTypeInfo = this.GetBase();

            if (baseTypeInfo == null)
            {
                return(null);
            }

            return(baseTypeInfo.GetMethod(name, parameterTypes));
        }
Ejemplo n.º 9
0
        public IProxyMethodInfo GetMethod(string name, Type[] parameterTypes, BindingFlags flags)
        {
            IProxyMethodInfo info = this.GetMethodInfo(name, parameterTypes);

            if (info != null)
            {
                return(info);
            }

#if NETFX_CORE
            MethodInfo methodInfo = this.type.GetMethod(name, flags);
#else
            MethodInfo methodInfo = this.type.GetMethod(name, flags, null, parameterTypes, null);
#endif
            if (methodInfo != null && methodInfo.DeclaringType.Equals(type))
            {
                return(this.CreateProxyMethodInfo(methodInfo));
            }

            IProxyType baseTypeInfo = this.GetBase();
            if (baseTypeInfo == null)
            {
                return(null);
            }

            return(baseTypeInfo.GetMethod(name, parameterTypes, flags));
        }
 public static IProxyFieldInfo AsProxy(this FieldInfo info)
 {
     IProxyType proxyType = factory.Get(info.DeclaringType);
     if (info.IsPublic)
         return proxyType.GetField(info.Name);
     return proxyType.GetField(info.Name, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static);
 }
        public static IProxyMethodInfo AsProxy(this MethodInfo info)
        {
            IProxyType proxyType = factory.Get(info.DeclaringType);
            Type[] types = info.GetParameterTypes().ToArray();
            if (info.IsPublic)
                return proxyType.GetMethod(info.Name, types);

            return proxyType.GetMethod(info.Name, types, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static);
        }
Ejemplo n.º 12
0
        public static void Run()
        {
            Account account = new Account()
            {
                ID       = 1,
                Username = "******",
                Password = "******",
                Email    = "*****@*****.**",
                Birthday = new DateTime(2000, 3, 3)
            };

            User user = new User()
            {
                FirstName = "Tom"
            };

            try
            {
                IProxyType userProxyType = ProxyFactory.Default.Get(typeof(User));
                UnityEngine.Debug.LogFormat("user.FirstName:{0}", userProxyType.GetProperty("FirstName").GetValue(user));
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogFormat("user exception:{0}", e);
            }

            try
            {
                IProxyType accountProxyType = ProxyFactory.Default.Get(typeof(Account));
                UnityEngine.Debug.LogFormat("account.Username:{0}", accountProxyType.GetProperty("Username").GetValue(account));
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogFormat("account exception:{0}", e);
            }

            //Test t = new Test()
            //{
            //    Username = "******"
            //};

            //try
            //{
            //    IProxyType testProxyType = ProxyFactory.Default.Get(typeof(Test));
            //    UnityEngine.Debug.LogFormat("test.Username:{0}", testProxyType.GetProperty("Username").GetValue(t));
            //}
            //catch (Exception e)
            //{
            //    UnityEngine.Debug.LogFormat("user exception:{0}", e);
            //}
        }
Ejemplo n.º 13
0
        public IProxyType GetBase()
        {
            if (this.baseType != null)
            {
                return(this.baseType);
            }

            Type _baseType = type.GetTypeInfo().BaseType;

            if (_baseType == null)
            {
                return(null);
            }

            this.baseType = factory.Get(_baseType);
            return(this.baseType);
        }
Ejemplo n.º 14
0
        public IProxyType GetBase()
        {
            if (this.baseType != null)
            {
                return(this.baseType);
            }

#if NETFX_CORE
            Type _baseType = type.GetTypeInfo().BaseType;
#else
            Type _baseType = type.BaseType;
#endif

            if (_baseType == null)
            {
                return(null);
            }

            this.baseType = factory.Get(_baseType);
            return(this.baseType);
        }
Ejemplo n.º 15
0
        private IList <SettingKey> SaveSettings(IEnumerable <KeyValuePair <SettingKey, SettingItem> > values)
        {
            List <SettingKey> keys = new List <SettingKey>();

            using (SettingsEntities entities = EntityFrameworkHelper.CreateContext <SettingsEntities>(EdmxPath))
            {
                foreach (var pair in values)
                {
                    SettingKey          key   = pair.Key;
                    IProxyType <string> value = pair.Value;

                    try
                    {
                        if (AddOrUpdateSetting(entities, key, value))
                        {
                            keys.Add(key);
                        }
                    }
                    catch (ConstraintException ex)
                    {
                        Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.SettingAddOrUpdateConstraintError, key);
                        Logger.Instance.LogException(this, ex);
                    }
                    catch (DataException ex)
                    {
                        Logger.Instance.LogFormat(LogType.Error, this, Properties.Resources.SettingAddOrUpdateError, key);
                        Logger.Instance.LogException(this, ex);
                    }
                }

                if (keys.Count > 0)
                {
                    entities.SaveChanges();
                }
            }

            return(keys);
        }
        public static IProxyPropertyInfo AsProxy(this PropertyInfo info)
        {
            IProxyType proxyType = factory.Create(info.DeclaringType);

            return(proxyType.GetProperty(info));
        }
        public static IProxyFieldInfo AsProxy(this FieldInfo info)
        {
            IProxyType proxyType = factory.Create(info.DeclaringType);

            return(proxyType.GetField(info));
        }
Ejemplo n.º 18
0
        public List <IDetectable> Find <T>(IDetectable proxyTypeDetectable, params Type[] ignoredTypes)
        {
            IProxyType proxyTypeInstance = (IProxyType)Activator.CreateInstance(proxyTypeDetectable.Implementation);

            return(Find <T>(proxyTypeInstance.Type, ignoredTypes));
        }
        private static bool AddOrUpdateSetting(SettingsEntities entities, SettingKey key, IProxyType<string> value)
        {
            UserSettingData userSetting = entities.GetUserSettingData(key.Identifier, key.Name);
            if (userSetting == null)
            {
                userSetting = new UserSettingData();
                userSetting.Identifier = key.Identifier;
                userSetting.Name = key.Name;
                entities.UserSettings.AddObject(userSetting);
            }

            string valueToPersist = value.ProxiedValue;
            if (!string.Equals(userSetting.Value, valueToPersist, StringComparison.Ordinal))
            {
                userSetting.Value = valueToPersist;

                return true;
            }

            return false;
        }
Ejemplo n.º 20
0
        public ITargetProxy CreateProxy(object target, BindingDescription description)
        {
            IProxyType       type       = target.GetType().AsProxy();
            IProxyMemberInfo memberInfo = type.GetMember(description.TargetName);

            if (memberInfo == null)
            {
                memberInfo = type.GetMember(description.TargetName, BindingFlags.Instance | BindingFlags.NonPublic);
            }

            if (memberInfo == null)
            {
                throw new MissingMemberException(type.Type.FullName, description.TargetName);
            }

            var propertyInfo = memberInfo as IProxyPropertyInfo;

            if (propertyInfo != null)
            {
                var valueType = propertyInfo.ValueType;
                if (typeof(IObservableProperty).IsAssignableFrom(valueType))
                {
                    object observableValue = propertyInfo.GetValue(target);
                    if (observableValue == null)
                    {
                        throw new NullReferenceException(string.Format("The \"{0}\" property is null in class \"{1}\".", propertyInfo.Name, propertyInfo.DeclaringType.Name));
                    }

                    return(new ObservableTargetProxy(target, (IObservableProperty)observableValue));
                }

                if (typeof(IInteractionAction).IsAssignableFrom(valueType))
                {
                    object interactionAction = propertyInfo.GetValue(target);
                    if (interactionAction == null)
                    {
                        return(null);
                    }

                    return(new InteractionTargetProxy(target, (IInteractionAction)interactionAction));
                }

                return(new PropertyTargetProxy(target, propertyInfo));
            }

            var fieldInfo = memberInfo as IProxyFieldInfo;

            if (fieldInfo != null)
            {
                var valueType = fieldInfo.ValueType;
                if (typeof(IObservableProperty).IsAssignableFrom(valueType))
                {
                    object observableValue = fieldInfo.GetValue(target);
                    if (observableValue == null)
                    {
                        throw new NullReferenceException(string.Format("The \"{0}\" field is null in class \"{1}\".", fieldInfo.Name, fieldInfo.DeclaringType.Name));
                    }

                    return(new ObservableTargetProxy(target, (IObservableProperty)observableValue));
                }

                if (typeof(IInteractionAction).IsAssignableFrom(valueType))
                {
                    object interactionAction = fieldInfo.GetValue(target);
                    if (interactionAction == null)
                    {
                        return(null);
                    }

                    return(new InteractionTargetProxy(target, (IInteractionAction)interactionAction));
                }

                return(new FieldTargetProxy(target, fieldInfo));
            }

            var eventInfo = memberInfo as IProxyEventInfo;

            if (eventInfo != null)
            {
                return(new EventTargetProxy(target, eventInfo));
            }

            var methodInfo = memberInfo as IProxyMethodInfo;

            if (methodInfo != null)
            {
                return(new MethodTargetProxy(target, methodInfo));
            }

            return(null);
        }
 public static IProxyEventInfo AsProxy(this EventInfo info)
 {
     IProxyType proxyType = factory.Get(info.DeclaringType);
     return proxyType.GetEvent(info.Name);
 }
        public ITargetProxy CreateProxy(object target, BindingDescription description)
        {
            if (!target.GetType().IsSubclassOfGenericTypeDefinition(typeof(INotifyValueChanged <>)))
            {
                return(null);
            }

            if ("RegisterValueChangedCallback".Equals(description.TargetName))
            {
                return(this.CreateValueChangedEventProxy(target));
            }

            IProxyType       type       = target.GetType().AsProxy();
            IProxyMemberInfo memberInfo = type.GetMember(description.TargetName);

            if (memberInfo == null)
            {
                memberInfo = type.GetMember(description.TargetName, BindingFlags.Instance | BindingFlags.NonPublic);
            }

            if (memberInfo == null)
            {
                throw new MissingMemberException(type.Type.FullName, description.TargetName);
            }

            var propertyInfo = memberInfo as IProxyPropertyInfo;

            if (propertyInfo != null)
            {
                if (typeof(IObservableProperty).IsAssignableFrom(propertyInfo.ValueType))
                {
                    return(null);
                }

                if (typeof(Clickable).IsAssignableFrom(propertyInfo.ValueType))
                {
                    //Event Type
                    object clickable = propertyInfo.GetValue(target);
                    if (clickable == null)
                    {
                        throw new NullReferenceException(propertyInfo.Name);
                    }

                    return(new ClickableEventProxy(target, (Clickable)clickable));
                }

                //Other Property Type
                if (!"RegisterValueChangedCallback".Equals(description.UpdateTrigger))/* by UniversalTargetProxyFactory */
                {
                    return(null);
                }

                return(CreateVisualElementPropertyProxy(target, propertyInfo));
            }

            var fieldInfo = memberInfo as IProxyFieldInfo;

            if (fieldInfo != null)
            {
                if (typeof(IObservableProperty).IsAssignableFrom(fieldInfo.ValueType))
                {
                    return(null);
                }

                if (typeof(Clickable).IsAssignableFrom(fieldInfo.ValueType))
                {
                    //Event Type
                    object clickable = fieldInfo.GetValue(target);
                    if (clickable == null)
                    {
                        throw new NullReferenceException(fieldInfo.Name);
                    }

                    return(new ClickableEventProxy(target, (Clickable)clickable));
                }

                //Other Property Type
                if (!"RegisterValueChangedCallback".Equals(description.UpdateTrigger))/* by UniversalTargetProxyFactory */
                {
                    return(null);
                }

                return(CreateVisualElementFieldProxy(target, fieldInfo));
            }

            return(null);
        }
Ejemplo n.º 23
0
        //private static readonly ILog log = LogManager.GetLogger(typeof(UnityTargetProxyFactory));

        public ITargetProxy CreateProxy(object target, BindingDescription description)
        {
            IProxyType       type       = target.GetType().AsProxy();
            IProxyMemberInfo memberInfo = type.GetMember(description.TargetName);

            if (memberInfo == null)
            {
                memberInfo = type.GetMember(description.TargetName, BindingFlags.Instance | BindingFlags.NonPublic);
            }

            if (memberInfo == null)
            {
                return(null);
            }

            UnityEventBase updateTrigger = null;

            if (!string.IsNullOrEmpty(description.UpdateTrigger))
            {
                var updateTriggerPropertyInfo = type.GetProperty(description.UpdateTrigger);
                if (updateTriggerPropertyInfo != null)
                {
                    updateTrigger = updateTriggerPropertyInfo.GetValue(target) as UnityEventBase;
                }

                if (updateTriggerPropertyInfo == null)
                {
                    var updateTriggerFieldInfo = type.GetField(description.UpdateTrigger);
                    if (updateTriggerFieldInfo != null)
                    {
                        updateTrigger = updateTriggerFieldInfo.GetValue(target) as UnityEventBase;
                    }
                }
            }

            var propertyInfo = memberInfo as IProxyPropertyInfo;

            if (propertyInfo != null)
            {
                if (typeof(IObservableProperty).IsAssignableFrom(propertyInfo.ValueType))
                {
                    return(null);
                }

                if (typeof(UnityEventBase).IsAssignableFrom(propertyInfo.ValueType))
                {
                    //Event Type
                    object unityEvent = propertyInfo.GetValue(target);
                    Type[] paramTypes = GetUnityEventParametersType(propertyInfo.ValueType);
                    return(CreateUnityEventProxy(target, (UnityEventBase)unityEvent, paramTypes));
                }

                //Other Property Type
                if (updateTrigger == null)/* by UniversalTargetProxyFactory */
                {
                    return(null);
                }

                return(CreateUnityPropertyProxy(target, propertyInfo, updateTrigger));
            }

            var fieldInfo = memberInfo as IProxyFieldInfo;

            if (fieldInfo != null)
            {
                if (typeof(IObservableProperty).IsAssignableFrom(fieldInfo.ValueType))
                {
                    return(null);
                }

                if (typeof(UnityEventBase).IsAssignableFrom(fieldInfo.ValueType))
                {
                    //Event Type
                    object unityEvent = fieldInfo.GetValue(target);
                    Type[] paramTypes = GetUnityEventParametersType(fieldInfo.ValueType);
                    return(CreateUnityEventProxy(target, (UnityEventBase)unityEvent, paramTypes));
                }

                //Other Property Type
                if (updateTrigger == null)/* by UniversalTargetProxyFactory */
                {
                    return(null);
                }

                return(CreateUnityFieldProxy(target, fieldInfo, updateTrigger));
            }

            return(null);
        }
Ejemplo n.º 24
0
        private static bool AddOrUpdateSetting(IRepository<SettingData> repository, SettingKey key, IProxyType<string> value)
        {
            SettingData setting = repository.Query.FirstOrDefault(_ => _.Identifier == key.Identifier && _.Name == key.Name);

            if (setting == null)
            {
                setting = new SettingData();
                setting.Identifier = key.Identifier;
                setting.Name = key.Name;

                repository.Insert(setting);
            }

            string valueToPersist = value.ProxiedValue;
            if (!string.Equals(setting.Value, valueToPersist, StringComparison.Ordinal))
            {
                setting.Value = valueToPersist;

                return true;
            }

            return false;
        }
Ejemplo n.º 25
0
        protected virtual ISourceProxy CreateProxy(object source, IPathNode node)
        {
            IProxyType proxyType = source.GetType().AsProxy();

            if (node is IndexedNode)
            {
                var itemInfo = proxyType.GetItem();
                if (itemInfo == null)
                {
                    return(null);
                }

                var intIndexedNode = node as IntegerIndexedNode;
                if (intIndexedNode != null)
                {
                    return(new IntItemNodeProxy((ICollection)source, intIndexedNode.Value, itemInfo));
                }

                var stringIndexedNode = node as StringIndexedNode;
                if (stringIndexedNode != null)
                {
                    return(new StringItemNodeProxy((ICollection)source, stringIndexedNode.Value, itemInfo));
                }

                return(null);
            }

            var memberNode = node as MemberNode;

            if (memberNode == null)
            {
                return(null);
            }

            var memberInfo = memberNode.MemberInfo;

            if (memberInfo == null)
            {
                memberInfo = source.GetType().FindFirstMemberInfo(memberNode.Name);
            }

            if (memberInfo == null || memberInfo.IsStatic())
            {
                return(null);
            }

            var propertyInfo = memberInfo as PropertyInfo;

            if (propertyInfo != null)
            {
                IProxyPropertyInfo proxyPropertyInfo = propertyInfo.AsProxy();
                var valueType = proxyPropertyInfo.ValueType;
                if (typeof(IObservableProperty).IsAssignableFrom(valueType))
                {
                    object observableValue = proxyPropertyInfo.GetValue(source);
                    if (observableValue == null)
                    {
                        return(null);
                    }

                    return(new ObservableNodeProxy(source, (IObservableProperty)observableValue));
                }
                // else if (typeof(IInteractionRequest).IsAssignableFrom(valueType))
                // {
                // object request = proxyPropertyInfo.GetValue(source);
                // if (request == null)
                // return null;

                // return new InteractionNodeProxy(source, (IInteractionRequest)request);
                // }
                else
                {
                    return(new PropertyNodeProxy(source, proxyPropertyInfo));
                }
            }

            var fieldInfo = memberInfo as FieldInfo;

            if (fieldInfo != null)
            {
                IProxyFieldInfo proxyFieldInfo = fieldInfo.AsProxy();
                var             valueType      = proxyFieldInfo.ValueType;
                if (typeof(IObservableProperty).IsAssignableFrom(valueType))
                {
                    object observableValue = proxyFieldInfo.GetValue(source);
                    if (observableValue == null)
                    {
                        return(null);
                    }

                    return(new ObservableNodeProxy(source, (IObservableProperty)observableValue));
                }
                // else if (typeof(IInteractionRequest).IsAssignableFrom(valueType))
                // {
                // object request = proxyFieldInfo.GetValue(source);
                // if (request == null)
                // return null;

                // return new InteractionNodeProxy(source, (IInteractionRequest)request);
                // }
                else
                {
                    return(new FieldNodeProxy(source, proxyFieldInfo));
                }
            }

            var methodInfo = memberInfo as MethodInfo;

            if (methodInfo != null && methodInfo.ReturnType.Equals(typeof(void)))
            {
                return(new MethodNodeProxy(source, methodInfo.AsProxy()));
            }

            var eventInfo = memberInfo as EventInfo;

            if (eventInfo != null)
            {
                return(new EventNodeProxy(source, eventInfo.AsProxy()));
            }

            return(null);
        }
Ejemplo n.º 26
0
        public ITargetProxy CreateProxy(object target, BindingDescription description)
        {
            IProxyType       type       = target.GetType().AsProxy();
            IProxyMemberInfo memberInfo = type.GetMember(description.TargetName);

            if (memberInfo == null)
            {
                memberInfo = type.GetMember(description.TargetName, BindingFlags.Instance | BindingFlags.NonPublic);
            }

            if (memberInfo == null)
            {
                return(null);
            }

            var propertyInfo = memberInfo as IProxyPropertyInfo;

            if (propertyInfo != null)
            {
                var valueType = propertyInfo.ValueType;
                if (typeof(IObservableProperty).IsAssignableFrom(valueType))
                {
                    object observableValue = propertyInfo.GetValue(target);
                    if (observableValue == null)
                    {
                        return(null);
                    }

                    return(new ObservableTargetProxy(target, (IObservableProperty)observableValue));
                }

                // if (typeof(IInteractionAction).IsAssignableFrom(valueType))
                // {
                //     object interactionAction = propertyInfo.GetValue(target);
                //     if (interactionAction == null)
                //         return null;
                //
                //     return new InteractionTargetProxy(target, (IInteractionAction)interactionAction);
                // }

                return(new PropertyTargetProxy(target, propertyInfo));
            }

            var fieldInfo = memberInfo as IProxyFieldInfo;

            if (fieldInfo != null)
            {
                var valueType = fieldInfo.ValueType;
                if (typeof(IObservableProperty).IsAssignableFrom(valueType))
                {
                    object observableValue = fieldInfo.GetValue(target);
                    if (observableValue == null)
                    {
                        return(null);
                    }

                    return(new ObservableTargetProxy(target, (IObservableProperty)observableValue));
                }

                // if (typeof(IInteractionAction).IsAssignableFrom(valueType))
                // {
                //     object interactionAction = fieldInfo.GetValue(target);
                //     if (interactionAction == null)
                //         return null;
                //
                //     return new InteractionTargetProxy(target, (IInteractionAction)interactionAction);
                // }

                return(new FieldTargetProxy(target, fieldInfo));
            }

            var eventInfo = memberInfo as IProxyEventInfo;

            if (eventInfo != null)
            {
                return(new EventTargetProxy(target, eventInfo));
            }

            var methodInfo = memberInfo as IProxyMethodInfo;

            if (methodInfo != null)
            {
                return(new MethodTargetProxy(target, methodInfo));
            }

            return(null);
        }
        public static IProxyMethodInfo AsProxy(this MethodInfo info)
        {
            IProxyType proxyType = factory.Create(info.DeclaringType);

            return(proxyType.GetMethod(info));
        }
Ejemplo n.º 28
0
        private static bool AddOrUpdateSetting(SettingsEntities entities, SettingKey key, IProxyType <string> value)
        {
            UserSettingData userSetting = entities.GetUserSettingData(key.Identifier, key.Name);

            if (userSetting == null)
            {
                userSetting            = new UserSettingData();
                userSetting.Identifier = key.Identifier;
                userSetting.Name       = key.Name;
                entities.UserSettings.AddObject(userSetting);
            }

            string valueToPersist = value.ProxiedValue;

            if (!string.Equals(userSetting.Value, valueToPersist, StringComparison.Ordinal))
            {
                userSetting.Value = valueToPersist;

                return(true);
            }

            return(false);
        }
Ejemplo n.º 29
0
        private static bool AddOrUpdateSetting(IRepository <SettingData> repository, SettingKey key, IProxyType <string> value)
        {
            SettingData setting = repository.Query.FirstOrDefault(_ => _.Identifier == key.Identifier && _.Name == key.Name);

            if (setting == null)
            {
                setting            = new SettingData();
                setting.Identifier = key.Identifier;
                setting.Name       = key.Name;

                repository.Insert(setting);
            }

            string valueToPersist = value.ProxiedValue;

            if (!string.Equals(setting.Value, valueToPersist, StringComparison.Ordinal))
            {
                setting.Value = valueToPersist;

                return(true);
            }

            return(false);
        }
        protected virtual ISourceProxy CreateProxy(object source, IPathNode node)
        {
            IProxyType proxyType = source.GetType().AsProxy();

            if (node is IndexedNode)
            {
                if (!(source is ICollection))
                {
                    throw new ProxyException("Type \"{0}\" is not a collection and cannot be accessed by index \"{1}\".", proxyType.Type.Name, node.ToString());
                }

                var itemInfo = proxyType.GetItem();
                if (itemInfo == null)
                {
                    throw new MissingMemberException(proxyType.Type.FullName, "Item");
                }

                var intIndexedNode = node as IntegerIndexedNode;
                if (intIndexedNode != null)
                {
                    return(new IntItemNodeProxy((ICollection)source, intIndexedNode.Value, itemInfo));
                }

                var stringIndexedNode = node as StringIndexedNode;
                if (stringIndexedNode != null)
                {
                    return(new StringItemNodeProxy((ICollection)source, stringIndexedNode.Value, itemInfo));
                }

                return(null);
            }

            var memberNode = node as MemberNode;

            if (memberNode == null)
            {
                return(null);
            }

            var memberInfo = memberNode.MemberInfo;

            if (memberInfo == null)
            {
                memberInfo = source.GetType().FindFirstMemberInfo(memberNode.Name);
            }

            if (memberInfo == null || memberInfo.IsStatic())
            {
                throw new MissingMemberException(proxyType.Type.FullName, memberNode.Name);
            }

            var propertyInfo = memberInfo as PropertyInfo;

            if (propertyInfo != null)
            {
                IProxyPropertyInfo proxyPropertyInfo = propertyInfo.AsProxy();
                var valueType = proxyPropertyInfo.ValueType;
                if (typeof(IObservableProperty).IsAssignableFrom(valueType))
                {
                    object observableValue = proxyPropertyInfo.GetValue(source);
                    if (observableValue == null)
                    {
                        return(null);
                    }

                    return(new ObservableNodeProxy(source, (IObservableProperty)observableValue));
                }
                else if (typeof(IInteractionRequest).IsAssignableFrom(valueType))
                {
                    object request = proxyPropertyInfo.GetValue(source);
                    if (request == null)
                    {
                        return(null);
                    }

                    return(new InteractionNodeProxy(source, (IInteractionRequest)request));
                }
                else
                {
                    return(new PropertyNodeProxy(source, proxyPropertyInfo));
                }
            }

            var fieldInfo = memberInfo as FieldInfo;

            if (fieldInfo != null)
            {
                IProxyFieldInfo proxyFieldInfo = fieldInfo.AsProxy();
                var             valueType      = proxyFieldInfo.ValueType;
                if (typeof(IObservableProperty).IsAssignableFrom(valueType))
                {
                    object observableValue = proxyFieldInfo.GetValue(source);
                    if (observableValue == null)
                    {
                        return(null);
                    }

                    return(new ObservableNodeProxy(source, (IObservableProperty)observableValue));
                }
                else if (typeof(IInteractionRequest).IsAssignableFrom(valueType))
                {
                    object request = proxyFieldInfo.GetValue(source);
                    if (request == null)
                    {
                        return(null);
                    }

                    return(new InteractionNodeProxy(source, (IInteractionRequest)request));
                }
                else
                {
                    return(new FieldNodeProxy(source, proxyFieldInfo));
                }
            }

            var methodInfo = memberInfo as MethodInfo;

            if (methodInfo != null && methodInfo.ReturnType.Equals(typeof(void)))
            {
                return(new MethodNodeProxy(source, methodInfo.AsProxy()));
            }

            var eventInfo = memberInfo as EventInfo;

            if (eventInfo != null)
            {
                return(new EventNodeProxy(source, eventInfo.AsProxy()));
            }

            return(null);
        }
Ejemplo n.º 31
0
        public ITargetProxy CreateProxy(object target, BindingDescription description)
        {
            IProxyType       type       = target.GetType().AsProxy();
            IProxyMemberInfo memberInfo = type.GetMember(description.TargetName);

            if (memberInfo == null)
            {
                memberInfo = type.GetMember(description.TargetName, BindingFlags.Instance | BindingFlags.NonPublic);
            }

            if (memberInfo == null)
            {
                throw new MissingMemberException(type.Type.FullName, description.TargetName);
            }

            EventListener updateTrigger = null;

            if (!string.IsNullOrEmpty(description.UpdateTrigger))
            {
                IProxyPropertyInfo updateTriggerPropertyInfo = type.GetProperty(description.UpdateTrigger);
                IProxyFieldInfo    updateTriggerFieldInfo    = updateTriggerPropertyInfo == null?type.GetField(description.UpdateTrigger) : null;

                if (updateTriggerPropertyInfo != null)
                {
                    updateTrigger = updateTriggerPropertyInfo.GetValue(target) as EventListener;
                }

                if (updateTriggerFieldInfo != null)
                {
                    updateTrigger = updateTriggerFieldInfo.GetValue(target) as EventListener;
                }

                if (updateTriggerPropertyInfo == null && updateTriggerFieldInfo == null)
                {
                    throw new MissingMemberException(type.Type.FullName, description.UpdateTrigger);
                }

                //Other Property Type
                if (updateTrigger == null) /* by UniversalTargetProxyFactory */
                {
                    return(null);
                }
            }

            var propertyInfo = memberInfo as IProxyPropertyInfo;

            if (propertyInfo != null)
            {
                if (typeof(IObservableProperty).IsAssignableFrom(propertyInfo.ValueType))
                {
                    return(null);
                }

                if (typeof(EventListener).IsAssignableFrom(propertyInfo.ValueType))
                {
                    //Event Type
                    object listener = propertyInfo.GetValue(target);
                    if (listener == null)
                    {
                        throw new NullReferenceException(propertyInfo.Name);
                    }

                    return(new FairyEventProxy(target, (EventListener)listener));
                }

                //Other Property Type
                if (updateTrigger == null)/* by UniversalTargetProxyFactory */
                {
                    return(null);
                }

                return(new FairyPropertyProxy(target, propertyInfo, updateTrigger));
            }

            var fieldInfo = memberInfo as IProxyFieldInfo;

            if (fieldInfo != null)
            {
                if (typeof(IObservableProperty).IsAssignableFrom(fieldInfo.ValueType))
                {
                    return(null);
                }

                if (typeof(EventListener).IsAssignableFrom(fieldInfo.ValueType))
                {
                    //Event Type
                    object listener = fieldInfo.GetValue(target);
                    if (listener == null)
                    {
                        throw new NullReferenceException(fieldInfo.Name);
                    }

                    return(new FairyEventProxy(target, (EventListener)listener));
                }

                //Other Property Type
                if (updateTrigger == null)/* by UniversalTargetProxyFactory */
                {
                    return(null);
                }

                return(new FairyFieldProxy(target, fieldInfo, updateTrigger));
            }

            return(null);
        }
Ejemplo n.º 32
0
 internal SearchResultWithConversion(SearchResult parent, IProxyType proxyType)
 {
     _parent = parent;
     _proxyType = proxyType;
 }