コード例 #1
0
        /// <summary>
        /// Updates the user's geoposition (latitude and longitude) and save to the config
        /// </summary>
        /// <param name="configBuilder">config builder for the AutoDarkModeConfig</param>
        /// <returns></returns>
        public static async Task <bool> UpdateGeoposition(AdmConfigBuilder configBuilder)
        {
            GlobalState state = GlobalState.Instance();

            state.GeolocatorIsUpdating = true;
            bool success = false;

            if (configBuilder.Config.Location.UseGeolocatorService)
            {
                success = await UpdateWithGeolocator(configBuilder);
            }
            else
            {
                configBuilder.LocationData.Lat                    = configBuilder.Config.Location.CustomLat;
                configBuilder.LocationData.Lon                    = configBuilder.Config.Location.CustomLon;
                configBuilder.LocationData.LastUpdate             = DateTime.Now;
                configBuilder.LocationData.DataSourceIsGeolocator = false;
            }
            try
            {
                UpdateSunTime(configBuilder);
                configBuilder.SaveLocationData();
            }
            catch (Exception e)
            {
                Logger.Error(e, $"could not update geoposition, source: {e.Source}, error:");
            }
            //await Task.Delay(2500);
            state.GeolocatorIsUpdating = false;
            return(success);
        }
コード例 #2
0
        /// <summary>
        /// Updates the user's geoposition (latitude and longitude) and save to the config
        /// </summary>
        /// <param name="configBuilder">config builder for the AutoDarkModeConfig</param>
        /// <returns></returns>
        public static async Task <bool> UpdateGeoposition(AdmConfigBuilder configBuilder)
        {
            var permission = await Geolocator.RequestAccessAsync();

            var success = false;

            switch (permission)
            {
            case GeolocationAccessStatus.Allowed:
                Geolocator  locator  = new Geolocator();
                Geoposition location = await locator.GetGeopositionAsync();

                BasicGeoposition position = location.Coordinate.Point.Position;
                configBuilder.LocationData.Lon        = position.Longitude;
                configBuilder.LocationData.Lat        = position.Latitude;
                configBuilder.LocationData.LastUpdate = DateTime.Now;
                Logger.Info($"retrieved latitude {position.Latitude} and longitude {position.Longitude}");
                success = true;
                break;

            default:
                configBuilder.Config.Location.Enabled = false;
                Logger.Warn($"no geolocation access, please enable in system settings");
                break;
            }
            UpdateSunTime(configBuilder);
            try
            {
                configBuilder.SaveLocationData();
            }
            catch (Exception e)
            {
                Logger.Error(e, "could not update configuration file while retrieving location");
            }

            return(success);
        }