Esempio n. 1
0
        public string Serialize(object obj, bool ignoreCustomSerialization)
        {
            if (this.owner == null)
            {
                if (obj is Control)
                {
                    this.owner = ((Control)obj);

                    if (obj is Observable)
                    {
                        foreach (ConfigItem item in ((Observable)obj).CustomConfig)
                        {
                            this.exclude.Add(item.Name);
                        }
                    }
                }
                else if (obj is StateManagedItem)
                {
                    this.owner = ((StateManagedItem)obj).Owner;
                }
            }

            if (obj is ICustomConfigSerialization && !ignoreCustomSerialization)
            {
                return((obj as ICustomConfigSerialization).ToScript(owner));
            }

            this.sb     = new StringBuilder();
            this.sw     = new StringWriter(sb);
            this.writer = new JsonTextWriter(sw);

            // PG Change - this makes the JSON to standards
            this.writer.QuoteName = true;

            if (this.owner is XControl)
            {
                XControl wc = (XControl)this.owner;

                if (wc != null)
                {
                    ResourceManager sm = null;

                    sm = wc.SafeResourceManager;

                    if (sm != null && sm.SourceFormatting)
                    {
                        this.writer.Formatting = Formatting.Indented;
                    }
                }
            }

            this.writer.WriteStartObject();

            this.Process(obj);

            this.writer.WriteEndObject();
            this.writer.Flush();

            return(sw.GetStringBuilder().ToString());
        }
Esempio n. 2
0
        void DataBindPoint(object sender, EventArgs e)
        {
            XControl owner = this.Owner as XControl;

            if (this.AutoDataBind || (owner != null && owner.AutoDataBind))
            {
                this.DataBind();
            }
        }
Esempio n. 3
0
        protected BaseScriptBuilder(XControl control)
        {
            this.control = control;

            if (!this.control.HasOwnIDMode || this.control.IDMode == IDMode.Inherit)
            {
                this.control.IDMode = IDMode.Client;
            }
        }
Esempio n. 4
0
        protected BaseScriptBuilder(XControl control)
        {
            this.control = control;

            if (!this.control.HasOwnIDMode || this.control.IDMode == IDMode.Inherit)
            {
                this.control.IDMode = IDMode.Client;    
            }
        }
Esempio n. 5
0
        public void EnsureDataBind()
        {
            XControl owner = this.Owner as XControl;

            if (!this.dataBindRegistered && (this.AutoDataBind || (owner != null && owner.AutoDataBind)))
            {
                this.dataBindRegistered = true;
                this.DataBind();
            }
        }
Esempio n. 6
0
 protected virtual void CheckIcon(XControl control, List <Icon> icons)
 {
     if (control is IIcon)
     {
         List <Icon> cIcons = ((IIcon)control).Icons;
         foreach (Icon icon in cIcons)
         {
             if (!icons.Contains(icon) && icon != Icon.None)
             {
                 icons.Add(icon);
             }
         }
     }
 }
Esempio n. 7
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());
        }
Esempio n. 8
0
        protected ContentScriptBuilder(XControl control) : base(control)
        {
            items = new List<object>(0);
            if (control is IItems)
            {
                items = ((IItems) control).ItemsList;

                if (items.Count == 1 && items[0] is Layout)
                {
                    layoutItems = ((Layout) items[0]).Items;
                }
                else
                {
                    layoutItems = items;
                }
            }

            if (control is IContent)
            {
                contentContainer = ((IContent) control).ContentContainer;
            }
        }
Esempio n. 9
0
        protected ContentScriptBuilder(XControl control) : base(control)
        {
            items = new List <object>(0);
            if (control is IItems)
            {
                items = ((IItems)control).ItemsList;

                if (items.Count == 1 && items[0] is Layout)
                {
                    layoutItems = ((Layout)items[0]).Items;
                }
                else
                {
                    layoutItems = items;
                }
            }

            if (control is IContent)
            {
                contentContainer = ((IContent)control).ContentContainer;
            }
        }
