Ejemplo n.º 1
0
        string GetGroupName(string displayExpression, string rawExpression, ref int grpIdx, ref string item, ref string groupName)
        {
            var expr = displayExpression;

            if (displayExpression.Contains("().") || displayExpression.Contains("(*)."))
            {
                grpIdx++;
                var index = grpIdx.ToString(CultureInfo.InvariantCulture);
                if (rawExpression.Contains(".WarewolfPositionColumn"))
                {
                    index = item;
                    item  = "";
                }
                groupName = rawExpression.Replace(".WarewolfPositionColumn", "");
                expr      = DataListUtil.AddBracketsToValueIfNotExist(DataListUtil.CreateRecordsetDisplayValue(DataListUtil.ExtractRecordsetNameFromValue(_variable), DataListUtil.ExtractFieldNameFromValue(_variable), index)).Replace(".WarewolfPositionColumn", "");
            }
            else
            {
                var indexRegionFromRecordset = DataListUtil.ExtractIndexRegionFromRecordset(expr);
                int.TryParse(indexRegionFromRecordset, out int indexForRecset);

                if (indexForRecset > 0)
                {
                    var indexOfOpenningBracket = expr.IndexOf("(", StringComparison.Ordinal) + 1;
                    var group = expr.Substring(0, indexOfOpenningBracket) + "*" + expr.Substring(indexOfOpenningBracket + indexRegionFromRecordset.Length);
                    grpIdx++;
                    groupName = @group;
                }
            }
            return(expr);
        }
Ejemplo n.º 2
0
        private static void AddEntireRecsetGroup(IExecutionEnvironment environment, IGrouping <string, IServiceTestOutput> groupedRecset)
        {
            var dataListItems = groupedRecset.GroupBy(item => DataListUtil.ExtractIndexRegionFromRecordset(item.Variable));

            foreach (var dataListItem in dataListItems)
            {
                var recSetsToAssign = new List <IServiceTestOutput>();
                var empty           = true;
                foreach (var listItem in dataListItem)
                {
                    if (!string.IsNullOrEmpty(listItem.Value))
                    {
                        empty = false;
                    }
                    recSetsToAssign.Add(listItem);
                }
                if (!empty)
                {
                    foreach (var serviceTestInput in recSetsToAssign)
                    {
                        environment.Assign(DataListUtil.AddBracketsToValueIfNotExist(serviceTestInput.Variable), serviceTestInput.Value, 0);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 private static void AddRecordsetsOutputs(IEnumerable <IServiceTestOutput> recSets, IExecutionEnvironment environment)
 {
     if (recSets != null)
     {
         var groupedRecsets = recSets.GroupBy(item => DataListUtil.ExtractRecordsetNameFromValue(item.Variable));
         foreach (var groupedRecset in groupedRecsets)
         {
             var dataListItems = groupedRecset.GroupBy(item => DataListUtil.ExtractIndexRegionFromRecordset(item.Variable));
             foreach (var dataListItem in dataListItems)
             {
                 List <IServiceTestOutput> recSetsToAssign = new List <IServiceTestOutput>();
                 var empty = true;
                 foreach (var listItem in dataListItem)
                 {
                     if (!string.IsNullOrEmpty(listItem.Value))
                     {
                         empty = false;
                     }
                     recSetsToAssign.Add(listItem);
                 }
                 if (!empty)
                 {
                     foreach (var serviceTestInput in recSetsToAssign)
                     {
                         environment.Assign(DataListUtil.AddBracketsToValueIfNotExist(serviceTestInput.Variable), serviceTestInput.Value, 0);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
        public static void ProcessOutputMapping(IExecutionEnvironment environment, int update, ref bool started, ref int rowIdx, DataRow row, IServiceOutputMapping serviceOutputMapping)
        {
            var rsType   = DataListUtil.GetRecordsetIndexType(serviceOutputMapping.MappedTo);
            var rowIndex = DataListUtil.ExtractIndexRegionFromRecordset(serviceOutputMapping.MappedTo);

            var rs = serviceOutputMapping.RecordSetName;

            if (!string.IsNullOrEmpty(rs) && environment.HasRecordSet(DataListUtil.AddBracketsToValueIfNotExist(DataListUtil.MakeValueIntoHighLevelRecordset(rs, rsType == enRecordsetIndexType.Star))))
            {
                if (started)
                {
                    rowIdx  = environment.GetLength(rs) + 1;
                    started = false;
                }
            }
            else
            {
                try
                {
                    environment.AssignDataShape(serviceOutputMapping.MappedTo);
                }
                catch (Exception e)
                {
                    Dev2Logger.Error(e, GlobalConstants.WarewolfError);
                }
            }

            GetRowIndex(ref started, ref rowIdx, rsType, rowIndex);
            if (!row.Table.Columns.Contains(serviceOutputMapping.MappedFrom))
            {
                return;
            }

            var value = row[serviceOutputMapping.MappedFrom];

            var colDataType = row.Table.Columns[serviceOutputMapping.MappedFrom].DataType;

            if (colDataType.Name == "Byte[]")
            {
                value = Encoding.UTF8.GetString(value as byte[]);
            }

            if (update != 0)
            {
                rowIdx = update;
            }

            var displayExpression = DataListUtil.ReplaceRecordsetBlankWithIndex(DataListUtil.AddBracketsToValueIfNotExist(serviceOutputMapping.MappedTo), rowIdx);

            if (rsType == enRecordsetIndexType.Star)
            {
                displayExpression = DataListUtil.ReplaceStarWithFixedIndex(displayExpression, rowIdx);
            }

            environment.Assign(displayExpression, value.ToString(), update);
        }
Ejemplo n.º 5
0
 static void CheckIndex(string toCheck)
 {
     if (!String.IsNullOrEmpty(toCheck) && DataListUtil.IsEvaluated(toCheck) && DataListUtil.IsValueRecordset(toCheck) && DataListUtil.GetRecordsetIndexType(toCheck) == enRecordsetIndexType.Numeric)
     {
         int index;
         if (!int.TryParse(DataListUtil.ExtractIndexRegionFromRecordset(toCheck), out index) || index < 0)
         {
             throw new Exception(string.Format("Invalid numeric index for Recordset {0}", toCheck));
         }
     }
 }
Ejemplo n.º 6
0
        static void ObjectGroupName(ref int grpIdx, string displayExpression, ref string groupName)
        {
            var indexRegionFromRecordset = DataListUtil.ExtractIndexRegionFromRecordset(displayExpression);

            int.TryParse(indexRegionFromRecordset, out int indexForRecset);

            if (indexForRecset > 0)
            {
                var indexOfOpenningBracket = displayExpression.IndexOf("(", StringComparison.Ordinal) + 1;
                var group = displayExpression.Substring(0, indexOfOpenningBracket) + "*" + displayExpression.Substring(indexOfOpenningBracket + indexRegionFromRecordset.Length);
                grpIdx++;
                groupName = @group;
            }
        }
Ejemplo n.º 7
0
 static void AddRecordsetsInputs(IEnumerable <IServiceTestInput> recSets, IExecutionEnvironment environment)
 {
     if (recSets != null)
     {
         var groupedRecsets = recSets.GroupBy(item => DataListUtil.ExtractRecordsetNameFromValue(item.Variable));
         foreach (var groupedRecset in groupedRecsets)
         {
             var dataListItems = groupedRecset.GroupBy(item => DataListUtil.ExtractIndexRegionFromRecordset(item.Variable));
             foreach (var dataListItem in dataListItems)
             {
                 AddRecordsetInput(environment, dataListItem);
             }
         }
     }
 }
Ejemplo n.º 8
0
 public void AddNewOutput(string varName)
 {
     if (DataListUtil.IsValueRecordset(varName))
     {
         if (DataListUtil.GetRecordsetIndexType(varName) == enRecordsetIndexType.Numeric)
         {
             var extractedIndex = DataListUtil.ExtractIndexRegionFromRecordset(varName);
             int intIndex;
             if (int.TryParse(extractedIndex, out intIndex))
             {
                 intIndex++;
                 var blankName   = DataListUtil.ReplaceRecordsetIndexWithBlank(varName);
                 var indexedName = DataListUtil.ReplaceRecordsetBlankWithIndex(blankName, intIndex);
                 if (StepOutputs.FirstOrDefault(output => output.Variable.Equals(indexedName, StringComparison.InvariantCultureIgnoreCase)) == null)
                 {
                     var serviceTestOutput = new ServiceTestOutput(indexedName, "", "", "")
                     {
                         AddNewAction = () => AddNewOutput(indexedName)
                     };
                     StepOutputs?.Add(serviceTestOutput);
                 }
             }
         }
         else
         {
             if (StepOutputs != null && StepOutputs.Count >= 1)
             {
                 var testOutput = StepOutputs.Last();
                 if (string.IsNullOrWhiteSpace(testOutput?.Variable) && string.IsNullOrWhiteSpace(testOutput?.Value))
                 {
                     if (testOutput != null)
                     {
                         testOutput.Variable = varName;
                     }
                 }
             }
             else
             {
                 var serviceTestOutput = new ServiceTestOutput(varName, "", "", "")
                 {
                     AddNewAction = () => AddNewOutput(varName)
                 };
                 StepOutputs?.Add(serviceTestOutput);
             }
         }
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Determines whether [is recorset without field] [the specified field].
        /// </summary>
        /// <param name="field">The field.</param>
        /// <param name="recSet">The rec set.</param>
        /// <returns>
        ///   <c>true</c> if [is recorset without field] [the specified field]; otherwise, <c>false</c>.
        /// </returns>
        private bool IsRecorsetWithoutField(string field, string recSet)
        {
            bool result = false;

            if (string.IsNullOrWhiteSpace(DataListUtil.ExtractFieldNameFromValue(field)))
            {
                if (string.IsNullOrWhiteSpace(DataListUtil.ExtractIndexRegionFromRecordset(field)))
                {
                    string recsetName = DataListUtil.ExtractRecordsetNameFromValue(field);
                    if (recsetName == recSet)
                    {
                        result = true;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 10
0
        static void ProcessOutputMapping(DataTable executeService, IExecutionEnvironment environment, int update, ref bool started, ref int rowIdx, DataRow row, IServiceOutputMapping serviceOutputMapping)
        {
            var rsType   = DataListUtil.GetRecordsetIndexType(serviceOutputMapping.MappedTo);
            var rowIndex = DataListUtil.ExtractIndexRegionFromRecordset(serviceOutputMapping.MappedTo);
            var rs       = serviceOutputMapping.RecordSetName;

            if (!string.IsNullOrEmpty(rs) && environment.HasRecordSet(rs))
            {
                if (started)
                {
                    rowIdx  = environment.GetLength(rs) + 1;
                    started = false;
                }
            }
            else
            {
                try
                {
                    environment.AssignDataShape(serviceOutputMapping.MappedTo);
                }
                catch (Exception e)
                {
                    Dev2Logger.Error(e, GlobalConstants.WarewolfError);
                }
            }
            GetRowIndex(ref started, ref rowIdx, rsType, rowIndex);
            if (!executeService.Columns.Contains(serviceOutputMapping.MappedFrom) && !executeService.Columns.Contains("ReadForXml"))
            {
                return;
            }
            var value = GetColumnValue(executeService, row, serviceOutputMapping);

            if (update != 0)
            {
                rowIdx = update;
            }
            var displayExpression = DataListUtil.ReplaceRecordsetBlankWithIndex(DataListUtil.AddBracketsToValueIfNotExist(serviceOutputMapping.MappedTo), rowIdx);

            if (rsType == enRecordsetIndexType.Star)
            {
                displayExpression = DataListUtil.ReplaceStarWithFixedIndex(displayExpression, rowIdx);
            }
            environment.Assign(displayExpression, value.ToString(), update);
        }
Ejemplo n.º 11
0
        static string PerformResultInsertionForRecordsets(string input, IntellisenseProviderContext context, Region region, string replace)
        {
            string updatedInputText;
            var    caretPosition = context.CaretPosition;
            var    inputText     = context.InputText ?? string.Empty;
            var    name          = region.Name ?? string.Empty;
            var    startIndex    = region.StartIndex;

            var indexOfStringToReplace = name.IndexOf(replace, StringComparison.Ordinal);
            var recordsetIndex         = DataListUtil.ExtractIndexRegionFromRecordset(name) ?? string.Empty;

            if (indexOfStringToReplace + replace.Length == caretPosition)
            {
                if (DataListUtil.IsValueRecordsetWithFields(replace) && !DataListUtil.IsValueRecordset(replace))
                {
                    var substitude = inputText.Replace(inputText, input);

                    if (DataListUtil.IsValueRecordset(input))
                    {
                        updatedInputText = DataListUtil.IsStarIndex(name) ? substitude : substitude.Insert(inputText.IndexOf(recordsetIndex, StringComparison.Ordinal), recordsetIndex);

                        context.CaretPosition = caretPosition + (updatedInputText.Length - inputText.Length);
                        return(updatedInputText);
                    }

                    if (input.Equals(substitude))
                    {
                        updatedInputText = inputText
                                           .Remove(indexOfStringToReplace, replace.Length)
                                           .Insert(indexOfStringToReplace, ")." + input);

                        context.CaretPosition = caretPosition + (updatedInputText.Length - inputText.Length);
                        return(updatedInputText);
                    }
                }
            }

            updatedInputText = inputText.Remove(startIndex, name.Length)
                               .Insert(startIndex, input);

            context.CaretPosition = caretPosition + (updatedInputText.Length - inputText.Length);
            return(updatedInputText);
        }
        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);
        }
Ejemplo n.º 13
0
        static void AddSingleDebugResult(string rowValue, DebugItemResult debugItemResult)
        {
            var variableValuePair = rowValue.Split(new[] { " =" }, StringSplitOptions.None);

            debugItemResult.Variable = variableValuePair[0];
            debugItemResult.Value    = variableValuePair[1];
            debugItemResult.Type     = DebugItemResultType.Variable;
            var variable = debugItemResult.Variable;

            if (DataListUtil.IsValueRecordset(variable))
            {
                var indexRegionFromRecordset = DataListUtil.ExtractIndexRegionFromRecordset(variable);
                if (!string.IsNullOrEmpty(indexRegionFromRecordset))
                {
                    int indexForRecset;
                    int.TryParse(indexRegionFromRecordset, out indexForRecset);

                    List <Tuple <string, string> > variableList;
                    if (!ScenarioContext.Current.TryGetValue("variableList", out variableList))
                    {
                        return;
                    }

                    var indexType = enRecordsetIndexType.Star;
                    if (variableList.Find(tuple => tuple.Item1 == variable) != null)
                    {
                        indexType = enRecordsetIndexType.Numeric;
                    }

                    if (indexForRecset > 0 && indexType != enRecordsetIndexType.Numeric)
                    {
                        var indexOfOpenningBracket = variable.IndexOf("(", StringComparison.Ordinal) + 1;
                        debugItemResult.GroupIndex = indexForRecset;
                        var groupName = variable.Substring(0, indexOfOpenningBracket) + "*" + variable.Substring(indexOfOpenningBracket + indexRegionFromRecordset.Length);
                        debugItemResult.GroupName = variableList.Find(tuple => tuple.Item1 == groupName) != null ? groupName : groupName.Replace("*", "");
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public void AddRow(IServiceTestOutput itemToAdd, IDataListModel dataList)
        {
            if (itemToAdd != null && DataListUtil.IsValueRecordset(itemToAdd.Variable))
            {
                var recordsetNameFromValue = DataListUtil.ExtractRecordsetNameFromValue(itemToAdd.Variable);
                var recordset = dataList.ShapeRecordSets.FirstOrDefault(set => set.Name == recordsetNameFromValue);
                if (recordset == null)
                {
                    return;
                }
                var recsetCols = new List <IScalar>();
                foreach (var column in recordset.Columns)
                {
                    var cols = column.Value.Where(scalar => scalar.IODirection == enDev2ColumnArgumentDirection.Output || scalar.IODirection == enDev2ColumnArgumentDirection.Both);
                    recsetCols.AddRange(cols);
                }

                var numberOfRows = Outputs.Where(c => DataListUtil.ExtractRecordsetNameFromValue(c.Variable) == recordsetNameFromValue);
                IEnumerable <IServiceTestOutput> dataListItems = numberOfRows as IServiceTestOutput[] ?? numberOfRows.ToArray();
                var lastItem        = dataListItems.Last();
                var indexToInsertAt = Outputs.IndexOf(lastItem);
                var indexString     = DataListUtil.ExtractIndexRegionFromRecordset(lastItem.Variable);
                var indexNum        = Convert.ToInt32(indexString) + 1;
                var lastRow         = dataListItems.Where(c => DataListUtil.ExtractIndexRegionFromRecordset(c.Variable) == indexString);
                var addRow          = false;
                foreach (var item in lastRow)
                {
                    if (item.Value != string.Empty)
                    {
                        addRow = true;
                    }
                }
                if (addRow)
                {
                    AddBlankRowToRecordset(itemToAdd, recsetCols, indexToInsertAt, indexNum, dataList);
                }
            }
        }
Ejemplo n.º 15
0
        public IList <IntellisenseProviderResult> GetIntellisenseResults(IntellisenseProviderContext context)
        {
            if (context == null)
            {
                return(new List <IntellisenseProviderResult>());
            }

            if (IsDisposed)
            {
                throw new ObjectDisposedException("DefaultIntellisenseProvider");
            }

            if (!Equals(TextBox, context.TextBox))
            {
                TextBox = context.TextBox as IntellisenseTextBox;
            }
            IList <IIntellisenseResult> results;
            var input         = context.InputText ?? string.Empty;
            var caretPosition = context.CaretPosition;

            if (caretPosition > input.Length || caretPosition < 0)
            {
                return(new List <IntellisenseProviderResult>());
            }

            enIntellisensePartType       filterType       = context.FilterType;
            enIntellisensePartType       altfilterType    = context.FilterType;
            IntellisenseDesiredResultSet desiredResultSet = context.DesiredResultSet;

            string searchText     = context.FindTextToSearch();
            string recordsetIndex = string.Empty;
            string recordserName  = string.Empty;
            var    region         = input.RegionInPostion(caretPosition);
            var    regionName     = region.Name;

            if (DataListUtil.IsValueRecordset(regionName))
            {
                recordsetIndex = DataListUtil.ExtractIndexRegionFromRecordset(regionName);
                recordserName  = DataListUtil.ExtractRecordsetNameFromValue(regionName);
                if (!string.IsNullOrEmpty(recordsetIndex) && DataListUtil.IsValueRecordsetWithFields(searchText))
                {
                    altfilterType = enIntellisensePartType.RecordsetFields;
                }
            }

            if (input.Equals(DataListUtil.OpeningSquareBrackets))
            {
                searchText = context.InputText;
            }
            else
            {
                searchText = searchText.StartsWith(DataListUtil.OpeningSquareBrackets) || string.IsNullOrEmpty(searchText) ? searchText : DataListUtil.OpeningSquareBrackets + searchText;
            }

            switch (desiredResultSet)
            {
            case IntellisenseDesiredResultSet.EntireSet: results = GetIntellisenseResultsImpl(DataListUtil.OpeningSquareBrackets, filterType); break;

            default:
            {
                results = GetIntellisenseResultsImpl(searchText, filterType);
                if (results == null || results.Count == 0 && HandlesResultInsertion)
                {
                    results = new List <IIntellisenseResult>();
                    string inputText       = input;
                    var    regionInPostion = inputText.RegionInPostion(caretPosition);

                    inputText = !string.IsNullOrEmpty(regionInPostion.Name) ? regionInPostion.Name : inputText;

                    var getErrors = GetIntellisenseResultsImpl(inputText, filterType)
                                    .Where(i => i.ErrorCode != enIntellisenseErrorCode.None)
                                    .ToList();

                    getErrors.ForEach(results.Add);
                }
                break;
            }
            }

            if (altfilterType == enIntellisensePartType.RecordsetFields)
            {
                var filteredRecordsetFields = results.Where(r => r.Option.Recordset.Equals(recordserName) || r.Option.IsScalar);

                if (!string.IsNullOrEmpty(recordsetIndex))
                {
                    results = filteredRecordsetFields.ToList().Where(r => !r.Option.HasRecordsetIndex || r.Option.IsScalar).ToList();
                }
            }

            IList <IntellisenseProviderResult> trueResults = new List <IntellisenseProviderResult>();

            string[] openParts  = Regex.Split(input, @"\[\[");
            string[] closeParts = Regex.Split(input, @"\]\]");
            if (openParts.Length != closeParts.Length)
            {
                if (results != null)
                {
                    results.Add(IntellisenseFactory.CreateCalculateIntellisenseResult(2, 2, "Invalid Expression", "", StringResources.IntellisenseErrorMisMacthingBrackets));
                }
            }

            if (results != null)
            {
                foreach (IIntellisenseResult currentResult in results)
                {
                    if (currentResult.ErrorCode != enIntellisenseErrorCode.None)
                    {
                        if (currentResult.Type == enIntellisenseResultType.Error && currentResult.IsClosedRegion)
                        {
                            var displayValue = currentResult.Option == null ? string.Empty : currentResult.Option.DisplayValue;
                            trueResults.Add(new IntellisenseProviderResult(this, displayValue, currentResult.Message, currentResult.Message, true));
                        }
                    }


                    if (currentResult.Type == enIntellisenseResultType.Selectable)
                    {
                        var displayValue = currentResult.Option == null ? string.Empty : currentResult.Option.DisplayValue;
                        var description  = currentResult.Option == null ? string.Empty : currentResult.Option.Description;
                        trueResults.Add(new IntellisenseProviderResult(this, displayValue, description, description, false));
                    }
                }
            }

            return(trueResults);
        }
Ejemplo n.º 16
0
        void AtomListResultNoLabel(List <IDebugItemResult> results)
        {
            string groupName = null;
            var    grpIdx    = 0;

            foreach (var item in _warewolfAtomListresult.Item)
            {
                var displayExpression = _variable;
                var rawExpression     = _variable;
                if (displayExpression.Contains("()") || displayExpression.Contains("(*)"))
                {
                    grpIdx++;
                    groupName = rawExpression;
                    if (!rawExpression.StartsWith("[[@"))
                    {
                        displayExpression = GetObjectDisplayExpression(grpIdx);
                    }
                    else
                    {
                        var varName = DataListUtil.ExtractRecordsetNameFromValue(_variable);
                        displayExpression = DataListUtil.AddBracketsToValueIfNotExist(string.Concat(varName, "(", grpIdx, ")"));
                    }
                }
                else
                {
                    var indexRegionFromRecordset = DataListUtil.ExtractIndexRegionFromRecordset(displayExpression);
                    int.TryParse(indexRegionFromRecordset, out int indexForRecset);

                    if (indexForRecset > 0)
                    {
                        var indexOfOpenningBracket = displayExpression.IndexOf("(", StringComparison.Ordinal) + 1;
                        var group = displayExpression.Substring(0, indexOfOpenningBracket) + "*" + displayExpression.Substring(indexOfOpenningBracket + indexRegionFromRecordset.Length);
                        grpIdx++;
                        groupName = @group;
                    }
                }

                var debugOperator = "";
                var debugType     = DebugItemResultType.Value;
                if (DataListUtil.IsEvaluated(displayExpression))
                {
                    debugOperator = "=";
                    debugType     = DebugItemResultType.Variable;
                    if (_isCalculate)
                    {
                        displayExpression = groupName ?? displayExpression;
                    }
                }
                else
                {
                    displayExpression = null;
                }
                results.Add(new DebugItemResult
                {
                    Type         = debugType,
                    Variable     = DataListUtil.IsEvaluated(displayExpression) ? displayExpression : null,
                    Operator     = debugOperator,
                    GroupName    = groupName,
                    Value        = ExecutionEnvironment.WarewolfAtomToString(item),
                    GroupIndex   = grpIdx,
                    MockSelected = _mockSelected
                });
            }
        }
Ejemplo n.º 17
0
        static void ProcessRecordsetInputs(IServiceTestModelTO serviceTestModelTO, IDev2Definition dev2Definition)
        {
            var rec     = DataListUtil.CreateRecordsetDisplayValue(dev2Definition.RecordSetName, dev2Definition.Name, "");
            var indexes = serviceTestModelTO.Inputs.Where(input => DataListUtil.ExtractRecordsetNameFromValue(input.Variable) == dev2Definition.RecordSetName).Select(input => DataListUtil.ExtractIndexRegionFromRecordset(input.Variable)).Distinct(StringComparer.OrdinalIgnoreCase).ToList();

            if (serviceTestModelTO.Inputs.FirstOrDefault(input => DataListUtil.ReplaceRecordsetIndexWithBlank(input.Variable) == rec) == null)
            {
                if (indexes.Count == 0)
                {
                    serviceTestModelTO.Inputs.Add(new ServiceTestInputTO
                    {
                        Variable    = DataListUtil.CreateRecordsetDisplayValue(dev2Definition.RecordSetName, dev2Definition.Name, "1"),
                        Value       = "",
                        EmptyIsNull = false
                    });
                }
                else
                {
                    foreach (var index in indexes)
                    {
                        serviceTestModelTO.Inputs.Add(new ServiceTestInputTO
                        {
                            Variable    = DataListUtil.CreateRecordsetDisplayValue(dev2Definition.RecordSetName, dev2Definition.Name, index),
                            Value       = "",
                            EmptyIsNull = false
                        });
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public Guid Populate(object input, Guid targetDl, string outputDefs, out ErrorResultTO errors)
        {
            errors = new ErrorResultTO();
            var           compiler = DataListFactory.CreateDataListCompiler();
            ErrorResultTO invokeErrors;

            IBinaryDataList targetDL = compiler.FetchBinaryDataList(targetDl, out invokeErrors);

            errors.MergeErrors(invokeErrors);

            DataTable dbData = (input as DataTable);

            if (dbData != null && outputDefs != null)
            {
                var defs = DataListFactory.CreateOutputParser().Parse(outputDefs);
                HashSet <string> processedRecNames = new HashSet <string>();

                foreach (var def in defs)
                {
                    var expression = def.Value;
                    var rsName     = DataListUtil.ExtractRecordsetNameFromValue(expression);
                    var rsType     = DataListUtil.GetRecordsetIndexType(expression);
                    var rowIndex   = DataListUtil.ExtractIndexRegionFromRecordset(expression);
                    var rsNameUse  = def.RecordSetName;

                    if (string.IsNullOrEmpty(rsName))
                    {
                        rsName = rsNameUse;
                    }
                    if (string.IsNullOrEmpty(rsName))
                    {
                        rsName = def.Name;
                    }

                    if (processedRecNames.Contains(rsName))
                    {
                        continue;
                    }

                    processedRecNames.Add(rsName);

                    // build up the columns ;)
                    string error;
                    IBinaryDataListEntry entry;
                    if (targetDL.TryGetEntry(rsName, out entry, out error))
                    {
                        if (entry.IsRecordset)
                        {
                            var cols = entry.Columns;
                            IDictionary <int, string> colMapping = BuildColumnNameToIndexMap(entry.Columns,
                                                                                             dbData.Columns,
                                                                                             defs);

                            // now convert to binary datalist ;)
                            int rowIdx = entry.FetchAppendRecordsetIndex();
                            if (rsType == enRecordsetIndexType.Star)
                            {
                                rowIdx = 1;
                            }
                            if (rsType == enRecordsetIndexType.Numeric)
                            {
                                rowIdx = int.Parse(rowIndex);
                            }

                            if (dbData.Rows != null)
                            {
                                foreach (DataRow row in dbData.Rows)
                                {
                                    IList <IBinaryDataListItem> items = new List <IBinaryDataListItem>(cols.Count);
                                    // build up the row
                                    int idx = 0;

                                    foreach (var item in row.ItemArray)
                                    {
                                        string colName;

                                        if (colMapping.TryGetValue(idx, out colName))
                                        {
                                            items.Add(new BinaryDataListItem(item.ToString(), rsNameUse, colName, rowIdx));
                                        }

                                        idx++;
                                    }

                                    // add the row ;)
                                    entry.TryPutRecordRowAt(items, rowIdx, out error);

                                    errors.AddError(error);
                                    rowIdx++;
                                }
                            }
                        }
                        else
                        {
                            // handle a scalar coming out ;)
                            if (dbData.Rows != null && dbData.Rows.Count == 1)
                            {
                                var row = dbData.Rows[0].ItemArray;
                                // Look up the correct index from the columns ;)

                                int pos  = 0;
                                var cols = dbData.Columns;
                                int idx  = -1;

                                while (pos < cols.Count && idx == -1)
                                {
                                    if (cols[pos].ColumnName == entry.Namespace)
                                    {
                                        idx = pos;
                                    }
                                    pos++;
                                }

                                entry.TryPutScalar(new BinaryDataListItem(row[idx].ToString(), entry.Namespace), out error);
                                errors.AddError(error);
                            }
                        }
                    }
                    else
                    {
                        errors.AddError(error);
                    }
                }
            }

            compiler.PushBinaryDataList(targetDL.UID, targetDL, out invokeErrors);
            errors.MergeErrors(invokeErrors);

            return(targetDL.UID);
        }
        List <IDebugItemResult> BuildDebugItemFromAtomList()
        {
            var results = new List <IDebugItemResult>();

            if (!string.IsNullOrEmpty(_leftLabel))
            {
                string groupName = null;
                int    grpIdx    = 0;
                if (_warewolfAtomListresult != null)
                {
                    foreach (var atomItem in _warewolfAtomListresult.Item)
                    {
                        string displayExpression = _variable;
                        string rawExpression     = _variable;
                        var    item = atomItem.ToString();
                        if (displayExpression.Contains("().") || displayExpression.Contains("(*)."))
                        {
                            grpIdx++;
                            string index = grpIdx.ToString(CultureInfo.InvariantCulture);
                            if (rawExpression.Contains(".WarewolfPositionColumn"))
                            {
                                index = item;
                                item  = "";
                            }
                            groupName = rawExpression.Replace(".WarewolfPositionColumn", "");
                            // ReSharper disable EmptyStatement
                            displayExpression = DataListUtil.AddBracketsToValueIfNotExist(DataListUtil.CreateRecordsetDisplayValue(DataListUtil.ExtractRecordsetNameFromValue(_variable), DataListUtil.ExtractFieldNameFromValue(_variable), index)).Replace(".WarewolfPositionColumn", "");;
                            // ReSharper restore EmptyStatement
                        }
                        else
                        {
                            string indexRegionFromRecordset = DataListUtil.ExtractIndexRegionFromRecordset(displayExpression);
                            int    indexForRecset;
                            int.TryParse(indexRegionFromRecordset, out indexForRecset);

                            if (indexForRecset > 0)
                            {
                                int    indexOfOpenningBracket = displayExpression.IndexOf("(", StringComparison.Ordinal) + 1;
                                string group = displayExpression.Substring(0, indexOfOpenningBracket) + "*" + displayExpression.Substring(indexOfOpenningBracket + indexRegionFromRecordset.Length);
                                grpIdx++;
                                groupName = @group;
                            }
                        }

                        var debugOperator = "";
                        var debugType     = DebugItemResultType.Value;
                        if (DataListUtil.IsEvaluated(displayExpression))
                        {
                            debugOperator = String.IsNullOrEmpty(item)?"": "=";
                            debugType     = DebugItemResultType.Variable;
                        }
                        else
                        {
                            displayExpression = null;
                        }
                        results.Add(new DebugItemResult
                        {
                            Type       = debugType,
                            Label      = _leftLabel,
                            Variable   = DataListUtil.IsEvaluated(displayExpression) ? displayExpression : null,
                            Operator   = debugOperator,
                            GroupName  = groupName,
                            Value      = item,
                            GroupIndex = grpIdx
                        });
                    }
                }
                else
                {
                    results.Add(new DebugItemResult
                    {
                        Type       = DebugItemResultType.Variable,
                        Label      = _leftLabel,
                        Variable   = DataListUtil.IsEvaluated(Variable) ? Variable : null,
                        Operator   = _operand,
                        GroupName  = null,
                        Value      = "",
                        GroupIndex = grpIdx
                    });
                }
            }

            if (!string.IsNullOrEmpty(_rightLabel))
            {
                if (_oldValue != null)
                {
                    if (_oldValue.IsWarewolfAtomResult)
                    {
                        var scalarResult = _oldValue as WarewolfDataEvaluationCommon.WarewolfEvalResult.WarewolfAtomResult;
                        if (scalarResult != null)
                        {
                            results.Add(new DebugItemResult
                            {
                                Type       = DebugItemResultType.Variable,
                                Label      = _rightLabel,
                                Variable   = DataListUtil.IsEvaluated(_assignedToVariableName) ? _assignedToVariableName : null,
                                Operator   = string.IsNullOrEmpty(_operand) ? "" : "=",
                                GroupName  = null,
                                Value      = ExecutionEnvironment.WarewolfAtomToString(scalarResult.Item),
                                GroupIndex = 0
                            });
                        }
                    }
                    else if (_oldValue.IsWarewolfAtomListresult)
                    {
                        var    recSetResult = _oldValue as WarewolfDataEvaluationCommon.WarewolfEvalResult.WarewolfAtomListresult;
                        string groupName    = null;
                        int    grpIdx       = 0;
                        if (recSetResult != null)
                        {
                            foreach (var item in recSetResult.Item)
                            {
                                string displayExpression = _assignedToVariableName;
                                string rawExpression     = _assignedToVariableName;
                                if (displayExpression.Contains("().") || displayExpression.Contains("(*)."))
                                {
                                    grpIdx++;
                                    groupName         = rawExpression;
                                    displayExpression = DataListUtil.AddBracketsToValueIfNotExist(DataListUtil.CreateRecordsetDisplayValue(DataListUtil.ExtractRecordsetNameFromValue(_assignedToVariableName), DataListUtil.ExtractFieldNameFromValue(_assignedToVariableName), grpIdx.ToString()));
                                }
                                else
                                {
                                    string indexRegionFromRecordset = DataListUtil.ExtractIndexRegionFromRecordset(displayExpression);
                                    int    indexForRecset;
                                    int.TryParse(indexRegionFromRecordset, out indexForRecset);

                                    if (indexForRecset > 0)
                                    {
                                        int    indexOfOpenningBracket = displayExpression.IndexOf("(", StringComparison.Ordinal) + 1;
                                        string group = displayExpression.Substring(0, indexOfOpenningBracket) + "*" + displayExpression.Substring(indexOfOpenningBracket + indexRegionFromRecordset.Length);
                                        grpIdx++;
                                        groupName = @group;
                                    }
                                }

                                var debugOperator = "";
                                var debugType     = DebugItemResultType.Value;
                                if (DataListUtil.IsEvaluated(displayExpression))
                                {
                                    debugOperator = "=";
                                    debugType     = DebugItemResultType.Variable;
                                }
                                else
                                {
                                    displayExpression = null;
                                }
                                var debugItemResult = new DebugItemResult
                                {
                                    Type       = debugType,
                                    Label      = _rightLabel,
                                    Variable   = DataListUtil.IsEvaluated(displayExpression) ? displayExpression : null,
                                    Operator   = debugOperator,
                                    GroupName  = groupName,
                                    Value      = ExecutionEnvironment.WarewolfAtomToString(item),
                                    GroupIndex = grpIdx
                                };
                                results.Add(debugItemResult);
                            }
                        }
                    }
                }
                if (_oldValue == null)
                {
                    var debugItemResult = new DebugItemResult
                    {
                        Type       = DebugItemResultType.Variable,
                        Label      = _rightLabel,
                        Variable   = null,
                        Operator   = "=",
                        GroupName  = null,
                        Value      = _newValue,
                        GroupIndex = 0
                    };
                    results.Add(debugItemResult);
                }
            }

            if (string.IsNullOrEmpty(_rightLabel) && string.IsNullOrEmpty(_leftLabel))
            {
                string groupName = null;
                int    grpIdx    = 0;
                if (_warewolfAtomListresult != null)
                {
                    foreach (var item in _warewolfAtomListresult.Item)
                    {
                        string displayExpression = _variable;
                        string rawExpression     = _variable;
                        if (displayExpression.Contains("().") || displayExpression.Contains("(*)."))
                        {
                            grpIdx++;
                            groupName         = rawExpression;
                            displayExpression = DataListUtil.AddBracketsToValueIfNotExist(DataListUtil.CreateRecordsetDisplayValue(DataListUtil.ExtractRecordsetNameFromValue(_variable), DataListUtil.ExtractFieldNameOnlyFromValue(DataListUtil.AddBracketsToValueIfNotExist(_variable)), grpIdx.ToString()));

                            if (DataListUtil.GetRecordsetIndexType(_variable) == enRecordsetIndexType.Star)
                            {
                                displayExpression += _variable.Replace(DataListUtil.ReplaceRecordsetIndexWithStar(displayExpression), "");
                            }
                            else if (DataListUtil.GetRecordsetIndexType(_variable) == enRecordsetIndexType.Blank)
                            {
                                displayExpression += _variable.Replace(DataListUtil.ReplaceRecordsetIndexWithBlank(displayExpression), "");
                            }
                        }
                        else
                        {
                            string indexRegionFromRecordset = DataListUtil.ExtractIndexRegionFromRecordset(displayExpression);
                            int    indexForRecset;
                            int.TryParse(indexRegionFromRecordset, out indexForRecset);

                            if (indexForRecset > 0)
                            {
                                int    indexOfOpenningBracket = displayExpression.IndexOf("(", StringComparison.Ordinal) + 1;
                                string group = displayExpression.Substring(0, indexOfOpenningBracket) + "*" + displayExpression.Substring(indexOfOpenningBracket + indexRegionFromRecordset.Length);
                                grpIdx++;
                                groupName = @group;
                            }
                        }

                        var debugOperator = "";
                        var debugType     = DebugItemResultType.Value;
                        if (DataListUtil.IsEvaluated(displayExpression))
                        {
                            debugOperator = "=";
                            debugType     = DebugItemResultType.Variable;
                        }
                        else
                        {
                            displayExpression = null;
                        }
                        results.Add(new DebugItemResult
                        {
                            Type       = debugType,
                            Variable   = DataListUtil.IsEvaluated(displayExpression) ? displayExpression : null,
                            Operator   = debugOperator,
                            GroupName  = groupName,
                            Value      = ExecutionEnvironment.WarewolfAtomToString(item),
                            GroupIndex = grpIdx
                        });
                    }
                }
                else
                {
                    results.Add(new DebugItemResult
                    {
                        Type       = DebugItemResultType.Variable,
                        Variable   = DataListUtil.IsEvaluated(Variable) ? Variable : null,
                        Operator   = _operand,
                        GroupName  = null,
                        Value      = "",
                        GroupIndex = grpIdx
                    });
                }
            }
            return(results);
        }
        private void AtomListResultNoLabel(List <IDebugItemResult> results)
        {
            string groupName = null;
            int    grpIdx    = 0;

            foreach (var item in _warewolfAtomListresult.Item)
            {
                string displayExpression = _variable;
                string rawExpression     = _variable;
                if (displayExpression.Contains("().") || displayExpression.Contains("(*)."))
                {
                    grpIdx++;
                    groupName         = rawExpression;
                    displayExpression = DataListUtil.AddBracketsToValueIfNotExist(DataListUtil.CreateRecordsetDisplayValue(DataListUtil.ExtractRecordsetNameFromValue(_variable), DataListUtil.ExtractFieldNameOnlyFromValue(DataListUtil.AddBracketsToValueIfNotExist(_variable)), grpIdx.ToString()));

                    if (DataListUtil.GetRecordsetIndexType(_variable) == enRecordsetIndexType.Star)
                    {
                        displayExpression += _variable.Replace(DataListUtil.ReplaceRecordsetIndexWithStar(displayExpression), "");
                    }
                    else if (DataListUtil.GetRecordsetIndexType(_variable) == enRecordsetIndexType.Blank)
                    {
                        displayExpression += _variable.Replace(DataListUtil.ReplaceRecordsetIndexWithBlank(displayExpression), "");
                    }
                }
                else
                {
                    string indexRegionFromRecordset = DataListUtil.ExtractIndexRegionFromRecordset(displayExpression);
                    int    indexForRecset;
                    int.TryParse(indexRegionFromRecordset, out indexForRecset);

                    if (indexForRecset > 0)
                    {
                        int    indexOfOpenningBracket = displayExpression.IndexOf("(", StringComparison.Ordinal) + 1;
                        string group = displayExpression.Substring(0, indexOfOpenningBracket) + "*" + displayExpression.Substring(indexOfOpenningBracket + indexRegionFromRecordset.Length);
                        grpIdx++;
                        groupName = @group;
                    }
                }

                var debugOperator = "";
                var debugType     = DebugItemResultType.Value;
                if (DataListUtil.IsEvaluated(displayExpression))
                {
                    debugOperator = "=";
                    debugType     = DebugItemResultType.Variable;
                    if (_isCalculate)
                    {
                        displayExpression = groupName ?? displayExpression;
                    }
                }
                else
                {
                    displayExpression = null;
                }
                results.Add(new DebugItemResult
                {
                    Type         = debugType,
                    Variable     = DataListUtil.IsEvaluated(displayExpression) ? displayExpression : null,
                    Operator     = debugOperator,
                    GroupName    = groupName,
                    Value        = ExecutionEnvironment.WarewolfAtomToString(item),
                    GroupIndex   = grpIdx,
                    MockSelected = _mockSelected
                });
            }
        }
Ejemplo n.º 21
0
        private string EvaluateExpressiomToStringValue(string expression, Dev2DecisionMode mode, IBinaryDataList dataList)
        {
            string            result = string.Empty;
            IDataListCompiler c      = DataListFactory.CreateDataListCompiler();

            ErrorResultTO errors;
            var           dlEntry = c.Evaluate(dataList.UID, enActionType.User, expression, false, out errors);

            if (dlEntry != null && dlEntry.IsRecordset)
            {
                if (DataListUtil.GetRecordsetIndexType(expression) == enRecordsetIndexType.Numeric)
                {
                    int index;
                    if (int.TryParse(DataListUtil.ExtractIndexRegionFromRecordset(expression), out index))
                    {
                        string error;
                        IList <IBinaryDataListItem> listOfCols = dlEntry.FetchRecordAt(index, out error);
                        if (listOfCols != null)
                        {
                            foreach (IBinaryDataListItem binaryDataListItem in listOfCols)
                            {
                                result = binaryDataListItem.TheValue;
                            }
                        }
                    }
                }
                else
                {
                    if (DataListUtil.GetRecordsetIndexType(expression) == enRecordsetIndexType.Star)
                    {
                        IDev2IteratorCollection       colItr       = Dev2ValueObjectFactory.CreateIteratorCollection();
                        IBinaryDataListEntry          entry        = c.Evaluate(dataList.UID, enActionType.User, expression, false, out errors);
                        IDev2DataListEvaluateIterator col1Iterator = Dev2ValueObjectFactory.CreateEvaluateIterator(entry);
                        colItr.AddIterator(col1Iterator);

                        bool firstTime = true;
                        while (colItr.HasMoreData())
                        {
                            if (firstTime)
                            {
                                result    = colItr.FetchNextRow(col1Iterator).TheValue;
                                firstTime = false;
                            }
                            else
                            {
                                result += " " + mode + " " + colItr.FetchNextRow(col1Iterator).TheValue;
                            }
                        }
                    }
                    else
                    {
                        result = string.Empty;
                    }
                }
            }
            else
            {
                if (dlEntry != null)
                {
                    var scalarItem = dlEntry.FetchScalar();
                    result = scalarItem.TheValue;
                }
            }


            return(result);
        }
Ejemplo n.º 22
0
        IList <IDebugItemResult> CreateRecordsetDebugItems(string expression, IBinaryDataListEntry dlEntry, string value, int iterCnt, string labelText)
        {
            var results = new List <IDebugItemResult>();

            if (dlEntry.ComplexExpressionAuditor == null)
            {
                string initExpression = expression;

                string fieldName = DataListUtil.ExtractFieldNameFromValue(expression);
                enRecordsetIndexType indexType = DataListUtil.GetRecordsetIndexType(expression);
                if (indexType == enRecordsetIndexType.Blank && string.IsNullOrEmpty(fieldName))
                {
                    indexType = enRecordsetIndexType.Star;
                }
                if (indexType == enRecordsetIndexType.Star || indexType == enRecordsetIndexType.Numeric)
                {
                    IIndexIterator idxItr = dlEntry.FetchRecordsetIndexes();
                    while (idxItr.HasMore())
                    {
                        GetValues(dlEntry, value, iterCnt, idxItr, indexType, results, initExpression, labelText, fieldName);
                    }
                }
            }
            else
            {
                // Complex expressions are handled differently ;)
                ComplexExpressionAuditor auditor   = dlEntry.ComplexExpressionAuditor;
                enRecordsetIndexType     indexType = DataListUtil.GetRecordsetIndexType(expression);

                foreach (ComplexExpressionAuditItem item in auditor.FetchAuditItems())
                {
                    int grpIdx = -1;

                    try
                    {
                        grpIdx = Int32.Parse(DataListUtil.ExtractIndexRegionFromRecordset(item.TokenBinding));
                    }
                    // ReSharper disable EmptyGeneralCatchClause
                    catch (Exception)
                    // ReSharper restore EmptyGeneralCatchClause
                    {
                        // Best effort ;)
                    }

                    if (indexType == enRecordsetIndexType.Star)
                    {
                        string displayExpression = item.Expression.Replace(item.Token, item.RawExpression);
                        results.Add(new DebugItemResult {
                            Type = DebugItemResultType.Variable, Value = displayExpression, GroupName = displayExpression, GroupIndex = grpIdx
                        });
                        results.Add(new DebugItemResult {
                            Type = DebugItemResultType.Label, Value = GlobalConstants.EqualsExpression, GroupName = displayExpression, GroupIndex = grpIdx
                        });
                        results.Add(new DebugItemResult {
                            Type = DebugItemResultType.Value, Value = item.BoundValue, GroupName = displayExpression, GroupIndex = grpIdx
                        });
                    }
                }
            }

            return(results);
        }
Ejemplo n.º 23
0
        private void TranslateDataTableToEnvironment(DataTable executeService, IExecutionEnvironment environment, int update)
        {
            var started = true;

            if (executeService != null && Outputs != null && Outputs.Count != 0)
            {
                if (executeService.Rows != null)
                {
                    var rowIdx = 1;
                    foreach (DataRow row in executeService.Rows)
                    {
                        foreach (var serviceOutputMapping in Outputs)
                        {
                            if (!string.IsNullOrEmpty(serviceOutputMapping.MappedTo))
                            {
                                var rsType   = DataListUtil.GetRecordsetIndexType(serviceOutputMapping.MappedTo);
                                var rowIndex = DataListUtil.ExtractIndexRegionFromRecordset(serviceOutputMapping.MappedTo);
                                var rs       = serviceOutputMapping.RecordSetName;

                                if (environment.HasRecordSet(rs))
                                {
                                    if (started)
                                    {
                                        rowIdx  = environment.GetLength(rs) + 1;
                                        started = false;
                                    }
                                }
                                else
                                {
                                    environment.AssignDataShape(serviceOutputMapping.MappedTo);
                                }
                                if (rsType == enRecordsetIndexType.Star && started)
                                {
                                    rowIdx  = 1;
                                    started = false;
                                }
                                if (rsType == enRecordsetIndexType.Numeric)
                                {
                                    rowIdx = int.Parse(rowIndex);
                                }
                                if (!executeService.Columns.Contains(serviceOutputMapping.MappedFrom))
                                {
                                    continue;
                                }
                                var value = row[serviceOutputMapping.MappedFrom];
                                if (update != 0)
                                {
                                    rowIdx = update;
                                }
                                var displayExpression = DataListUtil.ReplaceRecordsetBlankWithIndex(DataListUtil.AddBracketsToValueIfNotExist(serviceOutputMapping.MappedTo), rowIdx);
                                if (rsType == enRecordsetIndexType.Star)
                                {
                                    displayExpression = DataListUtil.ReplaceStarWithFixedIndex(displayExpression, rowIdx);
                                }
                                environment.Assign(displayExpression, value.ToString(), update);
                            }
                        }
                        rowIdx++;
                    }
                }
            }
        }
        private void OldValueAtomListResult(List <IDebugItemResult> results)
        {
            var    recSetResult = _oldValue as CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult;
            string groupName    = null;
            int    grpIdx       = 0;

            if (recSetResult != null)
            {
                foreach (var item in recSetResult.Item)
                {
                    string displayExpression = _assignedToVariableName;
                    string rawExpression     = _assignedToVariableName;
                    if (displayExpression.Contains("().") || displayExpression.Contains("(*)."))
                    {
                        grpIdx++;
                        groupName = rawExpression;
                        Dev2DataLanguageParser dataLanguageParser = new Dev2DataLanguageParser();
                        var vals = dataLanguageParser.ParseForActivityDataItems(_assignedToVariableName);
                        if (vals != null)
                        {
                            foreach (var val in vals)
                            {
                                var repVal = DataListUtil.CreateRecordsetDisplayValue(DataListUtil.ExtractRecordsetNameFromValue(val), DataListUtil.ExtractFieldNameFromValue(val), grpIdx.ToString());
                                displayExpression = _assignedToVariableName.Replace(val, repVal);
                            }
                        }
                    }
                    else
                    {
                        string indexRegionFromRecordset = DataListUtil.ExtractIndexRegionFromRecordset(displayExpression);
                        int    indexForRecset;
                        int.TryParse(indexRegionFromRecordset, out indexForRecset);

                        if (indexForRecset > 0)
                        {
                            int    indexOfOpenningBracket = displayExpression.IndexOf("(", StringComparison.Ordinal) + 1;
                            string group = displayExpression.Substring(0, indexOfOpenningBracket) + "*" + displayExpression.Substring(indexOfOpenningBracket + indexRegionFromRecordset.Length);
                            grpIdx++;
                            groupName = @group;
                        }
                    }

                    var debugOperator = "";
                    var debugType     = DebugItemResultType.Value;
                    if (DataListUtil.IsEvaluated(displayExpression))
                    {
                        debugOperator = "=";
                        debugType     = DebugItemResultType.Variable;
                        if (_isCalculate)
                        {
                            displayExpression = groupName ?? displayExpression;
                        }
                    }
                    else
                    {
                        displayExpression = null;
                    }
                    var debugItemResult = new DebugItemResult
                    {
                        Type         = debugType,
                        Label        = _rightLabel,
                        Variable     = DataListUtil.IsEvaluated(displayExpression) ? displayExpression : null,
                        Operator     = debugOperator,
                        GroupName    = groupName,
                        Value        = ExecutionEnvironment.WarewolfAtomToString(item),
                        GroupIndex   = grpIdx,
                        MockSelected = _mockSelected
                    };
                    results.Add(debugItemResult);
                }
            }
        }
Ejemplo n.º 25
0
        private void Build(dynamic variable, XElement shape, XElement data, int rowIndex)
        {
            try
            {
                if (DataListUtil.IsValueRecordset(variable.Item1))
                {
                    string recordset   = RetrieveItemForEvaluation(enIntellisensePartType.RecordsetsOnly, variable.Item1);
                    string recordField = RetrieveItemForEvaluation(enIntellisensePartType.RecordsetFields, variable.Item1);

                    List <string> addedRecordsets;
                    ScenarioContext.Current.TryGetValue("addedRecordsets", out addedRecordsets);

                    if (addedRecordsets == null)
                    {
                        addedRecordsets = new List <string>();
                        ScenarioContext.Current.Add("addedRecordsets", addedRecordsets);
                    }

                    List <string> addedFieldset;
                    ScenarioContext.Current.TryGetValue("addedFieldset", out addedFieldset);

                    if (addedFieldset == null)
                    {
                        addedFieldset = new List <string>();
                        ScenarioContext.Current.Add("addedFieldset", addedFieldset);
                    }

                    var recordSetElement = shape
                                           .Descendants(recordset)
                                           .FirstOrDefault();
                    if (recordSetElement == null)
                    {
                        shape.Add(new XElement(recordset, new XElement(recordField)));
                    }
                    else
                    {
                        var recordSetField = recordSetElement
                                             .Elements(recordField)
                                             .FirstOrDefault();

                        if (recordSetField == null)
                        {
                            recordSetElement.Add(new XElement(recordField));
                        }
                    }

                    var indexRegionFromRecordset = DataListUtil.ExtractIndexRegionFromRecordset(variable.Item1);

                    if (!string.IsNullOrEmpty(indexRegionFromRecordset))
                    {
                        int indexForRecset;
                        int.TryParse(indexRegionFromRecordset, out indexForRecset);

                        var blankRowsToAdd = rowIndex == 0 ? 0 : (indexForRecset - 1) - _lastAddedIndex;

                        if (blankRowsToAdd > 0)
                        {
                            for (int i = 0; i < blankRowsToAdd; i++)
                            {
                                if (!String.IsNullOrEmpty(variable.Item2))
                                {
                                    data.Add(new XElement(recordset, new XElement(recordField)));
                                }
                                _lastAddedIndex++;
                            }
                        }
                    }

                    if (!String.IsNullOrEmpty(variable.Item2))
                    {
                        try
                        {
                            data.Add(new XElement(recordset, new XElement(recordField, XElement.Parse(variable.Item2))));
                        }
                        catch
                        {
                            data.Add(new XElement(recordset, new XElement(recordField, variable.Item2)));
                        }
                        _lastAddedIndex++;
                    }

                    string rec;
                    ScenarioContext.Current.TryGetValue("recordset", out rec);

                    if (string.IsNullOrEmpty(rec))
                    {
                        ScenarioContext.Current.Add("recordset", recordset);
                    }

                    string field;
                    ScenarioContext.Current.TryGetValue("recordField", out field);

                    if (string.IsNullOrEmpty(field))
                    {
                        ScenarioContext.Current.Add("recordField", recordField);
                    }
                }
                else
                {
                    string variableName = DataListUtil.RemoveLanguageBrackets(variable.Item1);
                    if (!String.IsNullOrEmpty(variableName))
                    {
                        shape.Add(new XElement(variableName));
                        try
                        {
                            data.Add(new XElement(variableName, XElement.Parse(variable.Item2)));
                        }
                        catch
                        {
                            data.Add(new XElement(variableName, (string)variable.Item2));
                        }
                    }
                }
            }
            // ReSharper disable EmptyGeneralCatchClause
            catch (Exception)
            // ReSharper restore EmptyGeneralCatchClause
            {
                //Swallow xml exception to allow testing of special characters on variables
            }
        }
Ejemplo n.º 26
0
        static void GetValue(IBinaryDataListEntry entry, DebugTO debugTo, string labelText, List <string> regions, List <IDebugItemResult> results)
        {
            ComplexExpressionAuditor auditor = entry.ComplexExpressionAuditor;

            if (auditor != null)
            {
                int grpIdx = 0;
                IList <ComplexExpressionAuditItem> complexExpressionAuditItems = auditor.FetchAuditItems();

                foreach (ComplexExpressionAuditItem item in complexExpressionAuditItems)
                {
                    string groupName         = null;
                    string displayExpression = item.Expression;
                    string rawExpression     = item.RawExpression;
                    if (regions != null && regions.Count > 0)
                    {
                        //
                    }

                    if (displayExpression.Contains("().") || displayExpression.Contains("(*)."))
                    {
                        grpIdx++;
                        groupName         = displayExpression;
                        displayExpression = rawExpression;
                    }
                    else
                    {
                        if (regions != null && regions.Count > 0)
                        {
                            string indexRegionFromRecordset = DataListUtil.ExtractIndexRegionFromRecordset(displayExpression);
                            int    indexForRecset;
                            int.TryParse(indexRegionFromRecordset, out indexForRecset);

                            if (indexForRecset > 0)
                            {
                                int    indexOfOpenningBracket = displayExpression.IndexOf("(", StringComparison.Ordinal) + 1;
                                string group = displayExpression.Substring(0, indexOfOpenningBracket) + "*" + displayExpression.Substring(indexOfOpenningBracket + indexRegionFromRecordset.Length);

                                if (regions.Contains(@group))
                                {
                                    grpIdx++;
                                    groupName = @group;
                                }
                            }
                        }
                    }

                    int count = complexExpressionAuditItems.Count(i => i.Expression.Equals(item.Expression));
                    if (count < 2)
                    {
                        groupName = "";
                    }

                    var debugOperator = "";
                    var debugType     = DebugItemResultType.Value;
                    if (DataListUtil.IsEvaluated(displayExpression))
                    {
                        debugOperator = "=";
                        debugType     = DebugItemResultType.Variable;
                    }
                    else
                    {
                        displayExpression = null;
                    }
                    results.Add(new DebugItemResult
                    {
                        Type       = debugType,
                        Label      = labelText,
                        Variable   = displayExpression,
                        Operator   = debugOperator,
                        GroupName  = groupName,
                        Value      = item.BoundValue,
                        GroupIndex = grpIdx
                    });
                }
            }
            else
            {
                //Could not evaluate
                results.Add(new DebugItemResult
                {
                    Type      = DebugItemResultType.Value,
                    Label     = labelText,
                    Variable  = debugTo.Expression,
                    Operator  = "=",
                    GroupName = "",
                    Value     = ""
                });
            }
        }
Ejemplo n.º 27
0
        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);
        }
Ejemplo n.º 28
0
        void TranslateDataTableToEnvironment(DataTable executeService, IExecutionEnvironment environment)
        {
            if (executeService != null && InstanceOutputDefintions != null)
            {
                var defs = DataListFactory.CreateOutputParser().Parse(InstanceOutputDefintions);
                HashSet <string>          processedRecNames = new HashSet <string>();
                IDictionary <int, string> colMapping        = BuildColumnNameToIndexMap(executeService.Columns, defs);
                foreach (var def in defs)
                {
                    var expression = def.Value;
                    var rs         = def.RawValue;
                    var rsName     = DataListUtil.ExtractRecordsetNameFromValue(expression);
                    var rsType     = DataListUtil.GetRecordsetIndexType(expression);
                    var rowIndex   = DataListUtil.ExtractIndexRegionFromRecordset(expression);
                    var rsNameUse  = def.RecordSetName;
                    environment.AssignDataShape(def.RawValue);

                    if (DataListUtil.IsValueRecordset(rs))
                    {
                        if (string.IsNullOrEmpty(rsName))
                        {
                            rsName = rsNameUse;
                        }
                        if (string.IsNullOrEmpty(rsName))
                        {
                            rsName = def.Name;
                        }

                        if (processedRecNames.Contains(rsName))
                        {
                            continue;
                        }

                        processedRecNames.Add(rsName);


                        // now convert to binary datalist ;)
                        int rowIdx = 1;

                        if (environment.HasRecordSet(rs))
                        {
                            rowIdx = environment.GetLength(rs);
                        }

                        if (rsType == enRecordsetIndexType.Star)
                        {
                            rowIdx = 1;
                        }
                        if (rsType == enRecordsetIndexType.Numeric)
                        {
                            rowIdx = int.Parse(rowIndex);
                        }

                        if (executeService.Rows != null)
                        {
                            foreach (DataRow row in executeService.Rows)
                            {
                                // build up the row
                                int idx = 0;

                                foreach (var item in row.ItemArray)
                                {
                                    string colName;

                                    if (colMapping.TryGetValue(idx, out colName))
                                    {
                                        var displayExpression = DataListUtil.AddBracketsToValueIfNotExist(DataListUtil.CreateRecordsetDisplayValue(DataListUtil.ExtractRecordsetNameFromValue(def.Value), colName, rowIdx.ToString()));
                                        environment.Assign(displayExpression, item.ToString(), 0);
                                    }

                                    idx++;
                                }

                                rowIdx++;
                            }
                        }
                    }
                    else
                    {
                        // handle a scalar coming out ;)
                        if (executeService.Rows != null && executeService.Rows.Count == 1)
                        {
                            var row = executeService.Rows[0].ItemArray;
                            // Look up the correct index from the columns ;)

                            int pos  = 0;
                            var cols = executeService.Columns;
                            int idx  = -1;

                            while (pos < cols.Count && idx == -1)
                            {
                                if (colMapping[pos] == expression)
                                {
                                    idx = pos;
                                }
                                pos++;
                            }
                            environment.Assign(DataListUtil.AddBracketsToValueIfNotExist(expression), row[idx].ToString(), 0);
                        }
                    }
                }
            }
        }
Ejemplo n.º 29
0
        // 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);
                }
            }
        }