public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
        JArray array = JArray.Load(reader);

        RootObj result = new RootObj();

        result.category = array[0].ToObject <Category>();
        array.RemoveAt(0);
        result.details = array.ToObject <List <Detail> >();
        return(result);
    }
        public void GraphSettings()
        {
            var   visualizer = new ObjectGraphVisualizer();
            IData data;

            var root = new RootObj();

            var dot = visualizer.Visualize(root, out data);


            Assert.That(dot, Does.Contain("graph [splines=ortho]"));
            Assert.That(dot, Does.Contain("node [shape=box style=rounded]"));
        }
Exemplo n.º 3
0
        public static async Task <Response> GetSteamApps()
        {
            HttpClient _client = new HttpClient
            {
                BaseAddress = new Uri("https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/?key=EA2DE8B677990527C7B93F095BF2A8C1&steamid=76561198022727943&include_appinfo=1")
            };

            _client.DefaultRequestHeaders.Accept.Clear();
            _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            string response = await _client.GetStringAsync(_client.BaseAddress);

            RootObj obj = JsonConvert.DeserializeObject <RootObj>(response);

            return(obj.response);
        }
        public void InspectObjDelegate()
        {
            var visualizer = new ObjectGraphVisualizer(
                o => { return(o.Object.GetType().Equals(typeof(RootObj))); });
            IData data;

            var root = new RootObj();

            var dot = visualizer.Visualize(root, out data);

            Assert.That(dot, Does.Contain(
                            "1 [ label=\"YetiCommon.Tests.Util.RootObj\" id=\"dark googlegreen\" ];"));
            Assert.That(dot, Does.Contain(
                            "2 [ label=\"YetiCommon.Tests.Util.InteriorObj\" id=\"googlered\" ];"));
            Assert.That(dot, Does.Not.Contain("YetiCommon.Tests.Util.LeafObj"));

            Assert.That(dot, Does.Contain("1 -> 2 [ label=\"interiorObj\" ];"));
            Assert.That(dot, Does.Not.Contain("2 -> 3"));

            Assert.That(data.RootObject, Is.EqualTo(root));
            Assert.That(data.InternalNodes, Is.EquivalentTo(new object[] { root }));
            Assert.That(data.TruncatedNodes, Is.EquivalentTo(new object[] { root.interiorObj }));
            Assert.That(data.LeafNodes, Is.Empty);
        }
        public void VisualizeSimpleGraph()
        {
            var   visualizer = new ObjectGraphVisualizer();
            IData data;

            var root = new RootObj();

            var dot = visualizer.Visualize(root, out data);

            Assert.That(dot, Does.Contain(
                            "1 [ label=\"YetiCommon.Tests.Util.RootObj\" id=\"dark googlegreen\" ];"));
            Assert.That(dot, Does.Contain("2 [ label=\"YetiCommon.Tests.Util.InteriorObj\" ];"));
            Assert.That(dot, Does.Contain(
                            "3 [ label=\"YetiCommon.Tests.Util.LeafObj\" id=\"dark googlered\" ];"));

            Assert.That(dot, Does.Contain("1 -> 2 [ label=\"interiorObj\" ];"));
            Assert.That(dot, Does.Contain("2 -> 3 [ label=\"leafObj\" ];"));

            Assert.That(data.RootObject, Is.EqualTo(root));
            Assert.That(data.InternalNodes,
                        Is.EquivalentTo(new object[] { root, root.interiorObj }));
            Assert.That(data.TruncatedNodes, Is.Empty);
            Assert.That(data.LeafNodes, Is.EquivalentTo(new object[] { root.interiorObj.leafObj }));
        }
Exemplo n.º 6
0
        public async Task PullDataAsync(int page = 1, int pageSize = 25, bool withTuin = false)
        {
            try
            {
                string url;

                if (withTuin)
                {
                    url = "http://partnerapi.funda.nl/feeds/Aanbod.svc/json/ac1b0b1572524640a0ecc54de453ea9f/?type=koop&zo=/amsterdam/tuin/";
                }
                else
                {
                    url = "http://partnerapi.funda.nl/feeds/Aanbod.svc/json/ac1b0b1572524640a0ecc54de453ea9f/?type=koop&zo=/amsterdam/";
                }
                // hardcoding here for easier reading, but a config file would be more appropriate to store the base url
                var response = await _httpClient.GetAsync(url + "&page=" + page + "&pagesize=" + pageSize);

                if (response.IsSuccessStatusCode)
                {
                    string responseString = await response.Content.ReadAsStringAsync();

                    // parse the root object
                    RootObj responseObject = JsonConvert.DeserializeObject <RootObj>(responseString);
                    // store all the object makelaar
                    makelaarList.AddRange(responseObject.Objects);

                    // check if there are any more pages to fetch
                    if (responseObject.Paging.AantalPaginas >= page)
                    {
                        page++;
                        // there are more pages to fetch!
                        await PullDataAsync(page : page, withTuin : withTuin);
                    }
                    else
                    {
                        // no more data to fetch, we can calculate which makelaar have most occurrence
                        List <MakelaarObj> returnMakelaarList = new List <MakelaarObj>();

                        // annoyingly since we lose the reference to the object after the groupBy I cannot return directly the result but i need to parse it
                        List <MakelaarOccurrence> makelaarsIds = makelaarList.GroupBy(i => i.MakelaarId).OrderByDescending(grp => grp.Count()).Select(y => new MakelaarOccurrence {
                            Makelaar = y.Key, Counter = y.Count()
                        }).Take(10).ToList();
                        foreach (MakelaarOccurrence item in makelaarsIds)
                        {
                            // populate the final object and add it to the return list
                            MakelaarObj makelaarData = new MakelaarObj()
                            {
                                Makelaar    = makelaarList.First(i => i.MakelaarId == item.Makelaar),
                                ListedSales = item.Counter
                            };

                            returnMakelaarList.Add(makelaarData);
                        }

                        if (withTuin)
                        {
                            _cache.MakelaarWithMostListedSalesWithTuin = returnMakelaarList;
                        }
                        else
                        {
                            _cache.MakelaarWithMostListedSales = returnMakelaarList;
                        }

                        // clear the makelaar list cache and update the internal cache time
                        makelaarList.Clear();
                        _cache.UpdatedAt = DateTime.UtcNow;
                    }
                }
                else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                {
                    // we hitted the request limit
                    // wait for some seconds before retrying to query the data
                    await Task.Delay(10 * 1000);

                    // add page and page size
                    await PullDataAsync(page : page, withTuin : withTuin);
                }
                else
                {
                    throw new Exception(response.StatusCode.ToString());
                }
            } catch (Exception exc)
            {
                throw exc;
            }
        }