/// <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));
            }
        }
        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));
        }
Beispiel #3
0
 private bool IsElementVisible(IEdmEntityContainerElement element)
 {
     return(this.model.Configuration
            .GetHookPoints <IModelVisibilityFilter>().Reverse()
            .All(filter => filter.IsVisible(
                     this.model.Configuration,
                     this.model.Context,
                     this.model.InnerModel,
                     element)));
 }
Beispiel #4
0
        internal static string FullyQualifiedName(IEdmVocabularyAnnotatable element)
        {
            IEdmSchemaElement schemaElement = element as IEdmSchemaElement;

            if (schemaElement != null)
            {
                IEdmOperation operation = schemaElement as IEdmOperation;
                if (operation != null)
                {
                    return(ParameterizedName(operation));
                }
                else
                {
                    return(schemaElement.FullName());
                }
            }
            else
            {
                IEdmEntityContainerElement containerElement = element as IEdmEntityContainerElement;
                if (containerElement != null)
                {
                    return(containerElement.Container.FullName() + "/" + containerElement.Name);
                }
                else
                {
                    IEdmProperty property = element as IEdmProperty;
                    if (property != null)
                    {
                        IEdmSchemaType declaringSchemaType = property.DeclaringType as IEdmSchemaType;
                        if (declaringSchemaType != null)
                        {
                            string propertyOwnerName = FullyQualifiedName(declaringSchemaType);
                            if (propertyOwnerName != null)
                            {
                                return(propertyOwnerName + "/" + property.Name);
                            }
                        }
                    }
                    else
                    {
                        IEdmOperationParameter parameter = element as IEdmOperationParameter;
                        if (parameter != null)
                        {
                            string parameterOwnerName = FullyQualifiedName(parameter.DeclaringOperation);
                            if (parameterOwnerName != null)
                            {
                                return(parameterOwnerName + "/" + parameter.Name);
                            }
                        }
                    }
                }
            }

            return(null);
        }
Beispiel #5
0
 public bool IsVisible(
     DomainConfiguration configuration,
     InvocationContext context,
     IEdmModel model, IEdmEntityContainerElement element)
 {
     if (element.Name == "TestEntitySet")
     {
         return(false);
     }
     return(true);
 }
 public bool IsVisible(
     DomainConfiguration configuration,
     InvocationContext context,
     IEdmModel model, IEdmEntityContainerElement element)
 {
     if (element.Name == "TestEntitySet")
     {
         return false;
     }
     return true;
 }
Beispiel #7
0
        protected void VerifyFindEntityContainerElement(XElement sourceCsdl, IEdmModel testModel)
        {
            var csdlNamespace = EdmLibCsdlContentGenerator.GetCsdlFullNamespace(this.EdmVersion);

            Assert.AreEqual(csdlNamespace, sourceCsdl.Name.Namespace, "The source CSDL's namespace should match the target EDM version of the test cases.");

            Console.WriteLine("Test CSDL:\n\r{0}", sourceCsdl.ToString());

            var entityContainers = from element in sourceCsdl.DescendantsAndSelf(XName.Get("EntityContainer", csdlNamespace.NamespaceName))
                                   select element;

            IEnumerable <string> entityContainerElementTypes = new string[] { "EntitySet", "FunctionImport" };

            foreach (var entityContainer in entityContainers)
            {
                var entityContainerElements = from element in entityContainer.Descendants()
                                              where entityContainerElementTypes.Select(n => XName.Get(n, csdlNamespace.NamespaceName)).Any(m => m == element.Name)
                                              select element;
                var entityContainerName = entityContainer.Attribute("Name").Value;
                var entityContainerObj  = testModel.FindEntityContainer(entityContainerName) as IEdmEntityContainer;

                foreach (var entityContainerElement in entityContainerElements)
                {
                    var entityContainerElementName = entityContainerElement.Attribute("Name").Value;
                    var entitySetFound             = entityContainerObj.FindEntitySet(entityContainerElementName);
                    var functionImportsFound       = entityContainerObj.FindOperationImports(entityContainerElementName);

                    IEdmEntityContainerElement entityContainerElementFound = null;
                    var elementsWithSameName = entityContainerElements.Where(n => n.Attribute("Name").Value.Equals(entityContainerElementName)).Count();

                    if (functionImportsFound != null && functionImportsFound.Count() == elementsWithSameName)
                    {
                        entityContainerElementFound = functionImportsFound.First();
                    }
                    else if (entitySetFound != null)
                    {
                        entityContainerElementFound = entitySetFound;
                    }

                    Assert.IsNotNull(entityContainerElementFound, "FindElement failed for {0}.{1}", entityContainerName, entityContainerElementName);
                    Assert.AreEqual
                    (
                        entityContainerElementName,
                        entityContainerElementFound.Name,
                        "FindElement returned a wrong result, {0}, for {1}", entityContainerElementFound.Name, entityContainerElementName
                    );
                    Assert.IsTrue
                    (
                        entityContainerElement.Name.LocalName == "EntitySet" || entityContainerElement.Name.LocalName == "FunctionImport",
                        "FoundElement for {0} returns a wrong element kind", entityContainerName
                    );
                }
            }
        }
