Пример #1
0
 public UnresolvedFunction(string qualifiedName, string errorMessage, EdmLocation location)
     : base(new EdmError[] { new EdmError(location, EdmErrorCode.BadUnresolvedFunction, errorMessage) })
 {
     qualifiedName = qualifiedName ?? string.Empty;
     EdmUtil.TryGetNamespaceNameFromQualifiedName(qualifiedName, out this.namespaceName, out this.name);
     this.returnType = new BadTypeReference(new BadType(this.Errors), true);
 }
Пример #2
0
 public BadPrimitiveType(string qualifiedName, EdmPrimitiveTypeKind primitiveKind, IEnumerable <EdmError> errors)
     : base(errors)
 {
     this.primitiveKind = primitiveKind;
     qualifiedName      = qualifiedName ?? string.Empty;
     EdmUtil.TryGetNamespaceNameFromQualifiedName(qualifiedName, out this.namespaceName, out this.name);
 }
Пример #3
0
        public BadAssociation(string qualifiedName, IEnumerable <EdmError> errors) : base(errors)
        {
            string str   = qualifiedName;
            string empty = str;

            if (str == null)
            {
                empty = string.Empty;
            }
            qualifiedName = empty;
            EdmUtil.TryGetNamespaceNameFromQualifiedName(qualifiedName, out this.namespaceName, out this.name);
        }
Пример #4
0
        protected UnresolvedVocabularyTerm(string qualifiedName)
        {
            string str   = qualifiedName;
            string empty = str;

            if (str == null)
            {
                empty = string.Empty;
            }
            qualifiedName = empty;
            EdmUtil.TryGetNamespaceNameFromQualifiedName(qualifiedName, out this.namespaceName, out this.name);
        }
Пример #5
0
        protected BadNamedStructuredType(string qualifiedName, IEnumerable <EdmError> errors) : base(errors)
        {
            string str   = qualifiedName;
            string empty = str;

            if (str == null)
            {
                empty = string.Empty;
            }
            qualifiedName = empty;
            EdmUtil.TryGetNamespaceNameFromQualifiedName(qualifiedName, out this.namespaceName, out this.name);
        }
Пример #6
0
        public BadPrimitiveType(string qualifiedName, EdmPrimitiveTypeKind primitiveKind, IEnumerable <EdmError> errors) : base(errors)
        {
            this.primitiveKind = primitiveKind;
            string str   = qualifiedName;
            string empty = str;

            if (str == null)
            {
                empty = string.Empty;
            }
            qualifiedName = empty;
            EdmUtil.TryGetNamespaceNameFromQualifiedName(qualifiedName, out this.namespaceName, out this.name);
        }
Пример #7
0
        public UnresolvedType(string qualifiedName, EdmLocation location)
            : base(new EdmError[] { new EdmError(location, EdmErrorCode.BadUnresolvedType, Strings.Bad_UnresolvedType(qualifiedName)) })
        {
            string str   = qualifiedName;
            string empty = str;

            if (str == null)
            {
                empty = string.Empty;
            }
            qualifiedName = empty;
            EdmUtil.TryGetNamespaceNameFromQualifiedName(qualifiedName, out this.namespaceName, out this.name);
        }
Пример #8
0
        /// <summary>
        /// Registers schema elements (entity types, operations, entity containers, etc.) from the
        /// specified schema into the model.
        /// </summary>
        /// <param name="schemaWrapper">The <see cref="CsdlSemanticsSchema"/> to add elements from</param>
        private void AddSchemaElements(CsdlSemanticsSchema schemaWrapper)
        {
            foreach (IEdmSchemaType type in schemaWrapper.Types)
            {
                CsdlSemanticsStructuredTypeDefinition structuredType = type as CsdlSemanticsStructuredTypeDefinition;
                if (structuredType != null)
                {
                    string baseTypeName;
                    string baseTypeFullName = ((CsdlNamedStructuredType)structuredType.Element).BaseTypeName;
                    if (baseTypeFullName != null)
                    {
                        EdmUtil.TryGetNamespaceNameFromQualifiedName(baseTypeFullName, out _, out baseTypeName);
                        if (baseTypeName != null)
                        {
                            List <IEdmStructuredType> derivedTypes;
                            if (!this.derivedTypeMappings.TryGetValue(baseTypeName, out derivedTypes))
                            {
                                derivedTypes = new List <IEdmStructuredType>();
                                this.derivedTypeMappings[baseTypeName] = derivedTypes;
                            }

                            // TODO: REF referenced derived types
                            derivedTypes.Add(structuredType);
                        }
                    }
                }

                RegisterElement(type);
            }

            foreach (IEdmOperation function in schemaWrapper.Operations)
            {
                RegisterElement(function);
            }

            foreach (IEdmTerm valueTerm in schemaWrapper.Terms)
            {
                RegisterElement(valueTerm);
            }

            foreach (IEdmEntityContainer container in schemaWrapper.EntityContainers)
            {
                RegisterElement(container);
            }
        }
Пример #9
0
        /// <summary>
        /// Checks whether the specified annoation should be included in the model based
        /// on whether it matches any of the provided <see cref="IEdmIncludeAnnotations"/> references.
        /// </summary>
        /// <param name="annotation">The annotation to test</param>
        /// <param name="target">The target of the annotation, with the alias already resolved if any</param>
        /// <param name="includeAnnotationsIndex">Cache of the schema's out-of-line <see cref="IEdmIncludeAnnotations"/>s indexed by the term namespace.
        /// The annotation should be included if it matches at least one of references in this cache.</param>
        /// <returns>Whether or not the annotation should be included in the model.</returns>
        private bool ShouldIncludeAnnotation(
            CsdlAnnotation annotation,
            string target,
            Dictionary <string, List <CsdlIncludeAnnotations> > includeAnnotationsIndex)
        {
            // include annotation if it matches one of the edmx:IncludeAnnotation references
            // we check if the namespace matches, and (if applicable) also the target namespace and the qualifier
            // see: http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_IncludedAnnotations

            string qualifiedTerm = this.ReplaceAlias(annotation.Term);

            EdmUtil.TryGetNamespaceNameFromQualifiedName(target, out string targetNamespace, out _);
            if (EdmUtil.TryGetNamespaceNameFromQualifiedName(qualifiedTerm, out string termNamespace, out _))
            {
                if (includeAnnotationsIndex.TryGetValue(termNamespace, out List <CsdlIncludeAnnotations> includeAnnotations))
                {
                    return(includeAnnotations.Any(include =>
                                                  (string.IsNullOrEmpty(include.Qualifier) || annotation.Qualifier == include.Qualifier) &&
                                                  (string.IsNullOrEmpty(include.TargetNamespace) || targetNamespace == include.TargetNamespace)));
                }
            }

            return(false);
        }
Пример #10
0
 public UnresolvedVocabularyTerm(string qualifiedName)
 {
     qualifiedName = qualifiedName ?? string.Empty;
     EdmUtil.TryGetNamespaceNameFromQualifiedName(qualifiedName, out this.namespaceName, out this.name);
 }
Пример #11
0
 public BadTypeDefinition(string qualifiedName, IEnumerable <EdmError> errors)
     : base(errors)
 {
     qualifiedName = qualifiedName ?? string.Empty;
     EdmUtil.TryGetNamespaceNameFromQualifiedName(qualifiedName, out this.namespaceName, out this.name);
 }
Пример #12
0
        private void AddSchema(CsdlSchema schema)
        {
            CsdlSemanticsSchema schemaWrapper = new CsdlSemanticsSchema(this, schema);

            this.schemata.Add(schemaWrapper);

            foreach (IEdmSchemaType type in schemaWrapper.Types)
            {
                CsdlSemanticsStructuredTypeDefinition structuredType = type as CsdlSemanticsStructuredTypeDefinition;
                if (structuredType != null)
                {
                    string baseTypeNamespace;
                    string baseTypeName;
                    string baseTypeFullName = ((CsdlNamedStructuredType)structuredType.Element).BaseTypeName;
                    if (baseTypeFullName != null)
                    {
                        EdmUtil.TryGetNamespaceNameFromQualifiedName(baseTypeFullName, out baseTypeNamespace, out baseTypeName);
                        if (baseTypeName != null)
                        {
                            List <IEdmStructuredType> derivedTypes;
                            if (!this.derivedTypeMappings.TryGetValue(baseTypeName, out derivedTypes))
                            {
                                derivedTypes = new List <IEdmStructuredType>();
                                this.derivedTypeMappings[baseTypeName] = derivedTypes;
                            }

                            derivedTypes.Add(structuredType);
                        }
                    }
                }

                RegisterElement(type);
            }

            foreach (CsdlSemanticsAssociation association in schemaWrapper.Associations)
            {
                RegistrationHelper.AddElement(association, association.Namespace + "." + association.Name, this.associationDictionary, CreateAmbiguousAssociationBinding);
            }

            foreach (IEdmFunction function in schemaWrapper.Functions)
            {
                RegisterElement(function);
            }

            foreach (IEdmValueTerm valueTerm in schemaWrapper.ValueTerms)
            {
                RegisterElement(valueTerm);
            }

            foreach (IEdmEntityContainer container in schemaWrapper.EntityContainers)
            {
                RegisterElement(container);
            }

            foreach (CsdlAnnotations schemaOutOfLineAnnotations in schema.OutOfLineAnnotations)
            {
                string target   = schemaOutOfLineAnnotations.Target;
                string replaced = schemaWrapper.ReplaceAlias(target);
                if (replaced != null)
                {
                    target = replaced;
                }

                List <CsdlSemanticsAnnotations> annotations;
                if (!this.outOfLineAnnotations.TryGetValue(target, out annotations))
                {
                    annotations = new List <CsdlSemanticsAnnotations>();
                    this.outOfLineAnnotations[target] = annotations;
                }

                annotations.Add(new CsdlSemanticsAnnotations(schemaWrapper, schemaOutOfLineAnnotations));
            }

            foreach (CsdlUsing used in schema.Usings)
            {
                this.SetNamespaceAlias(used.Namespace, used.Alias);
            }

            var edmVersion = this.GetEdmVersion();

            if (edmVersion == null || edmVersion < schema.Version)
            {
                this.SetEdmVersion(schema.Version);
            }
        }
Пример #13
0
 protected BadNamedStructuredType(string qualifiedName, IEnumerable <EdmError> errors)
     : base(errors)
 {
     qualifiedName = qualifiedName ?? string.Empty;
     EdmUtil.TryGetNamespaceNameFromQualifiedName(qualifiedName, out this.namespaceName, out this.name);
 }
Пример #14
0
        private void AddSchema(CsdlSchema schema)
        {
            CsdlSemanticsSchema item = new CsdlSemanticsSchema(this, schema);

            this.schemata.Add(item);
            foreach (IEdmSchemaType type in item.Types)
            {
                CsdlSemanticsStructuredTypeDefinition definition = type as CsdlSemanticsStructuredTypeDefinition;
                if (definition != null)
                {
                    string baseTypeName = ((CsdlNamedStructuredType)definition.Element).BaseTypeName;
                    if (baseTypeName != null)
                    {
                        string str;
                        string str2;
                        EdmUtil.TryGetNamespaceNameFromQualifiedName(baseTypeName, out str, out str2);
                        if (str2 != null)
                        {
                            List <IEdmStructuredType> list;
                            if (!this.derivedTypeMappings.TryGetValue(str2, out list))
                            {
                                list = new List <IEdmStructuredType>();
                                this.derivedTypeMappings[str2] = list;
                            }
                            list.Add(definition);
                        }
                    }
                }
                base.RegisterElement(type);
            }
            foreach (CsdlSemanticsAssociation association in item.Associations)
            {
                RegistrationHelper.AddElement <IEdmAssociation>(association, association.Namespace + "." + association.Name, this.associationDictionary, new Func <IEdmAssociation, IEdmAssociation, IEdmAssociation>(CsdlSemanticsModel.CreateAmbiguousAssociationBinding));
            }
            foreach (IEdmFunction function in item.Functions)
            {
                base.RegisterElement(function);
            }
            foreach (IEdmValueTerm term in item.ValueTerms)
            {
                base.RegisterElement(term);
            }
            foreach (IEdmEntityContainer container in item.EntityContainers)
            {
                base.RegisterElement(container);
            }
            foreach (CsdlAnnotations annotations in schema.OutOfLineAnnotations)
            {
                List <CsdlSemanticsAnnotations> list2;
                string target = annotations.Target;
                string str5   = item.ReplaceAlias(target);
                if (str5 != null)
                {
                    target = str5;
                }
                if (!this.outOfLineAnnotations.TryGetValue(target, out list2))
                {
                    list2 = new List <CsdlSemanticsAnnotations>();
                    this.outOfLineAnnotations[target] = list2;
                }
                list2.Add(new CsdlSemanticsAnnotations(item, annotations));
            }
            foreach (CsdlUsing @using in schema.Usings)
            {
                this.SetNamespaceAlias(@using.Namespace, @using.Alias);
            }
            Version edmVersion = this.GetEdmVersion();

            if ((edmVersion == null) || (edmVersion < schema.Version))
            {
                this.SetEdmVersion(schema.Version);
            }
        }
Пример #15
0
 public UnresolvedType(string qualifiedName, EdmLocation location)
     : base(new EdmError[] { new EdmError(location, EdmErrorCode.BadUnresolvedType, Edm.Strings.Bad_UnresolvedType(qualifiedName)) })
 {
     qualifiedName = qualifiedName ?? string.Empty;
     EdmUtil.TryGetNamespaceNameFromQualifiedName(qualifiedName, out this.namespaceName, out this.name);
 }
Пример #16
0
 public BadEntityContainer(string qualifiedName, IEnumerable <EdmError> errors)
     : base(errors)
 {
     qualifiedName = qualifiedName ?? string.Empty;
     EdmUtil.TryGetNamespaceNameFromQualifiedName(qualifiedName, out this.namespaceName, out this.name);
 }
Пример #17
0
        private void AddSchema(CsdlSchema schema, bool addAnnotations)
        {
            CsdlSemanticsSchema schemaWrapper = new CsdlSemanticsSchema(this, schema);

            this.schemata.Add(schemaWrapper);
            foreach (IEdmSchemaType type in schemaWrapper.Types)
            {
                CsdlSemanticsStructuredTypeDefinition structuredType = type as CsdlSemanticsStructuredTypeDefinition;
                if (structuredType != null)
                {
                    string baseTypeNamespace;
                    string baseTypeName;
                    string baseTypeFullName = ((CsdlNamedStructuredType)structuredType.Element).BaseTypeName;
                    if (baseTypeFullName != null)
                    {
                        EdmUtil.TryGetNamespaceNameFromQualifiedName(baseTypeFullName, out baseTypeNamespace, out baseTypeName);
                        if (baseTypeName != null)
                        {
                            List <IEdmStructuredType> derivedTypes;
                            if (!this.derivedTypeMappings.TryGetValue(baseTypeName, out derivedTypes))
                            {
                                derivedTypes = new List <IEdmStructuredType>();
                                this.derivedTypeMappings[baseTypeName] = derivedTypes;
                            }

                            // TODO: REF referenced derived types
                            derivedTypes.Add(structuredType);
                        }
                    }
                }

                RegisterElement(type);
            }

            foreach (IEdmOperation function in schemaWrapper.Operations)
            {
                RegisterElement(function);
            }

            foreach (IEdmTerm valueTerm in schemaWrapper.Terms)
            {
                RegisterElement(valueTerm);
            }

            foreach (IEdmEntityContainer container in schemaWrapper.EntityContainers)
            {
                RegisterElement(container);
            }

            if (!string.IsNullOrEmpty(schema.Alias))
            {
                this.SetNamespaceAlias(schema.Namespace, schema.Alias);
            }

            if (addAnnotations)
            {
                foreach (CsdlAnnotations schemaOutOfLineAnnotations in schema.OutOfLineAnnotations)
                {
                    string target   = schemaOutOfLineAnnotations.Target;
                    string replaced = this.ReplaceAlias(target);
                    if (replaced != null)
                    {
                        target = replaced;
                    }

                    List <CsdlSemanticsAnnotations> annotations;
                    if (!this.outOfLineAnnotations.TryGetValue(target, out annotations))
                    {
                        annotations = new List <CsdlSemanticsAnnotations>();
                        this.outOfLineAnnotations[target] = annotations;
                    }

                    annotations.Add(new CsdlSemanticsAnnotations(schemaWrapper, schemaOutOfLineAnnotations));
                }
            }

            var edmVersion = this.GetEdmVersion();

            if (edmVersion == null || edmVersion < schema.Version)
            {
                this.SetEdmVersion(schema.Version);
            }
        }