protected override void ExecuteTool(IDSFDataObject dataObject, int update) { _dataObject = dataObject; ErrorResultTO allErrors = new ErrorResultTO(); int indexToUpsertTo = 0; InitializeDebug(dataObject); try { var runtimeSource = ResourceCatalog.Instance.GetResource <EmailSource>(dataObject.WorkspaceID, SelectedEmailSource.ResourceID); if (runtimeSource == null) { dataObject.Environment.Errors.Add("Invalid Email Source"); return; } if (IsDebug) { var fromAccount = FromAccount; if (String.IsNullOrEmpty(fromAccount)) { fromAccount = runtimeSource.UserName; AddDebugInputItem(fromAccount, "From Account"); } else { AddDebugInputItem(new DebugEvalResult(FromAccount, "From Account", dataObject.Environment, update)); } AddDebugInputItem(new DebugEvalResult(To, "To", dataObject.Environment, update)); AddDebugInputItem(new DebugEvalResult(Subject, "Subject", dataObject.Environment, update)); AddDebugInputItem(new DebugEvalResult(Body, "Body", dataObject.Environment, update)); } var colItr = new WarewolfListIterator(); var fromAccountItr = new WarewolfIterator(dataObject.Environment.Eval(FromAccount ?? string.Empty, update)); colItr.AddVariableToIterateOn(fromAccountItr); var passwordItr = new WarewolfIterator(dataObject.Environment.Eval(DecryptedPassword, update)); colItr.AddVariableToIterateOn(passwordItr); var toItr = new WarewolfIterator(dataObject.Environment.Eval(To, update)); colItr.AddVariableToIterateOn(toItr); var ccItr = new WarewolfIterator(dataObject.Environment.Eval(Cc, update)); colItr.AddVariableToIterateOn(ccItr); var bccItr = new WarewolfIterator(dataObject.Environment.Eval(Bcc, update)); colItr.AddVariableToIterateOn(bccItr); var subjectItr = new WarewolfIterator(dataObject.Environment.Eval(Subject, update)); colItr.AddVariableToIterateOn(subjectItr); var bodyItr = new WarewolfIterator(dataObject.Environment.Eval(Body ?? string.Empty, update)); colItr.AddVariableToIterateOn(bodyItr); var attachmentsItr = new WarewolfIterator(dataObject.Environment.Eval(Attachments ?? string.Empty, update)); colItr.AddVariableToIterateOn(attachmentsItr); if (!allErrors.HasErrors()) { while (colItr.HasMoreData()) { ErrorResultTO errors; var result = SendEmail(runtimeSource, colItr, fromAccountItr, passwordItr, toItr, ccItr, bccItr, subjectItr, bodyItr, attachmentsItr, out errors); allErrors.MergeErrors(errors); if (!allErrors.HasErrors()) { indexToUpsertTo = UpsertResult(indexToUpsertTo, dataObject.Environment, result, update); } } if (IsDebug && !allErrors.HasErrors()) { if (!string.IsNullOrEmpty(Result)) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update)); } } } else { if (IsDebug) { AddDebugInputItem(FromAccount, "From Account"); AddDebugInputItem(To, "To"); AddDebugInputItem(Subject, "Subject"); AddDebugInputItem(Body, "Body"); } } } catch (Exception e) { Dev2Logger.Log.Error("DSFEmail", e); allErrors.AddError(e.Message); } finally { // Handle Errors if (allErrors.HasErrors()) { foreach (var err in allErrors.FetchErrors()) { dataObject.Environment.Errors.Add(err); } UpsertResult(indexToUpsertTo, dataObject.Environment, null, update); if (dataObject.IsDebugMode()) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DisplayAndWriteError("DsfSendEmailActivity", allErrors); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
protected void ExecuteImpl(out ErrorResultTO errors, int update) { errors = new ErrorResultTO(); #region Create OutputFormatter // ReSharper disable RedundantAssignment IOutputFormatter outputFormatter = null; // ReSharper restore RedundantAssignment try { if (!string.IsNullOrEmpty(InstanceOutputDefintions)) { outputFormatter = GetOutputFormatter(Service); } } catch (Exception) { if (HandlesOutputFormatting) { errors.AddError( string.Format(ErrorResource.InvalidOutputFormat + "Please edit and remap.", Service.ResourceName)); return; } } if (HandlesOutputFormatting && outputFormatter == null && !string.IsNullOrEmpty(InstanceOutputDefintions)) { errors.AddError(string.Format(ErrorResource.InvalidOutputFormat, Service.ResourceName)); return; } #endregion try { ErrorResultTO invokeErrors; var itrs = new List <IWarewolfIterator>(5); IWarewolfListIterator itrCollection = new WarewolfListIterator(); if (string.IsNullOrEmpty(InstanceInputDefinitions) && string.IsNullOrEmpty(InstanceOutputDefintions)) { if (Inputs != null && Inputs.Count == 0) { ExecuteService(out invokeErrors, update, outputFormatter); errors.MergeErrors(invokeErrors); return; } else { BuildParameterIterators(update, null, itrCollection, itrs); while (itrCollection.HasMoreData()) { ExecuteService(itrCollection, itrs, out invokeErrors, update, outputFormatter); errors.MergeErrors(invokeErrors); } return; } } ServiceMethod method = Service.Method; var inputs = method.Parameters; if (inputs.Count == 0) { ExecuteService(out invokeErrors, update, outputFormatter); errors.MergeErrors(invokeErrors); } else { BuildParameterIterators(update, inputs, itrCollection, itrs); while (itrCollection.HasMoreData()) { ExecuteService(itrCollection, itrs, out invokeErrors, update, outputFormatter); errors.MergeErrors(invokeErrors); } } } finally { var disposable = Service as IDisposable; disposable?.Dispose(); // ensure errors bubble up ;) errors.MergeErrors(ErrorResult); } }
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) { 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>(); 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); } } }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { _debugInputs = new List <DebugItem>(); _debugOutputs = new List <DebugItem>(); _indexCounter = 1; ErrorResultTO allErrors = new ErrorResultTO(); try { var sharepointReadListTos = _sharepointUtils.GetValidReadListItems(ReadListItems).ToList(); if (sharepointReadListTos.Any()) { var sharepointSource = ResourceCatalog.GetResource <SharepointSource>(dataObject.WorkspaceID, SharepointServerResourceId); Dictionary <string, IWarewolfIterator> listOfIterators = new Dictionary <string, IWarewolfIterator>(); if (sharepointSource == null) { var contents = ResourceCatalog.GetResourceContents(dataObject.WorkspaceID, SharepointServerResourceId); sharepointSource = new SharepointSource(contents.ToXElement()); } var env = dataObject.Environment; if (dataObject.IsDebugMode()) { AddInputDebug(env, update); } var sharepointHelper = sharepointSource.CreateSharepointHelper(); var fields = sharepointHelper.LoadFieldsForList(SharepointList, true); using (var ctx = sharepointHelper.GetContext()) { var list = sharepointHelper.LoadFieldsForList(SharepointList, ctx, true); var iteratorList = new WarewolfListIterator(); foreach (var sharepointReadListTo in sharepointReadListTos) { var warewolfIterator = new WarewolfIterator(env.Eval(sharepointReadListTo.VariableName, update)); iteratorList.AddVariableToIterateOn(warewolfIterator); listOfIterators.Add(sharepointReadListTo.FieldName, warewolfIterator); } while (iteratorList.HasMoreData()) { var itemCreateInfo = new ListItemCreationInformation(); var listItem = list.AddItem(itemCreateInfo); foreach (var warewolfIterator in listOfIterators) { var sharepointFieldTo = fields.FirstOrDefault(to => to.Name == warewolfIterator.Key); if (sharepointFieldTo != null) { object value = warewolfIterator.Value.GetNextValue(); value = _sharepointUtils.CastWarewolfValueToCorrectType(value, sharepointFieldTo.Type); listItem[sharepointFieldTo.InternalName] = value; } } listItem.Update(); ctx.ExecuteQuery(); } } if (!string.IsNullOrEmpty(Result)) { env.Assign(Result, "Success", update); AddOutputDebug(dataObject, env, update); } } } catch (Exception e) { Dev2Logger.Error("SharepointCreateListItemActivity", e); allErrors.AddError(e.Message); } finally { var hasErrors = allErrors.HasErrors(); if (hasErrors) { dataObject.Environment.Assign(Result, "Failed", update); DisplayAndWriteError("SharepointCreateListItemActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
protected override IList <OutputTO> ExecuteConcreteAction(IDSFDataObject dataObject, out ErrorResultTO allErrors) { IList <OutputTO> outputs = new List <OutputTO>(); allErrors = new ErrorResultTO(); var colItr = new WarewolfListIterator(); //get all the possible paths for all the string variables var inputItr = new WarewolfIterator(dataObject.Environment.Eval(OutputPath)); colItr.AddVariableToIterateOn(inputItr); var unameItr = new WarewolfIterator(dataObject.Environment.Eval(Username)); colItr.AddVariableToIterateOn(unameItr); var passItr = new WarewolfIterator(dataObject.Environment.Eval(Password)); colItr.AddVariableToIterateOn(passItr); var contentItr = new WarewolfIterator(dataObject.Environment.Eval(FileContents)); colItr.AddVariableToIterateOn(contentItr); outputs.Add(DataListFactory.CreateOutputTO(Result)); if (dataObject.IsDebugMode()) { AddDebugInputItem(OutputPath, "Output Path", dataObject.Environment); AddDebugInputItem(new DebugItemStaticDataParams(GetMethod(), "Method")); AddDebugInputItemUserNamePassword(dataObject.Environment); AddDebugInputItem(FileContents, "File Contents", dataObject.Environment); } while (colItr.HasMoreData()) { IActivityOperationsBroker broker = ActivityIOFactory.CreateOperationsBroker(); var writeType = GetCorrectWriteType(); Dev2PutRawOperationTO putTo = ActivityIOFactory.CreatePutRawOperationTO(writeType, TextUtils.ReplaceWorkflowNewLinesWithEnvironmentNewLines(colItr.FetchNextValue(contentItr))); IActivityIOPath opath = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(inputItr), colItr.FetchNextValue(unameItr), colItr.FetchNextValue(passItr), true); IActivityIOOperationsEndPoint endPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(opath); try { if (allErrors.HasErrors()) { outputs[0].OutputStrings.Add(null); } else { string result = broker.PutRaw(endPoint, putTo); outputs[0].OutputStrings.Add(result); } } catch (Exception e) { outputs[0].OutputStrings.Add(null); allErrors.AddError(e.Message); break; } } return(outputs); }
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); } }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { _debugOutputs.Clear(); _debugInputs.Clear(); if (WebRequestInvoker == null) { return; } var allErrors = new ErrorResultTO(); InitializeDebug(dataObject); try { allErrors.MergeErrors(errorsTo); if (dataObject.IsDebugMode()) { DebugItem debugItem = new DebugItem(); AddDebugItem(new DebugEvalResult(Url, "URL", dataObject.Environment, update), debugItem); _debugInputs.Add(debugItem); } var colItr = new WarewolfListIterator(); var urlitr = new WarewolfIterator(dataObject.Environment.Eval(Url, update)); var headerItr = new WarewolfIterator(dataObject.Environment.Eval(Headers, update)); colItr.AddVariableToIterateOn(urlitr); colItr.AddVariableToIterateOn(headerItr); while (colItr.HasMoreData()) { var c = colItr.FetchNextValue(urlitr); var headerValue = colItr.FetchNextValue(headerItr); var headers = string.IsNullOrEmpty(headerValue) ? new string[0] : headerValue.Split(new[] { '\n', '\r', ';' }, StringSplitOptions.RemoveEmptyEntries); var headersEntries = new List <Tuple <string, string> >(); foreach (var header in headers) { var headerSegments = header.Split(':'); headersEntries.Add(new Tuple <string, string>(headerSegments[0], headerSegments[1])); if (dataObject.IsDebugMode()) { DebugItem debugItem = new DebugItem(); AddDebugItem(new DebugEvalResult(Headers, "Header", dataObject.Environment, update), debugItem); _debugInputs.Add(debugItem); } } bool timeoutSecondsError = false; if (!string.IsNullOrEmpty(TimeOutText)) { int timeoutval; if (int.TryParse(WarewolfDataEvaluationCommon.EvalResultToString(dataObject.Environment.Eval(TimeOutText, update)), out timeoutval)) { if (timeoutval < 0) { allErrors.AddError(string.Format("Value of TimeoutSecondsText out of range: please specify a value between 0 and {0}.", int.MaxValue)); timeoutSecondsError = true; } else { TimeoutSeconds = timeoutval; } } else { allErrors.AddError(string.Format("Value {0} for TimeoutSecondsText could not be interpreted as a numeric value.", TimeOutText)); timeoutSecondsError = true; } if (dataObject.IsDebugMode()) { DebugItem debugItem = new DebugItem(); AddDebugItem(new DebugEvalResult(String.IsNullOrEmpty(TimeOutText) ? "100" : TimeOutText, "Time Out Seconds", dataObject.Environment, update), debugItem); _debugInputs.Add(debugItem); } } if (!timeoutSecondsError) { var result = WebRequestInvoker.ExecuteRequest(Method, c, headersEntries, TimeoutSeconds == 0 ? Timeout.Infinite : TimeoutSeconds * 1000 // important to list the parameter name here to see the conversion from seconds to milliseconds ); allErrors.MergeErrors(errorsTo); PushResultsToDataList(Result, result, dataObject, update); } else { throw new ApplicationException("Execution aborted - see error messages."); } } } catch (Exception e) { Dev2Logger.Log.Error("DSFWebGetRequest", e); allErrors.AddError(e.Message); } finally { if (allErrors.HasErrors()) { DisplayAndWriteError("DsfWebGetRequestActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); var expression = Result; PushResultsToDataList(expression, null, dataObject, update); } if (dataObject.IsDebugMode()) { 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 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, "")); } DisplayAndWriteError("DsfNumberFormatActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { _indexCounter = 1; ErrorResultTO allErrors = new ErrorResultTO(); var env = dataObject.Environment; WarewolfListIterator iter = new WarewolfListIterator(); InitializeDebug(dataObject); try { var sourceString = SourceString ?? ""; if (dataObject.IsDebugMode()) { AddDebugInputItem(new DebugEvalResult(sourceString, "String to Split", env, update)); AddDebugInputItem(new DebugItemStaticDataParams(ReverseOrder ? "Backward" : "Forward", "Process Direction")); AddDebugInputItem(new DebugItemStaticDataParams(SkipBlankRows ? "Yes" : "No", "Skip blank rows")); AddDebug(ResultsCollection, dataObject.Environment, update); } var res = new WarewolfIterator(env.Eval(sourceString, update)); iter.AddVariableToIterateOn(res); IDictionary <string, int> positions = new Dictionary <string, int>(); CleanArguments(ResultsCollection); ResultsCollection.ToList().ForEach(a => { if (!positions.ContainsKey(a.OutputVariable)) { if (update == 0) { positions.Add(a.OutputVariable, 1); } else { positions.Add(a.OutputVariable, update); } } IsSingleValueRule.ApplyIsSingleValueRule(a.OutputVariable, allErrors); }); bool singleInnerIteration = ArePureScalarTargets(ResultsCollection); var resultsEnumerator = ResultsCollection.GetEnumerator(); var debugDictionary = new List <string>(); while (res.HasMoreData()) { const int OpCnt = 0; var item = res.GetNextValue(); // item is the thing we split on if (!string.IsNullOrEmpty(item)) { string val = item; var blankRows = new List <int>(); if (SkipBlankRows) { var strings = val.Split(new[] { Environment.NewLine, "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); var newSourceString = string.Join(Environment.NewLine, strings); val = newSourceString; } else { var strings = val.Split(new[] { Environment.NewLine }, StringSplitOptions.None); for (int blankRow = 0; blankRow < strings.Length; blankRow++) { if (String.IsNullOrEmpty(strings[blankRow])) { blankRows.Add(blankRow); } } } ErrorResultTO errors; IDev2Tokenizer tokenizer = CreateSplitPattern(ref val, ResultsCollection, env, out errors, update); allErrors.MergeErrors(errors); if (!allErrors.HasErrors()) { if (tokenizer != null) { int pos = 0; int end = (ResultsCollection.Count - 1); // track used tokens so we can adjust flushing ;) while (tokenizer.HasMoreOps()) { var currentval = resultsEnumerator.MoveNext(); if (!currentval) { if (singleInnerIteration) { break; } resultsEnumerator.Reset(); resultsEnumerator.MoveNext(); } string tmp = tokenizer.NextToken(); if (tmp.StartsWith(Environment.NewLine) && !SkipBlankRows) { resultsEnumerator.Reset(); while (resultsEnumerator.MoveNext()) { var tovar = resultsEnumerator.Current.OutputVariable; if (!String.IsNullOrEmpty(tovar)) { var assignToVar = ExecutionEnvironment.ConvertToIndex(tovar, positions[tovar]); env.AssignWithFrame(new AssignValue(assignToVar, ""), update); positions[tovar] = positions[tovar] + 1; } } resultsEnumerator.Reset(); resultsEnumerator.MoveNext(); } if (blankRows.Contains(OpCnt) && blankRows.Count != 0) { tmp = tmp.Replace(Environment.NewLine, ""); while (pos != end + 1) { pos++; } } var outputVar = resultsEnumerator.Current.OutputVariable; if (!String.IsNullOrEmpty(outputVar)) { var assignVar = ExecutionEnvironment.ConvertToIndex(outputVar, positions[outputVar]); if (ExecutionEnvironment.IsRecordsetIdentifier(assignVar)) { env.AssignWithFrame(new AssignValue(assignVar, tmp), update); } else if (ExecutionEnvironment.IsScalar(assignVar) && positions[outputVar] == 1) { env.AssignWithFrame(new AssignValue(assignVar, tmp), update); } else { env.AssignWithFrame(new AssignValue(assignVar, tmp), update); } positions[outputVar] = positions[outputVar] + 1; } if (dataObject.IsDebugMode()) { var debugItem = new DebugItem(); var outputVarTo = resultsEnumerator.Current.OutputVariable; AddDebugItem(new DebugEvalResult(outputVarTo, "", env, update), debugItem); if (!debugDictionary.Contains(outputVarTo)) { debugDictionary.Add(outputVarTo); } } if (pos == end) { } else { pos++; } } } } } env.CommitAssign(); if (singleInnerIteration) { break; } } if (dataObject.IsDebugMode()) { var outputIndex = 1; foreach (var varDebug in debugDictionary) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", outputIndex.ToString(CultureInfo.InvariantCulture)), debugItem); var dataSplitUsesStarForOutput = varDebug.Replace("().", "(*)."); AddDebugItem(new DebugEvalResult(dataSplitUsesStarForOutput, "", env, update), debugItem); _debugOutputs.Add(debugItem); outputIndex++; } } } catch (Exception e) { Dev2Logger.Log.Error("DSFDataSplit", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfDataSplitActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { IDev2ReplaceOperation replaceOperation = Dev2OperationsFactory.CreateReplaceOperation(); IErrorResultTO errors; IErrorResultTO 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, update)); if (Find != null) { AddDebugInputItem(new DebugEvalResult(Find, "Find", dataObject.Environment, update)); } if (ReplaceWith != null) { AddDebugInputItem(new DebugEvalResult(ReplaceWith, "Replace With", dataObject.Environment, update)); } } } 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 { var counter = 1; 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(ErrorResource.RequiredVaraibleNameONLY); return; } if (!string.IsNullOrEmpty(findValue)) { if (!string.IsNullOrEmpty(Result) && !DataListUtil.IsValueScalar(Result)) { if (!dataObject.Environment.HasRecordSet(DataListUtil.ExtractRecordsetNameFromValue(Result))) { dataObject.Environment.AssignDataShape(Result); } } dataObject.Environment.ApplyUpdate(s, a => { replacementCount = 0; var replace = replaceOperation.Replace(a.ToString(), findValue, replaceWithValue, CaseMatch, out errors, ref replacementCount); if (!string.IsNullOrEmpty(Result) && !DataListUtil.IsValueScalar(Result)) { dataObject.Environment.Assign(Result, replacementCount.ToString(CultureInfo.InvariantCulture), update == 0 ? counter : update); } replacementTotal += replacementCount; counter++; return(DataStorage.WarewolfAtom.NewDataString(replace)); }, update); } if (DataListUtil.IsValueScalar(Result)) { dataObject.Environment.Assign(Result, replacementTotal.ToString(CultureInfo.InvariantCulture), update == 0 ? counter : update); } if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { if (!string.IsNullOrEmpty(Result)) { if (replacementTotal > 0) { AddDebugOutputItem(new DebugEvalResult(s, "", dataObject.Environment, update)); } } } } } } } if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { if (!string.IsNullOrEmpty(Result)) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update)); } } // now push the result to the server } // ReSharper disable EmptyGeneralCatchClause catch (Exception ex) { Dev2Logger.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, update); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
private ErrorResultTO UpdateEnvironment(IDSFDataObject dataObject, int update, ErrorResultTO allErrors, IExecutionEnvironment env, ErrorResultTO errors) { 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); }
IDev2Activity ExecuteDecision(IDSFDataObject dataObject) { InitializeDebug(dataObject); if (dataObject.IsDebugMode()) { _debugInputs = CreateDebugInputs(dataObject.Environment); DispatchDebugState(dataObject, StateType.Before, 0); } var errorIfNull = !Conditions.TheStack.Any(decision => decision.EvaluationFn == enDecisionType.IsNull || decision.EvaluationFn == enDecisionType.IsNotNull); var stack = Conditions.TheStack.Select(a => ParseDecision(dataObject.Environment, a, errorIfNull)); var factory = Dev2DecisionFactory.Instance(); var res = stack.SelectMany(a => { if (a.EvaluationFn == enDecisionType.IsError) { return(new[] { dataObject.Environment.AllErrors.Count > 0 }); } if (a.EvaluationFn == enDecisionType.IsNotError) { return(new[] { dataObject.Environment.AllErrors.Count == 0 }); } IList <bool> ret = new List <bool>(); var iter = new WarewolfListIterator(); var c1 = new WarewolfAtomIterator(a.Cols1); var c2 = new WarewolfAtomIterator(a.Cols2); var c3 = new WarewolfAtomIterator(a.Cols3); iter.AddVariableToIterateOn(c1); iter.AddVariableToIterateOn(c2); iter.AddVariableToIterateOn(c3); while (iter.HasMoreData()) { try { ret.Add(factory.FetchDecisionFunction(a.EvaluationFn).Invoke(new[] { iter.FetchNextValue(c1), iter.FetchNextValue(c2), iter.FetchNextValue(c3) })); } catch (Exception) { if (errorIfNull) { throw; } ret.Add(false); } } return(ret); }); var results = res as IList <bool> ?? res.ToList(); var resultval = true; if (results.Any()) { if (And) { if (results.Any(b => !b)) { resultval = false; } } else { resultval = results.Any(b => b); } } Result = GetResultString(resultval.ToString(), Conditions); if (dataObject.IsDebugMode()) { _debugOutputs = GetDebugOutputs(resultval.ToString()); } if (resultval) { if (TrueArm != null) { var activity = TrueArm.FirstOrDefault(); return(activity); } } else { if (FalseArm != null) { var activity = FalseArm.FirstOrDefault(); return(activity); } } return(null); }
private void TryExecuteTool(IDSFDataObject dataObject, int update, IDev2MergeOperations mergeOperations, ErrorResultTO allErrors, ErrorResultTO errorResultTo) { IWarewolfListIterator warewolfListIterator = new WarewolfListIterator(); allErrors.MergeErrors(errorResultTo); var listOfIterators = new Dictionary <int, List <IWarewolfIterator> >(); #region Create a iterator for each row in the data grid in the designer so that the right iteration happen on the data var dictionaryKey = 0; foreach (DataMergeDTO row in MergeCollection) { allErrors.MergeErrors(errorResultTo); if (dataObject.IsDebugMode()) { var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", (MergeCollection.IndexOf(row) + 1).ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugEvalResult(row.InputVariable, "", dataObject.Environment, update, true), debugItem); AddDebugItem(new DebugItemStaticDataParams(row.MergeType, "With"), debugItem); AddDebugItem(new DebugEvalResult(row.At, "Using", dataObject.Environment, update), debugItem); AddDebugItem(new DebugEvalResult(row.Padding, "Pad", dataObject.Environment, update), 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); } var listOfEvalResultsForInput = dataObject.Environment.EvalForDataMerge(row.InputVariable, update); var innerIterator = new WarewolfListIterator(); var innerListOfIters = new List <WarewolfIterator>(); foreach (var listOfIterator in listOfEvalResultsForInput) { var inIterator = new WarewolfIterator(listOfIterator); innerIterator.AddVariableToIterateOn(inIterator); innerListOfIters.Add(inIterator); } var atomList = new List <DataStorage.WarewolfAtom>(); while (innerIterator.HasMoreData()) { var stringToUse = ""; foreach (var warewolfIterator in innerListOfIters) { stringToUse += warewolfIterator.GetNextValue(); } atomList.Add(DataStorage.WarewolfAtom.NewDataString(stringToUse)); } var finalString = string.Join("", atomList); var inputListResult = CommonFunctions.WarewolfEvalResult.NewWarewolfAtomListresult(new WarewolfAtomList <DataStorage.WarewolfAtom>(DataStorage.WarewolfAtom.Nothing, atomList)); if (DataListUtil.IsFullyEvaluated(finalString)) { inputListResult = dataObject.Environment.Eval(finalString, update); } var inputIterator = new WarewolfIterator(inputListResult); var atIterator = new WarewolfIterator(dataObject.Environment.Eval(row.At, update)); var paddingIterator = new WarewolfIterator(dataObject.Environment.Eval(row.Padding, update)); warewolfListIterator.AddVariableToIterateOn(inputIterator); warewolfListIterator.AddVariableToIterateOn(atIterator); warewolfListIterator.AddVariableToIterateOn(paddingIterator); listOfIterators.Add(dictionaryKey, new List <IWarewolfIterator> { inputIterator, atIterator, paddingIterator }); dictionaryKey++; } #endregion #region Iterate and Merge Data if (!allErrors.HasErrors()) { while (warewolfListIterator.HasMoreData()) { var pos = 0; foreach (var iterator in listOfIterators) { var val = warewolfListIterator.FetchNextValue(iterator.Value[0]); var at = warewolfListIterator.FetchNextValue(iterator.Value[1]); var pad = warewolfListIterator.FetchNextValue(iterator.Value[2]); pos = AddErrorAndMerge(mergeOperations, allErrors, pos, val, at, pad); } } if (!allErrors.HasErrors()) { if (string.IsNullOrEmpty(Result)) { AddDebugOutputItem(new DebugItemStaticDataParams("", "")); } else { AddToErrorsToDebugOutput(dataObject, update, mergeOperations, allErrors, errorResultTo); } } } #endregion Iterate and Merge Data }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { ErrorResultTO allErrors = new ErrorResultTO(); InitializeDebug(dataObject); // Process if no errors try { IsSingleValueRule.ApplyIsSingleValueRule(Result, allErrors); if (dataObject.IsDebugMode()) { if (string.IsNullOrEmpty(DateTime)) { var defaultDateTimeDebugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("System Date Time", "Input"), defaultDateTimeDebugItem); AddDebugItem(new DebugItemStaticDataParams(System.DateTime.Now.ToString(CultureInfo.CurrentCulture), "="), defaultDateTimeDebugItem); _debugInputs.Add(defaultDateTimeDebugItem); } else { AddDebugInputItem(new DebugEvalResult(DateTime, "Input", dataObject.Environment, update)); } var cultureType = typeof(CultureInfo); var fieldInfo = cultureType.GetField("s_userDefaultCulture", BindingFlags.NonPublic | BindingFlags.Static); if (fieldInfo != null) { var val = fieldInfo.GetValue(CultureInfo.CurrentCulture); var newCul = val as CultureInfo; if (newCul != null) { Thread.CurrentThread.CurrentCulture = newCul; } } var dateTimePattern = string.Format("{0} {1}", Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern, Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongTimePattern); if (string.IsNullOrEmpty(InputFormat)) { var defaultDateTimeDebugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("System Date Time Format", "Input Format"), defaultDateTimeDebugItem); AddDebugItem(new DebugItemStaticDataParams(dateTimePattern, "="), defaultDateTimeDebugItem); _debugInputs.Add(defaultDateTimeDebugItem); } else { AddDebugInputItem(new DebugEvalResult(InputFormat, "Input Format", dataObject.Environment, update)); } var debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams(TimeModifierType, "Add Time"), debugItem); AddDebugItem(new DebugEvalResult(TimeModifierAmountDisplay, "", dataObject.Environment, update), debugItem); _debugInputs.Add(debugItem); if (string.IsNullOrEmpty(OutputFormat)) { var defaultDateTimeDebugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("System Date Time Format", "Output Format"), defaultDateTimeDebugItem); AddDebugItem(new DebugItemStaticDataParams(dateTimePattern, "="), defaultDateTimeDebugItem); _debugInputs.Add(defaultDateTimeDebugItem); } else { AddDebugInputItem(new DebugEvalResult(OutputFormat, "Output Format", dataObject.Environment, update)); } } if (DataListUtil.HasNegativeIndex(InputFormat)) { allErrors.AddError(string.Format("Negative Recordset Index for Input Format: {0}", InputFormat)); } if (DataListUtil.HasNegativeIndex(OutputFormat)) { allErrors.AddError(string.Format("Negative Recordset Index for Output Format: {0}", OutputFormat)); } if (DataListUtil.HasNegativeIndex(TimeModifierAmountDisplay)) { allErrors.AddError(string.Format("Negative Recordset Index for Add Time: {0}", TimeModifierAmountDisplay)); } if (!allErrors.HasErrors()) { var colItr = new WarewolfListIterator(); var dtItr = CreateDataListEvaluateIterator(string.IsNullOrEmpty(DateTime) ? GlobalConstants.CalcExpressionNow : DateTime, dataObject.Environment, update); colItr.AddVariableToIterateOn(dtItr); var ifItr = CreateDataListEvaluateIterator(InputFormat, dataObject.Environment, update); colItr.AddVariableToIterateOn(ifItr); var ofItr = CreateDataListEvaluateIterator(OutputFormat, dataObject.Environment, update); colItr.AddVariableToIterateOn(ofItr); var tmaItr = CreateDataListEvaluateIterator(TimeModifierAmountDisplay, dataObject.Environment, update); colItr.AddVariableToIterateOn(tmaItr); if (!allErrors.HasErrors()) { while (colItr.HasMoreData()) { IDateTimeOperationTO transObj = ConvertToDateTimeTo(colItr.FetchNextValue(dtItr), colItr.FetchNextValue(ifItr), colItr.FetchNextValue(ofItr), TimeModifierType, colItr.FetchNextValue(tmaItr) ); IDateTimeFormatter format = DateTimeConverterFactory.CreateFormatter(); string result; string error; if (format.TryFormat(transObj, out result, out error)) { string expression = Result; dataObject.Environment.Assign(expression, result, update); } else { allErrors.AddError(error); } } if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update)); } } } } catch (Exception e) { Dev2Logger.Error("DSFDateTime", e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfDateTimeActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { if (hasErrors) { AddDebugOutputItem(new DebugItemStaticDataParams("", Result, "")); } DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }
protected override void ExecuteTool(IDSFDataObject dataObject) { _debugOutputs.Clear(); _debugInputs.Clear(); if (WebRequestInvoker == null) { return; } var allErrors = new ErrorResultTO(); InitializeDebug(dataObject); try { allErrors.MergeErrors(errorsTo); if (dataObject.IsDebugMode()) { DebugItem debugItem = new DebugItem(); AddDebugItem(new DebugEvalResult(Url, "URL", dataObject.Environment), debugItem); _debugInputs.Add(debugItem); } var colItr = new WarewolfListIterator(); var urlitr = new WarewolfIterator(dataObject.Environment.Eval(Url)); var headerItr = new WarewolfIterator(dataObject.Environment.Eval(Headers)); colItr.AddVariableToIterateOn(urlitr); colItr.AddVariableToIterateOn(headerItr); const int IndexToUpsertTo = 1; while (colItr.HasMoreData()) { var c = colItr.FetchNextValue(urlitr); var headerValue = colItr.FetchNextValue(headerItr); var headers = string.IsNullOrEmpty(headerValue) ? new string[0] : headerValue.Split(new[] { '\n', '\r', ';' }, StringSplitOptions.RemoveEmptyEntries); var headersEntries = new List <Tuple <string, string> >(); foreach (var header in headers) { var headerSegments = header.Split(':'); headersEntries.Add(new Tuple <string, string>(headerSegments[0], headerSegments[1])); if (dataObject.IsDebugMode()) { DebugItem debugItem = new DebugItem(); AddDebugItem(new DebugEvalResult(Headers, "Header", dataObject.Environment), debugItem); _debugInputs.Add(debugItem); } } var result = WebRequestInvoker.ExecuteRequest(Method, c, headersEntries); allErrors.MergeErrors(errorsTo); var expression = GetExpression(IndexToUpsertTo); PushResultsToDataList(expression, result, dataObject); } } catch (Exception e) { Dev2Logger.Log.Error("DSFWebGetRequest", e); allErrors.AddError(e.Message); } finally { if (allErrors.HasErrors()) { DisplayAndWriteError("DsfWebGetRequestActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); var expression = GetExpression(1); PushResultsToDataList(expression, null, dataObject); } if (dataObject.IsDebugMode()) { 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(); var errors = new ErrorResultTO(); allErrors.MergeErrors(errors); InitializeDebug(dataObject); try { IsSingleValueRule.ApplyIsSingleValueRule(Result, allErrors); if (dataObject.IsDebugMode()) { AddDebugInputItem(dataObject.Environment, update); } var input = string.IsNullOrEmpty(Expression) ? Expression : Expression.Replace("\\r", string.Empty).Replace("\\n", string.Empty).Replace(Environment.NewLine, ""); var warewolfListIterator = new WarewolfListIterator(); var calc = String.Format(GlobalConstants.AggregateCalculateTextConvertFormat, input); var warewolfEvalResult = dataObject.Environment.Eval(calc, update); if (warewolfEvalResult is CommonFunctions.WarewolfEvalResult.WarewolfAtomResult scalarResult && scalarResult.Item.IsNothing) { throw new NullValueInVariableException(ErrorResource.VariableInputError, input); } var inputIterator = new WarewolfIterator(warewolfEvalResult); warewolfListIterator.AddVariableToIterateOn(inputIterator); var counter = 1; while (warewolfListIterator.HasMoreData()) { var result = warewolfListIterator.FetchNextValue(inputIterator); dataObject.Environment.Assign(Result, result, update == 0 ? counter : update); counter++; } if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { AddDebugOutputItem(Result, dataObject.Environment, update); } allErrors.MergeErrors(errors); } catch (Exception ex) { Dev2Logger.Error("Aggregate Calculate Exception", ex, GlobalConstants.WarewolfError); allErrors.AddError(ex.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); DisplayAndWriteError(dataObject, DisplayName, allErrors); } if (dataObject.IsDebugMode()) { if (hasErrors) { AddDebugOutputItem(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 static IEnumerable <TestRunResult> GetTestRunResults(IDSFDataObject dataObject, IServiceTestOutput output, Dev2DecisionFactory factory, IDebugState debugState) #pragma warning restore S1541 // Methods and properties should not be too complex { if (output == null) { var testResult = new TestRunResult { RunTestResult = RunResult.None }; return(new List <TestRunResult> { testResult }); } if (string.IsNullOrEmpty(output.Variable) && string.IsNullOrEmpty(output.Value)) { var testResult = new TestRunResult { RunTestResult = RunResult.None }; output.Result = testResult; return(new List <TestRunResult> { testResult }); } if (output.Result != null) { output.Result.RunTestResult = RunResult.TestInvalid; } if (string.IsNullOrEmpty(output.Variable)) { var testResult = new TestRunResult { RunTestResult = RunResult.TestInvalid, Message = Messages.Test_NothingToAssert }; output.Result = testResult; if (dataObject.IsDebugMode()) { var debugItemStaticDataParams = new DebugItemServiceTestStaticDataParams(testResult.Message, true); var itemToAdd = new DebugItem(); itemToAdd.AddRange(debugItemStaticDataParams.GetDebugItemResult()); debugState.AssertResultList.Add(itemToAdd); } return(new List <TestRunResult> { testResult }); } var opt = FindRecsetOptions.FindMatch(output.AssertOp); var decisionType = DecisionDisplayHelper.GetValue(output.AssertOp); var value = new List <DataStorage.WarewolfAtom> { DataStorage.WarewolfAtom.NewDataString(output.Value) }; var from = new List <DataStorage.WarewolfAtom> { DataStorage.WarewolfAtom.NewDataString(output.From) }; var to = new List <DataStorage.WarewolfAtom> { DataStorage.WarewolfAtom.NewDataString(output.To) }; IList <TestRunResult> ret = new List <TestRunResult>(); var iter = new WarewolfListIterator(); var cols1 = dataObject.Environment.EvalAsList(DataListUtil.AddBracketsToValueIfNotExist(output.Variable), 0); var c1 = new WarewolfAtomIterator(cols1); var c2 = new WarewolfAtomIterator(value); var c3 = new WarewolfAtomIterator(@from); if (opt.ArgumentCount > 2) { c2 = new WarewolfAtomIterator(to); } iter.AddVariableToIterateOn(c1); iter.AddVariableToIterateOn(c2); iter.AddVariableToIterateOn(c3); while (iter.HasMoreData()) { var val1 = iter.FetchNextValue(c1); var val2 = iter.FetchNextValue(c2); var val3 = iter.FetchNextValue(c3); var assertResult = factory.FetchDecisionFunction(decisionType).Invoke(new[] { val1, val2, val3 }); var testResult = new TestRunResult(); if (assertResult) { testResult.RunTestResult = RunResult.TestPassed; } else { testResult.RunTestResult = RunResult.TestFailed; var msg = DecisionDisplayHelper.GetFailureMessage(decisionType); var actMsg = string.Format(msg, val2, output.Variable, val1, val3); testResult.Message = new StringBuilder(testResult.Message).AppendLine(actMsg).ToString(); } if (dataObject.IsDebugMode()) { var msg = testResult.Message; if (testResult.RunTestResult == RunResult.TestPassed) { msg = Messages.Test_PassedResult; } var hasError = testResult.RunTestResult == RunResult.TestFailed; var debugItemStaticDataParams = new DebugItemServiceTestStaticDataParams(msg, hasError); var itemToAdd = new DebugItem(); itemToAdd.AddRange(debugItemStaticDataParams.GetDebugItemResult()); AddAssertResultList(debugState, itemToAdd); } output.Result = testResult; ret.Add(testResult); } return(ret); }
private (IEnumerable <INameValue> head, string query, string data, IEnumerable <IFormDataParameters> conditions) GetEnvironmentInputVariables(IExecutionEnvironment environment, int update) { IEnumerable <INameValue> head = null; if (Headers != null) { head = Headers.Select(a => new NameValue(ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval(a.Name, update)), ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval(a.Value, update)))); if (IsFormDataChecked) { var headersHelper = new WebRequestHeadersHelper(notEvaluatedHeaders: Headers, evaluatedHeaders: head); head = headersHelper.CalculateFormDataContentType(); } else if (IsUrlEncodedChecked) { var headersHelper = new WebRequestHeadersHelper(notEvaluatedHeaders: Headers, evaluatedHeaders: head); head = headersHelper.CalculateUrlEncodedContentType(); } } var query = string.Empty; if (QueryString != null) { query = ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval(QueryString, update)); } var postData = string.Empty; if (PostData != null && IsManualChecked) { postData = ExecutionEnvironment.WarewolfEvalResultToString(environment.Eval(PostData, update, true)); } var conditions = new List <IFormDataParameters>(); if ((Conditions ?? (Conditions = new List <FormDataConditionExpression>())).Any() && (IsFormDataChecked || IsUrlEncodedChecked)) { _errorsTo = new ErrorResultTO(); conditions = Conditions.SelectMany(o => o.Eval(GetArgumentsFunc, _errorsTo.HasErrors())).ToList(); } IEnumerable <string[]> GetArgumentsFunc(string col1s, string col2s, string col3s) { var col1 = environment.EvalAsList(col1s, 0, true); var col2 = environment.EvalAsList(col2s ?? "", 0, true); var col3 = environment.EvalAsList(col3s ?? "", 0, true); var iter = new WarewolfListIterator(); var c1 = new WarewolfAtomIterator(col1); var c2 = new WarewolfAtomIterator(col2); var c3 = new WarewolfAtomIterator(col3); iter.AddVariableToIterateOn(c1); iter.AddVariableToIterateOn(c2); iter.AddVariableToIterateOn(c3); while (iter.HasMoreData()) { var item = new[] { iter.FetchNextValue(c1), iter.FetchNextValue(c2), iter.FetchNextValue(c3) }; yield return(item); } yield break; } return(head, query, postData, conditions); }
protected override IList <OutputTO> TryExecuteConcreteAction(IDSFDataObject context, out ErrorResultTO error, int update) { IList <OutputTO> outputs = new List <OutputTO>(); error = new ErrorResultTO(); var colItr = new WarewolfListIterator(); //get all the possible paths for all the string variables var inputItr = new WarewolfIterator(context.Environment.Eval(OutputPath, update)); colItr.AddVariableToIterateOn(inputItr); var passItr = new WarewolfIterator(context.Environment.Eval(DecryptedPassword, update)); colItr.AddVariableToIterateOn(passItr); var privateKeyItr = new WarewolfIterator(context.Environment.Eval(PrivateKeyFile, update)); colItr.AddVariableToIterateOn(privateKeyItr); var contentItr = new WarewolfIterator(context.Environment.Eval(FileContents, update)); colItr.AddVariableToIterateOn(contentItr); outputs.Add(DataListFactory.CreateOutputTO(Result)); if (context.IsDebugMode()) { AddDebugInputItem(OutputPath, "Output Path", context.Environment, update); AddDebugInputItem(new DebugItemStaticDataParams(GetMethod(), "Method")); AddDebugInputItemUserNamePassword(context.Environment, update); if (!string.IsNullOrEmpty(PrivateKeyFile)) { AddDebugInputItem(PrivateKeyFile, "Private Key File", context.Environment, update); } AddDebugInputItem(FileContents, "File Contents", context.Environment, update); if (FileContentsAsBase64) { AddDebugInputItem(FileContentsAsBase64.ToString(), "File Contents As Base64", context.Environment, update); } } while (colItr.HasMoreData()) { var broker = ActivityIOFactory.CreateOperationsBroker(); var writeType = GetCorrectWriteType(); var putTo = ActivityIOFactory.CreatePutRawOperationTO(writeType, TextUtils.ReplaceWorkflowNewLinesWithEnvironmentNewLines(colItr.FetchNextValue(contentItr)), FileContentsAsBase64); var opath = ActivityIOFactory.CreatePathFromString(colItr.FetchNextValue(inputItr), Username, colItr.FetchNextValue(passItr), true, colItr.FetchNextValue(privateKeyItr)); var endPoint = ActivityIOFactory.CreateOperationEndPointFromIOPath(opath); try { if (error.HasErrors()) { outputs[0].OutputStrings.Add(null); } else { var result = broker.PutRaw(endPoint, putTo); outputs[0].OutputStrings.Add(result); } } catch (Exception e) { outputs[0].OutputStrings.Add(null); error.AddError(e.Message); break; } } return(outputs); }
static IEnumerable <TestRunResult> GetTestRunResults(IDSFDataObject dataObject, IServiceTestOutput output, Dev2DecisionFactory factory) { var expressionType = output.AssertOp ?? string.Empty; var opt = FindRecsetOptions.FindMatch(expressionType); var decisionType = DecisionDisplayHelper.GetValue(expressionType); if (decisionType == enDecisionType.IsError) { var testResult = new TestRunResult(); if (dataObject.Environment.AllErrors.Any()) { testResult.RunTestResult = RunResult.TestPassed; } else { testResult.RunTestResult = RunResult.TestFailed; testResult.Message = new StringBuilder(testResult.Message).AppendLine(Messages.Test_FailureResult).ToString(); } return(new[] { testResult }); } if (decisionType == enDecisionType.IsNotError) { var testResult = new TestRunResult(); var actMsg = dataObject.Environment.FetchErrors(); if (string.IsNullOrWhiteSpace(actMsg)) { testResult.RunTestResult = RunResult.TestPassed; } else { testResult.RunTestResult = RunResult.TestFailed; testResult.Message = new StringBuilder(testResult.Message).AppendLine("Failed: " + actMsg).ToString(); } return(new[] { testResult }); } var value = new List <DataStorage.WarewolfAtom> { DataStorage.WarewolfAtom.NewDataString(output.Value) }; var from = new List <DataStorage.WarewolfAtom> { DataStorage.WarewolfAtom.NewDataString(output.From) }; var to = new List <DataStorage.WarewolfAtom> { DataStorage.WarewolfAtom.NewDataString(output.To) }; IList <TestRunResult> ret = new List <TestRunResult>(); var iter = new WarewolfListIterator(); var variable = DataListUtil.AddBracketsToValueIfNotExist(output.Variable); var cols1 = dataObject.Environment.EvalAsList(variable, 0); var c1 = new WarewolfAtomIterator(cols1); var c2 = new WarewolfAtomIterator(value); var c3 = new WarewolfAtomIterator(to); if (opt.ArgumentCount > 2) { c2 = new WarewolfAtomIterator(from); } iter.AddVariableToIterateOn(c1); iter.AddVariableToIterateOn(c2); iter.AddVariableToIterateOn(c3); while (iter.HasMoreData()) { var val1 = iter.FetchNextValue(c1); var val2 = iter.FetchNextValue(c2); var val3 = iter.FetchNextValue(c3); var assertResult = factory.FetchDecisionFunction(decisionType).Invoke(new[] { val1, val2, val3 }); var testResult = new TestRunResult(); if (assertResult) { testResult.RunTestResult = RunResult.TestPassed; } else { testResult.RunTestResult = RunResult.TestFailed; var msg = DecisionDisplayHelper.GetFailureMessage(decisionType); var actMsg = string.Format(msg, val2, variable, val1, val3); testResult.Message = new StringBuilder(testResult.Message).AppendLine(actMsg).ToString(); } output.Result = testResult; ret.Add(testResult); } return(ret); }
private int TryExecute(IDSFDataObject dataObject, int update, ErrorResultTO allErrors, int indexToUpsertTo, IExchange runtimeSource) { if (IsDebug) { AddDebugInputItem(new DebugEvalResult(To, "To", dataObject.Environment, update)); AddDebugInputItem(new DebugEvalResult(Subject, "Subject", dataObject.Environment, update)); AddDebugInputItem(new DebugEvalResult(Body, "Body", dataObject.Environment, update)); } var colItr = new WarewolfListIterator(); var toItr = new WarewolfIterator(dataObject.Environment.Eval(To, update)); colItr.AddVariableToIterateOn(toItr); var ccItr = new WarewolfIterator(dataObject.Environment.Eval(Cc, update)); colItr.AddVariableToIterateOn(ccItr); var bccItr = new WarewolfIterator(dataObject.Environment.Eval(Bcc, update)); colItr.AddVariableToIterateOn(bccItr); var subjectItr = new WarewolfIterator(dataObject.Environment.Eval(Subject, update)); colItr.AddVariableToIterateOn(subjectItr); var bodyItr = new WarewolfIterator(dataObject.Environment.Eval(Body, update)); colItr.AddVariableToIterateOn(bodyItr); var attachmentsItr = new WarewolfIterator(dataObject.Environment.Eval(Attachments ?? string.Empty, update)); colItr.AddVariableToIterateOn(attachmentsItr); if (!allErrors.HasErrors()) { while (colItr.HasMoreData()) { var result = _emailSender.SendEmail(runtimeSource, colItr, toItr, ccItr, bccItr, subjectItr, bodyItr, attachmentsItr, out ErrorResultTO errors, IsHtml); allErrors.MergeErrors(errors); if (!allErrors.HasErrors()) { indexToUpsertTo = UpsertResult(indexToUpsertTo, dataObject.Environment, result, update); } } if (IsDebug && !allErrors.HasErrors() && !string.IsNullOrEmpty(Result)) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update)); } } else { if (IsDebug) { AddDebugInputItem(To, "To"); AddDebugInputItem(Subject, "Subject"); AddDebugInputItem(Body, "Body"); } } return(indexToUpsertTo); }
protected override void ExecuteTool(IDSFDataObject dataObject, int update) { IDev2MergeOperations mergeOperations = new Dev2MergeOperations(); ErrorResultTO allErrors = new ErrorResultTO(); ErrorResultTO errorResultTo = new ErrorResultTO(); InitializeDebug(dataObject); try { CleanArguments(MergeCollection); if (MergeCollection.Count <= 0) { return; } IWarewolfListIterator warewolfListIterator = new WarewolfListIterator(); allErrors.MergeErrors(errorResultTo); Dictionary <int, List <IWarewolfIterator> > listOfIterators = new Dictionary <int, List <IWarewolfIterator> >(); #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) { allErrors.MergeErrors(errorResultTo); if (dataObject.IsDebugMode()) { DebugItem debugItem = new DebugItem(); AddDebugItem(new DebugItemStaticDataParams("", (MergeCollection.IndexOf(row) + 1).ToString(CultureInfo.InvariantCulture)), debugItem); AddDebugItem(new DebugEvalResult(row.InputVariable, "", dataObject.Environment, update, true), debugItem); AddDebugItem(new DebugItemStaticDataParams(row.MergeType, "With"), debugItem); AddDebugItem(new DebugEvalResult(row.At, "Using", dataObject.Environment, update), debugItem); AddDebugItem(new DebugEvalResult(row.Padding, "Pad", dataObject.Environment, update), 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); } var listOfEvalResultsForInput = dataObject.Environment.EvalForDataMerge(row.InputVariable, update); var innerIterator = new WarewolfListIterator(); var innerListOfIters = new List <WarewolfIterator>(); foreach (var listOfIterator in listOfEvalResultsForInput) { var inIterator = new WarewolfIterator(listOfIterator); innerIterator.AddVariableToIterateOn(inIterator); innerListOfIters.Add(inIterator); } var atomList = new List <DataASTMutable.WarewolfAtom>(); while (innerIterator.HasMoreData()) { var stringToUse = ""; foreach (var warewolfIterator in innerListOfIters) { stringToUse += warewolfIterator.GetNextValue(); } atomList.Add(DataASTMutable.WarewolfAtom.NewDataString(stringToUse)); } var finalString = string.Join("", atomList); var inputListResult = WarewolfDataEvaluationCommon.WarewolfEvalResult.NewWarewolfAtomListresult(new WarewolfAtomList <DataASTMutable.WarewolfAtom>(DataASTMutable.WarewolfAtom.Nothing, atomList)); if (DataListUtil.IsFullyEvaluated(finalString)) { inputListResult = dataObject.Environment.Eval(finalString, update); } var inputIterator = new WarewolfIterator(inputListResult); var atIterator = new WarewolfIterator(dataObject.Environment.Eval(row.At, update)); var paddingIterator = new WarewolfIterator(dataObject.Environment.Eval(row.Padding, update)); warewolfListIterator.AddVariableToIterateOn(inputIterator); warewolfListIterator.AddVariableToIterateOn(atIterator); warewolfListIterator.AddVariableToIterateOn(paddingIterator); listOfIterators.Add(dictionaryKey, new List <IWarewolfIterator> { inputIterator, atIterator, paddingIterator }); dictionaryKey++; } #endregion #region Iterate and Merge Data if (!allErrors.HasErrors()) { while (warewolfListIterator.HasMoreData()) { int pos = 0; foreach (var iterator in listOfIterators) { var val = warewolfListIterator.FetchNextValue(iterator.Value[0]); var at = warewolfListIterator.FetchNextValue(iterator.Value[1]); var pad = warewolfListIterator.FetchNextValue(iterator.Value[2]); if (val != null) { if (at != null) { if (pad != null) { if (MergeCollection[pos].MergeType == "Index") { if (string.IsNullOrEmpty(at)) { allErrors.AddError("The 'Using' value cannot be blank."); } int atValue; if (!Int32.TryParse(at, out atValue) || atValue < 0) { allErrors.AddError("The 'Using' value must be a real number."); } if (pad.Length > 1) { allErrors.AddError("'Padding' must be a single character"); } } else { if (MergeCollection[pos].MergeType == "Chars" && string.IsNullOrEmpty(at)) { allErrors.AddError("The 'Using' value cannot be blank."); } } mergeOperations.Merge(val, MergeCollection[pos].MergeType, at, pad, MergeCollection[pos].Alignment); pos++; } } } } } if (!allErrors.HasErrors()) { if (string.IsNullOrEmpty(Result)) { AddDebugOutputItem(new DebugItemStaticDataParams("", "")); } else { dataObject.Environment.Assign(Result, mergeOperations.MergeData.ToString(), update); allErrors.MergeErrors(errorResultTo); if (dataObject.IsDebugMode() && !allErrors.HasErrors()) { AddDebugOutputItem(new DebugEvalResult(Result, "", dataObject.Environment, update)); } } } } #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); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } #endregion } }