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 #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); }
/// <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); } } }