mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-16 07:06:33 +01:00
132 lines
4.1 KiB
C#
132 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Runtime.Serialization;
|
|
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
|
|
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
|
|
using TINK.Model.State;
|
|
|
|
namespace TINK.Model.Bikes.BikeInfoNS.BC
|
|
{
|
|
[DataContract]
|
|
public class BikeInfoMutable : IBikeInfoMutable, INotifyPropertyChanged
|
|
{
|
|
/// <summary> Holds the bike. </summary>
|
|
private readonly BikeNS.Bike _Bike;
|
|
|
|
/// <summary> Holds the drive of the bike. </summary>
|
|
private readonly Drive _Drive;
|
|
|
|
/// <summary> Holds the state info of the bike. </summary>
|
|
private readonly StateInfoMutable _StateInfo;
|
|
|
|
/// <summary>
|
|
/// Constructs a bike.
|
|
/// </summary>
|
|
/// <param name="isDemo">True if device is demo device, false otherwise.</param>
|
|
/// <param name="dateTimeProvider">Provider for current date time to calculate remainig 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(
|
|
BikeNS.Bike bike,
|
|
Drive drive,
|
|
bool isDemo = BikeInfo.DEFAULTVALUEISDEMO,
|
|
IEnumerable<string> group = null,
|
|
string stationId = null,
|
|
string stationName = null,
|
|
Uri operatorUri = null,
|
|
RentalDescription tariffDescription = null,
|
|
Func<DateTime> dateTimeProvider = null,
|
|
IStateInfo stateInfo = null)
|
|
{
|
|
IsDemo = isDemo;
|
|
Group = group;
|
|
_Bike = bike;
|
|
_Drive = drive;
|
|
_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> Constructs a bike object from source. </summary>
|
|
public BikeInfoMutable(IBikeInfo bike, string stationName) : this(
|
|
bike != null
|
|
? bike.Bike
|
|
: throw new ArgumentNullException(nameof(bike)),
|
|
bike.Drive,
|
|
bike.IsDemo,
|
|
bike.Group,
|
|
bike.StationId,
|
|
stationName,
|
|
bike.OperatorUri,
|
|
bike.TariffDescription,
|
|
null /* date time provider */,
|
|
bike.State)
|
|
{
|
|
}
|
|
|
|
/// <summary> Id of station a which bike is located, null otherwise.</summary>
|
|
[DataMember]
|
|
public string StationId { get; }
|
|
|
|
/// <summary> Name of station a which bike is located, null otherwise. </summary>
|
|
[DataMember]
|
|
public string StationName { get; }
|
|
|
|
/// <summary> Holds description about the tarif. </summary>
|
|
[DataMember]
|
|
public RentalDescription 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 (TINK, Konrad, ...). </summary>
|
|
public IEnumerable<string> Group { get; }
|
|
|
|
public WheelType? WheelType => _Bike.WheelType;
|
|
|
|
public TypeOfBike? TypeOfBike => _Bike.TypeOfBike;
|
|
|
|
public LockModel LockModel => _Bike.LockModel;
|
|
|
|
public string Description => _Bike.Description;
|
|
|
|
public Drive Drive => _Drive;
|
|
|
|
/// <summary>
|
|
/// Fired whenever property of bike changes.
|
|
/// </summary>
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
/// <summary>
|
|
/// Converts the instance to text.
|
|
/// </summary>
|
|
public new 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")}.";
|
|
}
|
|
}
|
|
}
|