Exemplo n.º 1
0
        public static bool GetByte(Schema schema, XmlReader reader, out byte value)
        {
            DebugCheck.NotNull(schema);
            DebugCheck.NotNull(reader);

            if (reader.SchemaInfo.Validity
                == XmlSchemaValidity.Invalid)
            {
                // an error has already been issued by the xsd validation
                value = 0;
                ;
                return(false);
            }

            var text = reader.Value;

            value = byte.MinValue;

            if (byte.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out value))
            {
                return(true);
            }

            schema.AddError(
                ErrorCode.ByteValueExpected, EdmSchemaErrorSeverity.Error, reader,
                Strings.ValueNotUnderstood(reader.Value, reader.Name));

            return(false);
        }
Exemplo n.º 2
0
        public static bool GetBool(Schema schema, XmlReader reader, out bool value)
        {
            DebugCheck.NotNull(schema);
            DebugCheck.NotNull(reader);

            if (reader.SchemaInfo.Validity
                == XmlSchemaValidity.Invalid)
            {
                value = true; // we have to set the value to something before returning.
                return(false);
            }

            // do this in a try catch, just in case the attribute wasn't validated against an xsd:boolean
            try
            {
                value = reader.ReadContentAsBoolean();
                return(true);
            }
            catch (XmlException)
            {
                // we already handled the valid and invalid cases, so it must be NotKnown now.
                Debug.Assert(reader.SchemaInfo.Validity == XmlSchemaValidity.NotKnown, "The schema validity must be NotKnown at this point");
                schema.AddError(
                    ErrorCode.BoolValueExpected, EdmSchemaErrorSeverity.Error, reader,
                    Strings.ValueNotUnderstood(reader.Value, reader.Name));
            }

            value = true; // we have to set the value to something before returning.
            return(false);
        }
Exemplo n.º 3
0
        public static bool GetUndottedName(Schema schema, XmlReader reader, out string name)
        {
            DebugCheck.NotNull(schema);
            DebugCheck.NotNull(reader);

            if (reader.SchemaInfo.Validity == XmlSchemaValidity.Invalid)
            {
                // the xsd already put in an error
                name = null;
                return(false);
            }

            name = reader.Value;
            if (string.IsNullOrEmpty(name))
            {
                schema.AddError(
                    ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader,
                    Strings.EmptyName(reader.Name));
                return(false);
            }

            if (schema.DataModel == SchemaDataModelOption.EntityDataModel &&
                !name.IsValidUndottedName())
            {
                schema.AddError(
                    ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader,
                    Strings.InvalidName(name, reader.Name));
                return(false);
            }

            Debug.Assert(
                !(schema.DataModel == SchemaDataModelOption.EntityDataModel && name.IndexOf('.') >= 0),
                string.Format(CultureInfo.CurrentCulture, "{1} ({0}) is not valid. {1} cannot be qualified.", name, reader.Name));

            return(true);
        }
Exemplo n.º 4
0
        private void AddError(
            ErrorCode errorCode, EdmSchemaErrorSeverity severity, string sourceLocation, int lineNumber, int linePosition, object message)
        {
            EdmSchemaError error         = null;
            var            messageString = message as string;

            if (messageString != null)
            {
                error = new EdmSchemaError(messageString, (int)errorCode, severity, sourceLocation, lineNumber, linePosition);
            }
            else
            {
                var ex = message as Exception;
                if (ex != null)
                {
                    error = new EdmSchemaError(ex.Message, (int)errorCode, severity, sourceLocation, lineNumber, linePosition, ex);
                }
                else
                {
                    error = new EdmSchemaError(message.ToString(), (int)errorCode, severity, sourceLocation, lineNumber, linePosition);
                }
            }
            Schema.AddError(error);
        }
Exemplo n.º 5
0
        public static bool GetString(Schema schema, XmlReader reader, out string value)
        {
            DebugCheck.NotNull(schema);
            DebugCheck.NotNull(reader);

            if (reader.SchemaInfo.Validity
                == XmlSchemaValidity.Invalid)
            {
                // an error has already been issued by the xsd validation
                value = null;
                return(false);
            }

            value = reader.Value;

            if (string.IsNullOrEmpty(value))
            {
                schema.AddError(
                    ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader,
                    Strings.InvalidName(value, reader.Name));
                return(false);
            }
            return(true);
        }
