Exemplo n.º 1
0
        //Returns true if the summoner was updated successfully, false otherwise
        public OperationResult FindSummoner(string summonerName, ref Summoner outputSummoner)
        {
            if (!Connected)
            {
                return(OperationResult.NotConnected);
            }

            try
            {
                Summoner summoner = StatisticsService.GetSummoner(Region, summonerName);
                if (summoner != null)
                {
                    //The summoner is already in the database, don't update them, just provide the account ID
                    //This behaviour is more convenient for the general use case
                }
                else
                {
                    //The summoner name is not in the database
                    //Retrieve the account ID to see if it's actually a new summoner or just somebody who changed their name
                    PublicSummoner publicSummoner = RPC.GetSummonerByName(summonerName);
                    if (publicSummoner == null)
                    {
                        //No such summoner
                        return(OperationResult.NotFound);
                    }

                    using (var connection = Provider.GetConnection())
                    {
                        summoner = StatisticsService.GetSummoner(Region, publicSummoner.acctId);
                        if (summoner != null)
                        {
                            //It's a summoner who was already in the database, just their name changed
                            UpdateSummonerFields(summoner, connection);
                        }
                        else
                        {
                            //It's a new summoner
                            summoner = new Summoner(publicSummoner, Region);
                            InsertNewSummoner(summoner, connection);
                            StatisticsService.AddSummonerToCache(Region, summoner);
                        }
                    }
                }
                outputSummoner = summoner;
                return(OperationResult.Success);
            }
            catch (RPCTimeoutException)
            {
                return(OperationResult.Timeout);
            }
            catch (RPCNotConnectedException)
            {
                return(OperationResult.NotConnected);
            }
        }
Exemplo n.º 2
0
        void UpdateSummonerFields(Summoner summoner, DbConnection connection, bool isFullUpdate = false)
        {
            string[] fields =
            {
                "summoner_name",
                "internal_name",

                "summoner_level",
                "profile_icon",

                "has_been_updated",

                "time_updated",
            };

            long currentTime = Time.UnixTime();

            if (isFullUpdate)
            {
                summoner.HasBeenUpdated = true;
                summoner.TimeUpdated    = (int)currentTime;
            }

            using (var update = Command("update summoner set {0} where id = :summoner_id", connection, GetUpdateString(fields)))
            {
                update.Set("summoner_id", summoner.Id);

                update.SetFieldNames(fields);

                update.Set(summoner.SummonerName);
                update.Set(summoner.InternalName);

                update.Set(summoner.SummonerLevel);
                update.Set(summoner.ProfileIcon);

                update.Set(summoner.HasBeenUpdated);

                update.Set(currentTime);

                update.Execute();
            }

            //Inform the statistics service about the update
            StatisticsService.AddSummonerToCache(Region, summoner);
        }