Esempio n. 1
0
        public void AssignStrict(string exp, string value, bool throwsifnotexists, int update)
        {
            if (string.IsNullOrEmpty(exp))
            {
                return;
            }

            try
            {
                var envTemp = PublicFunctions.EvalAssignWithFrameStrict(new AssignValue(exp, value), update, _env);

                _env = envTemp;
                CommitAssign();
            }
            catch (Exception err)
            {
                var msg = err.Message;
                if (throwsifnotexists && err.Message.Contains("parse error"))
                {
                    throw new WarewolfExecutionEnvironmentException(msg + ": " + "{ " + DataListUtilBase.StripLeadingAndTrailingBracketsFromValue(exp) + " }");
                }
                if (throwsifnotexists && err.Message.Contains("invalid variable assigned to"))
                {
                    throw new WarewolfExecutionEnvironmentException(msg);
                }
                //NOTE:This have a possibility to duplicate error add if caller is also catching exceptions and adding error, use with caution
                Errors.Add(msg + ": " + "{ " + DataListUtilBase.StripLeadingAndTrailingBracketsFromValue(exp) + " }");
            }
        }
Esempio n. 2
0
        public void AssignString(string exp, string value, bool throwsifnotexists, int update)
        {
            if (string.IsNullOrEmpty(exp))
            {
                return;
            }

            try
            {
                var envTemp = PublicFunctions.EvalAssignWithFrameTypeCast(new AssignValue(exp, value), update, _env, ShouldTypeCast.No);

                _env = envTemp;
                CommitAssign();
            }
            catch (Exception err)
            {
                var msg = err.Message;
                if (throwsifnotexists)
                {
                    throw new WarewolfExecutionEnvironmentException(msg + ": " + "{ " + DataListUtilBase.StripLeadingAndTrailingBracketsFromValue(exp) + " }");
                }

                Errors.Add(msg + ": " + "{ " + DataListUtilBase.StripLeadingAndTrailingBracketsFromValue(exp) + " }");
            }
        }
Esempio n. 3
0
        public void Assign(string exp, string value, bool throwsifnotexists, int update)
        {
            if (string.IsNullOrEmpty(exp))
            {
                return;
            }

            try
            {
                var envTemp = PublicFunctions.EvalAssignWithFrame(new AssignValue(exp, value), update, _env);

                _env = envTemp;
                CommitAssign();
            }
            catch (Exception err)
            {
                var msg = err.Message;
                var msgWithVariableName = msg + ": " + "{ " + DataListUtilBase.StripLeadingAndTrailingBracketsFromValue(exp) + " }";
                if (err is NullValueInVariableException variableException && err.Message.Contains("Scalar value "))
                {
                    throw new WarewolfExecutionEnvironmentException(err.Message);
                }
                if (throwsifnotexists)
                {
                    throw new WarewolfExecutionEnvironmentException(msgWithVariableName);
                }

                Errors.Add(msgWithVariableName);
            }
        }
Esempio n. 4
0
        public void AssignJson(IAssignValue value, int update)
        {
            try
            {
                if (string.IsNullOrEmpty(value.Name))
                {
                    return;
                }

                var envTemp = AssignEvaluation.evalJsonAssign(value, update, _env, ShouldTypeCast.Yes);
                _env = envTemp;
            }
            catch (Exception err)
            {
                var res = err.Message + ": " + "{ " + DataListUtilBase.StripLeadingAndTrailingBracketsFromValue(value.Name) + " }";
                Errors.Add(res);
                throw new WarewolfExecutionEnvironmentException(res);
            }
        }
Esempio n. 5
0
        public CommonFunctions.WarewolfEvalResult Eval(string exp, int update, bool throwsifnotexists, bool shouldEscape)
        {
            try
            {
                return(PublicFunctions.EvalEnvExpression(exp, update, shouldEscape, _env));
            }
            catch (IndexOutOfRangeException)
            {
                throw;
            }
            catch (Exception e)
            {
                if (throwsifnotexists)
                {
                    if (e is NullValueInVariableException variableException && e.Message.Contains("variable not found"))
                    {
                        throw new WarewolfExecutionEnvironmentException("variable { " + DataListUtilBase.StripLeadingAndTrailingBracketsFromValue(variableException.VariableName) + " } not found");
                    }

                    if (e is IndexOutOfRangeException || e.Message.Contains(@"index was not an int"))
                    {
                        throw;
                    }

                    throw new WarewolfExecutionEnvironmentException(e.Message + "{ " + DataListUtilBase.StripLeadingAndTrailingBracketsFromValue(exp) + " }");
                }

                return(CommonFunctions.WarewolfEvalResult.NewWarewolfAtomResult(DataStorage.WarewolfAtom.Nothing));
            }
        }
Esempio n. 6
0
        public IList <string> EvalAsListOfStrings(string expression, int update)
        {
            var result = Eval(expression, update);

            if (result.IsWarewolfAtomResult && result is CommonFunctions.WarewolfEvalResult.WarewolfAtomResult x)
            {
                return(new List <string> {
                    WarewolfAtomToString(x.Item)
                });
            }

            if (result.IsWarewolfRecordSetResult && result is CommonFunctions.WarewolfEvalResult.WarewolfRecordSetResult recSetResult)
            {
                var recSetData = recSetResult.Item;
                if (recSetData != null)
                {
                    return(EvalListOfStringsHelper(recSetData));
                }
            }

            if (result is CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult warewolfAtomListresult)
            {
                var item = warewolfAtomListresult.Item;
                return(item.Select(WarewolfAtomToString).ToList());
            }

            throw new WarewolfExecutionEnvironmentException(string.Format(ErrorResource.CouldNotRetrieveStringsFromExpression, "{ " + DataListUtilBase.StripLeadingAndTrailingBracketsFromValue(expression) + " }"));
        }
Esempio n. 7
0
 public void AssignWithFrame(IAssignValue values, int update)
 {
     try
     {
         var envTemp = PublicFunctions.EvalAssignWithFrame(values, update, _env);
         _env = envTemp;
     }
     catch (Exception err)
     {
         throw new WarewolfExecutionEnvironmentException(err.Message + ": " + "{ " + DataListUtilBase.StripLeadingAndTrailingBracketsFromValue(values.Name) + " }");
     }
 }
        public void DataListUtilBase_StripLeadingAndTrailingBracketsFromValue_GivenVarialbleName_ShouldReturnName()
        {
            var result = DataListUtilBase.StripLeadingAndTrailingBracketsFromValue("[[name]]");

            Assert.AreEqual("name", result);
        }