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); }
public string GetNextValue() { _currentValue++; if (_listResult.MoveNext()) { _currentResult = _listResult.Current; return(ExecutionEnvironment.WarewolfAtomToStringNullAsNothing(_listResult.Current)); } return(ExecutionEnvironment.WarewolfAtomToStringNullAsNothing(_currentResult)); }
public static string WarewolfAtomToStringErrorIfNull(DataStorage.WarewolfAtom a) { if (a == null) { return(string.Empty); } if (a.IsNothing) { throw new NullValueInVariableException(ErrorResource.VariableIsNull, string.Empty); } return(a.ToString()); }
static void ParseDataItemToOutputs(JObject jObject, string key, DataStorage.WarewolfAtom warewolfAtom) { if (warewolfAtom is DataStorage.WarewolfAtom.DataString stringResult) { jObject.Add(key, stringResult.Item); } else if (warewolfAtom is DataStorage.WarewolfAtom.Int intResult) { jObject.Add(key, intResult.Item); } else if (warewolfAtom is DataStorage.WarewolfAtom.Float floatResult) { jObject.Add(key, floatResult.Item); } else { jObject.Add(key, warewolfAtom.ToString()); } }
private static KeyValuePair <string, WarewolfAtomList <DataStorage.WarewolfAtom> > CreateDataItem(JArray newArray, KeyValuePair <string, WarewolfAtomList <DataStorage.WarewolfAtom> > dataItem, JObject jObjForArray, int i, DataStorage.WarewolfAtom warewolfAtom) { if (newArray.Count < i + 1 || newArray.Count == 0) { newArray.Add(jObjForArray); } else { var jToken = newArray[i] as JObject; jToken?.Add(new JProperty(dataItem.Key, warewolfAtom.ToString())); } return(dataItem); }
public static string WarewolfAtomToStringNullAsNothing(DataStorage.WarewolfAtom a) => a == null ? null : (a.IsNothing ? null : a.ToString());
public static string WarewolfAtomToString(DataStorage.WarewolfAtom a) => a?.ToString() ?? string.Empty;
#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 static bool RunBetween(IEnumerable <DataStorage.WarewolfAtom> warewolfAtoms, IEnumerable <DataStorage.WarewolfAtom> tovals, DataStorage.WarewolfAtom a) #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 { var iterator = new WarewolfListIterator(); var from = new WarewolfAtomIterator(warewolfAtoms); var to = new WarewolfAtomIterator(tovals); iterator.AddVariableToIterateOn(@from); iterator.AddVariableToIterateOn(to); while (iterator.HasMoreData()) { var fromval = iterator.FetchNextValue(@from); var toVal = iterator.FetchNextValue(to); if (DateTime.TryParse(fromval, out DateTime fromDt)) { if (!DateTime.TryParse(toVal, out DateTime toDt)) { throw new InvalidDataException(ErrorResource.IsBetweenDataTypeMismatch); } if (DateTime.TryParse(a.ToString(), out DateTime recDateTime) && recDateTime > fromDt && recDateTime < toDt) { return(true); } } if (double.TryParse(fromval, out double fromNum)) { if (!double.TryParse(toVal, out double toNum)) { return(false); } if (!double.TryParse(a.ToString(), out double recNum)) { continue; } if (recNum > fromNum && recNum < toNum) { return(true); } } } return(false); }
static bool RunBetween(IEnumerable <DataStorage.WarewolfAtom> warewolfAtoms, IEnumerable <DataStorage.WarewolfAtom> tovals, DataStorage.WarewolfAtom a) { var iterator = new WarewolfListIterator(); var from = new WarewolfAtomIterator(warewolfAtoms); var to = new WarewolfAtomIterator(tovals); iterator.AddVariableToIterateOn(@from); iterator.AddVariableToIterateOn(to); while (iterator.HasMoreData()) { var fromval = iterator.FetchNextValue(@from); var toVal = iterator.FetchNextValue(to); if (DateTime.TryParse(fromval, out DateTime fromDt)) { if (!DateTime.TryParse(toVal, out DateTime toDt)) { throw new InvalidDataException(ErrorResource.IsBetweenDataTypeMismatch); } if (DateTime.TryParse(a.ToString(), out DateTime recDateTime) && recDateTime > fromDt && recDateTime < toDt) { return(true); } } if (double.TryParse(fromval, out double fromNum)) { if (!double.TryParse(toVal, out double toNum)) { return(false); } if (!double.TryParse(a.ToString(), out double recNum)) { continue; } if (recNum > fromNum && recNum < toNum) { return(true); } } } return(false); }
public static string WarewolfAtomToString(DataStorage.WarewolfAtom a) { return(a?.ToString() ?? string.Empty); }