sharee.bike-App/SharedBusinessLogic/Model/Bikes/BikeInfoNS/BC/BikeInfoMutable.cs

158 lines
5.1 KiB
C#
Raw Normal View History

2023-01-18 14:22:51 +01:00
using System;
2021-05-13 20:03:07 +02:00
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
2024-04-09 12:53:23 +02:00
using ShareeBike.Model.Bikes.BikeInfoNS.BikeNS;
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS;
using ShareeBike.Model.State;
2021-05-13 20:03:07 +02:00
2024-04-09 12:53:23 +02:00
namespace ShareeBike.Model.Bikes.BikeInfoNS.BC
2021-05-13 20:03:07 +02:00
{
2022-09-06 16:08:19 +02:00
[DataContract]
2023-04-19 12:14:14 +02:00
public abstract class BikeInfoMutable : IBikeInfoMutable, INotifyPropertyChanged
2022-09-06 16:08:19 +02:00
{
/// <summary> Holds the bike. </summary>
2023-01-18 14:22:51 +01:00
private readonly Bike _Bike;
2022-09-06 16:08:19 +02:00
/// <summary> Holds the drive of the bike. </summary>
2023-08-31 12:31:38 +02:00
private readonly DriveMutable _Drive;
2022-09-06 16:08:19 +02:00
/// <summary> Holds the state info of the bike. </summary>
private readonly StateInfoMutable _StateInfo;
/// <summary>
2023-06-06 12:00:24 +02:00
/// Constructs a bike info object.
2022-09-06 16:08:19 +02:00
/// </summary>
/// <param name="isDemo">True if device is demo device, false otherwise.</param>
2023-04-19 12:14:14 +02:00
/// <param name="dateTimeProvider">Provider for current date time to calculate remaining time on demand for state of type reserved.</param>
2022-09-06 16:08:19 +02:00
/// <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(
2023-01-18 14:22:51 +01:00
Bike bike,
2023-08-31 12:31:38 +02:00
DriveMutable drive,
2023-01-18 14:22:51 +01:00
DataSource dataSource,
2022-09-06 16:08:19 +02:00
bool isDemo = BikeInfo.DEFAULTVALUEISDEMO,
IEnumerable<string> group = null,
string stationId = null,
string stationName = null,
Uri operatorUri = null,
2023-06-06 12:00:24 +02:00
IRentalDescription tariffDescription = null,
2022-09-06 16:08:19 +02:00
Func<DateTime> dateTimeProvider = null,
IStateInfo stateInfo = null)
{
IsDemo = isDemo;
Group = group;
_Bike = bike;
_Drive = drive;
2023-01-18 14:22:51 +01:00
DataSource = dataSource;
2022-09-06 16:08:19 +02:00
_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]
2023-07-04 11:06:38 +02:00
public string StationId { get; private set; }
2022-09-06 16:08:19 +02:00
/// <summary> Name of station a which bike is located, null otherwise. </summary>
[DataMember]
public string StationName { get; }
2023-04-19 12:14:14 +02:00
/// <summary> Holds description about the tariff. </summary>
2022-09-06 16:08:19 +02:00
[DataMember]
2023-06-06 12:00:24 +02:00
public IRentalDescription TariffDescription { get; private set; }
2022-09-06 16:08:19 +02:00
/// <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; }
2024-04-09 12:53:23 +02:00
/// <summary> Returns the group (ShareeBike, Citybike, ...). </summary>
2022-09-06 16:08:19 +02:00
public IEnumerable<string> Group { get; }
public WheelType? WheelType => _Bike.WheelType;
public TypeOfBike? TypeOfBike => _Bike.TypeOfBike;
2023-04-19 12:14:14 +02:00
/// <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;
2022-09-06 16:08:19 +02:00
public LockModel LockModel => _Bike.LockModel;
public string Description => _Bike.Description;
2023-08-31 12:31:38 +02:00
public DriveMutable Drive => _Drive;
2022-09-06 16:08:19 +02:00
/// <summary>
/// Fired whenever property of bike changes.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
2023-01-18 14:22:51 +01:00
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)));
}
}
2023-07-04 11:06:38 +02:00
/// <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;
}
2022-09-06 16:08:19 +02:00
/// <summary>
/// Converts the instance to text.
/// </summary>
2023-11-06 12:23:09 +01:00
public override string ToString()
2022-09-06 16:08:19 +02:00
{
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")}.";
}
}
2021-05-13 20:03:07 +02:00
}