/// <summary>
        /// Fetches the switch data.
        /// </summary>
        /// <param name="variableName">Name of the variable.</param>
        /// <param name="oldAmbientData">The old ambient data.</param>
        /// <returns></returns>
        public string FetchSwitchData(string variableName, IList <string> oldAmbientData)
        {
            ErrorResultTO        errors;
            Guid                 dlId = FetchDataListID(oldAmbientData);
            IBinaryDataListEntry tmp  = EvaluateForSwitch(variableName, dlId, out errors);

            if (errors.HasErrors())
            {
                Compiler.UpsertSystemTag(dlId, enSystemTag.Dev2Error, errors.MakeDataListReady(), out errors);
            }

            if (tmp != null)
            {
                if (tmp.IsRecordset)
                {
                    string error;
                    return(tmp.TryFetchLastIndexedRecordsetUpsertPayload(out error).TheValue);
                }

                var scalar = tmp.FetchScalar();

                return(scalar.TheValue);
            }

            return(string.Empty);
        }
示例#2
0
 public void Merge(IBinaryDataListEntry toMerge, out string error)
 {
     error = string.Empty;
     if (IsRecordset && toMerge.IsRecordset)
     {
         IIndexIterator ii = toMerge.FetchRecordsetIndexes();
         while (ii.HasMore())
         {
             int next = ii.FetchNextIndex();
             // merge toMerge into this
             foreach (IBinaryDataListItem item in toMerge.FetchRecordAt(next, out error))
             {
                 TryAppendRecordItem(item, out error);
             }
         }
     }
     else if (!IsRecordset && !toMerge.IsRecordset)
     {
         TryPutScalar(toMerge.FetchScalar(), out error); // over write this with toMerge
     }
     else
     {
         error = "Type mis-match, one side is Recordset while the other is a scalar";
     }
 }
示例#3
0
        public List <DebugItem> GetDebugInputs(IList <IDev2Definition> inputs, IBinaryDataList dataList, ErrorResultTO errors)
        {
            if (errors == null)
            {
                throw new ArgumentNullException("errors");
            }

            IDataListCompiler compiler = DataListFactory.CreateDataListCompiler();
            var results = new List <DebugItem>();

            foreach (IDev2Definition dev2Definition in inputs)
            {
                IBinaryDataListEntry tmpEntry = compiler.Evaluate(dataList.UID, enActionType.User, GetVariableName(dev2Definition), false, out errors);

                var val = tmpEntry.FetchScalar();

                val.TheValue += "";

                DebugItem itemToAdd = new DebugItem();
                AddDebugItem(new DebugItemVariableParams(GetVariableName(dev2Definition), "", tmpEntry, dataList.UID), itemToAdd);
                results.Add(itemToAdd);
            }

            foreach (IDebugItem debugInput in results)
            {
                debugInput.FlushStringBuilder();
            }

            return(results);
        }
示例#4
0
        /// <summary>
        /// Fetches the next row data.
        /// If scalar repeat
        /// If RS append notation repeat
        /// </summary>
        /// <returns></returns>
        public IList <IBinaryDataListItem> FetchNextRowData()
        {
            IList <IBinaryDataListItem> result = new List <IBinaryDataListItem>();

            if (_entry.IsRecordset)
            {
                string error;
                if (_idxItr.HasMore())
                {
                    var idx = _idxItr.FetchNextIndex();
                    result = _entry.FetchRecordAt(idx, out error);
                }
                else
                {
                    result = _entry.FetchRecordAt(_idxItr.MaxIndex(), out error);
                }
            }
            else
            {
                try
                {
                    result = new List <IBinaryDataListItem> {
                        _entry.FetchScalar()
                    };
                }
                catch (Exception ex)
                {
                    Dev2Logger.Log.Error(ex);
                    // We trap because we want the result if successful else default to empty list
                }
                _iterIdx++;
            }

            return(result);
        }
        public void Can_Sub_Recordset_With_Index_Expect()
        {
            var                  dataListCompiler = DataListFactory.CreateDataListCompiler();
            ErrorResultTO        errors;
            IBinaryDataListEntry binaryDataListEntry = dataListCompiler.Evaluate(_dl2.UID, enActionType.User, "[[recset(1).f1]]", false, out errors);

            Assert.AreEqual("r1.f1.value", binaryDataListEntry.FetchScalar().TheValue);
        }
 private static void GetValue(IBinaryDataListEntry tmpEntry, IDev2Definition defn)
 {
     if (String.IsNullOrEmpty(defn.RecordSetName))
     {
         tmpEntry.FetchScalar(); // ask trav what this side effect means
     }
     else
     {
         string error;
         tmpEntry.MakeRecordsetEvaluateReady(GlobalConstants.AllIndexes, GlobalConstants.AllColumns, out error);
     }
 }
        public void Iteration_Evaluation_Expect_Evaluation_For_1_Iteration()
        {
            // Iteration evaluation is tested via the shape method ;)
            var          compiler = DataListFactory.CreateDataListCompiler();
            const string defs     = @"<Inputs><Input Name=""scalar1"" Source=""[[myScalar]]"" /></Inputs>";
            Guid         id       = compiler.Shape(_dl1.UID, enDev2ArgumentType.Input, defs, out _errors);

            IBinaryDataList bdl = compiler.FetchBinaryDataList(id, out _errors);

            bdl.TryGetEntry("scalar1", out _entry, out _error);

            var res = _entry.FetchScalar().TheValue;

            Assert.AreEqual("[[otherScalar]]", res);
        }
        /// <summary>
        /// Processes the scalar.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <returns></returns>
        private string ProcessScalar(IBinaryDataListEntry entry)
        {
            StringBuilder       result = new StringBuilder();
            string              fName  = entry.Namespace;
            IBinaryDataListItem val    = entry.FetchScalar();

            if (val != null)
            {
                result.Append("\"");
                result.Append(fName);
                result.Append("\":\"");
                result.Append(val.TheValue);
                result.Append("\"");
            }

            return(result.ToString());
        }
示例#9
0
        /// <summary>
        /// Gets a value from data list for a expression.
        /// </summary>
        /// <param name="expression">The expression to find the value for.</param>
        /// <param name="datalistID">The datalist unique identifier.</param>
        /// <param name="compiler">The compiler.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception"></exception>
        private static string GetValueFromDataList(string expression, Guid datalistID, IDataListCompiler compiler)
        {
            expression = DataListUtil.AddBracketsToValueIfNotExist(expression);
            ErrorResultTO errors;

            IBinaryDataListEntry returnedEntry = compiler.Evaluate(datalistID, enActionType.User, expression, false, out errors);

            if (returnedEntry == null)
            {
                throw new Exception(errors.MakeUserReady());
            }

            IBinaryDataListItem item = returnedEntry.FetchScalar();
            string result            = item.TheValue;

            return(result);
        }
        static string GetValueForDecisionVariable(Guid dlId, string decisionColumn)
        {
            if (!String.IsNullOrEmpty(decisionColumn))
            {
                IBinaryDataListItem  binaryDataListItem = null;
                ErrorResultTO        errors;
                IBinaryDataListEntry entry = Compiler.Evaluate(dlId, enActionType.User, decisionColumn, false, out errors);
                if (entry != null && entry.IsRecordset)
                {
                    string error;
                    var    indexType = DataListUtil.GetRecordsetIndexType(decisionColumn);
                    if (indexType == enRecordsetIndexType.Numeric)
                    {
                        var index      = int.Parse(DataListUtil.ExtractIndexRegionFromRecordset(decisionColumn));
                        var columnName = DataListUtil.ExtractFieldNameFromValue(decisionColumn);

                        binaryDataListItem = entry.TryFetchRecordsetColumnAtIndex(columnName, index, out error);
                    }
                    else
                    {
                        binaryDataListItem = entry.TryFetchLastIndexedRecordsetUpsertPayload(out error);
                    }
                }
                else
                {
                    if (entry != null)
                    {
                        binaryDataListItem = entry.FetchScalar();
                    }
                }
                if (binaryDataListItem != null)
                {
                    var value = binaryDataListItem.TheValue;
                    // handle \n coming from value ;)
                    value = value.Replace("\r\n", "__R__N__");
                    value = value.Replace("\n", "\r\n");
                    value = value.Replace("__R__N__", "\r\n");
                    return(value);
                }
            }
            return(null);
        }
示例#11
0
        /// <summary>
        /// Evaluates the function.
        /// </summary>
        /// <param name="expressionTO">The expression TO.</param>
        /// <param name="curDLID">The cur DLID.</param>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        public string EvaluateFunction(IEvaluationFunction expressionTO, Guid curDLID, out ErrorResultTO errors)
        {
            string            expression = expressionTO.Function;
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();
            SyntaxTreeBuilder builder    = new SyntaxTreeBuilder();
            ErrorResultTO     allErrors  = new ErrorResultTO();


            // Travis.Frisinger : 31.01.2013 - Hi-jack this and evaluate all our internal
            IBinaryDataListEntry bde = compiler.Evaluate(curDLID, enActionType.CalculateSubstitution, expression, false, out errors);

            allErrors.MergeErrors(errors);
            if (bde != null)
            {
                expression = bde.FetchScalar().TheValue;
                if (expression.StartsWith("\""))
                {
                    expression = expression.Replace("\"", "").Trim();
                }
            }

            Node[] nodes  = builder.Build(expression);
            string result = string.Empty;

            if (builder.EventLog.HasEventLogs)
            {
                IEnumerable <string> err = EvaluateEventLogs(expression);

                foreach (string e in err)
                {
                    allErrors.AddError(e);
                }
            }
            else
            {
                List <Node> allNodes = new List <Node>();
                nodes[0].CollectNodes(allNodes);

                IterationNodeValueSource valueSource = null;
                bool startedIteration          = false;
                bool isIteration               = false;
                bool pendingIterationRecordSet = false;
                int  maxRecords    = -1;
                int  currentRecord = 0;

                do
                {
                    if (startedIteration)
                    {
                        foreach (Node t in allNodes)
                        {
                            t.EvaluatedValue = null;
                        }
                    }

                    for (int i = allNodes.Count - 1; i >= 0; i--)
                    {
                        if (allNodes[i] is IterationNode)
                        {
                            IterationNode refNode = allNodes[i] as IterationNode;
                            if (valueSource == null)
                            {
                                valueSource = new IterationNodeValueSource(1);
                            }
                            refNode.ValueSource       = valueSource;
                            pendingIterationRecordSet = true;
                            isIteration = true;
                        }
                        else if (allNodes[i] is DatalistRecordSetNode)
                        {
                            DatalistRecordSetNode refNode = allNodes[i] as DatalistRecordSetNode;

                            if (refNode.Parameter != null)
                            {
                                if ((refNode.Parameter.Items != null && refNode.Parameter.Items.Length != 0) || refNode.Parameter.Statement != null)
                                {
                                    refNode.Parameter.EvaluatedValue = InternalEval(refNode.Parameter.GetEvaluatedValue());
                                }
                            }


                            // this way we fetch the correct field with the data...
                            IBinaryDataListEntry e = compiler.Evaluate(curDLID, enActionType.User, refNode.GetRepresentationForEvaluation(), false, out errors);
                            allErrors.MergeErrors(errors);
                            string error;
                            refNode.EvaluatedValue = e.TryFetchLastIndexedRecordsetUpsertPayload(out error).TheValue;
                            allErrors.AddError(error);

                            if (pendingIterationRecordSet)
                            {
                                pendingIterationRecordSet = false;

                                if (refNode.NestedIdentifier != null)
                                {
                                    allErrors.AddError("An error occurred while parsing { " + expression + " } Iteration operator can not be used with nested recordset identifiers.");
                                    break;
                                }

                                string evaluateRecordLeft = refNode.GetRepresentationForEvaluation();
                                evaluateRecordLeft = evaluateRecordLeft.Substring(2, evaluateRecordLeft.IndexOf('(') - 2);

                                int                  totalRecords = 0;
                                IBinaryDataList      bdl          = compiler.FetchBinaryDataList(curDLID, out errors);
                                IBinaryDataListEntry entry;
                                if (bdl.TryGetEntry(evaluateRecordLeft, out entry, out error))
                                {
                                    totalRecords = entry.FetchLastRecordsetIndex();
                                }
                                allErrors.AddError(error);

                                maxRecords = Math.Max(totalRecords, maxRecords);
                            }
                        }
                        else if (allNodes[i] is DatalistReferenceNode)
                        {
                            DatalistReferenceNode refNode = allNodes[i] as DatalistReferenceNode;
                            IBinaryDataListEntry  entry   = compiler.Evaluate(curDLID, enActionType.User, refNode.GetRepresentationForEvaluation(), false, out errors);
                            allErrors.MergeErrors(errors);

                            if (entry.IsRecordset)
                            {
                                string error;
                                refNode.EvaluatedValue = entry.TryFetchLastIndexedRecordsetUpsertPayload(out error).TheValue;
                                double testParse;
                                if (!Double.TryParse(refNode.EvaluatedValue, out testParse))
                                {
                                    refNode.EvaluatedValue = String.Concat("\"", refNode.EvaluatedValue, "\"");                                                        //Bug 6438
                                }
                            }
                            else
                            {
                                refNode.EvaluatedValue = entry.FetchScalar().TheValue;
                                double testParse;
                                if (!Double.TryParse(refNode.EvaluatedValue, out testParse))
                                {
                                    refNode.EvaluatedValue = String.Concat("\"", refNode.EvaluatedValue, "\"");                                                        //Bug 6438
                                }
                            }
                        }
                        else if (allNodes[i] is BinaryOperatorNode && allNodes[i].Identifier.Start.Definition == TokenKind.Colon)
                        {
                            BinaryOperatorNode biNode = (BinaryOperatorNode)allNodes[i];

                            if (!(biNode.Left is DatalistRecordSetFieldNode))
                            {
                                allErrors.AddError("An error occurred while parsing { " + expression + " } Range operator can only be used with record set fields.");
                                break;
                            }

                            if (!(biNode.Right is DatalistRecordSetFieldNode))
                            {
                                allErrors.AddError("An error occurred while parsing { " + expression + " } Range operator can only be used with record set fields.");
                                break;
                            }

                            DatalistRecordSetFieldNode fieldLeft  = (DatalistRecordSetFieldNode)biNode.Left;
                            DatalistRecordSetFieldNode fieldRight = (DatalistRecordSetFieldNode)biNode.Right;

                            string evaluateFieldLeft  = (fieldLeft.Field != null) ? fieldLeft.Field.GetEvaluatedValue() : fieldLeft.Identifier.Content;
                            string evaluateFieldRight = (fieldRight.Field != null) ? fieldRight.Field.GetEvaluatedValue() : fieldRight.Identifier.Content;

                            if (!String.Equals(evaluateFieldLeft, evaluateFieldRight, StringComparison.Ordinal))
                            {
                                allErrors.AddError("An error occurred while parsing { " + expression + " } Range operator must be used with the same record set fields.");
                                break;
                            }

                            string evaluateRecordLeft = fieldLeft.RecordSet.GetRepresentationForEvaluation();
                            evaluateRecordLeft = evaluateRecordLeft.Substring(2, evaluateRecordLeft.IndexOf('(') - 2);
                            string evaluateRecordRight = fieldRight.RecordSet.GetRepresentationForEvaluation();
                            evaluateRecordRight = evaluateRecordRight.Substring(2, evaluateRecordRight.IndexOf('(') - 2);

                            if (!String.Equals(evaluateRecordLeft, evaluateRecordRight, StringComparison.Ordinal))
                            {
                                allErrors.AddError("An error occurred while parsing { " + expression + " } Range operator must be used with the same record sets.");
                                break;
                            }

                            int                  totalRecords = 0;
                            IBinaryDataList      bdl          = compiler.FetchBinaryDataList(curDLID, out errors);
                            string               error;
                            IBinaryDataListEntry entry;
                            if (bdl.TryGetEntry(evaluateRecordLeft, out entry, out error))
                            {
                                totalRecords = entry.FetchLastRecordsetIndex();
                            }

                            string rawParamLeft = fieldLeft.RecordSet.Parameter.GetEvaluatedValue();
                            rawParamLeft = rawParamLeft.Length == 2 ? "" : rawParamLeft.Substring(1, rawParamLeft.Length - 2);
                            string rawParamRight = fieldRight.RecordSet.Parameter.GetEvaluatedValue();
                            rawParamRight = rawParamRight.Length == 2 ? "" : rawParamRight.Substring(1, rawParamRight.Length - 2);

                            int startIndex;
                            int endIndex;

                            if (!String.IsNullOrEmpty(rawParamLeft))
                            {
                                if (!Int32.TryParse(rawParamLeft, out startIndex) || startIndex <= 0)
                                {
                                    allErrors.AddError("An error occurred while parsing { " + expression + " } Recordset index must be a positive whole number that is greater than zero.");
                                    break;
                                }
                            }
                            else
                            {
                                startIndex = 1;
                            }

                            if (!String.IsNullOrEmpty(rawParamRight))
                            {
                                if (!Int32.TryParse(rawParamRight, out endIndex) || endIndex <= 0)
                                {
                                    allErrors.AddError("An error occurred while parsing { " + expression + " } Recordset index must be a positive whole number that is greater than zero.");
                                    break;
                                }

                                if (endIndex > totalRecords)
                                {
                                    allErrors.AddError("An error occurred while parsing { " + expression + " } Recordset end index must be a positive whole number that is less than the number of entries in the recordset.");
                                    break;
                                }
                            }
                            else
                            {
                                endIndex = totalRecords;
                            }

                            endIndex++;

                            StringBuilder rangeBuilder = new StringBuilder();

                            for (int k = startIndex; k < endIndex; k++)
                            {
                                if (k != startIndex)
                                {
                                    rangeBuilder.Append("," + entry.TryFetchRecordsetColumnAtIndex(evaluateFieldLeft, k, out error).TheValue);
                                    allErrors.AddError(error);
                                }
                                else
                                {
                                    rangeBuilder.Append(entry.TryFetchRecordsetColumnAtIndex(evaluateFieldLeft, k, out error).TheValue);
                                    allErrors.AddError(error);
                                }
                            }
                            allNodes[i].EvaluatedValue = rangeBuilder.ToString();
                        }
                    }

                    string evaluatedValue = nodes[0].GetEvaluatedValue();
                    result = InternalEval(evaluatedValue);

                    if (startedIteration)
                    {
                        currentRecord = valueSource.Index++;
                    }

                    if (isIteration && !startedIteration)
                    {
                        startedIteration = true;
                        currentRecord    = valueSource.Index++;
                    }
                }while(startedIteration && currentRecord < maxRecords);
            }

            errors = allErrors;

            return(result);
        }
        IList <IDataListItem> ConvertIBinaryDataListEntryToIDataListItem(IBinaryDataListEntry dataListEntry)
        {
            IList <IDataListItem> result = new List <IDataListItem>();

            if (dataListEntry.IsRecordset)
            {
                var sizeOfCollection = dataListEntry.ItemCollectionSize();
                if (sizeOfCollection == 0)
                {
                    sizeOfCollection++;
                }
                var count = 0;

                var fields = dataListEntry.Columns.Where(c => c.ColumnIODirection == enDev2ColumnArgumentDirection.Both || c.ColumnIODirection == enDev2ColumnArgumentDirection.Input).ToList();

                while (count < sizeOfCollection)
                {
                    string error;
                    var    items = dataListEntry.FetchRecordAt(count + 1, out error);
                    foreach (var item in items)
                    {
                        // check field mapping ;)
                        if (fields.Any(f => f.ColumnName == item.FieldName))
                        {
                            IDataListItem singleRes = new DataListItem();
                            singleRes.IsRecordset    = true;
                            singleRes.Recordset      = item.Namespace;
                            singleRes.Field          = item.FieldName;
                            singleRes.RecordsetIndex = (count + 1).ToString(CultureInfo.InvariantCulture);
                            try
                            {
                                singleRes.Value = item.TheValue;
                            }
                            catch (Exception)
                            {
                                singleRes.Value = null;
                            }

                            singleRes.DisplayValue = item.DisplayValue;
                            var desc = dataListEntry.Columns.FirstOrDefault(c => c.ColumnName == item.FieldName);
                            singleRes.Description = desc == null ? null : desc.ColumnDescription;
                            result.Add(singleRes);
                        }
                    }
                    count++;
                }
            }
            else
            {
                var item = dataListEntry.FetchScalar();
                if (item != null)
                {
                    IDataListItem singleRes = new DataListItem();
                    singleRes.IsRecordset  = false;
                    singleRes.Field        = item.FieldName;
                    singleRes.DisplayValue = item.FieldName;
                    try
                    {
                        singleRes.Value = item.TheValue;
                    }
                    catch (Exception)
                    {
                        singleRes.Value = null;
                    }
                    var desc = dataListEntry.Description;
                    singleRes.Description = string.IsNullOrWhiteSpace(desc) ? null : desc;
                    result.Add(singleRes);
                }
            }
            return(result);
        }
        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;
        }
        IList<IDataListItem> ConvertIBinaryDataListEntryToIDataListItem(IBinaryDataListEntry dataListEntry)
        {
            IList<IDataListItem> result = new List<IDataListItem>();
            if(dataListEntry.IsRecordset)
            {
                var sizeOfCollection = dataListEntry.ItemCollectionSize();
                if(sizeOfCollection == 0) { sizeOfCollection++; }
                var count = 0;

                var fields = dataListEntry.Columns.Where(c => c.ColumnIODirection == enDev2ColumnArgumentDirection.Both || c.ColumnIODirection == enDev2ColumnArgumentDirection.Input).ToList();

                while(count < sizeOfCollection)
                {
                    string error;
                    var items = dataListEntry.FetchRecordAt(count + 1, out error);
                    foreach(var item in items)
                    {
                        // check field mapping ;)
                        if(fields.Any(f => f.ColumnName == item.FieldName))
                        {
                            IDataListItem singleRes = new DataListItem();
                            singleRes.IsRecordset = true;
                            singleRes.Recordset = item.Namespace;
                            singleRes.Field = item.FieldName;
                            singleRes.RecordsetIndex = (count + 1).ToString(CultureInfo.InvariantCulture);
                            try
                            {
                                singleRes.Value = item.TheValue;
                            }
                            catch(Exception)
                            {
                                singleRes.Value = null;
                            }

                            singleRes.DisplayValue = item.DisplayValue;
                            var desc = dataListEntry.Columns.FirstOrDefault(c => c.ColumnName == item.FieldName);
                            singleRes.Description = desc == null ? null : desc.ColumnDescription;
                            result.Add(singleRes);
                        }
                    }
                    count++;
                }
            }
            else
            {
                var item = dataListEntry.FetchScalar();
                if(item != null)
                {
                    IDataListItem singleRes = new DataListItem();
                    singleRes.IsRecordset = false;
                    singleRes.Field = item.FieldName;
                    singleRes.DisplayValue = item.FieldName;
                    try
                    {
                        singleRes.Value = item.TheValue;
                    }
                    catch(Exception)
                    {
                        singleRes.Value = null;
                    }
                    var desc = dataListEntry.Description;
                    singleRes.Description = string.IsNullOrWhiteSpace(desc) ? null : desc;
                    result.Add(singleRes);
                }
            }
            return result;
        }
        /// <summary>
        /// Processes the scalar.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <returns></returns>
        private string ProcessScalar(IBinaryDataListEntry entry)
        {
            StringBuilder result = new StringBuilder();
            string fName = entry.Namespace;
            IBinaryDataListItem val = entry.FetchScalar();

            if(val != null)
            {
                result.Append("\"");
                result.Append(fName);
                result.Append("\":\"");
                result.Append(val.TheValue);
                result.Append("\"");
            }

            return result.ToString();
        }
示例#16
0
        /// <summary>
        /// Depths the merge.
        /// </summary>
        /// <param name="depth">The depth.</param>
        /// <param name="cloned">The cloned.</param>
        /// <param name="key"></param>
        /// <param name="errors">The errors.</param>
        private void DepthMerge(enTranslationDepth depth, IBinaryDataListEntry cloned, string key, out IList <string> errors)
        {
            errors = new List <string>();

            if (key != null)
            {
                if (depth == enTranslationDepth.Data || depth == enTranslationDepth.Data_With_Blank_OverWrite)
                {
                    // safe to add
                    if (cloned.IsRecordset)
                    {
                        // Inject into the intellisense options...
                        CreateIntelliseneResult(key, cloned.Columns);

                        //Massimo.Guerrera - 21-01-2013 - Added for the DeleteRecordOperation, it need to over write the data with blank values.
                        if (depth == enTranslationDepth.Data_With_Blank_OverWrite)
                        {
                            _templateDict[key] = cloned;
                        }
                        else
                        {
                            // merge all the cloned rows into this reference

#pragma warning disable 219
                            int insertIdx = 1; // always default to start of recordset
#pragma warning restore 219
                            // fetch last row id and build from there
                            IBinaryDataListEntry tmpRec;
                            bool isFound = _templateDict.TryGetValue(key, out tmpRec);
                            // verify that the key exist first ;)

                            IIndexIterator ii = cloned.FetchRecordsetIndexes();
                            while (ii.HasMore())
                            {
                                int    next = ii.FetchNextIndex();
                                string error;
                                IList <IBinaryDataListItem> cols = cloned.FetchRecordAt(next, out error);
                                if (error != string.Empty)
                                {
                                    errors.Add(error);
                                }

                                if (!isFound)
                                {
                                    // we need to boot strap the recordset ;)
                                    // intellisense takecare of with template method ;)
                                    TryCreateRecordsetTemplate(cloned.Namespace, cloned.Description, cloned.Columns, true, out error);
                                    if (error != string.Empty)
                                    {
                                        errors.Add(error);
                                    }
                                    isFound = true;
                                }

                                foreach (IBinaryDataListItem itm in cols)
                                {
                                    _templateDict[key].TryPutRecordItemAtIndex(itm, next, out error);
                                    if (error != string.Empty)
                                    {
                                        errors.Add(error);
                                    }
                                }
                                insertIdx++;
                            }
                        }
                    }
                    else
                    {
                        IBinaryDataListEntry thisTmp;
                        // we have an entry, better check clone for empty
                        if (_templateDict.TryGetValue(key, out thisTmp))
                        {
                            string theValue = null;
                            try
                            {
                                theValue = cloned.FetchScalar().TheValue;
                            }
                            catch (Exception e)
                            {
                                Dev2Logger.Log.Error(e);
                            }
                            if (theValue != string.Empty && depth == enTranslationDepth.Data)
                            {
                                // The clone has data, over write it on the merge ;)
                                _templateDict[key] = cloned;
                                // Inject into the intellisense options...
                                CreateIntelliseneResult(key);
                            }
                            else if (depth == enTranslationDepth.Data_With_Blank_OverWrite)
                            {
                                // The user wants to over-write Blank data on the right with existing data on the left ;)
                                _templateDict[key] = cloned;
                                // Inject into the intellisense options...
                                CreateIntelliseneResult(key);
                            }
                        }
                        else
                        {
                            // no entry, just place it there as there is no harm ;)
                            _templateDict[key] = cloned;
                            // Inject into the intellisense options...
                            CreateIntelliseneResult(key);
                        }
                    }
                }
                else if (depth == enTranslationDepth.Shape)
                {
                    _templateDict[key] = cloned; // set blank data ;)
                    // Inject into the intellisense options...
                    CreateIntelliseneResult(key);
                }
            }
        }
        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>
        /// Depths the merge.
        /// </summary>
        /// <param name="depth">The depth.</param>
        /// <param name="cloned">The cloned.</param>
        /// <param name="key"></param>
        /// <param name="errors">The errors.</param>
        private void DepthMerge(enTranslationDepth depth, IBinaryDataListEntry cloned, string key, out IList<string> errors)
        {
            errors = new List<string>();

            if(key != null)
            {

                if(depth == enTranslationDepth.Data || depth == enTranslationDepth.Data_With_Blank_OverWrite)
                {

                    // safe to add
                    if(cloned.IsRecordset)
                    {

                        // Inject into the intellisense options...
                        CreateIntelliseneResult(key, cloned.Columns);

                        //Massimo.Guerrera - 21-01-2013 - Added for the DeleteRecordOperation, it need to over write the data with blank values.
                        if(depth == enTranslationDepth.Data_With_Blank_OverWrite)
                        {
                            _templateDict[key] = cloned;
                        }
                        else
                        {
                            // merge all the cloned rows into this reference

#pragma warning disable 219
                            // ReSharper disable NotAccessedVariable
                            int insertIdx = 1; // always default to start of recordset
                            // ReSharper restore NotAccessedVariable
#pragma warning restore 219
                            // fetch last row id and build from there
                            IBinaryDataListEntry tmpRec;
                            bool isFound = _templateDict.TryGetValue(key, out tmpRec);
                            // verify that the key exist first ;)

                            IIndexIterator ii = cloned.FetchRecordsetIndexes();
                            while(ii.HasMore())
                            {
                                int next = ii.FetchNextIndex();
                                string error;
                                IList<IBinaryDataListItem> cols = cloned.FetchRecordAt(next, out error);
                                if(error != string.Empty)
                                {
                                    errors.Add(error);
                                }

                                if(!isFound)
                                {
                                    // we need to boot strap the recordset ;)
                                    // intellisense takecare of with template method ;)
                                    TryCreateRecordsetTemplate(cloned.Namespace, cloned.Description, cloned.Columns, true, out error);
                                    if(error != string.Empty)
                                    {
                                        errors.Add(error);
                                    }
                                    isFound = true;
                                }

                                foreach(IBinaryDataListItem itm in cols)
                                {
                                    _templateDict[key].TryPutRecordItemAtIndex(itm, next, out error);
                                    if(error != string.Empty)
                                    {
                                        errors.Add(error);
                                    }
                                }
                                insertIdx++;
                            }

                        }
                    }
                    else
                    {
                        IBinaryDataListEntry thisTmp;
                        // we have an entry, better check clone for empty
                        if(_templateDict.TryGetValue(key, out thisTmp))
                        {
                            string theValue = null;
                            try
                            {
                                theValue = cloned.FetchScalar().TheValue;
                            }
                            catch(Exception e)
                            {
                                Dev2Logger.Log.Error(e);
                            }
                            if(theValue != string.Empty && depth == enTranslationDepth.Data)
                            {
                                // The clone has data, over write it on the merge ;)
                                _templateDict[key] = cloned;
                                // Inject into the intellisense options...
                                CreateIntelliseneResult(key);
                            }
                            else if(depth == enTranslationDepth.Data_With_Blank_OverWrite)
                            {
                                // The user wants to over-write Blank data on the right with existing data on the left ;)
                                _templateDict[key] = cloned;
                                // Inject into the intellisense options...
                                CreateIntelliseneResult(key);
                            }
                        }
                        else
                        {
                            // no entry, just place it there as there is no harm ;)
                            _templateDict[key] = cloned;
                            // Inject into the intellisense options...
                            CreateIntelliseneResult(key);
                        }
                    }
                }
                else if(depth == enTranslationDepth.Shape)
                {
                    _templateDict[key] = cloned; // set blank data ;)
                    // Inject into the intellisense options...
                    CreateIntelliseneResult(key);
                }
            }
        }
示例#19
0
        /// <summary>
        /// Evaluates the system entry.
        /// </summary>
        /// <param name="curDlid">The cur DL ID.</param>
        /// <param name="sysTag">The system tag.</param>
        /// <param name="errors">The errors.</param>
        /// <returns></returns>
        public string EvaluateSystemEntry(Guid curDlid, enSystemTag sysTag, out ErrorResultTO errors)
        {
            IBinaryDataListEntry binaryDataListEntry = _svrCompiler.Evaluate(null, curDlid, enActionType.System, sysTag.ToString(), out errors) ?? DataListConstants.baseEntry;

            return(binaryDataListEntry.FetchScalar().TheValue);
        }
        // ReSharper restore RedundantOverridenMember

        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();
            Guid executionId             = dataObject.DataListID;

            ErrorResultTO allErrors = new ErrorResultTO();
            ErrorResultTO errors    = new ErrorResultTO();

            InitializeDebug(dataObject);
            try
            {
                ValidateRecordsetName(RecordsetName, errors);
                allErrors.MergeErrors(errors);

                if (!allErrors.HasErrors())
                {
                    var tmpRecsetIndex = DataListUtil.ExtractIndexRegionFromRecordset(RecordsetName);
                    IBinaryDataListEntry indexEntry = compiler.Evaluate(executionId, enActionType.User, tmpRecsetIndex, false, out errors);

                    IDev2DataListEvaluateIterator itr        = Dev2ValueObjectFactory.CreateEvaluateIterator(indexEntry);
                    IDev2IteratorCollection       collection = Dev2ValueObjectFactory.CreateIteratorCollection();
                    collection.AddIterator(itr);

                    while (collection.HasMoreData())
                    {
                        var evaluatedRecordset = RecordsetName.Remove(RecordsetName.IndexOf("(", StringComparison.Ordinal) + 1) + collection.FetchNextRow(itr).TheValue + ")]]";
                        if (dataObject.IsDebugMode())
                        {
                            IBinaryDataListEntry tmpentry = compiler.Evaluate(executionId, enActionType.User, evaluatedRecordset, false, out errors);
                            AddDebugInputItem(new DebugItemVariableParams(RecordsetName, "Records", tmpentry, executionId));
                        }

                        IBinaryDataListEntry entry = compiler.Evaluate(executionId, enActionType.Internal, evaluatedRecordset, false, out errors);

                        allErrors.MergeErrors(errors);
                        compiler.Upsert(executionId, Result, entry.FetchScalar().TheValue, out errors);

                        if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                        {
                            AddDebugOutputItem(new DebugItemVariableParams(Result, "", entry, executionId));
                        }
                        allErrors.MergeErrors(errors);
                    }
                }
            }
            catch (Exception e)
            {
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfDeleteRecordsActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                    compiler.Upsert(executionId, Result, (string)null, out errors);
                }

                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }