A simple, custom Debug Expression Console

Date: 20.09.2013

We've been asked by a customer if MatchPoint allows the manual execution of expressions under a specific user context. This can be a big help while developing, debugging or testing MatchPoint solutions. As MatchPoint's Expression Console (ctrl + e) is only accessible if it is enabled in the MatchPointConfiguration as well as if the current user is site collection administrator, there is no out of the box way to do this.

With a couple of lines of C# and JS code placed in a MatchPoint User Control, this functionality can easily be implemented.

Try it

To try this out you can follow below steps:

  1. Copy below code to a new User Control Configuration (leave the imports as they are as they are dependent of the current MatchPoint version)
  2. Name the configuration "DebugConsole.xml"
  3. Go to the edit mode of the page on which you would like to place this control
  4. Add a new User Control Web Part in which you set the UserControlExpression property to DebugConsole
  5. Save and reload the page. You should now be able to enter your expression which is evaluated on type.

Please note that this is a security risk when made available to end users, regardless if you are in a test or in a production environment. It is however, an example on how to easily build a small "helper", with only a couple of lines of code.

Just for your info: To disable the evaluation of Expressions being called via $$.Eval() and $$.Invoke(), you can set the DisableClientSideExpressions flag in MatchPoint Configuration.

Code

<script runat="server" language="C#">
    public string EvaluateExpression(string expression)
    {
        try
        {
            ExpressionString e = expression;
            return e.EvaluateToString(null);
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
    }
</script>

<script type="text/javascript">
    $(document).ready(function ()
    {
        var input = $("#DebugExpression");
        input.on('keyup', function ()
        {
            $$.Invoke("DebugConsole.EvaluateExpression",
                      input.val(), function (ret)
            {
                $('#ExpressionResult').text(ret.Value);
            });
        });
    });
</script>

<input id="DebugExpression" type="text" size="70" /><br />
<span id="ExpressionResult"></span>

results matching ""

    No results matching ""