void IncludeFiles(ConfigurationOptions options, Project project, ProjectDescription projectDescription) { #if DEBUG messages.WriteLine("Including project files..."); #endif string schemaVersion = string.Empty; #if DEBUG projectDescription.MessageAdapter = messages; #endif string mappingFile = string.Empty; try { #if DEBUG messages.WriteLine(" mapping..."); #endif mappingFile = project.DefaultMappingFileName(); projectDescription.AddFileToProject(mappingFile); } catch (Exception ex) { messages.WriteLine("Warning: Can't add mapping file '" + mappingFile + "' to the project. " + ex.Message); } try { NDOMapping mapping = new NDOMapping(mappingFile); schemaVersion = mapping.SchemaVersion; } catch (Exception ex) { messages.WriteLine("Warning: Can't extract schema version from the mapping file. Error message: " + ex.Message); } #if DEBUG messages.WriteLine("...ready"); #endif }
private void btnOK_Click(object sender, System.EventArgs e) { try { ConfigurationOptions options = new ConfigurationOptions(project); string connType = options.SQLScriptLanguage; string connName = options.DefaultConnection; WriteBack(options); if (options.SQLScriptLanguage != connType || options.DefaultConnection != connName) { string mappingFileName = this.project.MappingFilePath(); if (mappingFileName != null) { NDOMapping mapping = new NDOMapping(mappingFileName); bool connectionExists = false; foreach (Connection conn in mapping.Connections) { if (conn.Type == options.SQLScriptLanguage && conn.Name == options.DefaultConnection) { connectionExists = true; break; } } if (!connectionExists) { if (MessageBox.Show("The database connection settings have been changed. Should NDO change the connection settings in the mapping file " + Path.GetFileName(mappingFileName) + " too?", "NDO Configuration", MessageBoxButtons.YesNo) == DialogResult.Yes) { Connection conn = null; if (mapping.Connections.Count() == 1) { conn = (Connection)mapping.Connections.FirstOrDefault(); } else { conn = mapping.NewConnection(String.Empty, String.Empty); MessageBox.Show("Added a connection with the ID " + conn.ID, "NDO Configuration"); } conn.Type = options.SQLScriptLanguage; conn.Name = options.DefaultConnection; mapping.Save(); } } } } if (options.EnableAddIn) { if (!options.UseMsBuild) { options.UseMsBuild = true; } GeneratePackageReference(); } options.Save(this.projectDescription); } catch (Exception ex) { #if DEBUG MessageBox.Show("The following error occured while saving your options: " + ex.ToString(), "NDO Add-in"); #else MessageBox.Show("The following error occured while saving your options: " + ex.Message, "NDO Add-in"); #endif } }