Beispiel #8
0
 /// <summary>
 /// Indicates if an entity container element is currently visible.
 /// </summary>
 /// <param name="configuration">
 /// A domain configuration.
 /// </param>
 /// <param name="context">
 /// An optional invocation context.
 /// </param>
 /// <param name="model">
 /// A model.
 /// </param>
 /// <param name="element">
 /// An entity container element.
 /// </param>
 /// <returns>
 /// <c>true</c> if the element is currently
 /// visible; otherwise, <c>false</c>.
 /// </returns>
 public bool IsVisible(
     DomainConfiguration configuration,
     InvocationContext context,
     IEdmModel model,
     IEdmEntityContainerElement element)
 {
     Ensure.NotNull(element);
     return(this.IsVisible(
                configuration,
                context,
                null,
                element.Name));
 }
        /// <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.FunctionImport:
                    RegistrationHelper.AddFunction((IEdmFunctionImport)element, element.Name, this.functionImportDictionary);
                    break;
                case EdmContainerElementKind.None:
                    throw new InvalidOperationException(Edm.Strings.EdmEntityContainer_CannotUseElementWithTypeNone);
                default:
                    throw new InvalidOperationException(Edm.Strings.UnknownEnumVal_ContainerElementKind(element.ContainerElementKind));
            }
        }
