예제 #1
0
        /// <summary>
        /// Builds a complex type instance of the given type out of the given anonymous object
        /// </summary>
        /// <param name="complexType">The metadata type information for the complex type</param>
        /// <param name="anonymous">The data as an anonymous type</param>
        /// <returns>An entity instance with the given values</returns>
        public ComplexInstance ComplexInstance(ComplexType complexType, object anonymous)
        {
            ComplexInstance instance = new ComplexInstance(complexType.FullName, anonymous == null);
            if (anonymous != null)
            {
                this.PopulatePropertiesFromObject(instance, complexType.Properties, anonymous);
            }

            return instance;
        }
        /// <summary>
        /// Fills in the given type declaration based on the given metadata
        /// </summary>
        /// <param name="complexType">The complex type's metadata</param>
        /// <param name="complexTypeClass">The type declaration</param>
        protected override void DeclareComplexType(ComplexType complexType, CodeTypeDeclaration complexTypeClass)
        {
            complexTypeClass.IsPartial = true;
            complexTypeClass.IsClass = true;

            // Add public constructor for this type
            var constructor = complexTypeClass.AddConstructor();

            foreach (MemberProperty memberProperty in complexType.Properties)
            {
                this.DeclareMemberProperty(memberProperty, complexTypeClass);
                this.DeclareOptionalPropertyInitializer(memberProperty, constructor);
            }
        }
        /// <summary>
        /// Gets the CLR instance type for the specified complex type.
        /// </summary>
        /// <param name="complex">The complex type to get the instance type for.</param>
        /// <param name="canReflectOnInstanceType">true if reflection over the instance type is allowed; otherwise false.</param>
        /// <returns>The CLR instance type to use.</returns>
        protected override Type GetComplexInstanceType(ComplexType complex, out bool canReflectOnInstanceType)
        {
            Type complexType = null;
            ClrTypeAnnotation clrTypeAnnotation = complex.Annotations.OfType<ClrTypeAnnotation>().FirstOrDefault();

            if (clrTypeAnnotation == null)
            {
                complexType = (from exportedType in Workspace.ObjectLayerAssembly.GetExportedTypes()
                               where exportedType.Name == complex.Name
                               select exportedType).SingleOrDefault();
            }
            else
            {
                complexType = clrTypeAnnotation.ClrType;
            }

            ExceptionUtilities.CheckObjectNotNull(complexType, "Could not find complex type '{0}' in object layer", complex.Name);

            canReflectOnInstanceType = true;
            return complexType;
        }
예제 #4
0
        /// <summary>
        /// Adds and updates existing types in the default model to use Primitive and Complex Collections
        /// </summary>
        /// <param name="model">Model to add fixup to.</param>
        public void Fixup(EntityModelSchema model)
        {
            // Create entityType with all PrimitiveTypes lists
            EntityType allPrimitiveCollectionTypesEntity = new EntityType("AllPrimitiveCollectionTypesEntity");
            allPrimitiveCollectionTypesEntity.Add(new MemberProperty("Key", EdmDataTypes.Int32));
            allPrimitiveCollectionTypesEntity.Properties[0].IsPrimaryKey = true;
            for (int i = 0; i < primitiveTypes.Length; i++)
            {
                DataType t = DataTypes.CollectionType.WithElementDataType(primitiveTypes[i]);
                allPrimitiveCollectionTypesEntity.Add(new MemberProperty("Property" + i, t));
            }

            model.Add(allPrimitiveCollectionTypesEntity);

             // Create a complexType  with all PrimitiveTypes Bags and primitive properties in it
            ComplexType additionalComplexType = new ComplexType("AdditionalComplexType");
            additionalComplexType.Add(new MemberProperty("Bag1", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.DateTime())));
            additionalComplexType.Add(new MemberProperty("Bag3", EdmDataTypes.String()));
            model.Add(additionalComplexType);

            // Create a complexType  with all PrimitiveTypes Bags in it
            ComplexType complexPrimitiveCollectionsType = new ComplexType("ComplexTypePrimitiveCollections");
            for (int i = 0; i < primitiveTypes.Length; i++)
            {
                DataType t = DataTypes.CollectionType.WithElementDataType(primitiveTypes[i]);
                complexPrimitiveCollectionsType.Add(new MemberProperty("Property" + i, t));
            }

            complexPrimitiveCollectionsType.Add(new MemberProperty("ComplexTypeBag", DataTypes.CollectionType.WithElementDataType(DataTypes.ComplexType.WithDefinition(additionalComplexType))));
            model.Add(complexPrimitiveCollectionsType);

            // Add the complexPrimitiveCollectionsType to an entity
            EntityType complexBagsEntity = new EntityType("ComplexBagsEntity");
            complexBagsEntity.Add(new MemberProperty("Key", EdmDataTypes.Int32));
            complexBagsEntity.Properties[0].IsPrimaryKey = true;
            DataType complexDataType = DataTypes.ComplexType.WithDefinition(complexPrimitiveCollectionsType);
            complexBagsEntity.Add(new MemberProperty("CollectionComplexTypePrimitiveCollections", DataTypes.CollectionType.WithElementDataType(complexDataType)));
            complexBagsEntity.Add(new MemberProperty("ComplexTypePrimitiveCollections", complexDataType));

            model.Add(complexBagsEntity);

            int numberOfComplexCollections = 0;
            
            // Update existing model so that every 3rd complexType is a Collection of ComplexTypes
            foreach (EntityType t in model.EntityTypes)
            {
                foreach (MemberProperty complexProperty in t.Properties.Where(p => p.PropertyType is ComplexDataType).ToList())
                {
                    // Remove existing one
                    t.Properties.Remove(complexProperty);

                    // Add new one 
                    t.Properties.Add(new MemberProperty(complexProperty.Name + "Collection", DataTypes.CollectionType.WithElementDataType(complexProperty.PropertyType)));
                    numberOfComplexCollections++;

                    if (numberOfComplexCollections > 4)
                    {
                        break;
                    }
                }

                if (numberOfComplexCollections > 4)
                {
                    break;
                }
            }

            new ResolveReferencesFixup().Fixup(model);

            // ReApply the previously setup namespace on to the new types
            new ApplyDefaultNamespaceFixup(model.EntityTypes.First().NamespaceName).Fixup(model);
            new AddDefaultContainerFixup().Fixup(model);
            new SetDefaultCollectionTypesFixup().Fixup(model);
        }
 /// <summary>
 /// Gets the CLR instance type for the specified complex type.
 /// </summary>
 /// <param name="complex">The complex type to get the instance type for.</param>
 /// <param name="canReflectOnInstanceType">true if reflection over the instance type is allowed; otherwise false.</param>
 /// <returns>The CLR instance type to use.</returns>
 protected abstract Type GetComplexInstanceType(ComplexType complex, out bool canReflectOnInstanceType);
        private ComplexType ConvertToTaupoComplexType(IEdmComplexType edmComplexType)
        {
            // Taupo TODO: Abstract for ComplexType
            var taupoComplexType = new ComplexType(edmComplexType.Namespace, edmComplexType.Name);

            if (edmComplexType.BaseType != null)
            {
                taupoComplexType.BaseType = new ComplexTypeReference(edmComplexType.BaseComplexType().Namespace, edmComplexType.BaseComplexType().Name);
            }

            foreach (var edmProperty in edmComplexType.DeclaredStructuralProperties())
            {
                var taupoProperty = this.ConvertToTaupoProperty(edmProperty);
                taupoComplexType.Add(taupoProperty);
            }

            this.ConvertAnnotationsIntoTaupo(edmComplexType, taupoComplexType);
            return taupoComplexType;
        }
