Esempio n. 1
0
        public static Rom GetGameByName(string platformId, string name, out string access)
        {
            access = "";
            try
            {
                string key  = Functions.LoadAPIKEY();
                string json = string.Empty;
                var    url  = Values.BaseAPIURL + "/v1.1/Games/ByGameName?apikey=" + key + "&name=" + name + "&platform=" + platformId;

                using (WebClient client = new WebClient())
                {
                    client.Encoding = System.Text.Encoding.UTF8;
                    json            = client.DownloadString(new Uri(url));
                }

                if (string.IsNullOrEmpty(json))
                {
                    return(null);
                }

                access = json.Substring(json.IndexOf("remaining_monthly_allowance") + "remaining_monthly_allowance:".Length + 1, 5).Replace(":", "").Replace(",", "").Trim();
                var part = json.Substring(json.IndexOf("games\":") + 7);
                part = part.Substring(0, part.IndexOf("]},\"pages") + 1);
                var list = JsonConvert.DeserializeObject <List <API_Game> >(part);

                List <Rom> games = new List <Rom>();

                foreach (var game in list)
                {
                    if (game.platform.ToString() != platformId)
                    {
                        continue;
                    }
                    games.Add(new Rom()
                    {
                        Id           = game.id.ToString(),
                        DBName       = game.game_title,
                        YearReleased = RomFunctions.GetYear(game.release_date)
                    });

                    return(games[0]);
                }
            }
            catch (APIException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (Exception ex)
            {
                return(null);
            }

            return(null);
        }
Esempio n. 2
0
        public static List <Rom> GetGamesListByPlatform(string platformId, string json, string platformName)
        {
            try
            {
                if (string.IsNullOrEmpty(json))
                {
                    json = GetGamesListJSONByPlatform(platformId, platformName);
                }

                if (json == null)
                {
                    throw new APIException("Cound not get json");
                }

                var        jobject = (JArray)JsonConvert.DeserializeObject(json);
                List <Rom> games   = new List <Rom>();

                foreach (var game in jobject)
                {
                    var objGame = (JObject)game;
                    games.Add(new Rom()
                    {
                        Id           = objGame.SelectToken("id").ToString(),
                        DBName       = objGame.SelectToken("game_title").ToString(),
                        YearReleased = RomFunctions.GetYear(objGame.SelectToken("release_date").ToString())
                    });
                }

                return(games.OrderBy(x => x.Name).ToList());
            }
            catch (APIException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Esempio n. 3
0
        public static Rom GetGameDetails(string gameId, Platform platform, out string access)
        {
            access = "";
            try
            {
                var publishers = GetPublishers();
                var developers = GetDevelopers();

                string key  = Functions.LoadAPIKEY();
                string json = string.Empty;
                var    url  = Values.BaseAPIURL + "/v1/Games/ByGameID?apikey=" + key + "&id=" + gameId;

                using (WebClient client = new WebClient())
                {
                    client.Encoding = System.Text.Encoding.UTF8;
                    try
                    {
                        json = client.DownloadString(new Uri(url));

                        if (string.IsNullOrEmpty(json))
                        {
                            throw new Exception();
                        }
                    }
                    catch
                    {
                        if (platform != null)
                        {
                            var pjson = RomFunctions.GetPlatformJson(platform.Name);
                            var list  = GetGamesListByPlatform(platform.Id, pjson, platform.Name);

                            return(list.FirstOrDefault(x => x.Id == gameId));
                        }
                    }
                }

                if (string.IsNullOrEmpty(json))
                {
                    return(null);
                }

                var result = new Rom();
                access = json.Substring(json.IndexOf("remaining_monthly_allowance") + "remaining_monthly_allowance:".Length + 1, 5).Replace(":", "").Replace(",", "").Trim();
                var jobject = (JObject)JsonConvert.DeserializeObject(json);
                var jgame   = jobject.SelectToken("data.games").First();
                result.Id           = gameId;
                result.DBName       = jgame.SelectToken("game_title").ToString();
                result.YearReleased = RomFunctions.GetYear(jgame.SelectToken("release_date").ToString());
                //result.Description = jobject.SelectToken("data.games").First().SelectToken("description").ToString();

                result.Platform = new Platform();

                try
                {
                    var jplatform = jgame.SelectToken("platform");

                    if (jplatform != null)
                    {
                        result.Platform.Id = jplatform.ToString();
                        var list = Functions.GetPlatformsXML();
                        result.Platform.Name = list[result.Platform.Id];
                    }
                }
                catch
                {
                }

                try
                {
                    var jpublisher = jgame.SelectToken("publisher");

                    if (jpublisher != null)
                    {
                        result.Publisher = publishers[Convert.ToInt32(jpublisher.ToString())];
                    }
                }
                catch
                {
                }

                try
                {
                    var jdevelopers = jgame.SelectToken("developers");

                    if (jdevelopers != null)
                    {
                        result.Developer = developers[Convert.ToInt32(jdevelopers.First().ToString())];
                    }
                }
                catch
                {
                }

                return(result);
            }
            catch (APIException ex)
            {
                throw new Exception(ex.Message);
            }
            catch (Exception ex)
            {
                return(null);
            }

            return(null);
        }