mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-12-23 07:36:31 +01:00
31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
|
|||
|
namespace TINK.Services.BluetoothLock
|
|||
|
{
|
|||
|
public class TimeOutProvider : ITimeOutProvider
|
|||
|
{
|
|||
|
/// <summary> Maximum factor applied on timeout factor. </summary>
|
|||
|
private readonly int MAXIMUMFACTORTIMEOUT = 4;
|
|||
|
|
|||
|
/// <summary> Default timeout to connect to bluetooth lock. </summary>
|
|||
|
public static int DEFAULT_BLUETOOTHCONNECT_TIMEOUTSECONDS = 5;
|
|||
|
|
|||
|
public TimeOutProvider(IEnumerable<TimeSpan> timeOuts = null)
|
|||
|
{
|
|||
|
TimeOuts = timeOuts != null && timeOuts.Count() > 0
|
|||
|
? timeOuts.ToList()
|
|||
|
: new List<TimeSpan> { new TimeSpan(0, 0, DEFAULT_BLUETOOTHCONNECT_TIMEOUTSECONDS) };
|
|||
|
}
|
|||
|
|
|||
|
private List<TimeSpan> TimeOuts { get; }
|
|||
|
|
|||
|
public TimeSpan MultiConnect => TimeOuts.ToArray()[0];
|
|||
|
|
|||
|
public TimeSpan GetSingleConnect(int countOfTry) => countOfTry < TimeOuts.Count
|
|||
|
? TimeOuts.ToArray()[countOfTry]
|
|||
|
: new TimeSpan(TimeOuts.ToArray()[0].Ticks * Math.Min(countOfTry, MAXIMUMFACTORTIMEOUT)) ;
|
|||
|
}
|
|||
|
}
|