Пример #1
0
		internal static bool AddMemberNameToHashSet(IEdmNamedElement item, HashSetInternal<string> memberNameList, ValidationContext context, EdmErrorCode errorCode, string errorString, bool suppressError)
		{
			string name;
			IEdmSchemaElement edmSchemaElement = item as IEdmSchemaElement;
			if (edmSchemaElement != null)
			{
				name = edmSchemaElement.FullName();
			}
			else
			{
				name = item.Name;
			}
			string str = name;
			if (memberNameList.Add(str))
			{
				return true;
			}
			else
			{
				if (!suppressError)
				{
					context.AddError(item.Location(), errorCode, errorString);
				}
				return false;
			}
		}
Пример #2
0
        internal static bool AddMemberNameToHashSet(IEdmNamedElement item, HashSetInternal <string> memberNameList, ValidationContext context, EdmErrorCode errorCode, string errorString, bool suppressError)
        {
            string            name;
            IEdmSchemaElement edmSchemaElement = item as IEdmSchemaElement;

            if (edmSchemaElement != null)
            {
                name = edmSchemaElement.FullName();
            }
            else
            {
                name = item.Name;
            }
            string str = name;

            if (memberNameList.Add(str))
            {
                return(true);
            }
            else
            {
                if (!suppressError)
                {
                    context.AddError(item.Location(), errorCode, errorString);
                }
                return(false);
            }
        }
Пример #3
0
        private static string GetPropertyNameForEdmModel(MemberInfo currentProperty, IEdmNamedElement edmProperty)
        {
            Contract.Requires(currentProperty != null);
            Contract.Requires(edmProperty != null);

            return(TypeHelper.GetPropertyName(currentProperty, edmProperty.Name));
        }
        public void CreateAmbiguousBinding()
        {
            EdmModel model = new EdmModel();

            EdmComplexType c1 = new EdmComplexType("Ambiguous", "Binding");
            EdmComplexType c2 = new EdmComplexType("Ambiguous", "Binding");
            EdmComplexType c3 = new EdmComplexType("Ambiguous", "Binding");

            model.AddElement(c1);
            Assert.AreEqual(c1, model.FindType("Ambiguous.Binding"), "Single item resolved");

            model.AddElement(c2);
            model.AddElement(c3);

            IEdmNamedElement ambiguous = model.FindType("Ambiguous.Binding");

            Assert.IsTrue(ambiguous.IsBad(), "Ambiguous binding is bad");
            Assert.AreEqual(EdmErrorCode.BadAmbiguousElementBinding, ambiguous.Errors().First().ErrorCode, "Ambiguous");

            c1 = null;
            c2 = new EdmComplexType("Ambiguous", "Binding2");

            Assert.IsTrue
            (
                model.SchemaElements.OfType <IEdmComplexType>().Count() == 3 && model.SchemaElements.OfType <IEdmComplexType>().All(n => n.FullName() == "Ambiguous.Binding"),
                "The model must be immutable."
            );
        }
 private string GetFullName(IEdmNamedElement element)
 {
     var schemaElement = element as IEdmSchemaElement;
     if (null != schemaElement)
     {
         return schemaElement.FullName();
     }
     return element.Name;
 }
        private static string GetPropertyNameForEdmModel(MemberInfo currentProperty, IEdmNamedElement edmProperty)
        {
            Contract.Requires(currentProperty != null);
            Contract.Requires(edmProperty != null);

            var dataMemberAttribute = currentProperty.GetCustomAttributes <DataMemberAttribute>()?.SingleOrDefault();

            return(!string.IsNullOrWhiteSpace(dataMemberAttribute?.Name) ? dataMemberAttribute.Name : edmProperty.Name);
        }
Пример #7
0
        private string GetFullName(IEdmNamedElement element)
        {
            var schemaElement = element as IEdmSchemaElement;

            if (null != schemaElement)
            {
                return(schemaElement.FullName());
            }
            return(element.Name);
        }
Пример #8
0
        /// <summary>
        /// Validate a model element (and its type) to see if it has been marked as deprecated
        /// </summary>
        /// <param name="element">The element being validated.</param>
        /// <param name="elementType">The type of element being validated.</param>
        /// <param name="context">The ODataUrlValidationContext providing validation context.</param>
        private static void Validate(IEdmNamedElement element, IEdmType elementType, ODataUrlValidationContext context)
        {
            string message;
            string version;
            Date?  date;
            Date?  removalDate;

            if (IsDeprecated(context.Model, element, out message, out version, out date, out removalDate))
            {
                context.Messages.Add(CreateUrlValidationMessage(element.Name, message, version, date, removalDate));
            }
        }
