mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-16 15:16:34 +01:00
65 lines
2.6 KiB
C#
65 lines
2.6 KiB
C#
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 System;
|
|
|
|
namespace TINK.Services.BluetoothLock
|
|
{
|
|
/// <summary>
|
|
/// Facke locks service implementation which simulates locks which are out of reach.
|
|
/// </summary>
|
|
public class LocksServiceOutOfReach : ILocksServiceFake
|
|
{
|
|
private IEnumerable<LockInfoTdo> LocksInfo { get; set; } = new List<LockInfoTdo>();
|
|
|
|
/// <summary> Holds timeout values for series of connecting attemps to a lock or multiple locks. </summary>
|
|
public ITimeOutProvider TimeOut { get; set; }
|
|
|
|
/// <summary> Connects to lock.</summary>
|
|
/// <param name="authInfo"> Info required to connect to lock.</param>
|
|
/// <param name="connectTimeout">Timeout for connect operation.</param>
|
|
public async Task<LockInfoTdo> ConnectAsync(LockInfoAuthTdo authInfo, TimeSpan connectTimeout)
|
|
{
|
|
return await Task.FromResult(new LockInfoTdo.Builder { Id = authInfo.Id, Guid = authInfo.Guid, State = null }.Build());
|
|
}
|
|
|
|
/// <summary> No info availalbe because no lock is in reach.</summary>
|
|
/// <param name="connectTimeout">Timeout for connect operation of a single lock.</param>
|
|
/// <returns>Empty collection.</returns>
|
|
public async Task<IEnumerable<LockInfoTdo>> GetLocksStateAsync(IEnumerable<LockInfoAuthTdo> locksInfo, TimeSpan connectTimeout) => await Task.FromResult(LocksInfo);
|
|
|
|
|
|
/// <summary> No changes required because lock state is unknown.</summary>
|
|
public void UpdateSimulation(BikeCollection bikes)
|
|
{
|
|
var locksInfo = new List<LockInfoTdo>();
|
|
|
|
// Add and process locks info object
|
|
foreach (var bikeInfo in bikes.OfType<BikeInfo>())
|
|
{
|
|
locksInfo.Add(new LockInfoTdo.Builder { Id = bikeInfo.LockInfo.Id, State = null }.Build());
|
|
}
|
|
|
|
LocksInfo = locksInfo;
|
|
}
|
|
|
|
/// <summary>Gets a lock by bike Id.</summary>
|
|
/// <param name="bikeId"></param>
|
|
/// <returns>Lock object</returns>
|
|
public ILockService this[int bikeId]
|
|
{
|
|
get
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <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);
|
|
}
|
|
}
|