예제 #7
0
        private void CompareComplexType(ComplexType expectedComplexType, ComplexType actualComplexType)
        {
            this.SatisfiesEquals(expectedComplexType.FullName, actualComplexType.FullName, "ComplexType name does not match.");

            this.CompareProperties(expectedComplexType, actualComplexType);
        }
 /// <summary>
 /// Creates a QueryComplexType using a ComplexType
 /// </summary>
 /// <param name="complexType">ComplexType to create Query Type Stub</param>
 /// <returns>Returns a Query Complex Type</returns>
 protected QueryComplexType CreateStubComplexType(ComplexType complexType)
 {
     return new QueryComplexType(this.EvaluationStrategy, complexType, null);
 }
 /// <summary>
 /// Fills in the given type declaration based on the given metadata and implements INotifyPropertyChanged on the type
 /// </summary>
 /// <param name="complexType">The complex type's metadata</param>
 /// <param name="complexTypeClass">The type declaration</param>
 protected override void DeclareComplexType(ComplexType complexType, CodeTypeDeclaration complexTypeClass)
 {
     base.DeclareComplexType(complexType, complexTypeClass);
     this.ImplementINotifyPropertyChanged(complexTypeClass);
 }
예제 #10
0
        /// <summary>
        /// Builds a code representation of an <see cref="ComplexType"/>.
        /// </summary>
        /// <param name="type">The <see cref="ComplexType"/> from which to generate code.</param>
        /// <returns>A <see cref="CodeTypeDeclaration"/> which represents the <see cref="ComplexType"/>.</returns>
        protected virtual CodeTypeDeclaration BuildType(ComplexType type)
        {
            var codeClass = new CodeTypeDeclaration(type.Name);
            codeClass.AddConstructor();

            ApplyTypeAccessModifier(codeClass, type.Annotations.OfType<TypeAccessModifierAnnotation>().SingleOrDefault());

            if (type.Annotations.Any(a => a is SerializableAnnotation))
            {
                codeClass.AddCustomAttribute(typeof(SerializableAttribute));
            }

            if (type.Annotations.Any(a => a is CodeAttributeAnnotation))
            {
                this.AddCodeAttributeAnnotationAsCustomAttribute(codeClass, type.Annotations.OfType<CodeAttributeAnnotation>());
            }

            this.AddProperties(codeClass, type);
            return codeClass;
        }
예제 #11
0
        /// <summary>
        /// Constructs a complex instance with the given property values
        /// </summary>
        /// <param name="type">The metadata for the complex type</param>
        /// <param name="propertyPath">Property Path to the ComplexInstance</param>
        /// <param name="namedValues">The property values. Keys are expected to be '.' delimited property paths.</param>
        /// <returns>A complex instance with the given values</returns>
        private ComplexInstance ComplexInstance(ComplexType type, string propertyPath, IEnumerable<NamedValue> namedValues)
        {
            ExceptionUtilities.CheckArgumentNotNull(type, "type");

            ComplexInstance instance = new ComplexInstance(type.FullName, namedValues == null);
            if (namedValues != null)
            {
                this.PopulatePropertiesFromPaths(instance, type.Properties, propertyPath, namedValues);
            }

            return instance;
        }
예제 #12
0
 /// <summary>
 /// Constructs a complex instance with the given property values
 /// </summary>
 /// <param name="complexType">The metadata for the complex type</param>
 /// <param name="namedValues">The property values. Keys are expected to be '.' delimited property paths.</param>
 /// <returns>A complex instance with the given values</returns>
 public ComplexInstance ComplexInstance(ComplexType complexType, IEnumerable<NamedValue> namedValues)
 {
     return this.ComplexInstance(complexType, null, namedValues);
 }
        private void AddPropertyAnnotations(ComplexType complexType)
        {
            complexType.Properties.ForEach(p => p.MakeMetadataDeclared());

            if (complexType.IsTypeBacked())
            {
                foreach (var property in complexType.Properties)
                {
                    if (this.Random.Next(2) == 0)
                    {
                        property.MakeTypeBacked();
                    }
                }
            }
        }
예제 #14
0
        /// <summary>
        /// Visits complex type
        /// </summary>
        /// <param name="complex">complex type to visit</param>
        protected virtual void VisitComplexType(ComplexType complex)
        {
            this.VisitAnnotatedItem(complex);

            foreach (var property in complex.Properties)
            {
                this.VisitMemberProperty(property);
            }
        }
예제 #15
0
 /// <summary>
 /// Removes a <see cref="ComplexType"/> from the model.
 /// </summary>
 /// <param name="complexType">Complex types to be removed.</param>
 public void Remove(ComplexType complexType)
 {
     ExceptionUtilities.CheckArgumentNotNull(complexType, "complexType");
     ExceptionUtilities.Assert(complexType.Model == this, "Complex type was not added to this model");
     ExceptionUtilities.Assert(this.complexTypesList.Remove(complexType), "Complex type was not added to this model");
     complexType.Model = null;
 }
 /// <summary>
 /// Fills in the given type declaration based on the given metadata
 /// </summary>
 /// <param name="complexType">The complex type's metadata</param>
 /// <param name="complexTypeClass">The type declaration</param>
 protected abstract void DeclareComplexType(ComplexType complexType, CodeTypeDeclaration complexTypeClass);
예제 #17
0
 /// <summary>
 /// Adds new <see cref="ComplexType"/> to the model.
 /// </summary>
 /// <param name="complexType">Complex types to be added.</param>
 public void Add(ComplexType complexType)
 {
     ExceptionUtilities.CheckArgumentNotNull(complexType, "complexType");
     ExceptionUtilities.Assert(complexType.Model == null, "Complex type was already added to another model");
     complexType.Model = this;
     this.complexTypesList.Add(complexType);
 }
예제 #18
0
        private ComplexType ParseComplexType(XElement complexTypeElement)
        {
            string name = complexTypeElement.GetRequiredAttributeValue("Name");
            var complexType = new ComplexType(this.CurrentNamespace, name);

            this.ParseNamedStructuralTypeAttributes(complexTypeElement, complexType);

            foreach (var propertyElement in complexTypeElement.Elements().Where(el => this.IsXsdlElement(el, "Property")))
            {
                complexType.Properties.Add(this.ParseProperty(propertyElement));
            }

            this.ParseAnnotations(complexType, complexTypeElement);
            return complexType;
        }
 private void CompareComplexType(ComplexType expectedComplexType, ComplexType actualComplexType)
 {
     foreach (MemberProperty memberProperty in expectedComplexType.Properties)
     {
         List<MemberProperty> members = actualComplexType.Properties.Where(p => p.Name == memberProperty.Name).ToList();
         if (!this.WriteErrorIfFalse(members.Count == 1, "Cannot find member '{0}'", memberProperty.Name))
         {
             MemberProperty ymemberProperty = members.Single();
             this.CompareMemberProperty(memberProperty, ymemberProperty);
         }
     }
 }
예제 #20
0
 /// <summary>
 /// Gets the <see cref="CollectionDataType"/> with complex data type as element type.
 /// </summary>
 /// <param name="complexType">Complex data type definition.</param>
 /// <returns>The data type.</returns>
 public static CollectionDataType CollectionOfComplex(ComplexType complexType)
 {
     return CollectionType.WithElementDataType(ComplexType.WithDefinition(complexType));
 }
 /// <summary>
 /// Gets the CLR instance type for the specified complex type.
 /// </summary>
 /// <param name="complex">The complex type to get the instance type for.</param>
 /// <param name="canReflectOnInstanceType">true if reflection over the instance type is allowed; otherwise false.</param>
 /// <returns>The CLR instance type to use.</returns>
 protected override Type GetComplexInstanceType(ComplexType complex, out bool canReflectOnInstanceType)
 {
     canReflectOnInstanceType = false;
     return typeof(DSPResource);
 }
예제 #22
0
        /// <summary>
        /// Generates new property values for the given type using this test's structural data services
        /// </summary>
        /// <param name="type">The type to generate properties for</param>
        /// <returns>A set of new property values for the given type</returns>
        protected internal IEnumerable<NamedValue> GeneratePropertyValues(ComplexType type)
        {
            ExceptionUtilities.CheckArgumentNotNull(type, "type");

            var generator = this.StructuralDataServices.GetStructuralGenerator(type.FullName);
            return generator.GenerateData();
        }