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);
        }
示例#2
0
        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());
 }
示例#4
0
 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());
     }
 }
示例#5
0
        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);
        }
示例#6
0
 public static string WarewolfAtomToStringNullAsNothing(DataStorage.WarewolfAtom a) => a == null ? null : (a.IsNothing ? null : a.ToString());
示例#7
0
 public static string WarewolfAtomToString(DataStorage.WarewolfAtom a) => a?.ToString() ?? string.Empty;
示例#8
0
#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);
        }
示例#9
0
        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);
 }