Version 3.0.337

This commit is contained in:
Anja Müller-Meißner 2022-08-30 15:42:25 +02:00
parent fd0e63cf10
commit 573fe77e12
2336 changed files with 33688 additions and 86082 deletions

View file

@ -1,4 +1,4 @@
using TINK.Model.Bike;
using TINK.Model.Bikes;
namespace TINK.Services.BluetoothLock
{

View file

@ -1,11 +1,11 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TINK.Model.Bike;
using TINK.Model.Bike.BluetoothLock;
using TINK.Services.BluetoothLock.Tdo;
using TINK.Model.Bikes;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
using TINK.Model.State;
using System;
using TINK.Services.BluetoothLock.Tdo;
namespace TINK.Services.BluetoothLock
{
@ -35,17 +35,18 @@ namespace TINK.Services.BluetoothLock
public void UpdateSimulation(BikeCollection bikes)
{
var locksInfo = new List<LockInfoTdo> ();
var locksInfo = new List<LockInfoTdo>();
// Add and process locks info object
foreach (var bikeInfo in bikes.OfType<BikeInfo>())
foreach (var bikeInfo in bikes.OfType<Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo>())
{
var lockInfo = bikeInfo.LockInfo;
switch (bikeInfo.State.Value)
{
case InUseStateEnum.Disposable:
switch (lockInfo.State )
case InUseStateEnum.FeedbackPending: // State feedback pending does not exist for bluetooth locks but maches from bluetooth perspective state disposable.
switch (lockInfo.State)
{
case LockingState.Open:
case LockingState.UnknownDisconnected:

View file

@ -1,10 +1,10 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using TINK.Model.Bike;
using TINK.Model.Bike.BluetoothLock;
using TINK.Model.Bikes;
using TINK.Model.Bikes.BikeInfoNS.BluetoothLock;
using TINK.Services.BluetoothLock.Tdo;
using System;
namespace TINK.Services.BluetoothLock
{
@ -38,7 +38,7 @@ namespace TINK.Services.BluetoothLock
var locksInfo = new List<LockInfoTdo>();
// Add and process locks info object
foreach (var bikeInfo in bikes.OfType<BikeInfo>())
foreach (var bikeInfo in bikes.OfType<Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo>())
{
locksInfo.Add(new LockInfoTdo.Builder { Id = bikeInfo.LockInfo.Id, State = null }.Build());
}

View file

@ -9,25 +9,25 @@ namespace TINK.Services.BluetoothLock
public class LocksServicesContainerMutable : IEnumerable<string>
{
/// <summary> Manages the different types of LocksService objects.</summary>
private ServicesContainerMutable<ILocksService> LocksServices { get; }
private ServicesContainerMutableT<ILocksService> LocksServices { get; }
/// <summary> Holds the name of the default locks service to use. </summary>
public static string DefaultLocksservice => typeof(BLE.LockItByScanServicePolling).FullName;
/// <summary></summary>
/// <param name="activeLockService">Name of active lock service implementation to use.</param>
/// <param name="activeLockService">Name of active lock service implementation to use.</param>
/// <param name="locksServices">Null for production (set of lock service implentations and some fake implementation will created) hash set of services for testing purposes. </param>
public LocksServicesContainerMutable(
string activeLockService,
HashSet<ILocksService> locksServices)
{
LocksServices = new ServicesContainerMutable<ILocksService>(
LocksServices = new ServicesContainerMutableT<ILocksService>(
locksServices,
activeLockService);
}
/// <summary> Active locks service.</summary>
public ILocksService Active => LocksServices.Active;
public ILocksService Active => LocksServices.Active;
/// <summary> Sets a lock service as active locks service by name. </summary>
/// <param name="active">Name of the new locks service.</param>

View file

@ -1,8 +1,8 @@
using Serilog;
using System;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using TINK.Model.Connector;
using Serilog;
using TINK.Model.Connector.Updater;
using TINK.Model.Device;
using TINK.Repository;
using TINK.Repository.Request;
@ -31,25 +31,24 @@ namespace TINK.Model.Services.CopriApi
/// <summary> Constructs copri provider object to connet to https using a cache objet. </summary>
/// <param name="copriHost"></param>
/// <param name="appContextInfo">Provides app related info (app name and version, merchantid) to pass to COPRI.</param>
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
/// <param name="sessionCookie">Cookie of user if a user is logged in, false otherwise.</param>
/// <param name="expiresAfter">Timespan which holds value after which cache expires.</param>
/// <param name="isExpired">Delegate which returns if cache conted is out of date or not.</param>
public CopriProviderHttps(
Uri copriHost,
string merchantId,
AppContextInfo appContextInfo,
string uiIsoLangugageName,
string sessionCookie = null,
TimeSpan? expiresAfter = null,
ICopriCache cacheServer = null,
ICopriServer httpsServer = null)
{
CacheServer = cacheServer ?? new CopriCallsMonkeyStore(merchantId, sessionCookie, expiresAfter);
HttpsServer = httpsServer ?? new CopriCallsHttps(copriHost, appContextInfo, sessionCookie);
CacheServer = cacheServer ?? new CopriCallsMonkeyStore(merchantId, uiIsoLangugageName, sessionCookie, expiresAfter);
HttpsServer = httpsServer ?? new CopriCallsHttps(copriHost, appContextInfo, uiIsoLangugageName, sessionCookie);
}
/// <summary>Gets bikes available.</summary>
/// <param name="p_strMerchantId">Id of the merchant.</param>
/// <param name="sessionCookie">Auto cookie of user if user is logged in.</param>
/// <returns>Response holding list of bikes.</returns>
public async Task<Result<BikesAvailableResponse>> GetBikesAvailable(bool fromCache = false)
{
@ -69,9 +68,8 @@ namespace TINK.Model.Services.CopriApi
var bikesAvailableResponse = await HttpsServer.GetBikesAvailableAsync();
return new Result<BikesAvailableResponse>(
typeof(CopriCallsHttps),
bikesAvailableResponse.GetIsResponseOk("Abfrage der verfügbaren Räder fehlgeschlagen."),
bikesAvailableResponse.GetIsResponseOk(MultilingualResources.AppResources.ErrorBikesAvailableResponseNotOk),
bikesAvailableResponse.GetGeneralData());
}
catch (Exception exception)
{
@ -146,7 +144,7 @@ namespace TINK.Model.Services.CopriApi
// Return response from cache.
Log.ForContext<CopriProviderHttps>().Debug("An error occurred querrying stations. {Exception}.", exception);
var stationsResponse = await CacheServer.GetStationsAsync();
return new Result<StationsAvailableResponse>(typeof(CopriCallsMonkeyStore), stationsResponse, stationsResponse.GetGeneralData(), exception);
return new Result<StationsAvailableResponse>(typeof(CopriCallsMonkeyStore), stationsResponse, stationsResponse.GetGeneralData(), exception);
}
}
@ -239,10 +237,10 @@ namespace TINK.Model.Services.CopriApi
LocationDto location,
double batteryLevel)
=> await HttpsServer.UpdateLockingStateAsync(
bikeId,
bikeId,
state,
operatorUri,
location,
location,
batteryLevel);
/// <summary> Books a bike. </summary>
@ -257,14 +255,23 @@ namespace TINK.Model.Services.CopriApi
/// <param name="bikeId">Id of the bike to book.</param>
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
/// <returns>Response on booking request.</returns>
public async Task<ReservationBookingResponse> BookAndStartOpeningAsync(
public async Task<ReservationBookingResponse> BookAvailableAndStartOpeningAsync(
string bikeId,
Uri operatorUri)
=> await HttpsServer.BookAndStartOpeningAsync(bikeId, operatorUri);
=> await HttpsServer.BookAvailableAndStartOpeningAsync(bikeId, operatorUri);
/// <summary> Books a bike and starts opening bike. </summary>
/// <param name="bikeId">Id of the bike to book.</param>
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
/// <returns>Response on booking request.</returns>
public async Task<ReservationBookingResponse> BookReservedAndStartOpeningAsync(
string bikeId,
Uri operatorUri)
=> await HttpsServer.BookReservedAndStartOpeningAsync(bikeId, operatorUri);
public async Task<DoReturnResponse> DoReturn(
string bikeId,
string bikeId,
LocationDto location,
ISmartDevice smartDevice,
Uri operatorUri)
@ -287,8 +294,8 @@ namespace TINK.Model.Services.CopriApi
/// <param name="bikeId">Id of the bike to submit feedback for.</param>
/// <param name="message">General purpose message or error description.</param>
/// <param name="isBikeBroken">True if bike is broken.</param>
public async Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, string message, bool isBikeBroken, Uri opertorUri) =>
await HttpsServer.DoSubmitFeedback(bikeId, message, isBikeBroken, opertorUri);
public async Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, int? currentChargeBars, string message, bool isBikeBroken, Uri opertorUri) =>
await HttpsServer.DoSubmitFeedback(bikeId, currentChargeBars, message, isBikeBroken, opertorUri);
/// <summary> Submits mini survey to copri server. </summary>
/// <param name="answers">Collection of answers.</param>

View file

@ -21,14 +21,16 @@ namespace TINK.Model.Services.CopriApi
/// <summary> Constructs object which Object which manages stored copri answers in a thread save way. </summary>
/// <param name="merchantId">Id of the merchant TINK-App.</param>
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
public CopriProviderMonkeyStore(
string merchantId,
string uiIsoLangugageName,
string sessionCookie)
{
monkeyStore = new CopriCallsMonkeyStore(merchantId, sessionCookie);
monkeyStore = new CopriCallsMonkeyStore(merchantId, uiIsoLangugageName, sessionCookie);
}
/// <summary> Gets the merchant id.</summary>
/// <summary> Gets the merchant id.</summary>
public string MerchantId => monkeyStore.MerchantId;
public Task<ReservationBookingResponse> DoReserveAsync(string bikeId, Uri operatorUri)
@ -47,16 +49,16 @@ namespace TINK.Model.Services.CopriApi
public async Task<ReservationBookingResponse> UpdateLockingStateAsync(
string bikeId,
string bikeId,
lock_state state,
Uri operatorUri,
LocationDto geolocation,
LocationDto geolocation,
double batteryLevel)
=> await monkeyStore.UpdateLockingStateAsync(
bikeId,
bikeId,
state,
operatorUri,
geolocation,
geolocation,
batteryLevel);
public async Task<ReservationBookingResponse> DoBookAsync(string bikeId, Guid guid, double batteryPercentage, Uri operatorUri)
@ -64,17 +66,22 @@ namespace TINK.Model.Services.CopriApi
return await monkeyStore.DoBookAsync(bikeId, guid, batteryPercentage, operatorUri);
}
public async Task<ReservationBookingResponse> BookAndStartOpeningAsync(
public async Task<ReservationBookingResponse> BookAvailableAndStartOpeningAsync(
string bikeId,
Uri operatorUri)
=> await monkeyStore.BookAndStartOpeningAsync(bikeId, operatorUri);
=> await monkeyStore.BookAvailableAndStartOpeningAsync(bikeId, operatorUri);
public async Task<ReservationBookingResponse> BookReservedAndStartOpeningAsync(
string bikeId,
Uri operatorUri)
=> await monkeyStore.BookReservedAndStartOpeningAsync(bikeId, operatorUri);
public async Task<DoReturnResponse> DoReturn(
string bikeId,
string bikeId,
LocationDto geolocation,
ISmartDevice smartDevice,
Uri operatorUri)
=> await monkeyStore.DoReturn(bikeId, geolocation, smartDevice, operatorUri);
=> await monkeyStore.DoReturn(bikeId, geolocation, smartDevice, operatorUri);
public async Task<DoReturnResponse> ReturnAndStartClosingAsync(
string bikeId,
@ -82,7 +89,7 @@ namespace TINK.Model.Services.CopriApi
Uri operatorUri)
=> await monkeyStore.ReturnAndStartClosingAsync(bikeId, smartDevice, operatorUri);
public Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, string messge, bool bIsBikeBroke, Uri operatorUri)
public Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, int? currentChargeBars, string messge, bool bIsBikeBroke, Uri operatorUri)
=> throw new NotImplementedException();
/// <summary> Submits mini survey to copri server. </summary>

View file

@ -0,0 +1,8 @@

namespace TINK.Services.CopriApi.Exception
{
public class BikeStillInStationException : System.Exception
{
public BikeStillInStationException(string message) : base(message) { }
}
}

View file

@ -12,7 +12,7 @@ namespace TINK.Services.CopriApi
public GeneralData(
IMapSpan initialMapSpan,
string merachantMessage,
string merachantMessage,
Version apiVersion,
ResourceUrls resourceUrls)
{

View file

@ -1,15 +1,17 @@
using Serilog;
using System;
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Serilog;
using TINK.Model;
using TINK.Model.Bikes.Bike.CopriLock;
using TINK.Model.Bikes.BikeInfoNS.CopriLock;
using TINK.Model.Connector;
using TINK.Model.Connector.Updater;
using TINK.Model.Device;
using TINK.Model.Services.CopriApi;
using TINK.Repository;
using TINK.Repository.Response;
using TINK.Services.CopriApi.Exception;
namespace TINK.Services.CopriApi
{
@ -18,11 +20,9 @@ namespace TINK.Services.CopriApi
/// <summary> Timeout for open/ close operations.</summary>
private const int OPEN_CLOSE_TIMEOUT_MS = 50000;
/// <summary>
/// Returns a bike and closes the lock.
/// </summary>
/// <summary> Opens lock.</summary>
/// <param name="corpiServer"> Instance to communicate with backend.</param>
/// <param name="bike">Bike to open.</param>
/// <param name="bike">Bike object holding id of bike to open. Lock state of object is updated after open request.</param>
public static async Task OpenAync(
this ICopriServerBase corpiServer,
IBikeInfoMutable bike)
@ -64,7 +64,7 @@ namespace TINK.Services.CopriApi
/// <param name="bike">Bike to book and open.</param>
/// <param name="mailAddress">Mail address of user which books bike.</param>
public static async Task BookAndOpenAync(
this ICopriServerBase corpiServer,
this ICopriServerBase corpiServer,
IBikeInfoMutable bike,
string mailAddress)
{
@ -73,38 +73,46 @@ namespace TINK.Services.CopriApi
throw new ArgumentNullException(nameof(bike), "Can not book bike and open lock. No bike object available.");
}
if (!(corpiServer is ICachedCopriServer cachedServer))
if (!(corpiServer is ICachedCopriServer cachedServer))
throw new ArgumentNullException(nameof(corpiServer));
// Send command to open lock
var response = (await corpiServer.BookAndStartOpeningAsync(bike.Id, bike.OperatorUri)).GetIsBookingResponseOk(bike.Id);
// Upate booking state
bike.Load(
response,
mailAddress,
Model.Bikes.Bike.BC.NotifyPropertyChangedLevel.None);
var response = bike.State.Value == Model.State.InUseStateEnum.Disposable
? (await corpiServer.BookAvailableAndStartOpeningAsync(bike.Id, bike.OperatorUri)).GetIsBookingResponseOk(bike.Id)
: (await corpiServer.BookReservedAndStartOpeningAsync(bike.Id, bike.OperatorUri)).GetIsBookingResponseOk(bike.Id);
// Upated locking state.
var lockingState = await cachedServer.GetLockStateAsync(bike.Id);
var lockingState = await cachedServer.GetOccupiedBikeLockStateAsync(bike.Id);
var watch = new Stopwatch();
watch.Start();
while (lockingState!= LockingState.Open
&& lockingState != LockingState.UnknownDisconnected
while (lockingState.HasValue /* if null bike is no more occupied*/ &&
lockingState.Value != LockingState.Open
&& watch.Elapsed < TimeSpan.FromMilliseconds(OPEN_CLOSE_TIMEOUT_MS))
{
// Delay a litte to reduce load on backend.
await Task.Delay(3000);
lockingState = await cachedServer.GetLockStateAsync(bike.Id);
Log.Information($"Current lock state is {lockingState}.");
lockingState = await cachedServer.GetOccupiedBikeLockStateAsync(bike.Id);
Log.Debug($"Current lock state of bike {bike.Id} is {(lockingState.HasValue ? lockingState.Value.ToString() : "-")}.");
}
// Check if bike is still occupied.
if (lockingState == null)
{
// User did not take bike out of the station
throw new BikeStillInStationException("Booking was cancelled because bike is still in station.");
}
// Upate booking state.
bike.Load(
response,
mailAddress,
Model.Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel.None);
// Update locking state.
bike.LockInfo.State = lockingState;
bike.LockInfo.State = lockingState.Value;
}
/// <summary>
@ -161,10 +169,10 @@ namespace TINK.Services.CopriApi
// Send command to open lock
DoReturnResponse response =
await corpiServer.ReturnAndStartClosingAsync(bike.Id, smartDevice, bike.OperatorUri);
await corpiServer.ReturnAndStartClosingAsync(bike.Id, smartDevice, bike.OperatorUri);
// Upate booking state
bike.Load(Model.Bikes.Bike.BC.NotifyPropertyChangedLevel.None);
bike.Load(Model.Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel.None);
var lockingState = await cachedServer.GetLockStateAsync(bike.Id);
@ -195,15 +203,42 @@ namespace TINK.Services.CopriApi
/// <param name="bikeId">Bike id to query lock state for.</param>
/// <returns>Locking state</returns>
private static async Task<LockingState> GetLockStateAsync(
this ICachedCopriServer corpiServer,
this ICachedCopriServer corpiServer,
string bikeId)
{
var bike = (await corpiServer.GetBikesOccupied(false))?.Response.bikes_occupied?.Values?.FirstOrDefault(x => x.bike == bikeId);
// Querry reserved or booked bikes first for performance reasons.
var bikeReservedOrBooked = (await corpiServer.GetBikesOccupied(false))?.Response.bikes_occupied?.Values?.FirstOrDefault(x => x.bike == bikeId);
if (bikeReservedOrBooked != null)
{
return bikeReservedOrBooked.GetCopriLockingState();
}
if (bike == null)
return LockingState.UnknownDisconnected;
var bikeAvailable = (await corpiServer.GetBikesAvailable(false))?.Response.bikes?.Values?.FirstOrDefault(x => x.bike == bikeId);
if (bikeAvailable != null)
{
return bikeAvailable.GetCopriLockingState();
}
return bike.GetCopriLockingState();
return LockingState.UnknownDisconnected;
}
/// <summary>
/// Queries the locking state of a occupied bike from copri.
/// </summary>
/// <param name="corpiServer">Service to use.</param>
/// <param name="bikeId">Bike id to query lock state for.</param>
/// <returns>Locking state if bike is still occupied, null otherwise.</returns>
private static async Task<LockingState?> GetOccupiedBikeLockStateAsync(
this ICachedCopriServer corpiServer,
string bikeId)
{
var bikeReservedOrBooked = (await corpiServer.GetBikesOccupied(false))?.Response.bikes_occupied?.Values?.FirstOrDefault(x => x.bike == bikeId);
if (bikeReservedOrBooked != null)
{
return bikeReservedOrBooked.GetCopriLockingState();
}
return null;
}
}
}

View file

@ -12,10 +12,10 @@ namespace TINK.Model.Services.CopriApi
/// <param name="response">Requested data (bikes, station).</param>
/// <param name="generalData">General data (common to all respones).</param>
public Result(
Type source,
T response,
Type source,
T response,
GeneralData generalData,
Exception exception = null)
Exception exception = null)
{
Source = source ?? throw new ArgumentException(nameof(source));
Response = response ?? throw new ArgumentException(nameof(response));
@ -27,7 +27,7 @@ namespace TINK.Model.Services.CopriApi
public T Response { get; }
/// <summary> Holds the general purpose data (common to all responses).</summary>
public GeneralData GeneralData { get; }
public GeneralData GeneralData { get; }
/// <summary> Specifies the source (type of provider) of the copri response.</summary>
public Type Source { get; }

View file

@ -13,14 +13,5 @@ namespace TINK.Services.CopriApi.ServerUris
public static bool GetIsCopri(this string hostName)
=> new Uri(CopriServerUriList.TINK_DEVEL).Host == hostName
|| new Uri(CopriServerUriList.TINK_LIVE).Host == hostName;
/// <summary> Get folder name depending on host name. </summary>
/// <param name="hostName">Host name.</param>
/// <returns>Folder name.</returns>
public static string GetAppFolderName(this string hostName)
=> hostName.GetIsCopri()
? "tinkapp" /* resource tree is more complex for TINK/ konrad*/
: "app";
}
}

View file

@ -1,7 +1,7 @@
using Newtonsoft.Json;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
namespace TINK.Model.Services.CopriApi.ServerUris
{
@ -26,7 +26,7 @@ namespace TINK.Model.Services.CopriApi.ServerUris
public const string SHAREE_LIVE = @"https://shareeapp-primary.copri.eu/APIjsonserver";
/// <summary>Constructs default uri list.</summary>
public CopriServerUriList(Uri activeUri = null) : this (
public CopriServerUriList(Uri activeUri = null) : this(
new List<Uri>
{
new Uri(SHAREE_LIVE),
@ -41,7 +41,7 @@ namespace TINK.Model.Services.CopriApi.ServerUris
/// <summary> Constructs uris object. </summary>
/// <param name="p_oSource">Object to copy from.</param>
public CopriServerUriList(CopriServerUriList p_oSource) : this(
p_oSource.Uris.ToArray(),
p_oSource.Uris.ToArray(),
p_oSource.ActiveUri)
{
}
@ -51,7 +51,7 @@ namespace TINK.Model.Services.CopriApi.ServerUris
/// <param name="p_oActiveUri">Zero based index of active uri.</param>
/// <param name="p_oDevelUri">Uri of the development server.</param>
public CopriServerUriList(
Uri[] uris,
Uri[] uris,
Uri p_oActiveUri)
{
if (uris == null || uris.Length < 1)
@ -61,7 +61,7 @@ namespace TINK.Model.Services.CopriApi.ServerUris
if (!uris.Contains(p_oActiveUri))
{
throw new ArgumentException($"Active uri {p_oActiveUri} not contained in ({string.Join("; ", uris.Select(x => x.AbsoluteUri))}).");
throw new ArgumentException($"Active uri {p_oActiveUri} not contained in ({string.Join("; ", uris.Select(x => x.AbsoluteUri))}).");
}
Uris = new List<Uri>(uris);
@ -81,7 +81,7 @@ namespace TINK.Model.Services.CopriApi.ServerUris
/// <summary> Gets the known uris. </summary>
[JsonProperty]
public IList<Uri> Uris { get ; }
public IList<Uri> Uris { get; }
/// <summary> Gets the default uri which is active after first installation. </summary>
public static Uri DefaultActiveUri

View file

@ -1,4 +1,4 @@
using TINK.Model.Bike;
using TINK.Model.Bikes;
using TINK.Model.Station;
namespace TINK.Model.Services.CopriApi

View file

@ -1,6 +1,6 @@
using TINK.Model.Device;
using Xamarin.Essentials;
namespace TINK.Services.Geolocation
{
public class GeolocationAccuracyBestService : GeolocationService

View file

@ -7,7 +7,7 @@ namespace TINK.Services.Geolocation
{
public GeolocationAccuracyMediumService(IGeolodationDependent dependent) : base(
dependent, GeolocationAccuracy.Medium)
{
{
}
}
}

View file

@ -1,7 +1,7 @@
using Serilog;
using System;
using System;
using System.Threading;
using System.Threading.Tasks;
using Serilog;
using TINK.Model.Device;
using Xamarin.Essentials;
@ -13,7 +13,7 @@ namespace TINK.Services.Geolocation
private const int GEOLOCATIONREQUEST_TIMEOUT_MS = 5000;
private IGeolodationDependent Dependent { get; }
private GeolocationAccuracy Accuracy { get; }
public GeolocationService(

View file

@ -1,7 +1,7 @@
using Serilog;
using System;
using System;
using System.Threading;
using System.Threading.Tasks;
using Serilog;
using TINK.Model.Device;
using Xamarin.Essentials;
@ -53,7 +53,7 @@ namespace TINK.Services.Geolocation
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;
}

View file

@ -0,0 +1,47 @@
using System;
using System.Collections.Concurrent;
using Serilog.Core;
using Serilog.Events;
namespace TINK.Services.Logging
{
public class MemoryStackSink : ILogEventSink
{
private readonly IFormatProvider _formatProvider;
private static ConcurrentStack<string> _MessageStack = new ConcurrentStack<string>();
/// <summary>
/// Reads all messages an clears memory stack.
/// </summary>
/// <returns>Array of messages.</returns>
public static string[] PopAllMessages()
{
int countOfMessages = _MessageStack.Count;
if (countOfMessages <= 0)
return new string[0];
string[] messages = new string[countOfMessages];
if (_MessageStack.TryPopRange(messages) <= 0)
return new string[0];
return messages;
}
/// <summary>
/// Clears the message stack.
/// </summary>
public static void ClearMessages() => _MessageStack.Clear();
public MemoryStackSink(IFormatProvider formatProvider)
{
_formatProvider = formatProvider;
}
public void Emit(LogEvent logEvent)
{
var message = logEvent.RenderMessage(_formatProvider);
_MessageStack.Push(DateTimeOffset.Now.ToString() + " " + message);
}
}
}

View file

@ -0,0 +1,16 @@
using System;
using Serilog;
using Serilog.Configuration;
namespace TINK.Services.Logging
{
public static class MemoryStackSinkExtensions
{
public static LoggerConfiguration MemoryQueueSink(
this LoggerSinkConfiguration loggerConfiguration,
IFormatProvider formatProvider = null)
{
return loggerConfiguration.Sink(new MemoryStackSink(formatProvider));
}
}
}

View file

@ -18,7 +18,7 @@ namespace TINK.Services.Permissions.Essentials
return Status.Granted;
}
if (status == XamPermissionStatus.Denied
if (status == XamPermissionStatus.Denied
&& DeviceInfo.Platform == DevicePlatform.iOS)
{
// Prompt the user to turn on in settings

View file

@ -6,11 +6,9 @@ using System.Linq;
namespace TINK.Services
{
/// <summary> Container of service objects (locks , geolocation, ...) where one service is active. </summary>
/// <remarks> All service objects must be of different type. </remarks>
public class ServicesContainerMutable<T>: IEnumerable<T>, INotifyPropertyChanged, IServicesContainer<T>
public class ServicesContainerMutable : IEnumerable<string>, INotifyPropertyChanged, IServicesContainer<string>
{
private readonly Dictionary<string, T> serviceDict;
private readonly Dictionary<string, string> serviceDict;
public event PropertyChangedEventHandler PropertyChanged;
@ -18,21 +16,21 @@ namespace TINK.Services
/// <param name="services">Fixed list of service- objects .</param>
/// <param name="activeName">LocksService name which is activated on startup of app.</param>
public ServicesContainerMutable(
IEnumerable<T> services,
string activeName)
IEnumerable<string> services,
string activeName)
{
serviceDict = services.Distinct().ToDictionary(x => x.GetType().FullName);
serviceDict = services.Distinct().ToDictionary(x => x);
if (!serviceDict.ContainsKey(activeName))
{
throw new ArgumentException($"Can not instantiate {typeof(T).Name}- object. Active lock service {activeName} must be contained in [{String.Join(",", serviceDict)}].");
throw new ArgumentException($"Can not instantiate {typeof(string).Name}- object. Active lock service {activeName} must be contained in [{String.Join(",", serviceDict)}].");
}
Active = serviceDict[activeName];
}
/// <summary> Active locks service.</summary>
public T Active { get; private set; }
public string Active { get; private set; }
/// <summary> Sets a lock service as active locks service by name. </summary>
/// <param name="active">Name of the new locks service.</param>
@ -48,7 +46,7 @@ namespace TINK.Services
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Active)));
}
public IEnumerator<T> GetEnumerator()
public IEnumerator<string> GetEnumerator()
=> serviceDict.Values.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()

View file

@ -0,0 +1,57 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace TINK.Services
{
/// <summary> Container of service objects (locks , geolocation, ...) where one service is active. </summary>
/// <remarks> All service objects must be of different type. </remarks>
public class ServicesContainerMutableT<T> : IEnumerable<T>, INotifyPropertyChanged, IServicesContainer<T>
{
private readonly Dictionary<string, T> serviceDict;
public event PropertyChangedEventHandler PropertyChanged;
/// <summary> Constructs object on startup of app.</summary>
/// <param name="services">Fixed list of service- objects .</param>
/// <param name="activeName">LocksService name which is activated on startup of app.</param>
public ServicesContainerMutableT(
IEnumerable<T> services,
string activeName)
{
serviceDict = services.Distinct().ToDictionary(x => x.GetType().FullName);
if (!serviceDict.ContainsKey(activeName))
{
throw new ArgumentException($"Can not instantiate {typeof(T).Name}- object. Active lock service {activeName} must be contained in [{String.Join(",", serviceDict)}].");
}
Active = serviceDict[activeName];
}
/// <summary> Active locks service.</summary>
public T Active { get; private set; }
/// <summary> Sets a lock service as active locks service by name. </summary>
/// <param name="active">Name of the new locks service.</param>
public void SetActive(string active)
{
if (!serviceDict.ContainsKey(active))
{
throw new ArgumentException($"Can not set active lock service {active}. Service must be contained in [{String.Join(",", serviceDict)}].");
}
Active = serviceDict[active];
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Active)));
}
public IEnumerator<T> GetEnumerator()
=> serviceDict.Values.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
=> serviceDict.Values.GetEnumerator();
}
}

View file

@ -0,0 +1,18 @@

namespace TINK.Services.ThemeNS
{
/// <summary>
/// Set of available app themes
/// </summary>
public enum ThemeSet
{
ShareeBike,
Konrad,
LastenradBayern
}
public interface ITheme
{
void SetActiveTheme(string themeName);
}
}

View file

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace TINK.Services.ThemeNS
{
/// <summary>
/// Manges themeing functionalty.
/// Objects ResourceDictionary, Themes.Konrad, ... need Xamarin.Forms framework to be initialized which might break tests.
/// </summary>
public class Theme : ITheme
{
private ICollection<ResourceDictionary> _MergedDictionaries;
public Theme(ICollection<ResourceDictionary> mergedDictionaries)
{
_MergedDictionaries = mergedDictionaries ?? throw new ArgumentNullException(nameof(mergedDictionaries));
}
/// <summary>
/// Sets active theme.
/// </summary>
/// <param name="themeName">Name of the new active theme.</param>
public void SetActiveTheme(string themeName)
{
if (!Enum.TryParse(themeName, false, out ThemeSet theme))
return;
if (_MergedDictionaries == null)
return;
_MergedDictionaries.Clear();
switch (theme)
{
case ThemeSet.Konrad:
_MergedDictionaries.Add(new Themes.Konrad());
break;
case ThemeSet.LastenradBayern:
_MergedDictionaries.Add(new Themes.LastenradBayern());
break;
default:
_MergedDictionaries.Add(new Themes.ShareeBike());
break;
}
}
}
}