private static MacroExpr GetMacroExpr(string originalExpression, string processedExpression)
    {
        var macroExpr = new MacroExpr();

        try
        {
            // Handle security
            macroExpr.Expression     = MacroSecurityProcessor.RemoveMacroSecurityParams(originalExpression, out macroExpr.SignedBy);
            macroExpr.SignatureValid = MacroSecurityProcessor.CheckMacroIntegrity(originalExpression, macroExpr.SignedBy);

            // Parse rule text
            macroExpr.RuleText   = MacroRuleTree.GetRuleText(macroExpr.Expression, true, true);
            macroExpr.Expression = MacroRuleTree.GetRuleCondition(macroExpr.Expression, true);

            // Macro expression does not support anonymous signature, remove the flag
            if (processedExpression.EndsWith("@", StringComparison.Ordinal))
            {
                processedExpression = processedExpression.Substring(0, processedExpression.Length - 1);
            }

            // Check syntax
            MacroExpression.ParseExpression(processedExpression);
        }
        catch (Exception ex)
        {
            macroExpr.Error        = true;
            macroExpr.ErrorMessage = ex.Message + "\r\n\r\n" + ex.StackTrace;
        }
        return(macroExpr);
    }
Exemplo n.º 2
0
    private void RefreshText()
    {
        string hdnValueTrim = hdnValue.Value.Trim();

        if (hdnValueTrim.StartsWithCSafe("rule(", true))
        {
            // Empty rule designer condition is not considered as rule conditions
            if (hdnValueTrim.EqualsCSafe("Rule(\"\", \"<rules></rules>\")", true))
            {
                hdnValue.Value = "";
            }
            else
            {
                try
                {
                    string ruleText = MacroRuleTree.GetRuleText(hdnValueTrim, true, true, TimeZoneTransformation);

                    // Display rule text
                    ltlMacro.Text    = ruleText;
                    txtMacro.Visible = false;
                    pnlRule.Visible  = true;

                    pnlUpdate.Update();

                    return;
                }
                catch
                {
                    // If failed to parse the rule, extract the condition
                    MacroExpression xml = MacroExpression.ExtractParameter(hdnValueTrim, "rule", 0);
                    if (xml != null)
                    {
                        string user;
                        hdnValue.Value = MacroSecurityProcessor.RemoveMacroSecurityParams(ValidationHelper.GetString(xml.Value, ""), out user);
                    }
                }
            }
        }


        if (string.IsNullOrEmpty(hdnValue.Value) && !string.IsNullOrEmpty(DefaultConditionText))
        {
            ltlMacro.Text    = DefaultConditionText;
            txtMacro.Text    = "";
            txtMacro.Visible = false;
            pnlRule.Visible  = true;
        }
        else
        {
            txtMacro.Text    = hdnValue.Value;
            hdnValue.Value   = null;
            txtMacro.Visible = true;
            pnlRule.Visible  = false;
        }

        pnlUpdate.Update();
    }
Exemplo n.º 3
0
    /// <summary>
    /// Gets the macro expression from the given object
    /// </summary>
    /// <param name="expression">Expression</param>
    private static MacroExpr GetMacroExpr(string expression)
    {
        var macroExpr = new MacroExpr();

        try
        {
            // Handle security
            macroExpr.Expression     = MacroSecurityProcessor.RemoveMacroSecurityParams(expression, out macroExpr.SignedBy);
            macroExpr.SignatureValid = MacroSecurityProcessor.CheckMacroIntegrity(expression, macroExpr.SignedBy);

            // Parse rule text
            macroExpr.RuleText   = MacroRuleTree.GetRuleText(macroExpr.Expression, true, true);
            macroExpr.Expression = MacroRuleTree.GetRuleCondition(macroExpr.Expression, true);
        }
        catch (Exception ex)
        {
            macroExpr.Error        = true;
            macroExpr.ErrorMessage = ex.Message + "\r\n\r\n" + ex.StackTrace;
        }
        return(macroExpr);
    }
    /// <summary>
    /// Extracts the condition from Rule method.
    /// </summary>
    public string ConditionFromExpression(string expression)
    {
        MacroExpression xml = null;

        try
        {
            xml = MacroExpression.ExtractParameter(expression, "rule", 1);
        }
        catch
        {
        }

        MacroIdentityOption identityOption;

        if (xml == null)
        {
            return(MacroSecurityProcessor.RemoveMacroSecurityParams(expression, out identityOption));
        }

        // Returns first parameter of the expression
        return(MacroSecurityProcessor.RemoveMacroSecurityParams(ValidationHelper.GetString(xml.Value, ""), out identityOption));
    }