Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Collections;
- using System.Threading.Tasks;
- using System.IO;
- using Sandwich.Services.Parser;
- using Newtonsoft.Json.Linq;
- using Newtonsoft.Json.Serialization;
- using System.Net.Http;
- using Newtonsoft.Json;
- using System.Diagnostics;
- using Windows.Data.Json;
- namespace Sandwich.Services.DataProvider
- {
- public class ProvideData
- {
- public HttpClient Request { get; set; }
- public ProvideData()
- {
- // TODO: Complete member initialization
- Request = new HttpClient();
- }
- public async Task<IList<Foods>> getlstDrinksAsync()
- {
- // Next set up our request URL, headers Content Type.
- /* Request = System.Net.HttpWebRequest.CreateHttp(new Uri("https://api.parse.com/1/Drinks"));
- Request.Headers["X-Parse-Application-Id"] = "EBJy7sR5IbWEYU3aLndx2ps10LL8ycT4RuGx87XK";
- Request.Headers["X-Parse-Windows-Key"] = "gPe29yqyMN5pFbi5vK2HgGhyRBIA0VbYuI4dShCC";
- Request.Method = "GET";
- Request.ContentType = "application/json";*/
- // Fetch a response from the server. This will give us back error codes or a successful code
- var response = await Request.GetStringAsync(new Uri("https://EBJy7sR5IbWEYU3aLndx2ps10LL8ycT4RuGx87XK:REST-API-key=hQtoDMxepJJmQ12RvQ84e4N2agQNbyPTetyj1afW@api.parse.com/1/classes/Drinks"));
- // string resultJson = string.Empty;
- // Convert Read the Json response in to a string
- /* using (var streamReader = new StreamReader(response.GetResponseStream()))
- {
- resultJson = streamReader.ReadToEnd();
- }*/
- var rawdrink = JObject.Parse(response);
- // get JSON result objects into a list
- IList<JToken> results = (List<JToken>)rawdrink.SelectTokens("results").Children();
- /* ["results"].Children().ToList();*/
- // serialize JSON results into .NET objects
- IList<Foods> lstDrinks = new List<Foods>();
- foreach (JToken result in results)
- {
- Foods searchResult = JsonConvert.DeserializeObject<Foods>(result.ToString());
- lstDrinks.Add(searchResult);
- }
- Request.Dispose(); //free the ressource
- return lstDrinks;
- }
- }
- using GalaSoft.MvvmLight;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using Sandwich.Services.DataProvider;
- using Sandwich.Services.Parser;
- using Sandwich.ViewModel;
- using System.Threading.Tasks;
- using System;
- namespace Sandwich.ViewModel
- {
- /// <summary>
- /// This class contains properties that the main View can data bind to.
- /// <para>
- /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
- /// </para>
- /// <para>
- /// You can also use Blend to data bind with the tool's support.
- /// </para>
- /// <para>
- /// See http://www.galasoft.ch/mvvm
- /// </para>
- /// </summary>
- public class MainViewModel : ViewModelBase, INotifyPropertyChanged
- {
- private ObservableCollection<Foods> _drinks = null;
- public ObservableCollection<Foods> Drinks { get { return _drinks; } set { _drinks = value; RaisePropertyChanged("Drinks"); } }
- /// <summary>
- /// Initializes a new instance of the MainViewModel class.
- /// </summary>
- public MainViewModel()
- {
- if (IsInDesignMode)
- {
- //// // Code runs in Blend --> create design time data.
- }
- else
- {
- //// // Code runs "for real"
- InitialiseAsync();
- }
- }
- public async Task InitialiseAsync()
- {
- var service = new ProvideData();
- var lstDrinks = await service.getlstDrinksAsync();
- Drinks = new ObservableCollection<Foods>(lstDrinks);
- }
- }
- 'Sandwich.WindowsPhone.exe' (CoreCLR: DefaultDomain): Loaded 'C:windows
- system32mscorlib.ni.dll'. Skipped loading symbols. Module is optimized
- and the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:DataSharedData
- PhoneToolsAppxLayouts5534067a-689a-4cf7-
- a832-0f14fb3a6014VS.Debug_AnyCPU.raoulSandwich.WindowsPhone.exe'. Symbols
- loaded.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- SYSTEM.RUNTIME.NI.DLL'. Skipped loading symbols. Module is optimized and
- the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- WinMetadataWindows.winmd'. Skipped loading symbols. Module is optimized
- and the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- SYSTEM.RUNTIME.INTEROPSERVICES.WINDOWSRUNTIME.NI.DLL'. Skipped loading
- symbols. Module is optimized and the debugger option 'Just My Code' is
- enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- SYSTEM.COLLECTIONS.NI.DLL'. Skipped loading symbols. Module is optimized
- and the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:DataSharedData
- PhoneToolsAppxLayouts5534067a-689a-4cf7-
- a832-0f14fb3a6014VS.Debug_AnyCPU.raoulGalaSoft.MvvmLight.DLL'. Cannot
- find or open the PDB file.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- SYSTEM.OBJECTMODEL.NI.DLL'. Skipped loading symbols. Module is optimized
- and the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- SYSTEM.NI.DLL'. Skipped loading symbols. Module is optimized and the
- debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:DataSharedData
- PhoneToolsAppxLayouts5534067a-689a-4cf7-
- a832-0f14fb3a6014VS.Debug_AnyCPU.raoul
- Microsoft.Practices.ServiceLocation.DLL'. Cannot find or open the PDB
- file.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:DataSharedData
- PhoneToolsAppxLayouts5534067a-689a-4cf7-
- a832-0f14fb3a6014VS.Debug_AnyCPU.raoulGalaSoft.MvvmLight.Extras.DLL'.
- Cannot find or open the PDB file.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- SYSTEM.COMPONENTMODEL.NI.DLL'. Skipped loading symbols. Module is
- optimized and the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- SYSTEM.REFLECTION.NI.DLL'. Skipped loading symbols. Module is optimized
- and the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- SYSTEM.THREADING.NI.DLL'. Skipped loading symbols. Module is optimized
- and the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- SYSTEM.GLOBALIZATION.NI.DLL'. Skipped loading symbols. Module is
- optimized and the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- SYSTEM.LINQ.NI.DLL'. Skipped loading symbols. Module is optimized and
- the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- SYSTEM.CORE.NI.DLL'. Skipped loading symbols. Module is optimized and
- the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- SYSTEM.DIAGNOSTICS.DEBUG.NI.DLL'. Skipped loading symbols. Module is
- optimized and the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- SYSTEM.THREADING.TASKS.NI.DLL'. Skipped loading symbols. Module is
- optimized and the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- System.Net.Http.ni.DLL'. Skipped loading symbols. Module is optimized
- and the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- System.Net.Http.Phone.ni.DLL'. Skipped loading symbols. Module is
- optimized and the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- System.Net.ni.DLL'. Skipped loading symbols. Module is optimized and the
- debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:DataSharedData
- PhoneToolsAppxLayouts5534067a-689a-4cf7-
- a832-0f14fb3a6014VS.Debug_AnyCPU.raoulNewtonsoft.Json.DLL'. Cannot find
- or open the PDB file.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
- System.Runtime.WindowsRuntime.NI.DLL'. Skipped loading symbols. Module
- is optimized and the debugger option 'Just My Code' is enabled.
- 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32en-US
- mscorlib.debug.resources.dll'. Module was built without symbols.
- A first chance exception of type 'System.Exception' occurred in
- mscorlib.ni.dll
- A first chance exception of type 'System.Exception' occurred in
- mscorlib.ni.dll
- The thread 0xb0c has exited with code 259 (0x103).
- The thread 0xb04 has exited with code 259 (0x103).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement