private void ReadChildTables(XmlSchemaComplexType complexType, CremaDataTable dataTable) { foreach (var item in complexType.GetSequenceElements()) { if (item.ElementSchemaType is XmlSchemaSimpleType == false) { var tableName = item.Name; var childTable = new CremaDataTable(tableName, dataTable.CategoryPath); childTable.BeginLoadInternal(); this.ReadTable(item.ElementSchemaType as XmlSchemaComplexType, childTable); childTable.EndLoadInternal(); childTable.Parent = dataTable; } } }
private void ReadTable(XmlSchemaElement element, CremaDataTable dataTable) { var complexType = element.ElementSchemaType as XmlSchemaComplexType; if (dataTable.InternalName != string.Empty && dataTable.InternalName != element.Name) { throw new CremaDataException("대상 테이블과 스키마 이름이 일치하지 않습니다."); } dataTable.InternalName = element.Name; if (this.itemName != null) { dataTable.InternalName = this.itemName.Name; dataTable.InternalCategoryPath = this.itemName.CategoryPath; } else { if (this.version.Major == 3) { if (element.QualifiedName.Namespace != CremaSchema.BaseNamespace) { dataTable.InternalName = CremaDataSet.GetTableName(this.dataSet, element.QualifiedName.Namespace); dataTable.InternalCategoryPath = CremaDataSet.GetTableCategoryPath(this.dataSet, element.QualifiedName.Namespace); } else if (this.version.Minor == 0) { var categoryName = complexType.ReadAppInfoAsString(CremaSchema.TableInfo, CremaSchema.Category) ?? string.Empty; var categoryPath = categoryName == string.Empty ? PathUtility.Separator : categoryName.WrapSeparator(); dataTable.InternalName = element.Name; dataTable.InternalCategoryPath = categoryPath; } else { dataTable.InternalName = element.Name; dataTable.InternalCategoryPath = complexType.ReadAppInfoAsString(CremaSchema.TableInfo, CremaSchema.CategoryPath, PathUtility.Separator); } } else { dataTable.InternalName = CremaDataSet.GetTableName(this.dataSet, element.QualifiedName.Namespace); dataTable.InternalCategoryPath = CremaDataSet.GetTableCategoryPath(this.dataSet, element.QualifiedName.Namespace); } } dataTable.BeginLoadInternal(); this.ReadTable(element.ElementSchemaType as XmlSchemaComplexType, dataTable); this.ReadChildTables(element.ElementSchemaType as XmlSchemaComplexType, dataTable); dataTable.EndLoadInternal(); this.tables.Add(dataTable.Name, dataTable); foreach (var item in dataTable.Childs) { this.tables.Add(item.Name, item); } if (this.dataSet != null) { lock (CremaSchema.lockobj) { this.dataSet.Tables.Add(dataTable); if (complexType.ContentModel != null) { var contentModel = complexType.ContentModel as XmlSchemaComplexContent; var content = contentModel.Content as XmlSchemaComplexContentExtension; var templatedParentName = content.BaseTypeName.Name.Substring(0, content.BaseTypeName.Name.Length - CremaSchema.ComplexTypeNameExtension.Length); var baseComplexType = content.GetBaseType(); var templateCategoryPath = PathUtility.Separator; if (this.version.Minor == 0) { templateCategoryPath = (baseComplexType.ReadAppInfoAsString(CremaSchema.TableInfo, CremaSchema.Category) ?? string.Empty).Wrap(PathUtility.SeparatorChar); } else { templateCategoryPath = baseComplexType.ReadAppInfoAsString(CremaSchema.TableInfo, CremaSchema.CategoryPath) ?? PathUtility.Separator; } var templateNamespace = this.dataSet.TableNamespace + templateCategoryPath + templatedParentName; var templatedParent = this.dataSet.Tables[templatedParentName, templateCategoryPath]; if (templatedParent != null) { dataTable.AttachTemplatedParent(templatedParent); } else { dataTable.AttachTemplatedParent(templateNamespace); } } else if (this.itemName != null) { var tableName = this.dataSet.GetTableName(element.QualifiedName.Namespace); var categoryPath = this.dataSet.GetTableCategoryPath(element.QualifiedName.Namespace); var templatedParent = this.dataSet.Tables[tableName, categoryPath]; if (dataTable != templatedParent) { if (templatedParent != null) { dataTable.AttachTemplatedParent(templatedParent); } else { dataTable.AttachTemplatedParent(element.QualifiedName.Namespace); } } } else if (complexType.ReadAppInfoAsString(CremaSchema.TableInfo, CremaSchema.TemplateNamespace) != null) { var templateNamespace = complexType.ReadAppInfoAsString(CremaSchema.TableInfo, CremaSchema.TemplateNamespace); dataTable.AttachTemplatedParent(templateNamespace); } else { var query = from item in this.dataSet.Tables where item.Parent == null where item != dataTable where item.TemplateNamespace == dataTable.Namespace select item; foreach (var item in query.ToArray()) { item.AttachTemplatedParent(dataTable); } } } } }