mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-22 21:06:30 +02:00
Version 3.0.362
This commit is contained in:
parent
cba4da9357
commit
4ff3307997
128 changed files with 3954 additions and 3193 deletions
36
TINKLib/Services/Geolocation/Geolocation.cs
Normal file
36
TINKLib/Services/Geolocation/Geolocation.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
|
||||
namespace TINK.Services.Geolocation
|
||||
{
|
||||
public class Geolocation : IGeolocation
|
||||
{
|
||||
private Geolocation() { }
|
||||
|
||||
public DateTimeOffset Timestamp { get; private set; }
|
||||
|
||||
public double Latitude { get; private set; }
|
||||
|
||||
public double Longitude { get; private set; }
|
||||
|
||||
public double? Accuracy { get; private set; }
|
||||
|
||||
public class Builder
|
||||
{
|
||||
|
||||
public DateTimeOffset Timestamp { get; set; }
|
||||
|
||||
public double Latitude { get; set; }
|
||||
|
||||
public double Longitude { get; set; }
|
||||
|
||||
public double? Accuracy { get; set; }
|
||||
|
||||
public Geolocation Build()
|
||||
=> new Geolocation() {
|
||||
Timestamp = Timestamp,
|
||||
Latitude = Latitude,
|
||||
Longitude = Longitude,
|
||||
Accuracy = Accuracy};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Serilog;
|
||||
|
@ -7,7 +7,7 @@ using Xamarin.Essentials;
|
|||
|
||||
namespace TINK.Services.Geolocation
|
||||
{
|
||||
public abstract class GeolocationService : IGeolocation
|
||||
public abstract class GeolocationService : IGeolocationService
|
||||
{
|
||||
/// <summary> Timeout for geolocation request operations.</summary>
|
||||
private const int GEOLOCATIONREQUEST_TIMEOUT_MS = 5000;
|
||||
|
@ -31,14 +31,14 @@ namespace TINK.Services.Geolocation
|
|||
/// <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)
|
||||
public async Task<IGeolocation> 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);
|
||||
? (await Xamarin.Essentials.Geolocation.GetLocationAsync(request, cancellationToken.Value)).ToGeolocation()
|
||||
: (await Xamarin.Essentials.Geolocation.GetLocationAsync(request)).ToGeolocation();
|
||||
}
|
||||
catch (FeatureNotSupportedException fnsEx)
|
||||
{
|
||||
|
|
|
@ -1,21 +1,15 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Device;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
using System;
|
||||
namespace TINK.Services.Geolocation
|
||||
{
|
||||
/// <summary> Query geolocation. </summary>
|
||||
public interface IGeolocation : IGeolodationDependent
|
||||
public interface IGeolocation
|
||||
{
|
||||
/// <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; }
|
||||
double Latitude { get; }
|
||||
|
||||
double Longitude { get; }
|
||||
|
||||
double? Accuracy { get; }
|
||||
|
||||
DateTimeOffset Timestamp { get; }
|
||||
}
|
||||
}
|
||||
|
|
21
TINKLib/Services/Geolocation/IGeolocationService.cs
Normal file
21
TINKLib/Services/Geolocation/IGeolocationService.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Device;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace TINK.Services.Geolocation
|
||||
{
|
||||
/// <summary> Query geolocation. </summary>
|
||||
public interface IGeolocationService : 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<IGeolocation> GetAsync(CancellationToken? cancellationToken = null, DateTime? timeStamp = null);
|
||||
|
||||
/// <summary> If true location data returned is simulated.</summary>
|
||||
bool IsSimulation { get; }
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Serilog;
|
||||
|
@ -7,7 +7,7 @@ using Xamarin.Essentials;
|
|||
|
||||
namespace TINK.Services.Geolocation
|
||||
{
|
||||
public class LastKnownGeolocationService : IGeolocation
|
||||
public class LastKnownGeolocationService : IGeolocationService
|
||||
{
|
||||
private IGeolodationDependent Dependent { get; }
|
||||
|
||||
|
@ -19,12 +19,12 @@ namespace TINK.Services.Geolocation
|
|||
/// <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)
|
||||
public async Task<IGeolocation> GetAsync(CancellationToken? cancelationToken = null, DateTime? timeStamp = null)
|
||||
{
|
||||
Location location;
|
||||
IGeolocation location;
|
||||
try
|
||||
{
|
||||
location = await Xamarin.Essentials.Geolocation.GetLastKnownLocationAsync();
|
||||
location = (await Xamarin.Essentials.Geolocation.GetLastKnownLocationAsync()).ToGeolocation();
|
||||
}
|
||||
catch (FeatureNotSupportedException fnsEx)
|
||||
{
|
||||
|
|
21
TINKLib/Services/Geolocation/LocationHelper.cs
Normal file
21
TINKLib/Services/Geolocation/LocationHelper.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using Xamarin.Essentials;
|
||||
|
||||
namespace TINK.Services.Geolocation
|
||||
{
|
||||
public static class LocationHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts Xamarin.Essentials Location object to Geolocatin object.
|
||||
/// </summary>
|
||||
/// <param name="location"></param>
|
||||
/// <returns></returns>
|
||||
public static IGeolocation ToGeolocation(this Location location)
|
||||
=> new Geolocation.Builder
|
||||
{
|
||||
Latitude = location.Latitude,
|
||||
Longitude = location.Longitude,
|
||||
Accuracy = location.Accuracy,
|
||||
Timestamp = location.Timestamp,
|
||||
}.Build();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using TINK.Model.Device;
|
||||
|
@ -6,7 +6,7 @@ using Xamarin.Essentials;
|
|||
|
||||
namespace TINK.Services.Geolocation
|
||||
{
|
||||
public class SimulatedGeolocationService : IGeolocation
|
||||
public class SimulatedGeolocationService : IGeolocationService
|
||||
{
|
||||
private IGeolodationDependent Dependent { get; }
|
||||
|
||||
|
@ -18,9 +18,13 @@ namespace TINK.Services.Geolocation
|
|||
/// <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)
|
||||
public async Task<IGeolocation> GetAsync(CancellationToken? cancelToken = null, DateTime? timeStamp = null)
|
||||
{
|
||||
return await Task.FromResult(new Location(47.976634, 7.825490) { Accuracy = 0, Timestamp = timeStamp ?? DateTime.Now }); ;
|
||||
return await Task.FromResult(new Geolocation.Builder {
|
||||
Latitude = 47.976634,
|
||||
Longitude = 7.825490,
|
||||
Accuracy = 0,
|
||||
Timestamp = timeStamp ?? DateTime.Now }.Build()); ;
|
||||
}
|
||||
|
||||
/// <summary> If true location data returned is simulated.</summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue