mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-19 03:27:29 +02:00
Version 3.0.366
This commit is contained in:
parent
0eb7362cb8
commit
24cdfbb0ca
84 changed files with 900 additions and 393 deletions
|
@ -21,7 +21,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BC
|
|||
private readonly StateInfoMutable _StateInfo;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a bike.
|
||||
/// 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>
|
||||
|
@ -38,7 +38,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BC
|
|||
string stationId = null,
|
||||
string stationName = null,
|
||||
Uri operatorUri = null,
|
||||
RentalDescription tariffDescription = null,
|
||||
IRentalDescription tariffDescription = null,
|
||||
Func<DateTime> dateTimeProvider = null,
|
||||
IStateInfo stateInfo = null)
|
||||
{
|
||||
|
@ -65,7 +65,7 @@ namespace TINK.Model.Bikes.BikeInfoNS.BC
|
|||
|
||||
/// <summary> Holds description about the tariff. </summary>
|
||||
[DataMember]
|
||||
public RentalDescription TariffDescription { get; private set; }
|
||||
public IRentalDescription TariffDescription { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the rent state of the bike.
|
||||
|
|
|
@ -64,6 +64,11 @@ namespace TINK.Model.Bikes.BikeInfoNS.BC
|
|||
/// <summary> Gets or sets the information where the data origins from. </summary>
|
||||
DataSource DataSource { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or set the rental description.
|
||||
/// </summary>
|
||||
IRentalDescription TariffDescription { get; }
|
||||
|
||||
event PropertyChangedEventHandler PropertyChanged;
|
||||
}
|
||||
|
||||
|
|
|
@ -83,8 +83,9 @@ namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
|
|||
new StateInfo(
|
||||
dateTimeProvider,
|
||||
requestedAt,
|
||||
tariffDescription?.MaxReservationTimeSpan ?? StateRequestedInfo.UNKNOWNMAXRESERVATIONTIMESPAN,
|
||||
mailAddress,
|
||||
""),
|
||||
"" ), // BC code
|
||||
bike != null
|
||||
? new Bike(
|
||||
bike.Id,
|
||||
|
|
|
@ -84,8 +84,9 @@ namespace TINK.Model.Bikes.BikeInfoNS.CopriLock
|
|||
new StateInfo(
|
||||
dateTimeProvider,
|
||||
requestedAt,
|
||||
tariffDescription?.MaxReservationTimeSpan ?? StateRequestedInfo.UNKNOWNMAXRESERVATIONTIMESPAN,
|
||||
mailAddress,
|
||||
""),
|
||||
""), // BC code
|
||||
bike != null
|
||||
? new Bike(
|
||||
bike.Id,
|
||||
|
|
29
TINKLib/Model/Bikes/BikeInfoNS/IRentalDescription.cs
Normal file
29
TINKLib/Model/Bikes/BikeInfoNS/IRentalDescription.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using static TINK.Model.Bikes.BikeInfoNS.RentalDescription;
|
||||
|
||||
namespace TINK.Model.Bikes.BikeInfoNS
|
||||
{
|
||||
public interface IRentalDescription
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the tariff.
|
||||
/// </summary>
|
||||
string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the time span for which a bike can be reserved.
|
||||
/// </summary>
|
||||
TimeSpan MaxReservationTimeSpan { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Dynamic language aware tariff elements to be displayed to user.
|
||||
/// </summary>
|
||||
Dictionary<string, TariffElement> TariffEntries { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Well known language aware elements (AGB, tracking info, ...) to be displayed to user.
|
||||
/// </summary>
|
||||
Dictionary<string, InfoElement> InfoEntries { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace TINK.Model.Bikes.BikeInfoNS
|
||||
|
@ -6,20 +7,20 @@ namespace TINK.Model.Bikes.BikeInfoNS
|
|||
/// Successor of TarifDescription- object.
|
||||
/// Manages tariff- and rental info.
|
||||
/// </summary>
|
||||
public class RentalDescription
|
||||
public class RentalDescription : IRentalDescription
|
||||
{
|
||||
/// <summary>
|
||||
/// The different elements of a tariff (example: "Max Gebühr", )
|
||||
/// The different elements of a tariff (example: "Max Gebühr", ) to be displayed by sharee.bike without processing
|
||||
/// </summary>
|
||||
public class TariffElement
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes the tariff element. To be displayed to user (example of elements: "Gratis Mietzeit", "Mietgebühr", "Max Gebühr").
|
||||
/// Describes the tariff element (language aware). To be displayed to user (example of elements: "Gratis Mietzeit", "Mietgebühr", "Max Gebühr").
|
||||
/// </summary>
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Holds the tariff element value. To be displayed to user (example: "9.00 € / Tag").
|
||||
/// Holds the tariff element value (language aware, i.e. value from backend might be english, german, ... depending on smart phone value). To be displayed to user (example: "9.00 € / Tag").
|
||||
/// </summary>
|
||||
public string Value { get; set; } = string.Empty;
|
||||
}
|
||||
|
@ -30,12 +31,12 @@ namespace TINK.Model.Bikes.BikeInfoNS
|
|||
public class InfoElement
|
||||
{
|
||||
/// <summary>
|
||||
/// Key which identyfies the value (required for special processing)
|
||||
/// Key which identifies the value (required for special processing)
|
||||
/// </summary>
|
||||
public string Key { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Text to be displayed to user.
|
||||
/// Text (language aware) to be displayed to user.
|
||||
/// </summary>
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
@ -50,8 +51,19 @@ namespace TINK.Model.Bikes.BikeInfoNS
|
|||
/// </summary>
|
||||
public int? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the time span for which a bike can be reserved.
|
||||
/// </summary>
|
||||
public TimeSpan MaxReservationTimeSpan { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Dynamic language aware tariff elements to be displayed to user.
|
||||
/// </summary>
|
||||
public Dictionary<string, TariffElement> TariffEntries { get; set; } = new Dictionary<string, TariffElement>();
|
||||
|
||||
/// <summary>
|
||||
/// Well known language aware elements (AGB, tracking info, ...) to be displayed to user.
|
||||
/// </summary>
|
||||
public Dictionary<string, InfoElement> InfoEntries { get; set; } = new Dictionary<string, InfoElement>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -438,5 +438,20 @@ namespace TINK.Model.Connector
|
|||
name,
|
||||
int.TryParse(bikeGroup?.bike_count ?? "0", out var countCity) ? countCity : 0,
|
||||
bikeGroup?.bike_group ?? string.Empty);
|
||||
|
||||
/// <summary>
|
||||
/// Default value for reserve_timerange.
|
||||
/// </summary>
|
||||
private static int DEFAULTMAXRESERVATIONTIMESPAN = 15;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reservation time span from response.
|
||||
/// </summary>
|
||||
/// <param name="description">Response to get time span from.</param>
|
||||
/// <returns>Time span.</returns>
|
||||
public static TimeSpan GetMaxReservationTimeSpan(this RentalDescription description) =>
|
||||
TimeSpan.FromMinutes(int.TryParse(description?.reserve_timerange, out int minutes)
|
||||
? minutes
|
||||
: DEFAULTMAXRESERVATIONTIMESPAN );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -313,7 +313,7 @@ namespace TINK.Model.Connector.Updater
|
|||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
// Contructor reported invalid arguemts (missing lock id, ....).
|
||||
// Constructor reported invalid arguments (missing lock id, ....).
|
||||
Log.Error($"Can not create new {nameof(BikeInfo)}-object from {nameof(BikeInfoReservedOrBooked)} argument. Invalid response detected. Booked bike with id {bikeInfo.bike} skipped. {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,58 +1,56 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TINK.Model.Bikes.BikeInfoNS;
|
||||
|
||||
namespace TINK.Model.Connector.Updater
|
||||
{
|
||||
public static class RentalDescriptionFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates rental description object from JSON- tarif description object.
|
||||
/// Creates rental description object from JSON- tariff description object.
|
||||
/// </summary>
|
||||
/// <param name="rentalDesciption">Source JSON object.</param>
|
||||
/// <returns>Tariff description object.</returns>
|
||||
|
||||
public static Bikes.BikeInfoNS.RentalDescription Create(this Repository.Response.RentalDescription rentalDesciption)
|
||||
public static RentalDescription Create(this Repository.Response.RentalDescription rentalDesciption)
|
||||
{
|
||||
Bikes.BikeInfoNS.RentalDescription.TariffElement CreateTarifEntry(string[] elementValue)
|
||||
{
|
||||
return new Bikes.BikeInfoNS.RentalDescription.TariffElement
|
||||
{
|
||||
Description = elementValue != null && elementValue.Length > 0 ? elementValue[0] : string.Empty,
|
||||
Value = elementValue != null && elementValue.Length > 1 ? elementValue[1] : string.Empty,
|
||||
};
|
||||
}
|
||||
RentalDescription.TariffElement CreateTarifEntry(string[] elementValue) =>
|
||||
new RentalDescription.TariffElement
|
||||
{
|
||||
Description = elementValue != null && elementValue.Length > 0 ? elementValue[0] : string.Empty,
|
||||
Value = elementValue != null && elementValue.Length > 1 ? elementValue[1] : string.Empty,
|
||||
};
|
||||
|
||||
Bikes.BikeInfoNS.RentalDescription.InfoElement CreateInfoElement(string[] elementValue)
|
||||
{
|
||||
return new Bikes.BikeInfoNS.RentalDescription.InfoElement
|
||||
RentalDescription.InfoElement CreateInfoElement(string[] elementValue) =>
|
||||
new RentalDescription.InfoElement
|
||||
{
|
||||
Key = elementValue != null && elementValue.Length > 0 ? elementValue[0] : string.Empty,
|
||||
Value = elementValue != null && elementValue.Length > 1 ? elementValue[1] : string.Empty,
|
||||
};
|
||||
}
|
||||
|
||||
// Read tariff elements.
|
||||
var tarifEntries = rentalDesciption?.tarif_elements != null
|
||||
? rentalDesciption.tarif_elements.Select(x => new
|
||||
{
|
||||
Key = x.Key,
|
||||
x.Key,
|
||||
Value = CreateTarifEntry(x.Value)
|
||||
}).ToLookup(x => x.Key, x => x.Value).ToDictionary(x => x.Key, x => x.First())
|
||||
: new Dictionary<string, Bikes.BikeInfoNS.RentalDescription.TariffElement>();
|
||||
: new Dictionary<string, RentalDescription.TariffElement>();
|
||||
|
||||
// Read info elements.
|
||||
var InfoEntries = rentalDesciption?.rental_info != null
|
||||
? rentalDesciption.rental_info.Select(x => new
|
||||
{
|
||||
Key = x.Key,
|
||||
x.Key,
|
||||
Value = CreateInfoElement(x.Value)
|
||||
}).ToLookup(x => x.Key, x => x.Value).ToDictionary(x => x.Key, x => x.First())
|
||||
: new Dictionary<string, Bikes.BikeInfoNS.RentalDescription.InfoElement>();
|
||||
: new Dictionary<string, RentalDescription.InfoElement>();
|
||||
|
||||
var bike = new Bikes.BikeInfoNS.RentalDescription
|
||||
var bike = new RentalDescription
|
||||
{
|
||||
Name = rentalDesciption?.name ?? string.Empty,
|
||||
Id = int.TryParse(rentalDesciption?.id ?? string.Empty, out int number) ? number : (int?)null,
|
||||
MaxReservationTimeSpan = rentalDesciption.GetMaxReservationTimeSpan(),
|
||||
TariffEntries = tarifEntries,
|
||||
InfoEntries = InfoEntries
|
||||
};
|
||||
|
|
|
@ -2,13 +2,11 @@ using System;
|
|||
using TINK.Model.Bikes.BikeInfoNS.BC;
|
||||
using TINK.Model.State;
|
||||
using TINK.Model.Stations;
|
||||
using TINK.Model.Stations.StationNS.Operator;
|
||||
using TINK.Model.User.Account;
|
||||
using TINK.Repository.Exception;
|
||||
using TINK.Repository.Response;
|
||||
using TINK.Repository.Response.Stations;
|
||||
using TINK.Services.CopriApi;
|
||||
using Xamarin.Forms;
|
||||
using IBikeInfoMutable = TINK.Model.Bikes.BikeInfoNS.BC.IBikeInfoMutable;
|
||||
|
||||
namespace TINK.Model.Connector.Updater
|
||||
|
@ -135,6 +133,7 @@ namespace TINK.Model.Connector.Updater
|
|||
bike.State.Load(
|
||||
InUseStateEnum.Reserved,
|
||||
bikeInfo.GetFrom(),
|
||||
bikeInfo.rental_description.GetMaxReservationTimeSpan(),
|
||||
mailAddress,
|
||||
bikeInfo.timeCode,
|
||||
notifyLevel);
|
||||
|
@ -144,9 +143,9 @@ namespace TINK.Model.Connector.Updater
|
|||
bike.State.Load(
|
||||
InUseStateEnum.Booked,
|
||||
bikeInfo.GetFrom(),
|
||||
mailAddress,
|
||||
bikeInfo.timeCode,
|
||||
notifyLevel);
|
||||
mailAddress: mailAddress,
|
||||
code: bikeInfo.timeCode,
|
||||
notifyLevel: notifyLevel);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace TINK.Model.State
|
||||
{
|
||||
|
@ -12,7 +12,7 @@ namespace TINK.Model.State
|
|||
[KnownType(typeof(StateOccupiedInfo))]
|
||||
public abstract class BaseState
|
||||
{
|
||||
/// <summary> Constructor for Json serialization. </summary>
|
||||
/// <summary> Constructor for JSON serialization. </summary>
|
||||
/// <param name="value">State value.</param>
|
||||
protected BaseState(InUseStateEnum value) { }
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
|
||||
namespace TINK.Model.State
|
||||
{
|
||||
|
@ -9,8 +9,16 @@ namespace TINK.Model.State
|
|||
{
|
||||
string MailAddress { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Date of request/ booking action.
|
||||
/// </summary>
|
||||
DateTime? From { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Time span for which a bike can be reserved.
|
||||
/// </summary>
|
||||
TimeSpan? MaxReservationTimeSpan { get; }
|
||||
|
||||
string Code { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
|
||||
namespace TINK.Model.State
|
||||
{
|
||||
|
@ -6,15 +6,17 @@ namespace TINK.Model.State
|
|||
{
|
||||
InUseStateEnum Value { get; }
|
||||
|
||||
/// <summary> Updates state from webserver. </summary>
|
||||
/// <summary> Updates state from web server. </summary>
|
||||
/// <param name="state">State of the bike.</param>
|
||||
/// <param name="from">Date time when bike was reserved/ booked.</param>
|
||||
/// <param name="mailAddress">Mailaddress of the one which reserved/ booked.</param>
|
||||
/// <param name="reservationTimeSpan">Time span for which a bike can be reserved.</param>
|
||||
/// <param name="mailAddress">Mail address of the one which reserved/ booked.</param>
|
||||
/// <param name="code">Booking code if bike is booked or reserved.</param>
|
||||
/// <param name="notifyLevel">Controls whether notify property changed events are fired or not.</param>
|
||||
void Load(
|
||||
InUseStateEnum state,
|
||||
DateTime? from = null,
|
||||
TimeSpan? reservationTimeSpan = null,
|
||||
string mailAddress = null,
|
||||
string code = null,
|
||||
Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel notifyLevel = Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel.All);
|
||||
|
|
|
@ -52,20 +52,21 @@ namespace TINK.Model.State
|
|||
/// Constructs a state info object when state is requested.
|
||||
/// </summary>
|
||||
/// <param name="requestedAt">Date time when bike was requested</param>
|
||||
/// <param name="maxReservationTimeSpan">Time span for which a bike can be reserved.</param>
|
||||
/// <param name="mailAddress">Mail address of user which requested bike.</param>
|
||||
/// <param name="code">Booking code.</param>
|
||||
/// <param name="dateTimeNowProvider">Date time provider to calculate remaining time.</param>
|
||||
public StateInfo(
|
||||
Func<DateTime> dateTimeNowProvider,
|
||||
DateTime requestedAt,
|
||||
TimeSpan maxReservationTimeSpan,
|
||||
string mailAddress,
|
||||
string code)
|
||||
{
|
||||
// Todo: Handle p_oFrom == null here.
|
||||
// Todo: Handle p_oDuration == null here.
|
||||
_InUseState = new StateRequestedInfo(
|
||||
dateTimeNowProvider ?? (() => DateTime.Now),
|
||||
requestedAt,
|
||||
maxReservationTimeSpan,
|
||||
mailAddress,
|
||||
code);
|
||||
}
|
||||
|
@ -81,9 +82,6 @@ namespace TINK.Model.State
|
|||
string p_strMailAddress,
|
||||
string p_strCode)
|
||||
{
|
||||
// Todo: Handle p_oFrom == null here.
|
||||
// Todo: Clearify question: What to do if code changes form one value to another? This should never happen.
|
||||
// Todo: Clearify question: What to do if from time changes form one value to another? This should never happen.
|
||||
_InUseState = new StateOccupiedInfo(
|
||||
p_oBookedAt,
|
||||
p_strMailAddress,
|
||||
|
@ -114,7 +112,7 @@ namespace TINK.Model.State
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Date of request/ bookeing action.
|
||||
/// Date of request/ booking action.
|
||||
/// </summary>
|
||||
public DateTime? From
|
||||
{
|
||||
|
@ -125,6 +123,14 @@ namespace TINK.Model.State
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Time span for which a bike can be reserved.
|
||||
/// </summary>
|
||||
public TimeSpan? MaxReservationTimeSpan =>
|
||||
_InUseState is StateRequestedInfo reserved
|
||||
? reserved.MaxReservationTimeSpan
|
||||
: (TimeSpan?)null;
|
||||
|
||||
/// <summary>
|
||||
/// Mail address.
|
||||
/// </summary>
|
||||
|
@ -152,7 +158,7 @@ namespace TINK.Model.State
|
|||
/// <summary>
|
||||
/// Tries update
|
||||
/// </summary>
|
||||
/// <returns>True if reservation span has not exeeded and state remains reserved, false otherwise.</returns>
|
||||
/// <returns>True if reservation span has not exceeded and state remains reserved, false otherwise.</returns>
|
||||
/// <todo>Implement logging of time stamps.</todo>
|
||||
public bool GetIsStillReserved(out TimeSpan? p_oRemainingTime)
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace TINK.Model.State
|
|||
{
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Manges the state of a bike.
|
||||
/// </summary>
|
||||
|
@ -90,19 +90,18 @@ namespace TINK.Model.State
|
|||
return new StateInfo(state != null ? state.Value == InUseStateEnum.FeedbackPending : false);
|
||||
|
||||
case InUseStateEnum.Reserved:
|
||||
// Todo: Handle p_oFrom == null here.
|
||||
// Todo: Handle p_oDuration == null here.
|
||||
return new StateInfo(
|
||||
dateTimeNowProvider,
|
||||
state.From.Value,
|
||||
state.From.HasValue ? dateTimeNowProvider : (() => DateTime.MaxValue),
|
||||
state.From.HasValue ? state.From.Value : DateTime.MaxValue,
|
||||
state.MaxReservationTimeSpan ?? StateRequestedInfo.UNKNOWNMAXRESERVATIONTIMESPAN,
|
||||
state.MailAddress,
|
||||
state.Code);
|
||||
|
||||
|
||||
case InUseStateEnum.Booked:
|
||||
// Todo: Handle p_oFrom == null here.
|
||||
// Todo: Clearify question: What to do if code changes form one value to another? This should never happen.
|
||||
// Todo: Clearify question: What to do if from time changes form one value to another? This should never happen.
|
||||
// Todo: Clarify question: What to do if code changes form one value to another? This should never happen.
|
||||
// Todo: Clarify question: What to do if from time changes form one value to another? This should never happen.
|
||||
return new StateInfo(
|
||||
state.From.Value,
|
||||
state.MailAddress,
|
||||
|
@ -139,7 +138,7 @@ namespace TINK.Model.State
|
|||
var l_oStateRequested = value as StateRequestedInfo;
|
||||
if (l_oStateRequested != null)
|
||||
{
|
||||
_StateInfo = new StateInfo(_DateTimeNowProvider, l_oStateRequested.From, l_oStateRequested.MailAddress, l_oStateRequested.Code);
|
||||
_StateInfo = new StateInfo(_DateTimeNowProvider, l_oStateRequested.From, l_oStateRequested.MaxReservationTimeSpan, l_oStateRequested.MailAddress, l_oStateRequested.Code);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -158,7 +157,7 @@ namespace TINK.Model.State
|
|||
/// <summary>
|
||||
/// Checks and updates state if required.
|
||||
/// </summary>
|
||||
/// <returns>Value indicating wheter state has changed</returns>
|
||||
/// <returns>Value indicating whether state has changed</returns>
|
||||
public void UpdateOnTimeElapsed()
|
||||
{
|
||||
switch (_StateInfo.Value)
|
||||
|
@ -172,7 +171,7 @@ namespace TINK.Model.State
|
|||
// Check if maximum reserved time has elapsed.
|
||||
if (!_StateInfo.GetIsStillReserved(out _RemainingTime))
|
||||
{
|
||||
// Time has elapsed, switch state to disposable and notfiy client
|
||||
// Time has elapsed, switch state to disposable and notify client
|
||||
_StateInfo = new StateInfo();
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(State)));
|
||||
return;
|
||||
|
@ -181,15 +180,17 @@ namespace TINK.Model.State
|
|||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(RemainingTime)));
|
||||
}
|
||||
|
||||
/// <summary> Updates state from webserver. </summary>
|
||||
/// <summary> Updates state from web server. </summary>
|
||||
/// <param name="state">State of the bike.</param>
|
||||
/// <param name="from">Date time when bike was reserved/ booked.</param>
|
||||
/// <param name="mailAddress">Mailaddress of the one which reserved/ booked.</param>
|
||||
/// <param name="maxReservationTimeSpan">Time span for which a bike can be reserved.</param>
|
||||
/// <param name="mailAddress">Mail address of the one which reserved/ booked.</param>
|
||||
/// <param name="code">Booking code if bike is booked or reserved.</param>
|
||||
/// <param name="supressNotifyPropertyChanged">Controls whether notify property changed events are fired or not.</param>
|
||||
public void Load(
|
||||
InUseStateEnum state,
|
||||
DateTime? from = null,
|
||||
TimeSpan? maxReservationTimeSpan = null,
|
||||
string mailAddress = null,
|
||||
string code = null,
|
||||
Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel notifyLevel = Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel.All)
|
||||
|
@ -206,11 +207,10 @@ namespace TINK.Model.State
|
|||
break;
|
||||
|
||||
case InUseStateEnum.Reserved:
|
||||
// Todo: Handle p_oFrom == null here.
|
||||
// Todo: Handle p_oDuration == null here.
|
||||
_StateInfo = new StateInfo(
|
||||
_DateTimeNowProvider,
|
||||
from.Value,
|
||||
from.HasValue ? _DateTimeNowProvider : (() => DateTime.MaxValue),
|
||||
from.HasValue ? from.Value : DateTime.MaxValue,
|
||||
maxReservationTimeSpan.HasValue ? maxReservationTimeSpan.Value : StateRequestedInfo.UNKNOWNMAXRESERVATIONTIMESPAN,
|
||||
mailAddress,
|
||||
code);
|
||||
|
||||
|
@ -245,7 +245,7 @@ namespace TINK.Model.State
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// If bike is reserved time raimaining while bike stays reserved, null otherwise.
|
||||
/// If bike is reserved time remaining while bike stays reserved, null otherwise.
|
||||
/// </summary>
|
||||
public TimeSpan? RemainingTime
|
||||
{
|
||||
|
@ -261,7 +261,7 @@ namespace TINK.Model.State
|
|||
|
||||
if (_RemainingTime.HasValue == false)
|
||||
{
|
||||
// Value was not yet querried.
|
||||
// Value was not yet queried.
|
||||
// Do query before returning object.
|
||||
_StateInfo.GetIsStillReserved(out _RemainingTime);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
@ -10,51 +10,63 @@ namespace TINK.Model.State
|
|||
[DataContract]
|
||||
public sealed class StateRequestedInfo : BaseState, IBaseState, INotAvailableState
|
||||
{
|
||||
// Maximum time while reserving request is kept.
|
||||
public static readonly TimeSpan MaximumReserveTime = new TimeSpan(0, 15, 0); // 15 mins
|
||||
/// <summary>
|
||||
/// Holds the value if time span is not known.
|
||||
/// </summary>
|
||||
/// <remarks> Default value see <see cref="TextToTypeHelper.DEFAULTMAXRESERVATIONTIMESPAN"/>. </remarks>
|
||||
public static TimeSpan UNKNOWNMAXRESERVATIONTIMESPAN = TimeSpan.Zero;
|
||||
|
||||
// Reference to date time provider.
|
||||
private Func<DateTime> _DateTimeNowProvider;
|
||||
private readonly Func<DateTime> _DateTimeNowProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Time span for which a bike can be reserved. Default value is zero.
|
||||
/// </summary>
|
||||
public TimeSpan MaxReservationTimeSpan { get; private set; } = UNKNOWNMAXRESERVATIONTIMESPAN;
|
||||
|
||||
/// <summary>
|
||||
/// Prevents an invalid instance to be created.
|
||||
/// Used by serializer only.
|
||||
/// </summary>
|
||||
private StateRequestedInfo() : base(InUseStateEnum.Reserved)
|
||||
internal StateRequestedInfo() : base(InUseStateEnum.Reserved)
|
||||
{
|
||||
// Is called in context of JSON deserialization.
|
||||
_DateTimeNowProvider = () => DateTime.Now;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reservation performed with other device/ before start of app.
|
||||
/// Date time info when bike was reserved has been received from webserver.
|
||||
/// Reservation performed with other device/ before start of app.
|
||||
/// Date time info when bike was reserved has been received from web server.
|
||||
/// </summary>
|
||||
/// <param name="p_oRemainingTime">Time span which holds duration how long bike still will be reserved.</param>
|
||||
/// <param name="maxReservationTimeSpan">Time span for which a bike can be reserved.</param>
|
||||
[JsonConstructor]
|
||||
private StateRequestedInfo(
|
||||
InUseStateEnum Value,
|
||||
DateTime From,
|
||||
TimeSpan maxReservationTimeSpan,
|
||||
string MailAddress,
|
||||
string Code) : this(() => DateTime.Now, From, MailAddress, Code)
|
||||
string Code) : this(() => DateTime.Now, From, maxReservationTimeSpan, MailAddress, Code)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reservation performed with other device/ before start of app.
|
||||
/// Date time info when bike was reserved has been received from webserver.
|
||||
/// Date time info when bike was reserved has been received from web server.
|
||||
/// </summary>
|
||||
/// <param name="dateTimeNowProvider">
|
||||
/// Used to to provide current date time information for potential calls of <seealso cref="GetIsStillReserved"/>.
|
||||
/// Not used to calculate remaining time because this duration whould always be shorter as the one received from webserver.
|
||||
/// Used to provide current date time information for potential calls of <seealso cref="GetIsStillReserved"/>.
|
||||
/// Not used to calculate remaining time because this duration would always be shorter as the one received from web server.
|
||||
/// </param>
|
||||
/// <param name="maxReservationTimeSpan">Time span for which a bike can be reserved.</param>
|
||||
public StateRequestedInfo(
|
||||
Func<DateTime> dateTimeNowProvider,
|
||||
DateTime from,
|
||||
TimeSpan maxReservationTimeSpan,
|
||||
string mailAddress,
|
||||
string code) : base(InUseStateEnum.Reserved)
|
||||
{
|
||||
_DateTimeNowProvider = dateTimeNowProvider ?? (() => DateTime.Now);
|
||||
MaxReservationTimeSpan = maxReservationTimeSpan;
|
||||
From = from;
|
||||
MailAddress = mailAddress;
|
||||
Code = code;
|
||||
|
@ -63,34 +75,28 @@ namespace TINK.Model.State
|
|||
/// <summary>
|
||||
/// Tries update
|
||||
/// </summary>
|
||||
/// <returns>True if reservation span has not exeeded and state remains reserved, false otherwise.</returns>
|
||||
/// <returns>True if reservation span has not exceeded and state remains reserved, false otherwise.</returns>
|
||||
/// <todo>Implement logging of time stamps.</todo>
|
||||
public bool GetIsStillReserved(out TimeSpan? p_oRemainingTime)
|
||||
public bool GetIsStillReserved(out TimeSpan? remainingTime)
|
||||
{
|
||||
var l_oTimeReserved = _DateTimeNowProvider().Subtract(From);
|
||||
if (l_oTimeReserved > MaximumReserveTime)
|
||||
var timeReserved = _DateTimeNowProvider().Subtract(From);
|
||||
if (timeReserved > MaxReservationTimeSpan)
|
||||
|
||||
{
|
||||
// Reservation has elapsed. To not update remaining time.
|
||||
p_oRemainingTime = null;
|
||||
// Reservation has elapsed. Do not update remaining time.
|
||||
remainingTime = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
p_oRemainingTime = MaximumReserveTime - l_oTimeReserved;
|
||||
remainingTime = MaxReservationTimeSpan - timeReserved;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// State reserved.
|
||||
/// Setter exists only for serialization purposes.
|
||||
/// State reserved.
|
||||
/// </summary>
|
||||
public override InUseStateEnum Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return InUseStateEnum.Reserved;
|
||||
}
|
||||
}
|
||||
public override InUseStateEnum Value =>
|
||||
InUseStateEnum.Reserved;
|
||||
|
||||
/// <summary>
|
||||
/// Date time when bike was reserved.
|
||||
|
|
|
@ -692,6 +692,11 @@ namespace TINK.Model
|
|||
AppResources.ChangeLog_3_0_365_MK_SB,
|
||||
new List<AppFlavor> { AppFlavor.MeinKonrad, AppFlavor.ShareeBike }
|
||||
},
|
||||
{
|
||||
new Version(3, 0, 366),
|
||||
AppResources.ChangeLog_3_0_366_MK_SB,
|
||||
new List<AppFlavor> { AppFlavor.MeinKonrad, AppFlavor.ShareeBike }
|
||||
},
|
||||
};
|
||||
|
||||
/// <summary> Manges the whats new information.</summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue