예제 #1
0
 public AjaxEventTriplet(string name, ComponentAjaxEvent ajaxEvent, ClientConfigAttribute attribute, PropertyInfo propertyInfo)
 {
     this.name         = name;
     this.ajaxEvent    = ajaxEvent;
     this.attribute    = attribute;
     this.propertyInfo = propertyInfo;
 }
예제 #2
0
        private static ConfigProperties GetProperties(object obj)
        {
            string           key = obj.GetType().FullName;
            ConfigProperties cahcheProperties = null;

            HttpContext context = HttpContext.Current;

            if (context != null)
            {
                cahcheProperties = context.Cache[key] as ConfigProperties;
            }


            if (cahcheProperties != null)
            {
                return(cahcheProperties);
            }
            else
            {
                PropertyInfo[] result = obj.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

                ConfigProperties list = new ConfigProperties();
                foreach (PropertyInfo propertyInfo in result)
                {
                    ClientConfigAttribute attr = ClientConfig.GetClientConfigAttribute(propertyInfo);
                    if (attr != null)
                    {
                        list.Add(new ConfigObject(propertyInfo, attr, ReflectionUtils.GetDefaultValue(propertyInfo)));
                    }
                }

                list.Reverse();

                if (context != null)
                {
                    context.Cache.Insert(key, list);
                }

                return(list);
            }
        }
예제 #3
0
        public object this[string key]
        {
            get
            {
                return(this.ViewState[key]);
            }
            set
            {
                this.ViewState[key] = value;
                if (Ext.IsAjaxRequest && control.AllowCallbackScriptMonitoring)
                {
                    PropertyInfo pi = control.GetType().GetProperty(key);

                    if (pi == null)
                    {
                        return;
                    }

                    object[] attrs = pi.GetCustomAttributes(typeof(AjaxEventUpdateAttribute), true);

                    if (attrs.Length > 0)
                    {
                        this.control.CallbackValues[key] = value;
                        ((AjaxEventUpdateAttribute)attrs[0]).RegisterScript(this.control, pi);
                    }
                    else
                    {
                        ClientConfigAttribute attr = ClientConfig.GetClientConfigAttribute(pi);
                        if (attr != null)
                        {
                            this.control.CallbackValues[key] = value;
                            this.control.AddScript(string.Format(AjaxEventUpdateAttribute.AutoGenerateFormat, this.control.ClientID, JSON.Serialize(value), StringUtils.ToLowerCamelCase(pi.Name)));
                        }
                    }
                }
            }
        }
예제 #4
0
 public ConfigObject(PropertyInfo propertyInfo, ClientConfigAttribute attr, object defValue)
 {
     this.propertyInfo = propertyInfo;
     this.attr         = attr;
     this.defaultValue = defValue;
 }
예제 #5
0
        private void ToExtConfig(PropertyInfo property, object obj, ClientConfigAttribute attr, object defaultValue)
        {
            if (attr.Mode != JsonMode.Ignore)
            {
                object originalValue = property.GetValue(obj, null);

                if (!IsNullEmptyOrDefault(ref defaultValue, ref originalValue))
                {
                    if (originalValue.Equals("NULL"))
                    {
                        originalValue = null;
                    }

                    string name = StringUtils.ToLowerCamelCase(property.Name);

                    /// TODO: HACK: Need to figure out a better place to populate this
                    /// Listener Arguments from list of ListenerArgumentAttribute's.
                    if (originalValue != null && originalValue is BaseListener)
                    {
                        ((BaseListener)originalValue).SetArgumentList(property);
                    }

                    if (!string.IsNullOrEmpty(attr.Name))
                    {
                        if (attr.Name.Contains(">"))
                        {
                            string[] parts = attr.Name.Split('>');
                            name = parts[0];
                            PropertyInfo          subProp = originalValue.GetType().GetProperty(parts[1]);
                            ClientConfigAttribute subAttr = ClientConfig.GetClientConfigAttribute(subProp);

                            if (subAttr != null)
                            {
                                attr          = subAttr;
                                originalValue = subProp.GetValue(originalValue, null);
                            }
                        }
                        else
                        {
                            name = attr.Name;
                        }
                    }

                    if (this.exclude.Contains(name))
                    {
                        return;
                    }

                    StringBuilder temp = new StringBuilder(128);

                    switch (attr.Mode)
                    {
                    case JsonMode.ToLower:
                        this.WriteValue(name, originalValue.ToString().ToLowerInvariant());
                        break;

                    case JsonMode.ToCamelLower:
                        this.WriteValue(name, StringUtils.ToLowerCamelCase(originalValue.ToString()));
                        break;

                    case JsonMode.Raw:
                        this.WriteRawValue(name, originalValue);
                        break;

                    case JsonMode.ObjectAllowEmpty:
                    case JsonMode.Object:
                        if (originalValue is InnerObservable)
                        {
                            InnerObservable obsr = originalValue as InnerObservable;
                            if (obsr.Visible)
                            {
                                this.WriteRawValue(name, string.Concat("this.", obsr.ClientID));
                            }

                            break;
                        }

                        temp.Append(new ClientConfig().SerializeInternal(originalValue, this.owner));

                        if (!IsEmptyObject(temp.ToString()) || attr.Mode == JsonMode.ObjectAllowEmpty)
                        {
                            InstanceOfAttribute type = this.GetInstanceOfAttribute(originalValue.GetType());

                            if (type != null && !string.IsNullOrEmpty(type.ClassName))
                            {
                                this.WriteRawValue(name, string.Format("new {0}({1})", type.ClassName, temp.ToString()));
                            }
                            else
                            {
                                this.WriteRawValue(name, temp.ToString());
                            }
                        }
                        break;

                    case JsonMode.UnrollCollection:
                        IEnumerable si = (IEnumerable)originalValue;
                        foreach (object unrollingObject in si)
                        {
                            if (unrollingObject != null)
                            {
                                this.Process(unrollingObject);
                            }
                        }
                        break;

                    case JsonMode.UnrollObject:
                        this.Process(originalValue);
                        break;

                    case JsonMode.Array:
                    case JsonMode.AlwaysArray:
                        if (originalValue is IEnumerable)
                        {
                            IList list = (IList)originalValue;
                            if (list.Count == 1 && attr.Mode != JsonMode.AlwaysArray)
                            {
                                temp.Append(new ClientConfig().SerializeInternal(list[0], this.owner));
                                if (!IsEmptyObject(temp.ToString()))
                                {
                                    this.WriteRawValue(name, temp.ToString());
                                }
                            }
                            else
                            {
                                bool comma = false;
                                temp.Append("[");
                                foreach (object o in list)
                                {
                                    if (comma)
                                    {
                                        temp.Append(",");
                                    }
                                    if (o.GetType().IsPrimitive || o is string)
                                    {
                                        temp.Append(JSON.Serialize(o));
                                    }
                                    else
                                    {
                                        temp.Append(new ClientConfig().SerializeInternal(o, this.owner));
                                    }

                                    comma = true;
                                }
                                temp.Append("]");

                                InstanceOfAttribute type = this.GetInstanceOfAttribute(originalValue.GetType());

                                if (type != null)
                                {
                                    this.WriteRawValue(name, string.Format("new {0}({1})", type.ClassName, temp.ToString()));
                                }
                                else
                                {
                                    this.WriteRawValue(name, temp.ToString());
                                }
                            }
                        }
                        break;

                    case JsonMode.ArrayToObject:
                        if (originalValue is IEnumerable)
                        {
                            IList list = (IList)originalValue;

                            temp.Append("{");
                            bool comma = false;
                            foreach (object o in list)
                            {
                                if (comma)
                                {
                                    temp.Append(",");
                                }
                                temp.Append(o.ToString());
                                comma = true;
                            }
                            temp.Append("}");

                            if (!IsEmptyObject(temp.ToString()))
                            {
                                this.WriteRawValue(name, temp.ToString());
                            }
                        }
                        break;

                    case JsonMode.Custom:
                        if (originalValue != null)
                        {
                            if (originalValue is IList && ((IList)originalValue).Count == 0)
                            {
                                break;
                            }

                            if (name != "-")
                            {
                                this.writer.WritePropertyName(name);
                            }

                            JsonConverter converter = (JsonConverter)Activator.CreateInstance(attr.JsonConverter);
                            PropertyInfo  prop      = converter.GetType().GetProperty("PropertyName");
                            if (prop != null)
                            {
                                prop.SetValue(converter, name, null);
                            }

                            converter.WriteJson(this.writer, originalValue);
                        }
                        break;

                    case JsonMode.ToClientID:
                        Control control = ControlUtils.FindControl(this.owner, originalValue.ToString(), true);
                        if (control != null)
                        {
                            if (name.StartsWith("{raw}"))
                            {
                                name = name.Substring(5);
                                this.WriteValue(name, control.ClientID);
                            }
                            else
                            {
                                this.WriteRawValue(name, control.ClientID);
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(string.Format("The Control with ID = '{0}' not found", originalValue.ToString()));
                        }
                        break;

                    case JsonMode.ToString:
                        this.WriteValue(name, originalValue.ToString());
                        break;

                    case JsonMode.Value:
                    default:
                        this.WriteValue(name, originalValue);
                        break;
                    }
                }
            }
        }
예제 #6
0
 public ListenerPropertyInfo(PropertyInfo propertyInfo, ClientConfigAttribute attribute)
 {
     this.propertyInfo = propertyInfo;
     this.attribute    = attribute;
 }
예제 #7
0
 public ListenerTriplet(string name, ComponentListener listener, ClientConfigAttribute attribute)
 {
     this.name      = name;
     this.listener  = listener;
     this.attribute = attribute;
 }