Example #1
0
 private void ValidateGuidDefaultValue(ScalarType scalar)
 {
     if (!scalar.TryParse(_default, out _defaultObject))
     {
         _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultGuid(_default));
     }
 }
Example #2
0
 private void ValidateIntegralDefaultValue(ScalarType scalar, long minValue, long maxValue)
 {
     if (!scalar.TryParse(_default, out _defaultObject))
     {
         _element.AddError(
             ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultIntegral(_default, minValue, maxValue));
     }
 }
Example #3
0
 private void ValidateGuidDefaultValue(ScalarType scalar)
 {
     if (scalar.TryParse(this._default, out this._defaultObject))
     {
         return;
     }
     this._element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, (object)Strings.InvalidDefaultGuid((object)this._default));
 }
Example #4
0
 private void ValidateDateTimeOffsetDefaultValue(ScalarType scalar)
 {
     if (scalar.TryParse(this._default, out this._defaultObject))
     {
         return;
     }
     this._element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, (object)Strings.InvalidDefaultDateTimeOffset((object)this._default, (object)"yyyy-MM-dd HH\\:mm\\:ss.fffffffz".Replace("\\", "")));
 }
Example #5
0
 private void ValidateIntegralDefaultValue(ScalarType scalar, long minValue, long maxValue)
 {
     if (scalar.TryParse(this._default, out this._defaultObject))
     {
         return;
     }
     this._element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, (object)Strings.InvalidDefaultIntegral((object)this._default, (object)minValue, (object)maxValue));
 }
Example #6
0
        private void ValidateDecimalDefaultValue(ScalarType scalar)
        {
            if (scalar.TryParse(_default, out _defaultObject))
            {
                return;
            }

            _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultDecimal(_default, 38, 38));
        }
Example #7
0
 private void ValidateFloatingPointDefaultValue(ScalarType scalar, double minValue, double maxValue)
 {
     if (!scalar.TryParse(_default, out _defaultObject))
     {
         _element.AddError(
             ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error,
             Strings.InvalidDefaultFloatingPoint(_default, minValue, maxValue));
     }
 }
Example #8
0
 private void ValidateDateTimeOffsetDefaultValue(ScalarType scalar)
 {
     if (!scalar.TryParse(_default, out _defaultObject))
     {
         _element.AddError(
             ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultDateTimeOffset(
                 _default,
                 ScalarType.DateTimeOffsetFormat.Replace(@"\", "")));
     }
 }
Example #9
0
 private void ValidateFloatingPointDefaultValue(
     ScalarType scalar,
     double minValue,
     double maxValue)
 {
     if (scalar.TryParse(this._default, out this._defaultObject))
     {
         return;
     }
     this._element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, (object)Strings.InvalidDefaultFloatingPoint((object)this._default, (object)minValue, (object)maxValue));
 }
Example #10
0
        internal void ValidateAndSetTypeUsage(ScalarType scalar, bool complainOnMissingFacet)
        {
            Trace.Assert(this._element != null);
            Trace.Assert(scalar != null);
            if (Helper.IsSpatialType(scalar.Type) && !this._facetValues.ContainsKey("IsStrict") && !this._element.Schema.UseStrongSpatialTypes)
            {
                this._facetValues.Add("IsStrict", (object)false);
            }
            Dictionary <string, Facet> calculatedFacets;

            if (this.TryGetFacets((EdmType)scalar.Type, complainOnMissingFacet, out calculatedFacets))
            {
                switch (scalar.TypeKind)
                {
                case PrimitiveTypeKind.Binary:
                    this.ValidateAndSetBinaryFacets((EdmType)scalar.Type, calculatedFacets);
                    break;

                case PrimitiveTypeKind.DateTime:
                case PrimitiveTypeKind.Time:
                case PrimitiveTypeKind.DateTimeOffset:
                    this.ValidatePrecisionFacetsForDateTimeFamily((EdmType)scalar.Type, calculatedFacets);
                    break;

                case PrimitiveTypeKind.Decimal:
                    this.ValidateAndSetDecimalFacets((EdmType)scalar.Type, calculatedFacets);
                    break;

                case PrimitiveTypeKind.String:
                    this.ValidateAndSetStringFacets((EdmType)scalar.Type, calculatedFacets);
                    break;

                case PrimitiveTypeKind.Geometry:
                case PrimitiveTypeKind.Geography:
                case PrimitiveTypeKind.GeometryPoint:
                case PrimitiveTypeKind.GeometryLineString:
                case PrimitiveTypeKind.GeometryPolygon:
                case PrimitiveTypeKind.GeometryMultiPoint:
                case PrimitiveTypeKind.GeometryMultiLineString:
                case PrimitiveTypeKind.GeometryMultiPolygon:
                case PrimitiveTypeKind.GeometryCollection:
                case PrimitiveTypeKind.GeographyPoint:
                case PrimitiveTypeKind.GeographyLineString:
                case PrimitiveTypeKind.GeographyPolygon:
                case PrimitiveTypeKind.GeographyMultiPoint:
                case PrimitiveTypeKind.GeographyMultiLineString:
                case PrimitiveTypeKind.GeographyMultiPolygon:
                case PrimitiveTypeKind.GeographyCollection:
                    this.ValidateSpatialFacets((EdmType)scalar.Type, calculatedFacets);
                    break;
                }
            }
            this._typeUsage = TypeUsage.Create((EdmType)scalar.Type, (IEnumerable <Facet>)calculatedFacets.Values);
        }
Example #11
0
        private void ValidateBinaryDefaultValue(ScalarType scalar)
        {
            if (scalar.TryParse(_default, out _defaultObject))
            {
                return;
            }

            var errorMessage = Strings.InvalidDefaultBinaryWithNoMaxLength(_default);

            _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, errorMessage);
        }
Example #12
0
        public bool TryParse(string text, out object value)
        {
            switch (this._primitiveType.PrimitiveTypeKind)
            {
            case PrimitiveTypeKind.Binary:
                return(ScalarType.TryParseBinary(text, out value));

            case PrimitiveTypeKind.Boolean:
                return(ScalarType.TryParseBoolean(text, out value));

            case PrimitiveTypeKind.Byte:
                return(ScalarType.TryParseByte(text, out value));

            case PrimitiveTypeKind.DateTime:
                return(ScalarType.TryParseDateTime(text, out value));

            case PrimitiveTypeKind.Decimal:
                return(ScalarType.TryParseDecimal(text, out value));

            case PrimitiveTypeKind.Double:
                return(ScalarType.TryParseDouble(text, out value));

            case PrimitiveTypeKind.Guid:
                return(ScalarType.TryParseGuid(text, out value));

            case PrimitiveTypeKind.Single:
                return(ScalarType.TryParseSingle(text, out value));

            case PrimitiveTypeKind.SByte:
                return(ScalarType.TryParseSByte(text, out value));

            case PrimitiveTypeKind.Int16:
                return(ScalarType.TryParseInt16(text, out value));

            case PrimitiveTypeKind.Int32:
                return(ScalarType.TryParseInt32(text, out value));

            case PrimitiveTypeKind.Int64:
                return(ScalarType.TryParseInt64(text, out value));

            case PrimitiveTypeKind.String:
                return(ScalarType.TryParseString(text, out value));

            case PrimitiveTypeKind.Time:
                return(ScalarType.TryParseTime(text, out value));

            case PrimitiveTypeKind.DateTimeOffset:
                return(ScalarType.TryParseDateTimeOffset(text, out value));

            default:
                throw new NotSupportedException(this._primitiveType.FullName);
            }
        }
Example #13
0
        private static bool TryParseBinary(string text, out object value)
        {
            if (!ScalarType._binaryValueValidator.IsMatch(text))
            {
                value = (object)null;
                return(false);
            }
            string text1 = text.Substring(2);

            value = (object)ScalarType.ConvertToByteArray(text1);
            return(true);
        }
Example #14
0
        internal void ValidateDefaultValue(SchemaType type)
        {
            if (this._default == null)
            {
                return;
            }
            ScalarType scalar = type as ScalarType;

            if (scalar != null)
            {
                this.ValidateScalarMemberDefaultValue(scalar);
            }
            else
            {
                this._element.AddError(ErrorCode.DefaultNotAllowed, EdmSchemaErrorSeverity.Error, (object)Strings.DefaultNotAllowed);
            }
        }
Example #15
0
        internal override void ResolveTopLevelNames()
        {
            base.ResolveTopLevelNames();
            if (this._type != null)
            {
                return;
            }
            this._type = this.ResolveType(this.UnresolvedType);
            this._typeUsageBuilder.ValidateDefaultValue(this._type);
            ScalarType type = this._type as ScalarType;

            if (type == null)
            {
                return;
            }
            this._typeUsageBuilder.ValidateAndSetTypeUsage(type, true);
        }
Example #16
0
        internal override void Validate()
        {
            base.Validate();
            ScalarType enumUnderlyingType = this.UnderlyingType as ScalarType;

            if (enumUnderlyingType == null || !Helper.IsSupportedEnumUnderlyingType(enumUnderlyingType.TypeKind))
            {
                this.AddError(ErrorCode.InvalidEnumUnderlyingType, EdmSchemaErrorSeverity.Error, (object)Strings.InvalidEnumUnderlyingType);
            }
            else
            {
                foreach (SchemaEnumMember schemaEnumMember in this._enumMembers.Where <SchemaEnumMember>((Func <SchemaEnumMember, bool>)(m => !Helper.IsEnumMemberValueInRange(enumUnderlyingType.TypeKind, m.Value.Value))))
                {
                    schemaEnumMember.AddError(ErrorCode.EnumMemberValueOutOfItsUnderylingTypeRange, EdmSchemaErrorSeverity.Error, (object)Strings.EnumMemberValueOutOfItsUnderylingTypeRange((object)schemaEnumMember.Value, (object)schemaEnumMember.Name, (object)this.UnderlyingType.Name));
                }
            }
            if (!this._enumMembers.GroupBy <SchemaEnumMember, string>((Func <SchemaEnumMember, string>)(o => o.Name)).Where <IGrouping <string, SchemaEnumMember> >((Func <IGrouping <string, SchemaEnumMember>, bool>)(g => g.Count <SchemaEnumMember>() > 1)).Any <IGrouping <string, SchemaEnumMember> >())
            {
                return;
            }
            this.AddError(ErrorCode.DuplicateEnumMember, EdmSchemaErrorSeverity.Error, (object)Strings.DuplicateEnumMember);
        }
 private void ValidateIntegralDefaultValue(ScalarType scalar, long minValue, long maxValue)
 {
     if (!scalar.TryParse(_default, out _defaultObject))
     {
         _element.AddError(
             ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultIntegral(_default, minValue, maxValue));
     }
 }
        /// <summary>
        ///     effects: adds errors to _element if there are any; creates a TypeUsage instance using the
        ///     facet values aggregated by this builder and the given scalar type
        /// </summary>
        /// <param name="scalar"> Scalar type for the type usage </param>
        internal void ValidateAndSetTypeUsage(ScalarType scalar, bool complainOnMissingFacet)
        {
            Trace.Assert(_element != null);
            Trace.Assert(scalar != null);
            Dictionary<string, Facet> calculatedFacets;

            // Forward compat FUTURE SYSTEM.SPATIAL
            // for now we treat all Geographic types the same, and likewise for geometry.
            // to allow us to later introduce the full heirarchy without breaking back compat
            // we require spatial types to have the IsStrict facet with a false value.    
            // Set this facet to false if the schema has the UseStrongSpatialTypes attribute with the a false.
            if (Helper.IsSpatialType(scalar.Type)
                && !_facetValues.ContainsKey(DbProviderManifest.IsStrictFacetName)
                && !_element.Schema.UseStrongSpatialTypes)
            {
                _facetValues.Add(DbProviderManifest.IsStrictFacetName, false /* only possible value */);
            }

            var noErrors = TryGetFacets(scalar.Type, complainOnMissingFacet, out calculatedFacets);

            if (noErrors)
            {
                // Only validate the values if there are no errros encountered in the above functions.
                // If there are errors encountered (like for e.g. precision
                switch (scalar.TypeKind)
                {
                    case PrimitiveTypeKind.Binary:
                        ValidateAndSetBinaryFacets(scalar.Type, calculatedFacets);
                        break;
                    case PrimitiveTypeKind.String:
                        ValidateAndSetStringFacets(scalar.Type, calculatedFacets);
                        break;
                    case PrimitiveTypeKind.Decimal:
                        ValidateAndSetDecimalFacets(scalar.Type, calculatedFacets);
                        break;
                    case PrimitiveTypeKind.DateTime:
                    case PrimitiveTypeKind.Time:
                    case PrimitiveTypeKind.DateTimeOffset:
                        ValidatePrecisionFacetsForDateTimeFamily(scalar.Type, calculatedFacets);
                        break;
                    case PrimitiveTypeKind.Int16:
                    case PrimitiveTypeKind.Int32:
                    case PrimitiveTypeKind.Int64:
                    case PrimitiveTypeKind.Boolean:
                    case PrimitiveTypeKind.Byte:
                    case PrimitiveTypeKind.SByte:
                    case PrimitiveTypeKind.Double:
                    case PrimitiveTypeKind.Guid:
                    case PrimitiveTypeKind.Single:
                        break;
                    case PrimitiveTypeKind.Geography:
                    case PrimitiveTypeKind.GeographyPoint:
                    case PrimitiveTypeKind.GeographyLineString:
                    case PrimitiveTypeKind.GeographyPolygon:
                    case PrimitiveTypeKind.GeographyMultiPoint:
                    case PrimitiveTypeKind.GeographyMultiLineString:
                    case PrimitiveTypeKind.GeographyMultiPolygon:
                    case PrimitiveTypeKind.GeographyCollection:
                    case PrimitiveTypeKind.Geometry:
                    case PrimitiveTypeKind.GeometryPoint:
                    case PrimitiveTypeKind.GeometryLineString:
                    case PrimitiveTypeKind.GeometryPolygon:
                    case PrimitiveTypeKind.GeometryMultiPoint:
                    case PrimitiveTypeKind.GeometryMultiLineString:
                    case PrimitiveTypeKind.GeometryMultiPolygon:
                    case PrimitiveTypeKind.GeometryCollection:
                        ValidateSpatialFacets(scalar.Type, calculatedFacets);
                        break;
                    default:
                        Debug.Fail("Did you miss a value");
                        break;
                }
            }

            _typeUsage = TypeUsage.Create(scalar.Type, calculatedFacets.Values);
        }
Example #19
0
        private void ValidateScalarMemberDefaultValue(ScalarType scalar)
        {
            if (scalar == null)
            {
                return;
            }
            switch (scalar.TypeKind)
            {
            case PrimitiveTypeKind.Binary:
                this.ValidateBinaryDefaultValue(scalar);
                break;

            case PrimitiveTypeKind.Boolean:
                this.ValidateBooleanDefaultValue(scalar);
                break;

            case PrimitiveTypeKind.Byte:
                this.ValidateIntegralDefaultValue(scalar, 0L, (long)byte.MaxValue);
                break;

            case PrimitiveTypeKind.DateTime:
                this.ValidateDateTimeDefaultValue(scalar);
                break;

            case PrimitiveTypeKind.Decimal:
                this.ValidateDecimalDefaultValue(scalar);
                break;

            case PrimitiveTypeKind.Double:
                this.ValidateFloatingPointDefaultValue(scalar, double.MinValue, double.MaxValue);
                break;

            case PrimitiveTypeKind.Guid:
                this.ValidateGuidDefaultValue(scalar);
                break;

            case PrimitiveTypeKind.Single:
                this.ValidateFloatingPointDefaultValue(scalar, -3.40282346638529E+38, 3.40282346638529E+38);
                break;

            case PrimitiveTypeKind.Int16:
                this.ValidateIntegralDefaultValue(scalar, (long)short.MinValue, (long)short.MaxValue);
                break;

            case PrimitiveTypeKind.Int32:
                this.ValidateIntegralDefaultValue(scalar, (long)int.MinValue, (long)int.MaxValue);
                break;

            case PrimitiveTypeKind.Int64:
                this.ValidateIntegralDefaultValue(scalar, long.MinValue, long.MaxValue);
                break;

            case PrimitiveTypeKind.String:
                this._defaultObject = (object)this._default;
                break;

            case PrimitiveTypeKind.Time:
                this.ValidateTimeDefaultValue(scalar);
                break;

            case PrimitiveTypeKind.DateTimeOffset:
                this.ValidateDateTimeOffsetDefaultValue(scalar);
                break;

            default:
                this._element.AddError(ErrorCode.DefaultNotAllowed, EdmSchemaErrorSeverity.Error, (object)Strings.DefaultNotAllowed);
                break;
            }
        }
        private void ValidateBinaryDefaultValue(ScalarType scalar)
        {
            if (scalar.TryParse(_default, out _defaultObject))
            {
                return;
            }

            var errorMessage = Strings.InvalidDefaultBinaryWithNoMaxLength(_default);
            _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, errorMessage);
        }
        private void ValidateScalarMemberDefaultValue(ScalarType scalar)
        {
            Debug.Assert(_default != null);

            if (scalar != null)
            {
                switch (scalar.TypeKind)
                {
                    case PrimitiveTypeKind.Binary:
                        // required format 0xhexdegits, no more than 2*maxSize digits
                        ValidateBinaryDefaultValue(scalar);
                        return;
                    case PrimitiveTypeKind.Boolean:
                        // required true or false (case sensitive?)
                        ValidateBooleanDefaultValue(scalar);
                        return;
                    case PrimitiveTypeKind.Byte:
                        // integer between byte.MinValue and byteMaxValue;
                        ValidateIntegralDefaultValue(scalar, byte.MinValue, byte.MaxValue);
                        return;
                    case PrimitiveTypeKind.DateTime:
                        // valid datetime parsable using the format in _dateTimeFormat in the SqlDateTime range
                        ValidateDateTimeDefaultValue(scalar);
                        return;
                    case PrimitiveTypeKind.Time:
                        // valid time parsable using the format in _timeFormat in the SqlTime range
                        ValidateTimeDefaultValue(scalar);
                        return;
                    case PrimitiveTypeKind.DateTimeOffset:
                        // valid time parsable using the format in _datetimeoffsetFormat in the SqlDateTimeOffset range
                        ValidateDateTimeOffsetDefaultValue(scalar);
                        return;

                    case PrimitiveTypeKind.Decimal:
                        // valid decimal value (optionally with M) with scale and precision in range
                        ValidateDecimalDefaultValue(scalar);
                        return;
                    case PrimitiveTypeKind.Double:
                        // valid double constant
                        ValidateFloatingPointDefaultValue(scalar, double.MinValue, double.MaxValue);
                        return;
                    case PrimitiveTypeKind.Guid:
                        // valid string parsable by Guid.ctor
                        ValidateGuidDefaultValue(scalar);
                        return;
                    case PrimitiveTypeKind.Int16:
                        // integer between short.MinValue and short.MaxValue
                        ValidateIntegralDefaultValue(scalar, short.MinValue, short.MaxValue);
                        return;
                    case PrimitiveTypeKind.Int32:
                        // integer between int.MinValue and int.MaxValue
                        ValidateIntegralDefaultValue(scalar, int.MinValue, int.MaxValue);
                        return;
                    case PrimitiveTypeKind.Int64:
                        // integer between long.MinValue and long.MaxValue
                        ValidateIntegralDefaultValue(scalar, long.MinValue, long.MaxValue);
                        return;
                    case PrimitiveTypeKind.Single:
                        // valid single value
                        ValidateFloatingPointDefaultValue(scalar, float.MinValue, float.MaxValue);
                        return;
                    case PrimitiveTypeKind.String:
                        // the default is already a string, no parsing check necessary
                        _defaultObject = _default;
                        return;
                    default:
                        _element.AddError(ErrorCode.DefaultNotAllowed, EdmSchemaErrorSeverity.Error, Strings.DefaultNotAllowed);
                        return;
                }
            }
        }
        /// <summary>
        ///     Get a primitive type when converting a CSDL schema
        /// </summary>
        /// <param name="scalarType"> The schema type representing the primitive type </param>
        /// <param name="providerManifest"> The provider manifest for retrieving the store types </param>
        private static PrimitiveType GetPrimitiveType(
            ScalarType scalarType,
            DbProviderManifest providerManifest)
        {
            PrimitiveType returnValue = null;
            var scalarTypeName = scalarType.Name;

            foreach (var primitiveType in providerManifest.GetStoreTypes())
            {
                if (primitiveType.Name == scalarTypeName)
                {
                    returnValue = primitiveType;
                    break;
                }
            }

            Debug.Assert(scalarType != null, "Som scalar type should always resolve to a primitive type");
            return returnValue;
        }
 internal void ValidateAndSetTypeUsage(ScalarType scalar)
 {
     _typeUsageBuilder.ValidateAndSetTypeUsage(scalar, false);
 }
