protected override void ExecuteTool(IDSFDataObject dataObject, int update) { IDev2IndexFinder indexFinder = new Dev2IndexFinder(); var allErrors = new ErrorResultTO(); var errors = new ErrorResultTO(); InitializeDebug(dataObject); try { TryExecute(dataObject, update, indexFinder, allErrors, errors); } catch (Exception e) { Dev2Logger.Error("DSFFindActivity", e, GlobalConstants.WarewolfError); 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); } } }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { IDev2IndexFinder indexFinder = new Dev2IndexFinder(); var allErrors = new ErrorResultTO(); var errors = new ErrorResultTO(); InitializeDebug(dataObject); try { TryExecute(dataObject, update, indexFinder, allErrors, errors); } catch (Exception e) { allErrors.AddError(e.Message); } finally { var hasErrors = allErrors.HasErrors(); if (hasErrors) { var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); DisplayAndWriteError(dataObject, DisplayName, allErrors); } if (dataObject.IsDebugMode()) { if (hasErrors) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update)); } DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
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); } } }
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); } } }
// 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); } } }