예제 #1
0
        public void GetCardImages(Game game)
        {
            LogManager.GetLogger().Log(game.Name, LogType.Game);

            var wc = new WebClient();

            foreach (var set in game.Sets)
            {
                if (set == null || !set.ImagesNeeded)
                {
                    continue;
                }

                LogManager.GetLogger().Log(set.Name, LogType.Set);

                foreach (var card in set.Cards)
                {
                    try
                    {
                        byte[] image = _cache.GetImage(card.Id);

                        if (image == null)
                        {
                            image = wc.DownloadData(ApiBaseUrl + "/" + Uri.EscapeUriString(set.Name) + "/" + card.Id + ".png");
                            _cache.SaveImage(card.Id, ".png", image);
                        }

                        _imageWriter.WriteImage(OctgnPaths.CardImagePath(game.Id, set.Id, card.Id, ".png"), image);
                    }
                    catch (WebException ex)
                    {
                        LogManager.GetLogger().Log("Unable to find: " + card.Name, LogType.Card);

                        if (((HttpWebResponse)ex.Response).StatusCode != HttpStatusCode.NotFound)
                        {
                            throw;
                        }
                    }
                }
            }
        }
예제 #2
0
        public void GetCardImages(Game game)
        {
            LogManager.GetLogger().Log(game.Name, LogType.Game);

            var wc = new WebClient();

            dynamic apiSets = Json.Decode(wc.DownloadString(ApiBaseUrl + "/api/public/packs/"));

            foreach (var apiSet in apiSets)
            {
                string setName = apiSet.name;

                //I needed to match the sets using a custom method since there were no identifying marks except for the actual name.
                var set = game.Sets.SingleOrDefault(s => StringExtensions.CustomContains(s.Name, setName));

                if (set == null || !set.ImagesNeeded)
                {
                    if (set == null)
                    {
                        LogManager.GetLogger().Log("Unable to map set: " + setName + ".  It may not be on OCTGN yet.", LogType.Error);
                    }

                    continue;
                }

                LogManager.GetLogger().Log(set.Name + ": " + apiSet.name, LogType.Set);

                dynamic apiCards = Json.Decode(wc.DownloadString(ApiBaseUrl + "/api/public/cards/" + apiSet.code));

                foreach (var apiCard in apiCards)
                {
                    var card = set.Cards.FirstOrDefault(c => c.Id.Equals(apiCard.octgnid));

                    if (card != null && apiCard.imagesrc != string.Empty)
                    {
                        try
                        {
                            byte[] image = _cache.GetImage(card.Id);

                            if (image == null)
                            {
                                image = wc.DownloadData(ApiBaseUrl + apiCard.imagesrc);
                                _cache.SaveImage(card.Id, ".jpg", image);
                            }

                            _imageWriter.WriteImage(OctgnPaths.CardImagePath(game.Id, set.Id, card.Id, ".jpg"), image);
                        }
                        catch (WebException ex)
                        {
                            LogManager.GetLogger().Log("Unable to find: " + card.Name, LogType.Card);

                            if (((HttpWebResponse)ex.Response).StatusCode != HttpStatusCode.NotFound)
                            {
                                throw;
                            }
                        }
                    }
                    else
                    {
                        LogManager.GetLogger().Log("Unable to find: " + apiCard.title, LogType.Card);
                    }
                }
            }
        }