Esempio n. 10
0
        protected virtual void CheckResources(XControl control)
        {
            if (HttpContext.Current.CurrentHandler is Page && !(HttpContext.Current.CurrentHandler is ISelfRenderingPage) && !this.ForceResources)
            {
                return;
            }

            foreach (ClientScriptItem item in control.GetScripts())
            {
                if (!scriptsResources.ContainsKey(item.PathEmbedded))
                {
                    scriptsResources.Add(item.PathEmbedded, GetWebResourceUrl(item.Type, item.PathEmbedded));
                }
            }

            foreach (ClientStyleItem item in control.GetStyles())
            {
                if (!stylesResources.ContainsKey(item.PathEmbedded) && item.Theme.Equals(Theme.Default))
                {
                    stylesResources.Add(item.PathEmbedded, GetWebResourceUrl(item.Type, item.PathEmbedded));
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userControlPath"></param>
        /// <param name="controlIdToRender"></param>
        /// <param name="mode"></param>
        /// <param name="element"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public virtual string Build(string userControlPath, string controlIdToRender, RenderMode mode, string element, int?index)
        {
            string      id         = "ID_" + Guid.NewGuid().ToString().Replace("-", "");
            UserControl uc         = UserControlRenderer.LoadControl(userControlPath, id);
            Page        pageHolder = uc.Page;

            XControl controlToRender = null;

            if (controlIdToRender.IsEmpty())
            {
                Container ct = new Container {
                    ID = id, IDMode = IDMode.Explicit
                };
                pageHolder.Controls.Add(ct);
                ct.ContentControls.Add(uc);
                controlToRender = ct;
            }
            else
            {
                pageHolder.Controls.Add(uc);
                XControl c = Ext.Net.Utilities.ControlUtils.FindControl <XControl>(pageHolder, controlIdToRender);
                if (c == null)
                {
                    throw new Exception("Cannot find the control with ID=" + controlIdToRender);
                }

                controlToRender = c;

                if (controlToRender.IDMode == IDMode.Inherit)
                {
                    controlToRender.IDMode = IDMode.Explicit;
                }
            }

            return(index.HasValue ? controlToRender.ToScript(mode, element, index.Value, true) : controlToRender.ToScript(mode, element, true));
        }
Esempio n. 12
0
 public Menu GetParentMenu(XControl control)
 {
     return((Menu)ReflectionUtils.GetTypeOfParent(this, typeof(Menu)));
 }
Esempio n. 13
0
 internal ListItem(XControl parent)
 {
     this.parent = parent;
 }
Esempio n. 14
0
 public void RegisterScript(XControl c, PropertyInfo property)
 {
     c.AddScript(this.GetScript(c, property));
 }
Esempio n. 15
0
 protected override void CheckResources(XControl control)
 {
 }
Esempio n. 16
0
 public Menu GetParentMenu(XControl control)
 {
     return (Menu)ReflectionUtils.GetTypeOfParent(this, typeof(Menu));
 }
Esempio n. 17
0
 protected DefaultScriptBuilder(XControl control) : base(control)
 {
 }
Esempio n. 18
0
 public static DefaultScriptBuilder Create(XControl control)
 {
     return(new DefaultScriptBuilder(control));
 }
Esempio n. 19
0
 /// <summary>
 ///
 /// </summary>
 public virtual Spotlight.Builder Show(XControl control)
 {
     this.ToComponent().Show(control);
     return(this);
 }
Esempio n. 20
0
 /// <summary>
 ///
 /// </summary>
 public SimpleStore(XControl control, ListItemCollection <T> items)
 {
     this.control = control;
     this.items   = items;
 }
Esempio n. 21
0
 public ConfigScriptBuilder(XControl control) : base(control) { }
Esempio n. 22
0
 public static DefaultScriptBuilder Create(XControl control)
 {
     return new DefaultScriptBuilder(control);
 }
Esempio n. 23
0
 protected override void CheckIcon(XControl control, List<Icon> icons)
 {
 }
Esempio n. 24
0
 protected DefaultScriptBuilder(XControl control) : base(control) { }
Esempio n. 25
0
        protected List <XControl> FindControls(Control seed, bool searchOnly, StringBuilder sb, List <Icon> icons)
        {
            if (seed == null)
            {
                return(null);
            }

            ResourceManager manager = ResourceManager.GetInstance(HttpContext.Current);

            if (icons == null)
            {
                icons = new List <Icon>();
            }

            if (sb != null && !searchOnly && manager != null)
            {
                try
                {
                    List <UserControl> userControls = ControlUtils.FindControls <UserControl>(this.Control);

                    foreach (UserControl userControl in userControls)
                    {
                        manager.AddDirectMethodControl(userControl, true);
                    }

                    string proxies = manager.BuildDirectMethodProxies(true);

                    foreach (UserControl userControl in userControls)
                    {
                        manager.RemoveDirectMethodControl(userControl, true);
                    }

                    if (!string.IsNullOrEmpty(proxies))
                    {
                        sb.Append(proxies);
                    }
                }
                catch (Exception e)
                {
                }
            }

            if (ReflectionUtils.IsTypeOf(seed, typeof(XControl), false))
            {
                XControl ctrl = (XControl)seed;
                if (!searchOnly)
                {
                    this.CheckIcon(ctrl, icons);
                    this.CheckResources(ctrl);
                }
                ctrl.IsDynamic = true;
                ctrl.EnsureChildControlsInternal();
                if (!searchOnly)
                {
                    ctrl.CallOnPreRender();

                    ctrl.RegisterStyles(manager);
                    ctrl.RegisterScripts(manager);
                }
            }

            List <XControl> foundControls = new List <XControl>();

            foreach (Control control in seed.Controls)
            {
                if (this.ExcludeControl(seed, control))
                {
                    continue;
                }

                if (ReflectionUtils.IsTypeOf(control, typeof(XControl), false))
                {
                    XControl ctrl = (XControl)control;
                    if (!searchOnly)
                    {
                        this.CheckIcon(ctrl, icons);
                        this.CheckResources(ctrl);
                    }
                    foundControls.Add(ctrl);

                    ctrl.IsDynamic = true;
                    ctrl.EnsureChildControlsInternal();
                    if (!searchOnly)
                    {
                        ctrl.CallOnPreRender();

                        ctrl.RegisterStyles(manager);
                        ctrl.RegisterScripts(manager);
                    }
                }

                if (ControlUtils.HasControls(control))
                {
                    foundControls.AddRange(this.FindControls(control, searchOnly, null, icons));
                }
            }

            if (sb != null && !searchOnly && icons.Count > 0)
            {
                string[] arr = new string[icons.Count];
                for (int i = 0; i < icons.Count; i++)
                {
                    arr[i] = icons[i].ToString();
                }
                sb.Append("Ext.net.ResourceMgr.registerIcon(");
                sb.Append(JSON.Serialize(arr));
                sb.Append(");");
                sb.Append(script);
            }

            return(foundControls);
        }
Esempio n. 26
0
 protected override void CheckResources(XControl control)
 {
 }
Esempio n. 27
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();
        }
Esempio n. 28
0
 protected virtual void CheckIcon(XControl control, List<Icon> icons)
 {
     if (control is IIcon)
     {
         List<Icon> cIcons = ((IIcon)control).Icons;
         foreach (Icon icon in cIcons)
         {
             if (!icons.Contains(icon) && icon != Icon.None)
             {
                 icons.Add(icon);
             }
         }
     }
 }
Esempio n. 29
0
 public static ContentScriptBuilder Create(XControl control)
 {
     return new ContentScriptBuilder(control);
 }
Esempio n. 30
0
 public void RegisterScript(XControl c, PropertyInfo property)
 {
     c.AddScript(this.GetScript(c, property));
 }
Esempio n. 31
0
 public virtual void Show(XControl control)
 {
     this.Call("show", new JRawValue(control.ClientID));
 }
Esempio n. 32
0
 public ConfigScriptBuilder(XControl control) : base(control)
 {
 }
Esempio n. 33
0
 public ViewStateProxy(XControl control, StateBag viewState)
 {
     this.control   = control;
     this.ViewState = viewState;
 }
Esempio n. 34
0
 public virtual void Show(XControl control)
 {
     this.Call("show", new JRawValue(control.ClientID));
 }
Esempio n. 35
0
 protected override void CheckIcon(XControl control, List <Icon> icons)
 {
 }
Esempio n. 36
0
        protected virtual void CheckResources(XControl control)
        {
            if (HttpContext.Current.CurrentHandler is Page && !(HttpContext.Current.CurrentHandler is ISelfRenderingPage) && !this.ForceResources)
            {
                return;
            }

            foreach (ClientScriptItem item in control.GetScripts())
            {
                if (!scriptsResources.ContainsKey(item.PathEmbedded))
                {
                    scriptsResources.Add(item.PathEmbedded, GetWebResourceUrl(item.Type, item.PathEmbedded));
                }
            }

            foreach (ClientStyleItem item in control.GetStyles())
            {
                if (!stylesResources.ContainsKey(item.PathEmbedded) && item.Theme.Equals(Theme.Default))
                {
                    stylesResources.Add(item.PathEmbedded, GetWebResourceUrl(item.Type, item.PathEmbedded));
                }
            }
        }
Esempio n. 37
0
 public ViewStateProxy(XControl control, StateBag viewState)
 {
     this.control = control;
     this.ViewState = viewState;
 }
Esempio n. 38
0
 public static ConfigScriptBuilder Create(XControl control)
 {
     return(new ConfigScriptBuilder(control));
 }