/// <summary>
 /// Constructor of MySQLDatabase
 /// </summary>
 /// <param name="aServerAddress">Network address of the server/computer where the database is located.</param>
 /// <param name="aDatabaseName">Name of the database instance.</param>
 /// <param name="aDatabaseUsername">Username of the account used to connect to the database.</param>
 /// <param name="aDatabasePassword">Password of the account used to connect to the database.</param>
 /// <param name="aDataCSV">Data from the TWB CSV file.</param>
 public SQLServerDatabase(string aServerAddress, string aDatabaseName, string aDatabaseUsername, string aDatabasePassword, CSVFileData aDataCSV)
 {
     _dataCSV = aDataCSV;
     //_connectionString = "Server = localhost\\SQLEXPRESS; Database = master; Trusted_Connection = True";
     _connectionString = String.Format(@"Data Source={0};Initial Catalog={1};User ID={2};Password={3}", aServerAddress, aDatabaseName, aDatabaseUsername, aDatabasePassword);
     _cnn = new SqlConnection(_connectionString);
     Console.WriteLine("Connecting to the SQL Server database {0}:{1} as {2}...", aServerAddress, aDatabaseName, aDatabaseUsername);
     _cnn.Open();
     Console.WriteLine("DONE\n");
     Console.WriteLine("Inserting the data into the database...");
     InsertData();
     Console.WriteLine("DONE\n");
     Console.WriteLine("Closing the connection...");
     _cnn.Close();
     Console.WriteLine("DONE\n");
 }
Beispiel #2
0
 /// <summary>
 /// Constructor of MySQLDatabase
 /// </summary>
 /// <param name="aServerAddress">Network address of the server/computer where the database is located.</param>
 /// <param name="aPort">Port used to connect to the MySQL database. 3306 by default.</param>
 /// <param name="aDatabaseName">Name of the database instance.</param>
 /// <param name="aDatabaseUsername">Username of the account used to connect to the database.</param>
 /// <param name="aDatabasePassword">Password of the account used to connect to the database.</param>
 /// <param name="aDataCSV">Data from the TWB CSV file.</param>
 public MySQLDatabase(string aServerAddress, string aPort, string aDatabaseName, string aDatabaseUsername, string aDatabasePassword, CSVFileData aDataCSV)
 {
     if (string.IsNullOrWhiteSpace(aPort))
     {
         aPort = "3306";
     }
     _dataCSV      = aDataCSV;
     _databaseName = aDatabaseName;
     //_connectionString = "Server = localhost\\SQLEXPRESS; Database = master; Trusted_Connection = True";
     _connectionString = String.Format(@"Server={0};Port={1};Database={2};UID={3};Password={4}", aServerAddress, aPort, aDatabaseName, aDatabaseUsername, aDatabasePassword);
     _cnn = new MySqlConnection(_connectionString);
     Console.WriteLine("Connecting to the MySQL database {0}:{1} as {2}...", aServerAddress, aDatabaseName, aDatabaseUsername);
     _cnn.Open();
     Console.WriteLine("DONE\n");
     Console.WriteLine("Inserting the data into the database...");
     InsertData();
     Console.WriteLine("DONE\n");
     Console.WriteLine("Closing the connection...");
     _cnn.Close();
     Console.WriteLine("DONE\n");
 }
Beispiel #3
0
        /// <summary>
        /// Entry point of the program.
        /// </summary>
        /// <param name="args">Unsued. Everything goes through the config.xml file.</param>
        static void Main(string[] args)
        {
            Console.WriteLine("|-----------------------------------------|\n" +
                              "| CSV Match Parser for tunawithbeacon.com |\n" +
                              "|-----------------------------------------|\n" +
                              "| Version                           1.3.0 |\n" +
                              "| Release Date                 2021-03-27 |\n" +
                              "| Author & Maintainer           @Servan42 |\n" +
                              "|-----------------------------------------|\n");


            // Maybe un-comment the following line if you have date problems.
            // Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us");

            try
            {
                // Read the config.
                Console.WriteLine("Loading the configuration from TWB_Parser.exe.config...");
                if (!File.Exists("TWB_Parser.exe.config"))
                {
                    throw new FileNotFoundException("ERROR: Config file not found.");
                }
                if (ConfigurationManager.AppSettings.Get("DatabaseType") != "MySQL" && ConfigurationManager.AppSettings.Get("DatabaseType") != "SQLServer")
                {
                    throw new FormatException("ERROR: Invalid database type in TWB_Parser.exe.config. The program only supports \"MySQL\" and \"SQLServer\".");
                }
                Console.WriteLine("DONE\n");

                // Parse the CSV file
                Console.WriteLine("Loading the data from \"{0}\"...", ConfigurationManager.AppSettings.Get("CSVMatchsFilename"));
                CSVFileData dataCSV = new CSVFileData(ConfigurationManager.AppSettings.Get("CSVMatchsFilename"));
                Console.WriteLine("DONE - {0} matches found.\n", dataCSV.Lines.Count);

                // Connect to the database, insert the information, and disconnect.
                if (ConfigurationManager.AppSettings.Get("DatabaseType") == "SQLServer")
                {
                    SQLServerDatabase sqlServerDB = new SQLServerDatabase(ConfigurationManager.AppSettings.Get("ServerAddress"),
                                                                          ConfigurationManager.AppSettings.Get("DatabaseName"),
                                                                          ConfigurationManager.AppSettings.Get("DatabaseUsername"),
                                                                          ConfigurationManager.AppSettings.Get("DatabasePassword"),
                                                                          dataCSV);
                    Console.WriteLine("\nSuccessful.");
                }
                else if (ConfigurationManager.AppSettings.Get("DatabaseType") == "MySQL")
                {
                    MySQLDatabase mySqlDB = new MySQLDatabase(ConfigurationManager.AppSettings.Get("ServerAddress"),
                                                              ConfigurationManager.AppSettings.Get("PortMySQL"),
                                                              ConfigurationManager.AppSettings.Get("DatabaseName"),
                                                              ConfigurationManager.AppSettings.Get("DatabaseUsername"),
                                                              ConfigurationManager.AppSettings.Get("DatabasePassword"),
                                                              dataCSV);
                    Console.WriteLine("\nSuccessful.");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                // Stacktrace for debugging.
                // Console.WriteLine("\n" + ex.StackTrace);
                Console.WriteLine("\nAborting.");
            }
            Console.WriteLine("\nPress any key to close.");
            Console.ReadKey();
        }