Пример #9
0
        internal static bool AddMemberNameToHashSet(IEdmNamedElement item, HashSetInternal<string> memberNameList, ValidationContext context, EdmErrorCode errorCode, string errorString, bool suppressError)
        {
            IEdmSchemaElement schemaElement = item as IEdmSchemaElement;
            string name = (schemaElement != null) ? schemaElement.FullName() : item.Name;
            if (!memberNameList.Add(name))
            {
                if (!suppressError)
                {
                    context.AddError(item.Location(), errorCode, errorString);
                }

                return false;
            }

            return true;
        }
Пример #10
0
        internal static bool AddMemberNameToHashSet(IEdmNamedElement item, HashSetInternal <string> memberNameList, ValidationContext context, EdmErrorCode errorCode, string errorString, bool suppressError)
        {
            IEdmSchemaElement schemaElement = item as IEdmSchemaElement;
            string            name          = (schemaElement != null) ? schemaElement.FullName() : item.Name;

            if (!memberNameList.Add(name))
            {
                if (!suppressError)
                {
                    context.AddError(item.Location(), errorCode, errorString);
                }

                return(false);
            }

            return(true);
        }
Пример #11
0
        /// <summary>
        /// Resolves the specified entity model schema type and returns the Edm model type for it.
        /// </summary>
        /// <param name="model">The model to get the type from.</param>
        /// <param name="schemaType">The entity model schema type to resolve.</param>
        /// <returns>The resolved type for the specified <paramref name="schemaType"/>.</returns>
        public static IEdmTypeReference ResolveEntityModelSchemaType(IEdmModel model, DataType schemaType)
        {
            if (schemaType == null)
            {
                return(null);
            }

            PrimitiveDataType primitiveDataType = schemaType as PrimitiveDataType;

            if (primitiveDataType != null)
            {
                return(GetPrimitiveTypeReference(primitiveDataType));
            }

            if (model == null)
            {
                return(null);
            }

            EntityDataType entityDataType = schemaType as EntityDataType;

            if (entityDataType != null)
            {
                IEdmNamedElement edmType = model.FindType(entityDataType.Definition.FullName);
                ExceptionUtilities.Assert(
                    edmType != null,
                    "The expected entity type '{0}' was not found in the entity model for this test.",
                    entityDataType.Definition.FullName);

                IEdmEntityType entityType = edmType as IEdmEntityType;
                ExceptionUtilities.Assert(
                    entityType != null,
                    "The expected entity type '{0}' is not defined as entity type in the test's metadata.",
                    entityDataType.Definition.FullName);
                return(entityType.ToTypeReference());
            }

            ComplexDataType complexDataType = schemaType as ComplexDataType;

            if (complexDataType != null)
            {
                return(GetComplexType(model, complexDataType));
            }

            CollectionDataType collectionDataType = schemaType as CollectionDataType;

            if (collectionDataType != null)
            {
                DataType          collectionElementType = collectionDataType.ElementDataType;
                PrimitiveDataType primitiveElementType  = collectionElementType as PrimitiveDataType;
                if (primitiveElementType != null)
                {
                    IEdmPrimitiveTypeReference primitiveElementTypeReference = GetPrimitiveTypeReference(primitiveElementType);
                    return(primitiveElementTypeReference.ToCollectionTypeReference());
                }

                ComplexDataType complexElementType = collectionElementType as ComplexDataType;
                if (complexElementType != null)
                {
                    IEdmComplexTypeReference complexElementTypeReference = GetComplexType(model, complexElementType);
                    return(complexElementTypeReference.ToCollectionTypeReference());
                }

                EntityDataType entityElementType = collectionElementType as EntityDataType;
                if (entityElementType != null)
                {
                    IEdmEntityTypeReference entityElementTypeReference = GetEntityType(model, entityElementType);
                    return(entityElementTypeReference.ToCollectionTypeReference());
                }

                throw new NotSupportedException("Collection types only support primitive, complex, and entity element types.");
            }

            StreamDataType streamType = schemaType as StreamDataType;

            if (streamType != null)
            {
                Type systemType = streamType.GetFacet <PrimitiveClrTypeFacet>().Value;
                ExceptionUtilities.Assert(systemType == typeof(Stream), "Expected the system type 'System.IO.Stream' for a stream reference property.");
                return(MetadataUtils.GetPrimitiveTypeReference(systemType));
            }

            throw new NotImplementedException("Unrecognized schema type " + schemaType.GetType().Name + ".");
        }
