public XmlDocument DoIt(Assembly ass)
        {
            try
            {
                assShortName = ass.FullName.Substring(0, ass.FullName.IndexOf(','));
                dllName      = ass.Location;

                this.doc = new XmlDocument();
                XmlElement pcs = doc.CreateElement("PersistentClasses");
                doc.AppendChild(pcs);

                Type[] theTypes = ass.GetTypes();
                AnalyzeTypes(theTypes, pcs, doc);
                //pcs.SetAttribute("AssemblyName", ass.FullName.Substring(0, ass.FullName.IndexOf(',')));
                pcs.SetAttribute("AssemblyFullName", ass.FullName);
                object[] attrs = ass.GetCustomAttributes(false);
                if (HasEnhancedAttribute(attrs))
                {
                    pcs.SetAttribute("IsEnhanced", "True");
                }
                string oidTypeName = GetOidTypeNameFromAttributes(attrs);
                if (oidTypeName != null)
                {
                    pcs.SetAttribute("OidType", oidTypeName);
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                messages.ShowError("SearchPersistenClasses(" + dllName + "): " + ex);
#else
                messages.ShowError("SearchPersistenClasses(" + dllName + "): " + ex.Message);
#endif
            }

            return(this.doc);
        }
Beispiel #2
0
        public void GenerateRelations()
        {
            DataTable dt = dsSchema.Tables[c.TableName];

            if (null == dt)
            {
                throw new InternalException(38, String.Format("GenerateRelations: DataTable {0} not found.", c.TableName));
            }

            ClassNode classNode = (ClassNode)allPersistentClasses[c.FullName];

            if (classNode == null)
            {
                throw new InternalException(42, "SchemaGenerator: GenerateRelations");
            }

//			ReferenceArrayList references = (ReferenceArrayList) allReferences[c.FullName];
//			if (references == null)
//				throw new NDOException(string.Format("Kann Relationsinformationen für die Klasse {0} nicht finden. Rekompilieren Sie ggf. das Assembly neu", c.FullName));
//
            foreach (Relation r in c.Relations)
            {
                string rname = r.FieldName;
                if (null == r)
                {
                    messages.WriteLine("Keine Mapping-Informationen für Relation " + c.FullName + "." + rname + ". Lassen Sie sich die Information generieren oder tragen Sie sie per Hand ein.");
                    continue;
                }

                if (r.MappingTable != null)
                {
                    continue;
                }

                NDO.Mapping.Class refClass = this.mappings.FindClass(r.ReferencedTypeName);
                if (null == refClass)
                {
                    throw new InternalException(64, String.Format("Reference Class {0} nicht gefunden", r.ReferencedTypeName));
                }

                ClassNode refClassNode = (ClassNode)allPersistentClasses[refClass.FullName];

                // Kann keine Relation zu einer abstrakten Klasse herstellen,
                // da diese keine Tabelle hat
                if (refClassNode.IsAbstract)
                {
                    continue;
                }

                //MM 5.2 Relationen anlegen
                // Zwei gegenläufige 1:1-Beziehungen benötigen zwei Relationen
                DataColumn parentCol;
                DataColumn childCol;
                DataTable  foreignTable = dsSchema.Tables[refClass.TableName];
                if (foreignTable == null)
                {
                    throw new InternalException(77, String.Format("SchemaGenerator: GenerateRelations: foreign Table {0} for class {1} not found.", refClass.TableName, refClass.FullName));
                }

                string relName;
                if (r.Multiplicity == RelationMultiplicity.Element && GegenRelationIs1To1(c.FullName, refClassNode, r))
                {
                    relName = GetLastElement(dt.TableName) + GetLastElement(refClass.TableName) + r.RelationName;
                }
                else
                {
                    if (refClass.TableName.CompareTo(dt.TableName) < 0)
                    {
                        relName = GetLastElement(refClass.TableName) + GetLastElement(dt.TableName) + r.RelationName;
                    }
                    else
                    {
                        relName = GetLastElement(dt.TableName) + GetLastElement(refClass.TableName) + r.RelationName;
                    }
                }
                int i = 0;
                new ForeignKeyIterator(r).Iterate(delegate(ForeignKeyColumn fkColumn, bool isLastElement)
                {
                    if (r.Multiplicity == RelationMultiplicity.Element)
                    {
                        childCol = dt.Columns[fkColumn.Name];
                        if (childCol == null)
                        {
                            throw new Exception(String.Format("Internal Error: GenerateRelations: Column {0}.{1} not found", dt.TableName, fkColumn.Name));
                        }
                        string oidColumnName = ((OidColumn)refClass.Oid.OidColumns[i]).Name;
                        parentCol            = foreignTable.Columns[oidColumnName];
                        if (parentCol == null)
                        {
                            throw new Exception(String.Format("Internal Error: GenerateRelations: Column {0}.{1} is null", foreignTable.TableName, oidColumnName));
                        }
                    }
                    else
                    {
                        childCol = foreignTable.Columns[fkColumn.Name];
                        if (childCol == null)
                        {
                            throw new Exception(String.Format("Internal Error: GenerateRelations: Column {0}.{1} not found", foreignTable.TableName, fkColumn.Name));
                        }
                        string oidColumnName = ((OidColumn)c.Oid.OidColumns[i]).Name;
                        parentCol            = dt.Columns[oidColumnName];
                        if (parentCol == null)
                        {
                            throw new Exception(String.Format("Internal Error: GenerateRelations: Column {0}.{1} is null", dt.TableName, oidColumnName));
                        }
                    }
                    if (null == dsSchema.Relations[relName])
                    {
                        try
                        {
                            DataRelation dr = new DataRelation(relName, parentCol, childCol, true);
                            dsSchema.Relations.Add(dr);
                            ForeignKeyConstraint fkc = dr.ChildKeyConstraint;
                            fkc.UpdateRule           = Rule.Cascade;
                            fkc.DeleteRule           = Rule.None;
                            fkc.AcceptRejectRule     = AcceptRejectRule.None;
                        }
                        catch (Exception ex)
                        {
                            if (verboseMode)
                            {
                                messages.ShowError("Error while constructing relation " + relName + ": " + ex.ToString());
                            }
                            else
                            {
                                messages.ShowError("Error while constructing relation " + relName + ": " + ex.Message);
                            }
                        }
                    }
                    i++;
                });
            }

#if !NDO20
#if BETA
            if (!NDOKey.CheckKey(new Guid("889b6a58-1d97-be54-d874-75a12a93f56e"),
                                 new LicenceKey().TheKey))
            {
                throw new WrongLicenceException2();
            }
#else
#if TRIAL
            if (!NDOKey.CheckKey(new Guid("7f63d54d-d500-228e-311d-b19bb99d9bd4"),
                                 new LicenceKey().TheKey))
            {
                throw new WrongLicenceException2();
            }
#else
#if ENT
            if (!NDOKey.CheckKey(new Guid("9d092588-f787-cbed-fe06-2dcd86720337"),
                                 new LicenceKey().TheKey))
            {
                throw new WrongLicenceException2();
            }
#else
#if PRO
            if (!NDOKey.CheckKey(new Guid("ed25a316-3365-1e4e-5144-f3a1766fe98d"),
                                 new LicenceKey().TheKey))
            {
                throw new WrongLicenceException2();
            }
#else
#if STD
            if (!NDOKey.CheckKey(new Guid("ec3be943-c358-b83a-e310-b8436322e322"),
                                 new LicenceKey().TheKey))
            {
                throw new WrongLicenceException2();
            }
#endif
#endif
#endif
#endif
#endif
#else  // NDO20
#if BETA
            if (!NDOKey.CheckKey(new Guid("2f29c228-6967-4941-02dd-369783fabdde"),
                                 new LicenceKey().TheKey))
            {
                throw new WrongLicenceException2();
            }
#else
#if TRIAL
            if (!NDOKey.CheckKey(new Guid("629dab4d-a032-a30e-54ea-1a53e0111cb9"),
                                 new LicenceKey().TheKey))
            {
                throw new WrongLicenceException2();
            }
#else
#if ENT
            if (!NDOKey.CheckKey(new Guid("9540866a-861c-3f19-ae8c-7f9785f62ce5"),
                                 new LicenceKey().TheKey))
            {
                throw new WrongLicenceException2();
            }
#else
#if PRO
            if (!NDOKey.CheckKey(new Guid("35473777-9fc3-f78f-83c6-475f23758b46"),
                                 new LicenceKey().TheKey))
            {
                throw new WrongLicenceException2();
            }
#else
#if STD
            if (!NDOKey.CheckKey(new Guid("36bf154d-4085-9f38-d2a9-1fea6a6f9df8"),
                                 new LicenceKey().TheKey))
            {
                throw new WrongLicenceException2();
            }
#endif
#endif
#endif
#endif
#endif
#endif // NDO20
        }