예제 #3
0
        public void GetCardImages(Game game)
        {
            LogManager.GetLogger().Log(game.Name, LogType.Game);

            var wc = new WebClient();

            dynamic apiSets = Json.Decode(wc.DownloadString(ApiBaseUrl + "/api/public/packs/"));

            foreach (var apiSet in apiSets)
            {
                // The maintainers of Got2 appear to be colapsing all cycle packs into a single set, so we have
                // to grab the set by the cycle number.
                string setName = apiSet.name;
                int    cycle   = apiSet.cycle_position;
                var    set     = game.Sets.SingleOrDefault(s => s.Name.StartsWith(cycle.ToString().PadLeft(2, '0')));

                if (set == null || !set.ImagesNeeded)
                {
                    if (set == null)
                    {
                        LogManager.GetLogger().Log("Unable to map set: " + setName + ".  It may not be on OCTGN yet.", LogType.Error);
                    }

                    continue;
                }

                LogManager.GetLogger().Log(set.Name + ": " + apiSet.name, LogType.Set);

                dynamic apiCards = Json.Decode(wc.DownloadString(ApiBaseUrl + "/api/public/cards/" + apiSet.code));

                foreach (var apiCard in apiCards)
                {
                    var card = set.Cards.FirstOrDefault(c => c.Id.Equals(apiCard.octgn_id));

                    if (card != null && apiCard.imagesrc != string.Empty)
                    {
                        try
                        {
                            byte[] image = _cache.GetImage(card.Id);

                            if (image == null)
                            {
                                image = wc.DownloadData(ApiBaseUrl + apiCard.imagesrc);
                                _cache.SaveImage(card.Id, ".jpg", image);
                            }

                            _imageWriter.WriteImage(OctgnPaths.CardImagePath(game.Id, set.Id, card.Id, ".jpg"), image);
                        }
                        catch (WebException ex)
                        {
                            LogManager.GetLogger().Log("Unable to find: " + card.Name, LogType.Card);

                            if (((HttpWebResponse)ex.Response).StatusCode != HttpStatusCode.NotFound)
                            {
                                throw;
                            }
                        }
                    }
                    else
                    {
                        LogManager.GetLogger().Log("Unable to find: " + apiCard.title, LogType.Card);
                    }
                }
            }
        }
예제 #4
0
        public void GetCardImages(Game game)
        {
            LogManager.GetLogger().Log(game.Name, LogType.Game);

            var wc = new WebClient();

            dynamic apiSets = Json.Decode(wc.DownloadString(ApiBaseUrl + "/api/sets/"));

            foreach (var apiSet in apiSets)
            {
                string setName = apiSet.name;
                var    set     = game.Sets.FindSetByName(setName);

                if (set == null || !set.ImagesNeeded)
                {
                    if (set == null)
                    {
                        LogManager.GetLogger().Log("Unable to map set: " + setName + ".  It may not be on OCTGN yet.", LogType.Error);
                    }

                    continue;
                }

                LogManager.GetLogger().Log(set.Name, LogType.Set);

                dynamic apiCards = Json.Decode(wc.DownloadString(ApiBaseUrl + "/api/set/" + apiSet.code));

                foreach (var apiCard in apiCards)
                {
                    // Certain card names can found acrosss multiple sets.  DTDB labels them with (Ext.#).  Need to strip that out for OCTGN lookup.
                    string apiTile = Regex.Replace(apiCard.title.ToString(), @"\(Exp.[\s]*[\d]*\)", "", RegexOptions.IgnoreCase).Trim();

                    var card =
                        // Standard
                        set.Cards.FirstOrDefault(
                            c => c.Name.Equals(apiTile, StringComparison.OrdinalIgnoreCase)) ??
                        // Try appending a missing the
                        set.Cards.FirstOrDefault(
                            c => String.Concat("The ", c.Name).Equals(apiTile, StringComparison.OrdinalIgnoreCase)) ??
                        // Fun with ampersand
                        set.Cards.FirstOrDefault(
                            c => c.Name.Replace("&", " & ").Equals(apiTile, StringComparison.OrdinalIgnoreCase)) ??
                        // There is some inconsitent nameing with é between the definition files and dtdb.  Try both ways if necessary
                        set.Cards.FirstOrDefault(
                            c => c.Name.Trim().Equals(apiTile.Replace("\u00e9", "e"), StringComparison.OrdinalIgnoreCase));

                    if (card != null && apiCard.imagesrc != string.Empty)
                    {
                        try
                        {
                            byte[] image = _cache.GetImage(card.Id);

                            if (image == null)
                            {
                                image = wc.DownloadData(ApiBaseUrl + apiCard.imagesrc);
                                _cache.SaveImage(card.Id, ".jpg", image);
                            }

                            _imageWriter.WriteImage(OctgnPaths.CardImagePath(game.Id, set.Id, card.Id, ".jpg"), image);
                        }
                        catch (WebException ex)
                        {
                            LogManager.GetLogger().Log("Unable to find: " + card.Name, LogType.Card);

                            if (((HttpWebResponse)ex.Response).StatusCode != HttpStatusCode.NotFound)
                            {
                                throw;
                            }
                        }
                    }
                    else
                    {
                        LogManager.GetLogger().Log("Unable to find: " + apiCard.title, LogType.Card);
                    }
                }
            }
        }