Exemplo n.º 6
0
        internal static bool ValidateDottedName(Schema schema, XmlReader reader, string name)
        {
            DebugCheck.NotNull(schema);
            DebugCheck.NotNull(reader);
            DebugCheck.NotEmpty(name);
            Debug.Assert(
                reader.SchemaInfo.Validity != XmlSchemaValidity.Invalid, "This method should not be called when the schema is invalid");

            if (schema.DataModel == SchemaDataModelOption.EntityDataModel)
            {
                // each part of the dotted name needs to be a valid name
                foreach (var namePart in name.Split('.'))
                {
                    if (!namePart.IsValidUndottedName())
                    {
                        schema.AddError(
                            ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader,
                            Strings.InvalidName(name, reader.Name));
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 7
0
        public static bool GetString(Schema schema, XmlReader reader, out string value)
        {
            DebugCheck.NotNull(schema);
            DebugCheck.NotNull(reader);

            if (reader.SchemaInfo.Validity
                == XmlSchemaValidity.Invalid)
            {
                // an error has already been issued by the xsd validation
                value = null;
                return false;
            }

            value = reader.Value;

            if (string.IsNullOrEmpty(value))
            {
                schema.AddError(
                    ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader,
                    Strings.InvalidName(value, reader.Name));
                return false;
            }
            return true;
        }
Exemplo n.º 8
0
        public static bool GetByte(Schema schema, XmlReader reader, out byte value)
        {
            DebugCheck.NotNull(schema);
            DebugCheck.NotNull(reader);

            if (reader.SchemaInfo.Validity
                == XmlSchemaValidity.Invalid)
            {
                // an error has already been issued by the xsd validation
                value = 0;
                ;
                return false;
            }

            var text = reader.Value;
            value = byte.MinValue;

            if (byte.TryParse(text, NumberStyles.Integer, CultureInfo.InvariantCulture, out value))
            {
                return true;
            }

            schema.AddError(
                ErrorCode.ByteValueExpected, EdmSchemaErrorSeverity.Error, reader,
                Strings.ValueNotUnderstood(reader.Value, reader.Name));

            return false;
        }
Exemplo n.º 9
0
        public static bool GetBool(Schema schema, XmlReader reader, out bool value)
        {
            DebugCheck.NotNull(schema);
            DebugCheck.NotNull(reader);

            if (reader.SchemaInfo.Validity
                == XmlSchemaValidity.Invalid)
            {
                value = true; // we have to set the value to something before returning.
                return false;
            }

            // do this in a try catch, just in case the attribute wasn't validated against an xsd:boolean
            try
            {
                value = reader.ReadContentAsBoolean();
                return true;
            }
            catch (XmlException)
            {
                // we already handled the valid and invalid cases, so it must be NotKnown now.
                Debug.Assert(reader.SchemaInfo.Validity == XmlSchemaValidity.NotKnown, "The schema validity must be NotKnown at this point");
                schema.AddError(
                    ErrorCode.BoolValueExpected, EdmSchemaErrorSeverity.Error, reader,
                    Strings.ValueNotUnderstood(reader.Value, reader.Name));
            }

            value = true; // we have to set the value to something before returning.
            return false;
        }
Exemplo n.º 10
0
        public static bool GetUndottedName(Schema schema, XmlReader reader, out string name)
        {
            DebugCheck.NotNull(schema);
            DebugCheck.NotNull(reader);

            if (reader.SchemaInfo.Validity == XmlSchemaValidity.Invalid)
            {
                // the xsd already put in an error
                name = null;
                return false;
            }

            name = reader.Value;
            if (string.IsNullOrEmpty(name))
            {
                schema.AddError(
                    ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader,
                    Strings.EmptyName(reader.Name));
                return false;
            }

            if (schema.DataModel == SchemaDataModelOption.EntityDataModel
                && !name.IsValidUndottedName())
            {
                schema.AddError(
                    ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader,
                    Strings.InvalidName(name, reader.Name));
                return false;
            }

            Debug.Assert(
                !(schema.DataModel == SchemaDataModelOption.EntityDataModel && name.IndexOf('.') >= 0),
                string.Format(CultureInfo.CurrentCulture, "{1} ({0}) is not valid. {1} cannot be qualified.", name, reader.Name));

            return true;
        }
Exemplo n.º 11
0
        internal static bool ValidateDottedName(Schema schema, XmlReader reader, string name)
        {
            DebugCheck.NotNull(schema);
            DebugCheck.NotNull(reader);
            DebugCheck.NotEmpty(name);
            Debug.Assert(
                reader.SchemaInfo.Validity != XmlSchemaValidity.Invalid, "This method should not be called when the schema is invalid");

            if (schema.DataModel == SchemaDataModelOption.EntityDataModel)
            {
                // each part of the dotted name needs to be a valid name
                foreach (var namePart in name.Split('.'))
                {
                    if (!namePart.IsValidUndottedName())
                    {
                        schema.AddError(
                            ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader,
                            Strings.InvalidName(name, reader.Name));
                        return false;
                    }
                }
            }
            return true;
        }