Пример #12
0
        private int CompareElements(IEdmElement left, IEdmElement right)
        {
            int num;

            if (left != right)
            {
                int hashCode  = left.GetHashCode();
                int hashCode1 = right.GetHashCode();
                if (hashCode >= hashCode1)
                {
                    if (hashCode <= hashCode1)
                    {
                        IEdmNamedElement edmNamedElement  = left as IEdmNamedElement;
                        IEdmNamedElement edmNamedElement1 = right as IEdmNamedElement;
                        if (edmNamedElement != null)
                        {
                            if (edmNamedElement1 != null)
                            {
                                int num1 = string.Compare(edmNamedElement.Name, edmNamedElement1.Name, StringComparison.Ordinal);
                                if (num1 != 0)
                                {
                                    return(num1);
                                }
                            }
                            else
                            {
                                return(1);
                            }
                        }
                        else
                        {
                            if (edmNamedElement1 != null)
                            {
                                return(-1);
                            }
                        }
                        while (true)
                        {
                            foreach (IEdmElement unsortedElement in this.unsortedElements)
                            {
                                if (unsortedElement != left)
                                {
                                    if (unsortedElement != right)
                                    {
                                        continue;
                                    }
                                    num = -1;
                                    return(num);
                                }
                                else
                                {
                                    num = 1;
                                    return(num);
                                }
                            }
                            lock (this.unsortedElementsLock)
                            {
                                this.unsortedElements = this.unsortedElements.Add(left);
                            }
                        }
                        return(num);
                    }
                    else
                    {
                        return(1);
                    }
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                return(0);
            }
        }
Пример #13
0
 private ModelEntityName ConvertToModelEntityName(IEdmNamedElement element, IEdmEntityContainer entityContainer)
 {
     return(new ModelEntityName(entityContainer.Namespace, element.Name, element.Name));
 }
Пример #14
0
 private static string UnescapeEdmField(IEdmNamedElement property)
 {
     return(property.Name);
 }
Пример #15
0
 protected virtual void ProcessNamedElement(IEdmNamedElement element)
 {
     this.ProcessElement(element);
 }
Пример #16
0
        private int CompareElements(IEdmElement left, IEdmElement right)
        {
            if (left == right)
            {
                return(0);
            }

            /* Left and right are distinct. */

            int leftHash  = left.GetHashCode();
            int rightHash = right.GetHashCode();

            if (leftHash < rightHash)
            {
                return(-1);
            }

            if (leftHash > rightHash)
            {
                return(1);
            }

            /* Left and right are distinct and have identical hash codes. */

            IEdmNamedElement leftNamed  = left as IEdmNamedElement;
            IEdmNamedElement rightNamed = right as IEdmNamedElement;

            if (leftNamed == null)
            {
                if (rightNamed != null)
                {
                    return(-1);
                }
            }
            else if (rightNamed == null)
            {
                return(1);
            }
            else
            {
                /* Left and right are both named. */

                int nameComparison = string.Compare(leftNamed.Name, rightNamed.Name, StringComparison.Ordinal);

                if (nameComparison != 0)
                {
                    return(nameComparison);
                }
            }

            /* Left and right are distinct, have identical hash codes, and have identical names. */

            /* The first element to occur in the unsorted list is the greatest. */

            while (true)
            {
                foreach (IEdmElement element in this.unsortedElements)
                {
                    if (element == left)
                    {
                        return(1);
                    }

                    if (element == right)
                    {
                        return(-1);
                    }
                }

                lock (this.unsortedElementsLock)
                {
                    this.unsortedElements = this.unsortedElements.Add(left);
                }
            }
        }
        private static string GetPropertyNameForEdmModel(MemberInfo currentProperty, IEdmNamedElement edmProperty)
        {
            Contract.Requires(currentProperty != null);
            Contract.Requires(edmProperty != null);

            var dataMemberAttribute = currentProperty.GetCustomAttributes<DataMemberAttribute>()?.SingleOrDefault();

            return !string.IsNullOrWhiteSpace(dataMemberAttribute?.Name) ? dataMemberAttribute.Name : edmProperty.Name;
        }