Пример #1
0
        List <IDebugItemResult> BuildDebugItemFromAtomList()
        {
            var results = new List <IDebugItemResult>();


            foreach (var item in _warewolfRecordset.Data)
            {
                if (item.Key == "WarewolfPositionColumn")
                {
                    continue;
                }

                var grpIdx = 0;
                foreach (var warewolfAtom in item.Value)
                {
                    var index    = _warewolfRecordset.Data["WarewolfPositionColumn"][grpIdx];
                    var position = ExecutionEnvironment.WarewolfAtomToString(index);
                    grpIdx++;
                    string displayExpression = DataListUtil.AddBracketsToValueIfNotExist(DataListUtil.CreateRecordsetDisplayValue(DataListUtil.ExtractRecordsetNameFromValue(_variable), item.Key, position));
                    var    debugType         = DebugItemResultType.Value;
                    if (DataListUtil.IsEvaluated(displayExpression))
                    {
                        _operand  = "=";
                        debugType = DebugItemResultType.Variable;
                    }
                    else
                    {
                        displayExpression = null;
                    }
                    if (!warewolfAtom.IsNothing)
                    {
                        results.Add(new DebugItemResult
                        {
                            Type       = debugType,
                            Label      = _labelText,
                            Variable   = displayExpression,
                            Operator   = _operand,
                            GroupName  = _variable,
                            Value      = ExecutionEnvironment.WarewolfAtomToString(warewolfAtom),
                            GroupIndex = grpIdx
                        });
                    }
                }
            }
            return(results);
        }
Пример #2
0
        /// <summary>
        /// Evaluates the region.
        /// </summary>
        /// <param name="payload">The payload.</param>
        /// <param name="dlId">The dl ID.</param>
        /// <returns></returns>
        private Dev2DecisionStack EvaluateRegion(string payload, Guid dlId)
        {
            var env = _environments[dlId];

            if (payload.StartsWith("{\"TheStack\":[{") || payload.StartsWith("{'TheStack':[{"))
            {
                //2013.05.06: Ashley Lewis for PBI 9460 - handle record-sets with stars in their index by resolving them
                var dds = Compiler.ConvertFromJsonToModel <Dev2DecisionStack>(new StringBuilder(payload));

                if (dds.TheStack != null)
                {
                    var effectedCols = new[] { false, false, false };
                    //Find decisions that mention record sets with starred indexes
                    var invalidDecisions = new List <Dev2Decision>();
                    for (int i = 0; i < dds.TotalDecisions; i++)
                    {
                        Dev2Decision dd = dds.GetModelItem(i);

                        if (dd.Col1 != null && DataListUtil.GetRecordsetIndexType(dd.Col1) == enRecordsetIndexType.Star)
                        {
                            invalidDecisions.Add(dd);
                            effectedCols[0] = true;
                        }
                        else
                        {
                            var warewolfEvalResult = GetWarewolfEvalResult(env, dd.Col1);
                            dd.Col1 = ExecutionEnvironment.WarewolfEvalResultToString(warewolfEvalResult);
                        }

                        if (dd.Col2 != null && DataListUtil.GetRecordsetIndexType(dd.Col2) == enRecordsetIndexType.Star)
                        {
                            if (!effectedCols[0])
                            {
                                invalidDecisions.Add(dd);
                            }
                            effectedCols[1] = true;
                        }
                        else
                        {
                            var warewolfEvalResult = GetWarewolfEvalResult(env, dd.Col2);
                            dd.Col2 = ExecutionEnvironment.WarewolfEvalResultToString(warewolfEvalResult);
                        }

                        if (dd.Col3 != null && DataListUtil.GetRecordsetIndexType(dd.Col3) == enRecordsetIndexType.Star)
                        {
                            if (!effectedCols[0] && !effectedCols[1])
                            {
                                invalidDecisions.Add(dd);
                            }
                            effectedCols[2] = true;
                        }
                        else
                        {
                            var warewolfEvalResult = GetWarewolfEvalResult(env, dd.Col3);
                            dd.Col3 = ExecutionEnvironment.WarewolfEvalResultToString(warewolfEvalResult);
                        }
                    }
                    //Remove those record sets and replace them with a new decision for each resolved value
                    foreach (Dev2Decision decision in invalidDecisions)
                    {
                        ErrorResultTO errors;
                        dds = ResolveAllRecords(env, dds, decision, effectedCols, out errors);
                    }
                }

                return(dds);
            }
            return(null);
        }
Пример #3
0
        string ResolveStarredIndices(IExecutionEnvironment env, string mode, out ErrorResultTO errors)
        {
            string        fn = DecisionDisplayHelper.GetDisplayValue(EvaluationFn);
            StringBuilder expandStarredIndices = new StringBuilder();

            if (DataListUtil.GetRecordsetIndexType(Col1) != enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col2) != enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col3) == enRecordsetIndexType.Star)
            {
                var allCol3Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col3, env, out errors);

                expandStarredIndices.Append(Col1 + " " + fn + " " + Col2 + " AND " + allCol3Values[0]);
                allCol3Values.RemoveAt(0);
                foreach (var value in allCol3Values)
                {
                    expandStarredIndices.Append(" " + mode + " " + Col1 + " " + fn + " " + Col2 + " AND " + value);
                }
                return("If " + expandStarredIndices);
            }
            if (DataListUtil.GetRecordsetIndexType(Col1) != enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col2) == enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col3) != enRecordsetIndexType.Star)
            {
                var allCol2Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col2, env, out errors);

                expandStarredIndices.Append(Col1 + " " + fn + " " + allCol2Values[0] + " AND " + Col3);
                allCol2Values.RemoveAt(0);
                foreach (var value in allCol2Values)
                {
                    expandStarredIndices.Append(" " + mode + " " + Col1 + " " + fn + " " + value + " AND " + Col3);
                }
                return("If " + expandStarredIndices);
            }
            if (DataListUtil.GetRecordsetIndexType(Col1) != enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col2) == enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col3) == enRecordsetIndexType.Star)
            {
                var allCol2Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col2, env, out errors);
                var allCol3Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col3, env, out errors);

                expandStarredIndices.Append(Col1 + " " + fn + " " + allCol2Values[0] + " AND " + allCol3Values[0]);
                allCol2Values.RemoveAt(0);
                allCol3Values.RemoveAt(0);
                for (var i = 0; i < Math.Max(allCol2Values.Count, allCol3Values.Count); i++)
                {
                    if (i > allCol2Values.Count)
                    {
                        allCol2Values.Add(null);
                    }
                    if (i > allCol3Values.Count)
                    {
                        allCol3Values.Add(null);
                    }
                    expandStarredIndices.Append(" " + mode + " " + Col1 + " " + fn + " " + allCol2Values[i] + " AND " + allCol3Values[i]);
                }
                return("If " + expandStarredIndices);
            }
            if (DataListUtil.GetRecordsetIndexType(Col1) == enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col2) != enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col3) != enRecordsetIndexType.Star)
            {
                var allCol1Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col1, env, out errors);

                expandStarredIndices.Append(allCol1Values[0] + " " + fn + " " + Col2 + " AND " + Col3);
                allCol1Values.RemoveAt(0);
                foreach (var value in allCol1Values)
                {
                    expandStarredIndices.Append(" " + mode + " " + value + " " + fn + " " + Col2 + " AND " + Col3);
                }
                return("If " + expandStarredIndices);
            }
            if (DataListUtil.GetRecordsetIndexType(Col1) == enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col2) != enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col3) == enRecordsetIndexType.Star)
            {
                var allCol1Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col1, env, out errors);
                var allCol3Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col3, env, out errors);

                expandStarredIndices.Append(allCol1Values[0] + " " + fn + " " + Col2 + " AND " + allCol3Values[0]);
                allCol1Values.RemoveAt(0);
                allCol3Values.RemoveAt(0);
                for (var i = 0; i < Math.Max(allCol1Values.Count, allCol3Values.Count); i++)
                {
                    if (i > allCol1Values.Count)
                    {
                        allCol1Values.Add(null);
                    }
                    if (i > allCol3Values.Count)
                    {
                        allCol3Values.Add(null);
                    }
                    expandStarredIndices.Append(" " + mode + " " + allCol1Values[i] + " " + fn + " " + Col2 + " AND " + allCol3Values[i]);
                }
                return("If " + expandStarredIndices);
            }
            if (DataListUtil.GetRecordsetIndexType(Col1) == enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col2) == enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col3) != enRecordsetIndexType.Star)
            {
                var allCol1Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col1, env, out errors);
                var allCol2Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col2, env, out errors);

                expandStarredIndices.Append(allCol1Values[0] + " " + fn + " " + allCol2Values[0] + " AND " + Col3);
                allCol1Values.RemoveAt(0);
                allCol2Values.RemoveAt(0);
                for (var i = 0; i < Math.Max(allCol1Values.Count, allCol2Values.Count); i++)
                {
                    if (i > allCol1Values.Count)
                    {
                        allCol1Values.Add(null);
                    }
                    if (i > allCol2Values.Count)
                    {
                        allCol2Values.Add(null);
                    }
                    expandStarredIndices.Append(" " + mode + " " + allCol1Values[i] + " " + fn + " " + allCol2Values[0] + " AND " + Col3);
                }
                return("If " + expandStarredIndices);
            }
            if (DataListUtil.GetRecordsetIndexType(Col1) == enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col2) == enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col3) == enRecordsetIndexType.Star)
            {
                var allCol1Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col1, env, out errors);
                var allCol2Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col2, env, out errors);
                var allCol3Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col3, env, out errors);

                expandStarredIndices.Append(allCol1Values[0] + " " + fn + " " + allCol2Values[0] + " AND " + allCol3Values[0]);
                allCol1Values.RemoveAt(0);
                allCol2Values.RemoveAt(0);
                allCol3Values.RemoveAt(0);
                for (var i = 0; i < Math.Max(allCol1Values.Count, Math.Max(allCol2Values.Count, allCol3Values.Count)); i++)
                {
                    if (i > allCol1Values.Count)
                    {
                        allCol1Values.Add(null);
                    }
                    if (i > allCol2Values.Count)
                    {
                        allCol2Values.Add(null);
                    }
                    if (i > allCol3Values.Count)
                    {
                        allCol3Values.Add(null);
                    }
                    expandStarredIndices.Append(" " + mode + " " + allCol1Values[i] + " " + fn + " " + allCol2Values[0] + " AND " + allCol3Values[i]);
                }
                return("If " + expandStarredIndices);
            }
            errors = new ErrorResultTO();
            return(null);
        }
Пример #4
0
        public string GenerateUserFriendlyModel(IExecutionEnvironment env, Dev2DecisionMode mode, out ErrorResultTO errors)
        {
            errors = new ErrorResultTO();
            ErrorResultTO allErrors = new ErrorResultTO();
            string        fn        = DecisionDisplayHelper.GetDisplayValue(EvaluationFn);

            if (PopulatedColumnCount == 0)
            {
                return("If " + fn + " ");
            }

            if (PopulatedColumnCount == 1)
            {
                if (DataListUtil.GetRecordsetIndexType(Col1) == enRecordsetIndexType.Star)
                {
                    var allValues = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col1, env, out errors);
                    allErrors.MergeErrors(errors);
                    StringBuilder expandStarredIndex = new StringBuilder();

                    expandStarredIndex.Append(allValues[0] + " " + fn);
                    allValues.RemoveAt(0);
                    foreach (var value in allValues)
                    {
                        expandStarredIndex.Append(" " + mode + " " + value + " " + fn);
                    }
                    errors = allErrors;
                    return("If " + expandStarredIndex);
                }
                errors = allErrors;
                return("If " + Col1 + " " + fn + " ");
            }

            if (PopulatedColumnCount == 2)
            {
                StringBuilder expandStarredIndices = new StringBuilder();
                if (DataListUtil.GetRecordsetIndexType(Col1) != enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col2) == enRecordsetIndexType.Star)
                {
                    var allCol2Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col2, env, out errors);
                    allErrors.MergeErrors(errors);
                    expandStarredIndices.Append(Col1 + " " + fn + " " + allCol2Values[0]);
                    allCol2Values.RemoveAt(0);
                    foreach (var value in allCol2Values)
                    {
                        expandStarredIndices.Append(" " + mode + " " + Col1 + " " + fn + " " + value);
                    }
                    errors = allErrors;
                    return("If " + expandStarredIndices);
                }
                if (DataListUtil.GetRecordsetIndexType(Col1) == enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col2) != enRecordsetIndexType.Star)
                {
                    var allCol1Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col1, env, out errors);
                    allErrors.MergeErrors(errors);
                    expandStarredIndices.Append(allCol1Values[0] + " " + fn + " " + Col2);
                    allCol1Values.RemoveAt(0);
                    foreach (var value in allCol1Values)
                    {
                        expandStarredIndices.Append(" " + mode + " " + value + " " + fn + " " + Col2);
                    }
                    errors = allErrors;
                    return("If " + expandStarredIndices);
                }
                if ((DataListUtil.GetRecordsetIndexType(Col1) == enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col2) == enRecordsetIndexType.Star) || (DataListUtil.GetRecordsetIndexType(Col1) != enRecordsetIndexType.Star && DataListUtil.GetRecordsetIndexType(Col2) != enRecordsetIndexType.Star))
                {
                    var allCol1Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col1, env, out errors);
                    allErrors.MergeErrors(errors);
                    var allCol2Values = DataListUtil.GetAllPossibleExpressionsForFunctionOperations(Col2, env, out errors);
                    allErrors.MergeErrors(errors);
                    expandStarredIndices.Append(allCol1Values[0] + " " + fn + " " + allCol2Values[0]);
                    allCol1Values.RemoveAt(0);
                    allCol2Values.RemoveAt(0);
                    for (var i = 0; i < Math.Max(allCol1Values.Count, allCol2Values.Count); i++)
                    {
                        if (i > allCol1Values.Count)
                        {
                            allCol1Values.Add(null);
                        }
                        if (i > allCol2Values.Count)
                        {
                            allCol2Values.Add(null);
                        }

                        try
                        {
                            expandStarredIndices.Append(" " + mode + " " + allCol1Values[i] + " " + fn + " " +
                                                        allCol2Values[i]);
                        }
                        catch (IndexOutOfRangeException)
                        {
                            errors.AddError("You appear to have recordsets of differnt sizes");
                            allErrors.MergeErrors(errors);
                        }
                    }
                    errors = allErrors;
                    return("If " + expandStarredIndices);
                }
                errors = allErrors;
                return("If " + Col1 + " " + fn + " " + Col2 + " ");
            }

            if (PopulatedColumnCount == 3)
            {
                var expandStarredIndices = ResolveStarredIndices(env, mode.ToString(), out errors);
                allErrors.MergeErrors(errors);
                if (!string.IsNullOrEmpty(expandStarredIndices))
                {
                    errors = allErrors;
                    return(expandStarredIndices);
                }
                errors = allErrors;
                return("If " + Col1 + " " + fn + " " + Col2 + " and " + Col3);
            }
            errors = allErrors;
            return("<< Internal Error Generating Decision Model: Populated Column Count Cannot Exeed 3 >>");
        }