public Generator(ProjectDefinaton project, PatternProject pattern, DbDatabase database, ExSchemaEngine schemaEngine)
 {
     _patternProject = pattern;
     _projectDef = project;
     _database = database;
     _schemaEngine = schemaEngine;
     _optionGenerateUnselectedForeigns = false;
 }
        public static ProjectDefinaton LoadDefaultProject()
        {
            ProjectDefinaton result = new ProjectDefinaton();

            result.ProjectName     = "Project1";
            result.LastGeneration  = DateTime.MinValue;
            result.GenerationPath  = AppConfig.DefaultOutputPath;
            result.ProjectFileName = "";

            result.DbSettions      = ProjectDbSettions.LoadDefaultSettings();
            result.CodeGenSettings = ProjectCodeGenSettings.LoadDefaultSettings();
            result.CodeGenSettings.CodeGenPatternFile = AppConfig.DefaultPatternFileName;

            return(result);
        }
        public static ProjectDefinaton LoadDefaultProject()
        {
            ProjectDefinaton result = new ProjectDefinaton();

            result.ProjectName = "Project1";
            result.LastGeneration = DateTime.MinValue;
            result.GenerationPath = AppConfig.DefaultOutputPath;
            result.ProjectFileName = "";

            result.DbSettions = ProjectDbSettions.LoadDefaultSettings();
            result.CodeGenSettings = ProjectCodeGenSettings.LoadDefaultSettings();
            result.CodeGenSettings.CodeGenPatternFile = AppConfig.DefaultPatternFileName;

            return result;
        }
        public void InitializeSchemaProject()
        {
            Project = new ProjectDefinaton();
            Pattern = new PatternProject();
            Database = new DbDatabase();

            Project.GenerationPath = Path.Combine(Path.GetTempPath(), @"SalarDbCodeGenerator.Tests\" + DateTime.Now.Ticks);
            Project.ProjectName = "SalarDbCodeGenerator.Tests";

            Pattern.LanguageSettings.KeywordsCaseSensitive = true;
            Pattern.LanguageSettings.LanguageInvalidChars = ", ./<>?;'\\:\"|[]{}`-=~!@#$%^&*()+";
            Pattern.LanguageSettings.LanguageInvalidCharsSuppress = '_';
            Pattern.LanguageSettings.LanguageKeywords.AddRange(new string[]
                                                               	{
                                                               		"readonly", "base", "break", "byte", "case", "catch", "checked",
                                                               		"class", "const", "continue", "default", "delegate", "do",
                                                               		"value", "else", "enum", "event", "explicit", "extern", "false",
                                                               		"finally", "fixed", "for", "foreach", "goto", "if", "implicit",
                                                               		"in", "interface", "internal", "is", "namespace", "new", "null",
                                                               		"object", "operator", "out", "override", "private", "protected",
                                                               		"public", "readonly", "ref", "return", "sealed", "sizeof",
                                                               		"static", "struct", "switch", "this", "throw", "true", "try",
                                                               		"typeof", "typeof", "unchecked", "unsafe", "using", "virtual",
                                                               		"while"
                                                               	});
            Pattern.LanguageSettings.NullableDataTypes.AddRange(new[] { "String", "Object" });
            Pattern.LanguageSettings.ExplicitCastDataTypes.AddRange(new[] { "Object", "Guid", "DateTimeOffset", "TimeSpan" });
            Pattern.LanguageSettings.VoidDataType = "void";
            Pattern.LanguageSettings.TextFieldIdenticator = "text";
            Pattern.LanguageSettings.ArrayIdenticator = "[]";
            Pattern.LanguageSettings.DbDecimalName = "decimal";
            Pattern.LanguageSettings.DbNumericName = "numeric";
            Pattern.LanguageSettings.DbDecimalType = "decimal([:Precision:],[:Scale:])";
            Pattern.LanguageSettings.DbNumericType = "numeric([:Precision:],[:Scale:])";
            Pattern.LanguageSettings.LanguageKeywordsSuppress = "{0}_{1}";

            Database.DatabaseName = "SalarDbCodeGeneratorTests";
            Database.Provider = DatabaseProvider.SQLServer;
        }
        public static void SaveToFile(ProjectDefinaton definaton, string fileName)
        {
            var genPath = definaton.GenerationPath;
            var patPath = definaton.CodeGenSettings.CodeGenPatternFile;

            try
            {
                // make relative
                definaton.CodeGenSettings.CodeGenPatternFile =
                    Common.AppVarPathMakeRelative(definaton.CodeGenSettings.CodeGenPatternFile);
                definaton.GenerationPath = Common.ProjectPathMakeRelative(definaton.GenerationPath, fileName);

                // save
                XmlSerializer saver = new XmlSerializer(typeof(ProjectDefinaton));
                using (StreamWriter writer = new StreamWriter(fileName))
                    saver.Serialize(writer, definaton);
            }
            finally
            {
                // restore
                definaton.CodeGenSettings.CodeGenPatternFile = patPath;
                definaton.GenerationPath = genPath;
            }
        }
 public SchemaAnalyzer(ProjectDefinaton project, PatternProject pattern, DbDatabase database)
 {
     _patternProject = pattern;
     _projectDef = project;
     _database = database;
 }
        public static void SaveToFile(ProjectDefinaton definaton, string fileName)
        {
            var genPath = definaton.GenerationPath;
            var patPath = definaton.CodeGenSettings.CodeGenPatternFile;
            try
            {
                // make relative
                definaton.CodeGenSettings.CodeGenPatternFile =
                    Common.AppVarPathMakeRelative(definaton.CodeGenSettings.CodeGenPatternFile);
                definaton.GenerationPath = Common.ProjectPathMakeRelative(definaton.GenerationPath, fileName);

                // save
                XmlSerializer saver = new XmlSerializer(typeof(ProjectDefinaton));
                using (StreamWriter writer = new StreamWriter(fileName))
                    saver.Serialize(writer, definaton);

            }
            finally
            {
                // restore
                definaton.CodeGenSettings.CodeGenPatternFile = patPath;
                definaton.GenerationPath = genPath;
            }
        }
        private void InitializeProjectModel()
        {
            if (ProjectInstance == null)
            {
                // load default settings
                ProjectInstance = ProjectDefinaton.LoadDefaultProject();
            }

            ProjectInstance.ProjectName = txtProjectName.Text;
            ProjectInstance.CodeGenSettings.DefaultNamespace = txtNamespace.Text;
            ProjectInstance.GenerationPath = txtGenerationPath.Text;
            ProjectInstance.CodeGenSettings.CodeGenPatternFile = txtPatternfile.Text;

            ProjectInstance.CodeGenSettings.GenerateTablesForeignKeys = chkGenForeignKey.Checked;
            ProjectInstance.CodeGenSettings.GenerateColumnsDescription = chkGenDescription.Checked;

            ProjectInstance.CodeGenSettings.GenerateConstraintKeys = chkTableConstraintKeys.Checked;

            ProjectInstance.RenamingOptions.UnderlineWordDelimiter = chkRenUnderlineWordDelimiter.Checked;
            ProjectInstance.RenamingOptions.RemoveUnderline.Enabled = chkRenRemUnderline.Checked;
            ProjectInstance.RenamingOptions.RemoveUnderline.Tables = chkRenUnderlineTables.Checked;
            ProjectInstance.RenamingOptions.RemoveUnderline.Properties = chkRenUnderlineProps.Checked;

            ProjectInstance.RenamingOptions.CaseChange.Enabled = chkRenamingCase.Checked;
            ProjectInstance.RenamingOptions.CaseChange.Tables = chkRenCaseTables.Checked;
            ProjectInstance.RenamingOptions.CaseChange.Properties = chkRenCaseProps.Checked;
            ProjectInstance.RenamingOptions.CaseChangeMode = (ProjectRenaming.CaseChangeType)cmbRenamingCase.SelectedValue;

            if (pagerDatabaseProvider.SelectedTab == tabSQLServer)
            {
                ProjectInstance.DbSettions.ServerName = txtSqlHost.Text;
                ProjectInstance.DbSettions.DatabaseName = txtSqlDbName.Text;
                ProjectInstance.DbSettions.SqlUsername = txtSqlUsername.Text;
                ProjectInstance.DbSettions.SqlPassword = txtSqlPassword.Text;
                ProjectInstance.DbSettions.UseSqlAuthentication = rbtnSqlAuthentication.Checked;
                ProjectInstance.DbSettions.ConnectTimeout = Convert.ToInt32(txtSqlConnectTimeout.Text);
                ProjectInstance.DbSettions.DatabaseProvider = DatabaseProvider.SQLServer;
            }
            else if (pagerDatabaseProvider.SelectedTab == tabSQLite)
            {
                ProjectInstance.DbSettions.ServerName = txtSQLiteDatabaseName.Text;
                try
                {
                    ProjectInstance.DbSettions.DatabaseName = Path.GetFileNameWithoutExtension(txtSQLiteDatabaseName.Text);
                }
                catch { }
                ProjectInstance.DbSettions.SqlUsername = "";
                ProjectInstance.DbSettions.SqlPassword = txtSQLitePassword.Text;
                ProjectInstance.DbSettions.UseSqlAuthentication = false;
                ProjectInstance.DbSettions.ConnectTimeout = Convert.ToInt32(txtSQLiteConnectTimeout.Text);
                ProjectInstance.DbSettions.DatabaseProvider = DatabaseProvider.SQLite;
            }
            else if (pagerDatabaseProvider.SelectedTab == tabSqlCe)
            {
                ProjectInstance.DbSettions.ServerName = txtSqlCeDatabaseName.Text;
                try
                {
                    ProjectInstance.DbSettions.DatabaseName = Path.GetFileNameWithoutExtension(txtSqlCeDatabaseName.Text);
                }
                catch { }
                ProjectInstance.DbSettions.SqlUsername = "";
                ProjectInstance.DbSettions.SqlPassword = txtSqlCePassword.Text;
                if (string.IsNullOrEmpty(txtSqlCePassword.Text))
                    ProjectInstance.DbSettions.UseSqlAuthentication = false;
                else
                    ProjectInstance.DbSettions.UseSqlAuthentication = true;

                ProjectInstance.DbSettions.ConnectTimeout = -1;
                ProjectInstance.DbSettions.DatabaseProvider = DatabaseProvider.SqlCe4;
            }
            else if (pagerDatabaseProvider.SelectedTab == tabOracle)
            {
                ProjectInstance.DbSettions.ServerName = txtOrclDataSource.Text;
                ProjectInstance.DbSettions.ConnectTimeout = Convert.ToInt32(txtOrclConnectTimeout.Text);

                ProjectInstance.DbSettions.UseSqlAuthentication = rbtnOrclSpecificUsernamePass.Checked;

                ProjectInstance.DbSettions.DatabaseName = txtOrclDbName.Text;
                ProjectInstance.DbSettions.SqlUsername = txtOrclUsername.Text;
                ProjectInstance.DbSettions.SqlPassword = txtOrclPassword.Text;
                ProjectInstance.DbSettions.OracleUseSysdbaRole = chkOrclUserRoleSYSDBA.Checked;

                ProjectInstance.DbSettions.DatabaseProvider = DatabaseProvider.Oracle;
            }

            ProjectInstance.DbSettions.SuffixForTables = txtSuffixForTables.Text;
            ProjectInstance.DbSettions.SuffixForViews = txtSuffixForViews.Text;

            ProjectInstance.DbSettions.PrefixForTables = txtPrefixForTables.Text;
            ProjectInstance.DbSettions.PrefixForViews = txtPrefixForViews.Text;

            ProjectInstance.DbSettions.IgnoredPrefixes.Clear();
            foreach (var item in lstIgnoredPrefixes.Items)
                ProjectInstance.DbSettions.IgnoredPrefixes.Add(item.ToString());

            ProjectInstance.DbSettions.IgnoredSuffixes.Clear();
            foreach (var item in lstIgnoredSuffixes.Items)
                ProjectInstance.DbSettions.IgnoredSuffixes.Add(item.ToString());
        }