Version 3.0.338

This commit is contained in:
Anja Müller-Meißner 2022-09-06 16:08:19 +02:00 committed by Anja
parent 573fe77e12
commit 0468955d49
751 changed files with 62747 additions and 60672 deletions

View file

@ -3,11 +3,11 @@ using Xamarin.Essentials;
namespace TINK.Services.Geolocation
{
public class GeolocationAccuracyBestService : GeolocationService
{
public GeolocationAccuracyBestService(IGeolodationDependent dependent) : base(
dependent, GeolocationAccuracy.Best)
{
}
}
public class GeolocationAccuracyBestService : GeolocationService
{
public GeolocationAccuracyBestService(IGeolodationDependent dependent) : base(
dependent, GeolocationAccuracy.Best)
{
}
}
}

View file

@ -3,11 +3,11 @@ using Xamarin.Essentials;
namespace TINK.Services.Geolocation
{
public class GeolocationAccuracyHighService : GeolocationService
{
public GeolocationAccuracyHighService(IGeolodationDependent dependent) : base(
dependent, GeolocationAccuracy.High)
{
}
}
public class GeolocationAccuracyHighService : GeolocationService
{
public GeolocationAccuracyHighService(IGeolodationDependent dependent) : base(
dependent, GeolocationAccuracy.High)
{
}
}
}

View file

@ -3,11 +3,11 @@ using Xamarin.Essentials;
namespace TINK.Services.Geolocation
{
public class GeolocationAccuracyMediumService : GeolocationService
{
public GeolocationAccuracyMediumService(IGeolodationDependent dependent) : base(
dependent, GeolocationAccuracy.Medium)
{
}
}
public class GeolocationAccuracyMediumService : GeolocationService
{
public GeolocationAccuracyMediumService(IGeolodationDependent dependent) : base(
dependent, GeolocationAccuracy.Medium)
{
}
}
}

View file

@ -7,63 +7,63 @@ using Xamarin.Essentials;
namespace TINK.Services.Geolocation
{
public abstract class GeolocationService : IGeolocation
{
/// <summary> Timeout for geolocation request operations.</summary>
private const int GEOLOCATIONREQUEST_TIMEOUT_MS = 5000;
public abstract class GeolocationService : IGeolocation
{
/// <summary> Timeout for geolocation request operations.</summary>
private const int GEOLOCATIONREQUEST_TIMEOUT_MS = 5000;
private IGeolodationDependent Dependent { get; }
private IGeolodationDependent Dependent { get; }
private GeolocationAccuracy Accuracy { get; }
private GeolocationAccuracy Accuracy { get; }
public GeolocationService(
IGeolodationDependent dependent,
GeolocationAccuracy accuracy = GeolocationAccuracy.Default)
{
Dependent = dependent;
Accuracy = accuracy;
}
public GeolocationService(
IGeolodationDependent dependent,
GeolocationAccuracy accuracy = GeolocationAccuracy.Default)
{
Dependent = dependent;
Accuracy = accuracy;
}
public bool IsSimulation => false;
public bool IsSimulation => false;
public bool IsGeolcationEnabled => Dependent.IsGeolcationEnabled;
public bool IsGeolcationEnabled => Dependent.IsGeolcationEnabled;
/// <summary> Gets the current location.</summary>
/// <param name="cancellationToken">Token to cancel request for geolocation.</param>
/// <param name="timeStamp">Time when geolocation is of interest. Is used to determine whether cached geoloation can be used or not.</param>
public async Task<Location> GetAsync(CancellationToken? cancellationToken = null, DateTime? timeStamp = null)
{
try
{
var request = new GeolocationRequest(Accuracy, TimeSpan.FromMilliseconds(GEOLOCATIONREQUEST_TIMEOUT_MS));
return cancellationToken.HasValue
? await Xamarin.Essentials.Geolocation.GetLocationAsync(request, cancellationToken.Value)
: await Xamarin.Essentials.Geolocation.GetLocationAsync(request);
}
catch (FeatureNotSupportedException fnsEx)
{
// Handle not supported on device exception
Log.ForContext<GeolocationService>().Error("Retrieving Geolocation not supported on device. {Exception}", fnsEx);
throw new Exception("Abfrage Standort nicht möglich auf Gerät.", fnsEx);
}
catch (FeatureNotEnabledException fneEx)
{
// Handle not enabled on device exception
Log.ForContext<GeolocationService>().Error("Retrieving Geolocation not enabled on device. {Exception}", fneEx);
throw new Exception("Abfrage Standort nicht aktiviert auf Gerät.", fneEx);
}
catch (PermissionException pEx)
{
// Handle permission exception
Log.ForContext<GeolocationService>().Error("Retrieving Geolocation not permitted on device. {Exception}", pEx);
throw new Exception("Berechtiung für Abfrage Standort nicht erteilt für App.", pEx);
}
catch (Exception ex)
{
// Unable to get location
Log.ForContext<GeolocationService>().Error("Retrieving Geolocation failed. {Exception}", ex);
throw new Exception("Abfrage Standort fehlgeschlagen.", ex);
}
}
}
/// <summary> Gets the current location.</summary>
/// <param name="cancellationToken">Token to cancel request for geolocation.</param>
/// <param name="timeStamp">Time when geolocation is of interest. Is used to determine whether cached geoloation can be used or not.</param>
public async Task<Location> GetAsync(CancellationToken? cancellationToken = null, DateTime? timeStamp = null)
{
try
{
var request = new GeolocationRequest(Accuracy, TimeSpan.FromMilliseconds(GEOLOCATIONREQUEST_TIMEOUT_MS));
return cancellationToken.HasValue
? await Xamarin.Essentials.Geolocation.GetLocationAsync(request, cancellationToken.Value)
: await Xamarin.Essentials.Geolocation.GetLocationAsync(request);
}
catch (FeatureNotSupportedException fnsEx)
{
// Handle not supported on device exception
Log.ForContext<GeolocationService>().Error("Retrieving Geolocation not supported on device. {Exception}", fnsEx);
throw new Exception("Abfrage Standort nicht möglich auf Gerät.", fnsEx);
}
catch (FeatureNotEnabledException fneEx)
{
// Handle not enabled on device exception
Log.ForContext<GeolocationService>().Error("Retrieving Geolocation not enabled on device. {Exception}", fneEx);
throw new Exception("Abfrage Standort nicht aktiviert auf Gerät.", fneEx);
}
catch (PermissionException pEx)
{
// Handle permission exception
Log.ForContext<GeolocationService>().Error("Retrieving Geolocation not permitted on device. {Exception}", pEx);
throw new Exception("Berechtiung für Abfrage Standort nicht erteilt für App.", pEx);
}
catch (Exception ex)
{
// Unable to get location
Log.ForContext<GeolocationService>().Error("Retrieving Geolocation failed. {Exception}", ex);
throw new Exception("Abfrage Standort fehlgeschlagen.", ex);
}
}
}
}

View file

@ -6,16 +6,16 @@ using Xamarin.Essentials;
namespace TINK.Services.Geolocation
{
/// <summary> Query geolocation. </summary>
public interface IGeolocation : IGeolodationDependent
{
/// <summary> Gets the current location.</summary>
/// <param name="cancellationToken">Token to cancel request for geolocation. If null request can not be cancels and times out after GeolocationService.GEOLOCATIONREQUEST_TIMEOUT_MS if geolocation is not available.</param>
/// <param name="timeStamp">Time when geolocation is of interest. Is used to determine for some implementations whether cached geoloation can be used or not.</param>
/// <returns></returns>
Task<Location> GetAsync(CancellationToken? cancellationToken = null, DateTime? timeStamp = null);
/// <summary> Query geolocation. </summary>
public interface IGeolocation : IGeolodationDependent
{
/// <summary> Gets the current location.</summary>
/// <param name="cancellationToken">Token to cancel request for geolocation. If null request can not be cancels and times out after GeolocationService.GEOLOCATIONREQUEST_TIMEOUT_MS if geolocation is not available.</param>
/// <param name="timeStamp">Time when geolocation is of interest. Is used to determine for some implementations whether cached geoloation can be used or not.</param>
/// <returns></returns>
Task<Location> GetAsync(CancellationToken? cancellationToken = null, DateTime? timeStamp = null);
/// <summary> If true location data returned is simulated.</summary>
bool IsSimulation { get; }
}
/// <summary> If true location data returned is simulated.</summary>
bool IsSimulation { get; }
}
}

View file

@ -7,66 +7,66 @@ using Xamarin.Essentials;
namespace TINK.Services.Geolocation
{
public class LastKnownGeolocationService : IGeolocation
{
private IGeolodationDependent Dependent { get; }
public class LastKnownGeolocationService : IGeolocation
{
private IGeolodationDependent Dependent { get; }
public LastKnownGeolocationService(IGeolodationDependent dependent)
{
Dependent = dependent;
}
public LastKnownGeolocationService(IGeolodationDependent dependent)
{
Dependent = dependent;
}
/// <summary> Gets the current location.</summary>
/// <param name="cancelationToken">Token to cancel request for geolocation.</param>
/// <param name="timeStamp">Time when geolocation is of interest. Is used to determine whether cached geoloation can be used or not.</param>
public async Task<Location> GetAsync(CancellationToken? cancelationToken = null, DateTime? timeStamp = null)
{
Location location;
try
{
location = await Xamarin.Essentials.Geolocation.GetLastKnownLocationAsync();
}
catch (FeatureNotSupportedException fnsEx)
{
// Handle not supported on device exception
Log.ForContext<LastKnownGeolocationService>().Error("Retrieving Geolocation not supported on device. {Exception}", fnsEx);
throw new Exception("Abfrage Standort nicht möglich auf Gerät.", fnsEx);
}
catch (FeatureNotEnabledException fneEx)
{
// Handle not enabled on device exception
Log.ForContext<LastKnownGeolocationService>().Error("Retrieving Geolocation not enabled on device. {Exception}", fneEx);
throw new Exception("Abfrage Standort nicht aktiviert auf Gerät.", fneEx);
}
catch (PermissionException pEx)
{
// Handle permission exception
Log.ForContext<LastKnownGeolocationService>().Error("Retrieving Geolocation not permitted on device. {Exception}", pEx);
throw new Exception("Berechtiung für Abfrage Standort nicht erteilt für App.", pEx);
}
catch (Exception ex)
{
// Unable to get location
Log.ForContext<LastKnownGeolocationService>().Error("Retrieving Geolocation failed. {Exception}", ex);
throw new Exception("Abfrage Standort fehlgeschlagen.", ex);
}
/// <summary> Gets the current location.</summary>
/// <param name="cancelationToken">Token to cancel request for geolocation.</param>
/// <param name="timeStamp">Time when geolocation is of interest. Is used to determine whether cached geoloation can be used or not.</param>
public async Task<Location> GetAsync(CancellationToken? cancelationToken = null, DateTime? timeStamp = null)
{
Location location;
try
{
location = await Xamarin.Essentials.Geolocation.GetLastKnownLocationAsync();
}
catch (FeatureNotSupportedException fnsEx)
{
// Handle not supported on device exception
Log.ForContext<LastKnownGeolocationService>().Error("Retrieving Geolocation not supported on device. {Exception}", fnsEx);
throw new Exception("Abfrage Standort nicht möglich auf Gerät.", fnsEx);
}
catch (FeatureNotEnabledException fneEx)
{
// Handle not enabled on device exception
Log.ForContext<LastKnownGeolocationService>().Error("Retrieving Geolocation not enabled on device. {Exception}", fneEx);
throw new Exception("Abfrage Standort nicht aktiviert auf Gerät.", fneEx);
}
catch (PermissionException pEx)
{
// Handle permission exception
Log.ForContext<LastKnownGeolocationService>().Error("Retrieving Geolocation not permitted on device. {Exception}", pEx);
throw new Exception("Berechtiung für Abfrage Standort nicht erteilt für App.", pEx);
}
catch (Exception ex)
{
// Unable to get location
Log.ForContext<LastKnownGeolocationService>().Error("Retrieving Geolocation failed. {Exception}", ex);
throw new Exception("Abfrage Standort fehlgeschlagen.", ex);
}
if (location != null // Cached location is available.
&& (timeStamp == null || timeStamp.Value.Subtract(location.Timestamp.DateTime) < MaxAge))
{
// No time stamp available or location not too old.
return location;
}
if (location != null // Cached location is available.
&& (timeStamp == null || timeStamp.Value.Subtract(location.Timestamp.DateTime) < MaxAge))
{
// No time stamp available or location not too old.
return location;
}
return await new GeolocationAccuracyMediumService(Dependent).GetAsync(cancelationToken, timeStamp);
}
return await new GeolocationAccuracyMediumService(Dependent).GetAsync(cancelationToken, timeStamp);
}
/// <summary> If true location data returned is simulated.</summary>
public bool IsSimulation { get => false; }
/// <summary> If true location data returned is simulated.</summary>
public bool IsSimulation { get => false; }
/// <summary> Maximum age allowed for location info. </summary>
public TimeSpan MaxAge => new TimeSpan(0, 3 /*minutes*/, 0);
/// <summary> Maximum age allowed for location info. </summary>
public TimeSpan MaxAge => new TimeSpan(0, 3 /*minutes*/, 0);
public bool IsGeolcationEnabled => Dependent.IsGeolcationEnabled;
}
public bool IsGeolcationEnabled => Dependent.IsGeolcationEnabled;
}
}

View file

@ -6,26 +6,26 @@ using Xamarin.Essentials;
namespace TINK.Services.Geolocation
{
public class SimulatedGeolocationService : IGeolocation
{
private IGeolodationDependent Dependent { get; }
public class SimulatedGeolocationService : IGeolocation
{
private IGeolodationDependent Dependent { get; }
public SimulatedGeolocationService(IGeolodationDependent dependent)
{
Dependent = dependent;
}
public SimulatedGeolocationService(IGeolodationDependent dependent)
{
Dependent = dependent;
}
/// <summary> Gets the current location.</summary>
/// <param name="cancelToken">Token to cancel request for geolocation.</param>
/// <param name="timeStamp">Time when geolocation is of interest. Is used to determine whether cached geoloation can be used or not.</param>
public async Task<Location> GetAsync(CancellationToken? cancelToken = null, DateTime? timeStamp = null)
{
return await Task.FromResult(new Location(47.976634, 7.825490) { Accuracy = 0, Timestamp = timeStamp ?? DateTime.Now }); ;
}
/// <summary> Gets the current location.</summary>
/// <param name="cancelToken">Token to cancel request for geolocation.</param>
/// <param name="timeStamp">Time when geolocation is of interest. Is used to determine whether cached geoloation can be used or not.</param>
public async Task<Location> GetAsync(CancellationToken? cancelToken = null, DateTime? timeStamp = null)
{
return await Task.FromResult(new Location(47.976634, 7.825490) { Accuracy = 0, Timestamp = timeStamp ?? DateTime.Now }); ;
}
/// <summary> If true location data returned is simulated.</summary>
public bool IsSimulation { get => true; }
/// <summary> If true location data returned is simulated.</summary>
public bool IsSimulation { get => true; }
public bool IsGeolcationEnabled => Dependent.IsGeolcationEnabled;
}
public bool IsGeolcationEnabled => Dependent.IsGeolcationEnabled;
}
}