//public void LoadPlayersFromFile() //{ // var players = File.ReadAllLines(Config.DBPlayersInfoPath); // foreach (var player in players) // { // var playerinfo = player.Split(';'); // if (playerinfo.Length < 5) // { // Console.WriteLine(playerinfo + " - неверный формат сторки"); // continue; // } // SqliteCommand cmd = Connection.CreateCommand(); // cmd.CommandText = string.Format("INSERT INTO player (number, name, surname, surname_lower,position_id,vk_href,insta_href) " + // "VALUES({0}, '{1}', '{2}', '{3}', (select ID from position_dic where name = '{4}'), '{5}','{6}')", // playerinfo[0].Trim(), playerinfo[2].Trim(), playerinfo[1].Trim(), playerinfo[1].Trim().ToLower(), playerinfo[3],playerinfo[4], playerinfo[5]); // try // { // cmd.ExecuteNonQuery(); // } // catch (SqliteException ex) // { // Console.WriteLine(ex.Message); // } // } //} //public void LoadTeamsFromFile() //{ // var teams = File.ReadAllText(Config.DBTeamsInfoPath); // Match m = Regex.Match(teams, "(?<name>.*)\\((?<town>.*)\\)"); // while (m.Success) // { // SqliteCommand cmd = Connection.CreateCommand(); // cmd.CommandText = string.Format("INSERT INTO team (name, town, name_lower) VALUES('{0}', '{1}', '{2}')", // m.Groups["name"].ToString().Trim(), m.Groups["town"].ToString().Trim(), m.Groups["name"].ToString().Trim().ToLower()); // try // { // cmd.ExecuteNonQuery(); // } // catch (SqliteException ex) // { // Console.WriteLine(ex.Message); // } // m = m.NextMatch(); // } //} //public void LoadGamesFromFile() //{ // var teams = File.ReadAllText(Config.DBGamesInfoPath); // teams = teams.Replace("\r", "").Replace("\n", ""); // var games = teams.Split(new[] {"---"}, StringSplitOptions.RemoveEmptyEntries); // var players = GetAllPlayerWitoutStatistic(); // //var season = games[0]; // var season = GetSeasonByNameOrInsert(games[0]); // for (int i = 1; i < games.Length; i++) // { // var game = games[i]; // var gameinfo = game.Split(';'); // Game newgame = new Game(); // DateTime date = DateTime.Now; // DateTime.TryParse(gameinfo[0], CultureInfo.CreateSpecificCulture("ru"), DateTimeStyles.None, out date); // newgame.Date = date; // //newgame.Tournament = new Tournament(gameinfo[1]); // newgame.Tournament = GetTournamentByNameOrInsert(gameinfo[1], season.Id); // newgame.Team2 = gameinfo[2]; // var score = gameinfo[3].Split(':'); // newgame.Score = new Tuple<int, int>(Convert.ToInt32(score[0]), Convert.ToInt32(score[1])); // SqliteCommand cmd = Connection.CreateCommand(); // cmd.CommandText = string.Format("INSERT INTO game (date, opteam_id, opteamscore,tournament_id) " + // "VALUES('{0}',(select ID from team where name_lower = '{1}' )," + // " {2}, {3})", // newgame.Date, newgame.Team2.ToLower(), newgame.Score.Item2, newgame.Tournament.Id); // try // { // cmd.ExecuteNonQuery(); // cmd.CommandText = @"select last_insert_rowid()"; // newgame.Id = Convert.ToInt32((long) cmd.ExecuteScalar()); // } // catch (SqliteException ex) // { // Console.WriteLine(ex.Message); // continue; // } // var goals = gameinfo[4].Split(':')[1]; // var playergoal = goals.Split(','); // foreach (var pg in playergoal) // { // string name; // var num = 1; // Regex re = new Regex(@"(?<name>.*)\((?<num>\d+)\)"); // if (re.IsMatch(pg)) // { // var m = re.Match(pg); // name = m.Groups["name"].ToString().Trim(); // num = Convert.ToInt32(m.Groups["num"].ToString()); // } // else // { // name = pg.Trim(); // } // var player = players.Find(p => p.Surname == name); // if (player == null) continue; // for (int j = 0; j < num; j++) // { // AddAction(newgame.Id, player.Id, Action.Гол); // } // } // } //} #endregion public static void Initialization() { Console.WriteLine("Start Initialization"); File.Delete(Config.DBFile); DBCore db = new DBCore(); Console.WriteLine("CreateDB"); db.CreateDefaultDB(); //Console.WriteLine("FillPlayersFromFile"); //db.LoadPlayersFromFile(); //Console.WriteLine("FillTeamsFromFile"); //db.LoadTeamsFromFile(); //Console.WriteLine("FillGamesFromFile"); //db.LoadGamesFromFile(); db.Disconnect(); Console.WriteLine("Finish Initialization"); }
static DB() { DBConnection = new DBCore(); DBCommands = new DBCommands(); }
static void Main(string[] args) { //to ignore untrusted SSL certificates, linux and mono love it ;) ServicePointManager.ServerCertificateValidationCallback = Network.SSL.Validator; Stopwatch sw = new Stopwatch(); if (InitFromCode) { sw.Start(); } Console.CancelKeyPress += Console_CancelKeyPress; #region Тест для генератора статы //g.BestPlayer = new Player(71, "Кирилл", "Зайцев"); //g.Team2 = "РЭУ"; //g.Date = DateTime.Now; //g.Tournament = new Tournament("МСХЛ"); ////ig.Roster(g); /////////////////////////////////////////////////////// //g.Viewers = 551; //g.Team2 = "Тампа-Бэй Лайтнинг"; //g.Tournament = new Tournament("НХЛ"); //g.Score = new Tuple<int, int>(7, 6); //var kek = new Random(); //g.Stat1.Shots = kek.Next(0, 100); //g.Stat2.Shots = kek.Next(0, 100); //g.Stat1.ShotsIn = kek.Next(0, 100); //g.Stat2.ShotsIn = kek.Next(0, 100); //g.Stat1.Faceoff = kek.Next(0, 100); //g.Stat2.Faceoff = kek.Next(0, 100); //g.Stat1.Hits = kek.Next(0, 100); //g.Stat2.Shots = kek.Next(0, 100); //g.Stat1.Penalty = kek.Next(0, 100); //g.Stat2.Penalty = kek.Next(0, 100); //g.Stat1.BlockShots = kek.Next(0, 100); //g.Stat2.BlockShots = kek.Next(0, 100); //g.Place = new Place(@"Малая Арена ВТБ, г. Москва"); //ig.GameStatistic(g); //return; //#endregion //#region тест для подгрузки разметки статы //GameStat stat1 = new GameStat("Images\\gameStat.txt"); #endregion if (InitFromCode || args.Length > 0 && args[0] == "init") { try { DBCore.Initialization(); } catch (Exception e) { Console.WriteLine("Unknown DBCore exception: " + e.Message); } } if (LoadIncome || args.Length > 0 && args[0] == "load") { Parse.ProcessFiles(); } if (InitFromCode) { sw.Stop(); Console.WriteLine($"Инициализация и обработка файлов заняла {sw.Elapsed.ToString("g")}"); } var ig = new ImageGenerator(); Game g = DB.DBCommands.DBGame.GetLastGame(null); ig.GameStatistic(g); Console.WriteLine("Starting Bot..."); try { AviaBot.Start(); } catch (Exception e) { Console.WriteLine("Unknown AviaBot exception: " + e.Message); Console.WriteLine("Bot will be terminated."); } }