Пример #1
0
        public bool Load()
        {
            if (File.Exists(dataPath))
            {
                JsonSerializer serializer = new JsonSerializer();

                using (StreamReader sr = new StreamReader(dataPath))
                {
                    using (JsonReader reader = new JsonTextReader(sr))
                    {
                        try
                        {
                            vm.LootBoxes = serializer.Deserialize <List <LootBoxUSB> >(reader)
                                           .Select(x => new LootBoxVM(LootBoxFactory.RestoreLootBox(x)));
                        }
                        catch { return(false); }
                    }
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        private void LoadBoxes(string name)
        {
            RequestHandler.GetInstance().AddAction(RequestHandler.Priority.High, async() =>
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest
                                         .Create(RequestBuilder.SearchRequest(name));

                HttpWebResponse response = await RequestsUtil.GetResponseAsync(request);

                if (response == null)
                {
                    return(false);
                }

                Stream stream             = response.GetResponseStream();
                StreamReader streamReader = new StreamReader(stream);

                string content = streamReader.ReadToEnd();

                response.Close();

                JSONObject json = JSONParser.Parse(content);

                if (json.GetValue("success").ToString() == "false" ||
                    json.GetValue("total_count").ToString() == "0")
                {
                    return(false);
                }

                var results = json.GetArray("results");

                for (int i = 0; i < results.Count; i++)
                {
                    var hashName = results[i]["asset_description"].GetValue("market_hash_name").ToString();

                    // skip keys
                    if (hashName.Contains("Key"))
                    {
                        continue;
                    }

                    var iconUrl = results[i]["asset_description"].GetValue("icon_url").ToString();

                    var lootBox = LootBoxFactory.GetLootBox(hashName);

                    lootBox.GetIcon(iconUrl, hashName);

                    vm.AddLootBox(lootBox);
                }

                return(true);
            }, false);
        }