static string PerformCalcForAtom(DataStorage.WarewolfAtom warewolfAtom, FunctionEvaluator functionEvaluator) { var calcExpression = ExecutionEnvironment.WarewolfAtomToString(warewolfAtom); DataListUtil.IsCalcEvaluation(calcExpression, out string exp); var res = functionEvaluator.TryEvaluateFunction(exp, out string eval, out string error); if (eval == exp.Replace("\"", "") && exp.Contains("\"")) { try { var b = functionEvaluator.TryEvaluateFunction(exp.Replace("\"", ""), out string eval2, out error); if (b) { eval = eval2; } } catch (Exception err) { Dev2Logger.Warn(err, "Warewolf Warn"); } } if (!res) { throw new Exception(ErrorResource.InvalidCalculate); } return(eval); }
static string DoCalcution(string warewolfAtomToString) { string cleanExpression; var isCalcEvaluation = DataListUtil.IsCalcEvaluation(warewolfAtomToString, out cleanExpression); if (isCalcEvaluation) { var functionEvaluator = new FunctionEvaluator(); string eval; string error; var tryEvaluateFunction = functionEvaluator.TryEvaluateFunction(cleanExpression, out eval, out error); warewolfAtomToString = eval; if (eval == cleanExpression.Replace("\"", "") && cleanExpression.Contains("\"")) { try { string eval2; var b = functionEvaluator.TryEvaluateFunction(cleanExpression.Replace("\"", ""), out eval2, out error); if (b) { warewolfAtomToString = eval2; } } catch (Exception err) { Dev2Logger.Log.Warn(err); } } if (!tryEvaluateFunction) { throw new Exception(error); } } return(warewolfAtomToString); }
string DoCalcution(string argWarewolfAtomToString) { if (argWarewolfAtomToString == null) { return(null); } var warewolfAtomToString = argWarewolfAtomToString; var isCalcEvaluation = DataListUtil.IsCalcEvaluation(warewolfAtomToString, out string cleanExpression); if (isCalcEvaluation) { var functionEvaluator = new FunctionEvaluator(_functionEvaluatorOption); var tryEvaluateFunction = functionEvaluator.TryEvaluateFunction(cleanExpression, out string eval, out string error); warewolfAtomToString = eval; if (eval == cleanExpression.Replace("\"", "") && cleanExpression.Contains("\"")) { TryEvalAsFunction(ref warewolfAtomToString, cleanExpression, functionEvaluator, ref error); } if (!tryEvaluateFunction) { if (error == ErrorResource.IncorrectOperandType) { error += string.Format("Unable to calculate: '{0}'. Try rewriting the expression.", cleanExpression); } throw new Exception(error); } } return(warewolfAtomToString); }
private void RegularItem(IExecutionEnvironment environment, int update, bool isCalculate) { var evalToExpression = environment.EvalToExpression(_inputVariable, update); if (DataListUtil.IsEvaluated(evalToExpression)) { _inputVariable = evalToExpression; } _evalResult = environment.Eval(_inputVariable, update); string cleanExpression; var isCalcExpression = DataListUtil.IsCalcEvaluation(_inputVariable, out cleanExpression); if (isCalcExpression && !isCalculate) { if (_evalResult.IsWarewolfAtomResult) { var atomResult = _evalResult as CommonFunctions.WarewolfEvalResult.WarewolfAtomResult; if (atomResult != null) { var res = atomResult.Item.ToString(); string resValue; DataListUtil.IsCalcEvaluation(res, out resValue); _evalResult = CommonFunctions.WarewolfEvalResult.NewWarewolfAtomResult(DataStorage.WarewolfAtom.NewDataString(resValue)); } } _inputVariable = cleanExpression; } }
AssignValue DoCalculation(IExecutionEnvironment environment, string fieldName, string cleanExpression) { var functionEvaluator = new FunctionEvaluator(); var warewolfEvalResult = environment.Eval(cleanExpression); if (warewolfEvalResult.IsWarewolfAtomResult) { var result = warewolfEvalResult as WarewolfDataEvaluationCommon.WarewolfEvalResult.WarewolfAtomResult; if (result != null) { var calcExpression = ExecutionEnvironment.WarewolfAtomToString(result.Item); string exp; DataListUtil.IsCalcEvaluation(calcExpression, out exp); string eval; string error; var res = functionEvaluator.TryEvaluateFunction(exp, out eval, out error); if (eval == exp.Replace("\"", "") && exp.Contains("\"")) { try { string eval2; var b = functionEvaluator.TryEvaluateFunction(exp.Replace("\"", ""), out eval2, out error); if (b) { eval = eval2; } } catch (Exception err) { Dev2Logger.Log.Warn(err); } } if (!res) { throw new Exception("Invalid Calculate"); } return(new AssignValue(fieldName, eval)); } } if (warewolfEvalResult.IsWarewolfAtomListresult) { var result = warewolfEvalResult as WarewolfDataEvaluationCommon.WarewolfEvalResult.WarewolfAtomListresult; if (result != null) { } } return(null); }
void ExecuteField(IDSFDataObject dataObject, int update, int innerCount, ActivityDTO t, ErrorResultTO allErrors) { var assignValue = new AssignValue(t.FieldName, t.FieldValue); var isCalcEvaluation = DataListUtil.IsCalcEvaluation(t.FieldValue, out string cleanExpression); if (isCalcEvaluation) { assignValue = new AssignValue(t.FieldName, cleanExpression); } DebugItem debugItem = null; if (dataObject.IsDebugMode()) { debugItem = TryCreateDebugInput(dataObject.Environment, innerCount, assignValue, update); } try { if (isCalcEvaluation) { DoCalculation(dataObject.Environment, t.FieldName, t.FieldValue, update); } else { dataObject.Environment.AssignWithFrame(assignValue, update); } } catch (Exception e) { Dev2Logger.Error(nameof(DsfMultiAssignActivity), e, GlobalConstants.WarewolfError); allErrors.AddError(e.Message); } if (debugItem != null) { _debugInputs.Add(debugItem); } if (dataObject.IsDebugMode()) { if (DataListUtil.IsValueRecordset(assignValue.Name) && DataListUtil.GetRecordsetIndexType(assignValue.Name) == enRecordsetIndexType.Blank) { var length = dataObject.Environment.GetLength(DataListUtil.ExtractRecordsetNameFromValue(assignValue.Name)); assignValue = new AssignValue(DataListUtil.ReplaceRecordsetBlankWithIndex(assignValue.Name, length), assignValue.Value); } AddSingleDebugOutputItem(dataObject.Environment, innerCount, assignValue, update); } }
private void AssignField(IDSFDataObject dataObject, int update, int innerCount, ActivityDTO t, ErrorResultTO allErrors) { var assignValue = new AssignValue(t.FieldName, t.FieldValue); var isCalcEvaluation = DataListUtil.IsCalcEvaluation(t.FieldValue, out string cleanExpression); if (isCalcEvaluation) { assignValue = new AssignValue(t.FieldName, cleanExpression); } DebugItem debugItem = null; if (dataObject.IsDebugMode()) { debugItem = AddSingleInputDebugItem(dataObject.Environment, innerCount, assignValue, update); } try { if (isCalcEvaluation) { DoCalculation(dataObject.Environment, t.FieldName, t.FieldValue, update); } else { dataObject.Environment.AssignWithFrame(assignValue, update); } } catch (Exception e) { allErrors.AddError(e.Message); } if (debugItem != null) { _debugInputs.Add(debugItem); } if (dataObject.IsDebugMode()) { if (DataListUtil.IsValueRecordset(assignValue.Name) && DataListUtil.GetRecordsetIndexType(assignValue.Name) == enRecordsetIndexType.Blank && !assignValue.Name.Contains(DataListUtil.ObjectStartMarker)) { var length = dataObject.Environment.GetLength(DataListUtil.ExtractRecordsetNameFromValue(assignValue.Name)); assignValue = new AssignValue(DataListUtil.ReplaceRecordsetBlankWithIndex(assignValue.Name, length), assignValue.Value); } AddSingleDebugOutputItem(dataObject.Environment, innerCount, assignValue, update); } }
static string DoCalcution(string warewolfAtomToString) { if (warewolfAtomToString == null) { return(null); } string cleanExpression; var isCalcEvaluation = DataListUtil.IsCalcEvaluation(warewolfAtomToString, out cleanExpression); if (isCalcEvaluation) { var functionEvaluator = new FunctionEvaluator(); string eval; string error; var tryEvaluateFunction = functionEvaluator.TryEvaluateFunction(cleanExpression, out eval, out error); warewolfAtomToString = eval; if (eval == cleanExpression.Replace("\"", "") && cleanExpression.Contains("\"")) { try { string eval2; var b = functionEvaluator.TryEvaluateFunction(cleanExpression.Replace("\"", ""), out eval2, out error); if (b) { warewolfAtomToString = eval2; } } catch (Exception err) { Dev2Logger.Warn(err); } } if (!tryEvaluateFunction) { if (error == ErrorResource.IncorrectOperandType) { error += string.Format("Unable to calculate: '{0}'. Try rewriting the expression.", cleanExpression); } throw new Exception(error); } } return(warewolfAtomToString); }
public override IActionableErrorInfo Check() { var value = GetValue(); if (DataListUtil.IsCalcEvaluation(value, out string calculationExpression)) { value = calculationExpression; _syntaxBuilder.Build(value, false, out Token[] tokens); if (_syntaxBuilder.EventLog != null && _syntaxBuilder.HasEventLogs) { return(new ActionableErrorInfo(DoError) { Message = "Syntax Error An error occurred while parsing { " + value + " } It appears to be malformed" }); } } return(null); }
void TryExecuteField(IDSFDataObject dataObject, int update, ErrorResultTO allErrors, int innerCount, AssignObjectDTO t) { try { if (!string.IsNullOrEmpty(t.FieldName)) { var assignValue = new AssignValue(t.FieldName, t.FieldValue); var isCalcEvaluation = DataListUtil.IsCalcEvaluation(t.FieldValue, out string cleanExpression); if (isCalcEvaluation) { assignValue = new AssignValue(t.FieldName, cleanExpression); } DebugItem debugItem = null; if (dataObject.IsDebugMode()) { debugItem = AddSingleInputDebugItem(dataObject.Environment, innerCount, assignValue, update); } if (isCalcEvaluation) { DoCalculation(dataObject.Environment, t.FieldName, t.FieldValue, update); } else { dataObject.Environment.AssignJson(assignValue, update); } if (debugItem != null) { _debugInputs.Add(debugItem); } if (dataObject.IsDebugMode()) { assignValue = AddDebugOutputItem(dataObject, update, innerCount, assignValue); } } } catch (Exception e) { //Dev2Logger.Error(nameof(DsfMultiAssignObjectActivity), e, GlobalConstants.WarewolfError); allErrors.AddError(e.Message); } }
private int AssignField(IDSFDataObject dataObject, int update, int innerCount, AssignObjectDTO t) { if (!string.IsNullOrEmpty(t.FieldName)) { var assignValue = new AssignValue(t.FieldName, t.FieldValue); var isCalcEvaluation = DataListUtil.IsCalcEvaluation(t.FieldValue, out string cleanExpression); if (isCalcEvaluation) { assignValue = new AssignValue(t.FieldName, cleanExpression); } DebugItem debugItem = null; if (dataObject.IsDebugMode()) { debugItem = AddSingleInputDebugItem(dataObject.Environment, innerCount, assignValue, update); } if (isCalcEvaluation) { DoCalculation(dataObject.Environment, t.FieldName, t.FieldValue, update); } else { dataObject.Environment.AssignJson(assignValue, update); } if (debugItem != null) { _debugInputs.Add(debugItem); } if (dataObject.IsDebugMode()) { if (DataListUtil.IsValueRecordset(assignValue.Name) && DataListUtil.GetRecordsetIndexType(assignValue.Name) == enRecordsetIndexType.Blank) { var length = dataObject.Environment.GetObjectLength(DataListUtil.ExtractRecordsetNameFromValue(assignValue.Name)); assignValue = new AssignValue(DataListUtil.ReplaceObjectBlankWithIndex(assignValue.Name, length), assignValue.Value); } AddSingleDebugOutputItem(dataObject.Environment, innerCount, assignValue, update); } } innerCount++; return(innerCount); }
void ExecuteField(IDSFDataObject dataObject, int update, int innerCount, ActivityDTO t) { var assignValue = new AssignValue(t.FieldName, t.FieldValue); var isCalcEvaluation = DataListUtil.IsCalcEvaluation(t.FieldValue, out string cleanExpression); if (isCalcEvaluation) { assignValue = new AssignValue(t.FieldName, cleanExpression); } DebugItem debugItem = null; if (dataObject.IsDebugMode()) { debugItem = TryCreateDebugInput(dataObject.Environment, innerCount, assignValue, update); } if (isCalcEvaluation) { DoCalculation(dataObject.Environment, t.FieldName, t.FieldValue, update); } else { dataObject.Environment.AssignWithFrame(assignValue, update); } if (debugItem != null) { _debugInputs.Add(debugItem); } if (dataObject.IsDebugMode()) { if (DataListUtil.IsValueRecordset(assignValue.Name) && DataListUtil.GetRecordsetIndexType(assignValue.Name) == enRecordsetIndexType.Blank) { var length = dataObject.Environment.GetLength(DataListUtil.ExtractRecordsetNameFromValue(assignValue.Name)); assignValue = new AssignValue(DataListUtil.ReplaceRecordsetBlankWithIndex(assignValue.Name, length), assignValue.Value); } AddSingleDebugOutputItem(dataObject.Environment, innerCount, assignValue, update); } }
public override IActionableErrorInfo Check() { var value = GetValue(); bool isValid = true; string calculationExpression; if (DataListUtil.IsCalcEvaluation(value, out calculationExpression)) { IntellisenseProviderContext context = new IntellisenseProviderContext { CaretPosition = value.Length, InputText = value, IsInCalculateMode = true, DesiredResultSet = IntellisenseDesiredResultSet.ClosestMatch }; var results = _intellisenseProvider.GetIntellisenseResults(context); if (results.Any(e => e.IsError)) { isValid = false; ErrorText = results.First(e => e.IsError).Description; } } if (!isValid) { return(new ActionableErrorInfo(DoError) { Message = string.Format("{0} {1}", LabelText, ErrorText) }); } return(null); }
//public override IDev2Activity Execute(IDSFDataObject data) //{ // ExecuteTool(data); // if(NextNodes != null && NextNodes.Count()>0) // { // NextNodes.First().Execute(data); // return NextNodes.First(); // } // return null; //} #endregion protected override void ExecuteTool(IDSFDataObject dataObject, int update) { _debugOutputs.Clear(); _debugInputs.Clear(); InitializeDebug(dataObject); ErrorResultTO errors = new ErrorResultTO(); ErrorResultTO allErrors = new ErrorResultTO(); try { if (!errors.HasErrors()) { int innerCount = 1; foreach (ActivityDTO t in FieldsCollection) { try { if (!string.IsNullOrEmpty(t.FieldName)) { string cleanExpression; var assignValue = new AssignValue(t.FieldName, t.FieldValue); var isCalcEvaluation = DataListUtil.IsCalcEvaluation(t.FieldValue, out cleanExpression); if (isCalcEvaluation) { assignValue = new AssignValue(t.FieldName, cleanExpression); } DebugItem debugItem = null; if (dataObject.IsDebugMode()) { debugItem = AddSingleInputDebugItem(dataObject.Environment, innerCount, assignValue, update); } if (isCalcEvaluation) { DoCalculation(dataObject.Environment, t.FieldName, t.FieldValue, update); } else { dataObject.Environment.AssignWithFrame(assignValue, update); } if (debugItem != null) { _debugInputs.Add(debugItem); } if (dataObject.IsDebugMode()) { if (DataListUtil.IsValueRecordset(assignValue.Name) && DataListUtil.GetRecordsetIndexType(assignValue.Name) == enRecordsetIndexType.Blank) { var length = dataObject.Environment.GetLength(DataListUtil.ExtractRecordsetNameFromValue(assignValue.Name)); assignValue = new AssignValue(DataListUtil.ReplaceRecordsetBlankWithIndex(assignValue.Name, length), assignValue.Value); } AddSingleDebugOutputItem(dataObject.Environment, innerCount, assignValue, update); } } innerCount++; } catch (Exception e) { Dev2Logger.Error(e); allErrors.AddError(e.Message); } } dataObject.Environment.CommitAssign(); allErrors.MergeErrors(errors); } } catch (Exception e) { Dev2Logger.Error(e); allErrors.AddError(e.Message); } finally { // Handle Errors var hasErrors = allErrors.HasErrors(); if (hasErrors) { DisplayAndWriteError("DsfAssignActivity", allErrors); var errorString = allErrors.MakeDisplayReady(); dataObject.Environment.AddError(errorString); } if (dataObject.IsDebugMode()) { DispatchDebugState(dataObject, StateType.Before, update); DispatchDebugState(dataObject, StateType.After, update); } } }