Example #24
0
        private void ValidateScalarMemberDefaultValue(ScalarType scalar)
        {
            Debug.Assert(_default != null);

            if (scalar != null)
            {
                switch (scalar.TypeKind)
                {
                case PrimitiveTypeKind.Binary:
                    // required format 0xhexdegits, no more than 2*maxSize digits
                    ValidateBinaryDefaultValue(scalar);
                    return;

                case PrimitiveTypeKind.Boolean:
                    // required true or false (case sensitive?)
                    ValidateBooleanDefaultValue(scalar);
                    return;

                case PrimitiveTypeKind.Byte:
                    // integer between byte.MinValue and byteMaxValue;
                    ValidateIntegralDefaultValue(scalar, byte.MinValue, byte.MaxValue);
                    return;

                case PrimitiveTypeKind.DateTime:
                    // valid datetime parsable using the format in _dateTimeFormat in the SqlDateTime range
                    ValidateDateTimeDefaultValue(scalar);
                    return;

                case PrimitiveTypeKind.Time:
                    // valid time parsable using the format in _timeFormat in the SqlTime range
                    ValidateTimeDefaultValue(scalar);
                    return;

                case PrimitiveTypeKind.DateTimeOffset:
                    // valid time parsable using the format in _datetimeoffsetFormat in the SqlDateTimeOffset range
                    ValidateDateTimeOffsetDefaultValue(scalar);
                    return;

                case PrimitiveTypeKind.Decimal:
                    // valid decimal value (optionally with M) with scale and precision in range
                    ValidateDecimalDefaultValue(scalar);
                    return;

                case PrimitiveTypeKind.Double:
                    // valid double constant
                    ValidateFloatingPointDefaultValue(scalar, double.MinValue, double.MaxValue);
                    return;

                case PrimitiveTypeKind.Guid:
                    // valid string parsable by Guid.ctor
                    ValidateGuidDefaultValue(scalar);
                    return;

                case PrimitiveTypeKind.Int16:
                    // integer between short.MinValue and short.MaxValue
                    ValidateIntegralDefaultValue(scalar, short.MinValue, short.MaxValue);
                    return;

                case PrimitiveTypeKind.Int32:
                    // integer between int.MinValue and int.MaxValue
                    ValidateIntegralDefaultValue(scalar, int.MinValue, int.MaxValue);
                    return;

                case PrimitiveTypeKind.Int64:
                    // integer between long.MinValue and long.MaxValue
                    ValidateIntegralDefaultValue(scalar, long.MinValue, long.MaxValue);
                    return;

                case PrimitiveTypeKind.Single:
                    // valid single value
                    ValidateFloatingPointDefaultValue(scalar, float.MinValue, float.MaxValue);
                    return;

                case PrimitiveTypeKind.String:
                    // the default is already a string, no parsing check necessary
                    _defaultObject = _default;
                    return;

                default:
                    _element.AddError(ErrorCode.DefaultNotAllowed, EdmSchemaErrorSeverity.Error, Strings.DefaultNotAllowed);
                    return;
                }
            }
        }
Example #25
0
        // <summary>
        // effects: adds errors to _element if there are any; creates a TypeUsage instance using the
        // facet values aggregated by this builder and the given scalar type
        // </summary>
        // <param name="scalar"> Scalar type for the type usage </param>
        internal void ValidateAndSetTypeUsage(ScalarType scalar, bool complainOnMissingFacet)
        {
            Trace.Assert(_element != null);
            Trace.Assert(scalar != null);
            Dictionary <string, Facet> calculatedFacets;

            // Forward compat FUTURE SYSTEM.SPATIAL
            // for now we treat all Geographic types the same, and likewise for geometry.
            // to allow us to later introduce the full heirarchy without breaking back compat
            // we require spatial types to have the IsStrict facet with a false value.
            // Set this facet to false if the schema has the UseStrongSpatialTypes attribute with the a false.
            if (Helper.IsSpatialType(scalar.Type) &&
                !_facetValues.ContainsKey(DbProviderManifest.IsStrictFacetName) &&
                !_element.Schema.UseStrongSpatialTypes)
            {
                _facetValues.Add(DbProviderManifest.IsStrictFacetName, false /* only possible value */);
            }

            var noErrors = TryGetFacets(scalar.Type, complainOnMissingFacet, out calculatedFacets);

            if (noErrors)
            {
                // Only validate the values if there are no errros encountered in the above functions.
                // If there are errors encountered (like for e.g. precision
                switch (scalar.TypeKind)
                {
                case PrimitiveTypeKind.Binary:
                    ValidateAndSetBinaryFacets(scalar.Type, calculatedFacets);
                    break;

                case PrimitiveTypeKind.String:
                    ValidateAndSetStringFacets(scalar.Type, calculatedFacets);
                    break;

                case PrimitiveTypeKind.Decimal:
                    ValidateAndSetDecimalFacets(scalar.Type, calculatedFacets);
                    break;

                case PrimitiveTypeKind.DateTime:
                case PrimitiveTypeKind.Time:
                case PrimitiveTypeKind.DateTimeOffset:
                    ValidatePrecisionFacetsForDateTimeFamily(scalar.Type, calculatedFacets);
                    break;

                case PrimitiveTypeKind.Int16:
                case PrimitiveTypeKind.Int32:
                case PrimitiveTypeKind.Int64:
                case PrimitiveTypeKind.Boolean:
                case PrimitiveTypeKind.Byte:
                case PrimitiveTypeKind.SByte:
                case PrimitiveTypeKind.Double:
                case PrimitiveTypeKind.Guid:
                case PrimitiveTypeKind.HierarchyId:
                case PrimitiveTypeKind.Single:
                case PrimitiveTypeKind.DbId:
                    break;

                case PrimitiveTypeKind.Geography:
                case PrimitiveTypeKind.GeographyPoint:
                case PrimitiveTypeKind.GeographyLineString:
                case PrimitiveTypeKind.GeographyPolygon:
                case PrimitiveTypeKind.GeographyMultiPoint:
                case PrimitiveTypeKind.GeographyMultiLineString:
                case PrimitiveTypeKind.GeographyMultiPolygon:
                case PrimitiveTypeKind.GeographyCollection:
                case PrimitiveTypeKind.Geometry:
                case PrimitiveTypeKind.GeometryPoint:
                case PrimitiveTypeKind.GeometryLineString:
                case PrimitiveTypeKind.GeometryPolygon:
                case PrimitiveTypeKind.GeometryMultiPoint:
                case PrimitiveTypeKind.GeometryMultiLineString:
                case PrimitiveTypeKind.GeometryMultiPolygon:
                case PrimitiveTypeKind.GeometryCollection:
                    ValidateSpatialFacets(scalar.Type, calculatedFacets);
                    break;

                default:
                    Debug.Fail("Did you miss a value");
                    break;
                }
            }

            _typeUsage = TypeUsage.Create(scalar.Type, calculatedFacets.Values);
        }
 private void ValidateGuidDefaultValue(ScalarType scalar)
 {
     if (!scalar.TryParse(_default, out _defaultObject))
     {
         _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultGuid(_default));
     }
 }
 private void ValidateFloatingPointDefaultValue(ScalarType scalar, double minValue, double maxValue)
 {
     if (!scalar.TryParse(_default, out _defaultObject))
     {
         _element.AddError(
             ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error,
             Strings.InvalidDefaultFloatingPoint(_default, minValue, maxValue));
     }
 }
        private void ValidateDecimalDefaultValue(ScalarType scalar)
        {
            if (scalar.TryParse(_default, out _defaultObject))
            {
                return;
            }

            _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultDecimal(_default, 38, 38));
        }
 internal void ValidateAndSetTypeUsage(ScalarType scalar)
 {
     _typeUsageBuilder.ValidateAndSetTypeUsage(scalar, false);
 }
 private void ValidateDateTimeOffsetDefaultValue(ScalarType scalar)
 {
     if (!scalar.TryParse(_default, out _defaultObject))
     {
         _element.AddError(
             ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultDateTimeOffset(
                 _default,
                 ScalarType.DateTimeOffsetFormat.Replace(@"\", "")));
     }
 }