示例#1
0
    private void applyOverride(Control c, msPortalControlPropertyOverride o)
    {
        if (c == null)
        {
            return;
        }

        var pi = c.GetType().GetProperty(o.PropertyName);

        if (pi == null)
        {
            return;
        }

        try
        {
            object val = o.Value;
            if (pi.PropertyType == typeof(bool))  // try to cast
            {
                val = Convert.ToBoolean(o.Value);
            }

            if (pi.PropertyType == typeof(int))
            {
                val = Convert.ToInt32(o.Value);
            }

            if (pi.PropertyType == typeof(long))
            {
                val = Convert.ToInt64(o.Value);
            }

            if (pi.PropertyType == typeof(Unit))
            {
                val = Unit.Parse(o.Value);
            }

            if (pi.PropertyType.IsEnum)
            {
                val = Enum.Parse(pi.PropertyType, o.Value);
            }

            pi.SetValue(c, val, null);
        }
        catch
        {
        }
    }
示例#2
0
    private void _populateEligibleControls(List <string> allControls, List <msPortalControlPropertyOverride> eligibleControls)
    {
        _populateEligibleControls(allControls, eligibleControls, this.Page);

        // now, populate the title
        LiteralControl lc = null;
        bool           doNotAddControl = false;

        var pageTitleContent = PageTitle;

        // Check if the PageTitle content is wrapping another PageTitle (happens for the DataPage Master Page)
        var childControl = PageTitle.FindControl("PageTitle") as ContentPlaceHolder;

        if (childControl != null)
        {
            pageTitleContent = childControl;
        }

        foreach (var c in pageTitleContent.Controls)
        {
            if (c is LiteralControl && lc == null)
            {
                lc = (LiteralControl)c;
            }

            if (c is Literal) // there's already a literal
            {
                doNotAddControl = true;
            }
        }

        if (lc != null && !doNotAddControl)
        {
            var ppo = new msPortalControlPropertyOverride
            {
                PageName     = Request.Url.LocalPath,
                ControlName  = "__PageTitle",
                PropertyName = "Text",
                Value        = lc.Text
            };
            ppo["Type"] = typeof(LiteralControl).Name;

            eligibleControls.Add(ppo);
        }

        OnAddCustomOverrideEligibleControlsEvent(eligibleControls);
    }
示例#3
0
    /// <summary>
    /// Recursively populates the eligible controls.
    /// </summary>
    /// <param name="allControls"></param>
    /// <param name="eligibleControls">The eligible controls.</param>
    /// <param name="controlToStart">The control to start.</param>
    private void _populateEligibleControls(List <string> allControls, List <msPortalControlPropertyOverride> eligibleControls, Control controlToStart)
    {
        /* We won't bother for performance reasons
         * if (eligibleControls == null) throw new ArgumentNullException("eligibleControls");
         * if (controlToStart == null) throw new ArgumentNullException("controlToStart");
         * */

        foreach (Control c in controlToStart.Controls)
        {
            if (_isOverrideable(c))     // only override named controls
            {
                var piText = c.GetType().GetProperty("Text");

                if (piText != null)
                {
                    var ppo = new msPortalControlPropertyOverride
                    {
                        PageName     = Request.Url.LocalPath,
                        ControlName  = c.ID,
                        PropertyName = "Text",
                        Value        = Convert.ToString(piText.GetValue(c, null))
                    };
                    ppo["Type"] = c.GetType().Name;

                    eligibleControls.Add(ppo);
                }
            }

            if (!string.IsNullOrWhiteSpace(c.ID))
            {
                allControls.Add(c.ID);
            }

            if (_shouldDrillDownOn(c))
            {
                _populateEligibleControls(allControls, eligibleControls, c);
            }
        }

        return;
    }