Beispiel #1
0
        private object GetSourceObject(OPathVariable opathVariable)
        {
            object sourceObject;

            if (m_OPathDocument.ContainsKey(opathVariable.Name))
            {
                sourceObject = m_OPathDocument[opathVariable.Name];
            }
            else
            {
                object standardSourceObject;
                if (GetStandardSourceObject(opathVariable.Name, out standardSourceObject))
                {
                    sourceObject = standardSourceObject;
                }
                else
                {
                    throw new OPathException(string.Format(
                                                 "The expression contains variable '{0}', but no source object with that name was supplied.",
                                                 opathVariable.Name));
                }
            }

            return(sourceObject);
        }
Beispiel #2
0
        public string GetVariableXPathName(string variableReference)
        {
            OPathVariable variable          = this.variableSet[variableReference];
            string        variableXPathName = variable.XPathName;

            return(variableXPathName);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public string AddNewVariable()
        {
            string xpathName = GetNewVariableXPathName();

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

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

            return(xpathName);
        }
Beispiel #5
0
        private object EvaluateSingleVariable(OPathExpression opathExpression, OPathOptions opathOptions,
                                              object defaultValue, ValueLogger valueLogger)
        {
            OPathVariable opathVariable = opathExpression.Variables[0];

            object sourceObject = GetSourceObject(opathVariable);

            object variableValue =
                EvaluateVariableReference(
                    sourceObject, opathVariable, opathOptions, defaultValue, valueLogger, opathExpression.OPath);

            return(variableValue);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }