public void Generate(string scriptLanguage, bool utf8Encoding, DataSet dsSchema, DataSet dsBak, string filename, NDOMapping mappings, MessageAdapter messages) { string diffFile = filename.Replace(".ndo.sql", ".ndodiff." + mappings.SchemaVersion + ".sqltemp"); bool isNewDiffFile = !File.Exists(diffFile.Replace(".sqltemp", ".sql")); StreamWriter sw = new StreamWriter(diffFile, true, utf8Encoding ? System.Text.Encoding.UTF8 : System.Text.Encoding.Default); long initialLength = 0; if (isNewDiffFile) { sw.WriteLine(@"-- NDO accumulates all schema changes in this diff file. -- Note: If you change the mapping schema version, a new diff file will be created. -- You can change the mapping schema version in the NDO configuration dialog. -- Don't use the Mapping Tool to change the schema information, because it will be -- overwritten by the value set in the configuration. For automatic builds set -- the schema version value in the .ndoproj file. "); sw.Flush(); initialLength = sw.BaseStream.Length; } ISqlGenerator concreteGenerator = null; if (scriptLanguage == string.Empty) { messages.WriteLine("NDOEnhancer: No script language selected"); return; } if (!NDOProviderFactory.Instance.Generators.ContainsKey(scriptLanguage)) { // The error message should have been written by the Sql generator messages.WriteLine("NDOEnhancer: No Sql code generator for script language '" + scriptLanguage + "' found"); return; } concreteGenerator = (ISqlGenerator)NDOProviderFactory.Instance.Generators[scriptLanguage]; new GenericDiffGenerator(concreteGenerator, messages, mappings).Generate(dsSchema, dsBak, sw); sw.Close(); bool delete = false; if (isNewDiffFile) { FileStream fs = new FileStream(diffFile, FileMode.Open, FileAccess.Read); delete = fs.Length < initialLength + 2L; fs.Close(); } if (delete) { File.Delete(diffFile); } else { File.Copy(diffFile, diffFile.Replace(".sqltemp", ".sql"), true); } }
void CheckVersion(string method) { if (File.Exists(ilDasmPath)) { FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(ilDasmPath); if (string.Compare(fvi.CompanyName, "Microsoft Corporation", true) != 0 && fvi.FileVersion.StartsWith("4.0")) { messages.WriteLine("Wrong ILDasm version in file: " + ilDasmPath + ". CompanyName='" + fvi.CompanyName + "'; Version='" + fvi.FileVersion + "' Method used='" + method + "'. Trying to find ILDasm with other methods."); ilDasmPath = string.Empty; } } }
public void Generate(string scriptLanguage, bool utf8Encoding, DataSet dsSchema, DataSet dsOld, string filename, NDOMapping mappings, MessageAdapter messages, TypeManager typeManager, bool generateConstraints) { StreamWriter sw = new StreamWriter(filename, false, utf8Encoding ? System.Text.Encoding.UTF8 : System.Text.Encoding.Default); ISqlGenerator concreteGenerator = null; if (scriptLanguage == string.Empty) { messages.WriteLine("NDOEnhancer: No script language selected"); return; } concreteGenerator = (ISqlGenerator)NDOProviderFactory.Instance.Generators[scriptLanguage]; if (concreteGenerator == null) { messages.WriteLine("NDOEnhancer: No Sql code generator for script language '" + scriptLanguage + "' found"); return; } new GenericSqlGenerator(concreteGenerator, messages, mappings).Generate(dsSchema, dsOld, sw, typeManager, generateConstraints); sw.Close(); }
public void Generate(string scriptLanguage, DataSet dsSchema, string filename, NDOMapping mappings, MessageAdapter messages) { StreamWriter sr = new StreamWriter(filename, false, System.Text.Encoding.Default); ISqlGenerator concreteGenerator = null; if (scriptLanguage == string.Empty) { messages.WriteLine("NDOEnhancer: No script language selected"); return; } concreteGenerator = GeneratorFactory.Instance[scriptLanguage]; if (concreteGenerator == null) { messages.WriteLine("NDOEnhancer: No provider for script language '" + scriptLanguage + "' found"); return; } new GenericSqlGenerator(concreteGenerator, messages).Generate(dsSchema, sr, mappings); sr.Close(); }
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 }