public virtual string EvaluateExpressions(string redirectUrl, string redirectArgument, bool bEncrypt)
        {
            const string PREFIX_NO_ENCODE = "NoUrlEncode:";

            if ((_modifyRedirectUrlInProgress))
            {
                return(null);
            }
            else
            {
                _modifyRedirectUrlInProgress = true;
            }

            string finalRedirectUrl      = redirectUrl;
            string finalRedirectArgument = redirectArgument;

            if ((finalRedirectUrl == null || finalRedirectUrl.Length == 0))
            {
                return("");
            }
            else if ((finalRedirectUrl.IndexOf('{') < 0))
            {
                _modifyRedirectUrlInProgress = false;
                return(finalRedirectUrl);
            }
            else
            {
                if (redirectArgument != null && redirectArgument.Length > 0)
                {
                    string[] arguments = redirectArgument.Split(',');
                    for (int i = 0; i <= (arguments.Length - 1); i++)
                    {
                        finalRedirectUrl = finalRedirectUrl.Replace("{" + i.ToString() + "}", "{" + arguments[i] + "}");
                    }
                    finalRedirectArgument = "";
                }

                ArrayList controlList = GetAllRecordAndTableControls();
                if (controlList.Count == 0)
                {
                    return(finalRedirectUrl);
                }

                Hashtable controlIdList = new Hashtable();
                bool      found         = false;
                foreach (System.Web.UI.Control control in controlList)
                {
                    string uID = control.UniqueID;
                    int    pageContentIndex = uID.IndexOf("$PageContent$");
                    if (pageContentIndex > 0)
                    {
                        if (found == false)
                        {
                            //Remove all controls without $PageContent$ prefix, because this page is used with Master Page
                            //and these entries are irrelevant
                            controlIdList.Clear();
                        }
                        found = true;
                    }
                    if (found)
                    {
                        //If we found that Master Page is used for this page construction than disregard all controls
                        //without $PageContent$ prefix
                        if (pageContentIndex > 0)
                        {
                            uID = uID.Substring(pageContentIndex + "$PageContent$".Length);
                            controlIdList.Add(uID, control);
                        }
                    }
                    else
                    {
                        //No Master Page presense found so far
                        controlIdList.Add(uID, control);
                    }
                }
                ArrayList forwardTo    = new ArrayList();
                string    remainingUrl = finalRedirectUrl;
                while ((remainingUrl.IndexOf('{') >= 0) & (remainingUrl.IndexOf('}') > 0) & (remainingUrl.IndexOf('{') < remainingUrl.IndexOf('}')))
                {
                    int    leftIndex  = remainingUrl.IndexOf('{');
                    int    rightIndex = remainingUrl.IndexOf('}');
                    string expression = remainingUrl.Substring(leftIndex + 1, rightIndex - leftIndex - 1);
                    remainingUrl = remainingUrl.Substring(rightIndex + 1);
                    string prefix = null;
                    if ((expression.IndexOf(":") > 0))
                    {
                        prefix = expression.Substring(0, expression.IndexOf(":"));
                    }
                    if ((prefix != null) && (prefix.Length > 0) && (!((StringUtils.InvariantLCase(prefix) == StringUtils.InvariantLCase(PREFIX_NO_ENCODE)))) && (!(BaseRecord.IsKnownExpressionPrefix(prefix))))
                    {
                        if ((controlIdList.Contains(prefix)) & (!(forwardTo.Contains(prefix))))
                        {
                            forwardTo.Add(prefix);
                        }
                    }
                }

                foreach (string containerId in forwardTo)
                {
                    Control ctl = ((Control)(controlIdList[containerId]));
                    if (ctl != null)
                    {
                        if (ctl is BaseApplicationRecordControl)
                        {
                            finalRedirectUrl = ((BaseApplicationRecordControl)(ctl)).EvaluateExpressions(finalRedirectUrl, finalRedirectArgument, bEncrypt);
                        }
                        else if (ctl is BaseApplicationTableControl)
                        {
                            finalRedirectUrl = ((BaseApplicationTableControl)(ctl)).EvaluateExpressions(finalRedirectUrl, finalRedirectArgument, bEncrypt);
                        }
                    }
                }

                foreach (Control control in controlList)
                {
                    if ((forwardTo.IndexOf(control.ID) < 0))
                    {
                        if (control is BaseApplicationRecordControl)
                        {
                            finalRedirectUrl = ((BaseApplicationRecordControl)(control)).EvaluateExpressions(finalRedirectUrl, finalRedirectArgument, bEncrypt);
                        }
                        else if (control is BaseApplicationTableControl)
                        {
                            finalRedirectUrl = ((BaseApplicationTableControl)(control)).EvaluateExpressions(finalRedirectUrl, finalRedirectArgument, bEncrypt);
                        }
                    }
                }
            }
            _modifyRedirectUrlInProgress = false;
            return(finalRedirectUrl);
        }
Exemple #2
0
        public virtual string EvaluateExpressions(string redirectUrl, string redirectArgument, Object rec, bool bEncrypt)
        {
            const string PREFIX_NO_ENCODE      = "NoUrlEncode:";
            string       finalRedirectUrl      = redirectUrl;
            string       finalRedirectArgument = redirectArgument;

            if ((finalRedirectUrl == null || finalRedirectUrl.Length == 0))
            {
                return(finalRedirectUrl);
            }
            else if ((finalRedirectUrl.IndexOf('{') < 0))
            {
                return(finalRedirectUrl);
            }
            else
            {
                // The old way was to pass separate URL and arguments and use String.Format to
                // do the replacement.  Example:
                // URL:        EditProductsRecord?Products={0}
                // Argument:   PK
                // The new way to is pass the arguments directly in the URL.  Example:
                // URL:        EditProductsRecord?Products={PK}
                // If the old way is passsed, convert it to the new way.
                if (finalRedirectArgument != null && finalRedirectArgument.Length > 0)
                {
                    string[] arguments = finalRedirectArgument.Split(',');
                    for (int i = 0; i <= (arguments.Length - 1); i++)
                    {
                        finalRedirectUrl = finalRedirectUrl.Replace("{" + i.ToString() + "}", "{" + arguments[i] + "}");
                    }
                    finalRedirectArgument = "";
                }
                // Evaluate all of the expressions in the RedirectURL
                // Expressions can be of the form [ControlName:][NoUrlEncode:]Key[:Value]
                string remainingUrl = finalRedirectUrl;
                while ((remainingUrl.IndexOf('{') >= 0) & (remainingUrl.IndexOf('}') > 0) & (remainingUrl.IndexOf('{') < remainingUrl.IndexOf('}')))
                {
                    int    leftIndex      = remainingUrl.IndexOf('{');
                    int    rightIndex     = remainingUrl.IndexOf('}');
                    string expression     = remainingUrl.Substring(leftIndex + 1, rightIndex - leftIndex - 1);
                    string origExpression = expression;
                    remainingUrl = remainingUrl.Substring(rightIndex + 1);
                    bool   skip = false;
                    bool   returnEmptyStringOnFail = false;
                    string prefix = null;
                    // Check to see if this control must evaluate the expression
                    if ((expression.IndexOf(":") > 0))
                    {
                        prefix = expression.Substring(0, expression.IndexOf(":"));
                    }
                    if ((prefix != null) && (prefix.Length > 0) && (!((StringUtils.InvariantLCase(prefix) == StringUtils.InvariantLCase(PREFIX_NO_ENCODE)))) && (!(BaseRecord.IsKnownExpressionPrefix(prefix))))
                    {
                        // Remove the ASCX Prefix
                        string IdString = this.ID;
                        if (IdString.StartsWith("_"))
                        {
                            IdString = IdString.Remove(0, 1);
                        }
                        // The prefix is a control name.
                        if (prefix == IdString)
                        {
                            // This control is responsible for evaluating the expression,
                            // so if it can't be evaluated then return an empty string.
                            returnEmptyStringOnFail = true;
                            expression = expression.Substring(expression.IndexOf(":") + 1);
                        }
                        else
                        {
                            // It's not for this control to evaluate so skip.
                            skip = true;
                        }
                    }
                    if (!skip)
                    {
                        bool bUrlEncode = true;
                        if ((StringUtils.InvariantLCase(expression).StartsWith(StringUtils.InvariantLCase(PREFIX_NO_ENCODE))))
                        {
                            bUrlEncode = false;
                            expression = expression.Substring(PREFIX_NO_ENCODE.Length);
                        }
                        object result = null;
                        try
                        {
                            if (rec != null)
                            {
                                result = ((IRecord)rec).EvaluateExpression(expression);
                            }
                        }
                        catch (Exception)
                        {
                            //Fall through
                        }
                        if (result != null)
                        {
                            result = result.ToString();
                        }
                        if (result == null)
                        {
                            if (!returnEmptyStringOnFail)
                            {
                                return(finalRedirectUrl);
                            }
                            else
                            {
                                result = string.Empty;
                            }
                        }
                        if ((bUrlEncode))
                        {
                            result = System.Web.HttpUtility.UrlEncode(((string)(result)));
                            if (result == null)
                            {
                                result = string.Empty;
                            }
                        }
                        if (bEncrypt)
                        {
                            if (result != null)
                            {
                                result = ((BaseApplicationPage)(this.Page)).Encrypt((string)result);
                            }
                        }
                        finalRedirectUrl = finalRedirectUrl.Replace("{" + origExpression + "}", ((string)(result)));
                    }
                }
            }
            // If there are still expressions to evaluate. Forward to the page for further processing.
            return(finalRedirectUrl);
        }
        public virtual string EvaluateExpressions(string redirectUrl, string redirectArgument, bool bEncrypt)
        {
            const string PREFIX_NO_ENCODE = "NoUrlEncode:";

            if ((_modifyRedirectUrlInProgress))
            {
                return(null);
            }
            else
            {
                _modifyRedirectUrlInProgress = true;
            }
            string finalRedirectUrl      = redirectUrl;
            string finalRedirectArgument = redirectArgument;

            if ((finalRedirectUrl == null || finalRedirectUrl.Length == 0))
            {
                return("");
            }
            else if ((finalRedirectUrl.IndexOf('{') < 0))
            {
                _modifyRedirectUrlInProgress = false;
                return(finalRedirectUrl);
            }
            else
            {
                if (redirectArgument != null && redirectArgument.Length > 0)
                {
                    string[] arguments = redirectArgument.Split(',');
                    for (int i = 0; i <= (arguments.Length - 1); i++)
                    {
                        finalRedirectUrl = finalRedirectUrl.Replace("{" + i.ToString() + "}", "{" + arguments[i] + "}");
                    }
                    finalRedirectArgument = "";
                }

                ArrayList controlList = GetAllRecordAndTableControls();
                if (controlList.Count == 0)
                {
                    return(finalRedirectUrl);
                }

                Hashtable controlIdList = new Hashtable();
                foreach (Control control in controlList)
                {
                    controlIdList.Add(control.UniqueID, control);
                }

                ArrayList forwardTo    = new ArrayList();
                string    remainingUrl = finalRedirectUrl;
                while ((remainingUrl.IndexOf('{') >= 0) & (remainingUrl.IndexOf('}') > 0) & (remainingUrl.IndexOf('{') < remainingUrl.IndexOf('}')))
                {
                    int    leftIndex  = remainingUrl.IndexOf('{');
                    int    rightIndex = remainingUrl.IndexOf('}');
                    string expression = remainingUrl.Substring(leftIndex + 1, rightIndex - leftIndex - 1);

                    remainingUrl = remainingUrl.Substring(rightIndex + 1);
                    string prefix = null;
                    if ((expression.IndexOf(":") > 0))
                    {
                        prefix = expression.Substring(0, expression.IndexOf(":"));
                    }

                    if ((prefix != null) && (prefix.Length > 0) && (!((StringUtils.InvariantLCase(prefix) == StringUtils.InvariantLCase(PREFIX_NO_ENCODE)))) && (!(BaseRecord.IsKnownExpressionPrefix(prefix))))
                    {
                        if ((controlIdList.Contains(prefix)) & (!(forwardTo.Contains(prefix))))
                        {
                            forwardTo.Add(prefix);
                        }
                    }
                }

                foreach (string containerId in forwardTo)
                {
                    Control ctl = ((Control)(controlIdList[containerId]));
                    if (ctl != null)
                    {
                        if (ctl is BaseApplicationRecordControl)
                        {
                            finalRedirectUrl = ((BaseApplicationRecordControl)(ctl)).EvaluateExpressions(finalRedirectUrl, finalRedirectArgument, bEncrypt);
                        }
                        else if (ctl is BaseApplicationTableControl)
                        {
                            finalRedirectUrl = ((BaseApplicationTableControl)(ctl)).EvaluateExpressions(finalRedirectUrl, finalRedirectArgument, bEncrypt);
                        }
                    }
                }

                foreach (Control control in controlList)
                {
                    if ((forwardTo.IndexOf(control.ID) < 0))
                    {
                        if (control is BaseApplicationRecordControl)
                        {
                            finalRedirectUrl = ((BaseApplicationRecordControl)(control)).EvaluateExpressions(finalRedirectUrl, finalRedirectArgument, bEncrypt);
                        }
                        else if (control is BaseApplicationTableControl)
                        {
                            finalRedirectUrl = ((BaseApplicationTableControl)(control)).EvaluateExpressions(finalRedirectUrl, finalRedirectArgument, bEncrypt);
                        }
                    }
                }
            }
            _modifyRedirectUrlInProgress = false;
            return(finalRedirectUrl);
        }
