sharee.bike-App/TINKLib/Model/Bikes/BikeInfoNS/BluetoothLock/BikeInfo.cs

159 lines
6.9 KiB
C#
Raw Normal View History

2021-05-13 20:03:07 +02:00
using System;
using System.Collections.Generic;
2022-08-30 15:42:25 +02:00
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
2021-05-13 20:03:07 +02:00
using TINK.Model.State;
2022-08-30 15:42:25 +02:00
namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
2021-05-13 20:03:07 +02:00
{
2022-08-30 15:42:25 +02:00
public class BikeInfo : Model.Bikes.BikeInfoNS.BC.BikeInfo, IBikeInfo
2021-05-13 20:03:07 +02:00
{
/// <summary>
/// Constructs a bike info object for a available bike.
/// </summary>
/// <param name="lockId">Id of the lock.</param>
/// <param name="lockGuid">GUID specifying the lock.</param>
/// <param name="currentStationId">Id of station where bike is located.</param>
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
/// <param name="tariffDescription">Hold tariff description of bike.</param>
public BikeInfo(
2022-08-30 15:42:25 +02:00
BikeNS.Bike bike,
Drive drive,
2021-05-13 20:03:07 +02:00
int lockId,
Guid lockGuid,
2021-06-26 20:57:55 +02:00
string currentStationId,
2021-05-13 20:03:07 +02:00
Uri operatorUri = null,
2022-06-17 14:17:58 +02:00
RentalDescription tariffDescription = null,
2021-05-13 20:03:07 +02:00
bool? isDemo = DEFAULTVALUEISDEMO,
2022-08-30 15:42:25 +02:00
IEnumerable<string> group = null) : base(
2021-05-13 20:03:07 +02:00
new StateInfo(),
2022-08-30 15:42:25 +02:00
bike != null
? new BikeNS.Bike(
bike.Id,
LockModel.ILockIt /* Ensure consistend lock model value */,
bike.WheelType,
bike.TypeOfBike,
bike.Description)
: throw new ArgumentNullException(nameof(bike)),
drive,
2021-05-13 20:03:07 +02:00
isDemo,
group,
currentStationId,
operatorUri,
tariffDescription)
{
2022-08-30 15:42:25 +02:00
LockInfo = new Model.Bikes.BikeInfoNS.BluetoothLock.LockInfo.Builder { Id = lockId, Guid = lockGuid }.Build();
2021-05-13 20:03:07 +02:00
}
/// <summary>
/// Constructs a bike info object for a requested bike.
/// </summary>
/// <param name="dateTimeProvider">Provider for current date time to calculate remainig time on demand for state of type reserved.</param>
/// <param name="lockId">Id of the lock.</param>
/// <param name="lockGuid">GUID specifying the lock.</param>
/// <param name="requestedAt">Date time when bike was requested</param>
/// <param name="mailAddress">Mail address of user which requested bike.</param>
/// <param name="currentStationId">Name of station where bike is located, null if bike is on the road.</param>
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
/// <param name="tariffDescription">Hold tariff description of bike.</param>
2022-08-30 15:42:25 +02:00
/// <param name="dateTimeProvider">Date time provider to calculate reaining time.</param>
2021-05-13 20:03:07 +02:00
public BikeInfo(
2022-08-30 15:42:25 +02:00
BikeNS.Bike bike,
Drive drive,
2021-05-13 20:03:07 +02:00
int lockId,
Guid lockGuid,
byte[] userKey,
byte[] adminKey,
byte[] seed,
DateTime requestedAt,
string mailAddress,
2021-06-26 20:57:55 +02:00
string currentStationId,
2021-05-13 20:03:07 +02:00
Uri operatorUri,
2022-06-17 14:17:58 +02:00
RentalDescription tariffDescription,
2021-05-13 20:03:07 +02:00
Func<DateTime> dateTimeProvider,
bool? isDemo = DEFAULTVALUEISDEMO,
2022-08-30 15:42:25 +02:00
IEnumerable<string> group = null) : base(
2021-05-13 20:03:07 +02:00
new StateInfo(
dateTimeProvider,
requestedAt,
mailAddress,
""),
2022-08-30 15:42:25 +02:00
bike != null
? new BikeNS.Bike(
bike.Id,
LockModel.ILockIt /* Ensure consistend lock model value */,
bike.WheelType,
bike.TypeOfBike,
bike.Description)
: throw new ArgumentNullException(nameof(bike)),
drive,
2021-05-13 20:03:07 +02:00
isDemo,
group,
currentStationId,
operatorUri,
tariffDescription)
{
2022-08-30 15:42:25 +02:00
LockInfo = new Model.Bikes.BikeInfoNS.BluetoothLock.LockInfo.Builder { Id = lockId, Guid = lockGuid, UserKey = userKey, AdminKey = adminKey, Seed = seed }.Build();
2021-05-13 20:03:07 +02:00
}
/// <summary>
/// Constructs a bike info object for a booked bike.
/// </summary>
/// <param name="id">Unique id of bike.</param>
/// <param name="lockId">Id of the lock.</param>
/// <param name="lockGuid">GUID specifying the lock.</param>
/// <param name="bookedAt">Date time when bike was booked</param>
/// <param name="mailAddress">Mail address of user which booked bike.</param>
/// <param name="currentStationId">Name of station where bike is located, null if bike is on the road.</param>
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
/// <param name="tariffDescription">Hold tariff description of bike.</param>
/// <param name="wheelType"></param>
public BikeInfo(
2022-08-30 15:42:25 +02:00
BikeNS.Bike bike,
Drive drive,
2021-05-13 20:03:07 +02:00
int lockId,
Guid lockGuid,
byte[] userKey,
byte[] adminKey,
byte[] seed,
DateTime bookedAt,
string mailAddress,
2021-06-26 20:57:55 +02:00
string currentStationId,
2021-05-13 20:03:07 +02:00
Uri operatorUri,
2022-06-17 14:17:58 +02:00
RentalDescription tariffDescription = null,
2021-05-13 20:03:07 +02:00
bool? isDemo = DEFAULTVALUEISDEMO,
2022-08-30 15:42:25 +02:00
IEnumerable<string> group = null) : base(
2021-05-13 20:03:07 +02:00
new StateInfo(
bookedAt,
mailAddress,
""),
2022-08-30 15:42:25 +02:00
bike != null
? new BikeNS.Bike(
bike.Id,
LockModel.ILockIt /* Ensure consistend lock model value */,
bike.WheelType,
bike.TypeOfBike,
bike.Description)
: throw new ArgumentNullException(),
drive,
2021-05-13 20:03:07 +02:00
isDemo,
group,
currentStationId,
operatorUri,
tariffDescription)
{
2022-08-30 15:42:25 +02:00
LockInfo = new Model.Bikes.BikeInfoNS.BluetoothLock.LockInfo.Builder { Id = lockId, Guid = lockGuid, UserKey = userKey, AdminKey = adminKey, Seed = seed }.Build();
2021-05-13 20:03:07 +02:00
}
2022-08-30 15:42:25 +02:00
public BikeInfo(Model.Bikes.BikeInfoNS.BC.BikeInfo bikeInfo, Model.Bikes.BikeInfoNS.BluetoothLock.LockInfo lockInfo) : base(
2021-05-13 20:03:07 +02:00
bikeInfo ?? throw new ArgumentException($"Can not copy-construct {typeof(BikeInfo).Name}-object. Source bike info must not be null."))
{
LockInfo = lockInfo
?? throw new ArgumentException($"Can not copy-construct {typeof(BikeInfo).Name}-object. Source lock object must not be null.");
}
2022-08-30 15:42:25 +02:00
public Model.Bikes.BikeInfoNS.BluetoothLock.LockInfo LockInfo { get; private set; }
2021-05-13 20:03:07 +02:00
}
}