Esempio n. 1
0
        public async Task <allPinInfo> GetAll()
        {
            var client = new HttpClient
            {
                BaseAddress = new Uri(RestServiceUrl)
            };

            //// I want to add and accept a header for JSON
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            //// Retrieve all the groups with their items
            var response = await client.GetAsync("pins");

            //// Throw an exception if something went wrong
            response.EnsureSuccessStatusCode();

            //// In case you need date and time properties
            const string dateTimeFormat         = "yyyy-MM-ddTHH:mm:ss.fffffffZ";
            var          jsonSerializerSettings = new DataContractJsonSerializerSettings
            {
                DateTimeFormat = new DateTimeFormat(dateTimeFormat)
            };

            var jsonSerializer = new DataContractJsonSerializer(typeof(allPinInfo), jsonSerializerSettings);

            var stream = await response.Content.ReadAsStreamAsync();

            allPinInfo elem = (allPinInfo)jsonSerializer.ReadObject(stream);

            return(elem);
        }
Esempio n. 2
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected async override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState)
        {
            // TODO: Assign a bindable collection of items to this.DefaultViewModel["Items"]
            allPinInfo result = await GetAll();

            List <elemTab> list = (from s in result.body
                                   select new elemTab {
                Title = s.board, Subtitle = s.desc, Image = new BitmapImage(new Uri(s.src))
            }).ToList();

            itemsViewSource.Source = list;
        }