Exemple #1
0
        private bool TryGetFacets(
            EdmType edmType,
            bool complainOnMissingFacet,
            out Dictionary <string, Facet> calculatedFacets)
        {
            bool flag = true;
            Dictionary <string, Facet> dictionary = edmType.GetAssociatedFacetDescriptions().ToDictionary <FacetDescription, string, Facet>((Func <FacetDescription, string>)(f => f.FacetName), (Func <FacetDescription, Facet>)(f => f.DefaultValueFacet));

            calculatedFacets = new Dictionary <string, Facet>();
            foreach (Facet facet in dictionary.Values)
            {
                object obj;
                if (this._facetValues.TryGetValue(facet.Name, out obj))
                {
                    if (facet.Description.IsConstant)
                    {
                        this._element.AddError(ErrorCode.ConstantFacetSpecifiedInSchema, EdmSchemaErrorSeverity.Error, this._element, (object)Strings.ConstantFacetSpecifiedInSchema((object)facet.Name, (object)edmType.Name));
                        flag = false;
                    }
                    else
                    {
                        calculatedFacets.Add(facet.Name, Facet.Create(facet.Description, obj));
                    }
                    this._facetValues.Remove(facet.Name);
                }
                else if (complainOnMissingFacet && facet.Description.IsRequired)
                {
                    this._element.AddError(ErrorCode.RequiredFacetMissing, EdmSchemaErrorSeverity.Error, (object)Strings.RequiredFacetMissing((object)facet.Name, (object)edmType.Name));
                    flag = false;
                }
                else
                {
                    calculatedFacets.Add(facet.Name, facet);
                }
            }
            foreach (KeyValuePair <string, object> facetValue in this._facetValues)
            {
                if (facetValue.Key == "StoreGeneratedPattern")
                {
                    Facet facet = Facet.Create(Converter.StoreGeneratedPatternFacet, facetValue.Value);
                    calculatedFacets.Add(facet.Name, facet);
                }
                else if (facetValue.Key == "ConcurrencyMode")
                {
                    Facet facet = Facet.Create(Converter.ConcurrencyModeFacet, facetValue.Value);
                    calculatedFacets.Add(facet.Name, facet);
                }
                else if (edmType is PrimitiveType && ((PrimitiveType)edmType).PrimitiveTypeKind == PrimitiveTypeKind.String && facetValue.Key == "Collation")
                {
                    Facet facet = Facet.Create(Converter.CollationFacet, facetValue.Value);
                    calculatedFacets.Add(facet.Name, facet);
                }
                else
                {
                    this._element.AddError(ErrorCode.FacetNotAllowedByType, EdmSchemaErrorSeverity.Error, (object)Strings.FacetNotAllowed((object)facetValue.Key, (object)edmType.Name));
                }
            }
            return(flag);
        }
Exemple #2
0
        private bool TryGetFacets(EdmType edmType, bool complainOnMissingFacet, out Dictionary <string, Facet> calculatedFacets)
        {
            var noErrors      = true;
            var defaultFacets = edmType.GetAssociatedFacetDescriptions().ToDictionary(f => f.FacetName, f => f.DefaultValueFacet);

            calculatedFacets = new Dictionary <string, Facet>();

            foreach (var defaultFacet in defaultFacets.Values)
            {
                object value;
                if (_facetValues.TryGetValue(defaultFacet.Name, out value))
                {
                    // If the facet is a constant facet, then the facet must not be specified in the schema
                    if (defaultFacet.Description.IsConstant)
                    {
                        _element.AddError(
                            ErrorCode.ConstantFacetSpecifiedInSchema,
                            EdmSchemaErrorSeverity.Error,
                            _element,
                            Strings.ConstantFacetSpecifiedInSchema(defaultFacet.Name, edmType.Name));
                        noErrors = false;
                    }
                    else
                    {
                        calculatedFacets.Add(defaultFacet.Name, Facet.Create(defaultFacet.Description, value));
                    }

                    // remove the used facet
                    // so we know which ones we need to add below
                    _facetValues.Remove(defaultFacet.Name);
                }
                else if (complainOnMissingFacet && defaultFacet.Description.IsRequired)
                {
                    // Throw missing facet exception
                    _element.AddError(
                        ErrorCode.RequiredFacetMissing, EdmSchemaErrorSeverity.Error, Strings.RequiredFacetMissing(
                            defaultFacet.Name,
                            edmType.Name));
                    noErrors = false;
                }
                else
                {
                    calculatedFacets.Add(defaultFacet.Name, defaultFacet);
                }
            }

            foreach (var value in _facetValues)
            {
                if (value.Key
                    == EdmProviderManifest.StoreGeneratedPatternFacetName)
                {
                    var facet = Facet.Create(Converter.StoreGeneratedPatternFacet, value.Value);
                    calculatedFacets.Add(facet.Name, facet);
                }
                else if (value.Key
                         == EdmProviderManifest.ConcurrencyModeFacetName)
                {
                    var facet = Facet.Create(Converter.ConcurrencyModeFacet, value.Value);
                    calculatedFacets.Add(facet.Name, facet);
                }
                else if (edmType is PrimitiveType &&
                         ((PrimitiveType)edmType).PrimitiveTypeKind == PrimitiveTypeKind.String
                         &&
                         value.Key == DbProviderManifest.CollationFacetName)
                {
                    var facet = Facet.Create(Converter.CollationFacet, value.Value);
                    calculatedFacets.Add(facet.Name, facet);
                }
                else
                {
                    _element.AddError(
                        ErrorCode.FacetNotAllowedByType,
                        EdmSchemaErrorSeverity.Error,
                        Strings.FacetNotAllowed(value.Key, edmType.Name));
                }
            }

            return(noErrors);
        }