Exemple #1
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);
            }
        }
Exemple #2
0
 /// <summary>
 /// adds or replaces a codebit
 /// </summary>
 /// <param name="theCode"></param>
 /// <returns></returns>
 private bool AddCode(ICodeBit code)
 {
     if (_Code.ContainsKey(code.Handle))
     {
         _Code.Remove(code.Handle);
     }
     _Code.Add(key: code.Handle, value: code);
     return(true);
 }
Exemple #3
0
        /// <summary>
        /// run a rule rule and return an ienumerable of IDataObjects
        /// </summary>
        /// <param name="ruleid"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public IEnumerable <iDataObject> RunSelectionRule(string ruleid, params object[] parameters)
        {
            SelectionRule aRule = this.GetSelectionRule(id: ruleid);

            // search the rule
            if (aRule == null)
            {
                throw new RulezException(RulezException.Types.IdNotFound, arguments: new object[] { ruleid, "SelectionRule" });
            }
            // not the required number of arguments
            if (parameters.Length != aRule.Parameters.Count())
            {
                throw new RulezException(RulezException.Types.InvalidNumberOfArguments, arguments: new object[] { "SelectionRule", ruleid, aRule.Parameters.Count(), parameters.Length });
            }
            // get the Codebit
            ICodeBit theCode = this.GetCode(aRule.Handle);

            if (theCode == null)
            {
                throw new RulezException(RulezException.Types.HandleNotDefined, arguments: new object[] { aRule.ID });
            }
            if (theCode.Code == null)
            {
                throw new RulezException(RulezException.Types.InvalidCode, arguments: new object[] { aRule.ID, aRule.Handle });
            }
            // push the arguments
            _context.PushParameters(parameters);
            try
            {
                // run the theCode
                if (theCode.Code(_context) == false)
                {
                    return(null);
                }
                // pop result
                IEnumerable <iDataObject> result = (_context.Pop() as IEnumerable <iDataObject>);
                return(result);
            }
            catch (RulezException ex)
            {
                throw new RulezException(RulezException.Types.RunFailed, inner: ex, message: ex.Message);
            }
            catch (Exception ex)
            {
                throw new RulezException(RulezException.Types.RunFailed, inner: ex);
            }
        }
Exemple #4
0
        /// <summary>
        /// Generate from a rule the intermediate Code and store it
        /// </summary>
        /// <param name="rule"></param>
        /// <returns></returns>
        public bool Generate(IRule rule)
        {
            ICodeBit code = null;
            bool     result;

            try
            {
                switch (rule.NodeType)
                {
                // rule rule
                case otXPTNodeType.SelectionRule:
                    result = Generate((rule as SelectionRule), out code);
                    break;

                // no theCode
                default:
                    throw new RulezException(RulezException.Types.InvalidNodeType, arguments: new object[] { rule.NodeType.ToString(), "IRULE" });
                }

                // if successfull
                if (result)
                {
                    rule.RuleState = otRuleState.generatedCode;
                    //  get the handle
                    if (code != null && !String.IsNullOrEmpty(code.Handle))
                    {
                        code.Handle = rule.Handle;
                    }
                    // add it to the code base
                    if (code != null && !String.IsNullOrEmpty(code.Handle))
                    {
                        AddCode(code);
                    }
                    else
                    {
                        throw new RulezException(RulezException.Types.HandleNotDefined, arguments: new object[] { rule.ID });
                    }
                }
                return(result);
            } catch (Exception ex)
            {
                throw new RulezException(RulezException.Types.GenerateFailed, inner: ex);
            }
        }
Exemple #5
0
 /// <summary>
 /// adds or replaces a codebit
 /// </summary>
 /// <param name="theCode"></param>
 /// <returns></returns>
 private bool AddCode(ICodeBit code)
 {
     if (_Code.ContainsKey(code.Handle)) _Code.Remove(code.Handle);
      _Code.Add(key: code.Handle, value: code);
      return true;
 }
Exemple #6
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);
            }
        }