Func <DataASTMutable.WarewolfAtom, DataASTMutable.WarewolfAtom> TryConvertFunc(BaseConvertTO item, IExecutionEnvironment env, int update) { return(a => { IBaseConverter from = _fac.CreateConverter((enDev2BaseConvertType)Dev2EnumConverter.GetEnumFromStringDiscription(item.FromType, typeof(enDev2BaseConvertType))); IBaseConverter to = _fac.CreateConverter((enDev2BaseConvertType)Dev2EnumConverter.GetEnumFromStringDiscription(item.ToType, typeof(enDev2BaseConvertType))); IBaseConversionBroker broker = _fac.CreateBroker(@from, to); var value = a.ToString(); if (a.IsNothing) { throw new Exception(string.Format("Scalar value {{{0}}} is NULL", item.FromExpression)); } if (String.IsNullOrEmpty(value)) { return DataASTMutable.WarewolfAtom.NewDataString(""); } var upper = broker.Convert(value); var evalled = env.Eval(upper, update); if (evalled.IsWarewolfAtomResult) { var warewolfAtomResult = evalled as WarewolfDataEvaluationCommon.WarewolfEvalResult.WarewolfAtomResult; if (warewolfAtomResult != null) { return warewolfAtomResult.Item; } return DataASTMutable.WarewolfAtom.Nothing; } return DataASTMutable.WarewolfAtom.NewDataString(WarewolfDataEvaluationCommon.EvalResultToString(evalled)); }); }
private Func <DataASTMutable.WarewolfAtom, DataASTMutable.WarewolfAtom> TryConvertFunc(ICaseConvertTO conversionType, IExecutionEnvironment env, int update) { var convertFunct = CaseConverter.GetFuncs(); Func <string, string> returnedFunc; if (convertFunct.TryGetValue(conversionType.ConvertType, out returnedFunc)) { if (returnedFunc != null) { return(a => { var upper = returnedFunc.Invoke(a.ToString()); var evalled = env.Eval(upper, update); if (evalled.IsWarewolfAtomResult) { var warewolfAtomResult = evalled as WarewolfDataEvaluationCommon.WarewolfEvalResult.WarewolfAtomResult; if (warewolfAtomResult != null) { return warewolfAtomResult.Item; } return DataASTMutable.WarewolfAtom.Nothing; } return DataASTMutable.WarewolfAtom.NewDataString(WarewolfDataEvaluationCommon.EvalResultToString(evalled)); }); } } throw new Exception("Convert option does not exist"); }
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 = GetExpression(1); PushResultsToDataList(expression, null, dataObject, update); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }