private CremaDataTable GetTable(XmlSchemaKey constraint, string extension) { if (this.version.Major == CremaSchema.MajorVersion) { var keyName = constraint.Name.Substring(0, constraint.Name.Length - extension.Length); if (this.itemName == null) { return(this.tables[keyName]); } else { var tableName = CremaDataSet.GetTableName(this.dataSet, constraint.QualifiedName.Namespace); if (keyName == tableName) { return(this.tables[this.itemName.Name]); } else { tableName = Regex.Replace(keyName, string.Format("(^{0})([.].*)", tableName), this.itemName.Name + "$2"); return(this.tables[tableName]); } } } else { var keyName = GetTableNameObsolete(constraint); if (this.itemName == null) { var tableName = CremaDataSet.GetTableName(CremaSchemaObsolete.TableNamespaceObsolete, constraint.QualifiedName.Namespace); var categoryPath = CremaDataSet.GetTableCategoryPath(CremaSchemaObsolete.TableNamespaceObsolete, constraint.QualifiedName.Namespace); if (keyName == tableName) { return(this.dataSet.Tables[tableName, categoryPath]); } else { return(this.dataSet.Tables[tableName + "." + keyName, categoryPath]); } } else { var tableName = CremaDataSet.GetTableName(CremaSchemaObsolete.TableNamespaceObsolete, constraint.QualifiedName.Namespace); var categoryPath = CremaDataSet.GetTableCategoryPath(CremaSchemaObsolete.TableNamespaceObsolete, constraint.QualifiedName.Namespace); if (keyName == tableName) { return(this.dataSet.Tables[itemName.Name, itemName.CategoryPath]); } else { return(this.dataSet.Tables[itemName.Name + "." + keyName, itemName.CategoryPath]); } } } throw new CremaDataException(); }
public CremaXmlReadInfo(string xmlPath) { if (FileUtility.IsAbsolute(xmlPath) == false) { throw new ArgumentException("\"${xmlPath}\" 은(는) 절대 경로가 아닙니다.", nameof(xmlPath)); } if (File.Exists(xmlPath) == false) { throw new FileNotFoundException($"\"{xmlPath}\" 경로를 찾을 수 없습니다."); } this.xmlPath = xmlPath; this.xsdPath = Path.ChangeExtension(xmlPath, CremaSchema.SchemaExtension); this.xmlSize = new FileInfo(xmlPath).Length; using (var reader = XmlReader.Create(this.xmlPath)) { reader.MoveToContent(); var text = reader.GetAttribute(CremaSchema.Version); if (string.IsNullOrEmpty(text) == false) { Version.TryParse(text, out this.version); } } if (File.Exists(this.xsdPath) == false) { using (var reader = XmlReader.Create(xmlPath)) { reader.MoveToContent(); if (Version.TryParse(reader.GetAttribute(CremaSchema.Version), out Version version) == false) { version = new Version(2, 0); } if (version.Major == CremaSchema.MajorVersion) { FindSchemaLocation(reader, xmlPath, out this.xsdPath, out string tableNamespace); var categoryPath = CremaDataSet.GetTableCategoryPath(CremaSchema.TableNamespace, tableNamespace); var tableName = CremaDataSet.GetTableName(CremaSchema.TableNamespace, tableNamespace); this.itemName = new ItemName(categoryPath, tableName); } else { FindSchemaLocationVersion2(reader, xmlPath, out this.xsdPath, out string tableNamespace); var categoryPath = CremaDataSet.GetTableCategoryPath(CremaSchemaObsolete.TableNamespaceObsolete, tableNamespace); var tableName = CremaDataSet.GetTableName(CremaSchemaObsolete.TableNamespaceObsolete, tableNamespace); this.itemName = new ItemName(categoryPath, tableName); } } this.isInherited = true; } this.relativeXsdPath = UriUtility.MakeRelative(this.xmlPath, this.xsdPath); }
private void InitializeTables(XmlReader reader) { if (this.dataSet != null) { this.tables = new Dictionary <string, CremaDataTable>(this.dataSet.Tables.Count); if (itemName != null) { var dataTable = this.dataSet.Tables[itemName.Name, itemName.CategoryPath]; var items = EnumerableUtility.Friends(dataTable, dataTable.Childs); foreach (var item in items) { this.tables.Add(item.Name, item); } } else if (reader.NamespaceURI == this.dataSet.Namespace) { this.tables = new Dictionary <string, CremaDataTable>(this.dataSet.Tables.Count); foreach (var item in this.dataSet.Tables) { this.tables.Add(item.Name, item); } } else { var categoryPath = CremaDataSet.GetTableCategoryPath(this.dataSet, reader.NamespaceURI); var tableName = CremaDataSet.GetTableName(this.dataSet, reader.NamespaceURI); var dataTable = this.dataSet.Tables[tableName, categoryPath]; var items = EnumerableUtility.Friends(dataTable, dataTable.Childs); foreach (var item in items) { this.tables.Add(item.Name, item); } } } else { var items = EnumerableUtility.Friends(this.dataTable, this.dataTable.Childs); this.tables = new Dictionary <string, CremaDataTable>(items.Count()); foreach (var item in items) { this.tables.Add(item.Name, item); } } foreach (var item in this.tables) { if (item.Value.Rows.Count > 0) { throw new CremaDataException("'{0}'은(는) 데이터가 존재하기 때문에 읽어들일 수 없습니다.", item.Value.TableName); } } }
private void ReadHeaderInfo(XmlReader reader) { if (this.version.Major < CremaSchema.MajorVersion) { this.ReadHeaderInfoVersion2(reader); return; } var baseNamespace = this.dataSet != null ? this.dataSet.Namespace : CremaSchema.BaseNamespace; if (reader.NamespaceURI == baseNamespace) { foreach (var item in this.dataSet.Tables) { var user = item.Name + CremaSchema.ModifierExtension; var dateTime = item.Name + CremaSchema.ModifiedDateTimeExtension; var count = item.Name + CremaSchema.CountExtension; var id = item.Name + CremaSchema.IDExtension; item.MinimumCapacity = reader.GetAttributeAsInt32(count); item.InternalContentsInfo = reader.GetAttributeAsModificationInfo(user, dateTime); item.InternalTableID = reader.GetAttributeAsGuid(id); } } else if (this.itemName == null) { var categoryPath = CremaDataSet.GetTableCategoryPath(this.dataSet, reader.NamespaceURI); var tableName = CremaDataSet.GetTableName(this.dataSet, reader.NamespaceURI); var dataTable = this.dataTable ?? this.dataSet.Tables[tableName, categoryPath]; foreach (var item in EnumerableUtility.Friends(dataTable, dataTable.Childs)) { var user = item.Name + CremaSchema.ModifierExtension; var dateTime = item.Name + CremaSchema.ModifiedDateTimeExtension; var count = item.Name + CremaSchema.CountExtension; var id = item.Name + CremaSchema.IDExtension; item.MinimumCapacity = reader.GetAttributeAsInt32(count); item.InternalContentsInfo = reader.GetAttributeAsModificationInfo(user, dateTime); item.InternalTableID = reader.GetAttributeAsGuid(id); } } else { var tableNamespace = CremaSchema.TableNamespace + this.itemName.CategoryPath + this.itemName.Name; var dataTable = this.dataTable ?? this.dataSet.Tables[this.itemName.Name, this.itemName.CategoryPath]; if (reader.NamespaceURI != tableNamespace) { var creationInfo = reader.GetAttributeAsModificationInfo(CremaSchema.Creator, CremaSchema.CreatedDateTime); dataTable.InternalCreationInfo = creationInfo; } foreach (var item in EnumerableUtility.Friends(dataTable, dataTable.Childs)) { var serializableName = item.GetXmlPath(reader.NamespaceURI); var user = serializableName + CremaSchema.ModifierExtension; var dateTime = serializableName + CremaSchema.ModifiedDateTimeExtension; var count = serializableName + CremaSchema.CountExtension; var id = serializableName + CremaSchema.IDExtension; item.MinimumCapacity = reader.GetAttributeAsInt32(count); item.InternalContentsInfo = reader.GetAttributeAsModificationInfo(user, dateTime); item.InternalTableID = reader.GetAttributeAsGuid(id); } } }
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); } } } } }