Exemple #4
0
        public virtual bool AreAnyUrlParametersForMe(string url, string arg)
        {
            const string PREFIX_NO_ENCODE      = "NoUrlEncode:";
            string       finalRedirectUrl      = url;
            string       finalRedirectArgument = url;
            bool         skip = false;

            if (finalRedirectArgument != null && finalRedirectArgument.Length > 0)
            {
                string[] arguments = finalRedirectArgument.Split(',');
                for (int i = 0; i <= (arguments.Length - 1); i++)
                {
                    finalRedirectUrl = finalRedirectUrl.Replace("{" + i.ToString() + "}", "{" + arguments[i] + "}");
                }
                finalRedirectArgument = "";
            }
            // Evaluate all of the expressions in the RedirectURL
            // Expressions can be of the form [ControlName:][NoUrlEncode:]Key[:Value]
            string remainingUrl = finalRedirectUrl;

            while ((remainingUrl.IndexOf('{') > 0) & (remainingUrl.IndexOf('}') > 0) & (remainingUrl.IndexOf('{') < remainingUrl.IndexOf('}')))
            {
                int    leftIndex      = remainingUrl.IndexOf('{');
                int    rightIndex     = remainingUrl.IndexOf('}');
                string expression     = remainingUrl.Substring(leftIndex + 1, rightIndex - leftIndex - 1);
                string origExpression = expression;
                remainingUrl = remainingUrl.Substring(rightIndex + 1);
                string prefix = null;
                if (expression.IndexOf(":") > 0)
                {
                    prefix = expression.Substring(0, expression.IndexOf(":"));
                }
                if ((prefix != null) && (prefix.Length > 0) && (!((StringUtils.InvariantLCase(prefix) == StringUtils.InvariantLCase(PREFIX_NO_ENCODE)))) && (!(BaseRecord.IsKnownExpressionPrefix(prefix))))
                {
                    if (prefix == this.ID)
                    {
                        skip = false;
                        break;
                    }
                    else
                    {
                        skip = true;
                    }
                }
            }

            if (skip)
            {
                return(false);
            }

            return(true);
        }