Ejemplo n.º 1
0
        private object GetAnnotationValue(IEdmElement element, string namespaceName, string localName, VersioningDictionary <IEdmElement, object> annotationsDictionary)
        {
            IEdmDirectValueAnnotation annotation = FindTransientAnnotation(GetTransientAnnotations(element, annotationsDictionary), namespaceName, localName);

            if (annotation != null)
            {
                return(annotation.Value);
            }

            IEnumerable <IEdmDirectValueAnnotation> immutableAnnotations = this.GetAttachedAnnotations(element);

            if (immutableAnnotations != null)
            {
                foreach (IEdmDirectValueAnnotation existingAnnotation in immutableAnnotations)
                {
                    if (existingAnnotation.NamespaceUri == namespaceName && existingAnnotation.Name == localName)
                    {
                        // No need to check that the immutable annotation isn't Dead, because if it were
                        // the tombstone would have been found in the transient annotations.
                        return(existingAnnotation.Value);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private static IEnumerable <IEdmDirectValueAnnotation> TransientAnnotations(object transientAnnotations)
        {
            if (transientAnnotations == null)
            {
                yield break;
            }

            IEdmDirectValueAnnotation singleAnnotation = transientAnnotations as IEdmDirectValueAnnotation;

            if (singleAnnotation != null)
            {
                if (singleAnnotation.Value != null)
                {
                    yield return(singleAnnotation);
                }

                yield break;
            }

            VersioningList <IEdmDirectValueAnnotation> annotationsList = (VersioningList <IEdmDirectValueAnnotation>)transientAnnotations;

            foreach (IEdmDirectValueAnnotation existingAnnotation in annotationsList)
            {
                if (existingAnnotation.Value != null)
                {
                    yield return(existingAnnotation);
                }
            }
        }
Ejemplo n.º 3
0
 private static IEnumerable <IEdmDirectValueAnnotation> TransientAnnotations(object transientAnnotations)
 {
     if (transientAnnotations != null)
     {
         IEdmDirectValueAnnotation edmDirectValueAnnotation = transientAnnotations as IEdmDirectValueAnnotation;
         if (edmDirectValueAnnotation == null)
         {
             VersioningList <IEdmDirectValueAnnotation> edmDirectValueAnnotations = (VersioningList <IEdmDirectValueAnnotation>)transientAnnotations;
             foreach (IEdmDirectValueAnnotation edmDirectValueAnnotation1 in edmDirectValueAnnotations)
             {
                 if (edmDirectValueAnnotation1.Value == null)
                 {
                     continue;
                 }
                 yield return(edmDirectValueAnnotation1);
             }
         }
         else
         {
             if (edmDirectValueAnnotation.Value != null)
             {
                 yield return(edmDirectValueAnnotation);
             }
         }
     }
 }
Ejemplo n.º 4
0
        private static bool IsEpmAnnotation(this IEdmDirectValueAnnotation annotation)
        {
            string str;
            string str2;

            return(annotation.IsEpmAnnotation(out str, out str2));
        }
Ejemplo n.º 5
0
        private object GetAnnotationValue(IEdmElement element, string namespaceName, string localName, VersioningDictionary <IEdmElement, object> annotationsDictionary)
        {
            object value;
            IEdmDirectValueAnnotation edmDirectValueAnnotation = EdmDirectValueAnnotationsManager.FindTransientAnnotation(EdmDirectValueAnnotationsManager.GetTransientAnnotations(element, annotationsDictionary), namespaceName, localName);

            if (edmDirectValueAnnotation == null)
            {
                IEnumerable <IEdmDirectValueAnnotation> attachedAnnotations = this.GetAttachedAnnotations(element);
                if (attachedAnnotations != null)
                {
                    IEnumerator <IEdmDirectValueAnnotation> enumerator = attachedAnnotations.GetEnumerator();
                    using (enumerator)
                    {
                        while (enumerator.MoveNext())
                        {
                            IEdmDirectValueAnnotation current = enumerator.Current;
                            if (!(current.NamespaceUri == namespaceName) || !(current.Name == localName))
                            {
                                continue;
                            }
                            value = current.Value;
                            return(value);
                        }
                        return(null);
                    }
                    return(value);
                }
                return(null);
            }
            else
            {
                return(edmDirectValueAnnotation.Value);
            }
        }
Ejemplo n.º 6
0
        public void AnnotableGetAnnotation_ReturnsWhatsBeenSet()
        {
            var model = new EdmModel();

            foreach (IEdmElement annotatable in this.GetEdmAnnotatables())
            {
                var qualifiedNames = this.GetInterestingQualifiedNames().ToArray();

                // set
                for (int i = 0; i < qualifiedNames.Count(); i++)
                {
                    MyQualifiedName q = qualifiedNames[i];
                    model.SetAnnotationValue(annotatable, q.NamespaceName, q.Name, q.MyFullName);

                    Assert.AreEqual(i + 1, model.DirectValueAnnotations(annotatable).Count(), "Wrong # of Annotations on {0}.", annotatable);
                }

                // get
                object result = model.GetAnnotationValue(annotatable, "_Not_Exist_", "_Not_Exist_");
                Assert.IsNull(result, "GetAnnotation() on {0}.", annotatable);

                foreach (MyQualifiedName q in qualifiedNames)
                {
                    result = model.GetAnnotationValue(annotatable, q.NamespaceName, q.Name);
                    Assert.AreEqual(q.MyFullName, result, "GetAnnotation() on {0}.", annotatable);

                    IEdmDirectValueAnnotation annotation = model.DirectValueAnnotations(annotatable).FirstOrDefault(a => a.NamespaceUri == q.NamespaceName && a.Name == q.Name);
                    Assert.IsNotNull(annotation, "GetAnnotation() on {0}.", annotatable);
                    Assert.AreEqual(q.MyFullName, ((IEdmDirectValueAnnotation)annotation).Value, "GetAnnotation() on {0}.", annotatable);
                }
            }
        }
Ejemplo n.º 7
0
            /// <summary>
            /// Retrieves an annotation value for an EDM element. Returns null if no annotation with the given name exists.
            /// </summary>
            /// <param name="element">The annotated element.</param>
            /// <param name="namespaceName">Namespace that the annotation belongs to.</param>
            /// <param name="localName">Local name of the annotation.</param>
            /// <returns>Returns the annotation that corresponds to the provided name. Returns null if no annotation with the given name exists. </returns>
            public object GetAnnotationValue(IEdmElement element, string namespaceName, string localName)
            {
                List <IEdmDirectValueAnnotation> elementAnnotations = this.FindAnnotations(element, false);
                IEdmDirectValueAnnotation        annotation         = FindAnnotation(elementAnnotations, namespaceName, localName);

                return(annotation != null ? annotation.Value : null);
            }
Ejemplo n.º 8
0
        internal void WriteAnnotationStringAttribute(IEdmDirectValueAnnotation annotation)
        {
            var edmValue = (IEdmPrimitiveValue)annotation.Value;

            if (edmValue != null)
            {
                this.xmlWriter.WriteAttributeString(annotation.Name, annotation.NamespaceUri, EdmValueWriter.PrimitiveValueAsXml(edmValue));
            }
        }
Ejemplo n.º 9
0
        internal void WriteAnnotationStringElement(IEdmDirectValueAnnotation annotation)
        {
            var edmValue = (IEdmPrimitiveValue)annotation.Value;

            if (edmValue != null)
            {
                this.xmlWriter.WriteRaw(((IEdmStringValue)edmValue).Value);
            }
        }
        private static void SetAnnotation(IEnumerable <IEdmDirectValueAnnotation> immutableAnnotations, ref VersioningList <IEdmDirectValueAnnotation> transientAnnotations, string namespaceName, string localName, object value)
        {
            bool needTombstone = false;

            if (immutableAnnotations != null)
            {
                foreach (IEdmDirectValueAnnotation existingAnnotation in immutableAnnotations)
                {
                    if (existingAnnotation.NamespaceUri == namespaceName && existingAnnotation.Name == localName)
                    {
                        needTombstone = true;
                        break;
                    }
                }
            }

            if (value == null)
            {
                // "Removing" an immutable annotation leaves behind a transient annotation with a null value
                // as a tombstone to hide the immutable annotation. The normal logic below makes this happen.
                // Removing a transient annotation actually takes the annotation away.
                if (!needTombstone)
                {
                    RemoveTransientAnnotation(ref transientAnnotations, namespaceName, localName);
                    return;
                }
            }

            IEdmDirectValueAnnotation newAnnotation = value != null ?
                                                      new EdmDirectValueAnnotation(namespaceName, localName, value) :
                                                      new EdmDirectValueAnnotation(namespaceName, localName);

            if (transientAnnotations == null)
            {
                transientAnnotations = VersioningList <IEdmDirectValueAnnotation> .Create().Add(newAnnotation);

                return;
            }

            for (int index = 0; index < transientAnnotations.Count; index++)
            {
                IEdmDirectValueAnnotation existingAnnotation = transientAnnotations[index];
                if (existingAnnotation.NamespaceUri == namespaceName && existingAnnotation.Name == localName)
                {
                    transientAnnotations = transientAnnotations.RemoveAt(index);
                    break;
                }
            }

            transientAnnotations = transientAnnotations.Add(newAnnotation);
        }
Ejemplo n.º 11
0
 private static string ConvertEdmAnnotationValue(IEdmDirectValueAnnotation annotation)
 {
     object obj2 = annotation.Value;
     if (obj2 == null)
     {
         return null;
     }
     IEdmStringValue value2 = obj2 as IEdmStringValue;
     if (value2 == null)
     {
         throw new ODataException(Microsoft.Data.OData.Strings.EpmExtensionMethods_CannotConvertEdmAnnotationValue(annotation.NamespaceUri, annotation.Name, annotation.GetType().FullName));
     }
     return value2.Value;
 }
 private static void RemoveTransientAnnotation(ref VersioningList <IEdmDirectValueAnnotation> transientAnnotations, string namespaceName, string localName)
 {
     if (transientAnnotations != null)
     {
         for (int index = 0; index < transientAnnotations.Count; index++)
         {
             IEdmDirectValueAnnotation existingAnnotation = transientAnnotations[index];
             if (existingAnnotation.NamespaceUri == namespaceName && existingAnnotation.Name == localName)
             {
                 transientAnnotations = transientAnnotations.RemoveAt(index);
                 return;
             }
         }
     }
 }
        private static IEnumerable <IEdmDirectValueAnnotation> TransientAnnotations(VersioningList <IEdmDirectValueAnnotation> transientAnnotations)
        {
            if (transientAnnotations == null)
            {
                yield break;
            }

            for (int index = 0; index < transientAnnotations.Count; index++)
            {
                IEdmDirectValueAnnotation existingAnnotation = transientAnnotations[index];
                if (existingAnnotation.Value != null)
                {
                    yield return(existingAnnotation);
                }
            }
        }
Ejemplo n.º 14
0
        private static string ConvertEdmAnnotationValue(IEdmDirectValueAnnotation annotation)
        {
            object obj2 = annotation.Value;

            if (obj2 == null)
            {
                return(null);
            }
            IEdmStringValue value2 = obj2 as IEdmStringValue;

            if (value2 == null)
            {
                throw new ODataException(Microsoft.Data.OData.Strings.EpmExtensionMethods_CannotConvertEdmAnnotationValue(annotation.NamespaceUri, annotation.Name, annotation.GetType().FullName));
            }
            return(value2.Value);
        }
Ejemplo n.º 15
0
            /// <summary>
            /// Sets an annotation value for an EDM element. If the value is null, no annotation is added and an existing annotation with the same name is removed.
            /// </summary>
            /// <param name="element">The annotated element.</param>
            /// <param name="namespaceName">Namespace that the annotation belongs to.</param>
            /// <param name="localName">Name of the annotation within the namespace.</param>
            /// <param name="value">New annotation to set.</param>
            public void SetAnnotationValue(IEdmElement element, string namespaceName, string localName, object value)
            {
                List <IEdmDirectValueAnnotation> elementAnnotations = this.FindAnnotations(element, true);

                IEdmDirectValueAnnotation annotation = FindAnnotation(elementAnnotations, namespaceName, localName);

                if (annotation != null)
                {
                    elementAnnotations.Remove(annotation);
                }

                if (value != null)
                {
                    elementAnnotations.Add(new EdmDirectValueAnnotation(namespaceName, localName, value));
                }
            }
Ejemplo n.º 16
0
        private static bool IsEpmAnnotation(this IEdmDirectValueAnnotation annotation, out string baseName, out string suffix)
        {
            string name = annotation.Name;

            for (int i = 0; i < EpmAnnotationBaseNames.Length; i++)
            {
                string str2 = EpmAnnotationBaseNames[i];
                if (name.StartsWith(str2, StringComparison.Ordinal))
                {
                    baseName = str2;
                    suffix   = name.Substring(str2.Length);
                    return(true);
                }
            }
            baseName = null;
            suffix   = null;
            return(false);
        }
        private static IEdmDirectValueAnnotation FindTransientAnnotation(VersioningList <IEdmDirectValueAnnotation> transientAnnotations, string namespaceName, string localName)
        {
            if (transientAnnotations != null)
            {
                // This method runs very hot in schemas where direct value annotations are used.
                // 1. Doing indexed 'for' loop to avoid allocation of VersioningList enumerator.
                // 2. VersioningList random access is O(1) because it uses ArrayVersioningList.
                for (int index = 0; index < transientAnnotations.Count; index++)
                {
                    IEdmDirectValueAnnotation existingAnnotation = transientAnnotations[index];
                    if (existingAnnotation.NamespaceUri == namespaceName && existingAnnotation.Name == localName)
                    {
                        return(existingAnnotation);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 18
0
 private static void RemoveTransientAnnotation(ref object transientAnnotations, string namespaceName, string localName)
 {
     if (transientAnnotations != null)
     {
         IEdmDirectValueAnnotation edmDirectValueAnnotation = transientAnnotations as IEdmDirectValueAnnotation;
         if (edmDirectValueAnnotation == null)
         {
             VersioningList <IEdmDirectValueAnnotation> edmDirectValueAnnotations = (VersioningList <IEdmDirectValueAnnotation>)transientAnnotations;
             int num = 0;
             while (num < edmDirectValueAnnotations.Count)
             {
                 IEdmDirectValueAnnotation item = edmDirectValueAnnotations[num];
                 if (!(item.NamespaceUri == namespaceName) || !(item.Name == localName))
                 {
                     num++;
                 }
                 else
                 {
                     edmDirectValueAnnotations = edmDirectValueAnnotations.RemoveAt(num);
                     if (edmDirectValueAnnotations.Count != 1)
                     {
                         transientAnnotations = edmDirectValueAnnotations;
                         return;
                     }
                     else
                     {
                         transientAnnotations = edmDirectValueAnnotations.Single <IEdmDirectValueAnnotation>();
                         return;
                     }
                 }
             }
         }
         else
         {
             if (edmDirectValueAnnotation.NamespaceUri == namespaceName && edmDirectValueAnnotation.Name == localName)
             {
                 transientAnnotations = null;
                 return;
             }
         }
     }
 }
Ejemplo n.º 19
0
        private static IEdmDirectValueAnnotation FindTransientAnnotation(object transientAnnotations, string namespaceName, string localName)
        {
            if (transientAnnotations != null)
            {
                IEdmDirectValueAnnotation singleAnnotation = transientAnnotations as IEdmDirectValueAnnotation;
                if (singleAnnotation != null)
                {
                    if (singleAnnotation.NamespaceUri == namespaceName && singleAnnotation.Name == localName)
                    {
                        return(singleAnnotation);
                    }
                }
                else
                {
                    VersioningList <IEdmDirectValueAnnotation> annotationsList = (VersioningList <IEdmDirectValueAnnotation>)transientAnnotations;
                    return(annotationsList.FirstOrDefault(
                               existingAnnotation => existingAnnotation.NamespaceUri == namespaceName && existingAnnotation.Name == localName));
                }
            }

            return(null);
        }
Ejemplo n.º 20
0
        private static void RemoveTransientAnnotation(ref object transientAnnotations, string namespaceName, string localName)
        {
            if (transientAnnotations != null)
            {
                IEdmDirectValueAnnotation singleAnnotation = transientAnnotations as IEdmDirectValueAnnotation;
                if (singleAnnotation != null)
                {
                    if (singleAnnotation.NamespaceUri == namespaceName && singleAnnotation.Name == localName)
                    {
                        transientAnnotations = null;
                        return;
                    }
                }
                else
                {
                    VersioningList <IEdmDirectValueAnnotation> annotationsList = (VersioningList <IEdmDirectValueAnnotation>)transientAnnotations;
                    for (int index = 0; index < annotationsList.Count; index++)
                    {
                        IEdmDirectValueAnnotation existingAnnotation = annotationsList[index];
                        if (existingAnnotation.NamespaceUri == namespaceName && existingAnnotation.Name == localName)
                        {
                            annotationsList = annotationsList.RemoveAt(index);
                            if (annotationsList.Count == 1)
                            {
                                transientAnnotations = annotationsList.Single();
                            }
                            else
                            {
                                transientAnnotations = annotationsList;
                            }

                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 21
0
        private static IEdmDirectValueAnnotation FindTransientAnnotation(object transientAnnotations, string namespaceName, string localName)
        {
            Func <IEdmDirectValueAnnotation, bool> func = null;

            if (transientAnnotations != null)
            {
                IEdmDirectValueAnnotation edmDirectValueAnnotation = transientAnnotations as IEdmDirectValueAnnotation;
                if (edmDirectValueAnnotation == null)
                {
                    VersioningList <IEdmDirectValueAnnotation> edmDirectValueAnnotations  = (VersioningList <IEdmDirectValueAnnotation>)transientAnnotations;
                    VersioningList <IEdmDirectValueAnnotation> edmDirectValueAnnotations1 = edmDirectValueAnnotations;
                    if (func == null)
                    {
                        func = (IEdmDirectValueAnnotation existingAnnotation) => {
                            if (existingAnnotation.NamespaceUri != namespaceName)
                            {
                                return(false);
                            }
                            else
                            {
                                return(existingAnnotation.Name == localName);
                            }
                        }
                        ;
                    }
                    return(edmDirectValueAnnotations1.FirstOrDefault <IEdmDirectValueAnnotation>(func));
                }
                else
                {
                    if (edmDirectValueAnnotation.NamespaceUri == namespaceName && edmDirectValueAnnotation.Name == localName)
                    {
                        return(edmDirectValueAnnotation);
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 22
0
 private void ProcessAttributeAnnotation(IEdmDirectValueAnnotation annotation)
 {
     this.schemaWriter.WriteAnnotationStringAttribute(annotation);
 }
Ejemplo n.º 23
0
        private static void SetAnnotation(IEnumerable <IEdmDirectValueAnnotation> immutableAnnotations, ref object transientAnnotations, string namespaceName, string localName, object value)
        {
            IEdmDirectValueAnnotation edmDirectValueAnnotation;
            Func <IEdmDirectValueAnnotation, bool> func = null;
            bool flag = false;

            if (immutableAnnotations != null)
            {
                IEnumerable <IEdmDirectValueAnnotation> edmDirectValueAnnotations = immutableAnnotations;
                if (func == null)
                {
                    func = (IEdmDirectValueAnnotation existingAnnotation) => {
                        if (existingAnnotation.NamespaceUri != namespaceName)
                        {
                            return(false);
                        }
                        else
                        {
                            return(existingAnnotation.Name == localName);
                        }
                    }
                    ;
                }
                if (edmDirectValueAnnotations.Any <IEdmDirectValueAnnotation>(func))
                {
                    flag = true;
                }
            }
            if (value != null || flag)
            {
                if (!(namespaceName == "http://schemas.microsoft.com/ado/2011/04/edm/documentation") || value == null || value as IEdmDocumentation != null)
                {
                    if (value != null)
                    {
                        edmDirectValueAnnotation = new EdmDirectValueAnnotation(namespaceName, localName, value);
                    }
                    else
                    {
                        edmDirectValueAnnotation = new EdmDirectValueAnnotation(namespaceName, localName);
                    }
                    IEdmDirectValueAnnotation edmDirectValueAnnotation1 = edmDirectValueAnnotation;
                    if (transientAnnotations != null)
                    {
                        IEdmDirectValueAnnotation edmDirectValueAnnotation2 = transientAnnotations as IEdmDirectValueAnnotation;
                        if (edmDirectValueAnnotation2 == null)
                        {
                            VersioningList <IEdmDirectValueAnnotation> edmDirectValueAnnotations1 = (VersioningList <IEdmDirectValueAnnotation>)transientAnnotations;
                            int num = 0;
                            while (num < edmDirectValueAnnotations1.Count)
                            {
                                IEdmDirectValueAnnotation item = edmDirectValueAnnotations1[num];
                                if (!(item.NamespaceUri == namespaceName) || !(item.Name == localName))
                                {
                                    num++;
                                }
                                else
                                {
                                    edmDirectValueAnnotations1 = edmDirectValueAnnotations1.RemoveAt(num);
                                    break;
                                }
                            }
                            transientAnnotations = edmDirectValueAnnotations1.Add(edmDirectValueAnnotation1);
                            return;
                        }
                        else
                        {
                            if (!(edmDirectValueAnnotation2.NamespaceUri == namespaceName) || !(edmDirectValueAnnotation2.Name == localName))
                            {
                                transientAnnotations = VersioningList <IEdmDirectValueAnnotation> .Create().Add(edmDirectValueAnnotation2).Add(edmDirectValueAnnotation1);

                                return;
                            }
                            else
                            {
                                transientAnnotations = edmDirectValueAnnotation1;
                                return;
                            }
                        }
                    }
                    else
                    {
                        transientAnnotations = edmDirectValueAnnotation1;
                        return;
                    }
                }
                else
                {
                    throw new InvalidOperationException(Strings.Annotations_DocumentationPun(value.GetType().Name));
                }
            }
            else
            {
                EdmDirectValueAnnotationsManager.RemoveTransientAnnotation(ref transientAnnotations, namespaceName, localName);
                return;
            }
        }
Ejemplo n.º 24
0
 public void VisitAnnotation(IEdmDirectValueAnnotation annotation)
 {
     this.ProcessImmediateValueAnnotation((IEdmDirectValueAnnotation)annotation);
 }
Ejemplo n.º 25
0
 protected virtual void ProcessImmediateValueAnnotation(IEdmDirectValueAnnotation annotation)
 {
     this.ProcessNamedElement(annotation);
 }
Ejemplo n.º 26
0
 private void CheckImmediateAnnotation(IEdmDirectValueAnnotation immediateAnnotation, string termName, string value)
 {
     Assert.AreEqual(termName, immediateAnnotation.Name, "Invalid immediate annotation term.");
     Assert.AreEqual(value, ((EdmStringConstant)immediateAnnotation.Value).Value, "Invalid immediate annotation value.");
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Converts the value of the <paramref name="annotation"/> to a string.
        /// </summary>
        /// <param name="annotation">The <see cref="IEdmDirectValueAnnotation"/> to convert.</param>
        /// <returns>The string representation of the converted annotation value.</returns>
        private static string ConvertEdmAnnotationValue(IEdmDirectValueAnnotation annotation)
        {
            Debug.Assert(annotation != null, "annotation != null");

            object annotationValue = annotation.Value;
            if (annotationValue == null)
            { 
                return null;
            }

            IEdmStringValue stringValue = annotationValue as IEdmStringValue;
            if (stringValue != null)
            {
                return stringValue.Value;
            }

            throw new ODataException(o.Strings.EpmExtensionMethods_CannotConvertEdmAnnotationValue(annotation.NamespaceUri, annotation.Name, annotation.GetType().FullName));
        }
Ejemplo n.º 28
0
        private static void SetAnnotation(IEnumerable <IEdmDirectValueAnnotation> immutableAnnotations, ref object transientAnnotations, string namespaceName, string localName, object value)
        {
            bool needTombstone = false;

            if (immutableAnnotations != null)
            {
                if (immutableAnnotations.Any(existingAnnotation => existingAnnotation.NamespaceUri == namespaceName && existingAnnotation.Name == localName))
                {
                    needTombstone = true;
                }
            }

            if (value == null)
            {
                // "Removing" an immutable annotation leaves behind a transient annotation with a null value
                // as a tombstone to hide the immutable annotation. The normal logic below makes this happen.
                // Removing a transient annotation actually takes the annotation away.
                if (!needTombstone)
                {
                    RemoveTransientAnnotation(ref transientAnnotations, namespaceName, localName);
                    return;
                }
            }

            if (namespaceName == EdmConstants.DocumentationUri && value != null && !(value is IEdmDocumentation))
            {
                throw new InvalidOperationException(Edm.Strings.Annotations_DocumentationPun(value.GetType().Name));
            }

            IEdmDirectValueAnnotation newAnnotation = value != null ?
                                                      new EdmDirectValueAnnotation(namespaceName, localName, value) :
                                                      new EdmDirectValueAnnotation(namespaceName, localName);

            if (transientAnnotations == null)
            {
                transientAnnotations = newAnnotation;
                return;
            }

            IEdmDirectValueAnnotation singleAnnotation = transientAnnotations as IEdmDirectValueAnnotation;

            if (singleAnnotation != null)
            {
                if (singleAnnotation.NamespaceUri == namespaceName && singleAnnotation.Name == localName)
                {
                    transientAnnotations = newAnnotation;
                }
                else
                {
                    transientAnnotations = VersioningList <IEdmDirectValueAnnotation> .Create().Add(singleAnnotation).Add(newAnnotation);
                }

                return;
            }

            VersioningList <IEdmDirectValueAnnotation> annotationsList = (VersioningList <IEdmDirectValueAnnotation>)transientAnnotations;

            for (int index = 0; index < annotationsList.Count; index++)
            {
                IEdmDirectValueAnnotation existingAnnotation = annotationsList[index];
                if (existingAnnotation.NamespaceUri == namespaceName && existingAnnotation.Name == localName)
                {
                    annotationsList = annotationsList.RemoveAt(index);
                    break;
                }
            }

            transientAnnotations = annotationsList.Add(newAnnotation);
        }
Ejemplo n.º 29
0
 private void ProcessElementAnnotation(IEdmDirectValueAnnotation annotation)
 {
     this.schemaWriter.WriteAnnotationStringElement(annotation);
 }
Ejemplo n.º 30
0
 internal abstract void WriteAnnotationStringAttribute(IEdmDirectValueAnnotation annotation);
Ejemplo n.º 31
0
 internal abstract void WriteAnnotationStringElement(IEdmDirectValueAnnotation annotation);
        /// <summary>
        /// Populates test annotation values from the serializable annotation.
        /// </summary>
        /// <param name="feedMappingAnnotation">Test annotation to populate values for.</param>
        /// <param name="serializableAnnotation">Serializable annotation to populate values from.</param>
        /// <param name="propertyName">The name of the property to create the mapping for; null for mappings on the type.</param>
        private void PopulateTestAnnotationValues(PropertyMappingAnnotation feedMappingAnnotation, IEdmDirectValueAnnotation serializableAnnotation, string propertyName)
        {
            string localName = serializableAnnotation.Name;

            ExceptionUtilities.CheckObjectNotNull(localName, "localName cannot be null");

            if (localName.Count(c => c == UnderScore) == 2)
            {
                localName = localName.Remove(localName.LastIndexOf(UnderScore));
            }

            IEdmStringValue edmStringValue = serializableAnnotation.Value as IEdmStringValue;

            ExceptionUtilities.CheckObjectNotNull(edmStringValue, "edmStringValue cannot be null");
            string value = edmStringValue.Value;

            ExceptionUtilities.CheckObjectNotNull(value, "value cannot be null");

            switch (localName)
            {
            case ODataConstants.TargetPathAttribute:
                feedMappingAnnotation.TargetPath = this.HandleTargetPath(value, feedMappingAnnotation);
                break;

            case ODataConstants.SourcePathAttribute:
                if (value == null)
                {
                    feedMappingAnnotation.SourcePath = propertyName;
                }
                else if (propertyName != null && !value.StartsWith(propertyName))
                {
                    feedMappingAnnotation.SourcePath = propertyName + "/" + value;
                }
                else
                {
                    feedMappingAnnotation.SourcePath = value;
                }

                break;

            case ODataConstants.ContentKindAttribute:
                feedMappingAnnotation.SyndicationTextContentKind = ODataExtensions.FromTextContentKindAttributeString(value);
                break;

            case ODataConstants.KeepInContentAttribute:
                feedMappingAnnotation.KeepInContent = bool.Parse(value);
                break;

            case ODataConstants.NSPrefixAttribute:
                feedMappingAnnotation.TargetNamespacePrefix = value;
                break;

            case ODataConstants.NSUriAttribute:
                feedMappingAnnotation.TargetNamespaceUri = value;
                break;

            default:
                throw new TaupoArgumentException(
                          string.Format(CultureInfo.InvariantCulture, "Attribute Name:{0} does not match one of Attribute names for Customizing feeds", localName));
            }

            // if there is no source path, use the property name
            if (feedMappingAnnotation.SourcePath == null)
            {
                feedMappingAnnotation.SourcePath = propertyName;
            }
        }
Ejemplo n.º 33
0
 private void VisitDirectAnnotation(IEdmDirectValueAnnotation directAnnotation)
 {
     // TODO:
 }