Ejemplo n.º 1
0
        /// <summary>
        /// Returns a List of ints that represent Match Id's from a file in the matches Blob storage container
        /// </summary>
        /// <param name="filename">Name of file that contains a JSONified list of Ints</param>
        /// <returns>List of ints</returns>
        public List <int> LoadMatchsetFromFile(string filename)
        {
            try
            {
                var container = ApiTools.GetBlobContainer("matches");

                var blob = container.GetBlockBlobReference(filename);

                if (!blob.Exists())
                {
                    return(new List <int>());
                }

                var json = blob.DownloadText();

                var toReturn = JsonConvert.DeserializeObject <int[]>(json);
                Logger.LogMessageToFile(GetType().Name, "Matchset loaded from file");

                return(toReturn.ToList());
            }
            catch (Exception e)
            {
                Logger.LogMessageToFile(GetType().Name, e.Message);
                return(new List <int>());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Used to upload the Template file for ItemSets
        /// </summary>
        public static void UploadItemSetTemplate()
        {
            var container = ApiTools.GetBlobContainer("itemsets");

            var blob = container.GetBlockBlobReference("ItemSetTemplate.txt");

            using (var r = File.OpenRead(ConfigurationManager.AppSettings["ItemSetTemplatePath"]))
            {
                blob.UploadFromStream(r);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns all Blob items from the Cache
        /// </summary>
        /// <param name="cache">Name of Cache to load from</param>
        /// <returns></returns>
        public static List <T> GetAllFromCache(string cache)
        {
            var container = ApiTools.GetBlobContainer(cache);

            var allBlobs = container.ListBlobs(null, true);

            var toReturn = new List <T>();

            foreach (var blob in allBlobs)
            {
                var temp = (CloudBlockBlob)blob;
                toReturn.Add(JsonConvert.DeserializeObject <T>(temp.DownloadText()));
            }

            return(toReturn);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns all Blobs in a Cache that match based on a certain Prefix
        /// </summary>
        /// <param name="cache">Cache to load from</param>
        /// <param name="region">Region of Data</param>
        /// <param name="champId">ChampId of Data</param>
        /// <param name="role">Role of Data</param>
        /// <returns></returns>
        public static List <T> GetListFromCache(string cache, string region, int champId, string role)
        {
            var container = ApiTools.GetBlobContainer(cache);

            var allBlobs = container.ListBlobs(region + "_" + champId + "_" + role, true);


            var toReturn = new List <T>();

            foreach (var blob in allBlobs)
            {
                var temp = (CloudBlockBlob)blob;
                toReturn.Add(JsonConvert.DeserializeObject <T>(temp.DownloadText()));
            }

            return(toReturn);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Writes a Jsonified Object to a Cache
        /// </summary>
        /// <param name="cache">Name of Cache to write to</param>
        /// <param name="region">Region of data</param>
        /// <param name="id">ID of data</param>
        /// <param name="json">JSON to write</param>
        /// <returns></returns>
        public static bool WriteToCache(string cache, string region, string id, string json)
        {
            try
            {
                var container = ApiTools.GetBlobContainer(cache);

                var blob = container.GetBlockBlobReference(region + "_" + id + ".json");

                blob.UploadText(json);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets an Itemset from the Azure Storage.
        /// Does not use CacheService due to custom naming schemes and performance optimizations.
        /// </summary>
        /// <param name="region">Region of data</param>
        /// <param name="champId">Id of champion</param>
        /// <param name="role">Role of champion</param>
        /// <returns></returns>
        public CloudBlockBlob GetItemsetBlob(string region, int champId, string role)
        {
            var container = ApiTools.GetBlobContainer("itemsets");

            var filename = "LWI_" + StaticDataService.GetChampion(region, champId).Name + "_" + role + ".json";

            var blob = container.GetBlockBlobReference(filename);

            if (!blob.Exists())
            {
                var itemSet = GetItemset(region, champId, role);
                var json    = itemSet.GenerateJson();

                blob.UploadText(json);
            }

            return(blob);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Scrapes the Id's of current featured Matches in a region. Used to keep statistics up to date.
        /// This method is called externally.
        /// </summary>
        /// <param name="region"></param>
        public static void ScrapeCurrentFeaturedGames(string region)
        {
            Logger.LogMessageToFile(MethodBase.GetCurrentMethod().DeclaringType.ToString(), "Scraping current featured games");
            var client  = ApiTools.ApiClient(region);
            var request =
                new RestRequest(
                    "/observer-mode/rest/featured",
                    Method.GET);

            request.AddApiKey();

            var response = client.Execute <FeaturedGames>(request);

            //Check to see if we are approaching rate limiting
            if (response.StatusCode == HttpStatusCode.ServiceUnavailable || response.StatusCode.ToString() == "429")
            {
                Logger.LogMessageToFile(MethodBase.GetCurrentMethod().DeclaringType.ToString(), "Too many calls, briefly pausing. Headers: "
                                        + String.Join(",", response.Headers));
                Thread.Sleep(Convert.ToInt32(ConfigurationManager.AppSettings["msBetweenApiCalls"]) * 2);
            }

            var container = ApiTools.GetBlobContainer("matches");
            var blob      = container.GetAppendBlobReference("matchIds.txt");

            if (!blob.Exists())
            {
                blob.CreateOrReplace();
            }

            foreach (var game in response.Data.GameList)
            {
                // Only scrape Ranked games on Summoner's Rift
                if ((game.GameQueueConfigId == 4 || game.GameQueueConfigId == 42) && game.MapId == 11)
                {
                    blob.AppendText(game.GameId.ToString() + "\n");
                }
            }

            Logger.LogMessageToFile(MethodBase.GetCurrentMethod().DeclaringType.ToString(), String.Format("Scrape complete, {0} games scraped", response.Data.GameList.Count));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Logs a message to log.txt in the logs Azure Container
        /// </summary>
        /// <param name="callingClass">String indicating what class is logging the message</param>
        /// <param name="msg">Message to log</param>
        public static void LogMessageToFile(string callingClass, string msg)
        {
            try
            {
                var logLine = System.String.Format(
                    "{0:G}: [{2}] - {1}.", System.DateTime.Now, msg,
                    callingClass.Replace("LeagueStatisticallyBestItemset.", ""));

                var container = ApiTools.GetBlobContainer("logs");

                var logBlob = container.GetAppendBlobReference("log.txt");

                if (!logBlob.Exists())
                {
                    logBlob.CreateOrReplace();
                }

                logBlob.AppendText(logLine + "\n");
            }
            catch
            {
                // ignored
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns an Object from the cache
        /// Overloaded method that allows custom Data names to be passed in
        /// </summary>
        /// <param name="cache">Name of Cache to load from</param>
        /// <param name="filename">Name of Data Blob</param>
        /// <returns></returns>
        public static T GetFromCache(string cache, string filename)
        {
            try
            {
                var container = ApiTools.GetBlobContainer(cache);

                var blob = container.GetBlockBlobReference(filename);

                if (!blob.Exists())
                {
                    return(default(T));
                }

                var json     = blob.DownloadText();
                var toReturn = JsonConvert.DeserializeObject <T>(json);

                return(toReturn);
            }
            catch (Exception e)
            {
                Logger.LogMessageToFile("CacheService [" + cache + "]", e.Message);
                return(default(T));
            }
        }