Ejemplo n.º 1
0
        private void WriteDataTable(XmlSchema schema, CremaDataTable dataTable)
        {
            var tableNamespace = schema.TargetNamespace;
            var complexType    = new XmlSchemaComplexType()
            {
                Name = dataTable.TableTypeName
            };

            complexType.WriteAppInfo(CremaSchema.TableInfo, CremaSchema.Creator, dataTable.CreationInfo.ID, tableNamespace);
            complexType.WriteAppInfo(CremaSchema.TableInfo, CremaSchema.CreatedDateTime, dataTable.CreationInfo.DateTime, tableNamespace);
            complexType.WriteAppInfo(CremaSchema.TableInfo, CremaSchema.Modifier, dataTable.ModificationInfo.ID, tableNamespace);
            complexType.WriteAppInfo(CremaSchema.TableInfo, CremaSchema.ModifiedDateTime, dataTable.ModificationInfo.DateTime, tableNamespace);
            complexType.WriteAppInfo(CremaSchema.TableInfo, CremaSchema.Tags, dataTable.Tags, tableNamespace);
            complexType.WriteAppInfo(CremaSchema.TableInfo, CremaSchema.ID, dataTable.TableID, tableNamespace);
            complexType.WriteAppInfo(CremaSchema.TableInfo, CremaSchema.CategoryPath, dataTable.CategoryPath, tableNamespace, PathUtility.Separator);
            complexType.WriteAppInfo(CremaSchema.TableInfo, CremaSchema.IgnoreCaseSensitive, dataTable.IgnoreCaseSensitive, tableNamespace, false);

            if (dataTable.TemplateNamespace != string.Empty)
            {
                complexType.WriteAppInfo(CremaSchema.TableInfo, CremaSchema.TemplateNamespace, dataTable.TemplateNamespace, tableNamespace);
            }

            complexType.WriteDescription(dataTable.Comment);

            if (this.itemName != null || dataTable.TemplateNamespace == string.Empty || dataTable.TemplatedParent == null)
            {
                var sequence = new XmlSchemaSequence();

                foreach (var item in dataTable.Attributes)
                {
                    if (item.IsVisible == false)
                    {
                        continue;
                    }
                    this.WriteAttribute(schema, complexType, item);
                }

                foreach (var item in dataTable.Columns)
                {
                    this.WriteDataColumn(schema, item);
                    this.WriteElement(schema, sequence, item);
                }

                if (dataTable.RelationColumn != null && dataTable.Parent == null)
                {
                    var attribute = new XmlSchemaAttribute()
                    {
                        Name           = CremaSchema.RelationID,
                        SchemaTypeName = GetSystemQualifiedName(typeof(string))
                    };
                    complexType.Attributes.Add(attribute);
                }

                foreach (var item in dataTable.Childs)
                {
                    this.WriteElement(schema, sequence, item);
                    this.WriteDataTable(schema, item);
                }

                complexType.Particle = sequence;
            }
            else
            {
                var content   = new XmlSchemaComplexContent();
                var extension = new XmlSchemaComplexContentExtension()
                {
                    BaseTypeName = new XmlQualifiedName(dataTable.TemplateTypeName, tableNamespace)
                };
                content.Content          = extension;
                complexType.ContentModel = content;
            }

            schema.Items.Add(complexType);
        }