//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); } }
public OperationResult UpdateSummonerByAccountId(int accountId) { if (!Connected) { return(OperationResult.NotConnected); } WriteLine("Updating account {0}", accountId); ConcurrentRPC concurrentRPC = new ConcurrentRPC(RPC, accountId); OperationResult result = concurrentRPC.Run(); if (result == OperationResult.Success) { if (concurrentRPC.PublicSummonerData == null) { //This means that the summoner was not found, even though the other structures are actually non-null return(OperationResult.NotFound); } Summoner newSummoner = new Summoner(concurrentRPC.PublicSummonerData, Region); Summoner summoner = StatisticsService.GetSummoner(Region, accountId); if (summoner == null) { //The summoner wasn't in the database yet, add them using (var connection = Provider.GetConnection()) InsertNewSummoner(newSummoner, connection); summoner = newSummoner; } else { //Copy data that might have been changed summoner.SummonerName = newSummoner.SummonerName; summoner.InternalName = newSummoner.InternalName; summoner.SummonerLevel = newSummoner.SummonerLevel; summoner.ProfileIcon = newSummoner.ProfileIcon; } //Perform a full update using (var connection = Provider.GetConnection()) UpdateSummoner(summoner, concurrentRPC, connection); return(OperationResult.Success); } return(result); }
Reply ApiSummonerProfile(Request request) { PrivilegeCheck(request); var arguments = request.Arguments; string regionAbbreviation = (string)request.Arguments[0]; int accountId = (int)request.Arguments[1]; Worker worker = GetWorkerByAbbreviation(regionAbbreviation); SummonerProfileResult output; Summoner summoner = StatisticsService.GetSummoner(worker.Region, accountId); if (summoner != null) { output = new SummonerProfileResult(summoner); } else { output = new SummonerProfileResult(OperationResult.NotFound); } return(GetJSONReply(output)); }
Reply ApiSetAutomaticUpdates(Request request) { PrivilegeCheck(request); var arguments = request.Arguments; string regionAbbreviation = (string)request.Arguments[0]; int accountId = (int)request.Arguments[1]; bool updateAutomatically = (int)request.Arguments[2] != 0; Worker worker = GetWorkerByAbbreviation(regionAbbreviation); SummonerAutomaticUpdatesResult output; Summoner summoner = StatisticsService.GetSummoner(worker.Region, accountId); if (summoner != null) { OperationResult result = SetSummonerAutomaticUpdates(summoner, updateAutomatically); output = new SummonerAutomaticUpdatesResult(result); } else { output = new SummonerAutomaticUpdatesResult(OperationResult.NotFound); } return(GetJSONReply(output)); }
Reply ApiSummonerStatistics(Request request) { Profiler profiler = new Profiler(false, "ApiSummonerStatistics", GlobalHandler); profiler.Start("PrivilegeCheck"); PrivilegeCheck(request); profiler.Stop(); profiler.Start("GetSummoner"); var arguments = request.Arguments; string regionAbbreviation = (string)request.Arguments[0]; int accountId = (int)request.Arguments[1]; Worker worker = GetWorkerByAbbreviation(regionAbbreviation); SummonerStatisticsResult output; Summoner summoner = StatisticsService.GetSummoner(worker.Region, accountId); profiler.Stop(); if (summoner != null) { using (var connection = GetConnection()) { profiler.Start("GetSummonerStatistics"); SummonerStatistics statistics = GetSummonerStatistics(summoner, connection); profiler.Stop(); profiler.Start("SummonerStatisticsResult"); output = new SummonerStatisticsResult(statistics); profiler.Stop(); } } else { output = new SummonerStatisticsResult(OperationResult.NotFound); } profiler.Start("GetJSONReply"); Reply reply = GetJSONReply(output); profiler.Stop(); return(reply); }
Reply ApiSummonerGames(Request request) { PrivilegeCheck(request); var arguments = request.Arguments; string regionAbbreviation = (string)request.Arguments[0]; int accountId = (int)request.Arguments[1]; Worker worker = GetWorkerByAbbreviation(regionAbbreviation); SummonerGamesResult output; Summoner summoner = StatisticsService.GetSummoner(worker.Region, accountId); if (summoner != null) { using (var connection = GetConnection()) { List <ExtendedPlayer> games = GetSummonerGames(summoner, connection); output = new SummonerGamesResult(games); } } else { output = new SummonerGamesResult(OperationResult.NotFound); } return(GetJSONReply(output)); }