Ejemplo n.º 1
0
        /// <summary>
        /// Handles delete button clicks to remove the selected
        /// location from the Locations collection.
        /// </summary>
        private async void DeleteLocation_Click(object sender, RoutedEventArgs e)
        {
            var location = this.GetLocation(sender as Button);
            int index    = this.Locations.IndexOf(location);

            this.Locations.Remove(location);
            await LocationDataStore.SaveLocationDataAsync(this.Locations);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles clicks to the Track button to flag the selected location for monitoring
        /// by a background task that periodically checks traffic and sends a notification
        /// whenever traffic adds 10 minutes or more to the travel time.
        /// </summary>
        private async void TrackButton_Click(object sender, RoutedEventArgs e)
        {
            var button   = sender as ToggleButton;
            var location = this.GetLocation(button);

            location.IsMonitored = button.IsChecked.Value;
            this.UpdateTrafficMonitor(button.IsChecked.Value);
            await LocationDataStore.SaveLocationDataAsync(this.Locations);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Applies the changes represented by the specified LocationData to
        /// the cached location in edit, saves the changes to the file system,
        /// and updates the user interface to account for the changes.
        /// </summary>
        private async Task SaveAsync(LocationData workingCopy)
        {
            Flyout.GetAttachedFlyout(this.GetTemplateRootForLocation(this.locationInEdit)).Hide();

            this.isNewLocationInEdit = false;
            this.isExistingLocationBeingRepositioned = false;
            bool isAddressNew      = workingCopy.Address != this.locationInEdit.Address;
            bool areCoordinatesNew = !workingCopy.Position.Equals(this.locationInEdit.Position);

            // If just the address OR just the coordinates are new,
            // clear the other value so that it can be updated.
            if (isAddressNew ^ areCoordinatesNew)
            {
                if (isAddressNew)
                {
                    workingCopy.Position = new BasicGeoposition();
                }
                if (areCoordinatesNew)
                {
                    workingCopy.Address = string.Empty;
                }
            }

            // If the address, the coordinates, or both have changed, clear the travel
            // info and the route so that it doesn't reflect the old position.
            if (isAddressNew || areCoordinatesNew)
            {
                workingCopy.ClearTravelInfo();
                this.InputMap.Routes.Clear();
            }

            this.locationInEdit.Copy(workingCopy);

            var currentLocation = await this.GetCurrentLocationAsync();

            if (currentLocation != null)
            {
                if (isAddressNew ^ areCoordinatesNew)
                {
                    await LocationHelper.TryUpdateMissingLocationInfoAsync(this.locationInEdit, currentLocation);
                }
            }

            await LocationDataStore.SaveLocationDataAsync(this.Locations);

            if (currentLocation != null)
            {
                bool isNetworkAvailable = await this.TryUpdateLocationsTravelInfoAsync(this.Locations, currentLocation);

                if (isNetworkAvailable)
                {
                    this.InputMap.Routes.Add(new MapRouteView(this.locationInEdit.FastestRoute));
                }
            }
        }