private QueryValue BuildCollectionQueryValue(string propertyPath, QueryCollectionType queryCollectionType, EntitySetDataRow row)
        {
            QueryScalarType   scalarElementDataType      = queryCollectionType.ElementType as QueryScalarType;
            QueryComplexType  complexTypeElementDataType = queryCollectionType.ElementType as QueryComplexType;
            List <QueryValue> queryValues = new List <QueryValue>();

            if (scalarElementDataType != null)
            {
                int i = 0;
                while (row.PropertyPaths.Any(pp => pp == propertyPath + i))
                {
                    var value = row[propertyPath + i];
                    queryValues.Add(scalarElementDataType.CreateValue(value));
                    i++;
                }
            }
            else
            {
                ExceptionUtilities.CheckObjectNotNull(complexTypeElementDataType, "PropertyPath '{0}' is an invalid type '{1}'", propertyPath, queryCollectionType.ElementType);

                int i = 0;
                while (row.PropertyPaths.Where(pp => pp.StartsWith(propertyPath + i, StringComparison.Ordinal)).Count() > 0)
                {
                    QueryStructuralValue complexChildInstance = complexTypeElementDataType.CreateNewInstance();
                    this.BuildStructuralPropertiesQueryValue(complexChildInstance, propertyPath + i + ".", complexTypeElementDataType.ComplexType.Properties, complexTypeElementDataType.Properties, row);
                    queryValues.Add(complexChildInstance);
                    i++;
                }
            }

            return(queryCollectionType.CreateCollectionWithValues(queryValues.ToArray()));
        }
Example #2
0
        /// <summary>
        /// Creates a QueryProperty for a property that is a non entity Collection
        /// </summary>
        /// <param name="library">Library Query Type</param>
        /// <param name="result">resulting Query Structural Type</param>
        /// <param name="collectionProperty">Member to calculate</param>
        /// <param name="pathToProperty">Path to the Property</param>
        /// <returns>A Query Property of the collectionType</returns>
        protected override QueryProperty CreateNonentityCollectionMember(QueryTypeLibrary library, QueryStructuralType result, MemberProperty collectionProperty, PathToProperty pathToProperty)
        {
            ExceptionUtilities.CheckArgumentNotNull(collectionProperty, "collectionProperty");

            var collectionType = collectionProperty.PropertyType as CollectionDataType;

            ExceptionUtilities.Assert(collectionType != null, "This type of property is not supported.");
            var collectionPrimitiveElementType      = collectionType.ElementDataType as PrimitiveDataType;
            var collectionComplexElementType        = collectionType.ElementDataType as ComplexDataType;
            QueryCollectionType queryCollectionType = null;

            if (collectionPrimitiveElementType != null)
            {
                QueryScalarType queryPropertyType = this.GetQueryTypeForMappedProperty(pathToProperty, library, collectionPrimitiveElementType);
                queryCollectionType = queryPropertyType.CreateCollectionType();
            }
            else
            {
                ExceptionUtilities.Assert(collectionComplexElementType != null, "This type of property is not supported.");
                QueryComplexType queryComplexType = this.CreateStubComplexType(collectionComplexElementType.Definition);
                CreateMembers(library, queryComplexType, collectionComplexElementType.Definition.Properties, pathToProperty);
                queryCollectionType = queryComplexType.CreateCollectionType();
            }

            return(QueryProperty.Create(collectionProperty.Name, queryCollectionType));
        }
        /// <summary>
        /// Creates new members on a structural type
        /// </summary>
        /// <param name="library">Type library</param>
        /// <param name="result">Structural Type to add members to</param>
        /// <param name="properties">Properties of the Structural Type member</param>
        /// <param name="pathToProperty">Path to the Property</param>
        protected void CreateMembers(QueryTypeLibrary library, QueryStructuralType result, IEnumerable <MemberProperty> properties, PathToProperty pathToProperty)
        {
            // TODO: Some Taupo framework pieces skip over StreamDataType properties
            foreach (var prop in properties.Where(p => !(p.PropertyType is StreamDataType)))
            {
                QueryProperty queryProperty = null;
                pathToProperty.PathStackWithinEntityType.Add(prop.Name);

                var pdt = prop.PropertyType as PrimitiveDataType;
                var cdt = prop.PropertyType as ComplexDataType;
                if (pdt != null)
                {
                    QueryScalarType queryPropertyType = this.GetQueryTypeForMappedProperty(pathToProperty, library, pdt);
                    queryProperty = QueryProperty.Create(prop.Name, queryPropertyType);
                }
                else if (cdt != null)
                {
                    ComplexType      ct = cdt.Definition;
                    QueryComplexType queryComplexType = this.CreateStubComplexType(ct);
                    this.CreateMembers(library, queryComplexType, ct.Properties, pathToProperty);
                    library.SetQueryComplexType(ct, queryComplexType);
                    queryProperty = QueryProperty.Create(prop.Name, queryComplexType);
                }
                else
                {
                    queryProperty = this.CreateNonentityCollectionMember(library, result, prop, pathToProperty);
                }

                pathToProperty.PathStackWithinEntityType.RemoveAt(pathToProperty.PathStackWithinEntityType.Count - 1);

                queryProperty.SetPrimaryKey(prop.IsPrimaryKey);
                result.Add(queryProperty);
            }
        }
        private void BuildStructuralPropertiesQueryValue(QueryStructuralValue instance, string propertyPath, IList <MemberProperty> properties, IList <QueryProperty> queryProperties, EntitySetDataRow row)
        {
            ExceptionUtilities.Assert(properties.Count == queryProperties.Count, "QueryProperties '{0}' and MemberProperties '{1}' are not the same number!", CreateQueryPropertyList(queryProperties), CreateMemberPropertyList(properties));

            // TODO: Some Taupo framework pieces skip over StreamDataType properties
            foreach (MemberProperty childProperty in properties.Where(p => !(p.PropertyType is StreamDataType)))
            {
                string childPropertyPath = propertyPath + childProperty.Name;
                List <QueryProperty> childQueryProperties = queryProperties.Where(p => p.Name == childProperty.Name).ToList();
                ExceptionUtilities.Assert(childQueryProperties.Count == 1, "Could not find query property based on MemberProperty Name '{0}' in list of query properties '{1}'", childProperty.Name, CreateQueryPropertyList(childQueryProperties));

                QueryProperty childQueryProperty = childQueryProperties.First();

                QueryCollectionType childCollectionDataType = childQueryProperty.PropertyType as QueryCollectionType;
                QueryScalarType     childScalarType         = childQueryProperty.PropertyType as QueryScalarType;
                QueryComplexType    childComplexType        = childQueryProperty.PropertyType as QueryComplexType;

                if (childCollectionDataType != null)
                {
                    instance.SetValue(childProperty.Name, this.BuildCollectionQueryValue(childPropertyPath + ".", childCollectionDataType, row));
                }
                else if (childScalarType != null)
                {
                    var value      = row[childPropertyPath];
                    var queryValue = childScalarType.CreateValue(value);
                    instance.SetValue(childQueryProperty.Name, queryValue);
                }
                else
                {
                    ExceptionUtilities.CheckObjectNotNull(childComplexType, "Unknown type '{0}'", childProperty.PropertyType);

                    // If a complex type instance is null in the datarow, we will create a QueryStructuralValue indicating null and set it on the instance.
                    if (row.PropertyPaths.Contains(childPropertyPath) && row[childPropertyPath] == null)
                    {
                        instance.SetValue(childProperty.Name, new QueryStructuralValue(childComplexType, true, null, childComplexType.EvaluationStrategy));
                    }
                    else
                    {
                        QueryStructuralValue childInstance = childComplexType.CreateNewInstance();
                        this.BuildStructuralPropertiesQueryValue(childInstance, childPropertyPath + ".", childComplexType.ComplexType.Properties, childComplexType.Properties, row);
                        instance.SetValue(childProperty.Name, childInstance);
                    }
                }
            }
        }
        /// <summary>
        /// Creates a QueryValue of a given type.
        /// </summary>
        /// <param name="type">Type of the QueryValue that will be generated.</param>
        /// <returns>QueryValue representing the provided object.</returns>
        public QueryValue Visit(QueryComplexType type)
        {
            var resultFragment = this.ResultFragmentStack.Pop();

            QueryStructuralValue visitedComplexType;

            if (this.visitedStructurals.TryGetValue(resultFragment, out visitedComplexType))
            {
                return(visitedComplexType);
            }

            ExceptionUtilities.Assert(
                resultFragment.GetType().Name == type.ComplexType.Name,
                "Names don't match. Expecting: " + type.ComplexType.Name + ". Actual: " + resultFragment.GetType().Name + ".");

            var resultComplexType = type.CreateNewInstance();

            this.visitedStructurals[resultFragment] = resultComplexType;
            resultComplexType = this.PopulateProperties(resultComplexType, resultFragment);

            return(resultComplexType);
        }
Example #6
0
        /// <summary>
        /// Gets EDM type for primtive, entity and complex types
        /// </summary>
        /// <param name="type">The Query Type.</param>
        /// <returns>The EDM Type in string format.</returns>
        protected string GetEdmTypeName(QueryType type)
        {
            QueryComplexType complexType   = type as QueryComplexType;
            QueryEntityType  entityType    = type as QueryEntityType;
            IQueryClrType    clrBackedType = type as IQueryClrType;

            if (complexType != null)
            {
                return(complexType.ComplexType.FullName);
            }
            else if (entityType != null)
            {
                return(entityType.EntityType.FullName);
            }
            else if (clrBackedType != null)
            {
                ExceptionUtilities.CheckObjectNotNull(this.PrimitiveDataTypeConverter, "Cannot get edm type name for primitive clr type without converter");
                return(this.PrimitiveDataTypeConverter.ToDataType(clrBackedType.ClrType).GetEdmTypeName());
            }
            else
            {
                throw new TaupoNotSupportedException("Unable to find EDM type name for type which is not an entity type or a primitive type");
            }
        }
 /// <summary>
 /// Visits a <see cref="QueryComplexType"/>.
 /// </summary>
 /// <param name="type">Query type being visited.</param>
 /// <returns>The result of visiting this query type.</returns>
 public ComparisonResult Visit(QueryComplexType type)
 {
     return(this.parent.CompareStructural((QueryStructuralValue)this.expectedValue, this.actualValue, this.path, this.shouldThrow));
 }
Example #8
0
        private void UpdateRootComplexBag(QueryCollectionValue queryCollectionValue, IEnumerable <NamedValue> namedValues, QueryComplexType complexTypeElementDataType)
        {
            int i = 0;

            var complexCollection = new List <QueryValue>();
            List <NamedValue> complexInstanceNamedValues = namedValues.Where(pp => pp.Name.StartsWith(i + ".", StringComparison.Ordinal)).ToList();

            while (complexInstanceNamedValues.Any())
            {
                QueryStructuralValue complexValue = complexTypeElementDataType.CreateNewInstance();
                this.UpdateValues(complexValue, complexInstanceNamedValues, i.ToString(CultureInfo.InvariantCulture));
                complexCollection.Add(complexValue);

                i++;
                complexInstanceNamedValues = namedValues.Where(pp => pp.Name.StartsWith(i + ".", StringComparison.Ordinal)).ToList();
            }

            if (complexCollection.Any())
            {
                this.SetCollectionValue(queryCollectionValue, complexCollection);
            }
        }
Example #9
0
        private void UpdateComplexBag(QueryStructuralValue instance, QueryProperty memberProperty, string propertyPath, IEnumerable <NamedValue> namedValues, QueryComplexType complexTypeElementDataType)
        {
            int i = 0;

            var complexCollection = new List <QueryValue>();
            List <NamedValue> complexInstanceNamedValues = namedValues.Where(pp => pp.Name.StartsWith(propertyPath + "." + i + ".", StringComparison.Ordinal)).ToList();

            while (complexInstanceNamedValues.Any())
            {
                QueryStructuralValue complexValue = complexTypeElementDataType.CreateNewInstance();
                this.UpdateValues(complexValue, complexInstanceNamedValues, propertyPath + "." + i);
                complexCollection.Add(complexValue);

                i++;
                complexInstanceNamedValues = namedValues.Where(pp => pp.Name.StartsWith(propertyPath + "." + i + ".", StringComparison.Ordinal)).ToList();
            }

            if (complexCollection.Any())
            {
                this.SetCollectionProperty(instance, memberProperty, complexCollection);
            }
        }
        private void UpdateRootComplexBag(QueryCollectionValue queryCollectionValue, IEnumerable<NamedValue> namedValues, QueryComplexType complexTypeElementDataType)
        {
            int i = 0;

            var complexCollection = new List<QueryValue>();
            List<NamedValue> complexInstanceNamedValues = namedValues.Where(pp => pp.Name.StartsWith(i + ".", StringComparison.Ordinal)).ToList();
            while (complexInstanceNamedValues.Any())
            {
                QueryStructuralValue complexValue = complexTypeElementDataType.CreateNewInstance();
                this.UpdateValues(complexValue, complexInstanceNamedValues, i.ToString(CultureInfo.InvariantCulture));
                complexCollection.Add(complexValue);

                i++;
                complexInstanceNamedValues = namedValues.Where(pp => pp.Name.StartsWith(i + ".", StringComparison.Ordinal)).ToList();
            }

            if (complexCollection.Any())
            {
                this.SetCollectionValue(queryCollectionValue, complexCollection);
            }
        }
        private void UpdateComplexBag(QueryStructuralValue instance, QueryProperty memberProperty, string propertyPath, IEnumerable<NamedValue> namedValues, QueryComplexType complexTypeElementDataType)
        {
            int i = 0;

            var complexCollection = new List<QueryValue>();
            List<NamedValue> complexInstanceNamedValues = namedValues.Where(pp => pp.Name.StartsWith(propertyPath + "." + i + ".", StringComparison.Ordinal)).ToList();
            while (complexInstanceNamedValues.Any())
            {
                QueryStructuralValue complexValue = complexTypeElementDataType.CreateNewInstance();
                this.UpdateValues(complexValue, complexInstanceNamedValues, propertyPath + "." + i);
                complexCollection.Add(complexValue);

                i++;
                complexInstanceNamedValues = namedValues.Where(pp => pp.Name.StartsWith(propertyPath + "." + i + ".", StringComparison.Ordinal)).ToList();
            }

            if (complexCollection.Any())
            {
                this.SetCollectionProperty(instance, memberProperty, complexCollection);
            }
        }