Пример #1
0
        private static string GetDefaultForNullLogMessage(OPathVariable opathVariable, string evaluatedOPath,
                                                          object defaultValue)
        {
            string defaultForNullLogMessage =
                string.Format("{0} interpreted as '{1}' ({2} evaluated to '{3}')",
                              opathVariable.GetReference(), defaultValue ?? NULL_MESSAGE_STRING, evaluatedOPath, NULL_MESSAGE_STRING);

            return(defaultForNullLogMessage);
        }
Пример #2
0
        public string AddNewVariable()
        {
            string xpathName = GetNewVariableXPathName();

            OPathVariable variable = new OPathVariable(this.CurrentVariableName, GetOPathParts(), xpathName);

            this.variableSet.Add(variable.GetReference(), variable);

            return(xpathName);
        }
Пример #3
0
        private static string GetDefaultIfExceptionLogMessage(OPathVariable opathVariable, string evaluatedOPath,
                                                              OPathPart opathPart, object defaultValue, Exception exception)
        {
            string exceptionMessage = exception.Message;
            Type   exceptionType    = exception.GetType();

            if ((exception is OPathException) &&
                (exception.InnerException != null))
            {
                exceptionMessage = exception.InnerException.Message;
                exceptionType    = exception.InnerException.GetType();
            }

            string defaultIfExceptionLogMessage =
                string.Format("{0} interpreted as '{1}' ({2}{3} threw {4}: {5})",
                              opathVariable.GetReference(), defaultValue ?? NULL_MESSAGE_STRING, evaluatedOPath, opathPart,
                              exceptionType.Name, exceptionMessage);

            return(defaultIfExceptionLogMessage);
        }
Пример #4
0
        private object EvaluateVariableReference(object sourceObject, OPathVariable opathVariable,
                                                 OPathOptions opathOptions, object defaultValue, ValueLogger valueLogger, string opath)
        {
            object opathValue     = sourceObject;
            string evaluatedOPath = opathVariable.Name;

            foreach (OPathPart opathPart in opathVariable.OPathParts)
            {
                if (opathValue == null)
                {
                    if (IsReturnDefaultForNullOptionSet(opathOptions))
                    {
                        if (valueLogger != null)
                        {
                            string defaultForNullLogMessage =
                                GetDefaultForNullLogMessage(opathVariable, evaluatedOPath, defaultValue);
                            valueLogger(defaultForNullLogMessage);
                        }

                        opathValue = defaultValue;
                        break;
                    }
                    else
                    {
                        throw new OPathException(
                                  string.Format("{0} evaluated to '{1}'.", evaluatedOPath, NULL_MESSAGE_STRING));
                    }
                }

                try
                {
                    opathValue = opathPart.Evaluate(opathValue, evaluatedOPath);

                    evaluatedOPath += opathPart;
                }
                catch (Exception ex)
                {
                    if (IsReturnDefaultIfExceptionOptionSet(opathOptions))
                    {
                        if (valueLogger != null)
                        {
                            string defaultIfExceptionLogMessage =
                                GetDefaultIfExceptionLogMessage(
                                    opathVariable, evaluatedOPath, opathPart, defaultValue, ex);
                            valueLogger(defaultIfExceptionLogMessage);
                        }

                        opathValue = defaultValue;
                        break;
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            if (valueLogger != null)
            {
                valueLogger(
                    string.Format("{0} evaluated to '{1}'", opathVariable.GetReference(), opathValue ?? NULL_MESSAGE_STRING));
            }

            return(opathValue);
        }