示例#1
0
        public Worker(IGlobalHandler globalHandler, StatisticsService statisticsService, EngineRegionProfile regionProfile, Configuration configuration, Database provider)
        {
            Running = false;

            GlobalHandler = globalHandler;
            StatisticsService = statisticsService;
            Provider = provider;

            Configuration = configuration;
            Profile = regionProfile;

            AutomaticUpdatesThread = null;
            MassiveSummonerLookupThread = null;

            Connected = false;

            Profiler = new Profiler();
            ActiveAccountIds = new HashSet<int>();

            Region = (RegionType)Profile.Identifier;

            AutomaticUpdateInterval = configuration.AutomaticUpdateInterval;

            InitialiseAuthenticationProfile();
        }
示例#2
0
        public Program()
        {
            Serialiser = new Nil.Serialiser<Configuration>(ConfigurationPath);
            Configuration = Serialiser.Load();

            Database databaseProvider = new Database(Configuration);
            StatisticsService = new StatisticsService(this, Configuration, databaseProvider);
            WebService = new WebService(this, Configuration, StatisticsService, databaseProvider);
        }
示例#3
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);
            }
        }
示例#4
0
        public Program()
        {
            Serialiser = new Nil.Serialiser<Configuration>(ConfigurationPath);
            Configuration = Serialiser.Load();
            //Check for configuration errors
            Configuration.Check();
            //Store it right away to automatically remove unused content and provide new default values
            Serialiser.Store(Configuration);

            Database databaseProvider = new Database(Configuration);
            StatisticsService = new StatisticsService(this, Configuration, databaseProvider);
            WebService = new WebService(this, Configuration, StatisticsService, databaseProvider);
            UpdateService = new UpdateService(Configuration, this);
        }
示例#5
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);
        }
示例#6
0
        Reply Index(Request request)
        {
            List <string> regionStrings = new List <string>();

            foreach (var profile in StatisticsService.GetActiveProfiles())
            {
                //Avoid race conditions since the profile is modified by other threads
                lock (profile)
                    regionStrings.Add(string.Format("[{0}, {1}, {2}]", GetJavaScriptString(profile.Abbreviation), GetJavaScriptString(profile.Description), profile.Identifier));
            }
            string regions = string.Format("[{0}]", string.Join(", ", regionStrings));
            string content = IndexContents;

            content = content.Replace("$REGIONS", regions);
            content = content.Replace("$PRIVILEGES", GetPrivilegeString(request));
            content = content.Replace("$REVISION", Assembly.GetEntryAssembly().GetName().Version.Revision.ToString());
            return(new Reply(content));
        }
        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);
        }
示例#8
0
        public WebService(IGlobalHandler globalHandler, Configuration configuration, StatisticsService statisticsService, Database databaseProvider)
        {
            GlobalHandler = globalHandler;
            ProgramConfiguration = configuration;
            ServiceConfiguration = configuration.Web;
            StatisticsService = statisticsService;
            Server = new WebServer(ServiceConfiguration.Host, ServiceConfiguration.Port, ServiceConfiguration.EnableReverseProxyRealIPMode, this, this);

            DatabaseProvider = databaseProvider;

            WebServiceProfiler = new Profiler();

            Serialiser = new JavaScriptSerializer();

            Views = new HashSet<string>();
            PRNG = new Random();

            LoadIndex();
            InitialiseHandlers();
        }
示例#9
0
        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));
        }
示例#10
0
        public WebService(IGlobalHandler globalHandler, Configuration configuration, StatisticsService statisticsService, Database databaseProvider)
        {
            GlobalHandler        = globalHandler;
            ProgramConfiguration = configuration;
            ServiceConfiguration = configuration.Web;
            StatisticsService    = statisticsService;
            Server = new WebServer(ServiceConfiguration.Host, ServiceConfiguration.Port, ServiceConfiguration.EnableReverseProxyRealIPMode, this, this);

            DatabaseProvider = databaseProvider;

            WebServiceProfiler = new Profiler();

            Serialiser = new JavaScriptSerializer();

            Views = new HashSet <string>();
            PRNG  = new Random();

            LoadIndex();
            InitialiseHandlers();
        }
示例#11
0
        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));
        }
示例#12
0
        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);
        }
示例#13
0
        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));
        }
示例#14
0
        public Worker(IGlobalHandler globalHandler, StatisticsService statisticsService, EngineRegionProfile regionProfile, Configuration configuration, Database provider)
        {
            Running = false;

            GlobalHandler     = globalHandler;
            StatisticsService = statisticsService;
            Provider          = provider;

            Configuration = configuration;
            Profile       = regionProfile;

            AutomaticUpdatesThread = null;

            Connected = false;

            Profiler         = new Profiler();
            ActiveAccountIds = new HashSet <int>();

            Region = (RegionType)Profile.Identifier;

            AutomaticUpdateInterval = configuration.AutomaticUpdateInterval;

            InitialiseAuthenticationProfile();
        }