~john-park-west/concordion-net/builderconfig

« back to all changes in this revision

Viewing changes to Concordion_Config.Spec/Command/BannedWordCommand.cs

  • Committer: john.park.west@gmail.com
  • Date: 2010-09-26 23:31:49 UTC
  • Revision ID: john.park.west@gmail.com-20100926233149-3fjcuij7pmstux5d
Updates to allow user commands via new config "Builder" in Concordion.config and implemention of BaseInputDirectory

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.Collections.Generic;
 
3
using System.Linq;
 
4
using System.Text;
 
5
using Concordion.Internal.Commands;
 
6
using Concordion.Api;
 
7
using Concordion.Internal;
 
8
using Concordion.Internal.Util;
 
9
using System.Data;
 
10
using System.Text.RegularExpressions;
 
11
using System.Reflection;
 
12
 
 
13
namespace Concordion_Config.Spec.Command
 
14
{
 
15
    public class BannedWordCommand : AbstractCommand
 
16
    {
 
17
        public override void Execute(CommandCall commandCall, IEvaluator evaluator, IResultRecorder resultRecorder) 
 
18
        {
 
19
            String commandName = GetType().Name;
 
20
            Check.IsFalse(commandCall.HasChildCommands, "Nesting commands inside a '" + commandName + "' is not supported");
 
21
            var evalString=commandCall.Expression;
 
22
            Element element = commandCall.Element;
 
23
            Check.NotNull(evalString, "The " + commandName + " attribute must be set for an element containing " + commandName);
 
24
       
 
25
            object fixture = evaluator.Fixture;
 
26
            MethodInfo theMethod = fixture.GetType().GetMethod(evalString, new Type[] { typeof(string) });
 
27
            if (theMethod == null)
 
28
            {
 
29
                throw new Exception("Fixture: " + fixture.GetType().FullName + " does not contain method named [" + evalString + "(string)]");
 
30
            }
 
31
            object result=theMethod.Invoke(fixture,new object[]{element.Text});
 
32
            if (result == null)
 
33
            {
 
34
                element.AddStyleClass("success");
 
35
                resultRecorder.Record(Result.Success);
 
36
                return;
 
37
            }
 
38
            String bannedWord = result as String;
 
39
            if (bannedWord == null)
 
40
            {
 
41
                throw new Exception("Method method named [" + evalString + "(string)] in " + fixture.GetType().FullName + " did not return string");
 
42
            }
 
43
            else
 
44
            {
 
45
                element.AddStyleClass("failure");
 
46
                resultRecorder.Record(Result.Failure);
 
47
                Element span=new Element("span");
 
48
                span.AddStyleClass("commentary");
 
49
                span.AppendText("Banned word ["+bannedWord+"] used");
 
50
                element.AppendChild(span);
 
51
            }
 
52
       
 
53
        }
 
54
 
 
55
        public override void Setup(CommandCall commandCall, IEvaluator evaluator, IResultRecorder resultRecorder) { }
 
56
        public  override void Verify(CommandCall commandCall, IEvaluator evaluator, IResultRecorder resultRecorder) { }
 
57
    }
 
58
}