Beispiel #10
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));
		}
        private IEdmVocabularyAnnotatable ComputeTarget()
        {
            if (this.targetContext != null)
            {
                return(this.targetContext);
            }
            else
            {
                Debug.Assert(this.annotationsContext != null, "Annotation must either have a target context or annotations context");
                string              target              = this.annotationsContext.Annotations.Target;
                string[]            targetSegments      = target.Split('/');
                int                 targetSegmentsCount = targetSegments.Count();
                IEdmEntityContainer container;

                if (targetSegmentsCount == 1)
                {
                    string         elementName = targetSegments[0];
                    IEdmSchemaType type        = this.schema.FindType(elementName);
                    if (type != null)
                    {
                        return(type);
                    }

                    IEdmValueTerm term = this.schema.FindValueTerm(elementName);
                    if (term != null)
                    {
                        return(term);
                    }

                    IEdmOperation operation = this.FindParameterizedOperation(elementName, this.Schema.FindOperations, this.CreateAmbiguousOperation);
                    if (operation != null)
                    {
                        return(operation);
                    }

                    container = this.schema.FindEntityContainer(elementName);
                    if (container != null)
                    {
                        return(container);
                    }

                    return(new UnresolvedType(this.Schema.UnresolvedName(targetSegments[0]), this.Location));
                }

                if (targetSegmentsCount == 2)
                {
                    container = this.schema.FindEntityContainer(targetSegments[0]);
                    if (container != null)
                    {
                        IEdmEntityContainerElement containerElement = container.FindEntitySetExtended(targetSegments[1]);
                        if (containerElement != null)
                        {
                            return(containerElement);
                        }

                        IEdmOperationImport operationImport = this.FindParameterizedOperationImport(targetSegments[1], container.FindOperationImportsExtended, this.CreateAmbiguousOperationImport);
                        if (operationImport != null)
                        {
                            return(operationImport);
                        }

                        return(new UnresolvedEntitySet(targetSegments[1], container, this.Location));
                    }

                    IEdmStructuredType type = this.schema.FindType(targetSegments[0]) as IEdmStructuredType;
                    if (type != null)
                    {
                        IEdmProperty property = type.FindProperty(targetSegments[1]);
                        if (property != null)
                        {
                            return(property);
                        }

                        return(new UnresolvedProperty(type, targetSegments[1], this.Location));
                    }

                    IEdmOperation operation = this.FindParameterizedOperation(targetSegments[0], this.Schema.FindOperations, this.CreateAmbiguousOperation);
                    if (operation != null)
                    {
                        IEdmOperationParameter parameter = operation.FindParameter(targetSegments[1]);
                        if (parameter != null)
                        {
                            return(parameter);
                        }

                        return(new UnresolvedParameter(operation, targetSegments[1], this.Location));
                    }

                    return(new UnresolvedProperty(new UnresolvedEntityType(this.Schema.UnresolvedName(targetSegments[0]), this.Location), targetSegments[1], this.Location));
                }

                if (targetSegmentsCount == 3)
                {
                    // The only valid target with three segments is a function parameter.
                    string containerName = targetSegments[0];
                    string operationName = targetSegments[1];
                    string parameterName = targetSegments[2];

                    container = this.Model.FindEntityContainer(containerName);
                    if (container != null)
                    {
                        IEdmOperationImport operationImport = this.FindParameterizedOperationImport(operationName, container.FindOperationImportsExtended, this.CreateAmbiguousOperationImport);
                        if (operationImport != null)
                        {
                            IEdmOperationParameter parameter = operationImport.Operation.FindParameter(parameterName);
                            if (parameter != null)
                            {
                                return(parameter);
                            }

                            return(new UnresolvedParameter(operationImport.Operation, parameterName, this.Location));
                        }
                    }

                    string qualifiedOperationName           = containerName + "/" + operationName;
                    UnresolvedOperation unresolvedOperation = new UnresolvedOperation(qualifiedOperationName, Edm.Strings.Bad_UnresolvedOperation(qualifiedOperationName), this.Location);
                    return(new UnresolvedParameter(unresolvedOperation, parameterName, this.Location));
                }

                return(new BadElement(new EdmError[] { new EdmError(this.Location, EdmErrorCode.ImpossibleAnnotationsTarget, Edm.Strings.CsdlSemantics_ImpossibleAnnotationsTarget(target)) }));
            }
        }
Beispiel #12
0
 /// <summary>
 /// Adds an element
 /// </summary>
 /// <param name="element">The element to add</param>
 public void Add(IEdmEntityContainerElement element)
 {
     this.elements.Add(element);
 }
 /// <summary>
 /// Adds an element
 /// </summary>
 /// <param name="element">The element to add</param>
 public void Add(IEdmEntityContainerElement element)
 {
     this.elements.Add(element);
 }
