// ReSharper disable InconsistentNaming public void IsSingleValueRule_Ctor_Single_Expectmessage_Has_Default() // ReSharper restore InconsistentNaming { //------------Setup for test-------------------------- var isSingleValueRule = new IsSingleValueRule(() => "[[rec().a]]"); //------------Execute Test--------------------------- Assert.IsNull(isSingleValueRule.Check()); //------------Assert Results------------------------- }
// ReSharper disable InconsistentNaming public void IsSingleValueRule_Check_SingleNested_ExpectNull() // ReSharper restore InconsistentNaming { //------------Setup for test-------------------------- var isSingleValueRule = new IsSingleValueRule(() => "[[rec([[rec().b]]).a]]"); //------------Execute Test--------------------------- Assert.IsNull(isSingleValueRule.Check()); //------------Assert Results------------------------- }
ErrorResultTO TryExecute(IDSFDataObject dataObject, int update, ErrorResultTO allErrors) { var rs = DataListUtil.ExtractRecordsetNameFromValue(RecordsetName); if (RecordsLength == string.Empty) { allErrors.AddError(ErrorResource.BlankResultVariable); } if (dataObject.IsDebugMode()) { var warewolfEvalResult = dataObject.Environment.Eval(RecordsetName.Replace("()", "(*)"), update); if (warewolfEvalResult.IsWarewolfRecordSetResult && warewolfEvalResult is CommonFunctions.WarewolfEvalResult.WarewolfRecordSetResult recsetResult) { AddDebugInputItem(new DebugItemWarewolfRecordset(recsetResult.Item, RecordsetName, "Recordset", "=")); } if (warewolfEvalResult.IsWarewolfAtomListresult && warewolfEvalResult is CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult atomListResult) { AddDebugInputItem(new DebugEvalResult(RecordsetName, "Recordset", dataObject.Environment, update)); } } var rule = new IsSingleValueRule(() => RecordsLength); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { var count = 0; if (dataObject.Environment.HasRecordSet(RecordsetName)) { count = dataObject.Environment.GetLength(rs); } else { allErrors.AddError("Recordset: " + RecordsetName + " does not exist."); } var value = count.ToString(); dataObject.Environment.Assign(RecordsLength, value, update); AddDebugOutputItem(new DebugItemWarewolfAtomResult(value, RecordsLength, "")); } return(allErrors); }
private void TryExecute(IDSFDataObject dataObject, int update, ErrorResultTO allErrors) { var rs = DataListUtil.ExtractRecordsetNameFromValue(RecordsetName); if (CountNumber == string.Empty) { allErrors.AddError(ErrorResource.BlankResultVariable); } if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugEvalResult(dataObject.Environment.ToStar(RecordsetName), "Recordset", dataObject.Environment, update)); } var rule = new IsSingleValueRule(() => CountNumber); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { var hasRecordSet = dataObject.Environment.HasRecordSet(RecordsetName); if (hasRecordSet)//null check happens here { var count = dataObject.Environment.GetCount(rs); var value = count.ToString(); dataObject.Environment.Assign(CountNumber, value, update); AddDebugOutputItem(new DebugEvalResult(CountNumber, "", dataObject.Environment, update)); } else { if (TreatNullAsZero) { dataObject.Environment.Assign(CountNumber, 0.ToString(), update); AddDebugOutputItem(new DebugEvalResult(CountNumber, "", dataObject.Environment, update)); } else { allErrors.AddError(string.Format(ErrorResource.NullRecordSet, RecordsetName)); } } } }
private void CheckForErrors(IDSFDataObject dataObject, int update, IDev2IndexFinder indexFinder, ErrorResultTO allErrors, ErrorResultTO errors, WarewolfListIterator innerIteratorCollection, List <string> completeResultList, WarewolfIterator itrInField, string chars) { if (!string.IsNullOrEmpty(InField) && !string.IsNullOrEmpty(Characters)) { var val = innerIteratorCollection.FetchNextValue(itrInField); if (val != null) { var returedData = indexFinder.FindIndex(val, Index, chars, Direction, MatchCase, StartIndex); completeResultList.AddRange(returedData.Select(value => value.ToString(CultureInfo.InvariantCulture)).ToList()); var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { dataObject.Environment.Assign(Result, string.Join(",", completeResultList), update); allErrors.MergeErrors(errors); } } } }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); allErrors.MergeErrors(errors); InitializeDebug(dataObject); // Process if no errors try { ValidateRecordsetName(RecordsetName, errors); allErrors.MergeErrors(errors); if (!allErrors.HasErrors()) { try { string rs = DataListUtil.ExtractRecordsetNameFromValue(RecordsetName); if (CountNumber == string.Empty) { allErrors.AddError("Blank result variable"); } if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugEvalResult(dataObject.Environment.ToStar(RecordsetName), "Recordset", dataObject.Environment, update)); } var rule = new IsSingleValueRule(() => CountNumber); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { var count = 0; if (dataObject.Environment.HasRecordSet(RecordsetName)) { count = dataObject.Environment.GetCount(rs); } var value = count.ToString(); dataObject.Environment.Assign(CountNumber, value, update); AddDebugOutputItem(new DebugEvalResult(CountNumber, "", dataObject.Environment, update)); } } catch (Exception e) { AddDebugInputItem(new DebugItemStaticDataParams("", RecordsetName, "Recordset", "=")); allErrors.AddError(e.Message); dataObject.Environment.Assign(CountNumber, "0", update); AddDebugOutputItem(new DebugItemStaticDataParams("0", CountNumber, "", "=")); } } } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfCountRecordsActivity", allErrors); var errorString = allErrors.MakeDataListReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); var dataObject = context.GetExtension <IDSFDataObject>(); var compiler = DataListFactory.CreateDataListCompiler(); var allErrors = new ErrorResultTO(); ErrorResultTO errors; var executionId = DataListExecutionID.Get(context); var toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); InitializeDebug(dataObject); try { var expression = Expression ?? string.Empty; var roundingDecimalPlaces = RoundingDecimalPlaces ?? string.Empty; var decimalPlacesToShow = DecimalPlacesToShow ?? string.Empty; var colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); var expressionIterator = CreateDataListEvaluateIterator(expression, executionId, compiler, colItr, allErrors); var roundingDecimalPlacesIterator = CreateDataListEvaluateIterator(roundingDecimalPlaces, executionId, compiler, colItr, allErrors); var decimalPlacesToShowIterator = CreateDataListEvaluateIterator(decimalPlacesToShow, executionId, compiler, colItr, allErrors); if (dataObject.IsDebugMode()) { AddDebugInputItem(expression, "Number", expressionIterator.FetchEntry(), executionId); if (!String.IsNullOrEmpty(RoundingType)) { AddDebugInputItem(new DebugItemStaticDataParams(RoundingType, "Rounding")); } AddDebugInputItem(roundingDecimalPlaces, "Rounding Value", roundingDecimalPlacesIterator.FetchEntry(), executionId); AddDebugInputItem(decimalPlacesToShow, "Decimals to show", decimalPlacesToShowIterator.FetchEntry(), executionId); } // Loop data ;) var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); while (colItr.HasMoreData()) { int decimalPlacesToShowValue; var tmpDecimalPlacesToShow = colItr.FetchNextRow(decimalPlacesToShowIterator).TheValue; var adjustDecimalPlaces = tmpDecimalPlacesToShow.IsRealNumber(out decimalPlacesToShowValue); if (!string.IsNullOrEmpty(tmpDecimalPlacesToShow) && !adjustDecimalPlaces) { throw new Exception("Decimals to show is not valid"); } var tmpDecimalPlaces = colItr.FetchNextRow(roundingDecimalPlacesIterator).TheValue; var roundingDecimalPlacesValue = 0; if (!string.IsNullOrEmpty(tmpDecimalPlaces) && !tmpDecimalPlaces.IsRealNumber(out roundingDecimalPlacesValue)) { throw new Exception("Rounding decimal places is not valid"); } var binaryDataListItem = colItr.FetchNextRow(expressionIterator); var val = binaryDataListItem.TheValue; FormatNumberTO formatNumberTo = new FormatNumberTO(val, RoundingType, roundingDecimalPlacesValue, adjustDecimalPlaces, decimalPlacesToShowValue); var result = _numberFormatter.Format(formatNumberTo); if (single != null) { allErrors.AddError(single.Message); } else { UpdateResultRegions(toUpsert, result); } } compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); if (!allErrors.HasErrors()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } catch (Exception e) { Dev2Logger.Log.Error("DSFNumberFormatActivity", e); allErrors.AddError(e.Message); } finally { if (allErrors.HasErrors()) { if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DisplayAndWriteError("DsfNumberFormatActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); compiler.Upsert(executionId, Result, (string)null, out errors); } if (dataObject.IsDebugMode()) { DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
protected override void ExecuteTool(IDSFDataObject dataObject) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); var allErrors = new ErrorResultTO(); InitializeDebug(dataObject); try { var expression = Expression ?? string.Empty; var roundingDecimalPlaces = RoundingDecimalPlaces ?? string.Empty; var decimalPlacesToShow = DecimalPlacesToShow ?? string.Empty; if (dataObject.IsDebugMode()) { AddDebugInputItem(expression, "Number", dataObject.Environment); if (!String.IsNullOrEmpty(RoundingType)) { AddDebugInputItem(new DebugItemStaticDataParams(RoundingType, "Rounding")); } AddDebugInputItem(roundingDecimalPlaces, "Rounding Value", dataObject.Environment); AddDebugInputItem(decimalPlacesToShow, "Decimals to show", dataObject.Environment); } var colItr = new WarewolfListIterator(); var expressionIterator = CreateDataListEvaluateIterator(expression, dataObject.Environment); var roundingDecimalPlacesIterator = CreateDataListEvaluateIterator(roundingDecimalPlaces, dataObject.Environment); var decimalPlacesToShowIterator = CreateDataListEvaluateIterator(decimalPlacesToShow, dataObject.Environment); colItr.AddVariableToIterateOn(expressionIterator); colItr.AddVariableToIterateOn(roundingDecimalPlacesIterator); colItr.AddVariableToIterateOn(decimalPlacesToShowIterator); // Loop data ;) var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); while (colItr.HasMoreData()) { int decimalPlacesToShowValue; var tmpDecimalPlacesToShow = colItr.FetchNextValue(decimalPlacesToShowIterator); var adjustDecimalPlaces = tmpDecimalPlacesToShow.IsRealNumber(out decimalPlacesToShowValue); if (!string.IsNullOrEmpty(tmpDecimalPlacesToShow) && !adjustDecimalPlaces) { throw new Exception("Decimals to show is not valid"); } var tmpDecimalPlaces = colItr.FetchNextValue(roundingDecimalPlacesIterator); var roundingDecimalPlacesValue = 0; if (!string.IsNullOrEmpty(tmpDecimalPlaces) && !tmpDecimalPlaces.IsRealNumber(out roundingDecimalPlacesValue)) { throw new Exception("Rounding decimal places is not valid"); } var binaryDataListItem = colItr.FetchNextValue(expressionIterator); var val = binaryDataListItem; FormatNumberTO formatNumberTo = new FormatNumberTO(val, RoundingType, roundingDecimalPlacesValue, adjustDecimalPlaces, decimalPlacesToShowValue); var result = _numberFormatter.Format(formatNumberTo); if (single != null) { allErrors.AddError(single.Message); } else { UpdateResultRegions(dataObject.Environment, result); if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams(result, Result, "", "=")); } } } } catch (Exception e) { Dev2Logger.Log.Error("DSFNumberFormatActivity", e); allErrors.AddError(e.Message); } finally { if (allErrors.HasErrors()) { if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DisplayAndWriteError("DsfNumberFormatActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before); DispatchDebugState(dataObject, StateType.After); } } }
/// <summary> /// Executes the logic of the activity and calls the backend code to do the work /// Also responsible for adding the results to the data list /// </summary> /// <param name="context"></param> protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); var compiler = DataListFactory.CreateDataListCompiler(); var dataObject = context.GetExtension <IDSFDataObject>(); var errorResultTo = new ErrorResultTO(); var allErrors = new ErrorResultTO(); var executionId = dataObject.DataListID; InitializeDebug(dataObject); int iterationIndex; try { IList <string> toSearch = FieldsToSearch.Split(','); if (dataObject.IsDebugMode()) { AddDebugInputValues(dataObject, toSearch, compiler, executionId, ref errorResultTo); } allErrors.MergeErrors(errorResultTo); IEnumerable <string> results = new List <string>(); var toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); bool isFirstIteration = true; // ReSharper disable ForCanBeConvertedToForeach for (var i = 0; i < ResultsCollection.Count; i++) // ReSharper restore ForCanBeConvertedToForeach { IEnumerable <string> resultsDuringSearch = new List <string>(); var currenSearchResults = new List <string>(); IDev2IteratorCollection itrCollection = Dev2ValueObjectFactory.CreateIteratorCollection(); IBinaryDataListEntry binaryDataListEntrySearchCrit = compiler.Evaluate(executionId, enActionType.User, ResultsCollection[i].SearchCriteria, false, out errorResultTo); IDev2DataListEvaluateIterator searchCritItr = Dev2ValueObjectFactory.CreateEvaluateIterator(binaryDataListEntrySearchCrit); itrCollection.AddIterator(searchCritItr); allErrors.MergeErrors(errorResultTo); IBinaryDataListEntry binaryDataListEntryFrom = compiler.Evaluate(executionId, enActionType.User, ResultsCollection[i].From, false, out errorResultTo); IDev2DataListEvaluateIterator fromItr = Dev2ValueObjectFactory.CreateEvaluateIterator(binaryDataListEntryFrom); itrCollection.AddIterator(fromItr); allErrors.MergeErrors(errorResultTo); IBinaryDataListEntry binaryDataListEntryTo = compiler.Evaluate(executionId, enActionType.User, ResultsCollection[i].To, false, out errorResultTo); IDev2DataListEvaluateIterator toItr = Dev2ValueObjectFactory.CreateEvaluateIterator(binaryDataListEntryTo); itrCollection.AddIterator(toItr); allErrors.MergeErrors(errorResultTo); int idx; if (!Int32.TryParse(StartIndex, out idx)) { idx = 1; } var toSearchList = compiler.FetchBinaryDataList(executionId, out errorResultTo); allErrors.MergeErrors(errorResultTo); var searchType = ResultsCollection[i].SearchType; if (string.IsNullOrEmpty(searchType)) { continue; } // ReSharper disable PossibleMultipleEnumeration while (itrCollection.HasMoreData()) { var currentResults = results as IList <string> ?? results.ToList(); var splitOn = new[] { "," }; var fieldsToSearch = FieldsToSearch.Split(splitOn, StringSplitOptions.RemoveEmptyEntries); SearchTO searchTo; if (fieldsToSearch.Length > 0) { bool isFirstFieldIteration = true; foreach (var field in fieldsToSearch) { IList <string> iterationResults = new List <string>(); searchTo = DataListFactory.CreateSearchTO(field, searchType, itrCollection.FetchNextRow(searchCritItr) .TheValue, idx.ToString(CultureInfo.InvariantCulture), Result, MatchCase, false, itrCollection.FetchNextRow(fromItr).TheValue, itrCollection.FetchNextRow(toItr).TheValue); ValidateRequiredFields(searchTo, out errorResultTo); allErrors.MergeErrors(errorResultTo); // ReSharper disable ConvertClosureToMethodGroup (RecordsetInterrogator.FindRecords(toSearchList, searchTo, out errorResultTo)).ToList().ForEach(it => iterationResults.Add(it)); // ReSharper restore ConvertClosureToMethodGroup if (RequireAllFieldsToMatch) { resultsDuringSearch = isFirstFieldIteration ? iterationResults : currenSearchResults.Intersect(iterationResults); currenSearchResults = resultsDuringSearch.ToList(); } else { resultsDuringSearch = currenSearchResults.Union(iterationResults); currenSearchResults = RequireAllTrue ? new List <string>() : resultsDuringSearch.ToList(); } isFirstFieldIteration = false; } } else { searchTo = (SearchTO)ConvertToSearchTO(itrCollection.FetchNextRow(searchCritItr).TheValue, searchType, idx.ToString(CultureInfo.InvariantCulture), itrCollection.FetchNextRow(fromItr).TheValue, itrCollection.FetchNextRow(toItr).TheValue); ValidateRequiredFields(searchTo, out errorResultTo); allErrors.MergeErrors(errorResultTo); resultsDuringSearch = RecordsetInterrogator.FindRecords(toSearchList, searchTo, out errorResultTo); } allErrors.MergeErrors(errorResultTo); if (RequireAllTrue) { results = isFirstIteration ? resultsDuringSearch : currentResults.Intersect(resultsDuringSearch); } else { results = currentResults.Union(resultsDuringSearch); } isFirstIteration = false; } } DataListCleaningUtils.SplitIntoRegions(Result); var rule = new IsSingleValueRule(() => Result); var singleresError = rule.Check(); if (singleresError != null) { allErrors.AddError(singleresError.Message); } else { string concatRes = String.Empty; var allResults = results as IList <string> ?? results.ToList(); // ReSharper restore PossibleMultipleEnumeration if (allResults.Count == 0) { allResults.Add("-1"); } if (!DataListUtil.IsValueRecordset(Result)) { // ReSharper disable LoopCanBeConvertedToQuery foreach (var r in allResults) // ReSharper restore LoopCanBeConvertedToQuery { concatRes = string.Concat(concatRes, r, ","); } if (concatRes.EndsWith(",")) { concatRes = concatRes.Remove(concatRes.Length - 1); } toUpsert.Add(Result, concatRes); toUpsert.FlushIterationFrame(); } else { iterationIndex = 0; foreach (var r in allResults) { toUpsert.Add(Result, r); toUpsert.FlushIterationFrame(); iterationIndex++; } } compiler.Upsert(executionId, toUpsert, out errorResultTo); allErrors.MergeErrors(errorResultTo); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { foreach (var debugTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugTo)); } } } } catch (Exception exception) { Dev2Logger.Log.Error("DSFRecordsMultipleCriteria", exception); allErrors.AddError(exception.Message); } finally { var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfFindRecordsMultipleCriteriaActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errorResultTo); compiler.Upsert(executionId, Result, (string)null, out errorResultTo); } if (dataObject.IsDebugMode()) { if (hasErrors) { iterationIndex = 0; var regions = DataListCleaningUtils.SplitIntoRegions(Result); foreach (var region in regions) { AddDebugOutputItem(new DebugOutputParams(region, "", executionId, iterationIndex)); iterationIndex++; } } DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
protected override void ExecuteTool(IDSFDataObject dataObject) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); allErrors.MergeErrors(errors); InitializeDebug(dataObject); // Process if no errors try { if (dataObject.IsDebugMode()) { if (string.IsNullOrEmpty(Input1)) { AddDebugInputItem(new DebugItemStaticDataParams(DateTime.Now.ToString(CultureInfo.CurrentCulture), "now()", "Input 1", "=")); } else { AddDebugInputItem(Input1, "Input 1", dataObject.Environment); } if (string.IsNullOrEmpty(Input2)) { AddDebugInputItem(new DebugItemStaticDataParams(DateTime.Now.ToString(CultureInfo.CurrentCulture), "now()", "Input 2", "=")); } else { AddDebugInputItem(Input2, "Input 2", dataObject.Environment); } AddDebugInputItem(InputFormat, "Input Format", dataObject.Environment); if (!String.IsNullOrEmpty(OutputType)) { AddDebugInputItem(new DebugItemStaticDataParams(OutputType, "Output In")); } } var colItr = new WarewolfListIterator(); var input1Itr = new WarewolfIterator(dataObject.Environment.EvalStrict(string.IsNullOrEmpty(Input1) ? GlobalConstants.CalcExpressionNow : Input1)); colItr.AddVariableToIterateOn(input1Itr); var evalInp2 = dataObject.Environment.EvalStrict(string.IsNullOrEmpty(Input2) ? GlobalConstants.CalcExpressionNow : Input2); var input2Itr = new WarewolfIterator(evalInp2); colItr.AddVariableToIterateOn(input2Itr); var ifItr = new WarewolfIterator(dataObject.Environment.Eval(InputFormat ?? string.Empty)); colItr.AddVariableToIterateOn(ifItr); int indexToUpsertTo = 1; while (colItr.HasMoreData()) { IDateTimeDiffTO transObj = ConvertToDateTimeDiffTo(colItr.FetchNextValue(input1Itr), colItr.FetchNextValue(input2Itr), colItr.FetchNextValue(ifItr), OutputType); //Create a DateTimeComparer using the DateTimeConverterFactory IDateTimeComparer comparer = DateTimeConverterFactory.CreateComparer(); //Call the TryComparer method on the DateTimeComparer and pass it the IDateTimeDiffTO created from the ConvertToDateTimeDiffTO Method string result; string error; string expression = Result; if (comparer.TryCompare(transObj, out result, out error)) { if (DataListUtil.IsValueRecordset(Result) && DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Star) { expression = Result.Replace(GlobalConstants.StarExpression, indexToUpsertTo.ToString(CultureInfo.InvariantCulture)); } else { expression = Result; } var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { dataObject.Environment.Assign(expression, result); } } else { DoDebugOutput(dataObject, expression); allErrors.AddError(error); } indexToUpsertTo++; } allErrors.MergeErrors(errors); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { AddDebugOutputItem(new DebugEvalResult(Result, null, dataObject.Environment)); } } catch (Exception e) { Dev2Logger.Log.Error("DSFDateTime", e); allErrors.AddError(e.Message); } finally { // Handle Errors if (allErrors.HasErrors()) { DisplayAndWriteError("DsfDateTimeDifferenceActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); dataObject.Environment.Assign(Result, null); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before); DispatchDebugState(dataObject, StateType.After); } } }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { IDev2IndexFinder indexFinder = new Dev2IndexFinder(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); InitializeDebug(dataObject); try { var outerIteratorCollection = new WarewolfListIterator(); var innerIteratorCollection = new WarewolfListIterator(); allErrors.MergeErrors(errors); #region Iterate and Find Index if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugEvalResult(InField, "In Field", dataObject.Environment, update)); AddDebugInputItem(new DebugItemStaticDataParams(Index, "Index")); AddDebugInputItem(new DebugEvalResult(Characters, "Characters", dataObject.Environment, update)); AddDebugInputItem(new DebugItemStaticDataParams(Direction, "Direction")); } var itrChar = new WarewolfIterator(dataObject.Environment.Eval(Characters, update)); outerIteratorCollection.AddVariableToIterateOn(itrChar); var completeResultList = new List <string>(); if (String.IsNullOrEmpty(InField)) { allErrors.AddError("'In Field' is blank"); } else if (String.IsNullOrEmpty(Characters)) { allErrors.AddError("'Characters' is blank"); } else { while (outerIteratorCollection.HasMoreData()) { allErrors.MergeErrors(errors); errors.ClearErrors(); var itrInField = new WarewolfIterator(dataObject.Environment.Eval(InField, update)); innerIteratorCollection.AddVariableToIterateOn(itrInField); string chars = outerIteratorCollection.FetchNextValue(itrChar); while (innerIteratorCollection.HasMoreData()) { if (!string.IsNullOrEmpty(InField) && !string.IsNullOrEmpty(Characters)) { var val = innerIteratorCollection.FetchNextValue(itrInField); if (val != null) { IEnumerable <int> returedData = indexFinder.FindIndex(val, Index, chars, Direction, MatchCase, StartIndex); completeResultList.AddRange(returedData.Select(value => value.ToString(CultureInfo.InvariantCulture)).ToList()); //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result } } } } var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { if (DataListUtil.IsValueRecordset(Result)) { var rsType = DataListUtil.GetRecordsetIndexType(Result); if (rsType == enRecordsetIndexType.Numeric) { dataObject.Environment.Assign(Result, string.Join(",", completeResultList), update); allErrors.MergeErrors(errors); } else { var idx = 1; foreach (var res in completeResultList) { if (rsType == enRecordsetIndexType.Blank) { dataObject.Environment.Assign(Result, res, update); } if (rsType == enRecordsetIndexType.Star) { var expression = DataListUtil.CreateRecordsetDisplayValue(DataListUtil.ExtractRecordsetNameFromValue(Result), DataListUtil.ExtractFieldNameFromValue(Result), idx.ToString()); dataObject.Environment.Assign(DataListUtil.AddBracketsToValueIfNotExist(expression), res, update); idx++; } } } } else { dataObject.Environment.Assign(Result, string.Join(",", completeResultList), update); } allErrors.MergeErrors(errors); if (!allErrors.HasErrors() && dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update)); } } } #endregion } catch (Exception e) { Dev2Logger.Log.Error("DSFFindActivity", e); allErrors.AddError(e.Message); } finally { #region Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfIndexActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } #endregion if (dataObject.IsDebugMode()) { if (hasErrors) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update)); } DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
#pragma warning disable S1541 // Methods and properties should not be too complex protected override void ExecuteTool(IDSFDataObject dataObject, int update) #pragma warning restore S1541 // Methods and properties should not be too complex { var replaceOperation = Dev2OperationsFactory.CreateReplaceOperation(); IErrorResultTO errors = new ErrorResultTO(); IErrorResultTO allErrors = new ErrorResultTO(); var replacementCount = 0; var replacementTotal = 0; InitializeDebug(dataObject); try { IList <string> toSearch = FieldsToSearch.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); AddTypeDebugItem(dataObject, update, toSearch); foreach (string s in toSearch) { if (!DataListUtil.IsEvaluated(s)) { allErrors.AddError(ErrorResource.RequiredVaraibleNameONLY); return; } } IWarewolfListIterator iteratorCollection = new WarewolfListIterator(); var finRes = dataObject.Environment.Eval(Find, update); if (ExecutionEnvironment.IsNothing(finRes)) { if (!string.IsNullOrEmpty(Result)) { dataObject.Environment.Assign(Result, replacementTotal.ToString(CultureInfo.InvariantCulture), update); } } else { var itrFind = new WarewolfIterator(dataObject.Environment.Eval(Find, update)); iteratorCollection.AddVariableToIterateOn(itrFind); var itrReplace = new WarewolfIterator(dataObject.Environment.Eval(ReplaceWith, update)); iteratorCollection.AddVariableToIterateOn(itrReplace); var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { allErrors = TryExecute(dataObject, update, replaceOperation, ref errors, allErrors, ref replacementCount, ref replacementTotal, toSearch, iteratorCollection, itrFind, itrReplace); } } if (dataObject.IsDebugMode() && !allErrors.HasErrors() && !string.IsNullOrEmpty(Result)) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update)); } // now push the result to the server } catch (Exception ex) { Dev2Logger.Error("DSFReplace", ex, GlobalConstants.WarewolfError); allErrors.AddError(ex.Message); } finally { if (allErrors.HasErrors()) { if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); dataObject.Environment.Assign(Result, null, update); DisplayAndWriteError(dataObject, DisplayName, allErrors); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
protected override void ExecuteTool(IDSFDataObject dataObject) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); allErrors.MergeErrors(errors); var env = dataObject.Environment; InitializeDebug(dataObject); try { if (!errors.HasErrors()) { if (dataObject.IsDebugMode()) { AddDebugInputItem(Length, From, To, dataObject.Environment, RandomType); } IWarewolfIterator lengthItr = !String.IsNullOrEmpty(Length) ? new WarewolfIterator(env.EvalStrict(Length)) as IWarewolfIterator : new WarewolfAtomIterator(new[] { DataASTMutable.WarewolfAtom.Nothing, }); var fromItr = !String.IsNullOrEmpty(From) ? new WarewolfIterator(env.EvalStrict(From)) as IWarewolfIterator : new WarewolfAtomIterator(new[] { DataASTMutable.WarewolfAtom.Nothing, }); var toItr = !String.IsNullOrEmpty(To) ? new WarewolfIterator(env.EvalStrict(To)) as IWarewolfIterator : new WarewolfAtomIterator(new[] { DataASTMutable.WarewolfAtom.Nothing, }); WarewolfListIterator colItr = new WarewolfListIterator(); colItr.AddVariableToIterateOn(lengthItr); colItr.AddVariableToIterateOn(fromItr); colItr.AddVariableToIterateOn(toItr); Dev2Random dev2Random = new Dev2Random(); while (colItr.HasMoreData()) { int lengthNum = -1; int fromNum = -1; int toNum = -1; string fromValue = colItr.FetchNextValue(fromItr); string toValue = colItr.FetchNextValue(toItr); string lengthValue = colItr.FetchNextValue(lengthItr); if (RandomType != enRandomType.Guid) { if (RandomType == enRandomType.Numbers) { #region Getting the From fromNum = GetFromValue(fromValue, out errors); if (errors.HasErrors()) { allErrors.MergeErrors(errors); continue; } #endregion #region Getting the To toNum = GetToValue(toValue, out errors); if (errors.HasErrors()) { allErrors.MergeErrors(errors); continue; } #endregion } else { #region Getting the Length lengthNum = GetLengthValue(lengthValue, out errors); if (errors.HasErrors()) { allErrors.MergeErrors(errors); continue; } #endregion } } string value = dev2Random.GetRandom(RandomType, lengthNum, fromNum, toNum); var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { env.Assign(Result, value); } } } allErrors.MergeErrors(errors); if (!allErrors.HasErrors()) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment)); } } catch (Exception e) { Dev2Logger.Log.Error("DSFRandomActivity", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfRandomActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { if (hasErrors) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DispatchDebugState(dataObject, StateType.Before); DispatchDebugState(dataObject, StateType.After); } } }
#pragma warning disable S1541 // Methods and properties should not be too complex protected override void ExecuteTool(IDSFDataObject dataObject, int update) #pragma warning restore S1541 // Methods and properties should not be too complex { var allErrors = new ErrorResultTO(); InitializeDebug(dataObject); try { var expression = Expression ?? string.Empty; var roundingDecimalPlaces = RoundingDecimalPlaces ?? string.Empty; var decimalPlacesToShow = DecimalPlacesToShow ?? string.Empty; AddDebugInputItems(dataObject, update, expression, roundingDecimalPlaces, decimalPlacesToShow); var colItr = new WarewolfListIterator(); var expressionIterator = CreateDataListEvaluateIterator(expression, dataObject.Environment, update); var roundingDecimalPlacesIterator = CreateDataListEvaluateIterator(roundingDecimalPlaces, dataObject.Environment, update); var decimalPlacesToShowIterator = CreateDataListEvaluateIterator(decimalPlacesToShow, dataObject.Environment, update); colItr.AddVariableToIterateOn(expressionIterator); colItr.AddVariableToIterateOn(roundingDecimalPlacesIterator); colItr.AddVariableToIterateOn(decimalPlacesToShowIterator); // Loop data ;) var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); var counter = 1; while (colItr.HasMoreData()) { var tmpDecimalPlacesToShow = colItr.FetchNextValue(decimalPlacesToShowIterator); var adjustDecimalPlaces = tmpDecimalPlacesToShow.IsRealNumber(out int decimalPlacesToShowValue); if (!string.IsNullOrEmpty(tmpDecimalPlacesToShow) && !adjustDecimalPlaces) { throw new Exception(ErrorResource.DecimalsNotValid); } var tmpDecimalPlaces = colItr.FetchNextValue(roundingDecimalPlacesIterator); var roundingDecimalPlacesValue = 0; if (!string.IsNullOrEmpty(tmpDecimalPlaces) && !tmpDecimalPlaces.IsRealNumber(out roundingDecimalPlacesValue)) { throw new Exception(ErrorResource.RoundingNotValid); } string result; var binaryDataListItem = colItr.FetchNextValue(expressionIterator); var val = binaryDataListItem; { var formatNumberTo = new FormatNumberTO(val, RoundingType, roundingDecimalPlacesValue, adjustDecimalPlaces, decimalPlacesToShowValue); result = _numberFormatter.Format(formatNumberTo); } if (single != null) { allErrors.AddError(single.Message); } else { UpdateResultRegions(dataObject.Environment, result, update == 0 ? counter : update); counter++; } } if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update)); } } catch (Exception e) { Dev2Logger.Error("DSFNumberFormatActivity", e, GlobalConstants.WarewolfError); allErrors.AddError(e.Message); } finally { if (allErrors.HasErrors()) { if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); DisplayAndWriteError(dataObject, DisplayName, allErrors); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
/// <summary> /// When overridden runs the activity's execution logic /// </summary> /// <param name="context">The context to be used.</param> protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); Guid dlId = dataObject.DataListID; ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); Guid executionId = dlId; allErrors.MergeErrors(errors); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); toUpsert.ResourceID = dataObject.ResourceID; InitializeDebug(dataObject); try { if (!errors.HasErrors()) { IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); IDev2DataListEvaluateIterator lengthItr = CreateDataListEvaluateIterator(Length, executionId, compiler, colItr, allErrors); IBinaryDataListEntry lengthEntry = compiler.Evaluate(executionId, enActionType.User, Length, false, out errors); IDev2DataListEvaluateIterator fromItr = CreateDataListEvaluateIterator(From, executionId, compiler, colItr, allErrors); IBinaryDataListEntry fromEntry = compiler.Evaluate(executionId, enActionType.User, From, false, out errors); IDev2DataListEvaluateIterator toItr = CreateDataListEvaluateIterator(To, executionId, compiler, colItr, allErrors); IBinaryDataListEntry toEntry = compiler.Evaluate(executionId, enActionType.User, To, false, out errors); if (dataObject.IsDebugMode()) { AddDebugInputItem(Length, From, To, fromEntry, toEntry, lengthEntry, executionId, RandomType); } Dev2Random dev2Random = new Dev2Random(); while (colItr.HasMoreData()) { int lengthNum = -1; int fromNum = -1; int toNum = -1; string fromValue = colItr.FetchNextRow(fromItr).TheValue; string toValue = colItr.FetchNextRow(toItr).TheValue; string lengthValue = colItr.FetchNextRow(lengthItr).TheValue; if (RandomType != enRandomType.Guid) { if (RandomType == enRandomType.Numbers) { #region Getting the From fromNum = GetFromValue(fromValue, out errors); if (errors.HasErrors()) { allErrors.MergeErrors(errors); continue; } #endregion #region Getting the To toNum = GetToValue(toValue, out errors); if (errors.HasErrors()) { allErrors.MergeErrors(errors); continue; } #endregion } else { #region Getting the Length lengthNum = GetLengthValue(lengthValue, out errors); if (errors.HasErrors()) { allErrors.MergeErrors(errors); continue; } #endregion } } string value = dev2Random.GetRandom(RandomType, lengthNum, fromNum, toNum); //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { toUpsert.Add(Result, value); toUpsert.FlushIterationFrame(); } } compiler.Upsert(executionId, toUpsert, out errors); if (dataObject.IsDebugMode()) { if (string.IsNullOrEmpty(Result)) { AddDebugOutputItem(new DebugItemStaticDataParams("", "Result")); } else { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } allErrors.MergeErrors(errors); } } catch (Exception e) { Dev2Logger.Log.Error("DSFRandomActivity", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfRandomActivity", 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); } } }
static void GetValue(IsSingleValueRule isSingleValueRule) { //------------Execute Test--------------------------- var err = isSingleValueRule.Check(); //------------Assert Results------------------------- Assert.IsNotNull(err); Assert.AreEqual("The result field only allows a single result", err.Message); }
private void TryExecute(IDSFDataObject dataObject, int update, ErrorResultTO allErrors, ErrorResultTO errors) { if (dataObject.IsDebugMode()) { if (string.IsNullOrEmpty(Input1)) { AddDebugInputItem(new DebugItemStaticDataParams(DateTime.Now.ToString(GlobalConstants.PreviousDev2DotNetDefaultDateTimeFormat), "now()", "Input 1", "=")); } else { AddDebugInputItem(Input1, "Input 1", dataObject.Environment, update); } if (string.IsNullOrEmpty(Input2)) { AddDebugInputItem(new DebugItemStaticDataParams(DateTime.Now.ToString(GlobalConstants.PreviousDev2DotNetDefaultDateTimeFormat), "now()", "Input 2", "=")); } else { AddDebugInputItem(Input2, "Input 2", dataObject.Environment, update); } AddDebugInputItem(InputFormat, "Input Format", dataObject.Environment, update); if (!String.IsNullOrEmpty(OutputType)) { AddDebugInputItem(new DebugItemStaticDataParams(OutputType, "Output In")); } } var colItr = new WarewolfListIterator(); var input1Itr = new WarewolfIterator(dataObject.Environment.EvalStrict(string.IsNullOrEmpty(Input1) ? GlobalConstants.CalcExpressionNow : Input1, update)); colItr.AddVariableToIterateOn(input1Itr); var evalInp2 = dataObject.Environment.EvalStrict(string.IsNullOrEmpty(Input2) ? GlobalConstants.CalcExpressionNow : Input2, update); var input2Itr = new WarewolfIterator(evalInp2); colItr.AddVariableToIterateOn(input2Itr); var ifItr = new WarewolfIterator(dataObject.Environment.Eval(InputFormat ?? string.Empty, update)); colItr.AddVariableToIterateOn(ifItr); var indexToUpsertTo = 1; while (colItr.HasMoreData()) { var transObj = ConvertToDateTimeDiffTo(colItr.FetchNextValue(input1Itr), colItr.FetchNextValue(input2Itr), colItr.FetchNextValue(ifItr), OutputType); //Create a DateTimeComparer using the DateTimeConverterFactory var comparer = DateTimeConverterFactory.CreateComparer(); var expression = Result; if (comparer.TryCompare(transObj, out string result, out string error)) { expression = GetExpression(update, indexToUpsertTo, expression); var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { dataObject.Environment.Assign(expression, result, update); } }
// ReSharper restore RedundantOverridenMember /// <summary> /// The execute method that is called when the activity is executed at run time and will hold all the logic of the activity /// </summary> protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); IDev2IndexFinder indexFinder = new Dev2IndexFinder(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); Guid executionId = DataListExecutionID.Get(context); InitializeDebug(dataObject); IDev2DataListUpsertPayloadBuilder <List <string> > toUpsert = Dev2DataListBuilderFactory.CreateStringListDataListUpsertBuilder(); IDev2DataListUpsertPayloadBuilder <string> toUpsertScalar = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(); toUpsert.IsDebug = dataObject.IsDebugMode(); toUpsertScalar.IsDebug = dataObject.IsDebugMode(); try { IDev2IteratorCollection outerIteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection(); IDev2IteratorCollection innerIteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection(); allErrors.MergeErrors(errors); IBinaryDataListEntry expressionsEntry = compiler.Evaluate(executionId, enActionType.User, Characters, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator itrChar = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry); outerIteratorCollection.AddIterator(itrChar); #region Iterate and Find Index expressionsEntry = compiler.Evaluate(executionId, enActionType.User, InField, false, out errors); if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugItemVariableParams(InField, "In Field", expressionsEntry, executionId)); AddDebugInputItem(new DebugItemStaticDataParams(Index, "Index")); AddDebugInputItem(new DebugItemVariableParams(Characters, "Characters", itrChar.FetchEntry(), executionId)); AddDebugInputItem(new DebugItemStaticDataParams(Direction, "Direction")); } var completeResultList = new List <string>(); while (outerIteratorCollection.HasMoreData()) { allErrors.MergeErrors(errors); errors.ClearErrors(); IDev2DataListEvaluateIterator itrInField = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntry); innerIteratorCollection.AddIterator(itrInField); string chars = outerIteratorCollection.FetchNextRow(itrChar).TheValue; while (innerIteratorCollection.HasMoreData()) { if (!string.IsNullOrEmpty(InField) && !string.IsNullOrEmpty(Characters)) { var val = innerIteratorCollection.FetchNextRow(itrInField); if (val != null) { IEnumerable <int> returedData = indexFinder.FindIndex(val.TheValue, Index, chars, Direction, MatchCase, StartIndex); completeResultList.AddRange(returedData.Select(value => value.ToString(CultureInfo.InvariantCulture)).ToList()); //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result } } } } var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { var rsType = DataListUtil.GetRecordsetIndexType(Result); if (rsType == enRecordsetIndexType.Numeric) { toUpsertScalar.Add(Result, string.Join(",", completeResultList)); compiler.Upsert(executionId, toUpsertScalar, out errors); allErrors.MergeErrors(errors); if (!allErrors.HasErrors() && dataObject.IsDebugMode()) { foreach (var debugOutputTo in toUpsertScalar.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } toUpsert.DebugOutputs.Clear(); } } else { toUpsert.Add(Result, completeResultList); compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); if (!allErrors.HasErrors() && dataObject.IsDebugMode()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } toUpsert.DebugOutputs.Clear(); } } } #endregion } catch (Exception e) { Dev2Logger.Log.Error("DSFFindActivity", e); allErrors.AddError(e.Message); } finally { #region Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfIndexActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); compiler.Upsert(executionId, Result, (string)null, out errors); } #endregion if (dataObject.IsDebugMode()) { if (hasErrors) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
// 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 dlId = dataObject.DataListID; ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); Guid executionId = dlId; allErrors.MergeErrors(errors); InitializeDebug(dataObject); // Process if no errors try { ValidateRecordsetName(RecordsetName, errors); allErrors.MergeErrors(errors); IBinaryDataList bdl = compiler.FetchBinaryDataList(executionId, out errors); allErrors.MergeErrors(errors); if (!allErrors.HasErrors()) { try { string err; IBinaryDataListEntry recset; string rs = DataListUtil.ExtractRecordsetNameFromValue(RecordsetName); bdl.TryGetEntry(rs, out recset, out err); allErrors.AddError(err); if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugItemVariableParams(RecordsetName, "Recordset", recset, executionId)); } var rule = new IsSingleValueRule(() => CountNumber); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { if (recset != null) { if (recset.Columns != null && CountNumber != string.Empty) { if (recset.IsEmpty()) { compiler.Upsert(executionId, CountNumber, "0", out errors); if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugOutputParams(CountNumber, "0", executionId, 0)); } allErrors.MergeErrors(errors); } else { int cnt = recset.ItemCollectionSize(); compiler.Upsert(executionId, CountNumber, cnt.ToString(CultureInfo.InvariantCulture), out errors); if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugOutputParams(CountNumber, cnt.ToString(CultureInfo.InvariantCulture), executionId, 0)); } allErrors.MergeErrors(errors); } allErrors.MergeErrors(errors); } else if (recset.Columns == null) { allErrors.AddError(RecordsetName + " is not a recordset"); } else if (CountNumber == string.Empty) { allErrors.AddError("Blank result variable"); } } allErrors.MergeErrors(errors); } } catch (Exception e) { allErrors.AddError(e.Message); compiler.Upsert(executionId, CountNumber, (string)null, out errors); } } } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfCountRecordsActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); } if (dataObject.IsDebugMode()) { DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
// 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(); IDev2MergeOperations mergeOperations = new Dev2MergeOperations(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errorResultTo = new ErrorResultTO(); Guid executionId = DataListExecutionID.Get(context); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); toUpsert.ResourceID = dataObject.ResourceID; InitializeDebug(dataObject); try { CleanArguments(MergeCollection); if (MergeCollection.Count <= 0) { return; } IDev2IteratorCollection iteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection(); allErrors.MergeErrors(errorResultTo); Dictionary <int, List <IDev2DataListEvaluateIterator> > listOfIterators = new Dictionary <int, List <IDev2DataListEvaluateIterator> >(); #region Create a iterator for each row in the data grid in the designer so that the right iteration happen on the data int dictionaryKey = 0; foreach (DataMergeDTO row in MergeCollection) { IBinaryDataListEntry inputVariableExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.InputVariable, false, out errorResultTo); allErrors.MergeErrors(errorResultTo); IBinaryDataListEntry atExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.At, false, out errorResultTo); allErrors.MergeErrors(errorResultTo); IBinaryDataListEntry paddingExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.Padding, false, out errorResultTo); allErrors.MergeErrors(errorResultTo); var fieldName = row.InputVariable; var splitIntoRegions = DataListCleaningUtils.FindAllLanguagePieces(fieldName); var datalist = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errorResultTo).ToString(); if (!string.IsNullOrEmpty(datalist)) { foreach (var region in splitIntoRegions) { var r = DataListUtil.IsValueRecordset(region) ? DataListUtil.ReplaceRecordsetIndexWithBlank(region) : region; var isValidExpr = new IsValidExpressionRule(() => r, datalist) { LabelText = fieldName }; var errorInfo = isValidExpr.Check(); if (errorInfo != null) { row.InputVariable = ""; errorResultTo.AddError(errorInfo.Message); } allErrors.MergeErrors(errorResultTo); } } allErrors.MergeErrors(errorResultTo); if (dataObject.IsDebugMode()) { DebugItem debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", (MergeCollection.IndexOf(row) + 1).ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugItemVariableParams(row.InputVariable, "", inputVariableExpressionEntry, executionId), debugItem); AddDebugItem(new DebugItemStaticDataParams(row.MergeType, "With"), debugItem); AddDebugItem(new DebugItemVariableParams(row.At, "Using", atExpressionEntry, executionId), debugItem); AddDebugItem(new DebugItemVariableParams(row.Padding, "Pad", paddingExpressionEntry, executionId), debugItem); //Old workflows don't have this set. if (row.Alignment == null) { row.Alignment = string.Empty; } AddDebugItem(DataListUtil.IsEvaluated(row.Alignment) ? new DebugItemStaticDataParams("", row.Alignment, "Align") : new DebugItemStaticDataParams(row.Alignment, "Align"), debugItem); _debugInputs.Add(debugItem); } IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(inputVariableExpressionEntry); IDev2DataListEvaluateIterator atItr = Dev2ValueObjectFactory.CreateEvaluateIterator(atExpressionEntry); IDev2DataListEvaluateIterator padItr = Dev2ValueObjectFactory.CreateEvaluateIterator(paddingExpressionEntry); iteratorCollection.AddIterator(itr); iteratorCollection.AddIterator(atItr); iteratorCollection.AddIterator(padItr); listOfIterators.Add(dictionaryKey, new List <IDev2DataListEvaluateIterator> { itr, atItr, padItr }); dictionaryKey++; } #endregion #region Iterate and Merge Data if (!allErrors.HasErrors()) { while (iteratorCollection.HasMoreData()) { int pos = 0; foreach (var iterator in listOfIterators) { var val = iteratorCollection.FetchNextRow(iterator.Value[0]); var at = iteratorCollection.FetchNextRow(iterator.Value[1]); var pad = iteratorCollection.FetchNextRow(iterator.Value[2]); if (val != null) { if (at != null) { if (pad != null) { if (MergeCollection[pos].MergeType == "Index") { if (string.IsNullOrEmpty(at.TheValue)) { allErrors.AddError("The 'Using' value cannot be blank."); } int atValue; if (!Int32.TryParse(at.TheValue, out atValue) || atValue < 0) { allErrors.AddError("The 'Using' value must be a real number."); } if (pad.TheValue.Length > 1) { allErrors.AddError("'Padding' must be a single character"); } } else { if (MergeCollection[pos].MergeType == "Chars" && string.IsNullOrEmpty(at.TheValue)) { allErrors.AddError("The 'Using' value cannot be blank."); } } mergeOperations.Merge(val.TheValue, MergeCollection[pos].MergeType, at.TheValue, pad.TheValue, MergeCollection[pos].Alignment); pos++; } } } } } if (!allErrors.HasErrors()) { if (string.IsNullOrEmpty(Result)) { AddDebugOutputItem(new DebugItemStaticDataParams("", "")); } else { var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { toUpsert.Add(Result, mergeOperations.MergeData.ToString()); toUpsert.FlushIterationFrame(); compiler.Upsert(executionId, toUpsert, out errorResultTo); allErrors.MergeErrors(errorResultTo); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { if (debugOutputTo.LeftEntry != null && debugOutputTo.TargetEntry != null) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } } } } } #endregion Iterate and Merge Data } catch (Exception e) { Dev2Logger.Log.Error("DSFDataMerge", e); allErrors.AddError(e.Message); } finally { #region Handle Errors if (allErrors.HasErrors()) { if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DisplayAndWriteError("DsfDataMergeActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errorResultTo); compiler.Upsert(executionId, Result, (string)null, out errorResultTo); } if (dataObject.IsDebugMode()) { DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } #endregion } }
/// <summary> /// Executes the logic of the activity and calls the backend code to do the work /// Also responsible for adding the results to the data list /// </summary> /// <param name="context"></param> protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDev2ReplaceOperation replaceOperation = Dev2OperationsFactory.CreateReplaceOperation(); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(false); toUpsert.IsDebug = dataObject.IsDebugMode(); ErrorResultTO errors; ErrorResultTO allErrors = new ErrorResultTO(); Guid executionId = DataListExecutionID.Get(context); IDev2IteratorCollection iteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection(); IBinaryDataListEntry expressionsEntryFind = compiler.Evaluate(executionId, enActionType.User, Find, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator itrFind = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntryFind); iteratorCollection.AddIterator(itrFind); IBinaryDataListEntry expressionsEntryReplaceWith = compiler.Evaluate(executionId, enActionType.User, ReplaceWith, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator itrReplace = Dev2ValueObjectFactory.CreateEvaluateIterator(expressionsEntryReplaceWith); iteratorCollection.AddIterator(itrReplace); int replacementCount = 0; int replacementTotal = 0; InitializeDebug(dataObject); try { IList <string> toSearch = FieldsToSearch.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (var s in toSearch) { if (dataObject.IsDebugMode()) { IBinaryDataListEntry inFieldsEntry = compiler.Evaluate(executionId, enActionType.User, s, false, out errors); AddDebugInputItem(new DebugItemVariableParams(s, "In Field(s)", inFieldsEntry, executionId)); } } var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { while (iteratorCollection.HasMoreData()) { // now process each field for entire evaluated Where expression.... var findValue = iteratorCollection.FetchNextRow(itrFind).TheValue; var replaceWithValue = iteratorCollection.FetchNextRow(itrReplace).TheValue; foreach (string s in toSearch) { if (!DataListUtil.IsEvaluated(s)) { allErrors.AddError("Please insert only variables into Fields To Search"); return; } if (!string.IsNullOrEmpty(findValue)) { IBinaryDataListEntry entryToReplaceIn; toUpsert = replaceOperation.Replace(executionId, s.Trim(), findValue, replaceWithValue, CaseMatch, toUpsert, out errors, out replacementCount, out entryToReplaceIn); } replacementTotal += replacementCount; allErrors.MergeErrors(errors); } } } if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugItemVariableParams(Find, "Find", expressionsEntryFind, executionId)); AddDebugInputItem(new DebugItemVariableParams(ReplaceWith, "Replace With", expressionsEntryReplaceWith, executionId)); } toUpsert.Add(Result, replacementTotal.ToString(CultureInfo.InvariantCulture)); // now push the result to the server compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } // ReSharper disable EmptyGeneralCatchClause catch (Exception ex) { Dev2Logger.Log.Error("DSFReplace", ex); allErrors.AddError(ex.Message); } finally { if (allErrors.HasErrors()) { if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DisplayAndWriteError("DsfReplaceActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); compiler.Upsert(executionId, Result, (string)null, out errors); } if (dataObject.IsDebugMode()) { DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); allErrors.MergeErrors(errors); InitializeDebug(dataObject); // Process if no errors try { ValidateRecordsetName(RecordsetName, errors); allErrors.MergeErrors(errors); if (!allErrors.HasErrors()) { try { string rs = DataListUtil.ExtractRecordsetNameFromValue(RecordsetName); if (RecordsLength == string.Empty) { allErrors.AddError(ErrorResource.BlankResultVariable); } if (dataObject.IsDebugMode()) { var warewolfEvalResult = dataObject.Environment.Eval(RecordsetName.Replace("()", "(*)"), update); if (warewolfEvalResult.IsWarewolfRecordSetResult) { var recsetResult = warewolfEvalResult as CommonFunctions.WarewolfEvalResult.WarewolfRecordSetResult; if (recsetResult != null) { AddDebugInputItem(new DebugItemWarewolfRecordset(recsetResult.Item, RecordsetName, "Recordset", "=")); } } if (warewolfEvalResult.IsWarewolfAtomListresult) { var recsetResult = warewolfEvalResult as CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult; if (recsetResult != null) { AddDebugInputItem(new DebugEvalResult(RecordsetName, "Recordset", dataObject.Environment, update)); } } } var rule = new IsSingleValueRule(() => RecordsLength); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { var count = 0; if (dataObject.Environment.HasRecordSet(RecordsetName)) { count = dataObject.Environment.GetLength(rs); } else { allErrors.AddError("Recordset: " + RecordsetName + " does not exist."); } var value = count.ToString(); dataObject.Environment.Assign(RecordsLength, value, update); AddDebugOutputItem(new DebugItemWarewolfAtomResult(value, RecordsLength, "")); } } catch (Exception e) { allErrors.AddError(e.Message); dataObject.Environment.Assign(RecordsLength, "0", update); AddDebugOutputItem(new DebugItemStaticDataParams("0", RecordsLength, "", "=")); } } } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfRecordsetLengthActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
// ReSharper restore RedundantOverridenMember /// <summary> /// The execute method that is called when the activity is executed at run time and will hold all the logic of the activity /// </summary> protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); toUpsert.ReplaceStarWithFixedIndex = true; ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); Guid executionId = DataListExecutionID.Get(context); InitializeDebug(dataObject); try { CleanArgs(); ICaseConverter converter = CaseConverterFactory.CreateCaseConverter(); allErrors.MergeErrors(errors); int index = 1; int outIndex = 0; foreach (ICaseConvertTO item in ConvertCollection) { outIndex++; IBinaryDataListEntry tmp = compiler.Evaluate(executionId, enActionType.User, item.StringToConvert, false, out errors); allErrors.MergeErrors(errors); ValidateVariable(item.Result, compiler, dataObject, out errors); allErrors.MergeErrors(errors); IsSingleValueRule.ApplyIsSingleValueRule(item.ExpressionToConvert, allErrors); if (dataObject.IsDebugMode()) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", index.ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugItemVariableParams(item.StringToConvert, "Convert", tmp, executionId), debugItem); AddDebugItem(new DebugItemStaticDataParams(item.ConvertType, "To"), debugItem); _debugInputs.Add(debugItem); index++; } if (tmp != null) { IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(tmp); while (itr.HasMoreRecords()) { foreach (IBinaryDataListItem itm in itr.FetchNextRowData()) { try { IBinaryDataListItem res = converter.TryConvert(item.ConvertType, itm); string expression = item.Result; // 27.08.2013 // NOTE : The result must remain [ as this is how the fliping studio generates the result when using (*) notation // There is a proper bug in to fix this issue, but since the studio is spaghetti I will leave this to the experts ;) // This is a tmp fix to the issue if (expression == "[" || DataListUtil.GetRecordsetIndexType(expression) == enRecordsetIndexType.Star) { expression = DataListUtil.AddBracketsToValueIfNotExist(res.DisplayValue); } //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result IsSingleValueRule rule = new IsSingleValueRule(() => expression); var singleresError = rule.Check(); if (singleresError != null) { allErrors.AddError(singleresError.Message); } else { toUpsert.Add(expression, res.TheValue); // Upsert the entire payload } allErrors.MergeErrors(errors); } catch (Exception e) { allErrors.AddError(e.Message); toUpsert.Add(item.Result, null); } } } compiler.Upsert(executionId, toUpsert, out errors); if (!allErrors.HasErrors() && dataObject.IsDebugMode()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", outIndex.ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugItemVariableParams(debugOutputTo), debugItem); _debugOutputs.Add(debugItem); } toUpsert.DebugOutputs.Clear(); } } } } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfCaseConvertActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); } if (dataObject.IsDebugMode()) { if (hasErrors) { int outIndex = 1; foreach (ICaseConvertTO item in ConvertCollection) { IBinaryDataListEntry tmp = compiler.Evaluate(executionId, enActionType.User, item.StringToConvert, false, out errors); var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", outIndex.ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugItemVariableParams(item.Result, "", tmp, executionId), debugItem); _debugOutputs.Add(debugItem); outIndex++; } } DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }
#pragma warning disable S1541 // Methods and properties should not be too complex #pragma warning disable S3776 // Cognitive Complexity of methods should not be too high private ErrorResultTO UpdateEnvironment(IDSFDataObject dataObject, int update, ErrorResultTO allErrors, IExecutionEnvironment env, ErrorResultTO errors) #pragma warning restore S3776 // Cognitive Complexity of methods should not be too high #pragma warning restore S1541 // Methods and properties should not be too complex { if (dataObject.IsDebugMode()) { AddDebugInputItem(Length, From, To, dataObject.Environment, RandomType, update); } var lengthItr = !String.IsNullOrEmpty(Length) ? new WarewolfIterator(env.EvalStrict(Length, update)) as IWarewolfIterator : new WarewolfAtomIterator(new[] { DataStorage.WarewolfAtom.Nothing, }); var fromItr = !String.IsNullOrEmpty(From) ? new WarewolfIterator(env.EvalStrict(From, update)) as IWarewolfIterator : new WarewolfAtomIterator(new[] { DataStorage.WarewolfAtom.Nothing, }); var toItr = !String.IsNullOrEmpty(To) ? new WarewolfIterator(env.EvalStrict(To, update)) as IWarewolfIterator : new WarewolfAtomIterator(new[] { DataStorage.WarewolfAtom.Nothing, }); var colItr = new WarewolfListIterator(); colItr.AddVariableToIterateOn(lengthItr); colItr.AddVariableToIterateOn(fromItr); colItr.AddVariableToIterateOn(toItr); var dev2Random = new Dev2Random(); var counter = 1; while (colItr.HasMoreData()) { var lengthNum = -1; var fromNum = -1.0; var toNum = -1.0; var fromValue = colItr.FetchNextValue(fromItr); var toValue = colItr.FetchNextValue(toItr); var lengthValue = colItr.FetchNextValue(lengthItr); if (RandomType == enRandomType.Numbers) { #region Getting the From fromNum = GetFromValue(fromValue, out errors); if (errors.HasErrors()) { allErrors.MergeErrors(errors); continue; } #endregion #region Getting the To toNum = GetToValue(toValue, out errors); if (errors.HasErrors()) { allErrors.MergeErrors(errors); continue; } #endregion } if (RandomType != enRandomType.Numbers && RandomType != enRandomType.Guid) { #region Getting the Length lengthNum = GetLengthValue(lengthValue, out errors); if (errors.HasErrors()) { allErrors.MergeErrors(errors); continue; } #endregion } var value = dev2Random.GetRandom(RandomType, lengthNum, fromNum, toNum); var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { env.Assign(Result, value, update == 0 ? counter : update); } counter++; } return(errors); }
protected override void ExecuteTool(IDSFDataObject dataObject) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDev2ReplaceOperation replaceOperation = Dev2OperationsFactory.CreateReplaceOperation(); ErrorResultTO errors; ErrorResultTO allErrors = new ErrorResultTO(); int replacementCount = 0; int replacementTotal = 0; InitializeDebug(dataObject); try { IList <string> toSearch = FieldsToSearch.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (var s in toSearch) { if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugEvalResult(s, "In Field(s)", dataObject.Environment)); if (Find != null) { AddDebugInputItem(new DebugEvalResult(Find, "Find", dataObject.Environment)); } if (ReplaceWith != null) { AddDebugInputItem(new DebugEvalResult(ReplaceWith, "Replace With", dataObject.Environment)); } } } IWarewolfListIterator iteratorCollection = new WarewolfListIterator(); var finRes = dataObject.Environment.Eval(Find); if (ExecutionEnvironment.IsNothing(finRes)) { if (!string.IsNullOrEmpty(Result)) { dataObject.Environment.Assign(Result, replacementTotal.ToString(CultureInfo.InvariantCulture)); } } else { var itrFind = new WarewolfIterator(dataObject.Environment.Eval(Find)); iteratorCollection.AddVariableToIterateOn(itrFind); var itrReplace = new WarewolfIterator(dataObject.Environment.Eval(ReplaceWith)); iteratorCollection.AddVariableToIterateOn(itrReplace); var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { while (iteratorCollection.HasMoreData()) { // now process each field for entire evaluated Where expression.... var findValue = iteratorCollection.FetchNextValue(itrFind); var replaceWithValue = iteratorCollection.FetchNextValue(itrReplace); foreach (string s in toSearch) { if (!DataListUtil.IsEvaluated(s)) { allErrors.AddError("Please insert only variables into Fields To Search"); return; } if (!string.IsNullOrEmpty(findValue)) { dataObject.Environment.ApplyUpdate(s, a => DataASTMutable.WarewolfAtom.NewDataString(replaceOperation.Replace(a.ToString(), findValue, replaceWithValue, CaseMatch, out errors, ref replacementCount))); } replacementTotal += replacementCount; if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { if (!string.IsNullOrEmpty(Result)) { if (replacementCount > 0) { AddDebugOutputItem(new DebugEvalResult(s, "", dataObject.Environment)); } } } } } } if (!string.IsNullOrEmpty(Result)) { dataObject.Environment.Assign(Result, replacementTotal.ToString(CultureInfo.InvariantCulture)); } } if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { if (!string.IsNullOrEmpty(Result)) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment)); } } // now push the result to the server } // ReSharper disable EmptyGeneralCatchClause catch (Exception ex) { Dev2Logger.Log.Error("DSFReplace", ex); allErrors.AddError(ex.Message); } finally { if (allErrors.HasErrors()) { if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DisplayAndWriteError("DsfReplaceActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); dataObject.Environment.Assign(Result, null); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before); DispatchDebugState(dataObject, StateType.After); } } }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { IDev2IndexFinder indexFinder = new Dev2IndexFinder(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); InitializeDebug(dataObject); try { var outerIteratorCollection = new WarewolfListIterator(); var innerIteratorCollection = new WarewolfListIterator(); allErrors.MergeErrors(errors); #region Iterate and Find Index if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugEvalResult(InField, "In Field", dataObject.Environment, update)); AddDebugInputItem(new DebugItemStaticDataParams(Index, "Index")); AddDebugInputItem(new DebugEvalResult(Characters, "Characters", dataObject.Environment, update)); AddDebugInputItem(new DebugItemStaticDataParams(Direction, "Direction")); } var itrChar = new WarewolfIterator(dataObject.Environment.Eval(Characters, update)); outerIteratorCollection.AddVariableToIterateOn(itrChar); var completeResultList = new List <string>(); if (String.IsNullOrEmpty(InField)) { allErrors.AddError(string.Format(ErrorResource.IsBlank, "'In Field'")); } else if (String.IsNullOrEmpty(Characters)) { allErrors.AddError(string.Format(ErrorResource.IsBlank, "'Characters'")); } else { while (outerIteratorCollection.HasMoreData()) { allErrors.MergeErrors(errors); errors.ClearErrors(); var itrInField = new WarewolfIterator(dataObject.Environment.Eval(InField, update)); innerIteratorCollection.AddVariableToIterateOn(itrInField); string chars = outerIteratorCollection.FetchNextValue(itrChar); while (innerIteratorCollection.HasMoreData()) { if (!string.IsNullOrEmpty(InField) && !string.IsNullOrEmpty(Characters)) { var val = innerIteratorCollection.FetchNextValue(itrInField); if (val != null) { IEnumerable <int> returedData = indexFinder.FindIndex(val, Index, chars, Direction, MatchCase, StartIndex); completeResultList.AddRange(returedData.Select(value => value.ToString(CultureInfo.InvariantCulture)).ToList()); var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { dataObject.Environment.Assign(Result, string.Join(",", completeResultList), update); allErrors.MergeErrors(errors); } } } completeResultList = new List <string>(); } } if (!allErrors.HasErrors() && dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update)); } } #endregion } catch (Exception e) { Dev2Logger.Error("DSFFindActivity", e); allErrors.AddError(e.Message); } finally { #region Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfIndexActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } #endregion if (dataObject.IsDebugMode()) { if (hasErrors) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update)); } DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
// ReSharper restore RedundantOverridenMember /// <summary> /// The execute method that is called when the activity is executed at run time and will hold all the logic of the activity /// </summary> protected override void OnExecute(NativeActivityContext context) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); IDSFDataObject dataObject = context.GetExtension <IDSFDataObject>(); IDataListCompiler compiler = DataListFactory.CreateDataListCompiler(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errors = new ErrorResultTO(); Guid executionId = DataListExecutionID.Get(context); allErrors.MergeErrors(errors); InitializeDebug(dataObject); // Process if no errors try { IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true); toUpsert.IsDebug = dataObject.IsDebugMode(); IDev2IteratorCollection colItr = Dev2ValueObjectFactory.CreateIteratorCollection(); var datalist = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errors).ToString(); if (!string.IsNullOrEmpty(datalist)) { ValidateInput(datalist, allErrors, Input1); ValidateInput(datalist, allErrors, Input2); } IBinaryDataListEntry input1Entry = compiler.Evaluate(executionId, enActionType.User, string.IsNullOrEmpty(Input1) ? GlobalConstants.CalcExpressionNow : Input1, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator input1Itr = Dev2ValueObjectFactory.CreateEvaluateIterator(input1Entry); colItr.AddIterator(input1Itr); IBinaryDataListEntry input2Entry = compiler.Evaluate(executionId, enActionType.User, string.IsNullOrEmpty(Input2) ? GlobalConstants.CalcExpressionNow : Input2, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator input2Itr = Dev2ValueObjectFactory.CreateEvaluateIterator(input2Entry); colItr.AddIterator(input2Itr); IBinaryDataListEntry inputFormatEntry = compiler.Evaluate(executionId, enActionType.User, InputFormat ?? string.Empty, false, out errors); allErrors.MergeErrors(errors); IDev2DataListEvaluateIterator ifItr = Dev2ValueObjectFactory.CreateEvaluateIterator(inputFormatEntry); colItr.AddIterator(ifItr); if (dataObject.IsDebugMode()) { AddDebugInputItem(string.IsNullOrEmpty(Input1) ? GlobalConstants.CalcExpressionNow : Input1, "Input 1", input1Entry, executionId); AddDebugInputItem(string.IsNullOrEmpty(Input2) ? GlobalConstants.CalcExpressionNow : Input2, "Input 2", input2Entry, executionId); AddDebugInputItem(InputFormat, "Input Format", inputFormatEntry, executionId); AddDebugInputItem(new DebugItemStaticDataParams(OutputType, "Output In")); } int indexToUpsertTo = 1; while (colItr.HasMoreData()) { IDateTimeDiffTO transObj = ConvertToDateTimeDiffTo(colItr.FetchNextRow(input1Itr).TheValue, colItr.FetchNextRow(input2Itr).TheValue, colItr.FetchNextRow(ifItr).TheValue, OutputType); //Create a DateTimeComparer using the DateTimeConverterFactory IDateTimeComparer comparer = DateTimeConverterFactory.CreateComparer(); //Call the TryComparer method on the DateTimeComparer and pass it the IDateTimeDiffTO created from the ConvertToDateTimeDiffTO Method string result; string error; if (comparer.TryCompare(transObj, out result, out error)) { string expression; if (DataListUtil.IsValueRecordset(Result) && DataListUtil.GetRecordsetIndexType(Result) == enRecordsetIndexType.Star) { expression = Result.Replace(GlobalConstants.StarExpression, indexToUpsertTo.ToString(CultureInfo.InvariantCulture)); } else { expression = Result; } //2013.06.03: Ashley Lewis for bug 9498 - handle multiple regions in result var rule = new IsSingleValueRule(() => Result); var single = rule.Check(); if (single != null) { allErrors.AddError(single.Message); } else { toUpsert.Add(expression, result); } } else { DoDebugOutput(dataObject, Result, result, executionId, indexToUpsertTo); allErrors.AddError(error); } indexToUpsertTo++; } compiler.Upsert(executionId, toUpsert, out errors); allErrors.MergeErrors(errors); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { foreach (var debugOutputTo in toUpsert.DebugOutputs) { AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo)); } } } catch (Exception e) { Dev2Logger.Log.Error("DSFDateTime", e); allErrors.AddError(e.Message); } finally { // Handle Errors if (allErrors.HasErrors()) { DisplayAndWriteError("DsfDateTimeDifferenceActivity", allErrors); compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors); compiler.Upsert(executionId, Result, (string)null, out errors); } if (dataObject.IsDebugMode()) { DispatchDebugState(context, StateType.Before); DispatchDebugState(context, StateType.After); } } }