mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-23 05:16:29 +02:00
Version 3.0.381
This commit is contained in:
parent
f963c0a219
commit
3a363acf3a
1525 changed files with 60589 additions and 125098 deletions
112
SharedBusinessLogic/Model/Bikes/BikeInfoNS/BC/BikeInfo.cs
Normal file
112
SharedBusinessLogic/Model/Bikes/BikeInfoNS/BC/BikeInfo.cs
Normal file
|
@ -0,0 +1,112 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.BikeNS;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS;
|
||||
using ShareeBike.Model.State;
|
||||
|
||||
namespace ShareeBike.Model.Bikes.BikeInfoNS.BC
|
||||
{
|
||||
public abstract class BikeInfo : IBikeInfo
|
||||
{
|
||||
/// <summary> Default value of demo property. </summary>
|
||||
public const bool DEFAULTVALUEISDEMO = false;
|
||||
|
||||
/// <summary> Holds the info about the bike state. </summary>
|
||||
private readonly IStateInfo _StateInfo;
|
||||
|
||||
/// <summary>
|
||||
/// Holds the bike object.
|
||||
/// </summary>
|
||||
public Bike Bike { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the drive object.
|
||||
/// </summary>
|
||||
public DriveMutable Drive { get; }
|
||||
|
||||
/// <summary> Gets the information where the data origins from. </summary>
|
||||
public DataSource DataSource { get; }
|
||||
|
||||
/// <summary> Constructs a bike object.</summary>
|
||||
/// <param name="dataSource">Specified the source of the data.</param>
|
||||
protected BikeInfo(
|
||||
IStateInfo stateInfo,
|
||||
Bike bike,
|
||||
DriveMutable drive,
|
||||
DataSource dataSource,
|
||||
bool? isDemo = DEFAULTVALUEISDEMO,
|
||||
IEnumerable<string> group = null,
|
||||
string stationId = null,
|
||||
Uri operatorUri = null,
|
||||
RentalDescription tariffDescription = null)
|
||||
{
|
||||
Bike = bike ?? throw new ArgumentNullException(nameof(bike));
|
||||
Drive = drive ?? throw new ArgumentNullException(nameof(drive));
|
||||
DataSource = dataSource;
|
||||
_StateInfo = stateInfo;
|
||||
|
||||
IsDemo = isDemo ?? DEFAULTVALUEISDEMO;
|
||||
Group = group ?? new List<string>();
|
||||
StationId = stationId;
|
||||
OperatorUri = operatorUri;
|
||||
TariffDescription = tariffDescription;
|
||||
}
|
||||
|
||||
public BikeInfo(BikeInfo bikeInfo) : this(
|
||||
bikeInfo != null ? bikeInfo?.State : throw new ArgumentNullException(nameof(bikeInfo)),
|
||||
bikeInfo.Bike,
|
||||
bikeInfo.Drive,
|
||||
bikeInfo.DataSource,
|
||||
bikeInfo.IsDemo,
|
||||
bikeInfo.Group,
|
||||
bikeInfo.StationId,
|
||||
bikeInfo.OperatorUri,
|
||||
bikeInfo.TariffDescription)
|
||||
{ }
|
||||
|
||||
/// <summary> True if device is demo device, false otherwise. </summary>
|
||||
public bool IsDemo { get; }
|
||||
|
||||
/// <summary> Returns the group (ShareeBike, Citybike, ...). </summary>
|
||||
public IEnumerable<string> Group { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Station a which bike is located, null otherwise.
|
||||
/// </summary>
|
||||
public string StationId { get; }
|
||||
|
||||
/// <summary> Holds description about the tariff. </summary>
|
||||
public RentalDescription TariffDescription { get; }
|
||||
|
||||
/// Holds the rent state of the bike.
|
||||
/// </summary>
|
||||
public IStateInfo State
|
||||
{
|
||||
get { return _StateInfo; }
|
||||
}
|
||||
|
||||
public string Id => Bike.Id;
|
||||
|
||||
public WheelType? WheelType => Bike.WheelType;
|
||||
|
||||
public TypeOfBike? TypeOfBike => Bike.TypeOfBike;
|
||||
|
||||
/// <summary> Gets the model of the lock. </summary>
|
||||
public LockModel LockModel => Bike.LockModel;
|
||||
|
||||
public string Description => Bike.Description;
|
||||
|
||||
/// <summary>
|
||||
/// Uri of the operator or null, in case of single operator setup.
|
||||
/// </summary>
|
||||
public Uri OperatorUri { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Converts the instance to text.
|
||||
/// </summary>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Id={Bike.Id}{(Bike.WheelType != null ? $", wheel(s)={Bike.WheelType}" : string.Empty)}{(Bike.TypeOfBike != null ? $"type={Bike.TypeOfBike}" : "")}, state={State}, location={(!string.IsNullOrEmpty(StationId) ? $"Station {StationId}" : "On the road")}, is demo={IsDemo}.";
|
||||
}
|
||||
}
|
||||
}
|
157
SharedBusinessLogic/Model/Bikes/BikeInfoNS/BC/BikeInfoMutable.cs
Normal file
157
SharedBusinessLogic/Model/Bikes/BikeInfoNS/BC/BikeInfoMutable.cs
Normal file
|
@ -0,0 +1,157 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.Serialization;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.BikeNS;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS;
|
||||
using ShareeBike.Model.State;
|
||||
|
||||
namespace ShareeBike.Model.Bikes.BikeInfoNS.BC
|
||||
{
|
||||
[DataContract]
|
||||
public abstract class BikeInfoMutable : IBikeInfoMutable, INotifyPropertyChanged
|
||||
{
|
||||
/// <summary> Holds the bike. </summary>
|
||||
private readonly Bike _Bike;
|
||||
|
||||
/// <summary> Holds the drive of the bike. </summary>
|
||||
private readonly DriveMutable _Drive;
|
||||
|
||||
/// <summary> Holds the state info of the bike. </summary>
|
||||
private readonly StateInfoMutable _StateInfo;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a bike info object.
|
||||
/// </summary>
|
||||
/// <param name="isDemo">True if device is demo device, false otherwise.</param>
|
||||
/// <param name="dateTimeProvider">Provider for current date time to calculate remaining time on demand for state of type reserved.</param>
|
||||
/// <param name="stationId">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="stateInfo">Bike state info.</param>
|
||||
protected BikeInfoMutable(
|
||||
Bike bike,
|
||||
DriveMutable drive,
|
||||
DataSource dataSource,
|
||||
bool isDemo = BikeInfo.DEFAULTVALUEISDEMO,
|
||||
IEnumerable<string> group = null,
|
||||
string stationId = null,
|
||||
string stationName = null,
|
||||
Uri operatorUri = null,
|
||||
IRentalDescription tariffDescription = null,
|
||||
Func<DateTime> dateTimeProvider = null,
|
||||
IStateInfo stateInfo = null)
|
||||
{
|
||||
IsDemo = isDemo;
|
||||
Group = group;
|
||||
_Bike = bike;
|
||||
_Drive = drive;
|
||||
DataSource = dataSource;
|
||||
_StateInfo = new StateInfoMutable(dateTimeProvider, stateInfo);
|
||||
_StateInfo.PropertyChanged += (sender, eventargs) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(eventargs.PropertyName));
|
||||
StationId = stationId;
|
||||
StationName = stationName;
|
||||
OperatorUri = operatorUri;
|
||||
TariffDescription = tariffDescription;
|
||||
}
|
||||
|
||||
/// <summary> Id of station a which bike is located, null otherwise.</summary>
|
||||
[DataMember]
|
||||
public string StationId { get; private set; }
|
||||
|
||||
/// <summary> Name of station a which bike is located, null otherwise. </summary>
|
||||
[DataMember]
|
||||
public string StationName { get; }
|
||||
|
||||
/// <summary> Holds description about the tariff. </summary>
|
||||
[DataMember]
|
||||
public IRentalDescription TariffDescription { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the rent state of the bike.
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public StateInfoMutable State
|
||||
{
|
||||
get { return _StateInfo; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uri of the operator or null, in case of single operator setup.
|
||||
/// </summary>
|
||||
public Uri OperatorUri { get; }
|
||||
|
||||
/// <summary> Unused member. </summary>
|
||||
IStateInfoMutable IBikeInfoMutable.State => _StateInfo;
|
||||
|
||||
public string Id => _Bike.Id;
|
||||
|
||||
public bool IsDemo { get; }
|
||||
|
||||
/// <summary> Returns the group (ShareeBike, Citybike, ...). </summary>
|
||||
public IEnumerable<string> Group { get; }
|
||||
|
||||
public WheelType? WheelType => _Bike.WheelType;
|
||||
|
||||
public TypeOfBike? TypeOfBike => _Bike.TypeOfBike;
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether bike is a AA bike (bike must be always returned a the same station) or AB bike (start and end stations can be different stations).
|
||||
/// </summary>
|
||||
public AaRideType? AaRideType => _Bike.AaRideType;
|
||||
|
||||
|
||||
public LockModel LockModel => _Bike.LockModel;
|
||||
|
||||
public string Description => _Bike.Description;
|
||||
|
||||
public DriveMutable Drive => _Drive;
|
||||
|
||||
/// <summary>
|
||||
/// Fired whenever property of bike changes.
|
||||
/// </summary>
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private DataSource _DataSource = DataSource.Copri;
|
||||
|
||||
/// <summary> Gets or sets the information where the data origins from. </summary>
|
||||
public DataSource DataSource
|
||||
{
|
||||
get => _DataSource;
|
||||
set
|
||||
{
|
||||
if (_DataSource == value)
|
||||
return;
|
||||
|
||||
_DataSource = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DataSource)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Loads a bike object from copri server booking_cancel (cancel reservation)/ booking_update (return bike) response.</summary>
|
||||
/// <param name="bike">Bike object to load response into.</param>
|
||||
/// <param name="notifyLevel">Controls whether notify property changed events are fired or not.</param>
|
||||
/// <param name="stationId">Id of the station if bike station changed, null otherwise.</param>
|
||||
public void Load(
|
||||
NotifyPropertyChangedLevel notifyLevel,
|
||||
string stationId = null)
|
||||
{
|
||||
State.Load(InUseStateEnum.Disposable, notifyLevel: notifyLevel);
|
||||
if (stationId == null)
|
||||
{
|
||||
// Station did not change.
|
||||
return;
|
||||
}
|
||||
|
||||
StationId = stationId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the instance to text.
|
||||
/// </summary>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Id={Id}{(WheelType != null ? $", wheel(s)={WheelType}" : string.Empty)}{(TypeOfBike != null ? $", type={TypeOfBike}" : "")}, demo={IsDemo}, state={State.ToString()}, location={(!string.IsNullOrEmpty(StationId) ? $"Station {StationId}" : "On the road")}.";
|
||||
}
|
||||
}
|
||||
}
|
65
SharedBusinessLogic/Model/Bikes/BikeInfoNS/BC/IBikeInfo.cs
Normal file
65
SharedBusinessLogic/Model/Bikes/BikeInfoNS/BC/IBikeInfo.cs
Normal file
|
@ -0,0 +1,65 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS;
|
||||
using ShareeBike.Model.State;
|
||||
|
||||
namespace ShareeBike.Model.Bikes.BikeInfoNS.BC
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows to access bike info.
|
||||
/// </summary>
|
||||
public interface IBikeInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the bike object.
|
||||
/// </summary>
|
||||
BikeNS.Bike Bike { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the drive.
|
||||
/// </summary>
|
||||
DriveMutable Drive { get; }
|
||||
|
||||
/// <summary> Gets or sets the information where the data origins from. </summary>
|
||||
DataSource DataSource { get; }
|
||||
|
||||
/// <summary> True if bike is a demo bike. </summary>
|
||||
bool IsDemo { get; }
|
||||
|
||||
/// <summary> Returns the group (ShareeBike, Citybike, ...). </summary>
|
||||
IEnumerable<string> Group { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Station a which bike is located, null otherwise.
|
||||
/// </summary>
|
||||
string StationId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Uri of the operator or null, in case of single operator setup.
|
||||
/// </summary>
|
||||
Uri OperatorUri { get; }
|
||||
|
||||
/// <summary> Holds description about the tariff. </summary>
|
||||
RentalDescription TariffDescription { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the rent state of the bike.
|
||||
/// </summary>
|
||||
IStateInfo State { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Origin of the data.
|
||||
/// </summary>
|
||||
public enum DataSource
|
||||
{
|
||||
/// <summary>
|
||||
/// Data source copri.
|
||||
/// </summary>
|
||||
Copri,
|
||||
/// <summary>
|
||||
/// Data source cache.
|
||||
/// </summary>
|
||||
Cache
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.BikeNS;
|
||||
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS;
|
||||
using ShareeBike.Model.State;
|
||||
|
||||
namespace ShareeBike.Model.Bikes.BikeInfoNS.BC
|
||||
{
|
||||
public interface IBikeInfoMutable
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the unique id of the bike;
|
||||
/// </summary>
|
||||
string Id { get; }
|
||||
|
||||
/// <summary> True if bike is a demo bike. </summary>
|
||||
bool IsDemo { get; }
|
||||
|
||||
/// <summary> Returns the group (ShareeBike, Citybike, ...). </summary>
|
||||
IEnumerable<string> Group { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the count of wheels.
|
||||
/// </summary>
|
||||
WheelType? WheelType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the type of bike.
|
||||
/// </summary>
|
||||
TypeOfBike? TypeOfBike { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether bike is a AA bike (bike must be always returned a the same station) or AB bike (start and end stations can be different stations).
|
||||
/// </summary>
|
||||
AaRideType? AaRideType { get; }
|
||||
|
||||
/// <summary> Gets the model of the lock. </summary>
|
||||
LockModel LockModel { get; }
|
||||
|
||||
/// <summary> Holds the description of the bike. </summary>
|
||||
string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Station a which bike is located, null otherwise.
|
||||
/// </summary>
|
||||
string StationId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the rent state of the bike.
|
||||
/// </summary>
|
||||
IStateInfoMutable State { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Uri of the operator or null, in case of single operator setup.
|
||||
/// </summary>
|
||||
Uri OperatorUri { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Hold the drive object.
|
||||
/// </summary>
|
||||
DriveMutable Drive { get; }
|
||||
|
||||
/// <summary> Gets or sets the information where the data origins from. </summary>
|
||||
DataSource DataSource { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rental description.
|
||||
/// </summary>
|
||||
IRentalDescription TariffDescription { get; }
|
||||
|
||||
/// <summary> Loads a bike object from copri server booking_cancel (cancel reservation)/ booking_update (return bike) response.</summary>
|
||||
/// <param name="notifyLevel">Controls whether notify property changed events are fired or not.</param>
|
||||
/// <param name="stationId">Id of the station if bike station changed, null otherwise.</param>
|
||||
void Load(
|
||||
NotifyPropertyChangedLevel notifyLevel,
|
||||
string stationId = null);
|
||||
|
||||
event PropertyChangedEventHandler PropertyChanged;
|
||||
}
|
||||
|
||||
public enum NotifyPropertyChangedLevel
|
||||
{
|
||||
/// <summary> Notify about all property changes.</summary>
|
||||
All,
|
||||
|
||||
/// <summary> Notify about no property changes.</summary>
|
||||
None
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue