Esempio n. 1
0
        // Guid dlID
        /// <summary>
        /// Executes the decision stack.
        /// </summary>
        /// <param name="decisionDataPayload">The decision data payload.</param>
        /// <param name="oldAmbientData">The old ambient data.</param>
        /// <returns></returns>
        /// <exception cref="System.Data.InvalidExpressionException">Could not evaluate decision data - No decision function found for [  + typeOf + ]</exception>
        public bool ExecuteDecisionStack(string decisionDataPayload, IList <string> oldAmbientData)
        {
            Guid dlId = FetchDataListID(oldAmbientData);
//            if(dlId == GlobalConstants.NullDataListID) throw new InvalidExpressionException("Could not evaluate decision data - no DataList ID sent!");
            string newDecisionData = Dev2DecisionStack.FromVBPersitableModelToJSON(decisionDataPayload);
            var    dds             = EvaluateRegion(newDecisionData, dlId);


            var env = _environments[dlId];

            if (dds != null)
            {
                if (dlId != GlobalConstants.NullDataListID)
                {
                    try
                    {
                        if (dds.TheStack != null)
                        {
                            for (int i = 0; i < dds.TotalDecisions; i++)
                            {
                                Dev2Decision   dd     = dds.GetModelItem(i);
                                enDecisionType typeOf = dd.EvaluationFn;

                                // Treat Errors special
                                if (typeOf == enDecisionType.IsError || typeOf == enDecisionType.IsNotError)
                                {
                                    dd.Col1 = String.Join("", env.Errors);
                                }

                                IDecisionOperation op = Dev2DecisionFactory.Instance().FetchDecisionFunction(typeOf);
                                if (op != null)
                                {
                                    try
                                    {
                                        bool result = op.Invoke(dds.GetModelItem(i).FetchColsAsArray());

                                        if (!result && dds.Mode == Dev2DecisionMode.AND)
                                        {
                                            // Naughty stuff, we have a false in AND mode... break
                                            return(false);
                                        }

                                        if (result && dds.Mode == Dev2DecisionMode.OR)
                                        {
                                            return(true);
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        // An error, push into the DL
                                        env.AddError(e.Message);

                                        return(false);
                                    }
                                }
                                else
                                {
                                    throw new InvalidExpressionException("Could not evaluate decision data - No decision function found for [ " + typeOf + " ]");
                                }
                            }

                            // else we are in AND mode and all have passed ;)
                            if (dds.Mode == Dev2DecisionMode.AND)
                            {
                                return(true);
                            }

                            //finally, it must be OR mode with no matches ;(
                            return(false);
                        }

                        throw new InvalidExpressionException("Could not evaluate decision data - Invalid model data sent!");
                    }
                    catch
                    {
                        // all hell has broken loose... ;)
                        throw new InvalidExpressionException("Could not evaluate decision data - No model data sent!");
                    }
                }

                throw new InvalidExpressionException("Could not evaluate decision data - no DataList ID sent!");
            }

            throw new InvalidExpressionException("Could not populate decision model - DataList Errors!");
        }
        // Guid dlID
        /// <summary>
        /// Executes the decision stack.
        /// </summary>
        /// <param name="decisionDataPayload">The decision data payload.</param>
        /// <param name="oldAmbientData">The old ambient data.</param>
        /// <returns></returns>
        /// <exception cref="System.Data.InvalidExpressionException">Could not evaluate decision data - No decision function found for [  + typeOf + ]</exception>
        public bool ExecuteDecisionStack(string decisionDataPayload, IList <string> oldAmbientData)
        {
            // Evaluate decisionDataPayload through the EvaluateFunction ;)
            Guid dlId = FetchDataListID(oldAmbientData);

            if (dlId == GlobalConstants.NullDataListID)
            {
                throw new InvalidExpressionException("Could not evaluate decision data - no DataList ID sent!");
            }
            // Swap out ! with a new internal token to avoid nasty issues with
            string newDecisionData = Dev2DecisionStack.FromVBPersitableModelToJSON(decisionDataPayload);

            var dds = EvaluateRegion(newDecisionData, dlId);

            ErrorResultTO errors = new ErrorResultTO();

            if (dds != null)
            {
                if (dlId != GlobalConstants.NullDataListID)
                {
                    try
                    {
                        if (dds.TheStack != null)
                        {
                            for (int i = 0; i < dds.TotalDecisions; i++)
                            {
                                Dev2Decision   dd     = dds.GetModelItem(i);
                                enDecisionType typeOf = dd.EvaluationFn;

                                // Treat Errors special
                                if (typeOf == enDecisionType.IsError || typeOf == enDecisionType.IsNotError)
                                {
                                    dd.Col1 = Compiler.EvaluateSystemEntry(dlId, enSystemTag.Dev2Error, out errors);
                                }

                                IDecisionOperation op = Dev2DecisionFactory.Instance().FetchDecisionFunction(typeOf);
                                if (op != null)
                                {
                                    try
                                    {
                                        bool result = op.Invoke(dds.GetModelItem(i).FetchColsAsArray());

                                        if (!result && dds.Mode == Dev2DecisionMode.AND)
                                        {
                                            // Naughty stuff, we have a false in AND mode... break
                                            return(false);
                                        }

                                        if (result && dds.Mode == Dev2DecisionMode.OR)
                                        {
                                            return(true);
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        // An error, push into the DL
                                        ErrorResultTO errorErrors;
                                        errors.AddError(e.Message);
                                        Compiler.UpsertSystemTag(dlId, enSystemTag.Dev2Error, errors.MakeDataListReady(), out errorErrors);

                                        return(false);
                                    }
                                }
                                else
                                {
                                    throw new InvalidExpressionException("Could not evaluate decision data - No decision function found for [ " + typeOf + " ]");
                                }
                            }

                            // else we are in AND mode and all have passed ;)
                            if (dds.Mode == Dev2DecisionMode.AND)
                            {
                                return(true);
                            }

                            //finally, it must be OR mode with no matches ;(
                            return(false);
                        }

                        throw new InvalidExpressionException("Could not evaluate decision data - Invalid model data sent!");
                    }
                    catch
                    {
                        // all hell has broken loose... ;)
                        throw new InvalidExpressionException("Could not evaluate decision data - No model data sent!");
                    }
                }

                throw new InvalidExpressionException("Could not evaluate decision data - no DataList ID sent!");
            }

            throw new InvalidExpressionException("Could not populate decision model - DataList Errors!");
        }