コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public virtual string Build(UserControlRendrerConfig config)
        {
            string      id = config.UserControlId ?? BaseControl.GenerateID();
            UserControl uc = UserControlRenderer.LoadControl(config.UserControlPath, id);

#if NET40
            uc.ClientIDMode = config.UserControlClientIDMode;
#endif
            Page pageHolder = uc.Page;

            if (uc is IDynamicUserControl)
            {
                ((IDynamicUserControl)uc).BeforeRender();
            }

            BaseControl controlToRender = null;

            if (config.ControlIdToRender.IsEmpty() && !config.SingleControl)
            {
                Container ct = new Container {
                    ID = id + "_ct", IDMode = IDMode.Static
                };
                pageHolder.Controls.Add(ct);
                ct.ContentControls.Add(uc);
                controlToRender = ct;
            }
            else
            {
                pageHolder.Controls.Add(uc);
                BaseControl c;

                if (config.SingleControl)
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl <BaseControl>(uc);
                }
                else
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl <BaseControl>(pageHolder, config.ControlIdToRender);
                }

                if (c == null)
                {
                    if (config.SingleControl)
                    {
                        throw new Exception("Cannot find the Ext.Net control in the view");
                    }
                    else
                    {
                        throw new Exception("Cannot find the control with ID=" + config.ControlIdToRender);
                    }
                }

                controlToRender = c;

                if (!controlToRender.HasOwnIDMode)
                {
                    controlToRender.IDMode = IDMode.Static;
                }
            }

            config.OnBeforeRender(new ComponentAddedEventArgs(controlToRender));

            return(config.Index.HasValue ? controlToRender.ToScript(config.Mode, config.Element, config.Index.Value, true) : controlToRender.ToScript(config.Mode, config.Element, true));
        }
コード例 #2
0
        protected List <BaseControl> FindControls(Control seed, bool searchOnly, StringBuilder sb, List <Icon> icons, List <string> ns)
        {
            if (seed == null)
            {
                return(null);
            }

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

            if (ns == null)
            {
                ns = new List <string>();
            }

            ResourceManager manager = this.ResourceManager;

            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)
                {
                }
            }

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

                    this.RegisterControlResourcesInManager(manager, ctrl);
                }
            }

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

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

                bool isBaseControl = ReflectionUtils.IsTypeOf(control, typeof(BaseControl), false);

                if (!isBaseControl && (control.ID.IsEmpty() || BaseScriptBuilder.autoIDRegEx.IsMatch(control.ID)))
                {
                    control.ID = BaseControl.GenerateID();
                }

                if (isBaseControl && !(control is UserControlLoader))
                {
                    BaseControl ctrl = (BaseControl)control;
                    if (!searchOnly)
                    {
                        this.CheckIcon(ctrl, icons);
                        this.CheckResources(ctrl, manager);
                    }
                    foundControls.Add(ctrl);

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

                        this.RegisterControlResourcesInManager(manager, ctrl);
                    }
                }

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

            if (sb != null && !searchOnly)
            {
                this.RegisterNS(sb, ns);
            }

            return(foundControls);
        }
コード例 #3
0
        protected List <BaseControl> FindControls(Control seed, bool searchOnly, StringBuilder sb, List <Icon> icons, List <string> ns)
        {
            if (seed == null)
            {
                return(null);
            }

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

            if (ns == null)
            {
                ns = new List <string>();
            }

            ResourceManager manager = this.ResourceManager;

            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)
                {
                }
            }

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

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

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

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

                var isBaseControl = ReflectionUtils.IsTypeOf(control, typeof(BaseControl), false);

                if (!isBaseControl && (control.ID.IsEmpty() || BaseScriptBuilder.autoIDRegEx.IsMatch(control.ID)))
                {
                    control.ID = BaseControl.GenerateID();
                }

                if (isBaseControl && !(control is UserControlLoader))
                {
                    BaseControl ctrl = (BaseControl)control;
                    if (!searchOnly)
                    {
                        this.CheckIcon(ctrl, icons);
                        this.CheckResources(ctrl, manager);
                    }
                    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, ns));
                }
            }

            if (sb != null && !searchOnly)
            {
                /*if (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);
                 * }*/

                if (ns.Count > 0)
                {
                    sb.Append("Ext.ns(");

                    foreach (var n in ns)
                    {
                        sb.Append("\"").Append(n).Append("\",");
                    }

                    sb.Remove(sb.Length - 1, 1);
                    sb.Append(");");
                }
            }

            return(foundControls);
        }