Exemplo n.º 1
0
        public void GenerateAssembly()
        {
            Assembly      ass      = assemblyNode.Assembly;
            string        fullPath = Path.GetFullPath(ass.TargetDir);
            DirectoryInfo di       = new DirectoryInfo(Path.GetPathRoot(fullPath));

            di.CreateSubdirectory(fullPath.Substring(3));
            string     projExtension = ass.TargetLanguage == TargetLanguage.VB ? ".vbproj" : ".csproj";
            string     projFile      = Path.Combine(ass.TargetDir, ass.ProjectName + projExtension);
            string     ndoProjFile   = Path.ChangeExtension(projFile, ".ndoproj");
            VsProject  vsProject     = new VsProject(ass.TargetLanguage, projFile, ass.ProjectName, ass.TargetDir, ass.RootNamespace, databaseNode.Database.ConnectionType);
            NdoProject ndoProject    = new NdoProject(ndoProjFile,
                                                      Path.Combine(ass.TargetDir, "bin\\debug\\" + ass.ProjectName + ".dll"),
                                                      Path.Combine(ass.TargetDir, "obj\\debug\\"),
                                                      ass.TargetDir);

            ndoProject.Save();
            AssemblyGenerator assGen = new AssemblyGenerator(databaseNode, vsProject);

            assGen.GenerateCode();
            string filename = ass.TargetDir + "\\NDOMapping.xml";

            vsProject.AddXmlFile("NDOMapping.xml");
            new MappingGenerator(filename, databaseNode, assemblyNode).GenerateCode();
            vsProject.Save();
            List <string> filesWithConflicts = assGen.FilesWithConflicts;

            if (vsProject.HasConflicts)
            {
                filesWithConflicts.Insert(0, projFile);
            }
            if (filesWithConflicts.Count > 0)
            {
                string strConflicts = "Files with conflicts:\n\n";
                foreach (string s in filesWithConflicts)
                {
                    strConflicts += s + '\n';
                }
                strConflicts += "\nPlease resolve the conflicts, otherwise the project might not compile.";
                MessageBox.Show(strConflicts, "NDO Class Generator");
            }

            foreach (string oldFile in Directory.GetFiles(ass.TargetDir, "*.old"))
            {
                File.Delete(oldFile);
            }
        }