Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Expression Control for TFS Work Items

, 5 Oct 2010 CPOL
Custom control for TFS Work Items that shows the result of calculating an expression based on the work item fields contents
ExpressionControlForTFSWI.zip
ExpressionControl_installer.zip
Custom Controls Setup.msi
setup.exe
ExpressionControl_Risk.zip
ExpressionControl_source.zip
Custom Controls Setup
Custom Controls Setup.vdproj
Release
Konamiman's TFS custom controls
bin
Debug
ExpressionControl
Release
ExpressionControl
ExpressionControl.wicc
ExpressionEvaluator
Domain
Function.cd
LogicalExpression.cd
Properties
Konamiman's TFS custom controls.csproj.user
Properties
Referenced Assemblies
Evaluant.Antlr.dll
using System;
using System.Collections;
using System.Text;
using Antlr.Runtime.Tree;
using Evaluant.Calculator.Domain;
using Antlr.Runtime;

namespace Evaluant.Calculator
{
    public class Expression
    {
        protected string expression;

        public Expression(string expression)
        {
            if (expression == null || expression == String.Empty)
                throw new 
                    ArgumentException("Expression can't be empty", "expression");

            this.expression = expression;
        }

        protected CommonTree Parse(string expression)
        {
            ECalcLexer lexer = new ECalcLexer(new ANTLRStringStream(expression));
            ECalcParser parser = new ECalcParser(new CommonTokenStream(lexer));

            try
            {
                RuleReturnScope rule = parser.expression();
                if (parser.HasError)
                {
                    throw new EvaluationException(parser.ErrorMessage + " " + parser.ErrorPosition);
                }

                return rule.Tree as CommonTree;
            }
            catch (EvaluationException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new EvaluationException(e.Message, e);
            }
        }

        public object Evaluate()
        {
            EvaluationVisitor visitor = new EvaluationVisitor();
            visitor.EvaluateFunction += EvaluateFunction;
            visitor.EvaluateParameter += EvaluateParameter;
            visitor.Parameters = parameters;

            LogicalExpression.Create(Parse(expression)).Accept(visitor);
            return visitor.Result;
        }

        public event EvaluateFunctionHandler EvaluateFunction;
        public event EvaluateParameterHandler EvaluateParameter;

        private Hashtable parameters = new Hashtable();

        public Hashtable Parameters
        {
            get { return parameters; }
            set { parameters = value; }
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

konamiman.MSX
Software Developer SunHotels
Spain Spain
Under the secret identity of a C# programmer, a freaky guy who loves MSX computers and japanese culture is hidden. Beware!
Follow on   Twitter   LinkedIn

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 6 Oct 2010
Article Copyright 2010 by konamiman.MSX
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid