/// <summary>
        /// Processes the record set.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <param name="error">The error.</param>
        /// <returns></returns>
        private string ProcessRecordSet(IBinaryDataListEntry entry, out string error)
        {
            StringBuilder result = new StringBuilder();

            error = string.Empty;

            // MAKE RS START ;)
            result.Append("\"");
            result.Append(entry.Namespace);
            result.Append("\" : [");

            IIndexIterator idxItr = entry.FetchRecordsetIndexes();

            int rsCnt = 0;

            while (idxItr.HasMore() && !entry.IsEmpty())
            {
                int idx = idxItr.FetchNextIndex();

                IList <IBinaryDataListItem> rowData = entry.FetchRecordAt(idx, out error);
                result.Append("{");

                int colIdx = 0;
                foreach (IBinaryDataListItem col in rowData)
                {
                    result.Append("\"");
                    result.Append(col.FieldName);
                    result.Append("\":\"");
                    result.Append(col.TheValue);
                    result.Append("\"");

                    // add , if need be ;)
                    colIdx++;
                    if (colIdx < rowData.Count)
                    {
                        result.Append(",");
                    }
                }

                result.Append("}");

                // append , for row data ;)
                rsCnt++;
                if (rsCnt < idxItr.Count)
                {
                    result.Append(", ");
                }
            }

            // END RS ;)
            result.Append("]");


            return(result.ToString());
        }
示例#2
0
        //MO - Changed : new ctor that accepts the new arguments
        public ForEachBootstrapTOOld(enForEachType forEachType, string from, string to, string csvNumbers, string numberOfExecutes, string recordsetName, Guid dlID, IDataListCompiler compiler, out ErrorResultTO errors)
        {
            errors      = new ErrorResultTO();
            ForEachType = forEachType;
            IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection();
            IndexIterator           localIndexIterator;
            IndexList indexList;

            switch (forEachType)
            {
            case enForEachType.InRecordset:
                IBinaryDataListEntry recordset = compiler.Evaluate(dlID, enActionType.User, recordsetName, false, out errors);

                if (recordset == null || !recordset.IsRecordset)
                {
                    errors.AddError("When selecting a recordset only valid recordsets can be used");
                    break;
                }


                var isEmpty = recordset.IsEmpty();
                if (isEmpty)
                {
                    indexList = new IndexList(new HashSet <int> {
                        1
                    }, 0);
                    localIndexIterator = new IndexIterator(new HashSet <int> {
                        1
                    }, 0);
                }
                else
                {
                    indexList = new IndexList(new HashSet <int>(), 0)
                    {
                        MinValue = 1, MaxValue = recordset.FetchLastRecordsetIndex()
                    };
                    localIndexIterator = new IndexIterator(new HashSet <int>(), 0);
                }

                localIndexIterator.IndexList = indexList;
                IndexIterator = localIndexIterator;
                break;

            case enForEachType.InRange:
                if (string.IsNullOrWhiteSpace(from))
                {
                    errors.AddError("The from field can not be left empty.");
                    break;
                }

                if (string.IsNullOrWhiteSpace(to))
                {
                    errors.AddError("The to field can not be left empty.");
                    break;
                }

                if (from.Contains("(*)"))
                {
                    errors.AddError("The Star notation is not accepted in the From field.");
                    break;
                }

                var fromItr = CreateDataListEvaluateIterator(from, dlID, compiler, colItr, errors);
                colItr.AddIterator(fromItr);

                int intFrom;
                if (!int.TryParse(colItr.FetchNextRow(fromItr).TheValue, out intFrom) || intFrom < 1)
                {
                    errors.AddError("From range must be a whole number from 1 onwards.");
                    break;
                }

                if (to.Contains("(*)"))
                {
                    errors.AddError("The Star notation is not accepted in the To field.");
                    break;
                }

                var toItr = CreateDataListEvaluateIterator(to, dlID, compiler, colItr, errors);
                colItr.AddIterator(toItr);

                int intTo;
                if (!int.TryParse(colItr.FetchNextRow(toItr).TheValue, out intTo) || intTo < 1)
                {
                    errors.AddError("To range must be a whole number from 1 onwards.");
                    break;
                }
                if (intFrom > intTo)
                {
                    indexList = new IndexList(new HashSet <int>(), 0)
                    {
                        MinValue = intFrom, MaxValue = intTo
                    };
                    ReverseIndexIterator revIdxItr = new ReverseIndexIterator(new HashSet <int>(), 0)
                    {
                        IndexList = indexList
                    };
                    IndexIterator = revIdxItr;
                }
                else
                {
                    indexList = new IndexList(new HashSet <int>(), 0)
                    {
                        MinValue = intFrom, MaxValue = intTo
                    };
                    localIndexIterator = new IndexIterator(new HashSet <int>(), 0)
                    {
                        IndexList = indexList
                    };
                    IndexIterator = localIndexIterator;
                }

                break;

            case enForEachType.InCSV:
                var csvIndexedsItr = CreateDataListEvaluateIterator(csvNumbers, dlID, compiler, colItr, errors);
                colItr.AddIterator(csvIndexedsItr);
                ErrorResultTO allErrors;
                List <int>    listOfIndexes = SplitOutCsvIndexes(colItr.FetchNextRow(csvIndexedsItr).TheValue, out allErrors);
                if (allErrors.HasErrors())
                {
                    errors.MergeErrors(allErrors);
                    break;
                }
                ListIndexIterator listLocalIndexIterator = new ListIndexIterator(listOfIndexes);
                ListOfIndex       listOfIndex            = new ListOfIndex(listOfIndexes);
                listLocalIndexIterator.IndexList = listOfIndex;
                IndexIterator = listLocalIndexIterator;
                break;

            default:

                if (numberOfExecutes != null && numberOfExecutes.Contains("(*)"))
                {
                    errors.AddError("The Star notation is not accepted in the Numbers field.");
                    break;
                }

                int intExNum;
                var numOfExItr = CreateDataListEvaluateIterator(numberOfExecutes, dlID, compiler, colItr, errors);
                colItr.AddIterator(numOfExItr);

                if (!int.TryParse(colItr.FetchNextRow(numOfExItr).TheValue, out intExNum))
                {
                    errors.AddError("Number of executes must be a whole number from 1 onwards.");
                }
                IndexIterator = new IndexIterator(new HashSet <int>(), intExNum);
                break;
            }
        }
        public List<IDebugItemResult> CreateDebugItemsFromEntry(string expression, IBinaryDataListEntry dlEntry, Guid dlId, enDev2ArgumentType argumentType, string labelText, int indexToUse = -1)
        {
            var results = new List<IDebugItemResult>();
            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();
            IBinaryDataList dataList = compiler.FetchBinaryDataList(dlId, out ErrorsTo);

            if(
                !(expression.Contains(GlobalConstants.CalculateTextConvertPrefix) &&
                  expression.Contains(GlobalConstants.CalculateTextConvertSuffix)))
            {
                if(!expression.ContainsSafe("[["))
                {
                    results.Add(new DebugItemResult
                        {
                            Label = labelText,
                            Type = DebugItemResultType.Value,
                            Value = expression
                        });
                    return results;
                }
            }
            else
            {
                expression =
                    expression.Replace(GlobalConstants.CalculateTextConvertPrefix, string.Empty)
                              .Replace(GlobalConstants.CalculateTextConvertSuffix, string.Empty);
            }

            if(dlEntry != null && dlEntry.ComplexExpressionAuditor == null)
            {
                int groupIndex = 0;
                enRecordsetIndexType rsType = DataListUtil.GetRecordsetIndexType(expression);

                if(dlEntry.IsRecordset &&
                    (DataListUtil.IsValueRecordset(expression) &&
                     (rsType == enRecordsetIndexType.Star ||
                      (rsType == enRecordsetIndexType.Numeric &&
                       DataListUtil.ExtractFieldNameFromValue(expression) == string.Empty) ||
                      (rsType == enRecordsetIndexType.Blank &&
                       DataListUtil.ExtractFieldNameFromValue(expression) == string.Empty))))
                {
                    // Added IsEmpty check for Bug 9263 ;)
                    if(!dlEntry.IsEmpty())
                    {
                        IList<IDebugItemResult> collection = CreateRecordsetDebugItems(expression, dlEntry, string.Empty,
                                                                                      -1, labelText);
                        if(collection.Count < 2 && collection.Count > 0)
                        {
                            collection[0].GroupName = "";
                        }
                        results.AddRange(collection);
                    }
                    else
                    {
                        results.Add(new DebugItemResult
                            {
                                Type = DebugItemResultType.Variable,
                                Label = labelText,
                                Variable = expression,
                                Operator = string.IsNullOrEmpty(expression) ? "" : "=",
                                Value = "",
                            });
                    }
                }
                else
                {
                    if(DataListUtil.IsValueRecordset(expression) &&
                        (DataListUtil.GetRecordsetIndexType(expression) == enRecordsetIndexType.Blank))
                    {
                        if(indexToUse == -1)
                        {
                            IBinaryDataListEntry tmpEntry;
                            string error;
                            dataList.TryGetEntry(DataListUtil.ExtractRecordsetNameFromValue(expression),
                                                 out tmpEntry, out error);
                            if(tmpEntry != null)
                            {
                                int index = tmpEntry.FetchAppendRecordsetIndex() - 1;
                                if(index > 0)
                                {
                                    groupIndex = index;
                                    expression = expression.Replace("().", string.Concat("(", index, ")."));
                                }
                            }
                        }
                        else
                        {
                            expression = expression.Replace("().", string.Concat("(", indexToUse, ")."));
                        }
                    }

                    if(dlEntry.IsRecordset)
                    {
                        var strIndx = DataListUtil.ExtractIndexRegionFromRecordset(expression);
                        int indx;
                        if(int.TryParse(strIndx, out indx))
                        {
                            if(indx > 0)
                            {
                                IBinaryDataListItem item = dlEntry.FetchScalar();
                                try
                                {
                                    CreateScalarDebugItems(expression, item.TheValue, labelText, results, "", groupIndex);
                                }
                                catch(NullValueInVariableException)
                                {
                                    CreateScalarDebugItems(expression, "", labelText, results, "", groupIndex);
                                }
                            }
                            else
                            {
                                CreateScalarDebugItems(expression, "", labelText, results, "", groupIndex);
                            }
                        }
                        else
                        {
                            IBinaryDataListItem itemx = dlEntry.FetchScalar();

                            if(!string.IsNullOrEmpty(strIndx))
                            {
                                IBinaryDataListEntry indexBinaryEntry;
                                IBinaryDataListItem indexItem = null;
                                string error;
                                if(DataListUtil.IsValueRecordset(strIndx))
                                {
                                    dataList.TryGetEntry(DataListUtil.ExtractRecordsetNameFromValue(strIndx),
                                                 out indexBinaryEntry, out error);
                                    var fieldName = DataListUtil.ExtractFieldNameFromValue(strIndx);
                                    int index;
                                    if(int.TryParse(DataListUtil.ExtractIndexRegionFromRecordset(strIndx), out index))
                                    {
                                        indexItem = indexBinaryEntry.TryFetchRecordsetColumnAtIndex(fieldName, index, out error);
                                    }
                                }
                                else
                                {
                                    dataList.TryGetEntry(strIndx, out indexBinaryEntry, out error);
                                    indexItem = indexBinaryEntry.FetchScalar();
                                }
                                if(indexItem != null)
                                {
                                    expression = expression.Replace(string.Format("({0})", strIndx), string.Format("({0})", indexItem.TheValue));
                                }
                            }

                            try
                            {
                                CreateScalarDebugItems(expression, itemx.TheValue, labelText, results, "", groupIndex);
                            }
// ReSharper disable EmptyGeneralCatchClause
                            catch(Exception)
// ReSharper restore EmptyGeneralCatchClause
                            {
                                
                            }
                        }
                    }
                    else
                    {
                        IBinaryDataListItem item = dlEntry.FetchScalar();
                        try
                        {
                            CreateScalarDebugItems(expression, item.TheValue, labelText, results, "", groupIndex);
                        }
                        catch(Exception)
                        {
                            CreateScalarDebugItems(expression, null, labelText, results, "", groupIndex);
                        }
                    }
                }
            }
            else
            {
                // Complex expressions are handled differently ;)
                if(dlEntry != null)
                {
                    ComplexExpressionAuditor auditor = dlEntry.ComplexExpressionAuditor;

                    int idx = 1;

                    foreach(ComplexExpressionAuditItem item in auditor.FetchAuditItems())
                    {
                        int grpIdx = idx;
                        string groupName = item.RawExpression;
                        string displayExpression = item.RawExpression;
                        if(displayExpression.Contains("()."))
                        {
                            displayExpression = displayExpression.Replace("().",
                                string.Concat("(", auditor.GetMaxIndex(), ")."));
                        }
                        if(displayExpression.Contains("(*)."))
                        {
                            displayExpression = displayExpression.Replace("(*).", string.Concat("(", idx, ")."));
                        }

                        results.Add(new DebugItemResult
                        {
                            Type = DebugItemResultType.Variable,
                            Label = labelText,
                            Variable = displayExpression,
                            Operator = string.IsNullOrEmpty(displayExpression) ? "" : "=",
                            GroupName = groupName,
                            Value = item.BoundValue,
                            GroupIndex = grpIdx
                        });

                        idx++;
                    }
                }
            }

            return results;
        }
        public List <IDebugItemResult> CreateDebugItemsFromEntry(string expression, IBinaryDataListEntry dlEntry, Guid dlId, enDev2ArgumentType argumentType, string labelText, int indexToUse = -1)
        {
            var results = new List <IDebugItemResult>();
            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();
            IBinaryDataList   dataList = compiler.FetchBinaryDataList(dlId, out ErrorsTo);

            if (
                !(expression.Contains(GlobalConstants.CalculateTextConvertPrefix) &&
                  expression.Contains(GlobalConstants.CalculateTextConvertSuffix)))
            {
                if (!expression.ContainsSafe("[["))
                {
                    results.Add(new DebugItemResult
                    {
                        Label = labelText,
                        Type  = DebugItemResultType.Value,
                        Value = expression
                    });
                    return(results);
                }
            }
            else
            {
                expression =
                    expression.Replace(GlobalConstants.CalculateTextConvertPrefix, string.Empty)
                    .Replace(GlobalConstants.CalculateTextConvertSuffix, string.Empty);
            }

            if (dlEntry != null && dlEntry.ComplexExpressionAuditor == null)
            {
                int groupIndex = 0;
                enRecordsetIndexType rsType = DataListUtil.GetRecordsetIndexType(expression);

                if (dlEntry.IsRecordset &&
                    (DataListUtil.IsValueRecordset(expression) &&
                     (rsType == enRecordsetIndexType.Star ||
                      (rsType == enRecordsetIndexType.Numeric &&
                       DataListUtil.ExtractFieldNameFromValue(expression) == string.Empty) ||
                      (rsType == enRecordsetIndexType.Blank &&
                       DataListUtil.ExtractFieldNameFromValue(expression) == string.Empty))))
                {
                    // Added IsEmpty check for Bug 9263 ;)
                    if (!dlEntry.IsEmpty())
                    {
                        IList <IDebugItemResult> collection = CreateRecordsetDebugItems(expression, dlEntry, string.Empty,
                                                                                        -1, labelText);
                        if (collection.Count < 2 && collection.Count > 0)
                        {
                            collection[0].GroupName = "";
                        }
                        results.AddRange(collection);
                    }
                    else
                    {
                        results.Add(new DebugItemResult
                        {
                            Type     = DebugItemResultType.Variable,
                            Label    = labelText,
                            Variable = expression,
                            Operator = string.IsNullOrEmpty(expression) ? "" : "=",
                            Value    = "",
                        });
                    }
                }
                else
                {
                    if (DataListUtil.IsValueRecordset(expression) &&
                        (DataListUtil.GetRecordsetIndexType(expression) == enRecordsetIndexType.Blank))
                    {
                        if (indexToUse == -1)
                        {
                            IBinaryDataListEntry tmpEntry;
                            string error;
                            dataList.TryGetEntry(DataListUtil.ExtractRecordsetNameFromValue(expression),
                                                 out tmpEntry, out error);
                            if (tmpEntry != null)
                            {
                                int index = tmpEntry.FetchAppendRecordsetIndex() - 1;
                                if (index > 0)
                                {
                                    groupIndex = index;
                                    expression = expression.Replace("().", string.Concat("(", index, ")."));
                                }
                            }
                        }
                        else
                        {
                            expression = expression.Replace("().", string.Concat("(", indexToUse, ")."));
                        }
                    }

                    if (dlEntry.IsRecordset)
                    {
                        var strIndx = DataListUtil.ExtractIndexRegionFromRecordset(expression);
                        int indx;
                        if (int.TryParse(strIndx, out indx))
                        {
                            if (indx > 0)
                            {
                                IBinaryDataListItem item = dlEntry.FetchScalar();
                                try
                                {
                                    CreateScalarDebugItems(expression, item.TheValue, labelText, results, "", groupIndex);
                                }
                                catch (NullValueInVariableException)
                                {
                                    CreateScalarDebugItems(expression, "", labelText, results, "", groupIndex);
                                }
                            }
                            else
                            {
                                CreateScalarDebugItems(expression, "", labelText, results, "", groupIndex);
                            }
                        }
                        else
                        {
                            IBinaryDataListItem itemx = dlEntry.FetchScalar();

                            if (!string.IsNullOrEmpty(strIndx))
                            {
                                IBinaryDataListEntry indexBinaryEntry;
                                IBinaryDataListItem  indexItem = null;
                                string error;
                                if (DataListUtil.IsValueRecordset(strIndx))
                                {
                                    dataList.TryGetEntry(DataListUtil.ExtractRecordsetNameFromValue(strIndx),
                                                         out indexBinaryEntry, out error);
                                    var fieldName = DataListUtil.ExtractFieldNameFromValue(strIndx);
                                    int index;
                                    if (int.TryParse(DataListUtil.ExtractIndexRegionFromRecordset(strIndx), out index))
                                    {
                                        indexItem = indexBinaryEntry.TryFetchRecordsetColumnAtIndex(fieldName, index, out error);
                                    }
                                }
                                else
                                {
                                    dataList.TryGetEntry(strIndx, out indexBinaryEntry, out error);
                                    indexItem = indexBinaryEntry.FetchScalar();
                                }
                                if (indexItem != null)
                                {
                                    expression = expression.Replace(string.Format("({0})", strIndx), string.Format("({0})", indexItem.TheValue));
                                }
                            }

                            try
                            {
                                CreateScalarDebugItems(expression, itemx.TheValue, labelText, results, "", groupIndex);
                            }
// ReSharper disable EmptyGeneralCatchClause
                            catch (Exception)
// ReSharper restore EmptyGeneralCatchClause
                            {
                            }
                        }
                    }
                    else
                    {
                        IBinaryDataListItem item = dlEntry.FetchScalar();
                        try
                        {
                            CreateScalarDebugItems(expression, item.TheValue, labelText, results, "", groupIndex);
                        }
                        catch (Exception)
                        {
                            CreateScalarDebugItems(expression, null, labelText, results, "", groupIndex);
                        }
                    }
                }
            }
            else
            {
                // Complex expressions are handled differently ;)
                if (dlEntry != null)
                {
                    ComplexExpressionAuditor auditor = dlEntry.ComplexExpressionAuditor;

                    int idx = 1;

                    foreach (ComplexExpressionAuditItem item in auditor.FetchAuditItems())
                    {
                        int    grpIdx            = idx;
                        string groupName         = item.RawExpression;
                        string displayExpression = item.RawExpression;
                        if (displayExpression.Contains("()."))
                        {
                            displayExpression = displayExpression.Replace("().",
                                                                          string.Concat("(", auditor.GetMaxIndex(), ")."));
                        }
                        if (displayExpression.Contains("(*)."))
                        {
                            displayExpression = displayExpression.Replace("(*).", string.Concat("(", idx, ")."));
                        }

                        results.Add(new DebugItemResult
                        {
                            Type       = DebugItemResultType.Variable,
                            Label      = labelText,
                            Variable   = displayExpression,
                            Operator   = string.IsNullOrEmpty(displayExpression) ? "" : "=",
                            GroupName  = groupName,
                            Value      = item.BoundValue,
                            GroupIndex = grpIdx
                        });

                        idx++;
                    }
                }
            }

            return(results);
        }
        /// <summary>
        /// Processes the record set.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <param name="error">The error.</param>
        /// <returns></returns>
        private string ProcessRecordSet(IBinaryDataListEntry entry, out string error)
        {
            StringBuilder result = new StringBuilder();
            error = string.Empty;

            // MAKE RS START ;)
            result.Append("\"");
            result.Append(entry.Namespace);
            result.Append("\" : [");

            IIndexIterator idxItr = entry.FetchRecordsetIndexes();

            int rsCnt = 0;

            while(idxItr.HasMore() && !entry.IsEmpty())
            {
                int idx = idxItr.FetchNextIndex();

                IList<IBinaryDataListItem> rowData = entry.FetchRecordAt(idx, out error);
                result.Append("{");

                int colIdx = 0;
                foreach(IBinaryDataListItem col in rowData)
                {
                    result.Append("\"");
                    result.Append(col.FieldName);
                    result.Append("\":\"");
                    result.Append(col.TheValue);
                    result.Append("\"");

                    // add , if need be ;)
                    colIdx++;
                    if(colIdx < rowData.Count)
                    {
                        result.Append(",");
                    }
                }

                result.Append("}");

                // append , for row data ;)
                rsCnt++;
                if(rsCnt < idxItr.Count)
                {
                    result.Append(", ");
                }
            }

            // END RS ;)
            result.Append("]");


            return result.ToString();
        }