void Write50_XmlSchemaKeyref(XmlSchemaKeyref o) { if ((object)o == null) { return; } System.Type t = o.GetType(); WriteStartElement("keyref"); WriteAttribute(@"id", @"", ((System.String)o.@Id)); WriteAttribute(@"name", @"", ((System.String)o.@Name)); WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o); // WriteAttribute(@"refer", @"", o.@Refer); 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 KeyrefSchema(DataModelSchema dataModelSchema, XmlSchemaKeyref xmlSchemaKeyref) : base(dataModelSchema, xmlSchemaKeyref) { // Initialize the object this.xmlSchemaKeyref = xmlSchemaKeyref; this.Refer = GetRefer(xmlSchemaKeyref); }
/// <summary> /// Create a foreign key constraint on two tables. /// </summary> /// <param name="dataModelSchema">The parent data model schema.</param> /// <param name="xmlSchemaKeyref">The XmlSchema object that describes the foreignn key relation.</param> public RelationSchema(DataModelSchema dataModelSchema, XmlSchemaKeyref xmlSchemaKeyref) { // Initialize the object. this.name = xmlSchemaKeyref.Name; // This will search through each of the tables looking for the parent and child components of the relation. foreach (KeyValuePair <string, TableSchema> keyValuePair in dataModelSchema.Tables) { ConstraintSchema constraintSchema; // This is the parent component of the relation. if (keyValuePair.Value.Constraints.TryGetValue(xmlSchemaKeyref.Refer.Name, out constraintSchema)) { UniqueConstraintSchema uniqueConstraintSchema = constraintSchema as UniqueConstraintSchema; this.parentColumns = uniqueConstraintSchema.Columns; this.parentTable = uniqueConstraintSchema.Table; this.parentKeyConstraint = uniqueConstraintSchema; } // This is the child part of the relation. if (keyValuePair.Value.Constraints.TryGetValue(xmlSchemaKeyref.Name, out constraintSchema)) { ForeignKeyConstraintSchema foreignKeyConstraintSchema = constraintSchema as ForeignKeyConstraintSchema; this.childTable = foreignKeyConstraintSchema.Table; this.childColumns = foreignKeyConstraintSchema.Columns; this.childKeyConstraint = foreignKeyConstraintSchema; } } }
/// <summary> /// Create a foreign key constraint on two tables. /// </summary> /// <param name="dataModelSchema">The parent data model schema.</param> /// <param name="xmlSchemaKeyref">The XmlSchema object that describes the foreignn key relation.</param> public ForeignKeyConstraintSchema(DataModelSchema dataModelSchema, XmlSchemaKeyref xmlSchemaKeyref) : base(dataModelSchema, xmlSchemaKeyref) { // This will search through each of the tables looking for a key that matches the name of the reference. Note that // there is no checking to make sure the 'Refer' key exists. If it didn't exist, the XmlSchema would have caught it // and never have validated the schema. foreach (KeyValuePair <string, TableSchema> keyValuePair in dataModelSchema.Tables) { ConstraintSchema constraintSchema; if (keyValuePair.Value.Constraints.TryGetValue(xmlSchemaKeyref.Refer.Name, out constraintSchema)) { this.relatedTable = constraintSchema.Table; this.relatedColumns = constraintSchema.Columns; } } // Parse the cascading update rule out of the keyref specification. XmlAttribute updateRuleAttribute = ObjectSchema.GetUnhandledAttribute(xmlSchemaKeyref, QualifiedName.UpdateRule); this.updateRule = updateRuleAttribute == null ? CascadeRules.Cascade : (CascadeRules)Enum.Parse(typeof(CascadeRules), updateRuleAttribute.Value); // Parse the cascading delete rule out of the keyref specification. XmlAttribute deleteRuleAttribute = ObjectSchema.GetUnhandledAttribute(xmlSchemaKeyref, QualifiedName.DeleteRule); this.deleteRule = deleteRuleAttribute == null ? CascadeRules.Cascade : (CascadeRules)Enum.Parse(typeof(CascadeRules), deleteRuleAttribute.Value); }
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); }
public void Reset(XmlSchemaIdentityConstraint source) { this.source = source; this.selector = source.CompiledSelector; this.qname = source.QualifiedName; XmlSchemaKeyref xmlSchemaKeyref = source as XmlSchemaKeyref; if (xmlSchemaKeyref != null) { this.refKeyName = xmlSchemaKeyref.Refer; } this.StartDepth = 0; }
public XmlScopeKeyData FindKey(XmlSchemaKeyref schemaKeyRefInfo) { XmlScopeKeyData result; var element = this; do { result = element.ScopeData?.FindKey(schemaKeyRefInfo); element = element.ParentNode as MyXmlElement; } while (result == null && element != null); return(result); }
private ConstraintSchema GetRefer(XmlSchemaKeyref xmlSchemaKeyref) { foreach (TableSchema tableSchema in this.DataModelSchema.Tables) { foreach (ConstraintSchema constraintSchema in tableSchema.Constraints) { if (constraintSchema is KeySchema || constraintSchema is UniqueSchema && constraintSchema.QualifiedName == xmlSchemaKeyref.Refer) { return(constraintSchema); } } } return(null); }
/// <summary> /// The foreign constraints can only be evaluated after all the tables, keys and unique constraints have been evaluated. /// </summary> /// <param name="xmlSchema"></param> private void SecondPass(XmlSchemaSet xmlSchemaSet) { // This is the second pass through the schemas. Once the tables, keys and unique constraints have been evaluated, // then the foreign constraints can be constructed and applied to the parent and child tables. foreach (XmlSchemaElement xmlSchemaElement in xmlSchemaSet.GlobalElements.Values) { // Only the Microsoft DataSet element is evaluated for foreign keys. if (ObjectSchema.IsDataSetElement(xmlSchemaElement)) { // This will examine each of the constraints looking for a foreign key description. foreach (XmlSchemaIdentityConstraint xmlSchemaIdentityConstraint in xmlSchemaElement.Constraints) { // Evaluate the foreign keys in the data model. if (xmlSchemaIdentityConstraint is XmlSchemaKeyref) { // This object can be used as a foreign key constraint and, optionally, can be used to describe a // parent/child relationship. XmlSchemaKeyref xmlSchemaKeyref = xmlSchemaIdentityConstraint as XmlSchemaKeyref; // This creates a foreign key. ForeignKeyConstraintSchema foreignKeyConstraintSchema = new ForeignKeyConstraintSchema(this, xmlSchemaIdentityConstraint as XmlSchemaKeyref); // Foreign constraint schemas are always added to the list of constraints on a table. They can also // conditionally become the source for a relationship between two tables. foreignKeyConstraintSchema.Table.Add(foreignKeyConstraintSchema); // Unless specifically instructed to supress the relation, it will be created add added to both the // parent and child tables as well as the data model. XmlAttribute isConstraintOnlyAttribute = ObjectSchema.GetUnhandledAttribute(xmlSchemaIdentityConstraint, QualifiedName.ConstraintOnly); if (isConstraintOnlyAttribute == null || !Convert.ToBoolean(isConstraintOnlyAttribute.Value)) { RelationSchema relationSchema = new RelationSchema(this, xmlSchemaKeyref); relationSchema.ParentTable.ChildRelations.Add(relationSchema.Name, relationSchema); relationSchema.ChildTable.ParentRelations.Add(relationSchema.Name, relationSchema); this.Relations.Add(relationSchema.Name, relationSchema); } } } } } }
private void Write50_XmlSchemaKeyref(XmlSchemaKeyref o) { if (o != null) { o.GetType(); this.WriteStartElement("keyref"); this.WriteAttribute("id", "", o.Id); this.WriteAttribute("name", "", o.Name); this.WriteAttributes(o.UnhandledAttributes, o); this.WriteAttribute("refer", "", o.Refer); 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(); } }
/// <summary> /// Creates a Update Method for a table having an automatically generated identity key. /// </summary> /// <param name="this.ParentClass"></param> private void UpdateWithBase() { // These variables are used in serveral places to describe the table, columns and variables. string internalNamespaceName = this.ExternalInterfaceSchema.InternalNamespace; // Declare the method: // /// <summary>Updates a Algorithm record using Metadata Parameters.</summary> // /// <param name="parameters">Contains the metadata parameters for this method.</param> // public static void Update(ParameterList parameters) // { this.Comments.Add(new CodeCommentStatement(string.Format("<summary>Updates a {0} record using Metadata Parameters.</summary>", this.MiddleTierTable.ElementTable.Name), true)); this.Comments.Add(new CodeCommentStatement(@"<param name=""transaction"">Contains the parameters and exceptions for this command.</param>", true)); this.Attributes = MemberAttributes.Public | MemberAttributes.Final | MemberAttributes.New | MemberAttributes.Static; this.Name = "Update"; this.Parameters.Add(new CodeParameterDeclarationExpression("ParameterList", "parameters")); // These are shorthand notations for values that are use often to construct the tables: string tableVariable = string.Format("{0}Table", this.MiddleTierTable.ElementTable.Name[0].ToString().ToLower() + this.MiddleTierTable.ElementTable.Name.Remove(0, 1)); string rowVariable = string.Format("{0}Row", this.MiddleTierTable.ElementTable.Name[0].ToString().ToLower() + this.MiddleTierTable.ElementTable.Name.Remove(0, 1)); string tableTypeName = string.Format("{0}.{1}DataTable", this.ExternalInterfaceSchema.DataSetName, this.MiddleTierTable.ElementTable.Name); // Find the primary column element. XmlSchemaElement elementPrimaryColumn = null; foreach (XmlSchemaElement xmlSchemaElement in this.MiddleTierTable.ElementColumns) { if (xmlSchemaElement.Name == this.ExternalInterfaceSchema.RemoveXPath(this.MiddleTierTable.PrimaryKey.Fields[0])) { elementPrimaryColumn = xmlSchemaElement; } } string primaryVariableName = elementPrimaryColumn.Name[0].ToString().ToLower() + elementPrimaryColumn.Name.Remove(0, 1); // Get an accessor to the table schema information. This makes accessing information about the table much faster as // it doesn't need to do the lock checking each time it references the table. // // Accessor for the Algorithm Table. // ServerMarketData.AlgorithmDataTable algorithmTable = ServerMarketData.Algorithm; this.Statements.Add(new CodeCommentStatement(string.Format("Accessor for the {0} Table.", this.MiddleTierTable.ElementTable.Name))); this.Statements.Add(new CodeVariableDeclarationStatement(new CodeTypeReference(tableTypeName), tableVariable, new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(this.ExternalInterfaceSchema.DataSetName), this.MiddleTierTable.ElementTable.Name))); // Initialize each parameter to the 'Update' method from the command batch. // // Extract the parameters from the command batch. // string configurationId = method.Parameters["configurationId"]; // string externalAlgorithmId = (System.String)method.Parameters["algorithmId"]; // string externalAlgorithmTypeCode = (System.String)method.Parameters["algorithmTypeCode"]; // string name = (System.String)method.Parameters["name"]; // object description = method.Parameters["description"]; // string assembly = (System.String)method.Parameters["assembly"]; // string type = (System.String)method.Parameters["type"]; // string method = (System.String)method.Parameters["transaction"]; this.Statements.Add(new CodeCommentStatement("Extract the parameters from the command batch.")); this.Statements.Add(new CodeVariableDeclarationStatement("AdoTransaction", "adoTransaction", new CodeArrayIndexerExpression(new CodeArgumentReferenceExpression("parameters"), new CodeExpression[] { new CodePrimitiveExpression("adoTransaction") }))); this.Statements.Add(new CodeVariableDeclarationStatement("SqlTransaction", "sqlTransaction", new CodeArrayIndexerExpression(new CodeArgumentReferenceExpression("parameters"), new CodeExpression[] { new CodePrimitiveExpression("sqlTransaction") }))); if (this.MiddleTierTable.ElementTable.Name != "Configuration") { this.Statements.Add(new CodeVariableDeclarationStatement(typeof(object), "configurationId", new CodeFieldReferenceExpression(new CodeArrayIndexerExpression(new CodeArgumentReferenceExpression("parameters"), new CodeExpression[] { new CodePrimitiveExpression("configurationId") }), "Value"))); } foreach (XmlSchemaElement elementColumn in this.MiddleTierTable.ElementColumns) { if (!this.ExternalInterfaceSchema.IsIdentityColumn(this.MiddleTierTable.ElementBaseTable, elementColumn) && elementColumn.FixedValue == null && elementColumn.Name != "RowVersion" && elementColumn.Name.IndexOf("ExternalId") == -1) { bool isExternalIdColumn = this.ExternalInterfaceSchema.IsExternalIdColumn(this.MiddleTierTable.ElementTable, elementColumn); bool isPrimaryKeyColumn = this.ExternalInterfaceSchema.IsPrimaryKeyColumn(this.MiddleTierTable.ElementTable, elementColumn); Type typeParameter = ((XmlSchemaDatatype)elementColumn.ElementType).ValueType; Type typeVariable = isPrimaryKeyColumn ? (isExternalIdColumn ? typeof(string) : typeParameter) : typeof(object); string parameterName = elementColumn.Name[0].ToString().ToLower() + elementColumn.Name.Remove(0, 1); string variableName = isExternalIdColumn ? string.Format("external{0}", elementColumn.Name) : parameterName; if (typeVariable == typeof(object)) { this.Statements.Add(new CodeVariableDeclarationStatement(typeVariable, variableName, new CodeFieldReferenceExpression(new CodeArrayIndexerExpression(new CodeArgumentReferenceExpression("parameters"), new CodeExpression[] { new CodePrimitiveExpression(parameterName) }), "Value"))); } else { this.Statements.Add(new CodeVariableDeclarationStatement(typeVariable, variableName, new CodeCastExpression(typeof(string), new CodeArrayIndexerExpression(new CodeArgumentReferenceExpression("parameters"), new CodeExpression[] { new CodePrimitiveExpression(parameterName) })))); } } } // Declare a rowVersion // // The row versioning is largely disabled for external operations. The value is returned to the caller in the // // event it's needed for operations within the batch. // long rowVersion = long.MinValue; this.Statements.Add(new CodeCommentStatement("The row versioning is largely disabled for external operations. The value is returned to the caller in the")); this.Statements.Add(new CodeCommentStatement("event it's needed for operations within the batch.")); this.Statements.Add(new CodeVariableDeclarationStatement(typeof(long), "rowVersion", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(long)), "MinValue"))); // Resolve External Identifiers // // Resolve External Identifiers // int internalAlgorithmTypeCode = AlgorithmType.FindRequiredKey(configurationId, algorithmTypeCode); bool hasExternalKeyComment = false; foreach (XmlSchemaElement elementColumn in this.MiddleTierTable.ElementColumns) { if (!this.ExternalInterfaceSchema.IsPrimaryKeyColumn(this.MiddleTierTable.ElementBaseTable, elementColumn) && elementColumn.FixedValue == null) { // Primary key columns are required variables. bool isPrimaryKeyColumn = this.ExternalInterfaceSchema.IsPrimaryKeyColumn(this.MiddleTierTable.ElementTable, elementColumn); // This will determine if a key value can be used to look up an external user id. XmlSchemaKeyref keyrefSource = null; foreach (XmlSchemaKeyref innerKeyref in this.ExternalInterfaceSchema.GetParentKeys(this.MiddleTierTable.ElementTable)) { if (this.ExternalInterfaceSchema.RemoveXPath(innerKeyref.Fields[0]) == elementColumn.Name) { keyrefSource = innerKeyref; } } XmlSchemaIdentityConstraint keySource = keyrefSource == null ? (isPrimaryKeyColumn ? this.MiddleTierTable.PrimaryKey : null) : this.ExternalInterfaceSchema.FindKey(keyrefSource.Refer.Name); if (keySource != null && keySource.Fields.Count == 1) { XmlSchemaElement elementSourceTable = this.ExternalInterfaceSchema.FindTable(this.ExternalInterfaceSchema.RemoveXPath(keySource.Selector)); XmlSchemaObject elementSourceColumn = this.ExternalInterfaceSchema.FindColumn(elementSourceTable.Name, this.ExternalInterfaceSchema.RemoveXPath(keySource.Fields[0])); bool isExternalIdColumn = this.ExternalInterfaceSchema.IsExternalIdColumn(elementSourceTable, elementSourceColumn); // If a source table exists for the key value, the add an instruction to look up the internal identifier. if (isExternalIdColumn) { // Display a comment for the first external lookup issued. if (!hasExternalKeyComment) { this.Statements.Add(new CodeCommentStatement("Resolve External Identifiers")); hasExternalKeyComment = true; } Type typeVariable = isPrimaryKeyColumn ? ((XmlSchemaDatatype)elementColumn.ElementType).ValueType : typeof(object); string externalVariableName = string.Format("external{0}", elementColumn.Name); string variableName = elementColumn.Name[0].ToString().ToLower() + elementColumn.Name.Remove(0, 1); string className = this.ExternalInterfaceSchema.RemoveXPath(keySource.Selector); string methodName = isPrimaryKeyColumn ? "FindRequiredKey" : "FindOptionalKey"; this.Statements.Add(new CodeVariableDeclarationStatement(typeVariable, variableName, new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(className), methodName, new CodeExpression[] { new CodeVariableReferenceExpression("configurationId"), new CodePrimitiveExpression(variableName), new CodeVariableReferenceExpression(externalVariableName) }))); } } } } // // This disables the concurrency checking logic by finding the current row version and passing it to the // // internal method. // ServerMarketData.LoginRow loginRow = loginTable.FindByLoginId(loginId); // rowVersion = ((long)(loginRow[loginTable.RowVersionColumn])); this.Statements.Add(new CodeCommentStatement("This disables the concurrency checking logic by finding the current row version and passing it to the")); this.Statements.Add(new CodeCommentStatement("internal method.")); string keyColumns = string.Empty; string exeptionFormat = string.Empty; CodeExpression[] keyVariables = new CodeExpression[this.MiddleTierTable.PrimaryKey.Fields.Count]; CodeExpression[] exceptionVariables = new CodeExpression[this.MiddleTierTable.PrimaryKey.Fields.Count + 1]; for (int index = 0; index < this.MiddleTierTable.PrimaryKey.Fields.Count; index++) { string columnName = this.ExternalInterfaceSchema.RemoveXPath(this.MiddleTierTable.PrimaryKey.Fields[index]); string variableName = columnName[0].ToString().ToLower() + columnName.Remove(0, 1); keyColumns += columnName; exeptionFormat += string.Format("{{0}}", index); keyVariables[index] = new CodeVariableReferenceExpression(variableName); exceptionVariables[index + 1] = new CodeVariableReferenceExpression(variableName); } this.Statements.Add(new CodeVariableDeclarationStatement(string.Format("{0}.{1}Row", this.ExternalInterfaceSchema.DataSetName, this.MiddleTierTable.ElementTable.Name), rowVariable, new CodeMethodInvokeExpression(new CodeArgumentReferenceExpression(tableVariable), string.Format("FindBy{0}", keyColumns), keyVariables))); this.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("rowVersion"), new CodeCastExpression(typeof(long), new CodeArrayIndexerExpression(new CodeVariableReferenceExpression(rowVariable), new CodeExpression[] { new CodeFieldReferenceExpression(new CodeVariableReferenceExpression(tableVariable), "RowVersionColumn") })))); // Call the internal 'Update' method with the metadata parameters, the resolved parent keys and the current row version. // // Call the internal method to complete the operation. // Shadows.Web.Service.Algorithm.Update(transaction, algorithmId, algorithmTypeCode, ref rowVersion, name, description, assembly, type, method, externalId0, externalId1); CodeExpressionCollection updateArgs = new CodeExpressionCollection(); updateArgs.Add(new CodeArgumentReferenceExpression("adoTransaction")); updateArgs.Add(new CodeArgumentReferenceExpression("sqlTransaction")); updateArgs.Add(new CodeDirectionExpression(FieldDirection.Ref, new CodeVariableReferenceExpression("rowVersion"))); foreach (XmlSchemaElement elementColumn in this.MiddleTierTable.ElementColumns) { if (!this.ExternalInterfaceSchema.IsPrimaryKeyColumn(this.MiddleTierTable.ElementBaseTable, elementColumn) && elementColumn.FixedValue == null) { if (elementColumn.Name.IndexOf("ExternalId") != -1) { updateArgs.Add(new CodePrimitiveExpression(null)); } else { updateArgs.Add(new CodeVariableReferenceExpression(elementColumn.Name[0].ToString().ToLower() + elementColumn.Name.Remove(0, 1))); } } } CodeExpression[] updateArgArray = new CodeExpression[updateArgs.Count]; updateArgs.CopyTo(updateArgArray, 0); this.Statements.Add(new CodeCommentStatement("Call the internal method to complete the operation.")); this.Statements.Add(new CodeMethodInvokeExpression(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(internalNamespaceName), this.MiddleTierTable.ElementTable.Name), "Update", updateArgArray)); // The Return parameters. // // Return values. // method.Parameters.ReturnValue("rowVersion", rowVersion); this.Statements.Add(new CodeCommentStatement("Return values.")); this.Statements.Add(new CodeAssignStatement(new CodeArrayIndexerExpression(new CodeArgumentReferenceExpression("parameters"), new CodeExpression[] { new CodePrimitiveExpression("rowVersion") }), new CodeVariableReferenceExpression("rowVersion"))); }
protected virtual void Visit(XmlSchemaKeyref keyref) { Traverse(keyref.Selector); Traverse(keyref.Fields); }
static void Check(ConformanceCheckContext ctx, ConformanceChecker checker, Hashtable visitedObjects, XmlSchemaObject value) { if (value == null) { return; } if (visitedObjects.Contains(value)) { return; } visitedObjects.Add(value, value); if (value is XmlSchemaImport) { XmlSchemaImport so = (XmlSchemaImport)value; checker.Check(ctx, so); } else if (value is XmlSchemaAll) { XmlSchemaAll so = (XmlSchemaAll)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Items); } else if (value is XmlSchemaAnnotation) { XmlSchemaAnnotation so = (XmlSchemaAnnotation)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Items); } else if (value is XmlSchemaAttribute) { XmlSchemaAttribute so = (XmlSchemaAttribute)value; checker.Check(ctx, so); } else if (value is XmlSchemaAttributeGroup) { XmlSchemaAttributeGroup so = (XmlSchemaAttributeGroup)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Attributes); Check(ctx, checker, visitedObjects, so.AnyAttribute); Check(ctx, checker, visitedObjects, so.RedefinedAttributeGroup); } else if (value is XmlSchemaAttributeGroupRef) { XmlSchemaAttributeGroupRef so = (XmlSchemaAttributeGroupRef)value; checker.Check(ctx, so); } else if (value is XmlSchemaChoice) { XmlSchemaChoice so = (XmlSchemaChoice)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Items); } else if (value is XmlSchemaComplexContent) { XmlSchemaComplexContent so = (XmlSchemaComplexContent)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.Content); } else if (value is XmlSchemaComplexContentExtension) { XmlSchemaComplexContentExtension so = (XmlSchemaComplexContentExtension)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.Particle); CheckObjects(ctx, checker, visitedObjects, so.Attributes); Check(ctx, checker, visitedObjects, so.AnyAttribute); } else if (value is XmlSchemaComplexContentRestriction) { XmlSchemaComplexContentRestriction so = (XmlSchemaComplexContentRestriction)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.Particle); CheckObjects(ctx, checker, visitedObjects, so.Attributes); Check(ctx, checker, visitedObjects, so.AnyAttribute); } else if (value is XmlSchemaComplexType) { XmlSchemaComplexType so = (XmlSchemaComplexType)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.ContentModel); Check(ctx, checker, visitedObjects, so.Particle); CheckObjects(ctx, checker, visitedObjects, so.Attributes); Check(ctx, checker, visitedObjects, so.AnyAttribute); Check(ctx, checker, visitedObjects, so.ContentTypeParticle); Check(ctx, checker, visitedObjects, so.AttributeWildcard); } else if (value is XmlSchemaElement) { XmlSchemaElement so = (XmlSchemaElement)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.SchemaType); CheckObjects(ctx, checker, visitedObjects, so.Constraints); } else if (value is XmlSchemaGroup) { XmlSchemaGroup so = (XmlSchemaGroup)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.Particle); } else if (value is XmlSchemaGroupRef) { XmlSchemaGroupRef so = (XmlSchemaGroupRef)value; checker.Check(ctx, so); } else if (value is XmlSchemaIdentityConstraint) { XmlSchemaIdentityConstraint so = (XmlSchemaIdentityConstraint)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Fields); Check(ctx, checker, visitedObjects, so.Selector); } else if (value is XmlSchemaKeyref) { XmlSchemaKeyref so = (XmlSchemaKeyref)value; checker.Check(ctx, so); } else if (value is XmlSchemaRedefine) { XmlSchemaRedefine so = (XmlSchemaRedefine)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Items); } else if (value is XmlSchemaSequence) { XmlSchemaSequence so = (XmlSchemaSequence)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Items); } else if (value is XmlSchemaSimpleContent) { XmlSchemaSimpleContent so = (XmlSchemaSimpleContent)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.Content); } else if (value is XmlSchemaSimpleContentExtension) { XmlSchemaSimpleContentExtension so = (XmlSchemaSimpleContentExtension)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Attributes); Check(ctx, checker, visitedObjects, so.AnyAttribute); } else if (value is XmlSchemaSimpleContentRestriction) { XmlSchemaSimpleContentRestriction so = (XmlSchemaSimpleContentRestriction)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Attributes); Check(ctx, checker, visitedObjects, so.AnyAttribute); CheckObjects(ctx, checker, visitedObjects, so.Facets); } else if (value is XmlSchemaSimpleType) { XmlSchemaSimpleType so = (XmlSchemaSimpleType)value; checker.Check(ctx, so); Check(ctx, checker, visitedObjects, so.Content); } else if (value is XmlSchemaSimpleTypeList) { XmlSchemaSimpleTypeList so = (XmlSchemaSimpleTypeList)value; checker.Check(ctx, so); } else if (value is XmlSchemaSimpleTypeRestriction) { XmlSchemaSimpleTypeRestriction so = (XmlSchemaSimpleTypeRestriction)value; checker.Check(ctx, so); CheckObjects(ctx, checker, visitedObjects, so.Facets); } else if (value is XmlSchemaSimpleTypeUnion) { XmlSchemaSimpleTypeUnion so = (XmlSchemaSimpleTypeUnion)value; checker.Check(ctx, so); } }
public XmlSchemaComplexType FindBaseType(XmlSchemaObject baseObject) { if (baseObject is XmlSchemaComplexContentExtension) { XmlSchemaComplexContentExtension baseComplexContentExtension = baseObject as XmlSchemaComplexContentExtension; return(FindComplexType(baseComplexContentExtension)); } if (baseObject is XmlSchemaComplexType) { XmlSchemaComplexType baseComplexType = baseObject as XmlSchemaComplexType; if (baseComplexType.Parent is XmlSchemaElement) { XmlSchemaElement baseElement = baseComplexType.Parent as XmlSchemaElement; XmlSchemaIdentityConstraint primaryKey = FindPrimaryKey(baseElement); if (primaryKey == null) { return(null); } foreach (XmlSchemaObject xmlSchemaObject in RootSchema.Items) { if (xmlSchemaObject is XmlSchemaElement) { if (IsDataSetElement(xmlSchemaObject)) { XmlSchemaElement dataSetElement = xmlSchemaObject as XmlSchemaElement; foreach (XmlSchemaIdentityConstraint xmlSchemaIdentityConstraint in dataSetElement.Constraints) { if (xmlSchemaIdentityConstraint is XmlSchemaKeyref) { XmlSchemaKeyref xmlSchemaKeyref = xmlSchemaIdentityConstraint as XmlSchemaKeyref; if (this.FindSelector(xmlSchemaKeyref) == baseElement) { bool isMatch = xmlSchemaKeyref.Fields.Count == primaryKey.Fields.Count; for (int index = 0; index < xmlSchemaKeyref.Fields.Count; index++) { XmlSchemaXPath xPath1 = (XmlSchemaXPath)xmlSchemaKeyref.Fields[index]; XmlSchemaXPath xPath2 = (XmlSchemaXPath)primaryKey.Fields[index]; if (xPath1.XPath != xPath2.XPath) { isMatch = false; break; } } if (isMatch) { XmlSchemaIdentityConstraint xmlSchemaKey = FindKey(xmlSchemaKeyref); XmlSchemaElement xmlSchemaElement = FindSelector(xmlSchemaKey); return(xmlSchemaElement.SchemaType as XmlSchemaComplexType); } } } } } else { XmlSchemaElement tableElement = xmlSchemaObject as XmlSchemaElement; foreach (XmlSchemaIdentityConstraint xmlSchemaIdentityConstraint in tableElement.Constraints) { } } } } return(null); } } return(null); }
protected override void Visit(XmlSchemaKeyref keyref) { _writer.WriteConstraintRow(_context, ArtItem.KeyRef, "Key Reference", keyref); }
public KeyrefSchema(DataModelSchema schema, XmlSchemaKeyref xmlSchemaKeyref) : base(schema, xmlSchemaKeyref) { // Initialize the object this.xmlSchemaKeyref = xmlSchemaKeyref; }
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 virtual void Check(ConformanceCheckContext ctx, XmlSchemaKeyref value) { }
private static void Equal(XmlSchemaKeyref expected, XmlSchemaKeyref actual) { throw new NotImplementedException(); }
public XmlScopeKeyData FindKey(XmlSchemaKeyref schemaKeyRefInfo) { return(_keys.TryGetValue(schemaKeyRefInfo.Refer.Name, out var keyData) ? keyData : null); }
public override void Check(ConformanceCheckContext ctx, XmlSchemaKeyref value) { CheckSchemaQName(ctx, value, value.Refer); }
private void handleObject(XmlSchemaObject o) { string str = "unknown"; XmlSchemaObjectCollection children = new XmlSchemaObjectCollection(); if (o is XmlSchema) { str = "root"; children = ((XmlSchema)o).Items; } else if (o is XmlSchemaComplexType) { XmlSchemaComplexType type = (XmlSchemaComplexType)o; startNewDbFile(type); str = type.Name; children = type.Attributes; infos = new List <TypeInfo> (); } else if (o is XmlSchemaAttribute) { XmlSchemaAttribute attribute = (XmlSchemaAttribute)o; addDbAttribute(attribute); str = string.Format("{0} ({1})", attribute.Name, attribute.AttributeSchemaType.TypeCode); } else if (o is XmlSchemaElement) { // children = ((XmlSchemaElement)o). XmlSchemaElement element = (XmlSchemaElement)o; foreach (XmlSchemaObject constraint in element.Constraints) { if (constraint is XmlSchemaUnique) { XmlSchemaUnique unique = (XmlSchemaUnique)constraint; List <string> fields = new List <string> (unique.Fields.Count); foreach (XmlSchemaObject field in unique.Fields) { if (field is XmlSchemaXPath) { fields.Add(((XmlSchemaXPath)field).XPath); } } constraints.Add(new TableConstraint { Name = unique.Name, Table = unique.Selector.XPath, Fields = fields }); } else if (constraint is XmlSchemaKeyref) { XmlSchemaKeyref reference = (XmlSchemaKeyref)constraint; string fromTable = reference.Selector.XPath.Substring(3).Replace("_tables", ""); string fromRow = ((XmlSchemaXPath)reference.Fields [0]).XPath.Substring(1); try { TableReferenceEntry tableRef = resolveReference(reference.Name, fromTable, fromRow, reference.Refer.Name); if (tableRef != null) { Console.WriteLine("{0}#{1} - {2}#{3}", tableRef.fromTable, tableRef.fromTableIndex, tableRef.toTable, tableRef.toTableIndex); } else { Console.WriteLine("could not resolve reference"); } } catch (Exception x) { Console.WriteLine(x); } } } } else { Console.WriteLine("unknown type: {0}", o); } if (o is XmlSchemaAnnotated && ((XmlSchemaAnnotated)o).UnhandledAttributes != null) { string attlist = ""; new List <XmlAttribute> (((XmlSchemaAnnotated)o).UnhandledAttributes).ForEach(uh => attlist += " " + uh); str = string.Format("{0} (unhandled: {1})", str, attlist); } foreach (XmlSchemaObject child in children) { handleObject(child); } }