2021-05-13 20:03:07 +02:00
using System ;
using System.Collections ;
using System.Collections.Generic ;
using System.Linq ;
namespace TINK.Services.BluetoothLock
{
2022-09-06 16:08:19 +02:00
/// <summary> Manages Locks services and related configuration parameter. </summary>
public class LocksServicesContainerMutable : IEnumerable < string >
{
/// <summary> Manages the different types of LocksService objects.</summary>
private ServicesContainerMutableT < ILocksService > LocksServices { get ; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds the name of the default locks service to use. </summary>
public static string DefaultLocksservice = > typeof ( BLE . LockItByScanServicePolling ) . FullName ;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary></summary>
/// <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 ServicesContainerMutableT < ILocksService > (
locksServices ,
activeLockService ) ;
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Active locks service.</summary>
public ILocksService Active = > LocksServices . Active ;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <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 ) = > LocksServices . SetActive ( active ) ;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
IEnumerator < string > IEnumerable < string > . GetEnumerator ( )
= > LocksServices . Select ( x = > x . GetType ( ) . FullName ) . GetEnumerator ( ) ;
IEnumerator IEnumerable . GetEnumerator ( )
= > LocksServices . GetEnumerator ( ) ;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
public void SetTimeOut ( TimeSpan connectTimeout )
{
foreach ( var locksService in LocksServices )
{
locksService . TimeOut = new TimeOutProvider ( new List < TimeSpan > { connectTimeout } ) ;
}
}
}
2021-05-13 20:03:07 +02:00
}