private static bool SupportsOperation(this IAnnotatedItem annotatedItem, Func <SupportedOperationsAnnotation, bool> operationCheck) { var supportedOperationsAnnotation = annotatedItem.Annotations.OfType <SupportedOperationsAnnotation>().SingleOrDefault(); if (supportedOperationsAnnotation != null) { return(operationCheck(supportedOperationsAnnotation)); } return(true); }
/// <summary> /// Generates annotations for a given item. /// </summary> /// <param name="outputNamespace">The output namespace.</param> /// <param name="annotatedItem">Item with structural annotations.</param> /// <returns> /// Sequence of <see cref="XElement"/> that represent structural annotations. /// </returns> protected virtual IEnumerable <XObject> GenerateAnnotations(XNamespace outputNamespace, IAnnotatedItem annotatedItem) { var results = new List <XObject>(); foreach (Annotation annotation in annotatedItem.Annotations) { // if this annotation is handled elsewhere, skip it here if (this.IsSpecialAnnotation(annotation)) { continue; } // now this can be structural, attribute or custom var structuralAnnotation = annotation as StructuralAnnotation; if (structuralAnnotation != null) { results.Add(structuralAnnotation.Content); continue; } var attributeAnnotation = annotation as AttributeAnnotation; if (attributeAnnotation != null) { results.Add(attributeAnnotation.Content); continue; } if (this.GenerateTaupoAnnotations) { var customAnnotationSerializer = annotation as ICustomAnnotationSerializer; if (customAnnotationSerializer != null) { results.Add(customAnnotationSerializer.GetXObject()); continue; } // simple annotation without payload represent as taupo:Annotation="true" if (annotation is TagAnnotation) { results.Add(new XAttribute(EdmConstants.TaupoAnnotationsNamespace + annotation.GetType().Name, true)); continue; } // composite annotations are serailized as: // <taupo:Annotation> // <taupo:Property1>value</taupo:Property1> // <taupo:Property2>value</taupo:Property2> // ... // <taupo:PropertyN>value</taupo:PropertyN> // </taupo:Annotation> if (annotation is CompositeAnnotation) { var element = new XElement(EdmConstants.TaupoAnnotationsNamespace + annotation.GetType().Name); foreach (var prop in annotation.GetType().GetPublicProperties(true)) { object value = prop.GetValue(annotation, null); if (value != null) { element.Add(new XElement(EdmConstants.TaupoAnnotationsNamespace + prop.Name, Convert.ToString(value, CultureInfo.InvariantCulture))); } } results.Add(element); continue; } if (this.IgnoreUnsupportedAnnotations) { continue; } throw new TaupoNotSupportedException("Annotation '" + annotation.GetType().Name + "' cannot be serialized. Supported annotations must derive from: " + typeof(TagAnnotation).Name + ", " + typeof(CompositeAnnotation).Name + " or implement " + typeof(ICustomAnnotationSerializer).Name + "."); } } return(results); }
/// <summary> /// Convert annotations from Edm into Taupo /// </summary> /// <param name="edmAnnotatableItem">The edm item with Annotation</param> /// <param name="taupoAnnotatableItem">the taupo item with Annotation</param> /// <remarks>By default do nothing (because Annotation is *VERY* open). Please override in derived types to handle it properly.</remarks> protected virtual void ConvertAnnotationsIntoTaupo(IEdmElement edmAnnotatableItem, IAnnotatedItem taupoAnnotatableItem) { }
private void ApplyDataGeneratorAnnotationToStoreItem(IAnnotatedStoreItem storeItem, IAnnotatedItem modelItem) { var dataGen = modelItem.Annotations.OfType<DataGeneratorAnnotation>().Select(a => a.DataGenerator).SingleOrDefault(); if (dataGen != null) { storeItem.Annotations.Add(new StoreDataGeneratorAnnotation(dataGen)); } }
/// <summary> /// Convert annotations from Edm into Taupo /// </summary> /// <param name="edmAnnotatableItem">The edm item with Annotation</param> /// <param name="taupoAnnotatableItem">the taupo item with Annotation</param> /// <remarks>By default do nothing (because Annotation is *VERY* open). Please override in derived types to handle it properly.</remarks> protected virtual void ConvertAnnotationsIntoTaupo(IEdmElement edmAnnotatableItem, IAnnotatedItem taupoAnnotatableItem) { }
/// <summary> /// Returns a value indicating whether this item can be deleted /// </summary> /// <param name="annotatedItem">The metadata item to check delete support for </param> /// <returns>A value indicating whether this item can be deleted</returns> public static bool SupportsDelete(this IAnnotatedItem annotatedItem) { return(annotatedItem.SupportsOperation(annotation => annotation.SupportsDelete)); }
/// <summary> /// Returns a value indicating whether this item can be inserted /// </summary> /// <param name="annotatedItem">The metadata item to check insert support for </param> /// <returns>A value indicating whether this item can be inserted</returns> public static bool SupportsInsert(this IAnnotatedItem annotatedItem) { return(annotatedItem.SupportsOperation(annotation => annotation.SupportsInsert)); }
/// <summary> /// Returns a value indicating whether this item can be queried /// </summary> /// <param name="annotatedItem">The metadata item to check querying support for </param> /// <returns>A value indicating whether this item can be queried</returns> public static bool SupportsQuery(this IAnnotatedItem annotatedItem) { return(annotatedItem.SupportsOperation(annotation => annotation.SupportsQuery)); }
private void ApplyDataGeneratorAnnotationToStoreItem(IAnnotatedStoreItem storeItem, IAnnotatedItem modelItem) { var dataGen = modelItem.Annotations.OfType <DataGeneratorAnnotation>().Select(a => a.DataGenerator).SingleOrDefault(); if (dataGen != null) { storeItem.Annotations.Add(new StoreDataGeneratorAnnotation(dataGen)); } }
/// <summary> /// Generates annotations for a given item. /// </summary> /// <param name="outputNamespace">The output namespace.</param> /// <param name="annotatedItem">Item with structural annotations.</param> /// <returns> /// Sequence of <see cref="XElement"/> that represent structural annotations. /// </returns> protected virtual IEnumerable<XObject> GenerateAnnotations(XNamespace outputNamespace, IAnnotatedItem annotatedItem) { var results = new List<XObject>(); foreach (Annotation annotation in annotatedItem.Annotations) { // if this annotation is handled elsewhere, skip it here if (this.IsSpecialAnnotation(annotation)) { continue; } // now this can be structural, attribute or custom var structuralAnnotation = annotation as StructuralAnnotation; if (structuralAnnotation != null) { results.Add(structuralAnnotation.Content); continue; } var attributeAnnotation = annotation as AttributeAnnotation; if (attributeAnnotation != null) { results.Add(attributeAnnotation.Content); continue; } if (this.GenerateTaupoAnnotations) { var customAnnotationSerializer = annotation as ICustomAnnotationSerializer; if (customAnnotationSerializer != null) { results.Add(customAnnotationSerializer.GetXObject()); continue; } // simple annotation without payload represent as taupo:Annotation="true" if (annotation is TagAnnotation) { results.Add(new XAttribute(EdmConstants.TaupoAnnotationsNamespace + annotation.GetType().Name, true)); continue; } // composite annotations are serailized as: // <taupo:Annotation> // <taupo:Property1>value</taupo:Property1> // <taupo:Property2>value</taupo:Property2> // ... // <taupo:PropertyN>value</taupo:PropertyN> // </taupo:Annotation> if (annotation is CompositeAnnotation) { var element = new XElement(EdmConstants.TaupoAnnotationsNamespace + annotation.GetType().Name); foreach (var prop in annotation.GetType().GetPublicProperties(true)) { object value = prop.GetValue(annotation, null); if (value != null) { element.Add(new XElement(EdmConstants.TaupoAnnotationsNamespace + prop.Name, Convert.ToString(value, CultureInfo.InvariantCulture))); } } results.Add(element); continue; } if (this.IgnoreUnsupportedAnnotations) { continue; } throw new TaupoNotSupportedException("Annotation '" + annotation.GetType().Name + "' cannot be serialized. Supported annotations must derive from: " + typeof(TagAnnotation).Name + ", " + typeof(CompositeAnnotation).Name + " or implement " + typeof(ICustomAnnotationSerializer).Name + "."); } } return results; }