Esempio n. 1
0
        public MainWindow()
        {
            this.InitializeComponent();
            if (game == null)
            {
                game = DbContext.Get().GameById(Guid.Parse("A6C8D2E8-7CD8-11DD-8F94-E62B56D89593")) ?? throw new Exception("MTG is not installed!");
            }

            JArray octgnSetData;
            JArray scryfallSetData;

            using (var webclient = new WebClient()
            {
                Encoding = Encoding.UTF8
            })
            {
                octgnSetData    = (JArray)JsonConvert.DeserializeObject(webclient.DownloadString("http://www.octgngames.com/forum/json.php"));
                scryfallSetData = (JsonConvert.DeserializeObject(webclient.DownloadString("https://api.scryfall.com/sets")) as JObject)["data"] as JArray;
            }

            sets = new List <SetInfo>();

            foreach (var set in game.Sets().OrderBy(x => x.Name))
            {
                if (!set.Hidden && set.Cards.Count() > 0)
                {
                    var setInfo = new SetInfo();
                    setInfo.Set = set;
                    var jsonset = octgnSetData.FirstOrDefault(x => x.Value <string>("guid") == set.Id.ToString());
                    if (jsonset == null)
                    {
                        continue;
                    }
                    setInfo.Code = jsonset.Value <string>("octgn_code");

                    var scryfallset = scryfallSetData.FirstOrDefault(x => x.Value <string>("code") == setInfo.Code.ToLower());
                    if (scryfallset == null)
                    {
                        continue;
                    }
                    setInfo.SearchUri = scryfallset.Value <string>("search_uri");
                    var scryfalltokens = scryfallSetData.FirstOrDefault(x => x.Value <string>("parent_set_code") == setInfo.Code.ToLower() && x.Value <string>("set_type") == "token");
                    if (scryfalltokens != null)
                    {
                        setInfo.TokenUri = scryfalltokens.Value <string>("search_uri");
                    }


                    sets.Add(setInfo);
                }
            }

            SetList.ItemsSource = sets;


            this.Closing += CancelWorkers;
            backgroundWorker.WorkerReportsProgress      = true;
            backgroundWorker.WorkerSupportsCancellation = true;
            backgroundWorker.ProgressChanged           += ProgressChanged;
            backgroundWorker.RunWorkerCompleted        += BackgroundWorker_RunWorkerCompleted;
        }
Esempio n. 2
0
        public MainWindow()
        {
            this.InitializeComponent();
            this.DataContext = this;
            if (game == null)
            {
                game = DbContext.Get().GameById(Guid.Parse("A6C8D2E8-7CD8-11DD-8F94-E62B56D89593")) ?? throw new Exception("MTG is not installed!");
            }

            JArray scryfallSetData;
            JArray OctgnSetData;

            using (var webclient = new WebClient()
            {
                Encoding = Encoding.UTF8
            })
            {
                OctgnSetData    = (JArray)JsonConvert.DeserializeObject(webclient.DownloadString("http://www.octgngames.com/forum/json.php"));
                scryfallSetData = (JsonConvert.DeserializeObject(webclient.DownloadString("https://api.scryfall.com/sets")) as JObject)["data"] as JArray;
            }

            sets = new List <SetInfo>();

            foreach (var jsonset in scryfallSetData)
            {
                var setInfo = new SetInfo();

                setInfo.Code       = jsonset.Value <string>("code");
                setInfo.ParentCode = jsonset.Value <string>("parent_set_code");
                setInfo.BlockCode  = jsonset.Value <string>("block_code");

                setInfo.Type      = jsonset.Value <string>("set_type");
                setInfo.SearchUri = jsonset.Value <string>("search_uri");

                sets.Add(setInfo);
            }

            setList             = new List <SetItem>();
            SetList.ItemsSource = setList;

            foreach (var set in game.Sets())
            {
                if (!set.Hidden && set.Cards.Count() > 0)
                {
                    if (set.Id.ToString() == "a584b75b-266f-4378-bed5-9ffa96cd3961")
                    {
                        var setItem = new SetItem();
                        setItem.set = set;

                        setItem.releaseDate = new DateTime(3000, 1, 1);
                        setItem.extraSets   = new List <SetInfo>();
                        CountImageFiles(setItem);
                        setList.Add(setItem);
                    }
                    else
                    {
                        var octgndbset = OctgnSetData.FirstOrDefault(x => x.Value <string>("guid") == set.Id.ToString());
                        if (octgndbset == null)
                        {
                            continue;
                        }

                        var setItem = new SetItem();
                        setItem.set = set;

                        var setCode = octgndbset.Value <string>("octgn_code").ToLower();

                        setItem.setData = sets.First(x => x.Code == setCode);

                        setItem.extraSets = new List <SetInfo>();

                        setItem.extraSets.AddRange(sets.Where(x => x.ParentCode == setItem.setData.Code));
                        if (setItem.setData.BlockCode != setItem.setData.Code)
                        {
                            setItem.extraSets.AddRange(sets.Where(x => x.ParentCode == setItem.setData.BlockCode));
                        }

                        setItem.releaseDate = Convert.ToDateTime(octgndbset.Value <string>("date"));
                        CountImageFiles(setItem);
                        setList.Add(setItem);
                    }
                }
            }

            this.Closing += CancelWorkers;
        }