mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-06-22 22:07:28 +02:00
Initial version.
This commit is contained in:
parent
193aaa1a56
commit
b72c67a53e
228 changed files with 25924 additions and 0 deletions
151
TINKLib/Model/Bikes/Bike/BluetoothLock/BikeInfo.cs
Normal file
151
TINKLib/Model/Bikes/Bike/BluetoothLock/BikeInfo.cs
Normal file
|
@ -0,0 +1,151 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TINK.Model.Bikes.Bike;
|
||||
using TINK.Model.State;
|
||||
|
||||
namespace TINK.Model.Bike.BluetoothLock
|
||||
{
|
||||
public class BikeInfo : BC.BikeInfo, IBikeInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs a bike info object for a available bike.
|
||||
/// </summary>
|
||||
/// <param name="bikeId">Unique id of bike.</param>
|
||||
/// <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>
|
||||
/// <param name="wheelType">Trike, two wheels, mono, ....</param>
|
||||
public BikeInfo(
|
||||
int bikeId,
|
||||
int lockId,
|
||||
Guid lockGuid,
|
||||
int? currentStationId,
|
||||
Uri operatorUri = null,
|
||||
TariffDescription tariffDescription = null,
|
||||
bool? isDemo = DEFAULTVALUEISDEMO,
|
||||
IEnumerable<string> group = null,
|
||||
WheelType? wheelType = null,
|
||||
TypeOfBike? typeOfBike = null,
|
||||
string description = null) : base(
|
||||
new StateInfo(),
|
||||
bikeId,
|
||||
isDemo,
|
||||
group,
|
||||
wheelType,
|
||||
typeOfBike,
|
||||
description,
|
||||
currentStationId,
|
||||
operatorUri,
|
||||
tariffDescription)
|
||||
{
|
||||
LockInfo = new LockInfo.Builder { Id = lockId, Guid = lockGuid }.Build();
|
||||
}
|
||||
|
||||
/// <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="id">Unique id of bike.</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>
|
||||
/// <param name="p_oDateTimeNowProvider">Date time provider to calculate reaining time.</param>
|
||||
/// <param name="wheelType"></param>
|
||||
public BikeInfo(
|
||||
int id,
|
||||
int lockId,
|
||||
Guid lockGuid,
|
||||
byte[] userKey,
|
||||
byte[] adminKey,
|
||||
byte[] seed,
|
||||
DateTime requestedAt,
|
||||
string mailAddress,
|
||||
int? currentStationId,
|
||||
Uri operatorUri,
|
||||
TariffDescription tariffDescription,
|
||||
Func<DateTime> dateTimeProvider,
|
||||
bool? isDemo = DEFAULTVALUEISDEMO,
|
||||
IEnumerable<string> group = null,
|
||||
WheelType? wheelType = null,
|
||||
TypeOfBike? typeOfBike = null,
|
||||
string description = null) : base(
|
||||
new StateInfo(
|
||||
dateTimeProvider,
|
||||
requestedAt,
|
||||
mailAddress,
|
||||
""),
|
||||
id,
|
||||
isDemo,
|
||||
group,
|
||||
wheelType,
|
||||
typeOfBike,
|
||||
description,
|
||||
currentStationId,
|
||||
operatorUri,
|
||||
tariffDescription)
|
||||
{
|
||||
LockInfo = new LockInfo.Builder { Id = lockId, Guid = lockGuid, UserKey = userKey, AdminKey = adminKey, Seed = seed }.Build();
|
||||
}
|
||||
|
||||
/// <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(
|
||||
int id,
|
||||
int lockId,
|
||||
Guid lockGuid,
|
||||
byte[] userKey,
|
||||
byte[] adminKey,
|
||||
byte[] seed,
|
||||
DateTime bookedAt,
|
||||
string mailAddress,
|
||||
int? currentStationId,
|
||||
Uri operatorUri,
|
||||
TariffDescription tariffDescription = null,
|
||||
bool? isDemo = DEFAULTVALUEISDEMO,
|
||||
IEnumerable<string> group = null,
|
||||
WheelType? wheelType = null,
|
||||
TypeOfBike? typeOfBike = null,
|
||||
string description = null) : base(
|
||||
new StateInfo(
|
||||
bookedAt,
|
||||
mailAddress,
|
||||
""),
|
||||
id,
|
||||
isDemo,
|
||||
group,
|
||||
wheelType,
|
||||
typeOfBike,
|
||||
description,
|
||||
currentStationId,
|
||||
operatorUri,
|
||||
tariffDescription)
|
||||
{
|
||||
LockInfo = new LockInfo.Builder { Id = lockId, Guid = lockGuid, UserKey = userKey, AdminKey = adminKey, Seed = seed }.Build();
|
||||
}
|
||||
|
||||
public BikeInfo(BC.BikeInfo bikeInfo, LockInfo lockInfo) : base(
|
||||
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.");
|
||||
}
|
||||
|
||||
public LockInfo LockInfo { get; private set; }
|
||||
}
|
||||
}
|
36
TINKLib/Model/Bikes/Bike/BluetoothLock/BikeInfoMutable.cs
Normal file
36
TINKLib/Model/Bikes/Bike/BluetoothLock/BikeInfoMutable.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using TINK.Model.Bikes.Bike;
|
||||
using TINK.Model.Bikes.Bike.BluetoothLock;
|
||||
|
||||
namespace TINK.Model.Bike.BluetoothLock
|
||||
{
|
||||
public class BikeInfoMutable : BC.BikeInfoMutable, IBikeInfoMutable
|
||||
{
|
||||
/// <summary> Constructs a bike object from source. </summary>
|
||||
public BikeInfoMutable(BikeInfo bike) : base(
|
||||
bike.Id,
|
||||
bike.IsDemo,
|
||||
bike.Group,
|
||||
bike.WheelType,
|
||||
bike.TypeOfBike,
|
||||
bike.Description,
|
||||
bike.CurrentStation,
|
||||
bike.OperatorUri,
|
||||
bike.TariffDescription,
|
||||
() => DateTime.Now,
|
||||
bike.State)
|
||||
{
|
||||
LockInfo = new LockInfoMutable(
|
||||
bike.LockInfo.Id,
|
||||
bike.LockInfo.Guid,
|
||||
bike.LockInfo.UserKey,
|
||||
bike.LockInfo.AdminKey,
|
||||
bike.LockInfo.Seed,
|
||||
bike.LockInfo.State);
|
||||
}
|
||||
|
||||
public LockInfoMutable LockInfo { get; }
|
||||
|
||||
ILockInfoMutable IBikeInfoMutable.LockInfo => LockInfo;
|
||||
}
|
||||
}
|
6
TINKLib/Model/Bikes/Bike/BluetoothLock/IBikeInfo.cs
Normal file
6
TINKLib/Model/Bikes/Bike/BluetoothLock/IBikeInfo.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace TINK.Model.Bike.BluetoothLock
|
||||
{
|
||||
public interface IBikeInfo : BC.IBikeInfo
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
namespace TINK.Model.Bikes.Bike.BluetoothLock
|
||||
{
|
||||
public interface IBikeInfoMutable : BC.IBikeInfoMutable
|
||||
{
|
||||
ILockInfoMutable LockInfo { get; }
|
||||
}
|
||||
}
|
24
TINKLib/Model/Bikes/Bike/BluetoothLock/ILockInfoMutable.cs
Normal file
24
TINKLib/Model/Bikes/Bike/BluetoothLock/ILockInfoMutable.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using TINK.Model.Bike.BluetoothLock;
|
||||
|
||||
namespace TINK.Model.Bikes.Bike.BluetoothLock
|
||||
{
|
||||
public interface ILockInfoMutable
|
||||
{
|
||||
/// <summary> Identification number of bluetooth lock.</summary>
|
||||
int Id { get; }
|
||||
|
||||
/// <summary> Gets the user key.</summary>
|
||||
byte[] UserKey { get; }
|
||||
|
||||
LockingState State { get; set; }
|
||||
|
||||
/// <summary> Holds the percentage of lock battery.</summary>
|
||||
double BatteryPercentage { get; set; }
|
||||
|
||||
/// <summary> Changes during runtime: Can be unknown when set from copri and chang to a valid value when set from lock.</summary>
|
||||
Guid Guid { get; set; }
|
||||
|
||||
byte[] Seed { get; }
|
||||
}
|
||||
}
|
54
TINKLib/Model/Bikes/Bike/BluetoothLock/LockInfoMutable.cs
Normal file
54
TINKLib/Model/Bikes/Bike/BluetoothLock/LockInfoMutable.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using TINK.Model.Bikes.Bike.BluetoothLock;
|
||||
|
||||
namespace TINK.Model.Bike.BluetoothLock
|
||||
{
|
||||
public class LockInfoMutable : ILockInfoMutable
|
||||
{
|
||||
/// <summary> Lock info object. </summary>
|
||||
private LockInfo LockInfo { get; set; }
|
||||
|
||||
/// <summary> Constructs a bluetooth lock info object. </summary>
|
||||
/// <param name="id">Id of lock must always been known when constructing an lock info object.</param>
|
||||
public LockInfoMutable(
|
||||
int id,
|
||||
Guid guid,
|
||||
byte[] userKey,
|
||||
byte[] adminKey,
|
||||
byte[] seed,
|
||||
LockingState state)
|
||||
{
|
||||
LockInfo = new LockInfo.Builder() { Id = id, Guid = guid, UserKey = userKey, AdminKey = adminKey, Seed = seed, State = state }.Build();
|
||||
}
|
||||
|
||||
public int Id => LockInfo.Id;
|
||||
|
||||
/// <summary> Changes during runtime: Can be unknown when set from copri and chang to a valid value when set from lock.</summary>
|
||||
public Guid Guid
|
||||
{
|
||||
get => LockInfo.Guid;
|
||||
set => LockInfo = new LockInfo.Builder(LockInfo) { Guid = value }.Build();
|
||||
}
|
||||
|
||||
public byte[] Seed => LockInfo.Seed;
|
||||
|
||||
public byte[] UserKey => LockInfo.UserKey;
|
||||
|
||||
public byte[] AdminKey => LockInfo.AdminKey;
|
||||
|
||||
public LockingState State
|
||||
{
|
||||
get => LockInfo.State;
|
||||
set => LockInfo = new LockInfo.Builder(LockInfo) { State = value }.Build();
|
||||
}
|
||||
|
||||
/// <summary> Holds the percentage of lock battery.</summary>
|
||||
public double BatteryPercentage { get; set; } = double.NaN;
|
||||
|
||||
/// <summary> Loads lock info object from values. </summary>
|
||||
public void Load(int id, Guid guid, byte[] seed, byte[] userKey, byte[] adminKey)
|
||||
{
|
||||
LockInfo = new LockInfo.Builder(LockInfo) { Id = id, Guid = guid, Seed = seed, UserKey = userKey, AdminKey = adminKey}.Build();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue