Inheritance: System.Attribute
Example #1
0
 public DirectEventTriplet(string name, ComponentDirectEvent directEvent, ConfigOptionAttribute attribute, PropertyInfo propertyInfo)
 {
     this.name         = name;
     this.directEvent  = directEvent;
     this.attribute    = attribute;
     this.propertyInfo = propertyInfo;
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public void SetDirectEventUpdate(string key, object value)
        {
            if (((control.IsProxy && !control.ScriptSuspended) || (RequestManager.IsAjaxRequest && control.AllowCallbackScriptMonitoring && !control.IsDynamic)) && X.ControlsScripting)
            {
                PropertyInfo pi = control.GetType().GetProperty(key);

                if (pi == null)
                {
                    return;
                }

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

                if (attrs.Length > 0)
                {
                    this.CheckID();
                    this.control.CallbackValues[key] = value;
                    ((DirectEventUpdateAttribute)attrs[0]).RegisterScript(this.control, pi);
                }
                else
                {
                    ConfigOptionAttribute attr = ClientConfig.GetClientConfigAttribute(pi);
                    if (attr != null)
                    {
                        this.CheckID();
                        this.control.CallbackValues[key] = value;
                        this.control.AddScript(string.Format(DirectEventUpdateAttribute.AutoGenerateFormat, this.control.ClientID, JSON.Serialize(value), pi.Name.ToLowerCamelCase()));
                    }
                }
            }
        }
Example #3
0
        private SerializationOptions ConfigOptionAttr2SerializationOptions(ConfigOptionAttribute attr)
        {
            if (attr.JsonConverter != null)
            {
                return(new SerializationOptions(attr.Name, attr.JsonConverter));
            }

            return(new SerializationOptions(attr.Name, attr.Mode));
        }
Example #4
0
        public object this[string key]
        {
            get
            {
                return(this.ViewState[key]);
            }
            set
            {
                this.ViewState[key] = value;

                if ((control.GenerateMethodsCalling) || (RequestManager.IsAjaxRequest && (control.AllowCallbackScriptMonitoring && (!control.IsDynamic || control.IsProxy))))
                {
                    PropertyInfo pi = control.GetType().GetProperty(key);

                    if (pi == null)
                    {
                        return;
                    }

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

                    if (attrs.Length > 0)
                    {
                        this.control.CallbackValues[key] = value;

                        if (value is Icon)
                        {
                            if (this.ResourceManager != null)
                            {
                                this.ResourceManager.RegisterIcon((Icon)value);
                            }
                            else
                            {
                                this.control.AddScript("Ext.net.ResourceMgr.registerIcon({0});", JSON.Serialize(value));
                            }
                        }

                        ((DirectEventUpdateAttribute)attrs[0]).RegisterScript(this.control, pi);
                    }
                    else
                    {
                        ConfigOptionAttribute attr = ClientConfig.GetClientConfigAttribute(pi);
                        if (attr != null)
                        {
                            this.control.CallbackValues[key] = value;
                            this.control.AddScript(string.Format(DirectEventUpdateAttribute.AutoGenerateFormat, this.control.ClientID, JSON.Serialize(value), pi.Name.ToLowerCamelCase()));
                        }
                    }
                }
            }
        }
Example #5
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)
                {
                    ConfigOptionAttribute 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);
            }
        }
Example #6
0
 public ConfigObject(PropertyInfo propertyInfo, ConfigOptionAttribute attr, object defValue)
 {
     this.propertyInfo = propertyInfo;
     this.attr         = attr;
     this.defaultValue = defValue;
 }
Example #7
0
        private void ToExtConfig(object obj, ConfigOption configOption)
        {
            if (configOption.Serialization.Mode != JsonMode.Ignore)
            {
                object originalValue = configOption.Value;
                object defaultValue  = configOption.DefaultValue;

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

                    string name = configOption.PropertyName.ToLowerCamelCase();

                    if (configOption.Serialization.Name.IsNotEmpty())
                    {
                        if (configOption.Serialization.Name.Contains(">"))
                        {
                            string[] parts = configOption.Serialization.Name.Split('>');
                            name = parts[0];
                            PropertyInfo          subProp = originalValue.GetType().GetProperty(parts[1]);
                            ConfigOptionAttribute subAttr = ClientConfig.GetClientConfigAttribute(subProp);

                            if (subAttr != null)
                            {
                                configOption.Serialization = this.ConfigOptionAttr2SerializationOptions(subAttr);
                                originalValue = subProp.GetValue(originalValue, null);
                            }
                        }
                        else
                        {
                            name = configOption.Serialization.Name;
                        }
                    }

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

                    StringBuilder temp = new StringBuilder(128);

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

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

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

                    case JsonMode.ObjectAllowEmpty:
                    case JsonMode.Object:
                        temp.Append(new ClientConfig().SerializeInternal(originalValue, this.owner));

                        if (!IsEmptyObject(temp.ToString()) || configOption.Serialization.Mode == JsonMode.ObjectAllowEmpty)
                        {
                            string type = this.GetInstanceOf(originalValue);

                            if (type.IsNotEmpty())
                            {
                                this.WriteRawValue(name, "new {0}({1})".FormatWith(type, 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 && configOption.Serialization.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("]");

                                string type = this.GetInstanceOf(originalValue);

                                if (type.IsNotEmpty())
                                {
                                    this.WriteRawValue(name, "new {0}({1})".FormatWith(type, 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);
                            }

                            ExtJsonConverter converter = (ExtJsonConverter)Activator.CreateInstance(configOption.Serialization.JsonConverter);
                            converter.Name         = name;
                            converter.PropertyName = configOption.PropertyName.ToTitleCase(CultureInfo.InvariantCulture);
                            converter.Owner        = obj;

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

                    case JsonMode.ToClientID:
                        Control control   = null;
                        string  controlID = "";
                        bool    rawID     = false;

                        if (originalValue is Control)
                        {
                            control = (Control)originalValue;
                        }
                        else
                        {
                            controlID = originalValue.ToString() ?? "";

                            if (controlID.StartsWith("{raw}"))
                            {
                                controlID = controlID.Substring(5);
                                rawID     = true;
                            }
                            else
                            {
                                control = ControlUtils.FindControl(this.owner, controlID, true);
                            }
                        }

                        if (control != null || rawID)
                        {
                            if (name.StartsWith("{raw}"))
                            {
                                name = name.Substring(5);
                                this.WriteValue(name, control != null ? control.ClientID : controlID);
                            }
                            else
                            {
                                this.WriteRawValue(name, control != null ? control.ClientID : controlID);
                            }
                        }
                        else
                        {
                            this.WriteRawValue(name, controlID);
                        }

                        break;

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

                    case JsonMode.Url:
                        string url = originalValue.ToString();

                        this.WriteValue(name, this.owner == null ? url : this.owner.ResolveClientUrl(url));
                        break;

                    case JsonMode.Value:
                    default:
                        this.WriteValue(name, originalValue);
                        break;
                    }
                }
            }
        }
Example #8
0
 public ListenerPropertyInfo(PropertyInfo propertyInfo, ConfigOptionAttribute attribute)
 {
     this.propertyInfo = propertyInfo;
     this.attribute = attribute;
 }
Example #9
0
 public ListenerTriplet(string name, ComponentListener listener, ConfigOptionAttribute attribute)
 {
     this.name = name;
     this.listener = listener;
     this.attribute = attribute;
 }
Example #10
0
 public DirectEventTriplet(string name, ComponentDirectEvent directEvent, ConfigOptionAttribute attribute, PropertyInfo propertyInfo)
 {
     this.name = name;
     this.directEvent = directEvent;
     this.attribute = attribute;
     this.propertyInfo = propertyInfo;
 }
Example #11
0
 public ListenerPropertyInfo(PropertyInfo propertyInfo, ConfigOptionAttribute attribute)
 {
     this.propertyInfo = propertyInfo;
     this.attribute    = attribute;
 }
Example #12
0
 public ListenerTriplet(string name, ComponentListener listener, ConfigOptionAttribute attribute)
 {
     this.name      = name;
     this.listener  = listener;
     this.attribute = attribute;
 }