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);
    }
示例#2
0
    protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        SourcePointTypeEnum sourcePointType = SourcePointTypeEnum.Standard;
        GridViewRow         container       = null;

        switch (sourceName.ToLowerCSafe())
        {
        case "label":
            return(ResHelper.LocalizeString(HTMLHelper.HTMLEncode(ValidationHelper.GetString(parameter, String.Empty))));

        case "condition":
            string condition = MacroRuleTree.GetRuleText(ValidationHelper.GetString(parameter, String.Empty));
            return(GetDecoratedCondition(condition));

        case "allowaction":
            // Default case can't be moved or deleted. Same goes for condition step type case
            container       = (GridViewRow)parameter;
            sourcePointType = (SourcePointTypeEnum)ValidationHelper.GetInteger(DataHelper.GetDataRowViewValue((DataRowView)container.DataItem, "Type"), 0);
            if ((sourcePointType != SourcePointTypeEnum.SwitchCase) || (CurrentStepInfo.StepType == WorkflowStepTypeEnum.Condition))
            {
                ((Control)sender).Visible = false;
            }
            break;
        }
        return(parameter);
    }
    protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "condition":
            return(MacroRuleTree.GetRuleText(ValidationHelper.GetString(parameter, String.Empty)));

        case "type":
            DataRowView row = parameter as DataRowView;
            if (row != null)
            {
                ObjectWorkflowTriggerInfo trigger = new ObjectWorkflowTriggerInfo(row.Row);
                if (!string.IsNullOrEmpty(trigger.TriggerTargetObjectType))
                {
                    return(GetTriggerDescription(trigger));
                }
                else
                {
                    return(AutomationHelper.GetTriggerName(trigger.TriggerType, trigger.TriggerObjectType));
                }
            }
            return(parameter);

        case "delete":
            if (!WorkflowStepInfoProvider.CanUserManageAutomationProcesses(CurrentUser, CurrentSiteName))
            {
                CMSGridActionButton btn = (CMSGridActionButton)sender;
                btn.Enabled = false;
            }
            return(parameter);

        default:
            return(parameter);
        }
    }
    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();
    }
示例#5
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
            {
                bool   failToParseXml = false;
                string ruleText       = MacroRuleTree.GetRuleText(hdnValueTrim, true, out failToParseXml);
                if (failToParseXml)
                {
                    // If failed to parse the rule, extract the condition
                    MacroExpression xml = MacroExpression.ExtractParameter(hdnValueTrim, "rule", 0);
                    if (xml != null)
                    {
                        string user = null;
                        hdnValue.Value = MacroResolver.RemoveMacroSecurityParams(ValidationHelper.GetString(xml.Value, ""), out user);
                    }
                }
                else
                {
                    // Display rule text
                    ltlMacro.Text    = ruleText;
                    txtMacro.Visible = false;
                    pnlRule.Visible  = true;
                    return;
                }
            }
        }

        txtMacro.Text    = hdnValue.Value;
        hdnValue.Value   = null;
        txtMacro.Visible = true;
        pnlRule.Visible  = false;

        pnlUpdate.Update();
    }
示例#6
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);
    }