Пример #1
0
        public void AddElement(IEdmEntityContainerElement element)
        {
            EdmUtil.CheckArgumentNull <IEdmEntityContainerElement>(element, "element");
            this.containerElements.Add(element);
            EdmContainerElementKind containerElementKind = element.ContainerElementKind;

            switch (containerElementKind)
            {
            case EdmContainerElementKind.None:
            {
                throw new InvalidOperationException(Strings.EdmEntityContainer_CannotUseElementWithTypeNone);
            }

            case EdmContainerElementKind.EntitySet:
            {
                RegistrationHelper.AddElement <IEdmEntitySet>((IEdmEntitySet)element, element.Name, this.entitySetDictionary, new Func <IEdmEntitySet, IEdmEntitySet, IEdmEntitySet>(RegistrationHelper.CreateAmbiguousEntitySetBinding));
                return;
            }

            case EdmContainerElementKind.FunctionImport:
            {
                RegistrationHelper.AddFunction <IEdmFunctionImport>((IEdmFunctionImport)element, element.Name, this.functionImportDictionary);
                return;
            }
            }
            throw new InvalidOperationException(Strings.UnknownEnumVal_ContainerElementKind(element.ContainerElementKind));
        }
Пример #2
0
        /// <summary>
        /// Adds an entity container element to this entity container.
        /// </summary>
        /// <param name="element">The element to add.</param>
        public void AddElement(IEdmEntityContainerElement element)
        {
            EdmUtil.CheckArgumentNull(element, "element");

            this.containerElements.Add(element);

            switch (element.ContainerElementKind)
            {
            case EdmContainerElementKind.EntitySet:
                RegistrationHelper.AddElement((IEdmEntitySet)element, element.Name, this.entitySetDictionary, RegistrationHelper.CreateAmbiguousEntitySetBinding);
                break;

            case EdmContainerElementKind.Singleton:
                RegistrationHelper.AddElement((IEdmSingleton)element, element.Name, this.singletonDictionary, RegistrationHelper.CreateAmbiguousSingletonBinding);
                break;

            case EdmContainerElementKind.ActionImport:
            case EdmContainerElementKind.FunctionImport:
                RegistrationHelper.AddOperationImport((IEdmOperationImport)element, element.Name, this.operationImportDictionary);
                break;

            case EdmContainerElementKind.None:
                throw new InvalidOperationException(Edm.Strings.EdmEntityContainer_CannotUseElementWithTypeNone);

            default:
                throw new InvalidOperationException(Edm.Strings.UnknownEnumVal_ContainerElementKind(element.ContainerElementKind));
            }
        }
        private Dictionary <string, IEdmEntitySet> ComputeEntitySetDictionary()
        {
            Dictionary <string, IEdmEntitySet> strs = new Dictionary <string, IEdmEntitySet>();

            foreach (IEdmEntitySet edmEntitySet in this.Elements.OfType <IEdmEntitySet>())
            {
                RegistrationHelper.AddElement <IEdmEntitySet>(edmEntitySet, edmEntitySet.Name, strs, new Func <IEdmEntitySet, IEdmEntitySet, IEdmEntitySet>(RegistrationHelper.CreateAmbiguousEntitySetBinding));
            }
            return(strs);
        }
        private Dictionary <string, IEdmSingleton> ComputeSingletonDictionary()
        {
            Dictionary <string, IEdmSingleton> sets = new Dictionary <string, IEdmSingleton>();

            foreach (IEdmSingleton singleton in this.Elements.OfType <IEdmSingleton>())
            {
                RegistrationHelper.AddElement(singleton, singleton.Name, sets, RegistrationHelper.CreateAmbiguousSingletonBinding);
            }

            return(sets);
        }
        private Dictionary <string, IEdmEntitySet> ComputeEntitySetDictionary()
        {
            Dictionary <string, IEdmEntitySet> sets = new Dictionary <string, IEdmEntitySet>();

            foreach (IEdmEntitySet entitySet in this.Elements.OfType <IEdmEntitySet>())
            {
                RegistrationHelper.AddElement(entitySet, entitySet.Name, sets, RegistrationHelper.CreateAmbiguousEntitySetBinding);
            }

            return(sets);
        }
Пример #6
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);
            }
        }
Пример #7
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);
            }
        }