Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="schema"></param>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static bool GetUndottedName(Schema schema, XmlReader reader, out string name)
        {
            Debug.Assert(schema != null, "schema parameter is null");
            Debug.Assert(reader != null, "reader parameter is null");

            if (reader.SchemaInfo.Validity == System.Xml.Schema.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,
                                System.Data.Entity.Strings.EmptyName(reader.Name));
                return(false);
            }

            if (schema.DataModel == SchemaDataModelOption.EntityDataModel &&
                !ValidUndottedName(name))
            {
                schema.AddError(ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader,
                                System.Data.Entity.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);
        }
Example #2
0
        public static bool GetByte(Schema schema, XmlReader reader, out byte value)
        {
            Debug.Assert(schema != null, "schema parameter is null");
            Debug.Assert(reader != null, "reader parameter is null");

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

            string text = reader.Value;

            value = byte.MinValue;

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

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

            return(false);
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="schema"></param>
        /// <param name="reader"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool GetBool(Schema schema, XmlReader reader, out bool value)
        {
            Debug.Assert(schema != null, "schema parameter is null");
            Debug.Assert(reader != null, "reader parameter is null");

            if (reader.SchemaInfo.Validity == System.Xml.Schema.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 (System.Xml.XmlException)
            {
                // we already handled the valid and invalid cases, so it must be NotKnown now.
                Debug.Assert(reader.SchemaInfo.Validity == Xml.Schema.XmlSchemaValidity.NotKnown, "The schema validity must be NotKnown at this point");
                schema.AddError(ErrorCode.BoolValueExpected, EdmSchemaErrorSeverity.Error, reader,
                                System.Data.Entity.Strings.ValueNotUnderstood(reader.Value, reader.Name));
            }

            value = true; // we have to set the value to something before returning.
            return(false);
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="schema"></param>
        /// <param name="reader"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool GetString(Schema schema, XmlReader reader, out string value)
        {
            Debug.Assert(schema != null, "schema parameter is null");
            Debug.Assert(reader != null, "reader parameter is null");

            if (reader.SchemaInfo.Validity == System.Xml.Schema.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,
                                System.Data.Entity.Strings.InvalidName(value, reader.Name));
                return(false);
            }
            return(true);
        }
Example #5
0
        internal static bool ValidateDottedName(Schema schema, XmlReader reader, string name)
        {
            Debug.Assert(schema != null, "schema parameter is null");
            Debug.Assert(reader != null, "reader parameter is null");
            Debug.Assert(!string.IsNullOrEmpty(name), "name parameter is null or empty");
            Debug.Assert(reader.SchemaInfo.Validity != System.Xml.Schema.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 (string namePart in name.Split('.'))
                {
                    if (!ValidUndottedName(namePart))
                    {
                        schema.AddError(ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader,
                                        System.Data.Entity.Strings.InvalidName(name, reader.Name));
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="errorCode"></param>
        /// <param name="severity"></param>
        /// <param name="source"></param>
        /// <param name="lineNumber"></param>
        /// <param name="linePosition"></param>
        /// <param name="message"></param>
        private void AddError(ErrorCode errorCode, EdmSchemaErrorSeverity severity, string sourceLocation, int lineNumber, int linePosition, object message)
        {
            EdmSchemaError error         = null;
            string         messageString = message as string;

            if (messageString != null)
            {
                error = new EdmSchemaError(messageString, (int)errorCode, severity, sourceLocation, lineNumber, linePosition);
            }
            else
            {
                Exception 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);
        }
Example #7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="schema"></param>
        /// <param name="reader"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool GetString(Schema schema, XmlReader reader, out string value)
        {
            Debug.Assert(schema != null, "schema parameter is null");
            Debug.Assert(reader != null, "reader parameter is null");

            if (reader.SchemaInfo.Validity == System.Xml.Schema.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,
                    System.Data.Entity.Strings.InvalidName(value, reader.Name));
                return false;
            }
            return true;
        }
Example #8
0
        public static bool GetByte(Schema schema,XmlReader reader,out byte value)
        {
            Debug.Assert(schema != null, "schema parameter is null");
            Debug.Assert(reader != null, "reader parameter is null");

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

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

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

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

            return false;
        }
Example #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="schema"></param>
        /// <param name="reader"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool GetBool(Schema schema, XmlReader reader, out bool value)
        {
            Debug.Assert(schema != null, "schema parameter is null");
            Debug.Assert(reader != null, "reader parameter is null");

            if ( reader.SchemaInfo.Validity == System.Xml.Schema.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 (System.Xml.XmlException)
            {
                // we already handled the valid and invalid cases, so it must be NotKnown now.
                Debug.Assert(reader.SchemaInfo.Validity == Xml.Schema.XmlSchemaValidity.NotKnown, "The schema validity must be NotKnown at this point");
                schema.AddError(ErrorCode.BoolValueExpected, EdmSchemaErrorSeverity.Error, reader,
                    System.Data.Entity.Strings.ValueNotUnderstood(reader.Value, reader.Name));
            }
            
            value = true; // we have to set the value to something before returning.
            return false;
        }
Example #10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="schema"></param>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static bool GetUndottedName(Schema schema,XmlReader reader,out string name)
        {
            Debug.Assert(schema != null, "schema parameter is null");
            Debug.Assert(reader != null, "reader parameter is null");

            if (reader.SchemaInfo.Validity == System.Xml.Schema.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,
                    System.Data.Entity.Strings.EmptyName(reader.Name));
                return false;
            }

            if (schema.DataModel == SchemaDataModelOption.EntityDataModel &&
                !ValidUndottedName(name) )
            {
                schema.AddError( ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader,
                    System.Data.Entity.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;
        }
Example #11
0
        internal static bool ValidateDottedName(Schema schema, XmlReader reader, string name)
        {
            Debug.Assert(schema != null, "schema parameter is null");
            Debug.Assert(reader != null, "reader parameter is null");
            Debug.Assert(!string.IsNullOrEmpty(name), "name parameter is null or empty");
            Debug.Assert(reader.SchemaInfo.Validity != System.Xml.Schema.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 (string namePart in name.Split('.'))
                {
                    if (!ValidUndottedName(namePart))
                    {
                        schema.AddError(ErrorCode.InvalidName, EdmSchemaErrorSeverity.Error, reader,
                            System.Data.Entity.Strings.InvalidName(name, reader.Name));
                        return false;
                    }
                }
            }
            return true;
        }
Example #12
0
        public static bool GetInt(Schema schema, XmlReader reader, out int value)
        {
            Debug.Assert(schema != null, "schema parameter is null");
            Debug.Assert(reader != null, "reader parameter is null");

            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 = int.MinValue;

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

            schema.AddError(
                ErrorCode.IntegerExpected, EdmSchemaErrorSeverity.Error, reader,
                Strings.ValueNotUnderstood(reader.Value, reader.Name));
            return false;
        }