private void Write47_XmlSchemaKey(XmlSchemaKey o) { if ((object)o == null) { return; } System.Type t = o.GetType(); WriteStartElement("key"); WriteAttribute(@"id", @"", ((System.String)o.@Id)); WriteAttribute(@"name", @"", ((System.String)o.@Name)); WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o); Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation); Write49_XmlSchemaXPath(@"selector", @"", (XmlSchemaXPath)o.@Selector); { XmlSchemaObjectCollection a = (XmlSchemaObjectCollection)o.@Fields; if (a != null) { for (int ia = 0; ia < a.Count; ia++) { Write49_XmlSchemaXPath(@"field", @"", (XmlSchemaXPath)a[ia]); } } } WriteEndElement(); }
public XmlScopeKeyData RegisterKey(XmlSchemaKey keyInfo) { var keyData = new XmlScopeKeyData(this, keyInfo); _keys.Add(keyData.Name, keyData); return(keyData); }
private void WriteKeys(XmlSchema schema, XmlSchemaElement element, CremaDataTable dataTable) { if (dataTable.PrimaryKey.Any() == false) { return; } var key = new XmlSchemaKey() { Name = dataTable.KeyTypeName, Selector = new XmlSchemaXPath() }; key.Selector.XPath = dataTable.GetSelectorXPath(CremaSchema.TableTypePrefix, schema.TargetNamespace); foreach (var item in dataTable.PrimaryKey) { var field = new XmlSchemaXPath() { XPath = CremaSchema.TableTypePrefix + ":" + item.ColumnName }; key.Fields.Add(field); } element.Constraints.Add(key); }
public XmlScopeKeyData RegisterKey(XmlSchemaKey schemaKeyInfo) { if (this.ScopeData == null) { this.ScopeData = new XmlScopeData(this); } return(this.ScopeData.RegisterKey(schemaKeyInfo)); }
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 static XmlSchemaIdentityConstraint FindKey(XmlSchemaKeyref xmlSchemaKeyref) { foreach (XmlSchemaObject xmlSchemaObject in GetXmlSchema(xmlSchemaKeyref).Items) { if (xmlSchemaObject is XmlSchemaElement) { XmlSchemaElement xmlSchemaElement = xmlSchemaObject as XmlSchemaElement; if (IsDataSetElement(xmlSchemaElement)) { XmlSchemaElement dataSetElement = xmlSchemaObject as XmlSchemaElement; foreach (XmlSchemaIdentityConstraint xmlSchemaIdentityConstraint in dataSetElement.Constraints) { if (xmlSchemaIdentityConstraint is XmlSchemaUnique) { XmlSchemaUnique xmlSchemaUnique = xmlSchemaIdentityConstraint as XmlSchemaUnique; if (xmlSchemaUnique.QualifiedName.Namespace == xmlSchemaKeyref.Refer.Namespace && xmlSchemaUnique.QualifiedName.Name == xmlSchemaKeyref.Refer.Name) { return(xmlSchemaUnique); } } if (xmlSchemaIdentityConstraint is XmlSchemaKey) { XmlSchemaKey xmlSchemaKey = xmlSchemaIdentityConstraint as XmlSchemaKey; if (xmlSchemaKey.QualifiedName.Namespace == xmlSchemaKeyref.Refer.Namespace && xmlSchemaKey.QualifiedName.Name == xmlSchemaKeyref.Refer.Name) { return(xmlSchemaKey); } } } } else { foreach (XmlSchemaIdentityConstraint xmlSchemaIdentityConstraint in xmlSchemaElement.Constraints) { if (xmlSchemaIdentityConstraint is XmlSchemaKey) { XmlSchemaKey xmlSchemaKey = xmlSchemaIdentityConstraint as XmlSchemaKey; if (xmlSchemaKey.QualifiedName.Namespace == xmlSchemaKeyref.Refer.Namespace && xmlSchemaKey.QualifiedName.Name == xmlSchemaKeyref.Refer.Name) { return(xmlSchemaKey); } } } } } } return(null); }
private void ReadKey(XmlSchemaKey key) { var dataTable = this.GetTable(key, CremaSchema.KeyTypeNameExtension); lock (CremaSchema.lockobj) { foreach (var item in key.GetFields()) { var columnName = item.XPath.Replace(CremaSchema.TableTypePrefix + ":", string.Empty); var dataColumn = dataTable.Columns[columnName]; dataColumn.InternalIsKey = true; } } }
private void Write47_XmlSchemaKey(XmlSchemaKey o) { if (o != null) { o.GetType(); this.WriteStartElement("key"); this.WriteAttribute("id", "", o.Id); this.WriteAttribute("name", "", o.Name); this.WriteAttributes(o.UnhandledAttributes, o); this.Write5_XmlSchemaAnnotation(o.Annotation); this.Write49_XmlSchemaXPath("selector", "", o.Selector); XmlSchemaObjectCollection fields = o.Fields; if (fields != null) { for (int i = 0; i < fields.Count; i++) { this.Write49_XmlSchemaXPath("field", "", (XmlSchemaXPath)fields[i]); } } this.WriteEndElement(); } }
public bool GetPrimaryKeyStatus(XmlSchemaIdentityConstraint xmlSchemaIdentityConstraint) { if (xmlSchemaIdentityConstraint is XmlSchemaUnique) { XmlSchemaUnique xmlSchemaUnique = xmlSchemaIdentityConstraint as XmlSchemaUnique; if (xmlSchemaUnique.UnhandledAttributes != null) { foreach (XmlAttribute xmlAttribute in xmlSchemaUnique.UnhandledAttributes) { if (xmlAttribute.NamespaceURI == KeySchema.primaryKeyAttributeName.Namespace && xmlAttribute.LocalName == KeySchema.primaryKeyAttributeName.Name) { return(Convert.ToBoolean(xmlAttribute.Value)); } } } } if (xmlSchemaIdentityConstraint is XmlSchemaKey) { XmlSchemaKey xmlSchemaKey = xmlSchemaIdentityConstraint as XmlSchemaKey; if (xmlSchemaKey.UnhandledAttributes != null) { foreach (XmlAttribute xmlAttribute in xmlSchemaKey.UnhandledAttributes) { if (xmlAttribute.NamespaceURI == KeySchema.primaryKeyAttributeName.Namespace && xmlAttribute.LocalName == KeySchema.primaryKeyAttributeName.Name) { return(Convert.ToBoolean(xmlAttribute.Value)); } } } } return(false); }
public static void Main() { XmlTextReader tr = new XmlTextReader("empty.xsd"); XmlSchema schema = XmlSchema.Read(tr, new ValidationEventHandler(ValidationCallback)); schema.ElementFormDefault = XmlSchemaForm.Qualified; schema.TargetNamespace = "http://www.example.com/Report"; { XmlSchemaElement element = new XmlSchemaElement(); element.Name = "purchaseReport"; XmlSchemaComplexType element_complexType = new XmlSchemaComplexType(); XmlSchemaSequence element_complexType_sequence = new XmlSchemaSequence(); { XmlSchemaElement element_complexType_sequence_element = new XmlSchemaElement(); element_complexType_sequence_element.Name = "region"; element_complexType_sequence_element.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema") ; { XmlSchemaKeyref element_complexType_sequence_element_keyref = new XmlSchemaKeyref(); element_complexType_sequence_element_keyref.Name = "dummy2"; element_complexType_sequence_element_keyref.Selector = new XmlSchemaXPath(); element_complexType_sequence_element_keyref.Selector.XPath = "r:zip/r:part"; { XmlSchemaXPath field = new XmlSchemaXPath(); field.XPath = "@number"; element_complexType_sequence_element_keyref.Fields.Add(field); } element_complexType_sequence_element_keyref.Refer = new XmlQualifiedName("pNumKey", "http://www.example.com/Report") ; element_complexType_sequence_element.Constraints.Add(element_complexType_sequence_element_keyref); } element_complexType_sequence.Items.Add(element_complexType_sequence_element); } element_complexType.Particle = element_complexType_sequence; { XmlSchemaAttribute element_complexType_attribute = new XmlSchemaAttribute(); element_complexType_attribute.Name = "periodEnding"; element_complexType_attribute.SchemaTypeName = new XmlQualifiedName("date", "http://www.w3.org/2001/XMLSchema") ; element_complexType.Attributes.Add(element_complexType_attribute); } element.SchemaType = element_complexType; { XmlSchemaKey element_key = new XmlSchemaKey(); element_key.Name = "pNumKey"; element_key.Selector = new XmlSchemaXPath(); element_key.Selector.XPath = "r:parts/r:part"; { XmlSchemaXPath field = new XmlSchemaXPath(); field.XPath = "@number"; element_key.Fields.Add(field); } element.Constraints.Add(element_key); } schema.Items.Add(element); } schema.Write(Console.Out); }/* Main() */
public KeySchema(DataModelSchema schema, XmlSchemaKey xmlSchemaKey) : base(schema, xmlSchemaKey) { // Initialize the object this.xmlSchemaKey = xmlSchemaKey; }
private static void Equal(XmlSchemaKey expected, XmlSchemaKey actual) { throw new NotImplementedException(); }
public XmlScopeKeyData(XmlScopeData scopeData, XmlSchemaKey keyInfo) { this.ScopeData = scopeData; this.KeyInfo = keyInfo; }
protected override void Visit(XmlSchemaKey key) { _writer.WriteConstraintRow(_context, ArtItem.Key, "Key", key); }
protected virtual void Visit(XmlSchemaKey key) { Traverse(key.Selector); Traverse(key.Fields); }