static void Main(string[] args) { string conn_str = Constants.SqlConnectionString; Constants.States st; Constants.States action = Constants.States.OK; SqlConnection conn = Database.Connect(conn_str); try { // FIX ELO & YEARS NUMBER CAN BE ANYTHING. if ((st = Validator.Arguments(args, ref action)) != Constants.States.OK) { ErrorHandler.Errors(st); } // Possible arguments: // 1) Elo N where N is the number of teams < 100 (sorted) : List of ELO rated teams // 2) Years N where N is the number of teams < 100 (sorted) : Give yearly lead of each team. [revised for month weight] // 3) Add file where FILE is a .txt file with RSSF.org format conn.Open(); if (action == Constants.States.ARGUMENT_ADD) { Reader reader = new Reader(); if ((st = reader.Read(args[Constants.Argument_Number_Position], conn)) != Constants.States.OK) { ErrorHandler.Errors(st); } } // MAKE CONSTANTS FOR THIS.... //query = "CREATE TABLE IF NOT EXISTS " + argument + " (Team char(50), Before_ELO float, After_ELO float)"; //SqlCommand command = new SqlCommand(query, conn); //command.ExecuteNonQuery(); } catch (Exception ex) { ErrorHandler.Exception(ex); } finally { conn.Close(); conn.Dispose(); } Console.ReadLine(); }
public Constants.States Read(string argument, SqlConnection conn) { /* * Reads upon a txt file, defined by certain parameters, procceses the information * and returns a DataTable with some pre-established configuration. * Exception is catched by Program.cs * Errors will return a null dt(? */ // HARD CODED string path = @"C:\Users\TIAGO\txts\" + argument + ".txt"; Constants.States state = Constants.States.OK; if (!File.Exists(path)) { return(Constants.States.ERROR_FILE_PATH_NOT_EXIST); } using (StreamReader sr = new StreamReader(path)) { string line = ""; int i = 1; // Go through data. while ((line = sr.ReadLine()) != null) { //Look for the FIRST path delimiter. if (line.ToLower().Contains(Constants.File_PathDelimiter.ToLower() + " " + i)) { // Update current path delimiter count i++; for (i = 2; ; i++) { List <string[]> temp = new List <string[]>(); if ((state = this.Process(i, ref temp, ref line, sr)) != Constants.States.OK) { Database.Update(conn, temp); break; } Database.Update(conn, temp); } } } } return(Constants.States.OK); }
public static Constants.States Arguments(string[] arguments, ref Constants.States action) { // Possible arguments: // 1) Elo N where N is the number of teams < 100 (sorted) : List of ELO rated teams // 2) Years N where N is the number of teams < 100 (sorted) : Give yearly lead of each team. [revised for month weight] // 3) Add file where FILE is a .txt file with RSSF.org format if (arguments.Length > Constants.ArgumentsLength) { return(Constants.States.ERROR_MAX_ARGUMENT); } if (!IsValidArgument(arguments)) { return(Constants.States.ERROR_NOT_VALID_ARGUMENT); } action = GetArgument(arguments[Constants.Argument_String_Position]); return(Constants.States.OK); }
public static void Errors(Constants.States st) { Console.WriteLine("Error: " + st); Console.ReadLine(); }