private void ValidateFloatingPointDefaultValue(ScalarType scalar, double minValue, double maxValue)
 {
     if (!scalar.TryParse(_default, out _defaultObject))
     {
         _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidDefaultFloatingPoint(_default, minValue, maxValue));
     }
 }
 private void ValidateIntegralDefaultValue(ScalarType scalar, long minValue, long maxValue)
 {
     if (!scalar.TryParse(_default, out _defaultObject))
     {
         _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidDefaultIntegral(_default, minValue, maxValue));
     }
 }
 private void ValidateGuidDefaultValue(ScalarType scalar)
 {
     if (!scalar.TryParse(_default, out _defaultObject))
     {
         _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidDefaultGuid(_default));
     }
 }
 private void ValidateDateTimeOffsetDefaultValue(ScalarType scalar)
 {
     if (!scalar.TryParse(_default, out _defaultObject))
     {
         _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultDateTimeOffset(_default,
                                                                                                                        ScalarType.DateTimeOffsetFormat.Replace(@"\", "")));
     }
 }
        private void ValidateDecimalDefaultValue(ScalarType scalar)
        {
            if (scalar.TryParse(_default, out _defaultObject))
            {
                return;
            }

            _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidDefaultDecimal(_default, 38, 38));
        }
        private void ValidateBinaryDefaultValue(ScalarType scalar)
        {
            if (scalar.TryParse(_default, out _defaultObject))
            {
                return;
            }

            string errorMessage = Strings.InvalidDefaultBinaryWithNoMaxLength(_default);

            _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, errorMessage);
        }
        internal void ValidateDefaultValue(SchemaType type)
        {
            if (null == _default)
            {
                return;
            }
            ScalarType scalar = type as ScalarType;

            if (null != scalar)
            {
                ValidateScalarMemberDefaultValue(scalar);
            }
            else
            {
                _element.AddError(ErrorCode.DefaultNotAllowed, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.DefaultNotAllowed);
            }
        }
        /// <summary>
        ///
        /// </summary>
        internal override void ResolveTopLevelNames()
        {
            base.ResolveTopLevelNames();

            if (_type != null)
            {
                return;
            }

            _type = ResolveType(UnresolvedType);

            _typeUsageBuilder.ValidateDefaultValue(_type);

            ScalarType scalar = _type as ScalarType;

            if (scalar != null)
            {
                _typeUsageBuilder.ValidateAndSetTypeUsage(scalar, true);
            }
        }
Beispiel #9
0
 internal void ValidateAndSetTypeUsage(ScalarType scalar)
 {
     _typeUsageBuilder.ValidateAndSetTypeUsage(scalar, false);
 }
 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 ValidateGuidDefaultValue(ScalarType scalar)
 {
     if (!scalar.TryParse(_default, out _defaultObject))
     {
         _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultGuid(_default));
     }
 }
 private void ValidateDateTimeOffsetDefaultValue(ScalarType scalar)
 {
     if (!scalar.TryParse(_default, out _defaultObject))
     {
         _element.AddError(
             ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultDateTimeOffset(
                 _default,
                 ScalarType.DateTimeOffsetFormat.Replace(@"\", "")));
     }
 }
        private void ValidateDecimalDefaultValue(ScalarType scalar)
        {
            if (scalar.TryParse(_default, out _defaultObject))
            {
                return;
            }

            _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, Strings.InvalidDefaultDecimal(_default, 38, 38));
        }
        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 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);
        }
        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;
                }
            }
        }
 internal void ValidateAndSetTypeUsage(ScalarType scalar)
 {
     _typeUsageBuilder.ValidateAndSetTypeUsage(scalar, false);
 }
Beispiel #19
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)
        {
            System.Diagnostics.Trace.Assert(_element != null);
            System.Diagnostics.Trace.Assert(scalar != null);
            Dictionary<string, Facet> calculatedFacets;

            // Forward compat 




            if (Helper.IsSpatialType(scalar.Type) 
                && !_facetValues.ContainsKey(EdmProviderManifest.IsStrictFacetName)
                && !this._element.Schema.UseStrongSpatialTypes)
            {
                    this._facetValues.Add(EdmProviderManifest.IsStrictFacetName, false /* only possible value */);
            }

            bool 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);
        }
Beispiel #20
0
 private void ValidateBooleanDefaultValue(ScalarType scalar)
 {
     if (!scalar.TryParse(_default, out _defaultObject))
         _element.AddError(ErrorCode.InvalidDefault, EdmSchemaErrorSeverity.Error, System.Data.Entity.Strings.InvalidDefaultBoolean(_default));
 }
        /// <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)
        {
            System.Diagnostics.Trace.Assert(_element != null);
            System.Diagnostics.Trace.Assert(scalar != null);
            Dictionary <string, Facet> calculatedFacets;

            // Forward compat



            if (Helper.IsSpatialType(scalar.Type) &&
                !_facetValues.ContainsKey(EdmProviderManifest.IsStrictFacetName) &&
                !this._element.Schema.UseStrongSpatialTypes)
            {
                this._facetValues.Add(EdmProviderManifest.IsStrictFacetName, false /* only possible value */);
            }

            bool 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);
        }
        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, System.Data.Entity.Strings.DefaultNotAllowed);
                    return;
                }
            }
        }