Ejemplo n.º 1
0
        /// <summary>
        /// Button click that initiates a search for diffrent locations.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            ListBoxItems.Clear();
            XmlManager.LocationSheetList locationSheetList = new XmlManager.LocationSheetList();

            //Make sure to not block UI
            await Task.Run(() =>
            {
                try
                {
                    locationSheetList = WebServiceAPIContext.ReceiveLocationList(_SearchLocation, _ConnectionString);
                }
                catch (Exception ex)
                {
                    ShowErrorMessageBox(ex.Message);
                }
                if (locationSheetList.Error && locationSheetList.ExMsg != String.Empty)
                {
                    ShowErrorMessageBox(locationSheetList.ExMsg);
                }
            });

            if (locationSheetList.LocationSheets != null)
            {
                foreach (var x in locationSheetList.LocationSheets)
                {
                    Encoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(x.Name));

                    ListBoxItems.Add(x);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Seperate function to get trip and weather information to make sure UI thread isn't blocked.
        /// </summary>
        private async void RecieveWeatherAndTripToDestination()
        {
            await Task.Run(() =>
            {
                try
                {
                    SelectedTrip = WebServiceAPIContext.ReceiveTripToDestination(int.Parse(SelectedListBoxItem.ID), _ConnectionString);
                    WeatherSheet = WebServiceAPIContext.ReceiveWeather(SelectedTrip.DestinationLat,
                                                                       SelectedTrip.DestinationLon, DateTime.Parse(SelectedTrip.DestinationTime), _ConnectionString);
                }
                catch (Exception ex)
                {
                    ShowErrorMessageBox(ex.Message);
                }

                if (SelectedTrip.Error)
                {
                    ShowErrorMessageBox(SelectedTrip.ExMsg);
                }
                if (WeatherSheet.Error)
                {
                    ShowErrorMessageBox(WeatherSheet.ExMsg);
                }
            });
        }