예제 #1
0
        /// <summary>
        /// Adds out-of-line annotations from the specified schema
        /// if they are referenced in the <paramref name="includeAnnotationsIndex"/> cache.
        /// </summary>
        /// <param name="schema">The schema to add annotations from.</param>
        /// <param name="schemaWrapper">The <see cref="CsdlSemanticsSchema"/> wrapper for the provided schema</param>
        /// <param name="includeAnnotationsIndex">Cache of the schema's out-of-line <see cref="IEdmIncludeAnnotations"/>s indexed by the term namespace.
        /// If this dictionary is non-empty, then only annotations that match
        /// the references will be added. If it's empty, no annotations will be added. If it's null, all annotations
        /// will be added unconditionally.</param>
        private void AddOutOfLineAnnotationsFromSchema(
            CsdlSchema schema,
            CsdlSemanticsSchema schemaWrapper,
            Dictionary <string, List <CsdlIncludeAnnotations> > includeAnnotationsIndex)
        {
            if (includeAnnotationsIndex != null && includeAnnotationsIndex.Count == 0)
            {
                return;
            }

            foreach (CsdlAnnotations schemaOutOfLineAnnotations in schema.OutOfLineAnnotations)
            {
                string target = this.ReplaceAlias(schemaOutOfLineAnnotations.Target);

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

                CsdlAnnotations filteredAnnotations = FilterIncludedAnnotations(schemaOutOfLineAnnotations, target, includeAnnotationsIndex);
                annotations.Add(new CsdlSemanticsAnnotations(schemaWrapper, filteredAnnotations));
            }
        }
예제 #2
0
        /// <summary>
        /// Filters the annotations of the specified <paramref name="csdlAnnotations"/>
        /// and returns a copy containing only the annotations that match the
        /// specified <see cref="IEdmIncludeAnnotations"/>
        /// </summary>
        /// <param name="csdlAnnotations"><see cref="CsdlAnnotations"/> containing the out-of-line annotations to filter</param>
        /// <param name="target">The target of the out-of-line annotations with the alias namespace already resolved.</param>
        /// <param name="includeAnnotationsIndex">Cache of the schema's out-of-line <see cref="IEdmIncludeAnnotations"/>s indexed by the term namespace.
        /// If the dictionary is non-null, only annotations that match the references will be included.
        /// If it's null, all annotations will be added unconditionally.</param>
        /// <returns>A <see cref="CsdlAnnotations"/> object with the same target and qualifier as the original, but including
        /// only the annotations that match the references in the <paramref name="includeAnnotationsIndex"/>.</returns>
        private CsdlAnnotations FilterIncludedAnnotations(
            CsdlAnnotations csdlAnnotations,
            string target,
            Dictionary <string, List <CsdlIncludeAnnotations> > includeAnnotationsIndex)
        {
            if (includeAnnotationsIndex == null)
            {
                return(csdlAnnotations);
            }

            var filteredAnnotations = csdlAnnotations.Annotations.Where(annotation =>
                                                                        ShouldIncludeAnnotation(annotation, target, includeAnnotationsIndex));

            return(new CsdlAnnotations(filteredAnnotations, csdlAnnotations.Target, csdlAnnotations.Qualifier));
        }
 public CsdlSemanticsAnnotations(CsdlSemanticsSchema context, CsdlAnnotations annotations)
 {
     this.context     = context;
     this.annotations = annotations;
 }
예제 #4
0
        internal static CsdlSchema Schema(
            string namespaceName,
            string alias    = null,
            Version version = null,
            CsdlStructuredType[] csdlStructuredTypes = default(CsdlStructuredType[]),
            CsdlEnumType[] csdlEnumTypes             = default(CsdlEnumType[]),
            CsdlOperation[] csdlOperations           = default(CsdlOperation[]),
            CsdlTerm[] csdlTerms = default(CsdlTerm[]),
            CsdlEntityContainer[] csdlEntityContainers = default(CsdlEntityContainer[]),
            CsdlAnnotations[] csdlAnnotations          = default(CsdlAnnotations[]),
            CsdlTypeDefinition[] csdlTypeDefinitions   = default(CsdlTypeDefinition[]),
            CsdlLocation location = null)
        {
            if (csdlStructuredTypes == null)
            {
                csdlStructuredTypes = new CsdlStructuredType[] { };
            }

            if (csdlEnumTypes == null)
            {
                csdlEnumTypes = new CsdlEnumType[] { };
            }

            if (csdlOperations == null)
            {
                csdlOperations = new CsdlOperation[] { };
            }

            if (csdlTerms == null)
            {
                csdlTerms = new CsdlTerm[] { };
            }

            if (csdlEntityContainers == null)
            {
                csdlEntityContainers = new CsdlEntityContainer[] { };
            }

            if (csdlAnnotations == null)
            {
                csdlAnnotations = new CsdlAnnotations[] { };
            }

            if (csdlTypeDefinitions == null)
            {
                csdlTypeDefinitions = new CsdlTypeDefinition[] { };
            }

            var csdlSchema = new CsdlSchema(
                namespaceName,
                alias,
                version,
                csdlStructuredTypes,
                csdlEnumTypes,
                csdlOperations,
                csdlTerms,
                csdlEntityContainers,
                csdlAnnotations,
                csdlTypeDefinitions,
                location /*location*/);

            return(csdlSchema);
        }
예제 #5
0
        public void ParseCsdlOutOfLineAnnotationWithMembersWorksAsExpected()
        {
            string json = @"""$Annotations"": {
   ""self.Person"": {
       ""@Core.Description#Tablet"": ""Dummy"",
       ""@UI.DisplayName#MyTablet"": {
           ""$Path"": ""FirstName""
       }
   },
   ""self.MyEntityType"": {
      ""@self.Dummy"": true,
      ""@UI.Threshold#Example73"": {
         ""$Type"": ""Edm.Decimal"",
         ""$Cast"": {
           ""$Path"": ""Average""
           }
      }
   }
}";

            IList <CsdlAnnotations> annotations = ParseCsdlSchemaElement(json, SchemaJsonParser.ParseCsdlOutOfLineAnnotations);

            Assert.NotNull(annotations);
            Assert.Equal(2, annotations.Count);

            // #1
            CsdlAnnotations csdlAnnotations = annotations.First(c => c.Target == "self.Person");

            Assert.Null(csdlAnnotations.Qualifier);
            Assert.Equal(2, csdlAnnotations.Annotations.Count());

            // #1.1
            CsdlAnnotation csdlAnnotation = csdlAnnotations.Annotations.First(c => c.Term == "Core.Description");

            Assert.Equal("Tablet", csdlAnnotation.Qualifier);
            CsdlConstantExpression constExp = Assert.IsType <CsdlConstantExpression>(csdlAnnotation.Expression);

            Assert.Equal("Dummy", constExp.Value);
            Assert.Equal(EdmValueKind.String, constExp.ValueKind);

            // #1.2
            csdlAnnotation = csdlAnnotations.Annotations.First(c => c.Term == "UI.DisplayName");
            Assert.Equal("MyTablet", csdlAnnotation.Qualifier);
            CsdlPathExpression pathExp = Assert.IsType <CsdlPathExpression>(csdlAnnotation.Expression);

            Assert.Equal("FirstName", pathExp.Path);

            // #2
            csdlAnnotations = annotations.First(c => c.Target == "self.MyEntityType");
            Assert.Null(csdlAnnotations.Qualifier);
            Assert.Equal(2, csdlAnnotations.Annotations.Count());

            // #2.1
            csdlAnnotation = csdlAnnotations.Annotations.First(c => c.Term == "self.Dummy");
            Assert.Null(csdlAnnotation.Qualifier);
            constExp = Assert.IsType <CsdlConstantExpression>(csdlAnnotation.Expression);
            Assert.Equal("true", constExp.Value);
            Assert.Equal(EdmValueKind.Boolean, constExp.ValueKind);

            // #2.2
            csdlAnnotation = csdlAnnotations.Annotations.First(c => c.Term == "UI.Threshold");
            Assert.Equal("Example73", csdlAnnotation.Qualifier);
            CsdlCastExpression castExp = Assert.IsType <CsdlCastExpression>(csdlAnnotation.Expression);

            Assert.IsType <CsdlDecimalTypeReference>(castExp.Type);

            pathExp = Assert.IsType <CsdlPathExpression>(castExp.Operand);
            Assert.Equal("Average", pathExp.Path);
        }