Beispiel #14
0
        private IEdmVocabularyAnnotatable ComputeTarget()
        {
            if (this.targetContext != null)
            {
                return(this.targetContext);
            }
            else
            {
                Debug.Assert(this.annotationsContext != null, "Annotation must either have a target context or annotations context");
                string              target              = this.annotationsContext.Annotations.Target;
                string[]            targetSegments      = target.Split('/');
                int                 targetSegmentsCount = targetSegments.Length;
                IEdmEntityContainer container;

                if (targetSegmentsCount == 1)
                {
                    string         elementName = targetSegments[0];
                    IEdmSchemaType type        = this.schema.FindType(elementName);
                    if (type != null)
                    {
                        return(type);
                    }

                    IEdmTerm term = this.schema.FindTerm(elementName);
                    if (term != null)
                    {
                        return(term);
                    }

                    IEdmOperation operation = this.FindParameterizedOperation(elementName, this.Schema.FindOperations, this.CreateAmbiguousOperation);
                    if (operation != null)
                    {
                        return(operation);
                    }

                    container = this.schema.FindEntityContainer(elementName);
                    if (container != null)
                    {
                        return(container);
                    }

                    return(new UnresolvedType(this.Schema.UnresolvedName(targetSegments[0]), this.Location));
                }

                if (targetSegmentsCount == 2)
                {
                    container = this.schema.FindEntityContainer(targetSegments[0]);
                    if (container != null)
                    {
                        // Using the methods here results in a much faster lookup as it uses a dictionary instead of using the list of container elements.
                        IEdmEntityContainerElement containerElement = container.FindEntitySetExtended(targetSegments[1])
                                                                      ?? container.FindSingletonExtended(targetSegments[1]) as IEdmEntityContainerElement;
                        if (containerElement != null)
                        {
                            return(containerElement);
                        }

                        IEdmOperationImport operationImport = FindParameterizedOperationImport(targetSegments[1], container.FindOperationImportsExtended, this.CreateAmbiguousOperationImport);
                        if (operationImport != null)
                        {
                            return(operationImport);
                        }

                        return(new UnresolvedEntitySet(targetSegments[1], container, this.Location));
                    }

                    IEdmSchemaType type = this.schema.FindType(targetSegments[0]);
                    if (type != null)
                    {
                        IEdmStructuredType structuredType;
                        IEdmEnumType       enumType;
                        if ((structuredType = type as IEdmStructuredType) != null)
                        {
                            IEdmProperty property = structuredType.FindProperty(targetSegments[1]);
                            if (property != null)
                            {
                                return(property);
                            }

                            return(new UnresolvedProperty(structuredType, targetSegments[1], this.Location));
                        }
                        else if ((enumType = type as IEdmEnumType) != null)
                        {
                            foreach (IEdmEnumMember member in enumType.Members)
                            {
                                if (String.Equals(member.Name, targetSegments[1], StringComparison.OrdinalIgnoreCase))
                                {
                                    return(member);
                                }
                            }

                            return(new UnresolvedEnumMember(targetSegments[1], enumType, this.Location));
                        }
                    }

                    IEdmOperation operation = this.FindParameterizedOperation(targetSegments[0], this.Schema.FindOperations, this.CreateAmbiguousOperation);
                    if (operation != null)
                    {
                        // $ReturnType
                        if (targetSegments[1] == CsdlConstants.OperationReturnExternalTarget)
                        {
                            if (operation.ReturnType != null)
                            {
                                return(operation.GetReturn());
                            }

                            return(new UnresolvedReturn(operation, this.Location));
                        }

                        IEdmOperationParameter parameter = operation.FindParameter(targetSegments[1]);
                        if (parameter != null)
                        {
                            return(parameter);
                        }

                        return(new UnresolvedParameter(operation, targetSegments[1], this.Location));
                    }

                    return(new UnresolvedProperty(new UnresolvedEntityType(this.Schema.UnresolvedName(targetSegments[0]), this.Location), targetSegments[1], this.Location));
                }

                if (targetSegmentsCount == 3)
                {
                    // The only valid target with three segments is a function parameter, or an operation return.
                    string containerName = targetSegments[0];
                    string operationName = targetSegments[1];
                    string parameterName = targetSegments[2];

                    container = this.Model.FindEntityContainer(containerName);
                    if (container != null)
                    {
                        IEdmOperationImport operationImport = FindParameterizedOperationImport(operationName, container.FindOperationImportsExtended, this.CreateAmbiguousOperationImport);
                        if (operationImport != null)
                        {
                            // $ReturnType
                            if (parameterName == CsdlConstants.OperationReturnExternalTarget)
                            {
                                if (operationImport.Operation.ReturnType != null)
                                {
                                    return(operationImport.Operation.GetReturn());
                                }

                                return(new UnresolvedReturn(operationImport.Operation, this.Location));
                            }

                            IEdmOperationParameter parameter = operationImport.Operation.FindParameter(parameterName);
                            if (parameter != null)
                            {
                                return(parameter);
                            }

                            return(new UnresolvedParameter(operationImport.Operation, parameterName, this.Location));
                        }
                    }

                    string qualifiedOperationName           = containerName + "/" + operationName;
                    UnresolvedOperation unresolvedOperation = new UnresolvedOperation(qualifiedOperationName, Edm.Strings.Bad_UnresolvedOperation(qualifiedOperationName), this.Location);
                    if (parameterName == CsdlConstants.OperationReturnExternalTarget)
                    {
                        return(new UnresolvedReturn(unresolvedOperation, this.Location));
                    }
                    else
                    {
                        return(new UnresolvedParameter(unresolvedOperation, parameterName, this.Location));
                    }
                }

                return(new BadElement(new EdmError[] { new EdmError(this.Location, EdmErrorCode.ImpossibleAnnotationsTarget, Edm.Strings.CsdlSemantics_ImpossibleAnnotationsTarget(target)) }));
            }
        }
        private IEdmVocabularyAnnotatable ComputeTarget()
        {
            if (this.targetContext != null)
            {
                return(this.targetContext);
            }
            else
            {
                Debug.Assert(this.annotationsContext != null, "Annotation must either have a target context or annotations context");
                string              target              = this.annotationsContext.Annotations.Target;
                string[]            targetSegments      = target.Split('/');
                int                 targetSegmentsCount = targetSegments.Count();
                IEdmEntityContainer container;

                if (targetSegmentsCount == 1)
                {
                    string         elementName = targetSegments[0];
                    IEdmSchemaType type        = this.schema.FindType(elementName);
                    if (type != null)
                    {
                        return(type);
                    }

                    IEdmValueTerm term = this.schema.FindValueTerm(elementName);
                    if (term != null)
                    {
                        return(term);
                    }

                    IEdmFunction function = this.FindParameterizedFunction(elementName, this.Schema.FindFunctions, this.CreateAmbiguousFunction);
                    if (function != null)
                    {
                        return(function);
                    }

                    container = this.schema.FindEntityContainer(elementName);
                    if (container != null)
                    {
                        return(container);
                    }

                    return(new UnresolvedType(this.Schema.UnresolvedName(targetSegments[0]), this.Location));
                }

                if (targetSegmentsCount == 2)
                {
                    container = this.schema.FindEntityContainer(targetSegments[0]);
                    if (container != null)
                    {
                        IEdmEntityContainerElement containerElement = container.FindEntitySet(targetSegments[1]);
                        if (containerElement != null)
                        {
                            return(containerElement);
                        }

                        IEdmFunctionImport functionImport = this.FindParameterizedFunction(targetSegments[1], container.FindFunctionImports, this.CreateAmbiguousFunctionImport);
                        if (functionImport != null)
                        {
                            return(functionImport);
                        }

                        return(new UnresolvedEntitySet(targetSegments[1], container, this.Location));
                    }

                    IEdmStructuredType type = this.schema.FindType(targetSegments[0]) as IEdmStructuredType;
                    if (type != null)
                    {
                        IEdmProperty property = type.FindProperty(targetSegments[1]);
                        if (property != null)
                        {
                            return(property);
                        }

                        return(new UnresolvedProperty(type, targetSegments[1], this.Location));
                    }

                    IEdmFunction function = this.FindParameterizedFunction(targetSegments[0], this.Schema.FindFunctions, this.CreateAmbiguousFunction);
                    if (function != null)
                    {
                        IEdmFunctionParameter parameter = function.FindParameter(targetSegments[1]);
                        if (parameter != null)
                        {
                            return(parameter);
                        }

                        return(new UnresolvedParameter(function, targetSegments[1], this.Location));
                    }

                    return(new UnresolvedProperty(new UnresolvedEntityType(this.Schema.UnresolvedName(targetSegments[0]), this.Location), targetSegments[1], this.Location));
                }

                if (targetSegmentsCount == 3)
                {
                    container = this.Model.FindEntityContainer(targetSegments[0]);
                    if (container != null)
                    {
                        IEdmFunctionImport functionImport = this.FindParameterizedFunction(targetSegments[1], container.FindFunctionImports, this.CreateAmbiguousFunctionImport);
                        if (functionImport != null)
                        {
                            IEdmFunctionParameter parameter = functionImport.FindParameter(targetSegments[2]);
                            if (parameter != null)
                            {
                                return(parameter);
                            }

                            return(new UnresolvedParameter(functionImport, targetSegments[1], this.Location));
                        }
                    }
                }

                return(new BadElement(new EdmError[] { new EdmError(this.Location, EdmErrorCode.ImpossibleAnnotationsTarget, Edm.Strings.CsdlSemantics_ImpossibleAnnotationsTarget(target)) }));
            }
        }
Beispiel #16
0
        /// <summary>
        /// Gets the symbolic string of an annotated element.
        /// In the next breaking change, it's better to add a property into <see cref="IEdmVocabularyAnnotatable"/>.
        /// </summary>
        /// <param name="annotatedElement">The annotatable element.</param>
        /// <returns>null or a symbolic string.</returns>
        public static string GetSymbolicString(this IEdmVocabularyAnnotatable annotatedElement)
        {
            IEdmSchemaElement schemaElement = annotatedElement as IEdmSchemaElement;

            if (schemaElement != null)
            {
                // EntityType, ComplexType, EnumType, TypeDefinition
                if (schemaElement.SchemaElementKind == EdmSchemaElementKind.TypeDefinition)
                {
                    IEdmType edmType = (IEdmType)schemaElement;
                    switch (edmType.TypeKind)
                    {
                    case EdmTypeKind.Complex:
                        return("ComplexType");

                    case EdmTypeKind.Entity:
                        return("EntityType");

                    case EdmTypeKind.Enum:
                        return("EnumType");

                    case EdmTypeKind.TypeDefinition:
                        return("TypeDefinition");

                    default:
                        return(null);
                    }
                }
                else
                {
                    // Action, Function, Term, EntityContainer
                    return(schemaElement.SchemaElementKind.ToString());
                }
            }

            IEdmEntityContainerElement containerElement = annotatedElement as IEdmEntityContainerElement;

            if (containerElement != null)
            {
                // ActionImport, FunctionImport, EntitySet, Singleton
                return(containerElement.ContainerElementKind.ToString());
            }

            IEdmProperty property = annotatedElement as IEdmProperty;

            if (property != null)
            {
                // NavigationProperty, Property
                switch (property.PropertyKind)
                {
                case EdmPropertyKind.Navigation:
                    return("NavigationProperty");

                case EdmPropertyKind.Structural:
                    return("Property");

                default:
                    return(null);
                }
            }

            IEdmExpression expression = annotatedElement as IEdmExpression;

            if (expression != null)
            {
                switch (expression.ExpressionKind)
                {
                case EdmExpressionKind.FunctionApplication:
                    return("Apply");

                case EdmExpressionKind.IsType:
                    return("IsOf");

                case EdmExpressionKind.Labeled:
                    return("LabeledElement");

                case EdmExpressionKind.Cast:
                case EdmExpressionKind.Collection:
                case EdmExpressionKind.If:
                case EdmExpressionKind.Null:
                case EdmExpressionKind.Record:
                    return(expression.ExpressionKind.ToString());

                default:
                    return(null);
                }
            }

            if (annotatedElement is IEdmOperationParameter)
            {
                return("Parameter");
            }
            else if (annotatedElement is IEdmOperationReturn)
            {
                return("ReturnType");
            }
            else if (annotatedElement is IEdmReference)
            {
                return("Reference");
            }
            else if (annotatedElement is IEdmInclude)
            {
                return("Include");
            }
            else if (annotatedElement is IEdmReferentialConstraint)
            {
                return("ReferentialConstraint");
            }
            else if (annotatedElement is IEdmEnumMember)
            {
                return("Member");
            }
            else if (annotatedElement is IEdmVocabularyAnnotation)
            {
                return("Annotation");
            }
            else if (annotatedElement is IEdmPropertyConstructor)
            {
                return("PropertyValue");
            }

            // It's not supported "Schema, UrlRef, OnDelete"
            return(null);
        }
