Version 3.0.294

This commit is contained in:
Oliver Hauff 2022-04-25 22:15:15 +02:00
parent d92fb4a40f
commit 8f40f2c208
133 changed files with 17890 additions and 14246 deletions

View file

@ -22,6 +22,7 @@ namespace TINK.Model.Bike.BC
protected BikeInfo(
IStateInfo stateInfo,
string id,
LockModel lockModel,
bool? isDemo = DEFAULTVALUEISDEMO,
IEnumerable<string> group = null,
WheelType? wheelType = null,
@ -31,7 +32,7 @@ namespace TINK.Model.Bike.BC
Uri operatorUri = null,
TariffDescription tariffDescription = null)
{
Bike = new Bike(id, wheelType, typeOfBike, description);
Bike = new Bike(id, lockModel, wheelType, typeOfBike, description);
m_oStateInfo = stateInfo;
@ -45,6 +46,7 @@ namespace TINK.Model.Bike.BC
public BikeInfo(BikeInfo bikeInfo) : this(
bikeInfo?.State,
bikeInfo?.Id ?? throw new ArgumentException($"Can not copy-construct {typeof(BikeInfo).Name}-object. Source must not be null."),
bikeInfo.LockModel,
bikeInfo.IsDemo,
bikeInfo.Group,
bikeInfo.WheelType,
@ -64,6 +66,7 @@ namespace TINK.Model.Bike.BC
/// <param name="wheelType"></param>
public BikeInfo(
string id,
LockModel lockModel,
string stationId,
Uri operatorUri = null,
TariffDescription tariffDescription = null,
@ -73,7 +76,8 @@ namespace TINK.Model.Bike.BC
TypeOfBike? typeOfBike = null,
string description = null) : this(
new StateInfo(),
id,
id,
lockModel,
isDemo,
group,
wheelType,
@ -88,7 +92,6 @@ namespace TINK.Model.Bike.BC
/// <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="wheelType"></param>
/// <param name="id">Unique id of bike.</param>
/// <param name="stationId">Name of station where bike is located, null if bike is on the road.</param>
@ -97,9 +100,10 @@ namespace TINK.Model.Bike.BC
/// <param name="requestedAt">Date time when bike was requested</param>
/// <param name="mailAddress">Mail address of user which requested bike.</param>
/// <param name="code">Booking code.</param>
/// <param name="p_oDateTimeNowProvider">Date time provider to calculate reaining time.</param>
/// <param name="dateTimeProvider">Date time provider to calculate reaining time.</param>
public BikeInfo(
string id,
LockModel lockModel,
bool? isDemo,
IEnumerable<string> group,
WheelType? wheelType,
@ -117,7 +121,8 @@ namespace TINK.Model.Bike.BC
requestedAt,
mailAddress,
code),
id,
id,
lockModel,
isDemo,
group,
wheelType,
@ -134,6 +139,7 @@ namespace TINK.Model.Bike.BC
/// </summary>
/// <param name="dateTimeProvider">Provider for current date time to calculate remainig time on demand for state of type reserved.</param>
/// <param name="wheelType"></param>
/// <param name="lockModel">Specifies the lock model.</param>
/// <param name="id">Unique id of 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>
@ -143,6 +149,7 @@ namespace TINK.Model.Bike.BC
/// <param name="code">Booking code.</param>
public BikeInfo(
string id,
LockModel lockModel,
bool? isDemo,
IEnumerable<string> group,
WheelType? wheelType,
@ -158,7 +165,8 @@ namespace TINK.Model.Bike.BC
bookedAt,
mailAddress,
code),
id,
id,
lockModel,
isDemo,
group,
wheelType,
@ -198,6 +206,9 @@ namespace TINK.Model.Bike.BC
public TypeOfBike? TypeOfBike => Bike.TypeOfBike;
/// <summary> Gets the model of the lock. </summary>
public LockModel LockModel => Bike.LockModel;
public string Description => Bike.Description;
/// <summary>

View file

@ -30,6 +30,7 @@ namespace TINK.Model.Bike.BC
/// <param name="stateInfo">Bike state info.</param>
protected BikeInfoMutable(
string id,
LockModel lockModel,
bool isDemo = BikeInfo.DEFAULTVALUEISDEMO,
IEnumerable<string> group = null,
WheelType? wheelType = null,
@ -44,7 +45,7 @@ namespace TINK.Model.Bike.BC
{
IsDemo = isDemo;
Group = group;
m_oBike = new Bike(id, wheelType, typeOfBike, description);
m_oBike = new Bike(id, lockModel, wheelType, typeOfBike, description);
m_oStateInfo = new StateInfoMutable(dateTimeProvider, stateInfo);
m_oStateInfo.PropertyChanged += (sender, eventargs) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(eventargs.PropertyName));
StationId = stationId;
@ -56,6 +57,7 @@ namespace TINK.Model.Bike.BC
/// <summary> Constructs a bike object from source. </summary>
public BikeInfoMutable(IBikeInfo bike, string stationName) : this(
bike.Id,
bike.LockModel,
bike.IsDemo,
bike.Group,
bike.WheelType,
@ -110,6 +112,8 @@ namespace TINK.Model.Bike.BC
public TypeOfBike? TypeOfBike => m_oBike.TypeOfBike;
public LockModel LockModel => m_oBike.LockModel;
public string Description => m_oBike.Description;
/// <summary>

View file

@ -31,6 +31,9 @@ namespace TINK.Model.Bike.BC
/// </summary>
TypeOfBike? TypeOfBike { get; }
/// <summary> Gets the model of the lock. </summary>
LockModel LockModel { get; }
/// <summary> Holds the description of the bike. </summary>
string Description { get; }

View file

@ -29,6 +29,9 @@ namespace TINK.Model.Bikes.Bike.BC
/// </summary>
TypeOfBike? TypeOfBike { get; }
/// <summary> Gets the model of the lock. </summary>
LockModel LockModel { get; }
/// <summary> Holds the description of the bike. </summary>
string Description { get; }

View file

@ -2,7 +2,7 @@
using System.Collections.Generic;
namespace TINK.Model.Bike
{
{
/// <summary> Count of wheels. </summary>
public enum WheelType
{
@ -19,23 +19,36 @@ namespace TINK.Model.Bike
Citybike = 2,
}
/// <summary> Holds the model of lock. </summary>
public enum LockModel
{
ILockIt, // haveltec GbmH Brandenburg, Germany bluetooth lock
BordComputer, // Teilrad BC
Sigo, // Sigo Gmbh Darmstadt, Germany bike lock
}
/// <summary> Holds the type of lock. </summary>
public enum LockType
{
Backend, // Backend, i.e. COPRI controls lock (open, close, ...)
Bluethooth, // Lock is controlled.
}
public class Bike : IEquatable<Bike>
{
/// <summary>
/// Constructs a bike.
/// </summary>
/// <param name="dateTimeProvider">Provider for current date time to calculate remainig time on demand for state of type reserved.</param>
/// <param name="wheelType"></param>
/// <param name="p_iId">Unique id of bike.</param>
/// <param name="p_strCurrentStationName">Name of station where bike is located, null if bike is on the road.</param>
public Bike(
string p_iId,
LockModel lockModel,
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null)
{
WheelType = wheelType;
TypeOfBike = typeOfBike;
LockModel = lockModel;
Id = p_iId;
Description = description;
}
@ -55,6 +68,9 @@ namespace TINK.Model.Bike
/// </summary>
public TypeOfBike? TypeOfBike { get; }
/// <summary> Gets the model of the lock. </summary>
public LockModel LockModel { get; private set; }
/// <summary> Holds the description of the bike. </summary>
public string Description { get; }

View file

@ -0,0 +1,23 @@
using System;
using TINK.Model.Bike;
namespace TINK.Model.Bikes.Bike
{
public static class BikeExtension
{
public static LockType GetLockType(this LockModel model)
{
switch (model)
{
case LockModel.ILockIt:
return LockType.Bluethooth;
case LockModel.Sigo:
return LockType.Backend;
default:
throw new ArgumentException($"Unsupported lock model {model} detected.");
}
}
}
}

View file

@ -31,6 +31,7 @@ namespace TINK.Model.Bike.BluetoothLock
string description = null) : base(
new StateInfo(),
bikeId,
LockModel.ILockIt,
isDemo,
group,
wheelType,
@ -81,6 +82,7 @@ namespace TINK.Model.Bike.BluetoothLock
mailAddress,
""),
id,
LockModel.ILockIt,
isDemo,
group,
wheelType,
@ -127,6 +129,7 @@ namespace TINK.Model.Bike.BluetoothLock
mailAddress,
""),
id,
LockModel.ILockIt,
isDemo,
group,
wheelType,

View file

@ -7,7 +7,8 @@ namespace TINK.Model.Bike.BluetoothLock
{
/// <summary> Constructs a bike object from source. </summary>
public BikeInfoMutable(BikeInfo bike, string stationName) : base(
bike.Id,
bike.Id,
bike.LockModel,
bike.IsDemo,
bike.Group,
bike.WheelType,

View file

@ -0,0 +1,141 @@
using System;
using System.Collections.Generic;
using TINK.Model.Bikes.Bike;
using TINK.Model.Bikes.Bike.CopriLock;
using TINK.Model.State;
namespace TINK.Model.Bike.CopriLock
{
public class BikeInfo : BC.BikeInfo
{
/// <summary>
/// Constructs a bike info object for a available bike.
/// </summary>
/// <param name="bikeId">Unique id of bike.</param>
/// <param name="currentStationId">Id of station where bike is located.</param>
/// <param name="lockInfo">Lock info.</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(
string bikeId,
string currentStationId,
LockInfo lockInfo,
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,
LockModel.Sigo,
isDemo,
group,
wheelType,
typeOfBike,
description,
currentStationId,
operatorUri,
tariffDescription)
{
LockInfo = lockInfo;
}
/// <summary>
/// Constructs a bike info object for a requested bike.
/// </summary>
/// <param name="id">Unique id of bike.</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="lockInfo">Lock info.</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="dateTimeProvider">Provider for current date time to calculate remainig time on demand for state of type reserved.</param>
/// <param name="wheelType"></param>
public BikeInfo(
string id,
DateTime requestedAt,
string mailAddress,
string currentStationId,
LockInfo lockInfo,
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,
LockModel.ILockIt,
isDemo,
group,
wheelType,
typeOfBike,
description,
currentStationId,
operatorUri,
tariffDescription)
{
LockInfo = lockInfo;
}
/// <summary>
/// Constructs a bike info object for a booked bike.
/// </summary>
/// <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="lockInfo">Lock info.</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(
string id,
DateTime bookedAt,
string mailAddress,
string currentStationId,
LockInfo lockInfo,
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,
LockModel.ILockIt,
isDemo,
group,
wheelType,
typeOfBike,
description,
currentStationId,
operatorUri,
tariffDescription)
{
LockInfo = lockInfo;
}
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; }
}
}

View file

@ -0,0 +1,31 @@
using System;
using TINK.Model.Bikes.Bike.CopriLock;
namespace TINK.Model.Bike.CopriLock
{
public class BikeInfoMutable : BC.BikeInfoMutable, IBikeInfoMutable
{
/// <summary> Constructs a bike object from source. </summary>
public BikeInfoMutable(BikeInfo bike, string stationName) : base(
bike?.Id ?? throw new ArgumentException(nameof(bike)),
bike.LockModel,
bike.IsDemo,
bike.Group,
bike.WheelType,
bike.TypeOfBike,
bike.Description,
bike.StationId,
stationName,
bike.OperatorUri,
bike.TariffDescription,
() => DateTime.Now,
bike.State)
{
LockInfo = new LockInfoMutable(bike.LockInfo.State);
}
public LockInfoMutable LockInfo { get; }
ILockInfoMutable IBikeInfoMutable.LockInfo => LockInfo;
}
}

View file

@ -0,0 +1,7 @@
namespace TINK.Model.Bikes.Bike.CopriLock
{
public interface IBikeInfoMutable : BC.IBikeInfoMutable
{
ILockInfoMutable LockInfo { get; }
}
}

View file

@ -0,0 +1,8 @@

namespace TINK.Model.Bikes.Bike.CopriLock
{
public interface ILockInfoMutable
{
LockingState State { get; set; }
}
}

View file

@ -0,0 +1,33 @@
using System;
using TINK.Model.Bikes.Bike.CopriLock;
namespace TINK.Model.Bike.CopriLock
{
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(LockingState state)
{
LockInfo = new LockInfo.Builder() { State = state }.Build();
}
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()
{
LockInfo = new LockInfo.Builder(LockInfo) { }.Build();
}
}
}

View file

@ -43,8 +43,13 @@ namespace TINK.Model.Bike
// Check if bike has to be added to list of existing station.
if (ContainsKey(bikeInfo.Id) == false)
{
// Bike does not yet exist in list of bikes.
Add(BikeInfoMutableFactory.Create(bikeInfo, stationName));
var bikeInfoMutable = BikeInfoMutableFactory.Create(bikeInfo, stationName);
if (bikeInfoMutable != null)
{
// Bike does not yet exist in list of bikes.
Add(bikeInfoMutable);
}
continue;
}
@ -139,13 +144,24 @@ namespace TINK.Model.Bike
/// <summary>
/// Create mutable objects from immutable objects.
/// </summary>
private static class BikeInfoMutableFactory
public static class BikeInfoMutableFactory
{
public static BikeInfoMutable Create(BikeInfo bikeInfo, string stationName)
public static BikeInfoMutable Create(
BikeInfo bikeInfo,
string stationName)
{
return (bikeInfo is BluetoothLock.BikeInfo bluetoothLockBikeInfo)
? new BluetoothLock.BikeInfoMutable(bluetoothLockBikeInfo, stationName)
: new BikeInfoMutable(bikeInfo, stationName);
if (bikeInfo is BluetoothLock.BikeInfo btBikeInfo)
{
return new BluetoothLock.BikeInfoMutable(btBikeInfo, stationName);
}
else if (bikeInfo is CopriLock.BikeInfo copriBikeInfo)
{
return new CopriLock.BikeInfoMutable(copriBikeInfo, stationName);
}
// Unsupported type detected.
return null;
}
}
}