public bool ProcessClassicMatchResultsResponse(MatchDetailsResponse response, MatchTimeLineResponse timelineResponse, DbAdapterBase Adapter)
        {
            if (response == null)
            {
                LoggersAdapter.Warn($"Пришел пустой {nameof(response)}");
                throw new ArgumentNullException(nameof(response));
            }

            if (timelineResponse == null)
            {
                LoggersAdapter.Warn($"Пришел пустой {nameof(timelineResponse)}");
                throw new ArgumentNullException(nameof(timelineResponse));
            }

            var teamDlStats = response.teams[0];
            var teamUrStats = response.teams[1];

            var matchResult = new MatchResultDbClass
            {
                Duration = TimeSpan.FromSeconds(response.gameDuration),
                GameType = response.gameType,
                Id       = response.gameId,
            };

            FillCommonResultData(teamDlStats, teamUrStats, matchResult);
            FillMatchLogData(response, timelineResponse, matchResult);

            if (SaveMatchInfo(matchResult, Adapter))
            {
                return(true);
            }

            LoggersAdapter.Info($"Не удалось сохранить информацию о матче в БД. Матч {response.gameId}");
            return(false);
        }
예제 #2
0
        private void ProcessFeaturedGamesResponse(SpectatorGamesResponse response)
        {
            if (response == null)
            {
                LoggersAdapter.Warn($"Пришел пустой {nameof(response)}");
                throw new ArgumentNullException(nameof(response));
            }

            using (var transaction = Adapter.Connection.BeginTransaction())
            {
                try
                {
                    foreach (var gameMatch in response.gameList) // .Where(x => x.participants.All(part => !part.bot)) TODO: нужно или нет
                    {
                        const string q = "INSERT INTO lol.MatchDescription (id, dt_insert, dt_start, platform_id, game_mode, map_id) " +
                                         "VALUES (@game_id, UTC_TIMESTAMP(), @game_start_time, @platform_id, @game_mode, @map_id) " +
                                         "ON DUPLICATE KEY UPDATE id = id;";

                        var cmd = new MySqlCommand(q)
                        {
                            Connection  = Adapter.Connection,
                            Transaction = transaction,
                        };
                        cmd.Parameters.AddWithValue("@game_id", gameMatch.gameId);
                        cmd.Parameters.AddWithValue("@game_start_time", Utils.FromMilisecEpochTime(gameMatch.gameStartTime));
                        cmd.Parameters.AddWithValue("@platform_id", gameMatch.platformId);
                        cmd.Parameters.AddWithValue("@game_mode", gameMatch.gameMode);
                        cmd.Parameters.AddWithValue("@map_id", gameMatch.mapId);

                        cmd.ExecuteNonQuery();
                    }

                    transaction.Commit();
                }
                catch (MySqlException ex)
                {
                    try
                    {
                        transaction.Rollback();
                    }
                    catch (Exception e)
                    {
                        LoggersAdapter.Info($"Ошибка при попытке отката изменений в БД: {e}");
                    }
                }
                catch (Exception e)
                {
                    LoggersAdapter.Info($"Ошибка при попытке добавить новые матчи: {e}");
                }
            }
        }