public EntityCodeGenerator(EntityCodeGenerationModel model, GeneratorConfig config) { var kdiff3Paths = new[] { config.KDiff3Path, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "KDiff3\\kdiff3.exe"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "KDiff3\\kdiff3.exe"), }; this.model = model; CodeFileHelper.Kdiff3Path = kdiff3Paths.FirstOrDefault(File.Exists); if (config.TFSIntegration) { CodeFileHelper.SetupTFSIntegration(config.TFPath); } CodeFileHelper.SetupTSCPath(config.TSCPath); siteWebProj = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, config.WebProjectFile)); siteWebPath = Path.GetDirectoryName(siteWebProj); if (!string.IsNullOrEmpty(config.ScriptProjectFile)) { scriptProject = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, config.ScriptProjectFile)); scriptPath = Path.GetDirectoryName(scriptProject); if (!File.Exists(scriptProject)) { scriptProject = null; scriptPath = null; } } this.config = config; }
private void GenerateCodes_Click(object sender, RoutedEventArgs e) { var conn = (GeneratorConfig.Connection) this.ConnectionsCombo.SelectedItem; if (conn == null) { MessageBox.Show("A connection must be selected!"); return; } var tables = this._tables.Where(x => x.IsChecked == true); if (this.ConnectionsCombo.SelectedItem == null) { MessageBox.Show("Please select at least one table!"); return; } ; var noIdentifier = tables.FirstOrDefault(x => x.Identifier.IsTrimmedEmpty()); if (noIdentifier != null) { MessageBox.Show("Identifier for table " + noIdentifier.FullName + " is empty!"); return; } ; foreach (var table in tables) { try { EntityModel rowModel; using (var connection = SqlConnections.New(conn.ConnectionString, conn.ProviderName)) { connection.Open(); var tableName = table.FullName; string schema = null; if (tableName.IndexOf('.') > 0) { schema = tableName.Substring(0, tableName.IndexOf('.')); tableName = tableName.Substring(tableName.IndexOf('.') + 1); } rowModel = RowGenerator.GenerateModel(connection, schema, tableName, table.Module, table.ConnectionKey, table.Identifier, table.PermissionKey, config); var kdiff3Paths = new[] { config.KDiff3Path, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "KDiff3\\kdiff3.exe"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "KDiff3\\kdiff3.exe"), }; CodeFileHelper.Kdiff3Path = kdiff3Paths.FirstOrDefault(File.Exists); if (config.TFSIntegration) { CodeFileHelper.SetupTFSIntegration(config.TFPath); } CodeFileHelper.SetupTSCPath(config.TSCPath); var siteWebProj = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, config.WebProjectFile)); new EntityCodeGenerator(rowModel, config, siteWebProj).Run(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } if (config.GenerateService || config.GenerateUI || config.GenerateCustom) { var siteWebProj = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, config.WebProjectFile)); var siteWebPath = Path.GetDirectoryName(siteWebProj); CodeFileHelper.ExecuteTSC(Path.Combine(siteWebPath, @"Scripts\"), ""); } MessageBox.Show("Code files for the selected table is generated. Please REBUILD SOLUTION before running application, otherwise you may have script errors!"); GenerateCodeButton.IsEnabled = false; }