/// <summary> /// Constructor for the Application object. /// </summary> public App() { // Global handler for uncaught exceptions. UnhandledException += Application_UnhandledException; // Standard Silverlight initialization InitializeComponent(); // Phone-specific initialization InitializePhoneApplication(); // Show graphics profiling information while debugging. if (System.Diagnostics.Debugger.IsAttached) { // Display the current frame rate counters. Application.Current.Host.Settings.EnableFrameRateCounter = true; // Show the areas of the app that are being redrawn in each frame. //Application.Current.Host.Settings.EnableRedrawRegions = true; // Enable non-production analysis visualization mode, // which shows areas of a page that are handed off to GPU with a colored overlay. //Application.Current.Host.Settings.EnableCacheVisualization = true; // Disable the application idle detection by setting the UserIdleDetectionMode property of the // application's PhoneApplicationService object to Disabled. // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run // and consume battery power when the user is not using the phone. #if WP7 PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled; #endif } Recipes = new RecipeDataSource(); }
/// <summary> /// Constructor for the Application object. /// </summary> public App() { // Global handler for uncaught exceptions. UnhandledException += Application_UnhandledException; // Standard XAML initialization InitializeComponent(); // Phone-specific initialization InitializePhoneApplication(); // Language display initialization InitializeLanguage(); // Show graphics profiling information while debugging. if (Debugger.IsAttached) { // Display the current frame rate counters. Application.Current.Host.Settings.EnableFrameRateCounter = true; // Show the areas of the app that are being redrawn in each frame. //Application.Current.Host.Settings.EnableRedrawRegions = true; // Enable non-production analysis visualization mode, // which shows areas of a page that are handed off to GPU with a colored overlay. //Application.Current.Host.Settings.EnableCacheVisualization = true; // Prevent the screen from turning off while under the debugger by disabling // the application's idle detection. // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run // and consume battery power when the user is not using the phone. PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled; } Recipes = new RecipeDataSource(); }
private static async System.Threading.Tasks.Task CreateRecipesAndRecipeGroups(JsonArray array) { try { foreach (var item in array) { var obj = item.GetObject(); RecipeDataItem Recipe = new RecipeDataItem(); RecipeDataGroup group = null; foreach (var key in obj.Keys) { IJsonValue val; if (!obj.TryGetValue(key, out val)) continue; switch (key) { case "identifier": Recipe.UniqueId = val.GetString(); var client = new HttpClient(); client.MaxResponseContentBufferSize = 1024 * 1024; // Read up to 1 MB of data var response = await client.GetAsync(new Uri("http://me2day.net/api/get_content.json?domain=" + Recipe.Group.Title + "&identifier=" + Convert.ToInt32(val.GetString()) + "&akey=3345257cb3f6681909994ea2c0566e80&asig=MTMzOTE2NDY1MiQkYnlidWFtLnEkJDYzZTVlM2EwOWUyYmI5M2Q0OGU4ZjlmNzA4ZjUzYjMz&locale=ko-KR")); var result = await response.Content.ReadAsStringAsync(); // Parse the JSON Recipe data var Recipes = JsonObject.Parse(result/*.Substring(12, result.Length - 13)*/); foreach (var item1 in Recipes) { if (item1.Key == "detail") { //var obj1 = item1.GetObject(); var obj1 = item1.Value.GetObject(); foreach (var key1 in obj1) { IJsonValue val1; /* if (!obj1.TryGetValue(key1, out val1)) continue; */ val1 = key1.Value; switch (key1.Key) { case "title": Recipe.Title = val1.GetString(); break; case "artist": Recipe.ShortTitle = val1.GetString(); break; case "cast": Recipe.ShortTitle = val1.GetString(); break; case "author": Recipe.ShortTitle = val1.GetString(); break; // case "rate": // Recipe.PrepTime = Convert.ToInt32(val1.GetString()); // break; case "description": Recipe.Directions = val1.GetString(); Recipe.Directions = Recipe.Directions.Replace("&", "&"); Recipe.Directions = Recipe.Directions.Replace(">", ">"); Recipe.Directions = Recipe.Directions.Replace("<", "<"); break; case "image_url": Recipe.SetImage(val1.GetString()); break; } } } } break; case "domain": string groupKey = val.GetString(); group = _recipeDataSource.AllGroups.FirstOrDefault(c => c.Title.Equals(groupKey)); if (group == null) group = CreateRecipeGroup(groupKey); Recipe.Group = group; break; } } if (group != null) { Recipe.Ingredients = ""; group.Items.Add(Recipe); } } _recipeDataSource.AllGroups.FirstOrDefault(c => c.Title.Equals("movie")).Title = "영화"; _recipeDataSource.AllGroups.FirstOrDefault(c => c.Title.Equals("music_album")).Title = "음반"; _recipeDataSource.AllGroups.FirstOrDefault(c => c.Title.Equals("book")).Title = "책"; } catch (Exception ex) { _recipeDataSource = null; } }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += OnSuspending; Recipes = new RecipeDataSource(); }
public static async System.Threading.Tasks.Task LoadRemoteDataAsync() { if (_recipeDataSource != null && _recipeDataSource.AllGroups.Count > 0) return; var profile = NetworkInformation.GetInternetConnectionProfile(); if (profile==null||profile.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.InternetAccess) { } else { // Retrieve Recipe data from Azure try { var client = new HttpClient(); client.MaxResponseContentBufferSize = 1024 * 1024; // Read up to 1 MB of data var response = await client.GetAsync(new Uri("http://me2day.net/api/get_best_contents.json?&akey=3345257cb3f6681909994ea2c0566e80&asig=MTMzOTE2NDY1MiQkYnlidWFtLnEkJDYzZTVlM2EwOWUyYmI5M2Q0OGU4ZjlmNzA4ZjUzYjMz&locale=ko-KR")); var result = await response.Content.ReadAsStringAsync(); // Parse the JSON Recipe data var Recipes = JsonArray.Parse(result.Substring(12, result.Length - 13)); // Convert the JSON objects into RecipeDataItems and RecipeDataGroups await CreateRecipesAndRecipeGroups(Recipes); } catch (Exception ex) { _recipeDataSource = null; } } }