From: Richard B. <rb...@us...> - 2004-12-10 04:31:27
|
Update of /cvsroot/jcframework/FrameworkMapper/AFMappingClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5004/AFMappingClasses Added Files: AFMappingClasses.vbproj AssemblyInfo.vb CAssociationEntry.vb CAssociationEntryCollection.vb CAttributeList.vb CMappedAssociation.vb CMappedAttribute.vb CMappedAttributeCollection.vb CMappedClass.vb CMappedClassCollection.vb CMappedDatabase.vb CProject.vb MappedDatabaseList.vb XMLMapper.vb Log Message: Major update to incorporate CodeSmith scripts, and integration with WinMerge for viewing differences. --- NEW FILE: CMappedClassCollection.vb --- Public Class CMappedClassCollection Inherits CollectionBase Public Sub Add(ByVal a As CMappedClass) list.Add(a) End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then Throw New Exception("index value is outside of bounds") End If list.RemoveAt(index) End Sub Public Sub Remove(ByVal value As CMappedClass) list.Remove(value) End Sub Default Public ReadOnly Property Item(ByVal index As Integer) As CMappedClass Get Return CType(list.Item(index), CMappedClass) End Get End Property Default Public ReadOnly Property Item(ByVal _name As String) As CMappedClass Get For Each ma As CMappedClass In Me If ma.ClassName = _name Then Return ma End If Next End Get End Property End Class --- NEW FILE: CMappedDatabase.vb --- Public Class CMappedDatabase Public dbname As String Public dbType As String Public serverName As String Public user As String Public password As String Public OIDTable As String Public portNumber As String Public options As String Public NameParam As String Public Expanded As Boolean Public AnsiNulls As Boolean = True Public tables As New dbTableCollection Public Sub getDBSchema() Select Case dbType Case "CMSSQLDatabase" GetMSSQLDB() Case Else End Select End Sub Private Sub GetMSSQLDB() Dim conn As New SqlClient.SqlConnection Try conn.ConnectionString = _ "Data Source=" & serverName & ";" & _ "Initial Catalog=" & NameParam & ";" & _ "Integrated Security=false;" & _ "Persist Security Info=False;" & _ "User Id=" & user & ";" & _ "Password=" & password conn.Open() Catch ex As SqlClient.SqlException MsgBox("Connection to " & serverName & " couldn't be established") Return End Try Dim schemaDA As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("SELECT * FROM INFORMATION_SCHEMA.TABLES " & _ "ORDER BY TABLE_TYPE, TABLE_NAME", _ conn) Dim schemaTable As DataTable = New DataTable schemaDA.Fill(schemaTable) tables = New dbTableCollection Dim table As dbTable Dim col As dbColumn For Each dr As DataRow In schemaTable.Rows table = New dbTable table.tableName = dr("TABLE_NAME") table.tableOwner = dr("TABLE_SCHEMA") If dr("TABLE_TYPE") = "BASE TABLE" Then table.tableType = "TABLE" Else table.tableType = "VIEW" End If table.parentDB = Me tables.Add(table) Dim fieldDA As SqlClient.SqlDataAdapter = _ New SqlClient.SqlDataAdapter("SELECT * FROM INFORMATION_SCHEMA.COLUMNS " & _ "where table_schema = '" & dr("TABLE_SCHEMA") & "' and Table_name = '" & dr("TABLE_NAME") & "' " & _ "ORDER BY ORDINAL_POSITION", _ conn) Dim schemaTableCols As DataTable = New DataTable fieldDA.Fill(schemaTableCols) For Each colrow As DataRow In schemaTableCols.Rows col = New dbColumn col.colName = colrow("COLUMN_NAME") col.colType = colrow("DATA_TYPE") Select Case col.colType Case "bigint" col.dotnetTypeName = "long" Case "binary" col.dotnetTypeName = "Object" Case "bit" col.dotnetTypeName = "Boolean" Case "char" col.dotnetTypeName = "String" Case "datetime" col.dotnetTypeName = "DateTime" Case "decimal" col.dotnetTypeName = "Decimal" Case "float" col.dotnetTypeName = "Double" Case "image" col.dotnetTypeName = "Byte()" Case "int" col.dotnetTypeName = "Integer" Case "money" col.dotnetTypeName = "Decimal" Case "nchar" col.dotnetTypeName = "String" Case "ntext" col.dotnetTypeName = "String" Case "numeric" col.dotnetTypeName = "Decimal" Case "nvarchar" col.dotnetTypeName = "String" Case "real" col.dotnetTypeName = "Single" Case "smalldatetime" col.dotnetTypeName = "DateTime" Case "smallint" col.dotnetTypeName = "Short" Case "smallmoney" col.dotnetTypeName = "Decimal" Case "text" col.dotnetTypeName = "String" Case "timestamp" col.dotnetTypeName = "Byte()" Case "tinyint" col.dotnetTypeName = "Byte" Case "uniqueidentifier" col.dotnetTypeName = "Guid" Case "varbinary" col.dotnetTypeName = "Byte()" Case "varchar" col.dotnetTypeName = "String" Case "sql_variant" col.dotnetTypeName = "Object" End Select col.parentTable = table table.columns.Add(col) Next Dim constraintDA As SqlClient.SqlDataAdapter = _ New SqlClient.SqlDataAdapter("SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS " & _ "where table_schema = '" & dr("TABLE_SCHEMA") & "' and Table_name = '" & dr("TABLE_NAME") & "' " & _ "and CONSTRAINT_TYPE = 'PRIMARY KEY'", conn) Dim TableConstraintCols As DataTable = New DataTable constraintDA.Fill(TableConstraintCols) If TableConstraintCols.Rows.Count > 0 Then Dim constraintRow As DataRow = TableConstraintCols.Rows(0) Dim cname As String = constraintRow("CONSTRAINT_NAME") Dim primaryKeyDA As SqlClient.SqlDataAdapter = _ New SqlClient.SqlDataAdapter("SELECT * FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE " & _ "where table_schema = '" & dr("TABLE_SCHEMA") & "' and Table_name = '" & dr("TABLE_NAME") & "' " & _ "and CONSTRAINT_NAME = '" & cname & "'", conn) Dim constraintCols As DataTable = New DataTable primaryKeyDA.Fill(constraintCols) For Each conColrow As DataRow In constraintCols.Rows col = table.columns(conColrow("COLUMN_NAME")) col.isPrimaryKey = True Next End If Next End Sub End Class Public Class dbTable Public tableName As String Public tableOwner As String <NonSerialized(), Xml.Serialization.XmlIgnore()> Public parentDB As CMappedDatabase Public Expanded As Boolean Public columns As New dbColumnCollection Public tableType As String Public Overrides Function ToString() As String Return tableOwner & "." & tableName End Function End Class Public Class dbColumn Public colName As String Public colType As String Public dotnetTypeName As String Public parentTable As dbTable Public isPrimaryKey As Boolean End Class Public Class CMappedDatabaseCollection Inherits CollectionBase Public Sub Add(ByVal a As CMappedDatabase) list.Add(a) End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then Throw New Exception("index value is outside of bounds") End If list.RemoveAt(index) End Sub Public Sub Remove(ByVal value As CMappedDatabase) list.Remove(value) End Sub Default Public ReadOnly Property Item(ByVal index As Integer) As CMappedDatabase Get Return CType(list.Item(index), CMappedDatabase) End Get End Property Default Public ReadOnly Property Item(ByVal _name As String) As CMappedDatabase Get For Each ma As CMappedDatabase In Me If ma.dbname = _name Then Return ma End If Next End Get End Property End Class Public Class dbTableCollection Inherits CollectionBase Public Sub Add(ByVal a As dbTable) list.Add(a) End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then Throw New Exception("index value is outside of bounds") End If list.RemoveAt(index) End Sub Public Sub Remove(ByVal value As dbTable) list.Remove(value) End Sub Default Public ReadOnly Property Item(ByVal index As Integer) As dbTable Get Return CType(list.Item(index), dbTable) End Get End Property Default Public ReadOnly Property Item(ByVal _name As String) As dbTable Get For Each t As dbTable In Me If t.tableName = _name Then Return t End If Next End Get End Property End Class Public Class dbColumnCollection Inherits CollectionBase Public Sub Add(ByVal a As dbColumn) list.Add(a) End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then Throw New Exception("index value is outside of bounds") End If list.RemoveAt(index) End Sub Public Sub Remove(ByVal value As dbColumn) list.Remove(value) End Sub Default Public ReadOnly Property Item(ByVal index As Integer) As dbColumn Get Return CType(list.Item(index), dbColumn) End Get End Property Default Public ReadOnly Property Item(ByVal _name As String) As dbColumn Get For Each c As dbColumn In Me If c.colName = _name Then Return c End If Next End Get End Property End Class --- NEW FILE: XMLMapper.vb --- Option Strict Off Option Explicit On Imports System.Collections.Specialized Imports System.Xml Public Class CXMLMapper Private m_FileName As String Private p As CProject Public Sub New(ByVal xmlFile As String, ByRef inProj As CProject) MyBase.New() m_FileName = xmlFile p = inProj End Sub Public Sub Load() p.databases = New CMappedDatabaseCollection p.classes = New CMappedClassCollection Dim doc As New XmlDocument Try doc.Load(m_FileName) Catch ex As Exception Exit Sub End Try Dim node As XmlNode Dim elem As XmlElement Dim reldb As CMappedDatabase Dim clm As CMappedClass Dim elementRoot As XmlElement elementRoot = doc.DocumentElement node = elementRoot.FirstChild While Not node Is Nothing If node.NodeType = XmlNodeType.Element Then elem = node If node.Name = "database" Then reldb = getRelationalDatabase(elem) Try p.databases.Add(reldb) Catch ex As Exception Throw New Exception("Could not add database " & reldb.dbname & vbCrLf & ex.Message, ex) End Try ElseIf node.Name = "class" Then clm = getClassMap(elem) Try p.classes.Add(clm) Catch ex As Exception Throw New Exception("Could not add classmap " & clm.ClassName & vbCrLf & ex.Message, ex) End Try ElseIf node.Name = "association" Then processAssociation(elem) End If End If node = node.NextSibling() End While End Sub Private Function getRelationalDatabase(ByRef node As XmlElement) As CMappedDatabase Dim relDb As CMappedDatabase relDb = Nothing Dim attrPMName As String Dim attrClassName As XmlAttribute attrPMName = node.GetAttribute("name") attrClassName = node.GetAttributeNode("class") Dim params As HybridDictionary Dim nodeChild As XmlNode Dim elementChild As XmlElement Dim attrName, attrValue As XmlAttribute If ((Not attrPMName Is Nothing) And (Not attrClassName Is Nothing)) Then relDb = New CMappedDatabase relDb.dbType = attrClassName.Value relDb.dbname = attrPMName nodeChild = node.FirstChild() Do While Not nodeChild Is Nothing If nodeChild.NodeType = XmlNodeType.Element Then elementChild = nodeChild If elementChild.Name = "parameter" Then attrName = elementChild.GetAttributeNode("name") attrValue = elementChild.GetAttributeNode("value") Select Case attrName.Value Case "name" relDb.NameParam = attrValue.Value Case "serverName" relDb.serverName = attrValue.Value Case "user" relDb.user = attrValue.Value Case "password" If attrValue.Value = "N/A" Then relDb.password = Nothing Else relDb.password = attrValue.Value End If Case "OIDTable" relDb.OIDTable = attrValue.Value Case "port" relDb.portNumber = attrValue.Value Case "options" relDb.options = attrValue.Value End Select End If End If nodeChild = nodeChild.NextSibling Loop End If relDb.getDBSchema() Return relDb End Function Private Function getClassMap(ByVal node As XmlElement) As CMappedClass Dim attrClassName As XmlAttribute, attrTable As XmlAttribute, attrTableOwner As XmlAttribute Dim attrDatabase As XmlAttribute, attrSuperClassName As XmlAttribute, attrReadOnly As XmlAttribute, attrModifyOnly As XmlAttribute Dim attrClassNameSpace, attrAssemblyPath, attrFactory As XmlAttribute Dim attrSharedField As XmlAttribute, attrSharedValue As XmlAttribute attrClassName = node.GetAttributeNode("name") attrTable = node.GetAttributeNode("table") attrDatabase = node.GetAttributeNode("database") attrSuperClassName = node.GetAttributeNode("superclass") attrReadOnly = node.GetAttributeNode("readonly") attrModifyOnly = node.GetAttributeNode("modifyonly") attrTableOwner = node.GetAttributeNode("owner") attrSharedField = node.GetAttributeNode("sharedtablefield") attrSharedValue = node.GetAttributeNode("sharedtablevalue") attrClassNameSpace = node.GetAttributeNode("namespace") attrAssemblyPath = node.GetAttributeNode("assemblypath") attrFactory = node.GetAttributeNode("factory") Dim ClassMap As CMappedClass Dim dbMap As CMappedDatabase Dim nodeChild As XmlNode Dim elementChild As XmlElement Dim AttrMap As CMappedAttribute If ((Not attrClassName Is Nothing) And (Not attrDatabase Is Nothing)) Then ClassMap = New CMappedClass ClassMap.Project = p ClassMap.ClassName = attrClassName.Value If Not attrSuperClassName Is Nothing Then ClassMap.SuperClass = p.classes.Item(attrSuperClassName.Value) If Not attrSharedValue Is Nothing Then ClassMap.SharedValue = attrSharedValue.Value End If If Not attrSharedField Is Nothing Then ClassMap.SharedField = attrSharedField.Value End If End If If Not attrAssemblyPath Is Nothing Then ClassMap.AssemblyPath = attrAssemblyPath.Value End If If Not attrFactory Is Nothing Then ClassMap.Factory = attrFactory.Value End If If attrReadOnly Is Nothing Then ClassMap.ReadOnlyFlag = False Else ClassMap.ReadOnlyFlag = attrReadOnly.Value End If If attrModifyOnly Is Nothing Then ClassMap.ModifyOnlyFlag = False Else ClassMap.ModifyOnlyFlag = attrModifyOnly.Value End If If Not attrClassNameSpace Is Nothing Then ClassMap.ClassNameSpace = attrClassNameSpace.Value End If ClassMap.Database = p.databases.Item(attrDatabase.Value) ClassMap.Table = attrTable.Value If attrTableOwner Is Nothing Then ClassMap.TableOwner = "dbo" Else ClassMap.TableOwner = attrTableOwner.Value End If If Not ClassMap.Database Is Nothing Then For Each tbl As dbTable In ClassMap.Database.tables If tbl.tableName = ClassMap.Table AndAlso tbl.tableOwner = ClassMap.TableOwner Then ClassMap.MappedTable = tbl End If Next End If nodeChild = node.FirstChild Do While Not nodeChild Is Nothing If nodeChild.NodeType = XmlNodeType.Element Then elementChild = nodeChild If elementChild.Name = "attribute" Then AttrMap = getAttributeMap(elementChild, ClassMap) If Not AttrMap.Column Is Nothing AndAlso Not ClassMap.MappedTable Is Nothing Then For Each col As dbColumn In ClassMap.MappedTable.columns If col.colName = AttrMap.Column Then AttrMap.MappedColumn = col AttrMap.DataType = col.colType End If Next End If ClassMap.Attributes.Add(AttrMap) End If End If nodeChild = nodeChild.NextSibling Loop End If getClassMap = ClassMap End Function Private Function getAttributeMap(ByVal node As XmlElement, ByVal clMap As CMappedClass) As CMappedAttribute Dim attrColumn, attrName, attrKey, attrFind, attrProxy, attrTimeStamp, attrIdentity As XmlAttribute Dim attrReference As XmlAttribute attrName = node.GetAttributeNode("name") attrColumn = node.GetAttributeNode("column") attrKey = node.GetAttributeNode("key") attrReference = node.GetAttributeNode("reference") attrFind = node.GetAttributeNode("find") attrProxy = node.GetAttributeNode("proxy") attrTimeStamp = node.GetAttributeNode("timestamp") attrIdentity = node.GetAttributeNode("identity") Dim AttrMap As CMappedAttribute Dim refAttr As CMappedAttribute If Not attrName Is Nothing Then AttrMap = New CMappedAttribute AttrMap.Name = attrName.Value AttrMap.isKey = False If Not attrColumn Is Nothing Then AttrMap.Column = attrColumn.Value If Not attrKey Is Nothing Then If UCase(attrKey.Value) = "PRIMARY" Then AttrMap.isKey = True End If End If If Not attrFind Is Nothing Then AttrMap.isFind = CBool(attrFind.Value) End If If Not attrIdentity Is Nothing Then AttrMap.isIdentity = CBool(attrIdentity.Value) End If If Not attrTimeStamp Is Nothing Then AttrMap.isTimeStamp = CBool(attrTimeStamp.Value) Else AttrMap.isTimeStamp = False ' Default is not a timestamp End If End If If Not attrProxy Is Nothing Then AttrMap.isProxy = CBool(attrProxy.Value) Else AttrMap.isProxy = True End If If ((Not attrReference Is Nothing) And (Not clMap.SuperClass Is Nothing)) Then refAttr = clMap.SuperClass.Attributes.Item(attrReference.Value) If Not refAttr Is Nothing Then AttrMap.Reference = refAttr.Name End If End If getAttributeMap = AttrMap End If End Function Private Sub processAssociation(ByVal node As XmlElement) Dim attrToClass, attrFromClass, attrTarget As XmlAttribute Dim attrCardinality, attrFromClassNamespace, attrToClassNamespace As XmlAttribute Dim fromClassMap As CMappedClass Dim toClassMap As CMappedClass Dim udaAm As CMappedAssociation Dim nodeChild As XmlNode Dim elementChild As XmlElement Dim entry As CAssociationEntry Dim amFromAttribute As Object Dim amToAttribute As CMappedAttribute Dim attrFromAttribute As Object Dim attrToAttribute As XmlAttribute Dim attrName As XmlAttribute attrFromClass = node.GetAttributeNode("fromClass") attrToClass = node.GetAttributeNode("toClass") attrFromClassNamespace = node.GetAttributeNode("fromClassNameSpace") attrToClassNamespace = node.GetAttributeNode("toClassNameSpace") attrTarget = node.GetAttributeNode("target") attrCardinality = node.GetAttributeNode("cardinality") attrName = node.GetAttributeNode("name") If ((Not attrFromClass Is Nothing) And (Not attrToClass Is Nothing) And (Not attrTarget Is Nothing)) Then fromClassMap = p.classes.Item(attrFromClass.Value) toClassMap = p.classes.Item(attrToClass.Value) udaAm = New CMappedAssociation udaAm.fromClass = fromClassMap udaAm.ToClass = toClassMap If Not attrFromClassNamespace Is Nothing Then udaAm.FromClassNamespace = attrFromClassNamespace.Value End If If Not attrToClassNamespace Is Nothing Then udaAm.ToClassNamespace = attrToClassNamespace.Value End If udaAm.TargetAttribute = fromClassMap.Attributes.Item(attrTarget.Value) udaAm.DeleteAuto = node.GetAttributeNode("deleteAutomatic").Value udaAm.SaveAuto = node.GetAttributeNode("saveAutomatic").Value udaAm.RetrieveAuto = node.GetAttributeNode("retrieveAutomatic").Value If attrName Is Nothing Then udaAm.Name = udaAm.TargetAttribute.Name Else udaAm.Name = attrName.Value End If If Not attrCardinality Is Nothing Then If UCase(attrCardinality.Value) = "ONETOONE" Then udaAm.Cardinality = Cardinalities.OneToOne ElseIf UCase(attrCardinality.Value) = "ONETOMANY" Then udaAm.Cardinality = Cardinalities.OneToMany End If End If nodeChild = node.FirstChild Do While Not nodeChild Is Nothing If nodeChild.NodeType = XmlNodeType.Element Then elementChild = nodeChild If elementChild.Name = "entry" Then attrFromAttribute = elementChild.GetAttributeNode("fromAttribute") attrToAttribute = elementChild.GetAttributeNode("toAttribute") If ((Not attrFromAttribute Is Nothing) And (Not attrToAttribute Is Nothing)) Then amFromAttribute = fromClassMap.Attributes.Item(attrFromAttribute.Value) amToAttribute = toClassMap.Attributes.Item(attrToAttribute.Value) If amFromAttribute Is Nothing Then Throw New Exception("Error in association definition") End If If amToAttribute Is Nothing Then Throw New Exception("Error in association definition") End If entry = New CAssociationEntry entry.fromAttribute = amFromAttribute entry.toAttribute = amToAttribute udaAm.Entries.Add(entry) End If End If End If nodeChild = nodeChild.NextSibling Loop fromClassMap.Associations.Add(udaAm, udaAm.Name) Else Throw New Exception("Error in association definition: Missing FromClass, ToClass or Target attributes") End If End Sub Public Sub Save() Dim doc As New XmlDocument Dim elem As XmlElement Dim node As XmlNode Dim attr As XmlAttribute node = doc.CreateElement("map") For Each db As CMappedDatabase In p.databases elem = doc.CreateElement("database") saveDatabase(doc, elem, db) node.AppendChild(elem) Next For Each cls As CMappedClass In p.classes elem = doc.CreateElement("class") saveClass(doc, elem, cls) node.AppendChild(elem) Next For Each cls As CMappedClass In p.classes For Each ass As CMappedAssociation In cls.Associations elem = doc.CreateElement("association") saveassociation(doc, elem, ass) node.AppendChild(elem) Next Next doc.AppendChild(node) doc.Save(m_FileName) End Sub Private Sub saveDatabase(ByVal doc As XmlDocument, ByVal elem As XmlElement, ByVal db As CMappedDatabase) Dim attr As XmlAttribute Dim param As XmlElement 'db name CreateAttributeValue(doc, elem, "name", db.dbname) CreateAttributeValue(doc, elem, "class", db.dbType) 'Now add parameters If db.NameParam <> String.Empty Then param = doc.CreateElement("parameter") CreateAttributeValue(doc, param, "name", "name") CreateAttributeValue(doc, param, "value", db.NameParam) elem.AppendChild(param) End If If db.serverName <> String.Empty Then param = doc.CreateElement("parameter") CreateAttributeValue(doc, param, "name", "serverName") CreateAttributeValue(doc, param, "value", db.serverName) elem.AppendChild(param) End If If db.user <> String.Empty Then param = doc.CreateElement("parameter") CreateAttributeValue(doc, param, "name", "user") CreateAttributeValue(doc, param, "value", db.user) elem.AppendChild(param) End If If db.password <> String.Empty Then param = doc.CreateElement("parameter") CreateAttributeValue(doc, param, "name", "password") CreateAttributeValue(doc, param, "value", db.password) elem.AppendChild(param) End If If db.OIDTable <> String.Empty Then param = doc.CreateElement("parameter") CreateAttributeValue(doc, param, "name", "OIDTable") CreateAttributeValue(doc, param, "value", db.OIDTable) elem.AppendChild(param) End If If db.portNumber <> String.Empty Then param = doc.CreateElement("parameter") CreateAttributeValue(doc, param, "name", "port") CreateAttributeValue(doc, param, "value", db.portNumber) elem.AppendChild(param) End If If db.options <> String.Empty Then param = doc.CreateElement("parameter") CreateAttributeValue(doc, param, "name", "options") CreateAttributeValue(doc, param, "value", db.options) elem.AppendChild(param) End If End Sub Private Sub SaveClass(ByVal doc As XmlDocument, ByVal elem As XmlElement, ByVal cls As CMappedClass) Dim mappedAttr As XmlElement CreateAttributeValue(doc, elem, "name", cls.ClassName) CreateAttributeValue(doc, elem, "table", cls.Table) CreateAttributeValue(doc, elem, "database", cls.DatabaseName) If cls.TableOwner <> "dbo" AndAlso cls.TableOwner <> String.Empty Then CreateAttributeValue(doc, elem, "owner", cls.TableOwner) End If If Not cls.SuperClass Is Nothing Then CreateAttributeValue(doc, elem, "superclass", cls.SuperClass.ClassName) If cls.SharedField <> String.Empty Then CreateAttributeValue(doc, elem, "sharedtablefield", cls.SharedField) CreateAttributeValue(doc, elem, "sharedtablevalue", cls.SharedValue) End If End If If cls.ReadOnlyFlag Then CreateAttributeValue(doc, elem, "readonly", "true") End If If cls.ModifyOnlyFlag Then CreateAttributeValue(doc, elem, "modifyonly", "true") End If If cls.ClassNameSpace <> String.Empty Then CreateAttributeValue(doc, elem, "namespace", cls.ClassNameSpace) End If For Each attr As CMappedAttribute In cls.Attributes mappedAttr = doc.CreateElement("attribute") CreateAttributeValue(doc, mappedAttr, "name", attr.Name) If attr.Column <> String.Empty Then CreateAttributeValue(doc, mappedAttr, "column", attr.Column) End If If attr.isKey Then CreateAttributeValue(doc, mappedAttr, "key", "primary") End If If attr.isFind Then CreateAttributeValue(doc, mappedAttr, "find", "true") End If If attr.Reference <> String.Empty Then CreateAttributeValue(doc, mappedAttr, "reference", attr.Reference) End If If attr.isProxy = False Then CreateAttributeValue(doc, mappedAttr, "proxy", "false") End If If attr.isTimeStamp Then CreateAttributeValue(doc, mappedAttr, "timestamp", "true") End If If attr.isIdentity Then CreateAttributeValue(doc, mappedAttr, "identity", "true") End If elem.AppendChild(mappedAttr) Next End Sub Private Sub SaveAssociation(ByVal doc As XmlDocument, ByVal elem As XmlElement, ByVal ass As CMappedAssociation) Dim assEntry As XmlElement CreateAttributeValue(doc, elem, "fromClass", ass.fromClass.ClassName) CreateAttributeValue(doc, elem, "toClass", ass.ToClass.ClassName) If ass.TargetAttribute Is Nothing Then CreateAttributeValue(doc, elem, "target", "No Target") Else CreateAttributeValue(doc, elem, "target", ass.TargetAttribute.Name) End If If ass.Cardinality = Cardinalities.OneToOne Then CreateAttributeValue(doc, elem, "cardinality", "OneToOne") Else CreateAttributeValue(doc, elem, "cardinality", "OneToMany") End If If ass.Name <> ass.TargetAttribute.Name Then CreateAttributeValue(doc, elem, "name", ass.Name) End If If ass.RetrieveAuto Then CreateAttributeValue(doc, elem, "retrieveAutomatic", "true") Else CreateAttributeValue(doc, elem, "retrieveAutomatic", "false") End If If ass.SaveAuto Then CreateAttributeValue(doc, elem, "saveAutomatic", "true") Else CreateAttributeValue(doc, elem, "saveAutomatic", "false") End If If ass.DeleteAuto Then CreateAttributeValue(doc, elem, "deleteAutomatic", "true") Else CreateAttributeValue(doc, elem, "deleteAutomatic", "false") End If For Each e As CAssociationEntry In ass.Entries assEntry = doc.CreateElement("entry") CreateAttributeValue(doc, assEntry, "fromAttribute", e.fromAttribute.Name) CreateAttributeValue(doc, assEntry, "toAttribute", e.toAttribute.Name) elem.AppendChild(assEntry) Next End Sub Private Sub CreateAttributeValue(ByVal doc As XmlDocument, ByVal elem As XmlElement, ByVal name As String, ByVal value As String) Dim attr As XmlAttribute attr = doc.CreateAttribute(name) attr.Value = value elem.Attributes.Append(attr) End Sub End Class --- NEW FILE: MappedDatabaseList.vb --- Imports System.ComponentModel Public Class MappedDatabaseList Inherits StringConverter Public Overloads Overrides Function _ GetStandardValues(ByVal context As _ System.ComponentModel.ITypeDescriptorContext) _ As System.ComponentModel.TypeConverter.StandardValuesCollection Dim p As CProject Dim cls As CMappedClass Dim c As New ArrayList If context.Instance.GetType Is GetType(CMappedClass) Then cls = context.Instance p = cls.Project For Each db As CMappedDatabase In p.databases c.Add(db.dbname) Next End If c.Add("(None)") Return New StandardValuesCollection(c) End Function Public Overloads Overrides Function _ GetStandardValuesExclusive(ByVal context _ As System.ComponentModel.ITypeDescriptorContext) _ As Boolean Return True End Function Public Overloads Overrides Function GetStandardValuesSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean Return True End Function End Class --- NEW FILE: AFMappingClasses.vbproj --- <VisualStudioProject> <VisualBasic ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{AD59B3EC-022E-4CEB-B625-BB56C75A2255}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "AFMappingClasses" AssemblyOriginatorKeyFile = "" AssemblyOriginatorKeyMode = "None" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" OptionCompare = "Binary" OptionExplicit = "On" OptionStrict = "Off" RootNamespace = "AFMappingClasses" StartupObject = "AFMappingClasses.(None)" > <Config Name = "Debug" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "true" DefineTrace = "true" DebugSymbols = "true" IncrementalBuild = "true" Optimize = "false" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> <Config Name = "Release" BaseAddress = "285212672" ConfigurationOverrideFile = "" DefineConstants = "" DefineDebug = "false" DefineTrace = "true" DebugSymbols = "false" IncrementalBuild = "false" Optimize = "true" OutputPath = "bin\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "1" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" /> <Reference Name = "System.Data" AssemblyName = "System.Data" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" /> </References> <Imports> <Import Namespace = "Microsoft.VisualBasic" /> <Import Namespace = "System" /> <Import Namespace = "System.Collections" /> <Import Namespace = "System.Data" /> <Import Namespace = "System.Diagnostics" /> </Imports> </Build> <Files> <Include> <File RelPath = "AssemblyInfo.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CAssociationEntry.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CAssociationEntryCollection.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CAttributeList.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CMappedAssociation.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CMappedAttribute.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CMappedAttributeCollection.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CMappedClass.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CMappedClassCollection.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CMappedDatabase.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "CProject.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "MappedDatabaseList.vb" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "XMLMapper.vb" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </VisualBasic> </VisualStudioProject> --- NEW FILE: CAttributeList.vb --- Imports System.ComponentModel Imports AFMappingClasses Public Class CAttributeList Inherits StringConverter Public Overloads Overrides Function _ GetStandardValues(ByVal context As _ System.ComponentModel.ITypeDescriptorContext) _ As System.ComponentModel.TypeConverter.StandardValuesCollection Dim cls As CMappedClass Dim ass As CMappedAssociation Dim al As New ArrayList If context.Instance.GetType Is GetType(CMappedAssociation) Then ass = context.Instance cls = ass.FromClass For Each attr As CMappedAttribute In cls.Attributes al.Add(attr.Name) Next End If al.Add("(None)") Return New StandardValuesCollection(al) End Function Public Overloads Overrides Function _ GetStandardValuesExclusive(ByVal context _ As System.ComponentModel.ITypeDescriptorContext) _ As Boolean Return True End Function Public Overloads Overrides Function GetStandardValuesSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean Return True End Function End Class --- NEW FILE: CMappedAssociation.vb --- Imports System.ComponentModel Public Enum Cardinalities OneToOne OneToMany End Enum <DefaultProperty("Target")> _ Public Class CMappedAssociation Private _fromClass As CMappedClass Private _toClass As CMappedClass Private _name As String Private _targetAttribute As CMappedAttribute Private _cardinality As Cardinalities Private _deleteAuto As Boolean = False Private _saveAuto As Boolean = False Private _retrieveAuto As Boolean = False Private _lazyLoad As Boolean = False Private _entries As CAssociationEntryCollection Private _fromNamespace As String Private _toNamespace As String Public Event NameChanged As EventHandler <Browsable(False)> _ Public Property FromClass() As CMappedClass Get Return _fromClass End Get Set(ByVal Value As CMappedClass) _fromClass = Value End Set End Property Public ReadOnly Property FromClassName() As String Get If _fromClass Is Nothing Then Return "N/A" End If Return _fromClass.ClassName End Get End Property <Browsable(False)> _ Public Property ToClass() As CMappedClass Get Return _toClass End Get Set(ByVal Value As CMappedClass) _toClass = Value End Set End Property Public ReadOnly Property ToClassName() As String Get If _toClass Is Nothing Then Return "N/A" End If Return _toClass.ClassName End Get End Property Public Property Name() As String Get Return _name End Get Set(ByVal Value As String) _name = Value RaiseEvent NameChanged(Me, New EventArgs) End Set End Property <Browsable(False)> _ Public Property TargetAttribute() As CMappedAttribute Get Return _targetAttribute End Get Set(ByVal Value As CMappedAttribute) _targetAttribute = Value End Set End Property <TypeConverter(GetType(CAttributeList))> _ Public Property Target() As String Get If _targetAttribute Is Nothing Then Return "(None)" End If Return _targetAttribute.Name End Get Set(ByVal Value As String) If Value = "" Then Exit Property Dim s As String If _targetAttribute Is Nothing Then s = "(None)" Else If _targetAttribute.Name Is Nothing Then s = "(None)" Else s = _targetAttribute.Name End If End If If s <> Value Then If _fromClass Is Nothing Then _targetAttribute = Nothing End If If Value = "(None)" Then _targetAttribute = Nothing Else Try _targetAttribute = FromClass.Attributes(Value) If Left(Name, 9) = "No Target" Then Name = _targetAttribute.Name End If Catch _targetAttribute = Nothing End Try End If End If End Set End Property Public Property Cardinality() As Cardinalities Get Return _cardinality End Get Set(ByVal Value As Cardinalities) _cardinality = Value End Set End Property Public Property DeleteAuto() As Boolean Get Return _deleteAuto End Get Set(ByVal Value As Boolean) _deleteAuto = Value End Set End Property Public Property SaveAuto() As Boolean Get Return _saveAuto End Get Set(ByVal Value As Boolean) _saveAuto = Value End Set End Property Public Property RetrieveAuto() As Boolean Get Return _retrieveAuto End Get Set(ByVal Value As Boolean) _retrieveAuto = Value End Set End Property Public Property LazyLoad() As Boolean Get Return _lazyLoad End Get Set(ByVal Value As Boolean) _lazyLoad = Value End Set End Property <Browsable(False)> _ Public Property Entries() As CAssociationEntryCollection Get Return _entries End Get Set(ByVal Value As CAssociationEntryCollection) _entries = Value End Set End Property Public Sub New() _entries = New CAssociationEntryCollection _entries.parentAssociation = Me End Sub Public Property FromClassNamespace() As String Get Return _fromNamespace End Get Set(ByVal Value As String) _fromNamespace = Value End Set End Property Public Property ToClassNamespace() As String Get Return _toNamespace End Get Set(ByVal Value As String) _toNamespace = Value End Set End Property End Class --- NEW FILE: CProject.vb --- Public Class CProject Public ProjectName As String Public SourceCodeLocation As String Public IsNew As Boolean = True Public FileName As String Public XMLMappingFile As String Public BusinessClassScript As String Public XMLMappingScript As String Public DBSchemaScript As String Public databases As New CMappedDatabaseCollection Public classes As New CMappedClassCollection End Class --- NEW FILE: CMappedAttributeCollection.vb --- Option Explicit On Imports System.ComponentModel Public Class CMappedAttributeCollection Inherits CollectionBase Implements IBindingList Implements IComponent Public Sub Add(ByVal a As CMappedAttribute) list.Add(a) End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then Throw New Exception("index value is outside of bounds") End If list.RemoveAt(index) End Sub Public Sub Remove(ByVal value As CMappedAttribute) list.Remove(value) End Sub Default Public ReadOnly Property Item(ByVal index As Integer) As CMappedAttribute Get Return CType(list.Item(index), CMappedAttribute) End Get End Property Default Public ReadOnly Property Item(ByVal _name As String) As CMappedAttribute Get For Each ma As CMappedAttribute In Me If ma.Name = _name Then Return ma End If Next End Get End Property #Region "IBindlingList" Public Overridable Sub AddIndex(ByVal [property] As System.ComponentModel.PropertyDescriptor) Implements System.ComponentModel.IBindingList.AddIndex End Sub Public Overridable Function AddNew() As Object Implements System.ComponentModel.IBindingList.AddNew Dim cm As New CMappedAttribute list.Add(cm) Return cm End Function Public Overridable ReadOnly Property AllowEdit() As Boolean Implements System.ComponentModel.IBindingList.AllowEdit Get Return True End Get End Property Public Overridable ReadOnly Property AllowNew() As Boolean Implements System.ComponentModel.IBindingList.AllowNew Get Return True End Get End Property Public Overridable ReadOnly Property AllowRemove() As Boolean Implements System.ComponentModel.IBindingList.AllowRemove Get Return True End Get End Property Public Overridable Sub ApplySort(ByVal [property] As System.ComponentModel.PropertyDescriptor, ByVal direction As System.ComponentModel.ListSortDirection) Implements System.ComponentModel.IBindingList.ApplySort End Sub Public Overridable Function Find(ByVal [property] As System.ComponentModel.PropertyDescriptor, ByVal key As Object) As Integer Implements System.ComponentModel.IBindingList.Find End Function Public Overridable ReadOnly Property IsSorted() As Boolean Implements System.ComponentModel.IBindingList.IsSorted Get End Get End Property Public Event ListChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ListChangedEventArgs) Implements System.ComponentModel.IBindingList.ListChanged Public Overridable Sub RemoveIndex(ByVal [property] As System.ComponentModel.PropertyDescriptor) Implements System.ComponentModel.IBindingList.RemoveIndex End Sub Public Overridable Sub RemoveSort() Implements System.ComponentModel.IBindingList.RemoveSort End Sub Public Overridable ReadOnly Property SortDirection() As System.ComponentModel.ListSortDirection Implements System.ComponentModel.IBindingList.SortDirection Get End Get End Property Public Overridable ReadOnly Property SortProperty() As System.ComponentModel.PropertyDescriptor Implements System.ComponentModel.IBindingList.SortProperty Get End Get End Property Public Overridable ReadOnly Property SupportsChangeNotification() As Boolean Implements System.ComponentModel.IBindingList.SupportsChangeNotification Get Return True End Get End Property Public Overridable ReadOnly Property SupportsSearching() As Boolean Implements System.ComponentModel.IBindingList.SupportsSearching Get Return False End Get End Property Public Overridable ReadOnly Property SupportsSorting() As Boolean Implements System.ComponentModel.IBindingList.SupportsSorting Get Return False End Get End Property #End Region #Region "Collection Events" Protected Overrides Sub OnInsertComplete(ByVal index As Integer, ByVal value As Object) AddHandler CType(value, CMappedAttribute).RemoveMe, AddressOf Remove RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.ItemAdded, index)) End Sub Protected Overrides Sub OnClearComplete() RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.Reset, 0)) End Sub Protected Overrides Sub OnRemoveComplete(ByVal index As Integer, ByVal value As Object) RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.ItemDeleted, index)) End Sub Protected Overrides Sub OnSetComplete(ByVal index As Integer, ByVal oldValue As Object, ByVal newValue As Object) RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.ItemChanged, index)) End Sub #End Region #Region "IComponent Interface" Public Event Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Implements IComponent.Disposed Private m_curCPCSite As ISite <Browsable(False)> Public Property Site() As System.ComponentModel.ISite Implements IComponent.Site Get Return m_curCPCSite End Get Set(ByVal Value As System.ComponentModel.ISite) m_curCPCSite = Value End Set End Property Public Sub Dispose() Implements System.IDisposable.Dispose RaiseEvent Disposed(Me, EventArgs.Empty) End Sub #End Region End Class --- NEW FILE: AssemblyInfo.vb --- Imports System Imports System.Reflection Imports System.Runtime.InteropServices ' General Information about an assembly is controlled through the following ' set of attributes. Change these attribute values to modify the information ' associated with an assembly. ' Review the values of the assembly attributes <Assembly: AssemblyTitle("")> <Assembly: AssemblyDescription("")> <Assembly: AssemblyCompany("")> <Assembly: AssemblyProduct("")> <Assembly: AssemblyCopyright("")> <Assembly: AssemblyTrademark("")> <Assembly: CLSCompliant(True)> 'The following GUID is for the ID of the typelib if this project is exposed to COM <Assembly: Guid("9892C051-0923-47CD-81D8-E1F0C0A65B58")> ' Version information for an assembly consists of the following four values: ' ' Major Version ' Minor Version ' Build Number ' Revision ' ' You can specify all the values or you can default the Build and Revision Numbers ' by using the '*' as shown below: <Assembly: AssemblyVersion("1.0.*")> --- NEW FILE: CAssociationEntry.vb --- Imports System.ComponentModel Public Class CAssociationEntry Implements IEditableObject Implements IDataErrorInfo Private _fromAttribute As CMappedAttribute Private _toAttribute As CMappedAttribute Private _parentAssociation As CMappedAssociation Friend Event RemoveMe(ByVal Attribute As CAssociationEntry) Private m_isNew As Boolean Private m_editing As Boolean Private m_preEditCopy As CAssociationEntry <Browsable(False)> _ Public Property ParentAssociation() As CMappedAssociation Get Return _parentAssociation End Get Set(ByVal Value As CMappedAssociation) _parentAssociation = Value End Set End Property <Browsable(False)> _ Public Property fromAttribute() As CMappedAttribute Get Return _fromAttribute End Get Set(ByVal Value As CMappedAttribute) _fromAttribute = Value End Set End Property <Browsable(False)> _ Public Property toAttribute() As CMappedAttribute Get Return _toAttribute End Get Set(ByVal Value As CMappedAttribute) _toAttribute = Value End Set End Property Public Property fromAttributeName() As String Get If _fromAttribute Is Nothing Then Return "" End If Return _fromAttribute.Name End Get Set(ByVal Value As String) If _parentAssociation Is Nothing Then Exit Property _fromAttribute = _parentAssociation.FromClass.Attributes(Value) End Set End Property Public Property toAttributeName() As String Get If _toAttribute Is Nothing Then Return "" End If Return _toAttribute.Name End Get Set(ByVal Value As String) If _parentAssociation Is Nothing Then Exit Property _toAttribute = _parentAssociation.ToClass.Attributes(Value) End Set End Property Public Overridable Sub BeginEdit() Implements System.ComponentModel.IEditableObject.BeginEdit If Not m_editing Then m_preEditCopy = New CAssociationEntry m_preEditCopy.fromAttribute = Me.fromAttribute m_preEditCopy.toAttribute = Me.toAttribute m_preEditCopy.ParentAssociation = Me.ParentAssociation m_editing = True End If End Sub Public Overridable Sub CancelEdit() Implements System.ComponentModel.IEditableObject.CancelEdit m_editing = False If m_isNew Then m_isNew = False RaiseEvent RemoveMe(Me) Else Me.fromAttribute = m_preEditCopy.fromAttribute Me.toAttribute = m_preEditCopy.toAttribute Me.ParentAssociation = m_preEditCopy.ParentAssociation m_preEditCopy = Nothing End If End Sub Public Overridable Sub EndEdit() Implements System.ComponentModel.IEditableObject.EndEdit m_editing = False m_isNew = False End Sub #Region "IDataErrorInfo" <Browsable(False)> Public ReadOnly Property [Error]() As String Implements System.ComponentModel.IDataErrorInfo.Error Get If _fromAttribute Is Nothing Then Return "Missing FromAttribute" End If If _toAttribute Is Nothing Then Return "Missing ToAttribute" End If If _parentAssociation Is Nothing Then Return "Missing Association" End If Dim found As Integer = 0 For Each ae As CAssociationEntry In _parentAssociation.Entries If _fromAttribute.Name = ae.fromAttribute.Name Then found += 1 End If Next If found > 1 Then Return "From Attribute appears more than once" End If found = 0 For Each ae As CAssociationEntry In _parentAssociation.Entries If _toAttribute.Name = ae.toAttribute.Name Then found += 1 End If Next If found > 1 Then Return "To Attribute appears more than once" End If End Get End Property <Browsable(False)> Default Public ReadOnly Property Item(ByVal columnName As String) As String Implements System.ComponentModel.IDataErrorInfo.Item Get Return "" End Get End Property #End Region End Class --- NEW FILE: CAssociationEntryCollection.vb --- Option Explicit On Imports System.ComponentModel Public Class CAssociationEntryCollection Inherits CollectionBase Implements IBindingList Implements IComponent Private _parent As CMappedAssociation Public Property parentAssociation() As CMappedAssociation Get Return _parent End Get Set(ByVal Value As CMappedAssociation) _parent = Value End Set End Property Public Sub Add(ByVal ae As CAssociationEntry) If ae.ParentAssociation Is Nothing Then ae.ParentAssociation = _parent End If list.Add(ae) End Sub Public Sub Remove(ByVal index As Integer) If index > Count - 1 Or index < 0 Then Throw New Exception("index value is outside of bounds") End If list.RemoveAt(index) End Sub Public Sub Remove(ByVal value As CAssociationEntry) list.Remove(value) End Sub Default Public ReadOnly Property Item(ByVal index As Integer) As CAssociationEntry Get Return CType(list.Item(index), CAssociationEntry) End Get End Property #Region "IBindingList" Public Overridable Sub AddIndex(ByVal [property] As System.ComponentModel.PropertyDescriptor) Implements System.ComponentModel.IBindingList.AddIndex End Sub Public Overridable Function AddNew() As Object Implements System.ComponentModel.IBindingList.AddNew Dim ae As New CAssociationEntry ae.ParentAssociation = _parent list.Add(ae) Return ae End Function Public Overridable ReadOnly Property AllowEdit() As Boolean Implements System.ComponentModel.IBindingList.AllowEdit Get Return True End Get End Property Public Overridable ReadOnly Property AllowNew() As Boolean Implements System.ComponentModel.IBindingList.AllowNew Get Return True End Get End Property Public Overridable ReadOnly Property AllowRemove() As Boolean Implements System.ComponentModel.IBindingList.AllowRemove Get Return True End Get End Property Public Overridable Sub ApplySort(ByVal [property] As System.ComponentModel.PropertyDescriptor, ByVal direction As System.ComponentModel.ListSortDirection) Implements System.ComponentModel.IBindingList.ApplySort End Sub Public Overridable Function Find(ByVal [property] As System.ComponentModel.PropertyDescriptor, ByVal key As Object) As Integer Implements System.ComponentModel.IBindingList.Find End Function Public Overridable ReadOnly Property IsSorted() As Boolean Implements System.ComponentModel.IBindingList.IsSorted Get End Get End Property Public Event ListChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ListChangedEventArgs) Implements System.ComponentModel.IBindingList.ListChanged Public Overridable Sub RemoveIndex(ByVal [property] As System.ComponentModel.PropertyDescriptor) Implements System.ComponentModel.IBindingList.RemoveIndex End Sub Public Overridable Sub RemoveSort() Implements System.ComponentModel.IBindingList.RemoveSort End Sub Public Overridable ReadOnly Property SortDirection() As System.ComponentModel.ListSortDirection Implements System.ComponentModel.IBindingList.SortDirection Get End Get End Property Public Overridable ReadOnly Property SortProperty() As System.ComponentModel.PropertyDescriptor Implements System.ComponentModel.IBindingList.SortProperty Get End Get End Property Public Overridable ReadOnly Property SupportsChangeNotification() As Boolean Implements System.ComponentModel.IBindingList.SupportsChangeNotification Get Return True End Get End Property Public Overridable ReadOnly Property SupportsSearching() As Boolean Implements System.ComponentModel.IBindingList.SupportsSearching Get Return False End Get End Property Public Overridable ReadOnly Property SupportsSorting() As Boolean Implements System.ComponentModel.IBindingList.SupportsSorting Get Return False End Get End Property #End Region #Region "Collection events and Component interface" Protected Overrides Sub OnInsertComplete(ByVal index As Integer, ByVal value As Object) AddHandler CType(value, CAssociationEntry).RemoveMe, AddressOf Remove RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.ItemAdded, index)) End Sub Protected Overrides Sub OnClearComplete() RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.Reset, 0)) End Sub Protected Overrides Sub OnRemoveComplete(ByVal index As Integer, ByVal value As Object) RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.ItemDeleted, index)) End Sub Protected Overrides Sub OnSetComplete(ByVal index As Integer, ByVal oldValue As Object, ByVal newValue As Object) RaiseEvent ListChanged(Me, New ListChangedEventArgs(ListChangedType.ItemChanged, index)) End Sub Public Event Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Implements IComponent.Disposed Private m_curCPCSite As ISite <Browsable(False)> Public Property Site() As System.ComponentModel.ISite Implements IComponent.Site Get Return m_curCPCSite End Get Set(ByVal Value As System.ComponentModel.ISite) m_curCPCSite = Value End Set End Property Public Sub Dispose() Implements System.IDisposable.Dispose RaiseEvent Disposed(Me, EventArgs.Empty) End Sub #End Region End Class --- NEW FILE: CMappedClass.vb --- Imports System.ComponentModel <DefaultProperty("ClassName")> _ Public Class CMappedClass Private _ClassName As String Private _SourcFile As String Private _isNew As Boolean = True Private _attributes As New CMappedAttributeCollection Private _associations As New Collection Private _DefaultExpiry As Integer Private _database As CMappedDatabase Private _superclass As CMappedClass Private _table As String Private _tableOwner As String Private _readOnlyFlag As Boolean = False Private _modifyOnlyFlag As Boolean = False Private _sharedField As String Private _sharedValue As String Private _classNamespace As String Private _expanded As Boolean Private _project As CProject Private _mappedTable As dbTable Private _assemblyPath As String Private _factory As String Public Event ClassNameChanged As EventHandler Public Sub New() _ClassName = "New Class" End Sub Public Property ClassName() As String Get Return _ClassName End Get Set(ByVal Value As String) _ClassName = Value RaiseEvent ClassNameChanged(Me, New EventArgs) End Set End Property Public Property SourceFile() As String Get Return _SourcFile End Get Set(ByVal Value As String) _SourcFile = Value End Set End Property Public Property IsNew() As Boolean Get Return _isNew End Get Set(ByVal Value As Boolean) _isNew = Value End Set End Property <Browsable(False)> _ Public Property Attributes() As CMappedAttributeCollection Get Return _attributes End Get Set(ByVal Value As CMappedAttributeCollection) _attributes = Value End Set End Property <Browsable(False)> _ Public Property Associations() As Collection Get Return _associations End Get Set(ByVal Value As Collection) _associations = Value End Set End Property Public Property DefaultExpiry() As Integer Get Return _DefaultExpiry End Get Set(ByVal Value As Integer) _DefaultExpiry = Value End Set End Property <TypeConverter(GetType(MappedDatabaseList)), [ReadOnly](False)> _ Public Property DatabaseName() As String Get If _database Is Nothing Then Return "(None)" End If Return _database.dbname End Get Set(ByVal Value As String) If Value = "" Then Exit Property Dim s As String If _database Is Nothing Then s = "(None)" Else s = _database.dbname End If If s <> Value Then If _project Is Nothing Then _database = Nothing End If If Value = "(None)" Then _database = Nothing Else _database = _project.databases(Value) End If End If End Set End Property <Browsable(False)> _ Public Property Database() As CMappedDatabase Get Return _database End Get Set(ByVal Value As CMappedDatabase) _database = Value End Set End Property Public Property SuperClass() As CMappedClass Get Return _superclass End Get Set(ByVal Value As CMappedClass) _superclass = Value End Set End Property Public Property Table() As String Get Return _table End Get Set(ByVal Value As String) _table = Value End Set End Property Public Property TableOwner() As String Get Return _tableOwner End Get Set(ByVal Value As String) _tableOwner = Value End Set End Property <Browsable(False)> _ Public Property MappedTable() As dbTable Get Return _mappedTable End Get Set(ByVal Value As dbTable) _mappedTable = Value End Set End Property Public Property ReadOnlyFlag() As Boolean Get Return _readOnlyFlag End Get Set(ByVal Value As Boolean) _readOnlyFlag = Value End Set End Property Public Property ModifyOnlyFlag() As Boolean Get Return _modifyOnlyFlag End Get Set(ByVal Value As Boolean) _modifyOnlyFlag = Value End Set End Property Public Property SharedField() As String Get Return _sharedField End Get Set(ByVal Value As String) _sharedField = Value End Set End Property Public Property SharedValue() As String Get Return _sharedValue End Get Set(ByVal Value As String) _sharedValue = Value End Set End Property Public Property ClassNameSpace() As String Get Return _classNamespace End Get Set(ByVal Value As String) _classNamespace = Value End Set End Property <Browsable(False)> _ Public Property Expanded() As Boolean Get Return _expanded End Get Set(ByVal Value As Boolean) _expanded = Value End Set End Property <Browsable(False)> Public Property Project() As CProject Get Return _project End Get Set(ByVal Value As CProject) _project = Value End Set End Property Public Property AssemblyPath() As String Get Return _assemblyPath End Get Set(ByVal Value As String) _assemblyPath = Value End Set End Property Public Property Factory() As String Get Return _factory End Get Set(ByVal Value As String) _factory = Value End Set End Property End Class --- NEW FILE: CMappedAttribute.vb --- Imports System.ComponentModel Public Class CMappedAttribute Implements IEditableObject Private _Name As String Private _column As String Private _isKey As Boolean = False Private _isProxy As Boolean = True Private _isFind As Boolean = False Private _isIdentity As Boolean = False Private _isTimeStamp As Boolean = False Private _referenceToParentField As String Private _dataType As String Private _mappedColumn As dbColumn Friend Event RemoveMe(ByVal Attribute As CMappedAttribute) Private m_isNew As Boolean Private m_editing As Boolean Private m_preEditCopy As CMappedAttribute Public Property Name() As String Get Return _Name End Get Set(ByVal Value As String) _Name = Value End Set End Property Public Property Column() As String Get Return _column End Get Set(ByVal Value As String) _column = Value End Set End Property Public Property MappedColumn() As dbColumn Get Return _mappedColumn End Get Set(ByVal Value As dbColumn) _mappedColumn = Value End Set End Property Public Property isKey(... [truncated message content] |