/// <summary>
 /// Initialize all the build in type with the given type attributes and properties
 /// </summary>
 /// <param name="builtInType">The built In type which is getting initialized</param>
 /// <param name="name">name of the built in type</param>
 /// <param name="isAbstract">whether the type is abstract or not</param>
 /// <param name="isSealed">whether the type is sealed or not</param>
 /// <param name="baseType">The base type of the built in type</param>
 private static void InitializeBuiltInTypes(ComplexType builtInType,
                                             string name,
                                             bool isAbstract,
                                             ComplexType baseType)
 {
     // Initialize item attributes for all ancestor types
     EdmType.Initialize(builtInType, name, EdmConstants.EdmNamespace, DataSpace.CSpace, isAbstract, baseType);
 }
        /// <summary>
        /// Gets sub item of the specified ComplexType instance by the name 
        /// </summary>
        /// <param name="type">The ComplexType instance</param>
        /// <param name="name">The name of sub item</param>
        /// <returns>sub item object if one is found; null otherwise</returns>
        private static ODataUriItem GetItem(ComplexType type, string name)
        {
            ODataUriItem result = null;

            EdmProperty property;
            bool isProperty = type.Properties.TryGetValue(name, false, out property);
            if (isProperty)
            {
                result = new ODataUriItem(property, property.BuiltInTypeKind == BuiltInTypeKind.ComplexType ? UriType.URI3 : UriType.URI5);
            }

            return result;
        }
        /// <summary>
        /// Converts an complex type from SOM to metadata
        /// </summary>
        /// <param name="element">The SOM element to process</param>
        /// <param name="providerManifest">The provider manifest to be used for conversion</param>
        /// <param name="convertedItemCache">The item collection for currently existing metadata objects</param>
        /// <param name="newGlobalItems">The new GlobalItem objects that are created as a result of this conversion</param>
        /// <returns>The complex type object resulting from the convert</returns>
        private static ComplexType ConvertToComplexType(Som.SchemaComplexType element,
                                                        DbProviderManifest providerManifest,
                                                        ConversionCache convertedItemCache,
                                                        Dictionary<Som.SchemaElement, GlobalItem> newGlobalItems)
        {
            ComplexType complexType = new ComplexType(element.Name,
                                                      element.Namespace,
                                                      GetDataSpace(providerManifest));
            newGlobalItems.Add(element, complexType);

            foreach (Som.StructuredProperty somProperty in element.Properties)
            {
                complexType.AddMember(ConvertToProperty(somProperty,
                                                          providerManifest,
                                                          convertedItemCache,
                                                          newGlobalItems));
            }

            // set the abstract and sealed type values for the entity type
            complexType.Abstract = element.IsAbstract;

            if (element.BaseType != null)
            {
                complexType.BaseType = (EdmType)(LoadSchemaElement(element.BaseType,
                                                                  providerManifest,
                                                                  convertedItemCache,
                                                                  newGlobalItems));
            }

            // Extract the optional Documentation
            if (element.Documentation != null)
            {
                complexType.Documentation = ConvertToDocumentation(element.Documentation);
            }
            AddOtherContent(element, complexType);

            return complexType;
        }
        private ComplexType CreateModelComplexTypeForTvfResult(LoadMethodSessionState session, string functionImportName, RowType tvfReturnType)
        {
            Debug.Assert(MetadataUtil.IsStoreType(tvfReturnType), "this is not a store type");

            // create all the properties
            List<EdmMember> members = new List<EdmMember>();
            UniqueIdentifierService usedPropertyNames = new UniqueIdentifierService(false);

            string name = CreateModelName(functionImportName + "_Result", session.UsedGlobalModelTypeNames);

            // Don't want to have a property with the same name as the complex type
            usedPropertyNames.RegisterUsedIdentifier(name);
            foreach (EdmProperty storeProperty in tvfReturnType.Properties)
            {
                EdmProperty property = CreateModelProperty(session, storeProperty, usedPropertyNames);
                members.Add(property);
            }

            var complexType = new ComplexType(name, _namespaceName, DataSpace.CSpace);
            foreach (var m in members)
            {
                complexType.AddMember(m);
            }
            return complexType;
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="nestedType"></param>
 public ComplexTypeEmitter(ClientApiGenerator generator, ComplexType complexType)
     : base(generator, complexType)
 {
 }
        private bool VerifyComplexType(XElement payload, ComplexType complexType, Uri uriTarget, out ExtensionRuleViolationInfo info)
        {
            bool result = true;
            info = null;

            string xpathToProperty = "/*";
            var properties = payload.XPathSelectElements(xpathToProperty, ODataNamespaceManager.Instance);
            foreach (var property in properties)
            {
                var name = property.Name.LocalName;
                var typeOfProperty = from p in complexType.Properties where p.Name == name select p;
                if (typeOfProperty != null && typeOfProperty.Any() )
                {
                    var propType = typeOfProperty.First().TypeUsage.EdmType;
                    if (propType.BuiltInTypeKind == BuiltInTypeKind.PrimitiveType)
                    {
                        bool isWellFormatted = VerifyValueByPrimitiveType(property.Value, propType.FullName);
                        if (!isWellFormatted)
                        {
                            info = new ExtensionRuleViolationInfo("invalid formatted value for type " + propType.FullName, uriTarget, property.Value);
                            result = false;
                            break;
                        }
                    }
                }
            }

            return result;
        }
 /// <summary>
 /// Add a Type to the list of Is-Of types that this mapping is valid for
 /// </summary>
 internal void AddIsOfType(ComplexType type)
 {
     m_isOfTypes.Add(type.FullName, type);
 }
        protected override void Visit(ComplexType complexType)
        {
            int index;
            if (!this.AddObjectToSeenListAndHashBuilder(complexType, out index))
            {
                return;
            }

            this.AddObjectStartDumpToHashBuilder(complexType, index);

            #region Inner data visit
            this.AddObjectContentToHashBuilder(complexType.Abstract);
            this.AddObjectContentToHashBuilder(complexType.Identity);
            // Identity covers, FullName, Name, and NamespaceName

            base.Visit(complexType);

            #endregion

            this.AddObjectEndDumpToHashBuilder();
        }
 protected virtual void Visit(ComplexType complexType)
 {
     Visit(complexType.BaseType);
     foreach (var member in complexType.Members)
     {
         Visit(member);
     }
     foreach (var property in complexType.Properties)
     {
         Visit(property);
     }
 }
 internal FunctionImportComplexTypeMapping(ComplexType returnType, Collection<FunctionImportReturnTypePropertyMapping> columnsRenameList, LineInfo lineInfo)
     : base(columnsRenameList, lineInfo)
 {
     this.ReturnType = returnType;
 }
Exemple #11
0
 /// <summary>
 /// Validate an ComplexType object
 /// </summary>
 /// <param name="item">The ComplexType object to validate</param>
 /// <param name="errors">An error collection for adding validation errors</param>
 /// <param name="validatedItems">A dictionary keeping track of items that have been validated</param>
 private void ValidateComplexType(ComplexType item, List <EdmItemError> errors, HashSet <MetadataItem> validatedItems)
 {
     ValidateStructuralType(item, errors, validatedItems);
 }