Exemple #1
0
 /// <summary>
 /// returns a rule rule from the repository or creates a new one and returns this
 /// </summary>
 /// <param name="handle"></param>
 /// <returns></returns>
 public SelectionRule GetSelectionRule(string id = null)
 {
     if (_repository .HasSelectionRule (id)) return _repository .GetSelectionRule (id);
     SelectionRule aRule = new SelectionRule(id);
     _repository.AddSelectionRule(aRule.ID, aRule);
     return aRule;
 }
Exemple #2
0
        /// <summary>
        /// builds the XPT node of this
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public bool BuildXPTNode(SelectionRulezContext ctx)
        {
            // $ctx.XPTreeNode = (eXPressionTree.IeXPressionTree) new SelectionRule($ctx.ruleid().GetText(), engine: this.Engine);
            // get the name
            SelectionRule aRule = new SelectionRule(ctx.ruleid().GetText(), engine: this.Engine);
            ctx.XPTreeNode = aRule;

            // add expression
            if (ctx.selection() != null) {
                aRule.Selection = new SelectionStatementBlock(engine: this.Engine);
                aRule.Selection.Add(new @Return((SelectionExpression)ctx.selection().XPTreeNode));
            }
            else if (ctx.selectStatementBlock() != null) aRule.Selection = (SelectionStatementBlock)ctx.selectStatementBlock().XPTreeNode;
            // add the parameters
            foreach (ParameterDefinition aParameter in ctx.names.Values)
            {
                ISymbol symbol = aRule.AddNewParameter(aParameter.name, datatype: aParameter.datatype);
                // defaultvalue assignment
                if (aParameter.defaultvalue != null) aRule.Selection.Nodes.Insert(0, new eXPressionTree.IfThenElse(
                    eXPressionTree.CompareExpression.EQ(symbol, new Literal(null, otDataType.@Null)),
                    new eXPressionTree.Assignment(symbol, (IExpression)aParameter.defaultvalue)));
            }
            return true;
        }
Exemple #3
0
        /// <summary>
        /// generate theCode for a rule rule
        /// </summary>
        /// <param name="rule"></param>
        /// <returns></returns>
        public bool Generate(SelectionRule rule, out ICodeBit code)
        {
            try
            {
                bool result = true;
                code = null;

                // check if the object to which data engine
                foreach (iDataObjectEngine aDataEngine in _dataobjectEngines.Reverse <iDataObjectEngine > () )
                {
                    foreach (String aName in rule.ResultingObjectnames () )
                        result &= aDataEngine.Objects.HasObjectDefinition(id: aName);
                    if (result)
                        return aDataEngine.Generate((rule as eXPressionTree.IRule), out code);
                }

                // failure
                if (!result)
                {
                    String theNames = DataType.ToString(rule.ResultingObjectnames());
                    throw new RulezException(RulezException.Types.NoDataEngineAvailable, arguments: new object[] { theNames });
                }

                return false;
            }
            catch (Exception ex)
            {
                throw new RulezException(RulezException.Types.GenerateFailed, inner: ex);
            }
        }