Ejemplo n.º 1
0
        private void CompileAndMergeCUnit(CodeDomProvider provider, CodeCompileUnit cunit, string fileName)
        {
            MergeableFile mergeableFile = new MergeableFile(fileName, true);
            StreamWriter sw             = new StreamWriter(mergeableFile.Stream);

            try
            {
                CodeGeneratorOptions cgo = new CodeGeneratorOptions();
                cgo.BracingStyle = "C";
                provider.GenerateCodeFromCompileUnit(cunit, sw, cgo);
                sw.Flush();
            }
            catch (Exception ex)
            {
                sw.Close();
                mergeableFile.Restore();
                throw ex;
            }
            if (mergeableFile.Write())
            {
                this.filesWithConflicts.Add(fileName);
            }

            sw.Close();
        }
Ejemplo n.º 2
0
        public void Save()
        {
            XmlDocument doc = new XmlDocument();

            this.project.Save(doc);

            Merge.CommentPrefix = "<!--";
            MergeableFile mergeableFile = new MergeableFile(fileName);

            try
            {
                doc.Save(mergeableFile.Stream);
            }
            catch (Exception ex)
            {
                mergeableFile.Restore();
                mergeableFile.Stream.Close();
                throw ex;
            }
            this.hasConflicts = mergeableFile.Write();
            mergeableFile.Stream.Close();
        }
Ejemplo n.º 3
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;
            }
        }