コード例 #1
0
        public void Initialize()
        {
            string dbFileLocation = Path.Combine(Environment.CurrentDirectory, "UserData", "HitDatabase.sqlite");

            Plugin.Log.Debug($"Opening database located at: {dbFileLocation}");

            _dbConnection = new SQLiteConnection($"Data Source={dbFileLocation}");
            _dbConnection.Open();

            // prepare database tables
            using (var dbCommand = _dbConnection.CreateCommand())
            {
                foreach (string tableName in DatabaseSchemas.TableSchemas.Keys)
                {
                    if (!CheckDatabaseTableExists(dbCommand, tableName))
                    {
                        dbCommand.CommandText = DatabaseSchemas.BuildCreateTableStatement(tableName);
                        dbCommand.ExecuteNonQuery();
                    }
                }
            }
        }
コード例 #2
0
        public static void ProcessArguments(string[] args)
        {
            SetDefaultConfiguration();
            try
            {
                for (int i = 0; i < args.Length; i++)
                {
                    string arg = args[i].ToLower();
                    switch (arg)
                    {
                    case HelpSwitch:
                        PrintHelpPage();
                        Environment.Exit((int)ExitCode.OK);
                        break;

                    case ConfigFileSwitch:
                        AppConfigReader.LoadConfigurationFromFile(args[++i]);
                        ImportFromConfigFile();
                        break;

                    // Upgrade Script options
                    case UpgradeScriptSwitch:
                        RunUpgradeScripts = true;
                        break;

                    case UpgradeScriptDirectorySwitch:
                        UpgradeScriptDirectory = args[++i];
                        break;

                    case UpgradeScriptFileRegexSwitch:
                        UpgradeScriptFileRegex = args[++i];
                        break;

                    case UpgradeScriptTemplateGuidMonikerSwitch:
                        UpgradeScriptTemplateGuidMonikerPrefix = args[++i];
                        break;

                    // Entity code generation options
                    case EntityCodeGenerationSwitch:
                        RunEntityCodeGeneration = true;
                        break;

                    case TemplateDirectorySwitch:
                        TemplateDirectory = args[++i];
                        break;

                    case DatabaseSchemaListSwitch:
                        DatabaseSchemas = args[++i].Split(';');
                        break;

                    case CodeGenOutputSwitch:
                        EntityCodeOutputDirectory = args[++i];
                        break;

                    // Code build options
                    case CodeBuildSwitch:
                        RunCodeBuild = true;
                        break;

                    case ProjectNameSwitch:
                        ProjectName = args[++i];
                        break;


                    // Logging options
                    case LogFileSwitch:
                        DoLogging = true;
                        SetLogFile(args[++i]);
                        break;

                    case DebugSwitch:
                    case VerboseLoggingSwitch:
                        VerboseLogging = true;
                        break;

                    case LogMessagePrefixSwitch:
                        LogMessagePrefix = args[++i];
                        break;

                    // Database options
                    case DatabaseConnectionStringSwitch:
                        ConnectionString = args[++i];
                        break;

                    case DatabaseSwitch:
                        Database = args[++i];
                        break;
                    }
                }

                CheckDatabase();
                if (DatabaseSchemas.Contains("*"))
                {
                    string schemaQuery =
                        $"USE [{Database}] " +
                        "SELECT DISTINCT s.[name] FROM sys.tables t " +
                        "INNER JOIN sys.schemas s ON s.schema_id = t.schema_id " +
                        "WHERE s.[name] != 'dbo' " +
                        "UNION ALL SELECT 'dbo'";
                    var    queryResults = SQLInterface.ExecuteQueryIntoDataTable(schemaQuery);
                    string result       = "";
                    foreach (DataRow row in queryResults.Rows)
                    {
                        result += row.ItemArray[0].ToString() + ",";
                    }

                    DatabaseSchemas = result.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"ERROR: {e.Message}");
                PrintHelpPage();
                Environment.Exit((int)ExitCode.ArgumentError);
            }
        }