/// <summary> /// Loads the content needed for the APP /// </summary> /// <remarks> /// Can get the data from an API /// or the local DataBase, if exists! /// </remarks> private async void LoadContent() { try { Mouse.OverrideCursor = Cursors.Wait; LoadingBar.Value = 0; //check if there is internet connection networkService = new NetworkService(); //TODO true for testing if (!networkService.CheckNetConnection()) { LoadFromDB(); LblLoadFrom.Text = $"Data loaded from local DataBase on {DateTime.Now}"; network = false; } else { await LoadFromAPI(); LblLoadFrom.Text = $"Data loaded from API on {DateTime.Now}"; } //jumps from current block because there is no data loaded into Countries //or some save error happened if (Countries.Count == 0 || Countries.Count < 250) { LblLoadFrom.Text = $"Couldn't connect to the API or the Database."; LblLoadSave.Text = "Error loading..."; ProgressText.Text = "N/A"; return; } await CreateAdvancedSearchData(); //when connected to the internet saves/updates data in DB if (network) { await CheckLastUpdate(); } //adds the items from the list to a the dropdown list, displays the attribute Name from the list Countries.Add(new Country { Name = " --Select a Country--" }); Countries = Countries.OrderBy(x => x.Name).ToList(); CbCountry.ItemsSource = Countries; CbCountry.DisplayMemberPath = "Name"; CbCountry.Text = " --Select a Country--"; LoadingBar.Value = 100; } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.StackTrace); } finally { Mouse.OverrideCursor = null; saving = false; //delaying the Data Saved lbl await Task.Delay(5000); LblLoadSave.Visibility = Visibility.Hidden; } }