Ejemplo n.º 1
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()));
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public string GetScript(XControl c, PropertyInfo property)
        {
            StringBuilder sb = new StringBuilder();

            if (!c.CallbackValues.ContainsKey(property.Name))
            {
                return(null);
            }

            object value = c.CallbackValues[property.Name];

            if (this.Script.IsNotEmpty())
            {
                sb.AppendFormat(this.Script, c.ClientID, JSON.Serialize(value));
            }
            else if (this.MethodName.IsNotEmpty())
            {
                MethodInfo method = c.GetType().GetMethod(this.MethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { property.PropertyType }, null);

                if (method != null)
                {
                    method.Invoke(c, new object[] { value });
                }
            }
            else //simple script generating
            {
                switch (this.GenerateMode)
                {
                case AutoGeneratingScript.Simple:
                    sb.AppendFormat(DirectEventUpdateAttribute.AutoGenerateFormat, c.ClientID, JSON.Serialize(value), property.Name.ToLowerCamelCase());
                    break;

                case AutoGeneratingScript.WithSet:
                    sb.AppendFormat("{0}.set{2}({1});", c.ClientID, JSON.Serialize(value), property.Name);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(sb.ToString());
        }
Ejemplo n.º 3
0
        public string GetScript(XControl c, PropertyInfo property)
        {
            StringBuilder sb = new StringBuilder();

            if (!c.CallbackValues.ContainsKey(property.Name))
            {
                return null;
            }

            object value = c.CallbackValues[property.Name];

            if (this.Script.IsNotEmpty())
            {
                sb.AppendFormat(this.Script, c.ClientID, JSON.Serialize(value));
            }
            else if (this.MethodName.IsNotEmpty())
            {
                MethodInfo method = c.GetType().GetMethod(this.MethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { property.PropertyType }, null);

                if (method != null)
                {
                    method.Invoke(c, new object[] { value });
                }
            }
            else //simple script generating
            {
                switch (this.GenerateMode)
                {
                    case AutoGeneratingScript.Simple:
                        sb.AppendFormat(DirectEventUpdateAttribute.AutoGenerateFormat, c.ClientID, JSON.Serialize(value), property.Name.ToLowerCamelCase());
                        break;
                    case AutoGeneratingScript.WithSet:
                        sb.AppendFormat("{0}.set{2}({1});", c.ClientID, JSON.Serialize(value), property.Name);
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }

            return sb.ToString();
        }