/// <summary>
 /// Default-ctor to build an empty validation rule with given name, description and delegate
 /// </summary>
 internal RDFOntologyValidationRule(String ruleName,
                                    String ruleDescription,
                                    RuleDelegate ruleDelegate) {
     this.RuleName        = ruleName;
     this.RuleDescription = ruleDescription;
     this.ExecuteRule     = ruleDelegate;
 }
Example #2
0
 public Rule(Parser parser, RuleType ruleType, Predicate <Parser> lookAhead, RuleDelegate evaluate)
 {
     _parser    = parser;
     _ruleType  = ruleType;
     _lookAhead = lookAhead;
     _evaluate  = evaluate;
 }
Example #3
0
 public static void FireEvent(RuleDelegate ruleEvent, object sender, RuleEventArgs args)
 {
     if (ruleEvent != null)
     {
         ruleEvent(sender, args);
     }
 }
Example #4
0
 public Rule(Parser parser, RuleType ruleType, Predicate<Parser> lookAhead, RuleDelegate evaluate)
 {
     _parser = parser;
     _ruleType = ruleType;
     _lookAhead = lookAhead;
     _evaluate = evaluate;
 }
Example #5
0
        /// <summary>
        /// We created a delegate to create a flexible behaviour
        /// </summary>
        public static void ScenarioOne()
        {
            RuleDelegate addDelegate      = (x, y) => x + y;
            RuleDelegate multipleDelegate = (x, y) => x * y;

            var newOperation = new Calculator();

            newOperation.Math(10, 10, multipleDelegate);
            newOperation.Math(10, 10, addDelegate);
        }
Example #6
0
 /// <summary>
 /// Creates new rule with parameters.
 /// </summary>
 /// <param name="templateName">String name of the template.</param>
 /// <param name="tag">String tag for which the rule will be applied to.</param>
 /// <param name="ruleDelegate">Rule delegate to be invoked to process the rule.</param>
 internal Rule(string templateName, string tag, RuleDelegate ruleDelegate)
 {
     this.TemplateName = templateName;
     this.Tag          = tag;
     this.RuleDelegate = ruleDelegate;
 }
Example #7
0
 public static Rule Delay(RuleDelegate r) { return new DelayRule(r); }
Example #8
0
        public void Math(int x, int y, RuleDelegate del)
        {
            var result = del(x, y);

            System.Console.WriteLine(result);
        }
Example #9
0
 public virtual object ApplyOnce(object t, RuleDelegate whichRule)
     {
     originalAdaptor.ClearChanged();
     
     if (t==null)
         return null;
     //
     Debug.Assert(this.BacktrackingLevel == 0);
     try {
         // Share TreeParser object but not parsing-related state
         //
         state = new RecognizerSharedState();
         input = new CommonTreeNodeStream(originalAdaptor, t);
         ((CommonTreeNodeStream)input).TokenStream = originalTokenStream;
         //
         this.BacktrackingLevel = 1;
         //
         Debug.Assert(!this.Failed());
         TreeRuleReturnScope r = whichRule((NadirAST)t);
         //
         return (r==null ? null : r.Tree);
         }
     catch (RecognitionException) 
         {
         }
     finally
         {
         this.BacktrackingLevel = 0;
         }
     return t;
     }
Example #10
0
 ///////////////////////////////////////////
 //
 // Visitation
 //
 ///////////////////////////////////////////
 
 public override object ApplyOnce(object t, RuleDelegate whichRule)
     {
     object tNew = base.ApplyOnce(t, whichRule);
     //
     if (this.Failed() || !this.originalAdaptor.IsChanged())
         {
         this.originalAdaptor.ClearChanged();
         return t;
         }
     //        
     if (showTransformations)
         {
         this.ReportTransformation(t, tNew);
         }
     //
     return tNew;
     }
Example #11
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="propertyName">The name of the property the rule is based on. This may be blank if the rule is not for any specific property.</param>
 /// <param name="brokenDescription">A description of the rule that will be shown if the rule is broken.</param>
 /// <param name="ruleDelegate"></param>
 public BusinessRule(string propertyName, string brokenDescription, RuleDelegate ruleDelegate)
 {
     this.Description  = brokenDescription;
     this.PropertyName = propertyName;
     this.RuleDelegate = ruleDelegate;
 }
Example #12
0
 public static void FireEvent(RuleDelegate ruleEvent, object sender)
 {
     FireEvent(ruleEvent, sender, new RuleEventArgs());
 }
 /// <summary>
 /// Constructs a <c>DelegatedRule</c> with the given name and that
 /// applies in the circumstances defines by its <c>Precondition</c>.
 /// </summary>
 /// <param name="precondition">A <c>Precondition</c> instance.</param>
 /// <param name="name">The unique name for the rule.</param>
 /// <param name="function">The <see cref="RuleDelegate"/> delegate function.</param>
 public DelegatedRule(Precondition precondition, string name, RuleDelegate function)
     : base(precondition, name)
 {
     this.function = function;
 }
 /// <summary>
 /// Constructs a <c>DelegatedRule</c> that applies to any document. 
 /// </summary>
 /// <param name="name">The unique name for the rule.</param>
 /// <param name="function">The <see cref="RuleDelegate"/> delegate function.</param>
 public DelegatedRule(string name, RuleDelegate function)
     : base(name)
 {
     this.function = function;
 }
Example #15
0
 public static Rule Delay(string name, RuleDelegate r)
 {
     return(new RecursiveRule(name, r));
 }
Example #16
0
 public RecursiveRule(string name, RuleDelegate deleg)
 {
     Debug.Assert(deleg != null);
     mName = name;
     mDeleg = deleg;
 }
Example #17
0
 public static void FireEvent(RuleDelegate ruleEvent, object sender)
 {
     FireEvent(ruleEvent, sender, new RuleEventArgs());
 }
 /// <summary>
 /// Constructs a <c>DelegatedRule</c> that applies to any document.
 /// </summary>
 /// <param name="name">The unique name for the rule.</param>
 /// <param name="function">The <see cref="RuleDelegate"/> delegate function.</param>
 public DelegatedRule(string name, RuleDelegate function)
     : base(name)
 {
     this.function = function;
 }
 /// <summary>
 /// Constructs a <c>DelegatedRule</c> with the given name and that
 /// applies in the circumstances defines by its <c>Precondition</c>.
 /// </summary>
 /// <param name="precondition">A <c>Precondition</c> instance.</param>
 /// <param name="name">The unique name for the rule.</param>
 /// <param name="function">The <see cref="RuleDelegate"/> delegate function.</param>
 public DelegatedRule(Precondition precondition, string name, RuleDelegate function)
     : base(precondition, name)
 {
     this.function = function;
 }
Example #20
0
 public DelayRule(RuleDelegate deleg)
 {
     Trace.Assert(deleg != null);
     mDeleg = deleg;
 }
Example #21
0
 public static Rule Delay(RuleDelegate r)
 {
     return(new DelayRule(r));
 }
Example #22
0
 public static Rule Delay(string name, RuleDelegate r) { return new RecursiveRule(name, r); }
Example #23
0
 public void AddRule(RuleDelegate rule)
 {
     this.Rules.Add(rule);
 }
Example #24
0
        /// <summary>
        /// Compute the automata for this cell
        /// </summary>
        /// <param name="ruleAppliesFor">The 'neighbor skipping rule' to apply</param>
        public void ComputeNextState(RuleDelegate ruleAppliesFor, bool randomize)
        {
            CellState nextState;

            for (int x = -1; x <= 1; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    // Skip the middle cell (self)
                    if (x == 0 && y == 0)
                        continue;

                    // Apply the skipping rule
                    if (ruleAppliesFor(x, y))
                        continue;

                    // Obtain this cell's neighbor at offset (x,y) from the grid
                    Cell neighbor = grid.GetNeighborFor(this, x, y);

                    // If any of the cell?s four ... neighbours has
                    // the next state on from the cell
                    nextState = state.nextState + (randomize? rand.Next(-1, 1) : 0);
                    if (nextState == neighbor.state)
                    { tempState = nextState; return; }
                }
            }

            // No rules were met; return the current state
            tempState = this.state;
        }
Example #25
0
 public virtual object ApplyRepeatedly(object t, RuleDelegate whichRule)
     {
     bool fChanged = true;
     while (fChanged && t != null)
         {
         t = ApplyOnce(t, whichRule);
         fChanged = this.originalAdaptor.IsChanged();
         }
     //
     return t;
     }
Example #26
0
 public DelayRule(RuleDelegate deleg)
 {
     Trace.Assert(deleg != null);
     mDeleg = deleg;
 }
Example #27
0
 /// <summary>
 /// Adds new replacement rule to the template set.
 /// </summary>
 /// <param name="templateSet">Template set</param>
 /// <typeparam name="T">Template set class. Should be inherited from <see cref="AbstractTemplateSet"/>.</typeparam>
 /// <param name="template">Expression that defines template inside the template set. For example: ts => ts.Page.</param>
 /// <param name="tag">String tag for which the rule will be applied to.</param>
 /// <param name="rule">Rule that will be executed on specified template. All occurencies of tag will be replaced by returning value of the rule.</param>
 public static void AddRule <T>(this T templateSet, Expression <Func <T, string> > template, string tag, RuleDelegate rule) where T : AbstractTemplateSet
 {
     templateSet.ReplacementRules.Add(new Rule(templateSet.GetTemplateName(template), tag, rule));
 }
Example #28
0
 public RecursiveRule(string name, RuleDelegate deleg)
 {
     Debug.Assert(deleg != null);
     mName  = name;
     mDeleg = deleg;
 }