mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-06-21 21:46:27 +02:00
Version 3.0.290
This commit is contained in:
parent
af3c20ea1c
commit
ad3cdbcadf
231 changed files with 14555 additions and 7798 deletions
|
@ -48,8 +48,8 @@ namespace TINK.Services.BluetoothLock
|
|||
switch (lockInfo.State )
|
||||
{
|
||||
case LockingState.Open:
|
||||
case LockingState.Disconnected:
|
||||
case LockingState.Unknown:
|
||||
case LockingState.UnknownDisconnected:
|
||||
case LockingState.UnknownFromHardwareError:
|
||||
// Open bikes are never disposable because as soon as a they are open they get booked.
|
||||
if (LocksInfo.FirstOrDefault(x => x.Id == lockInfo.Id) != null)
|
||||
{
|
||||
|
@ -64,8 +64,8 @@ namespace TINK.Services.BluetoothLock
|
|||
switch (lockInfo.State)
|
||||
{
|
||||
case LockingState.Open:
|
||||
case LockingState.Disconnected:
|
||||
case LockingState.Unknown:
|
||||
case LockingState.UnknownDisconnected:
|
||||
case LockingState.UnknownFromHardwareError:
|
||||
// Closed bikes are never reserved because as soon as they are open they get booked.
|
||||
if (LocksInfo.FirstOrDefault(x => x.Id == lockInfo.Id) != null)
|
||||
{
|
||||
|
@ -79,8 +79,8 @@ namespace TINK.Services.BluetoothLock
|
|||
case InUseStateEnum.Booked:
|
||||
switch (lockInfo.State)
|
||||
{
|
||||
case LockingState.Disconnected:
|
||||
case LockingState.Unknown:
|
||||
case LockingState.UnknownDisconnected:
|
||||
case LockingState.UnknownFromHardwareError:
|
||||
if (LocksInfo.FirstOrDefault(x => x.Id == lockInfo.Id) != null)
|
||||
{
|
||||
continue; // Lock was already added.
|
||||
|
@ -152,6 +152,6 @@ namespace TINK.Services.BluetoothLock
|
|||
/// <summary> Disconnects lock.</summary>
|
||||
/// <param name="bikeId"> Id of lock to disconnect.</param>
|
||||
/// <param name="bikeGuid"> Guid of lock to disconnect.</param>
|
||||
public async Task<LockingState> DisconnectAsync(int bikeId, Guid bikeGuid) => await Task.FromResult(LockingState.Disconnected);
|
||||
public async Task<LockingState> DisconnectAsync(int bikeId, Guid bikeGuid) => await Task.FromResult(LockingState.UnknownDisconnected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,6 @@ namespace TINK.Services.BluetoothLock
|
|||
/// <summary> Disconnects lock.</summary>
|
||||
/// <param name="bikeId"> Id of lock to disconnect.</param>
|
||||
/// <param name="bikeGuid"> Guid of lock to disconnect.</param>
|
||||
public async Task<LockingState> DisconnectAsync(int bikeId, Guid bikeGuid) => await Task.FromResult(LockingState.Disconnected);
|
||||
public async Task<LockingState> DisconnectAsync(int bikeId, Guid bikeGuid) => await Task.FromResult(LockingState.UnknownDisconnected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
using Plugin.BLE.Abstractions.Contracts;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TINK.Services.BluetoothLock
|
||||
{
|
||||
public static class StateChecker
|
||||
{
|
||||
/// <summary>
|
||||
/// Get current bluetooth state
|
||||
/// </summary>
|
||||
/// <remarks>See https://github.com/xabre/xamarin-bluetooth-le/issues/112#issuecomment-380994887.</remarks>
|
||||
/// <param name="ble">Crossplatform bluetooth implementation object</param>
|
||||
/// <returns>BluetoothState</returns>
|
||||
public static Task<BluetoothState> GetBluetoothState(this IBluetoothLE ble)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<BluetoothState>();
|
||||
|
||||
if (ble.State != BluetoothState.Unknown)
|
||||
{
|
||||
// If we can detect state out of box just returning in
|
||||
tcs.SetResult(ble.State);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise let's setup dynamic event handler and wait for first state update
|
||||
EventHandler<Plugin.BLE.Abstractions.EventArgs.BluetoothStateChangedArgs> handler = null;
|
||||
handler = (o, e) =>
|
||||
{
|
||||
ble.StateChanged -= handler;
|
||||
// and return it as our state
|
||||
// we can have an 'Unknown' check here, but in normal situation it should never occur
|
||||
tcs.SetResult(e.NewState);
|
||||
};
|
||||
ble.StateChanged += handler;
|
||||
}
|
||||
|
||||
return tcs.Task;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -227,6 +227,11 @@ namespace TINK.Model.Services.CopriApi
|
|||
return await HttpsServer.CalculateAuthKeysAsync(bikeId, operatorUri);
|
||||
}
|
||||
|
||||
public async Task<ResponseBase> StartReturningBike(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> await HttpsServer.StartReturningBike(bikeId, operatorUri);
|
||||
|
||||
public async Task<ReservationBookingResponse> UpdateLockingStateAsync(
|
||||
string bikeId,
|
||||
LocationDto location,
|
||||
|
|
|
@ -40,6 +40,12 @@ namespace TINK.Model.Services.CopriApi
|
|||
public Task<ReservationBookingResponse> CalculateAuthKeysAsync(string bikeId, Uri operatorUri)
|
||||
=> throw new NotSupportedException($"{nameof(CalculateAuthKeysAsync)} is not cachable.");
|
||||
|
||||
public async Task<ResponseBase> StartReturningBike(
|
||||
string bikeId,
|
||||
Uri operatorUri)
|
||||
=> await monkeyStore.StartReturningBike(bikeId, operatorUri);
|
||||
|
||||
|
||||
public async Task<ReservationBookingResponse> UpdateLockingStateAsync(
|
||||
string bikeId,
|
||||
LocationDto geolocation,
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
using TINK.Model.Device;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace TINK.Services.Geolocation
|
||||
{
|
||||
public class GeolocationAccuracyBestService : GeolocationService
|
||||
{
|
||||
public GeolocationAccuracyBestService(IGeolodationDependent dependent) : base(
|
||||
dependent, GeolocationAccuracy.Best)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
using TINK.Model.Device;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace TINK.Services.Geolocation
|
||||
{
|
||||
public class GeolocationAccuracyHighService : GeolocationService
|
||||
{
|
||||
public GeolocationAccuracyHighService(IGeolodationDependent dependent) : base(
|
||||
dependent, GeolocationAccuracy.High)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
using TINK.Model.Device;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace TINK.Services.Geolocation
|
||||
{
|
||||
public class GeolocationAccuracyMediumService : GeolocationService
|
||||
{
|
||||
public GeolocationAccuracyMediumService(IGeolodationDependent dependent) : base(
|
||||
dependent, GeolocationAccuracy.Medium)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,18 +5,23 @@ using System.Threading.Tasks;
|
|||
using TINK.Model.Device;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace TINK.Model.Services.Geolocation
|
||||
namespace TINK.Services.Geolocation
|
||||
{
|
||||
public class GeolocationService : IGeolocation
|
||||
public abstract class GeolocationService : IGeolocation
|
||||
{
|
||||
/// <summary> Timeout for geolocation request operations.</summary>
|
||||
private const int GEOLOCATIONREQUEST_TIMEOUT_MS = 5000;
|
||||
|
||||
private IGeolodationDependent Dependent { get; }
|
||||
|
||||
public GeolocationService(IGeolodationDependent dependent)
|
||||
private GeolocationAccuracy Accuracy { get; }
|
||||
|
||||
public GeolocationService(
|
||||
IGeolodationDependent dependent,
|
||||
GeolocationAccuracy accuracy = GeolocationAccuracy.Default)
|
||||
{
|
||||
Dependent = dependent;
|
||||
Accuracy = accuracy;
|
||||
}
|
||||
|
||||
public bool IsSimulation => false;
|
||||
|
@ -30,7 +35,7 @@ namespace TINK.Model.Services.Geolocation
|
|||
{
|
||||
try
|
||||
{
|
||||
var request = new GeolocationRequest(GeolocationAccuracy.Medium, TimeSpan.FromMilliseconds(GEOLOCATIONREQUEST_TIMEOUT_MS));
|
||||
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);
|
||||
|
|
|
@ -4,7 +4,7 @@ using System.Threading.Tasks;
|
|||
using TINK.Model.Device;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace TINK.Model.Services.Geolocation
|
||||
namespace TINK.Services.Geolocation
|
||||
{
|
||||
/// <summary> Query geolocation. </summary>
|
||||
public interface IGeolocation : IGeolodationDependent
|
||||
|
|
|
@ -5,7 +5,7 @@ using System.Threading.Tasks;
|
|||
using TINK.Model.Device;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace TINK.Model.Services.Geolocation
|
||||
namespace TINK.Services.Geolocation
|
||||
{
|
||||
public class LastKnownGeolocationService : IGeolocation
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ namespace TINK.Model.Services.Geolocation
|
|||
return location;
|
||||
}
|
||||
|
||||
return await new GeolocationService(Dependent).GetAsync(cancelationToken, timeStamp);
|
||||
return await new GeolocationAccuracyMediumService(Dependent).GetAsync(cancelationToken, timeStamp);
|
||||
}
|
||||
|
||||
/// <summary> If true location data returned is simulated.</summary>
|
||||
|
|
|
@ -4,7 +4,7 @@ using System.Threading.Tasks;
|
|||
using TINK.Model.Device;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace TINK.Model.Services.Geolocation
|
||||
namespace TINK.Services.Geolocation
|
||||
{
|
||||
public class SimulatedGeolocationService : IGeolocation
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue