public void TermSetCorrectly() { IEdmTerm term = HardCodedTestModel.GetPrimitiveAnnotationTerm(); AnnotationSegment segment = new AnnotationSegment(term); segment.Term.Should().Be(term); }
public void Term_Path_OnEntityType() { this.SetupModelsAndValues(); const string applicationCsdl = @"<Schema Namespace=""Annotations"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <Annotations Target=""foo.Person""> <Annotation Term=""bar.Int32Value"" Qualifier=""CoolnessIndex"" Path=""CoolnessIndex"" /> <Annotation Term=""bar.Int64Value"" Qualifier=""WorkPhoneLocal"" Path=""ContactInfo/WorkPhone/Local"" /> <Annotation Term=""bar.StringValue"" Qualifier=""ZipMain"" Path=""Address/Zip/Main"" /> </Annotations> </Schema>"; IEdmModel applicationModel = this.Parse(applicationCsdl, this.baseModel, this.vocabularyDefinitionModel); EdmExpressionEvaluator expressionEvaluator = new EdmExpressionEvaluator(this.operationsLookup); IEdmTerm termInt32Value = this.vocabularyDefinitionModel.FindTerm("bar.Int32Value"); IEdmValue annotationCoolnessIndex = applicationModel.GetTermValue(this.personValue, termInt32Value, expressionEvaluator); Assert.AreEqual(Int32.MaxValue, ((IEdmIntegerValue)annotationCoolnessIndex).Value, "Term annotation value"); IEdmTerm termStringValue = this.vocabularyDefinitionModel.FindTerm("bar.StringValue"); IEdmValue annotationZipMain = applicationModel.GetTermValue(this.personValue, termStringValue, expressionEvaluator); Assert.AreEqual("98052", ((IEdmStringValue)annotationZipMain).Value, "Term annotation value"); IEdmTerm termInt64Value = this.vocabularyDefinitionModel.FindTerm("bar.Int64Value"); IEdmValue annotationWorkPhoneLocal = applicationModel.GetTermValue(this.personValue, termInt64Value, expressionEvaluator); Assert.AreEqual(9991234, ((IEdmIntegerValue)annotationWorkPhoneLocal).Value, "Term annotation value"); }
/// <summary> /// Gets the boolean term value for the given <see cref="IEdmVocabularyAnnotatable"/>. /// </summary> /// <param name="model">The Edm model.</param> /// <param name="target">The Edm target.</param> /// <param name="qualifiedName">The Term qualified name.</param> /// <returns>Null or the boolean value for this annotation.</returns> public static bool?GetBoolean(this IEdmModel model, IEdmVocabularyAnnotatable target, string qualifiedName) { Utils.CheckArgumentNull(model, nameof(model)); Utils.CheckArgumentNull(target, nameof(target)); Utils.CheckArgumentNull(qualifiedName, nameof(qualifiedName)); return(GetOrAddCached(model, target, qualifiedName, () => { bool?value = null; IEdmTerm term = model.FindTerm(qualifiedName); if (term != null) { value = model.GetBoolean(target, term); if (value != null) { return value; } else { // Note: Graph has a lot of annotations applied to the type, not to the navigation source. // Here's a work around to retrieve these annotations from type if we can't find it from navigation source. // It's the same reason for belows IEdmNavigationSource navigationSource = target as IEdmNavigationSource; if (navigationSource != null) { IEdmEntityType entityType = navigationSource.EntityType(); value = model.GetBoolean(entityType, term); } } } return value; })); }
private static bool?GetBoolean(this IEdmModel model, IEdmProperty property, IEdmTerm term) { var annotation = model.FindVocabularyAnnotation(property, term); var booleanExpression = annotation?.Value as IEdmBooleanConstantExpression; return(booleanExpression?.Value); }
/// <summary> /// Create the corresponding Authorization object. /// </summary> /// <param name="record">The input record.</param> /// <returns>The created <see cref="Authorization"/> object.</returns> public static IEnumerable <Authorization> GetAuthorizations(this IEdmModel model, IEdmVocabularyAnnotatable target) { Utils.CheckArgumentNull(model, nameof(model)); Utils.CheckArgumentNull(target, nameof(target)); return(GetOrAddCached(model, target, AuthorizationConstants.Authorizations, () => { IEdmTerm term = model.FindTerm(AuthorizationConstants.Authorizations); if (term != null) { IEdmVocabularyAnnotation annotation = model.FindVocabularyAnnotations <IEdmVocabularyAnnotation>(target, term).FirstOrDefault(); if (annotation != null && annotation.Value != null && annotation.Value.ExpressionKind == EdmExpressionKind.Collection) { IEdmCollectionExpression collection = (IEdmCollectionExpression)annotation.Value; if (collection.Elements != null) { return collection.Elements.Select(e => { Debug.Assert(e.ExpressionKind == EdmExpressionKind.Record); IEdmRecordExpression recordExpression = (IEdmRecordExpression)e; Authorization auth = Authorization.CreateAuthorization(recordExpression); return auth; }); } } } return null; })); }
public void Term_Constant_OnEntityType() { this.SetupModels(); IEdmEntityType person = this.baseModel.FindEntityType("NS1.Person"); IEdmTerm termInt32Value = this.longDefinitionModel.FindTerm("bar.Int32Value"); var annotation = this.CreateAndAttachVocabularyAnnotation(person, termInt32Value, new EdmIntegerConstant(100), "onPerson"); string expectedCsdl = @"<Schema Namespace=""NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <EntityType Name=""Person""> <Key> <PropertyRef Name=""Name"" /> </Key> <Property Name=""Name"" Type=""Edm.String"" Nullable=""false"" /> <Property Name=""Birthday"" Type=""Edm.DateTimeOffset"" Nullable=""false"" /> </EntityType> <Annotations Target=""NS1.Person""> <Annotation Term=""bar.Int32Value"" Qualifier=""onPerson"" Int=""100"" /> </Annotations> </Schema>"; this.SerializeAndVerifyAgainst(this.baseModel, expectedCsdl); }
public void Term_Record_OnEntityType() { this.SetupModels(); IEdmEntityType person = this.baseModel.FindEntityType("NS1.Person"); IEdmTerm termStringValue = this.longDefinitionModel.FindTerm("bar.StringValue"); var record = new EdmRecordExpression( new EdmPropertyConstructor("p1", new EdmStringConstant("s1")), new EdmPropertyConstructor("p2", new EdmIntegerConstant(2))); this.CreateAndAttachVocabularyAnnotation(person, termStringValue, record); string expectedCsdl = @"<Schema Namespace=""NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <EntityType Name=""Person""> <Key> <PropertyRef Name=""Name"" /> </Key> <Property Name=""Name"" Type=""Edm.String"" Nullable=""false"" /> <Property Name=""Birthday"" Type=""Edm.DateTimeOffset"" Nullable=""false"" /> </EntityType> <Annotations Target=""NS1.Person""> <Annotation Term=""bar.StringValue""> <Record> <PropertyValue Property=""p1"" String=""s1"" /> <PropertyValue Property=""p2"" Int=""2"" /> </Record> </Annotation> </Annotations> </Schema>"; this.SerializeAndVerifyAgainst(this.baseModel, expectedCsdl); }
public void Term_Collection_OnEntityType() { this.SetupModels(); IEdmEntityType person = this.baseModel.FindEntityType("NS1.Person"); IEdmTerm termStringValue = this.longDefinitionModel.FindTerm("bar.StringValue"); var collection = new EdmCollectionExpression(new EdmStringConstant("s1"), new EdmLabeledExpression("xyz", new EdmIntegerConstant(2))); this.CreateAndAttachVocabularyAnnotation(person, termStringValue, collection); string expectedCsdl = @"<Schema Namespace=""NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <EntityType Name=""Person""> <Key> <PropertyRef Name=""Name"" /> </Key> <Property Name=""Name"" Type=""Edm.String"" Nullable=""false"" /> <Property Name=""Birthday"" Type=""Edm.DateTimeOffset"" Nullable=""false"" /> </EntityType> <Annotations Target=""NS1.Person""> <Annotation Term=""bar.StringValue""> <Collection> <String>s1</String> <LabeledElement Name=""xyz""> <Int>2</Int> </LabeledElement> </Collection> </Annotation> </Annotations> </Schema>"; this.SerializeAndVerifyAgainst(this.baseModel, expectedCsdl); }
/// <summary> /// Gets the string term value for the given <see cref="IEdmVocabularyAnnotatable"/>. /// </summary> /// <param name="model">The Edm model.</param> /// <param name="target">The Edm target.</param> /// <param name="qualifiedName">The Term qualified name.</param> /// <returns>Null or the string value for this annotation.</returns> public static string GetString(this IEdmModel model, IEdmVocabularyAnnotatable target, string qualifiedName) { Utils.CheckArgumentNull(model, nameof(model)); Utils.CheckArgumentNull(target, nameof(target)); Utils.CheckArgumentNull(qualifiedName, nameof(qualifiedName)); return(GetOrAddCached(model, target, qualifiedName, () => { string value = null; IEdmTerm term = model.FindTerm(qualifiedName); if (term != null) { value = model.GetString(target, term); if (value != null) { return value; } else { IEdmNavigationSource navigationSource = target as IEdmNavigationSource; if (navigationSource != null) { IEdmEntityType entityType = navigationSource.EntityType(); value = model.GetString(entityType, term); } } } return value; })); }
private static void AddOptimisticConcurrencyAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target, NavigationSourceConfiguration navigationSourceConfiguration, EdmTypeMap edmTypeMap) { EntityTypeConfiguration entityTypeConfig = navigationSourceConfiguration.EntityType; IEnumerable <StructuralPropertyConfiguration> concurrencyPropertyies = entityTypeConfig.Properties.OfType <StructuralPropertyConfiguration>().Where(property => property.ConcurrencyToken); IList <IEdmStructuralProperty> edmProperties = new List <IEdmStructuralProperty>(); foreach (StructuralPropertyConfiguration property in concurrencyPropertyies) { IEdmProperty value; if (edmTypeMap.EdmProperties.TryGetValue(property.PropertyInfo, out value)) { var item = value as IEdmStructuralProperty; if (item != null) { edmProperties.Add(item); } } } if (edmProperties.Any()) { IEdmCollectionExpression collectionExpression = new EdmCollectionExpression(edmProperties.Select(p => new EdmPropertyPathExpression(p.Name)).ToArray()); IEdmTerm term = Microsoft.OData.Edm.Vocabularies.V1.CoreVocabularyModel.ConcurrencyTerm; EdmVocabularyAnnotation annotation = new EdmVocabularyAnnotation(target, term, collectionExpression); annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline); model.SetVocabularyAnnotation(annotation); } }
public void TermSetCorrectly() { IEdmTerm term = HardCodedTestModel.GetPrimitiveAnnotationTerm(); AnnotationSegment segment = new AnnotationSegment(term); Assert.Same(term, segment.Term); }
public void Term_Constant_OnDerivedEntityType() { this.SetupModelsAndValues(); const string applicationCsdl = @"<Schema Namespace=""Annotations"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <Annotations Target=""foo.Person""> <Annotation Term=""bar.Int32Value"" Qualifier=""onPerson"" Int=""100"" /> </Annotations> <Annotations Target=""foo.Professional""> <Annotation Term=""bar.Int32Value"" Qualifier=""onProfessional"" Int=""999"" /> </Annotations> </Schema>"; IEdmModel applicationModel = this.Parse(applicationCsdl, this.baseModel, this.vocabularyDefinitionModel); EdmExpressionEvaluator expressionEvaluator = new EdmExpressionEvaluator(this.operationsLookup); IEdmTerm termInt32Value = this.vocabularyDefinitionModel.FindTerm("bar.Int32Value"); IEdmValue annotationOnPerson = applicationModel.GetTermValue(this.personValue, termInt32Value, expressionEvaluator); Assert.AreEqual(100, ((IEdmIntegerValue)annotationOnPerson).Value, "Term annotation value"); IEdmValue annotationOnProfessional = applicationModel.GetTermValue(this.professionalValue, termInt32Value, "onProfessional", expressionEvaluator); Assert.AreEqual(999, ((IEdmIntegerValue)annotationOnProfessional).Value, "Term annotation value"); }
public void Term_FunctionApplication_OnNavigationProperty() { this.SetupModelsAndValues(); const string applicationCsdl = @"<Schema Namespace=""Annotations"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <Annotations Target=""foo.Person/Address""> <Annotation Term=""bar.StringValue""> <Apply Function=""Functions.StringConcat""> <Path>Zip/Main</Path> <Apply Function=""Functions.StringConcat""> <String>-</String> <Path>Zip/Extension</Path> </Apply> </Apply> </Annotation> </Annotations> </Schema>"; IEdmModel applicationModel = this.Parse(applicationCsdl, this.baseModel, this.vocabularyDefinitionModel, this.operationsModel); EdmExpressionEvaluator expressionEvaluator = new EdmExpressionEvaluator(this.operationsLookup); IEdmEntityType person = this.baseModel.FindEntityType("foo.Person"); IEdmProperty property = person.FindProperty("Address"); IEdmPropertyValue contextPropertyValue = ((IEdmStructuredValue)this.personValue).FindPropertyValue("Address"); IEdmTerm termStringValue = this.vocabularyDefinitionModel.FindTerm("bar.StringValue"); IEdmVocabularyAnnotation annotationString = property.VocabularyAnnotations(applicationModel).SingleOrDefault(a => a.Term == termStringValue); IEdmValue annotationStringValue = expressionEvaluator.Evaluate(annotationString.Value, (IEdmStructuredValue)contextPropertyValue.Value); Assert.AreEqual("98052-0000", ((IEdmStringValue)annotationStringValue).Value, "Term annotation value"); }
public void Term_Constant_OnBaseEntityTypesWithMultipleVocabularyAnnotation() { this.SetupModelsAndValues(); const string applicationCsdl = @"<Schema Namespace=""Annotations.Application"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <Annotations Target=""foo.Person""> <Annotation Term=""bar.Int32Value"" Qualifier=""q1.q1"" Int=""100"" /> <Annotation Term=""bar.Int32Value"" Qualifier=""q2.q2"" Int=""200"" /> </Annotations> </Schema>"; IEdmModel applicationModel = this.Parse(applicationCsdl, this.baseModel, this.vocabularyDefinitionModel); EdmExpressionEvaluator expressionEvaluator = new EdmExpressionEvaluator(this.operationsLookup); IEdmTerm termInt32Value = this.vocabularyDefinitionModel.FindTerm("bar.Int32Value"); IEdmValue annotationOnPerson = applicationModel.GetTermValue(this.personValue, termInt32Value, "q1.q1", expressionEvaluator); Assert.AreEqual(100, ((IEdmIntegerValue)annotationOnPerson).Value, "Term annotation value is wrong."); annotationOnPerson = applicationModel.GetTermValue(this.personValue, termInt32Value, "q2.q2", expressionEvaluator); Assert.AreEqual(200, ((IEdmIntegerValue)annotationOnPerson).Value, "Term annotation value is wrong."); IEdmValue annotationInherited = applicationModel.GetTermValue(this.professionalValue, termInt32Value, "q1.q1", expressionEvaluator); Assert.AreEqual(100, ((IEdmIntegerValue)annotationInherited).Value, "Term annotation value is wrong."); annotationInherited = applicationModel.GetTermValue(this.professionalValue, termInt32Value, "q2.q2", expressionEvaluator); Assert.AreEqual(200, ((IEdmIntegerValue)annotationInherited).Value, "Term annotation value is wrong."); }
public void Term_TypeTerm_If_OnEntityContainer() { this.SetupModelsAndValues(); const string applicationCsdl = @"<Schema Namespace=""Annotations"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <Annotations Target=""foo.fooContainer""> <Annotation Term=""bar.Int32Value""> <If> <Apply Function=""Functions.True"" /> <Int>999</Int> <Int>30</Int> </If> </Annotation> </Annotations> </Schema>"; IEdmModel applicationModel = this.Parse(applicationCsdl, this.baseModel, this.vocabularyDefinitionModel, this.operationsModel); EdmExpressionEvaluator expressionEvaluator = new EdmExpressionEvaluator(this.operationsLookup); IEdmEntityContainer container = this.baseModel.FindEntityContainer("fooContainer"); IEdmTerm termInt32Value = this.vocabularyDefinitionModel.FindTerm("bar.Int32Value"); IEdmVocabularyAnnotation valueAnnotation = applicationModel.FindVocabularyAnnotations <IEdmVocabularyAnnotation>(container, termInt32Value).SingleOrDefault(); // ?? why do I need a context here? IEdmValue valueOfValueAnnotation = expressionEvaluator.Evaluate(valueAnnotation.Value, this.personValue); Assert.AreEqual(999, ((IEdmIntegerValue)valueOfValueAnnotation).Value, "Annotation evaluated value."); }
private static void AddComplexPropertyCommunityAlternateKey(EdmModel model, EdmEntityType entity) { // Alternate key 1 -> Code List <IEdmExpression> propertyRefs = new List <IEdmExpression>(); IEdmRecordExpression propertyRef = new EdmRecordExpression( new EdmPropertyConstructor("Alias", new EdmStringConstant("Code")), new EdmPropertyConstructor("Name", new EdmPropertyPathExpression("Code"))); propertyRefs.Add(propertyRef); EdmRecordExpression alternateKey1 = new EdmRecordExpression(new EdmPropertyConstructor("Key", new EdmCollectionExpression(propertyRefs))); // Alternate key 2 -> City & Street propertyRefs = new List <IEdmExpression>(); propertyRef = new EdmRecordExpression( new EdmPropertyConstructor("Alias", new EdmStringConstant("City")), new EdmPropertyConstructor("Name", new EdmPropertyPathExpression("Location/City"))); propertyRefs.Add(propertyRef); propertyRef = new EdmRecordExpression( new EdmPropertyConstructor("Alias", new EdmStringConstant("Street")), new EdmPropertyConstructor("Name", new EdmPropertyPathExpression("Location/Street"))); propertyRefs.Add(propertyRef); EdmRecordExpression alternateKey2 = new EdmRecordExpression(new EdmPropertyConstructor("Key", new EdmCollectionExpression(propertyRefs))); IEdmTerm coreAlternateTerm = AlternateKeysVocabularyModel.Instance.FindDeclaredTerm("OData.Community.Keys.V1.AlternateKeys"); Assert.NotNull(coreAlternateTerm); var annotation = new EdmVocabularyAnnotation(entity, coreAlternateTerm, new EdmCollectionExpression(alternateKey1, alternateKey2)); annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline); model.SetVocabularyAnnotation(annotation); }
public void Term_FunctionApplication_WithOverloads_OnEntitySet() { this.SetupModelsAndValues(); const string applicationCsdl = @"<Schema Namespace=""Annotations"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <Annotations Target=""foo.fooContainer/PersonSet""> <Annotation Term=""bar.StringValue""> <If> <Apply Function=""Functions.True"" /> <Apply Function=""Functions.StringConcat""> <String>1</String> <String>2</String> <String>3</String> </Apply> <String>foo</String> </If> </Annotation> </Annotations> </Schema>"; IEdmModel applicationModel = this.Parse(applicationCsdl, this.baseModel, this.vocabularyDefinitionModel, this.operationsModel); EdmExpressionEvaluator expressionEvaluator = new EdmExpressionEvaluator(this.operationsLookup); IEdmEntitySet personSet = this.baseModel.FindEntityContainer("fooContainer").FindEntitySet("PersonSet"); IEdmTerm term = this.vocabularyDefinitionModel.FindTerm("bar.StringValue"); IEdmVocabularyAnnotation valueAnnotation = applicationModel.FindVocabularyAnnotations <IEdmVocabularyAnnotation>(personSet, term).SingleOrDefault(); IEdmValue valueOfAnnotation = expressionEvaluator.Evaluate(valueAnnotation.Value, this.personValue); Assert.AreEqual("123", ((IEdmStringValue)valueOfAnnotation).Value, "Annotation evaluated value."); }
static AlternateKeysVocabularyModel() { Assembly assembly = typeof(AlternateKeysVocabularyModel).GetAssembly(); // Resource name has leading namespace and folder in .NetStandard dll. string[] allResources = assembly.GetManifestResourceNames(); string alternateKeysVocabularies = allResources.Where(x => x.Contains("AlternateKeysVocabularies.xml")).FirstOrDefault(); Debug.Assert(alternateKeysVocabularies != null, "AlternateKeysVocabularies.xml: not found."); using (Stream stream = assembly.GetManifestResourceStream(alternateKeysVocabularies)) { IEnumerable<EdmError> errors; Debug.Assert(stream != null, "AlternateKeysVocabularies.xml: stream!=null"); SchemaReader.TryParse(new[] { XmlReader.Create(stream) }, out Instance, out errors); } AlternateKeysTerm = Instance.FindDeclaredTerm(AlternateKeysVocabularyConstants.AlternateKeys); Debug.Assert(AlternateKeysTerm != null, "Expected Alternate Key term"); AlternateKeyType = Instance.FindDeclaredType(AlternateKeysVocabularyConstants.AlternateKeyType) as IEdmComplexType; Debug.Assert(AlternateKeyType != null, "Expected Alternate Key type"); PropertyRefType = Instance.FindDeclaredType(AlternateKeysVocabularyConstants.PropertyRefType) as IEdmComplexType; Debug.Assert(PropertyRefType != null, "Expected Alternate Key property ref type"); }
static CoreVocabularyModel() { IsInitializing = true; Assembly assembly = typeof(CoreVocabularyModel).GetAssembly(); // Resource name has leading namespace and folder in .NetStandard dll. string[] allResources = assembly.GetManifestResourceNames(); string coreVocabularies = allResources.Where(x => x.Contains("CoreVocabularies.xml")).FirstOrDefault(); Debug.Assert(coreVocabularies != null, "CoreVocabularies.xml: not found."); using (Stream stream = assembly.GetManifestResourceStream(coreVocabularies)) { IEnumerable <EdmError> errors; Debug.Assert(stream != null, "CoreVocabularies.xml: stream!=null"); SchemaReader.TryParse(new[] { XmlReader.Create(stream) }, out Instance, out errors); IsInitializing = false; } AcceptableMediaTypesTerm = Instance.FindDeclaredTerm(CoreVocabularyConstants.AcceptableMediaTypes); ComputedTerm = Instance.FindDeclaredTerm(CoreVocabularyConstants.Computed); ConcurrencyTerm = Instance.FindDeclaredTerm(CoreVocabularyConstants.OptimisticConcurrency); ConventionalIDsTerm = Instance.FindDeclaredTerm(CoreVocabularyConstants.ConventionalIDs); DereferenceableIDsTerm = Instance.FindDeclaredTerm(CoreVocabularyConstants.DereferenceableIDs); DescriptionTerm = Instance.FindDeclaredTerm(CoreVocabularyConstants.Description); ImmutableTerm = Instance.FindDeclaredTerm(CoreVocabularyConstants.Immutable); IsLanguageDependentTerm = Instance.FindDeclaredTerm(CoreVocabularyConstants.IsLanguageDependent); IsMediaTypeTerm = Instance.FindDeclaredTerm(CoreVocabularyConstants.IsMediaType); IsURLTerm = Instance.FindDeclaredTerm(CoreVocabularyConstants.IsURL); LongDescriptionTerm = Instance.FindDeclaredTerm(CoreVocabularyConstants.LongDescription); MediaTypeTerm = Instance.FindDeclaredTerm(CoreVocabularyConstants.MediaType); RequiresTypeTerm = Instance.FindDeclaredTerm(CoreVocabularyConstants.RequiresType); ResourcePathTerm = Instance.FindDeclaredTerm(CoreVocabularyConstants.ResourcePath); PermissionsTerm = Instance.FindDeclaredTerm(CoreVocabularyConstants.Permissions); }
public void Term_EntityValue_OnEntityType() { this.SetupModelsAndValues(); const string applicationCsdl = @"<Schema Namespace=""Annotations"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <Annotations Target=""foo.Person""> <Annotation Term=""bar.EntityValue""> <Record> <PropertyValue Property=""Description"" String=""the summary."" /> <PropertyValue Property=""Age"" Int=""15"" /> </Record> </Annotation> </Annotations> </Schema>"; IEdmModel applicationModel = this.Parse(applicationCsdl, this.baseModel, this.vocabularyDefinitionModel, this.operationsModel); EdmExpressionEvaluator expressionEvaluator = new EdmExpressionEvaluator(this.operationsLookup); IEdmTerm termEntityValue = this.vocabularyDefinitionModel.FindTerm("bar.EntityValue"); IEdmValue annotationEntityValue = applicationModel.GetTermValue(this.personValue, termEntityValue, expressionEvaluator); var structuredValue = (IEdmStructuredValue)annotationEntityValue; Assert.IsNotNull(structuredValue, "value should be StructuredValue."); Assert.AreEqual(2, structuredValue.PropertyValues.Count(), "StructuredValue property count."); Assert.AreEqual("Description", structuredValue.PropertyValues.ElementAt(1).Name, "StructuredValue property Name."); Assert.AreEqual("the summary.", ((IEdmStringValue)structuredValue.PropertyValues.ElementAt(1).Value).Value, "StructuredValue property Value."); var entityReference = structuredValue.Type.AsEntity(); Assert.IsNotNull(entityReference, "StructuredValue.Type should be entity"); Assert.AreSame(this.vocabularyDefinitionModel.FindType("bar.MoreTransformedPerson"), entityReference.EntityDefinition(), "StructuredValue.Type EntityDefinition"); }
public void Term_Path_OnProperty() { this.SetupModelsAndValues(); const string applicationCsdl = @"<Schema Namespace=""Annotations"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""> <Annotations Target=""foo.Person/ContactInfo""> <Annotation Term=""bar.Int16Value"" Qualifier=""WorkPhoneLocal"" Path=""WorkPhone/Local"" /> </Annotations> </Schema>"; IEdmModel applicationModel = this.Parse(applicationCsdl, this.baseModel, this.vocabularyDefinitionModel); EdmExpressionEvaluator expressionEvaluator = new EdmExpressionEvaluator(this.operationsLookup); IEdmEntityType person = this.baseModel.FindEntityType("foo.Person"); IEdmProperty property = person.FindProperty("ContactInfo"); IEdmPropertyValue contextPropertyValue = ((IEdmStructuredValue)this.personValue).FindPropertyValue("ContactInfo"); IEdmTerm termInt16Value = this.vocabularyDefinitionModel.FindTerm("bar.Int16Value"); // ?? Assumes Entity always?? // IEdmValue annotationHotIndex = applicationModel.GetTermValue(contextPropertyValue.Value, termInt16Value, evaluator); IEdmVocabularyAnnotation annotation = property.VocabularyAnnotations(applicationModel).SingleOrDefault(a => a.Term == termInt16Value); IEdmExpression expression = annotation.Value; IEdmValue annotationWorkphoneLocal = expressionEvaluator.Evaluate(expression, (IEdmStructuredValue)contextPropertyValue.Value); Assert.AreEqual(9991234, ((IEdmIntegerValue)annotationWorkphoneLocal).Value, "Term annotation value"); }
protected EdmVocabularyAnnotation(IEdmVocabularyAnnotatable target, IEdmTerm term, string qualifier) { EdmUtil.CheckArgumentNull <IEdmVocabularyAnnotatable>(target, "target"); EdmUtil.CheckArgumentNull <IEdmTerm>(term, "term"); this.target = target; this.term = term; this.qualifier = qualifier; }
protected EdmVocabularyAnnotation(IEdmVocabularyAnnotatable target, IEdmTerm term, string qualifier) { EdmUtil.CheckArgumentNull<IEdmVocabularyAnnotatable>(target, "target"); EdmUtil.CheckArgumentNull<IEdmTerm>(term, "term"); this.target = target; this.term = term; this.qualifier = qualifier; }
/// <summary> /// Removes annotation for Term /// </summary> /// <param name="term">The specified term</param> public void RemoveAnnotationsForTerm(IEdmTerm term) { var found = this.vocabularyAnnotations.OfType<IEdmVocabularyAnnotation>().Where(a => a.Term.Equals(term)).ToArray(); foreach (var a in found) { this.vocabularyAnnotations.Remove(a); } }
/// <summary> /// Initializes a new instance of <see cref="HttpRequestProvider"/> class. /// </summary> /// <param name="model">The Edm model.</param> public HttpRequestProvider(IEdmModel model) { Utils.CheckArgumentNull(model, nameof(model)); Term = model.FindTerm("Org.OData.Core.V1.HttpRequests"); Model = model; }
/// <summary> /// Initializes a new instance of <see cref="AuthorizationProvider"/> class. /// </summary> /// <param name="model">The Edm model.</param> public AuthorizationProvider(IEdmModel model) { Utils.CheckArgumentNull(model, nameof(model)); Term = model.FindTerm(AuthorizationConstants.Authorizations); Model = model; }
public string ShowAndGetResultMenu(IEdmTerm term) { int maxRetry = 3; int retry = 1; string[] types = { "xml", "json", "yaml" }; while (true) { Console.Clear(); Console.WriteLine($"\nSelect output format for \"{term.FullName()}\":\n"); for (int i = 1; i <= types.Length; i++) { Console.WriteLine($"\t[{i}]: {types[i - 1]}"); } Console.Write("\nPlease select the output index or [Q/q] for quit:"); string input = Console.ReadLine().Trim(); if (input == "q" || input == "Q") { // Exit Environment.Exit(0); } bool bOk = Int32.TryParse(input, out int index); if (bOk) { if (index >= 1 && index <= types.Length) { return(types[index - 1]); } } ConsoleColor foreColor = Console.ForegroundColor; if (retry > maxRetry) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("[Error:] Max try reach, Close now. 88"); Console.ForegroundColor = foreColor; Environment.Exit(0); } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"[Error:] Wrong input, do you want to retry {retry}/{maxRetry} [y]?"); Console.ForegroundColor = foreColor; input = Console.ReadLine(); if (input == "Y" || input == "y") { retry++; } else { Environment.Exit(0); } } }
/// <summary> /// Check whether the source term and target term are the same. /// </summary> /// <param name="sourceTerm">The source term.</param> /// <param name="targetTerm">The target term.</param> /// <returns>A value indicating whether the two terms are the same.</returns> public static bool IsSameTerm(this IEdmTerm sourceTerm, IEdmTerm targetTerm) { if (sourceTerm.Namespace == targetTerm.Namespace && sourceTerm.Name == targetTerm.Name) { return(true); } return(false); }
private string TermAsXml(IEdmTerm term) { if (term == null) { return(string.Empty); } return(this.SerializationName(term)); }
private static void SetDerivedTypeAnnotation(EdmModel model, IEdmVocabularyAnnotatable target, params string[] derivedTypes) { IEdmTerm term = ValidationVocabularyModel.DerivedTypeConstraintTerm; var collectionExpression = new EdmCollectionExpression(derivedTypes.Select(d => new EdmStringConstant(d))); EdmVocabularyAnnotation valueAnnotationOnProperty = new EdmVocabularyAnnotation(target, term, collectionExpression); valueAnnotationOnProperty.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline); model.AddVocabularyAnnotation(valueAnnotationOnProperty); }
/// <summary> /// Removes annotation for Term /// </summary> /// <param name="term">The specified term</param> public void RemoveAnnotationsForTerm(IEdmTerm term) { var found = this.vocabularyAnnotations.OfType <IEdmVocabularyAnnotation>().Where(a => a.Term.Equals(term)).ToArray(); foreach (var a in found) { this.vocabularyAnnotations.Remove(a); } }
/// <summary> /// Build a segment based on an annotation term /// </summary> /// <param name="term">The annotation term that this segment represents.</param> /// <exception cref="System.ArgumentNullException">Throws if the input annotation term is null.</exception> public AnnotationSegment(IEdmTerm term) { ExceptionUtils.CheckArgumentNotNull(term, "term"); this.term = term; this.Identifier = term.Name; this.TargetEdmType = term.Type.Definition; this.SingleResult = !term.Type.IsCollection(); }
private string GetCanonicalName(IEdmTerm t) { return t.Namespace + "." + t.Name; }
/// <summary> /// Determines whether or not the term is the url-convention term. /// </summary> /// <param name="term">The term to check.</param> /// <returns>True if the term is the url-convention term.; false otherwise.</returns> private static bool IsUrlConventionTerm(IEdmTerm term) { return term != null && (term.Name == ConventionTermName && term.Namespace == ConventionTermNamespace); }
/// <summary> /// Initializes a new instance of the <see cref="EdmValueAnnotation"/> class. /// </summary> /// <param name="target">Element the annotation applies to.</param> /// <param name="term">Term bound by the annotation.</param> /// <param name="value">Expression producing the value of the annotation.</param> public EdmValueAnnotation(IEdmVocabularyAnnotatable target, IEdmTerm term, IEdmExpression value) : this(target, term, null, value) { }
/// <summary> /// Initializes a new instance of the <see cref="EdmValueAnnotation"/> class. /// </summary> /// <param name="target">Element the annotation applies to.</param> /// <param name="term">Term bound by the annotation.</param> /// <param name="qualifier">Qualifier used to discriminate between multiple bindings of the same property or type.</param> /// <param name="value">Expression producing the value of the annotation.</param> public EdmValueAnnotation(IEdmVocabularyAnnotatable target, IEdmTerm term, string qualifier, IEdmExpression value) : base(target, term, qualifier) { EdmUtil.CheckArgumentNull(value, "value"); this.value = value; }
public EdmTypeAnnotation(IEdmVocabularyAnnotatable target, IEdmTerm term, IEdmPropertyValueBinding[] propertyValueBindings) : this(target, term, null, propertyValueBindings) { }
public EdmTypeAnnotation(IEdmVocabularyAnnotatable target, IEdmTerm term, string qualifier, IEdmPropertyValueBinding[] propertyValueBindings) : this(target, term, qualifier, (IEnumerable<IEdmPropertyValueBinding>)propertyValueBindings) { }
public EdmTypeAnnotation(IEdmVocabularyAnnotatable target, IEdmTerm term, string qualifier, IEnumerable<IEdmPropertyValueBinding> propertyValueBindings) : base(target, term, qualifier) { EdmUtil.CheckArgumentNull<IEnumerable<IEdmPropertyValueBinding>>(propertyValueBindings, "propertyValueBindings"); this.propertyValueBindings = propertyValueBindings; }
public static bool IsSameTerm(this IEdmTerm sourceTerm, IEdmTerm targetTerm) { if (sourceTerm.Namespace == targetTerm.Namespace && sourceTerm.Name == targetTerm.Name) { return true; } return false; }