Beispiel #17
0
 protected virtual void ProcessEntityContainerElement(IEdmEntityContainerElement element)
 {
     this.ProcessNamedElement(element);
 }
 /// <summary>
 /// Indicates if an entity container element is currently visible.
 /// </summary>
 /// <param name="configuration">
 /// A domain configuration.
 /// </param>
 /// <param name="context">
 /// An optional invocation context.
 /// </param>
 /// <param name="model">
 /// A model.
 /// </param>
 /// <param name="element">
 /// An entity container element.
 /// </param>
 /// <returns>
 /// <c>true</c> if the element is currently
 /// visible; otherwise, <c>false</c>.
 /// </returns>
 public bool IsVisible(
     DomainConfiguration configuration,
     InvocationContext context,
     IEdmModel model,
     IEdmEntityContainerElement element)
 {
     Ensure.NotNull(element);
     return this.IsVisible(
         configuration,
         context,
         null,
         element.Name);
 }
Beispiel #19
0
        public static string FullyQualifiedName(IEdmVocabularyAnnotatable element)
        {
            IEdmSchemaElement edmSchemaElement = element as IEdmSchemaElement;

            if (edmSchemaElement == null)
            {
                IEdmEntityContainerElement edmEntityContainerElement = element as IEdmEntityContainerElement;
                if (edmEntityContainerElement == null)
                {
                    IEdmProperty edmProperty = element as IEdmProperty;
                    if (edmProperty == null)
                    {
                        IEdmFunctionParameter edmFunctionParameter = element as IEdmFunctionParameter;
                        if (edmFunctionParameter != null)
                        {
                            string str = EdmUtil.FullyQualifiedName(edmFunctionParameter.DeclaringFunction);
                            if (str != null)
                            {
                                return(string.Concat(str, "/", edmFunctionParameter.Name));
                            }
                        }
                    }
                    else
                    {
                        IEdmSchemaType declaringType = edmProperty.DeclaringType as IEdmSchemaType;
                        if (declaringType != null)
                        {
                            string str1 = EdmUtil.FullyQualifiedName(declaringType);
                            if (str1 != null)
                            {
                                return(string.Concat(str1, "/", edmProperty.Name));
                            }
                        }
                    }
                    return(null);
                }
                else
                {
                    IEdmFunctionImport edmFunctionImport = edmEntityContainerElement as IEdmFunctionImport;
                    if (edmFunctionImport == null)
                    {
                        return(string.Concat(edmEntityContainerElement.Container.FullName(), "/", edmEntityContainerElement.Name));
                    }
                    else
                    {
                        return(string.Concat(edmFunctionImport.Container.FullName(), "/", EdmUtil.ParameterizedName(edmFunctionImport)));
                    }
                }
            }
            else
            {
                IEdmFunction edmFunction = edmSchemaElement as IEdmFunction;
                if (edmFunction == null)
                {
                    return(edmSchemaElement.FullName());
                }
                else
                {
                    return(EdmUtil.ParameterizedName(edmFunction));
                }
            }
        }
Beispiel #20
0
        private IEdmVocabularyAnnotatable ComputeTarget()
        {
            IEdmEntityContainer edmEntityContainer;

            if (this.targetContext == null)
            {
                string target   = this.annotationsContext.Annotations.Target;
                char[] chrArray = new char[1];
                chrArray[0] = '/';
                string[] strArrays = target.Split(chrArray);
                int      num       = strArrays.Count <string>();
                if (num != 1)
                {
                    if (num != 2)
                    {
                        if (num == 3)
                        {
                            edmEntityContainer = this.Model.FindEntityContainer(strArrays[0]);
                            if (edmEntityContainer != null)
                            {
                                IEdmEntityContainer edmEntityContainer1 = edmEntityContainer;
                                IEdmFunctionImport  edmFunctionImport   = this.FindParameterizedFunction <IEdmFunctionImport>(strArrays[1], new Func <string, IEnumerable <IEdmFunctionImport> >(edmEntityContainer1.FindFunctionImports), new Func <IEnumerable <IEdmFunctionImport>, IEdmFunctionImport>(this.CreateAmbiguousFunctionImport));
                                if (edmFunctionImport != null)
                                {
                                    IEdmFunctionParameter edmFunctionParameter = edmFunctionImport.FindParameter(strArrays[2]);
                                    if (edmFunctionParameter == null)
                                    {
                                        return(new UnresolvedParameter(edmFunctionImport, strArrays[1], base.Location));
                                    }
                                    else
                                    {
                                        return(edmFunctionParameter);
                                    }
                                }
                            }
                        }
                        EdmError[] edmError = new EdmError[1];
                        edmError[0] = new EdmError(base.Location, EdmErrorCode.ImpossibleAnnotationsTarget, Strings.CsdlSemantics_ImpossibleAnnotationsTarget(target));
                        return(new BadElement(edmError));
                    }
                    else
                    {
                        edmEntityContainer = this.schema.FindEntityContainer(strArrays[0]);
                        if (edmEntityContainer == null)
                        {
                            IEdmStructuredType edmStructuredType = this.schema.FindType(strArrays[0]) as IEdmStructuredType;
                            if (edmStructuredType == null)
                            {
                                IEdmFunction edmFunction = this.FindParameterizedFunction <IEdmFunction>(strArrays[0], new Func <string, IEnumerable <IEdmFunction> >(this.Schema.FindFunctions), new Func <IEnumerable <IEdmFunction>, IEdmFunction>(this.CreateAmbiguousFunction));
                                if (edmFunction == null)
                                {
                                    return(new UnresolvedProperty(new UnresolvedEntityType(this.Schema.UnresolvedName(strArrays[0]), base.Location), strArrays[1], base.Location));
                                }
                                else
                                {
                                    IEdmFunctionParameter edmFunctionParameter1 = edmFunction.FindParameter(strArrays[1]);
                                    if (edmFunctionParameter1 == null)
                                    {
                                        return(new UnresolvedParameter(edmFunction, strArrays[1], base.Location));
                                    }
                                    else
                                    {
                                        return(edmFunctionParameter1);
                                    }
                                }
                            }
                            else
                            {
                                IEdmProperty edmProperty = edmStructuredType.FindProperty(strArrays[1]);
                                if (edmProperty == null)
                                {
                                    return(new UnresolvedProperty(edmStructuredType, strArrays[1], base.Location));
                                }
                                else
                                {
                                    return(edmProperty);
                                }
                            }
                        }
                        else
                        {
                            IEdmEntityContainerElement edmEntityContainerElement = edmEntityContainer.FindEntitySet(strArrays[1]);
                            if (edmEntityContainerElement == null)
                            {
                                IEdmEntityContainer edmEntityContainer2 = edmEntityContainer;
                                IEdmFunctionImport  edmFunctionImport1  = this.FindParameterizedFunction <IEdmFunctionImport>(strArrays[1], new Func <string, IEnumerable <IEdmFunctionImport> >(edmEntityContainer2.FindFunctionImports), new Func <IEnumerable <IEdmFunctionImport>, IEdmFunctionImport>(this.CreateAmbiguousFunctionImport));
                                if (edmFunctionImport1 == null)
                                {
                                    return(new UnresolvedEntitySet(strArrays[1], edmEntityContainer, base.Location));
                                }
                                else
                                {
                                    return(edmFunctionImport1);
                                }
                            }
                            else
                            {
                                return(edmEntityContainerElement);
                            }
                        }
                    }
                }
                else
                {
                    string         str           = strArrays[0];
                    IEdmSchemaType edmSchemaType = this.schema.FindType(str);
                    if (edmSchemaType == null)
                    {
                        IEdmValueTerm edmValueTerm = this.schema.FindValueTerm(str);
                        if (edmValueTerm == null)
                        {
                            IEdmFunction edmFunction1 = this.FindParameterizedFunction <IEdmFunction>(str, new Func <string, IEnumerable <IEdmFunction> >(this.Schema.FindFunctions), new Func <IEnumerable <IEdmFunction>, IEdmFunction>(this.CreateAmbiguousFunction));
                            if (edmFunction1 == null)
                            {
                                edmEntityContainer = this.schema.FindEntityContainer(str);
                                if (edmEntityContainer == null)
                                {
                                    return(new UnresolvedType(this.Schema.UnresolvedName(strArrays[0]), base.Location));
                                }
                                else
                                {
                                    return(edmEntityContainer);
                                }
                            }
                            else
                            {
                                return(edmFunction1);
                            }
                        }
                        else
                        {
                            return(edmValueTerm);
                        }
                    }
                    else
                    {
                        return(edmSchemaType);
                    }
                }
            }
            else
            {
                return(this.targetContext);
            }
        }
Beispiel #21
0
 private bool IsElementVisible(IEdmEntityContainerElement element)
 {
     return this.model.Configuration
         .GetHookPoints<IModelVisibilityFilter>().Reverse()
         .All(filter => filter.IsVisible(
             this.model.Configuration,
             this.model.Context,
             this.model.InnerModel,
             element));
 }