Ejemplo n.º 1
0
        public void GenerateCode()
        {
            NDO.Mapping.NDOMapping mapping = NDO.Mapping.NDOMapping.Create(fileName + ".new");
            mapping.SchemaVersion = "1.0";
            NDO.Mapping.Connection conn = new NDO.Mapping.Connection(mapping);
            conn.Type = database.ConnectionType;
            conn.Name = database.ConnectionString;
            conn.ID   = "C0";
            mapping.AddConnection(conn);
            foreach (NDOTreeNode treenode in databaseNode.Nodes)
            {
                TableNode tn = treenode as TableNode;
                if (tn != null && !tn.Table.Skipped)
                {
                    if (tn.Table.MappingType == TableMappingType.MappedAsClass ||
                        tn.Table.MappingType == TableMappingType.MappedAsIntermediateClass)
                    {
                        NDO.Mapping.Class cl = mapping.AddStandardClass(tn.Table.Namespace + "." + tn.Table.ClassName, ass.ProjectName, null);
                        // Todo: Check, if not other options were choosed.
                        if (tn.Table.MappingType == TableMappingType.MappedAsIntermediateClass)
                        {
                            //cl.Oid.ParentRelation = tn.DualKeyRelations[0];
                            //cl.Oid.ChildRelation = tn.DualKeyRelations[1];
                        }
                        if (((DatabaseNode)tn.Parent).Database.OwnerName != string.Empty)
                        {
                            cl.TableName = ((DatabaseNode)tn.Parent).Database.OwnerName + "." + tn.Table.Name;
                        }
                        else
                        {
                            cl.TableName = tn.Table.Name;
                        }
                        cl.ConnectionId = "C0";
                        AddFields(tn, cl);
                        AddRelations(tn, cl);
                    }
                }
            }
            MergeableFile mergeableFile = new MergeableFile(fileName);
            Stream        dummy         = mergeableFile.Stream; // moves the file to filename.old

            dummy.Close();
            try
            {
                mapping.Save();
                if (File.Exists(mergeableFile.OldFileName))
                {
                    Merge.CommentPrefix = "<!--";
                    Merge.MergeFiles(mergeableFile.OldFileName, fileName + ".new", fileName);
                    File.Delete(mergeableFile.OldFileName);
                    File.Delete(fileName + ".new");
                }
                else
                {
                    File.Copy(fileName + ".new", fileName, true);
                    File.Delete(fileName + ".new");
                }
            }
            catch (Exception ex)
            {
                mergeableFile.Restore();
                throw ex;
            }
        }
Ejemplo n.º 2
0
        static ObjectPropertyForm()
        {
            PersistenceManager pm = new PersistenceManager();

            mapping = pm.NDOMapping;
        }