Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Collections;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using Sandwich.Services.Parser;
  8. using Newtonsoft.Json.Linq;
  9. using Newtonsoft.Json.Serialization;
  10. using System.Net.Http;
  11. using Newtonsoft.Json;
  12. using System.Diagnostics;
  13. using Windows.Data.Json;
  14.  
  15.  
  16. namespace Sandwich.Services.DataProvider
  17. {
  18. public class ProvideData
  19. {
  20. public HttpClient Request { get; set; }
  21.  
  22. public ProvideData()
  23. {
  24. // TODO: Complete member initialization
  25. Request = new HttpClient();
  26. }
  27.  
  28.  
  29.  
  30. public async Task<IList<Foods>> getlstDrinksAsync()
  31. {
  32.  
  33. // Next set up our request URL, headers Content Type.
  34. /* Request = System.Net.HttpWebRequest.CreateHttp(new Uri("https://api.parse.com/1/Drinks"));
  35. Request.Headers["X-Parse-Application-Id"] = "EBJy7sR5IbWEYU3aLndx2ps10LL8ycT4RuGx87XK";
  36. Request.Headers["X-Parse-Windows-Key"] = "gPe29yqyMN5pFbi5vK2HgGhyRBIA0VbYuI4dShCC";
  37. Request.Method = "GET";
  38. Request.ContentType = "application/json";*/
  39.  
  40.  
  41.  
  42. // Fetch a response from the server. This will give us back error codes or a successful code
  43. var response = await Request.GetStringAsync(new Uri("https://EBJy7sR5IbWEYU3aLndx2ps10LL8ycT4RuGx87XK:REST-API-key=hQtoDMxepJJmQ12RvQ84e4N2agQNbyPTetyj1afW@api.parse.com/1/classes/Drinks"));
  44. // string resultJson = string.Empty;
  45.  
  46. // Convert Read the Json response in to a string
  47. /* using (var streamReader = new StreamReader(response.GetResponseStream()))
  48. {
  49. resultJson = streamReader.ReadToEnd();
  50. }*/
  51.  
  52. var rawdrink = JObject.Parse(response);
  53.  
  54. // get JSON result objects into a list
  55. IList<JToken> results = (List<JToken>)rawdrink.SelectTokens("results").Children();
  56.  
  57.  
  58.  
  59. /* ["results"].Children().ToList();*/
  60.  
  61. // serialize JSON results into .NET objects
  62. IList<Foods> lstDrinks = new List<Foods>();
  63. foreach (JToken result in results)
  64. {
  65. Foods searchResult = JsonConvert.DeserializeObject<Foods>(result.ToString());
  66. lstDrinks.Add(searchResult);
  67. }
  68.  
  69. Request.Dispose(); //free the ressource
  70.  
  71. return lstDrinks;
  72.  
  73.  
  74. }
  75.  
  76. }
  77.  
  78. using GalaSoft.MvvmLight;
  79. using System.Collections.ObjectModel;
  80. using System.ComponentModel;
  81. using Sandwich.Services.DataProvider;
  82. using Sandwich.Services.Parser;
  83. using Sandwich.ViewModel;
  84. using System.Threading.Tasks;
  85. using System;
  86.  
  87. namespace Sandwich.ViewModel
  88. {
  89. /// <summary>
  90. /// This class contains properties that the main View can data bind to.
  91. /// <para>
  92. /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
  93. /// </para>
  94. /// <para>
  95. /// You can also use Blend to data bind with the tool's support.
  96. /// </para>
  97. /// <para>
  98. /// See http://www.galasoft.ch/mvvm
  99. /// </para>
  100. /// </summary>
  101. public class MainViewModel : ViewModelBase, INotifyPropertyChanged
  102. {
  103. private ObservableCollection<Foods> _drinks = null;
  104. public ObservableCollection<Foods> Drinks { get { return _drinks; } set { _drinks = value; RaisePropertyChanged("Drinks"); } }
  105.  
  106. /// <summary>
  107. /// Initializes a new instance of the MainViewModel class.
  108. /// </summary>
  109. public MainViewModel()
  110. {
  111.  
  112. if (IsInDesignMode)
  113. {
  114. //// // Code runs in Blend --> create design time data.
  115. }
  116. else
  117. {
  118. //// // Code runs "for real"
  119.  
  120. InitialiseAsync();
  121.  
  122. }
  123. }
  124.  
  125. public async Task InitialiseAsync()
  126. {
  127. var service = new ProvideData();
  128. var lstDrinks = await service.getlstDrinksAsync();
  129.  
  130. Drinks = new ObservableCollection<Foods>(lstDrinks);
  131.  
  132.  
  133. }
  134. }
  135.  
  136. 'Sandwich.WindowsPhone.exe' (CoreCLR: DefaultDomain): Loaded 'C:windows
  137. system32mscorlib.ni.dll'. Skipped loading symbols. Module is optimized
  138. and the debugger option 'Just My Code' is enabled.
  139. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:DataSharedData
  140. PhoneToolsAppxLayouts5534067a-689a-4cf7-
  141. a832-0f14fb3a6014VS.Debug_AnyCPU.raoulSandwich.WindowsPhone.exe'. Symbols
  142. loaded.
  143. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  144. SYSTEM.RUNTIME.NI.DLL'. Skipped loading symbols. Module is optimized and
  145. the debugger option 'Just My Code' is enabled.
  146. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  147. WinMetadataWindows.winmd'. Skipped loading symbols. Module is optimized
  148. and the debugger option 'Just My Code' is enabled.
  149. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  150. SYSTEM.RUNTIME.INTEROPSERVICES.WINDOWSRUNTIME.NI.DLL'. Skipped loading
  151. symbols. Module is optimized and the debugger option 'Just My Code' is
  152. enabled.
  153. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  154. SYSTEM.COLLECTIONS.NI.DLL'. Skipped loading symbols. Module is optimized
  155. and the debugger option 'Just My Code' is enabled.
  156. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:DataSharedData
  157. PhoneToolsAppxLayouts5534067a-689a-4cf7-
  158. a832-0f14fb3a6014VS.Debug_AnyCPU.raoulGalaSoft.MvvmLight.DLL'. Cannot
  159. find or open the PDB file.
  160. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  161. SYSTEM.OBJECTMODEL.NI.DLL'. Skipped loading symbols. Module is optimized
  162. and the debugger option 'Just My Code' is enabled.
  163. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  164. SYSTEM.NI.DLL'. Skipped loading symbols. Module is optimized and the
  165. debugger option 'Just My Code' is enabled.
  166. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:DataSharedData
  167. PhoneToolsAppxLayouts5534067a-689a-4cf7-
  168. a832-0f14fb3a6014VS.Debug_AnyCPU.raoul
  169. Microsoft.Practices.ServiceLocation.DLL'. Cannot find or open the PDB
  170. file.
  171. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:DataSharedData
  172. PhoneToolsAppxLayouts5534067a-689a-4cf7-
  173. a832-0f14fb3a6014VS.Debug_AnyCPU.raoulGalaSoft.MvvmLight.Extras.DLL'.
  174. Cannot find or open the PDB file.
  175. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  176. SYSTEM.COMPONENTMODEL.NI.DLL'. Skipped loading symbols. Module is
  177. optimized and the debugger option 'Just My Code' is enabled.
  178. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  179. SYSTEM.REFLECTION.NI.DLL'. Skipped loading symbols. Module is optimized
  180. and the debugger option 'Just My Code' is enabled.
  181. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  182. SYSTEM.THREADING.NI.DLL'. Skipped loading symbols. Module is optimized
  183. and the debugger option 'Just My Code' is enabled.
  184. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  185. SYSTEM.GLOBALIZATION.NI.DLL'. Skipped loading symbols. Module is
  186. optimized and the debugger option 'Just My Code' is enabled.
  187. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  188. SYSTEM.LINQ.NI.DLL'. Skipped loading symbols. Module is optimized and
  189. the debugger option 'Just My Code' is enabled.
  190. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  191. SYSTEM.CORE.NI.DLL'. Skipped loading symbols. Module is optimized and
  192. the debugger option 'Just My Code' is enabled.
  193. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  194. SYSTEM.DIAGNOSTICS.DEBUG.NI.DLL'. Skipped loading symbols. Module is
  195. optimized and the debugger option 'Just My Code' is enabled.
  196. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  197. SYSTEM.THREADING.TASKS.NI.DLL'. Skipped loading symbols. Module is
  198. optimized and the debugger option 'Just My Code' is enabled.
  199. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  200. System.Net.Http.ni.DLL'. Skipped loading symbols. Module is optimized
  201. and the debugger option 'Just My Code' is enabled.
  202. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  203. System.Net.Http.Phone.ni.DLL'. Skipped loading symbols. Module is
  204. optimized and the debugger option 'Just My Code' is enabled.
  205. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  206. System.Net.ni.DLL'. Skipped loading symbols. Module is optimized and the
  207. debugger option 'Just My Code' is enabled.
  208. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:DataSharedData
  209. PhoneToolsAppxLayouts5534067a-689a-4cf7-
  210. a832-0f14fb3a6014VS.Debug_AnyCPU.raoulNewtonsoft.Json.DLL'. Cannot find
  211. or open the PDB file.
  212. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32
  213. System.Runtime.WindowsRuntime.NI.DLL'. Skipped loading symbols. Module
  214. is optimized and the debugger option 'Just My Code' is enabled.
  215. 'Sandwich.WindowsPhone.exe' (CoreCLR: .): Loaded 'C:windowssystem32en-US
  216. mscorlib.debug.resources.dll'. Module was built without symbols.
  217. A first chance exception of type 'System.Exception' occurred in
  218. mscorlib.ni.dll
  219. A first chance exception of type 'System.Exception' occurred in
  220. mscorlib.ni.dll
  221. The thread 0xb0c has exited with code 259 (0x103).
  222. The thread 0xb04 has exited with code 259 (0x103).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement