Exemple #1
0
        List <UserTeamPickId> ReadUserTeamPickIdList(IDataReader reader)
        {
            try
            {
                List <UserTeamPickId> list = new List <UserTeamPickId>();
                int column1 = reader.GetOrdinal("userteamid");
                int column2 = reader.GetOrdinal("gameweekid");
                int column3 = reader.GetOrdinal("position");

                //UserTeamPickId userTeamPickId = new UserTeamPickId(0, 0, 0);
                //UserTeamPickId userTeamChipId = new UserTeamPickId();

                while (reader.Read())
                {
                    //check for the null value and than add
                    if (!reader.IsDBNull(column1))
                    {
                        UserTeamPickId userTeamPickId = new UserTeamPickId(0, 0, 0);

                        userTeamPickId.userteamid = reader.GetInt32(column1);
                        userTeamPickId.gameweekid = reader.GetInt32(column2);
                        userTeamPickId.position   = reader.GetInt32(column3);
                        list.Add(userTeamPickId);
                    }
                }
                return(list);
            }
            catch (Exception ex)
            {
                Logger.Error("UserTeamPick Repository (ReadUserTeamPickIdList) error: " + ex.Message);
                throw ex;
            }
        }
Exemple #2
0
        //public static void GetUserTeamPickDataJson(int userTeamId, int gameweekId, UserTeamPicks userTeamPicksInsert, UserTeamPickAutomaticSubs userTeamPickAutomaticSubsInsert, string userTeamPicksUrl, SqlConnection db)
        //{
        //    //Logger.Out("GetUserTeamPickDataJson: Gameweek " + Convert.ToString(gameweekId) + " - starting");

        //    var urlUserTeamPicks = "";

        //    try
        //    {
        //        UserTeamPickRepository userTeamPickRepository = new UserTeamPickRepository();

        //        urlUserTeamPicks = string.Format(userTeamPicksUrl, userTeamId, gameweekId);

        //        HttpClient clientUserTeamPicks = new HttpClient();
        //        JsonSerializer serializerUserTeamPicks = new JsonSerializer();
        //        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

        //        //Logger.Out("Before using statements - url: " + urlUserTeamPicks);

        //        using (Stream sUserTeamPicks = clientUserTeamPicks.GetStreamAsync(urlUserTeamPicks).Result)
        //        using (StreamReader srUserTeamPicks = new StreamReader(sUserTeamPicks))
        //        using (JsonReader readerUserTeamPicks = new JsonTextReader(srUserTeamPicks))
        //        {
        //            Globals.ApiCalls += 1;
        //            Globals.ApiUserTeamPickCalls += 1;

        //            // read the json from a stream
        //            // json size doesn't matter because only a small piece is read at a time from the HTTP request
        //            var userTeamPickData = serializerUserTeamPicks.Deserialize<UserTeamPickData>(readerUserTeamPicks);

        //            if (userTeamPickData != null)
        //            {
        //                GetUserTeamPickJson(userTeamId, gameweekId, userTeamPicksInsert, userTeamPickData, db);
        //                GetUserTeamPickAutomaticSubJson(userTeamId, gameweekId, userTeamPickAutomaticSubsInsert, userTeamPickData, db);
        //            }
        //        }
        //        //Logger.Out("GetUserTeamPickDataJson: Gameweek " + Convert.ToString(gameweekId) + " - completed");
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error("GetUserTeamPickDataJson data exception (UserTeamId: " + userTeamId.ToString() + " GameweekId: " + gameweekId.ToString() + "): " + ex.Message);
        //        //throw new Exception("GetUserTeamPickDataJson data exception (UserTeamId: " + userTeamId.ToString() + "): " + ex.Message);
        //        GetUserTeamPickDataJson(userTeamId, gameweekId, userTeamPicksInsert, userTeamPickAutomaticSubsInsert, userTeamPicksUrl, db);
        //    }
        //}

        public static void GetUserTeamPickJson(int userTeamId, int gameweekId, string urlUserTeamPicks, UserTeamPicks userTeamPicksInsert, UserTeamPickAutomaticSubs userTeamPickAutomaticSubsInsert, SqlConnection db)
        {
            try
            {
                //Process UserTeamPick and UserTeamPickAutomaticSub
                if (gameweekId >= Globals.MaxGWFromPicksForUserTeamId)
                {
                    UserTeamPickRepository userTeamPickRepository = new UserTeamPickRepository();

                    urlUserTeamPicks = string.Format(urlUserTeamPicks, userTeamId, gameweekId);

                    JsonSerializer serializerUserTeamPicks = new JsonSerializer()
                    {
                        Formatting = Formatting.None
                    };

                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                    using (HttpClient clientUserTeamPicks = new HttpClient())
                        using (Stream sUserTeamPicks = clientUserTeamPicks.GetStreamAsync(urlUserTeamPicks).Result)
                            using (StreamReader srUserTeamPicks = new StreamReader(sUserTeamPicks))
                                using (JsonReader readerUserTeamPicks = new JsonTextReader(srUserTeamPicks))
                                {
                                    Globals.ApiCalls             += 1;
                                    Globals.ApiUserTeamPickCalls += 1;

                                    // read the json from a stream
                                    // json size doesn't matter because only a small piece is read at a time from the HTTP request
                                    var userTeamPickData = serializerUserTeamPicks.Deserialize <UserTeamPickData>(readerUserTeamPicks);

                                    if (userTeamPickData != null)
                                    {
                                        //Load UserTeamPick data
                                        //int userTeamPickIds_userteamid = 0;
                                        //int userTeamPickIds_gameweekid = 0;

                                        //UserTeamPickId userTeamPickId = new UserTeamPickId();
                                        //userTeamPickId.userteamid = userTeamId;
                                        //userTeamPickId.gameweekid = gameweekId;

                                        ///List<UserTeamPickId> userTeamPickIds = userTeamPickRepository.GetAllUserTeamPickIdsForUserTeamIdAndGameweekId(userTeamId, gameweekId, db);

                                        //if (userTeamPickIds.Count > 0)
                                        //{
                                        //    userTeamPickIds_userteamid = userTeamPickIds[0].userteamid;
                                        //    userTeamPickIds_gameweekid = userTeamPickIds[0].gameweekid;
                                        //}

                                        //UserTeamPicks userTeamPicksUpdate = new UserTeamPicks();

                                        foreach (UserTeamPick userTeamPick in userTeamPickData.picks)
                                        {
                                            UserTeamPickId userTeamPickId = new UserTeamPickId
                                                                            (
                                                userTeamId,
                                                gameweekId,
                                                userTeamPick.position
                                                                            );

                                            //needed if want to assign value from parent to add into db table
                                            userTeamPick.userteamid = userTeamId;
                                            userTeamPick.gameweekid = gameweekId;

                                            //if (!userTeamPickIds.Contains(userTeamPickId) && !userTeamPicksInsert.Contains(userTeamPick))
                                            if (!userTeamPicksInsert.Contains(userTeamPick))
                                            {
                                                userTeamPicksInsert.Add(userTeamPick);
                                            }
                                            //else
                                            //{
                                            //    userTeamPickRepository.UpdateUserTeamPick(userTeamPick);
                                            //}
                                        }
                                        //Logger.Out("GetUserTeamPickJson: Gameweek " + Convert.ToString(gameweekId) + " - completed");
                                    }
                                    GetUserTeamPickAutomaticSubJson(userTeamId, gameweekId, userTeamPickAutomaticSubsInsert, userTeamPickData, db);
                                }
                }
                //Logger.Out("GetUserTeamPickDataJson: Gameweek " + Convert.ToString(gameweekId) + " - completed");
            }
            catch (Exception ex)
            {
                Logger.Error("GetUserTeamPickJson data exception (UserTeamId:" + userTeamId.ToString() + "/GameweekId:" + gameweekId.ToString() + "): " + ex.Message);
                Logger.Error("GetUserTeamPickJson data exception (UserTeamId:" + userTeamId.ToString() + "/GameweekId:" + gameweekId.ToString() + "): skipping userteam/gameweek");
                //throw new Exception("GetUserTeamPickJson data exception (UserTeamId: " + userTeamId.ToString() + "): " + ex.Message);
                //GetUserTeamPickJson(userTeamId, gameweekId, urlUserTeamPicks, maxGWFromPicksForUserTeamId, userTeamPicksInsert, userTeamPickAutomaticSubsInsert, db);
                //if (gameweekId + 1 < Globals.ActualGameweek)
                //{
                //    gameweekId++;
                //    GetUserTeamPickJson(userTeamId, gameweekId, urlUserTeamPicks, maxGWFromPicksForUserTeamId, userTeamPicksInsert, userTeamPickAutomaticSubsInsert, db);
                //}
            }
        }