コード例 #1
0
        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);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
 /// <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)
 {
 }
コード例 #4
0
 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));
     }
 }
コード例 #5
0
 /// <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)
 {
 }
コード例 #6
0
 /// <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));
 }
コード例 #7
0
 /// <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));
 }
コード例 #8
0
 /// <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));
 }
コード例 #9
0
        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));
            }
        }
コード例 #10
0
        /// <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;
        }