Version 3.0.338

This commit is contained in:
Anja Müller-Meißner 2022-09-06 16:08:19 +02:00 committed by Anja
parent 573fe77e12
commit 0468955d49
751 changed files with 62747 additions and 60672 deletions

View file

@ -2,23 +2,23 @@
namespace TINK.Model.State
{
/// <summary>
/// Base type for serialization purposes.
/// </summary>
[DataContract]
[KnownType(typeof(StateFeedbackPendingInfo))]
[KnownType(typeof(StateAvailableInfo))]
[KnownType(typeof(StateRequestedInfo))]
[KnownType(typeof(StateOccupiedInfo))]
public abstract class BaseState
{
/// <summary> Constructor for Json serialization. </summary>
/// <param name="value">State value.</param>
protected BaseState(InUseStateEnum value) { }
/// <summary>
/// Base type for serialization purposes.
/// </summary>
[DataContract]
[KnownType(typeof(StateFeedbackPendingInfo))]
[KnownType(typeof(StateAvailableInfo))]
[KnownType(typeof(StateRequestedInfo))]
[KnownType(typeof(StateOccupiedInfo))]
public abstract class BaseState
{
/// <summary> Constructor for Json serialization. </summary>
/// <param name="value">State value.</param>
protected BaseState(InUseStateEnum value) { }
/// <summary>
/// Holds the state value.
/// </summary>
public abstract InUseStateEnum Value { get; }
}
/// <summary>
/// Holds the state value.
/// </summary>
public abstract InUseStateEnum Value { get; }
}
}

View file

@ -1,11 +1,11 @@

namespace TINK.Model.State
{
/// <summary>
/// Base state information.
/// </summary>
public interface IBaseState
{
InUseStateEnum Value { get; }
}
/// <summary>
/// Base state information.
/// </summary>
public interface IBaseState
{
InUseStateEnum Value { get; }
}
}

View file

@ -2,13 +2,13 @@
namespace TINK.Model.State
{
/// <summary>
/// State of bikes which are either reserved or booked.
/// </summary>
public interface INotAvailableState : IBaseState
{
DateTime From { get; }
string MailAddress { get; }
string Code { get; }
}
/// <summary>
/// State of bikes which are either reserved or booked.
/// </summary>
public interface INotAvailableState : IBaseState
{
DateTime From { get; }
string MailAddress { get; }
string Code { get; }
}
}

View file

@ -2,15 +2,15 @@
namespace TINK.Model.State
{
/// <summary>
/// Interface to access informations about bike information.
/// </summary>
public interface IStateInfo : IBaseState
{
string MailAddress { get; }
/// <summary>
/// Interface to access informations about bike information.
/// </summary>
public interface IStateInfo : IBaseState
{
string MailAddress { get; }
DateTime? From { get; }
DateTime? From { get; }
string Code { get; }
}
string Code { get; }
}
}

View file

@ -2,21 +2,21 @@
namespace TINK.Model.State
{
public interface IStateInfoMutable
{
InUseStateEnum Value { get; }
public interface IStateInfoMutable
{
InUseStateEnum Value { get; }
/// <summary> Updates state from webserver. </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="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,
string mailAddress = null,
string code = null,
Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel notifyLevel = Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel.All);
}
/// <summary> Updates state from webserver. </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="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,
string mailAddress = null,
string code = null,
Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel notifyLevel = Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel.All);
}
}

View file

@ -3,26 +3,26 @@ using Newtonsoft.Json;
namespace TINK.Model.State
{
/// <summary>
/// Represents the state available.
/// </summary>
[DataContract]
public sealed class StateAvailableInfo : BaseState, IBaseState
{
/// <summary>
/// Constructs state info object representing state available.
/// </summary>
public StateAvailableInfo() : base(InUseStateEnum.Disposable) { }
/// <summary>
/// Represents the state available.
/// </summary>
[DataContract]
public sealed class StateAvailableInfo : BaseState, IBaseState
{
/// <summary>
/// Constructs state info object representing state available.
/// </summary>
public StateAvailableInfo() : base(InUseStateEnum.Disposable) { }
/// <summary> Constructor for Json serialization. </summary>
/// <param name="value">Unused value.</param>
[JsonConstructor]
private StateAvailableInfo(InUseStateEnum value) : base(InUseStateEnum.Disposable) { }
/// <summary> Constructor for Json serialization. </summary>
/// <param name="value">Unused value.</param>
[JsonConstructor]
private StateAvailableInfo(InUseStateEnum value) : base(InUseStateEnum.Disposable) { }
/// <summary>
/// Gets the info that state is disposable.
/// Setter exists only for serialization purposes.
/// </summary>
public override InUseStateEnum Value => InUseStateEnum.Disposable;
}
/// <summary>
/// Gets the info that state is disposable.
/// Setter exists only for serialization purposes.
/// </summary>
public override InUseStateEnum Value => InUseStateEnum.Disposable;
}
}

View file

@ -3,26 +3,26 @@ using Newtonsoft.Json;
namespace TINK.Model.State
{
/// <summary>
/// Represents the state feedback pending.
/// </summary>
[DataContract]
public sealed class StateFeedbackPendingInfo : BaseState, IBaseState
{
/// <summary>
/// Constructs state info object representing feedback pending.
/// </summary>
public StateFeedbackPendingInfo() : base(InUseStateEnum.FeedbackPending) { }
/// <summary>
/// Represents the state feedback pending.
/// </summary>
[DataContract]
public sealed class StateFeedbackPendingInfo : BaseState, IBaseState
{
/// <summary>
/// Constructs state info object representing feedback pending.
/// </summary>
public StateFeedbackPendingInfo() : base(InUseStateEnum.FeedbackPending) { }
/// <summary> Constructor for Json serialization. </summary>
/// <param name="value">Unused value.</param>
[JsonConstructor]
private StateFeedbackPendingInfo(InUseStateEnum value) : base(InUseStateEnum.FeedbackPending) { }
/// <summary> Constructor for Json serialization. </summary>
/// <param name="value">Unused value.</param>
[JsonConstructor]
private StateFeedbackPendingInfo(InUseStateEnum value) : base(InUseStateEnum.FeedbackPending) { }
/// <summary>
/// Gets the info that state is disposable.
/// Setter exists only for serialization purposes.
/// </summary>
public override InUseStateEnum Value => InUseStateEnum.FeedbackPending;
}
/// <summary>
/// Gets the info that state is disposable.
/// Setter exists only for serialization purposes.
/// </summary>
public override InUseStateEnum Value => InUseStateEnum.FeedbackPending;
}
}

View file

@ -2,168 +2,168 @@
namespace TINK.Model.State
{
/// <summary>
/// Types of rent states
/// </summary>
public enum InUseStateEnum
{
/// <summary>
/// Bike was returned but no feedback given.
/// This applies to COPRI locks only because returning of bike is not done using app (Status: Supported locks are ILockIt and COPRI).
/// </summary>
FeedbackPending,
/// <summary>
/// Types of rent states
/// </summary>
public enum InUseStateEnum
{
/// <summary>
/// Bike was returned but no feedback given.
/// This applies to COPRI locks only because returning of bike is not done using app (Status: Supported locks are ILockIt and COPRI).
/// </summary>
FeedbackPending,
/// <summary>
/// Bike is not in use. Corresponding COPRI state is "available".
/// </summary>
Disposable,
/// <summary>
/// Bike is not in use. Corresponding COPRI state is "available".
/// </summary>
Disposable,
/// <summary>
/// Bike is reserved. Corresponding COPRI state is "requested".
/// </summary>
Reserved,
/// <summary>
/// Bike is reserved. Corresponding COPRI state is "requested".
/// </summary>
Reserved,
/// <summary>
/// Bike is booked. Corresponding COPRI statie is "occupied".
/// </summary>
Booked
}
/// <summary>
/// Bike is booked. Corresponding COPRI statie is "occupied".
/// </summary>
Booked
}
/// <summary>
/// Manages the state of a bike.
/// </summary>
public class StateInfo : IStateInfo
{
// Holds the current disposable state value.
private readonly BaseState _InUseState;
/// <summary>
/// Manages the state of a bike.
/// </summary>
public class StateInfo : IStateInfo
{
// Holds the current disposable state value.
private readonly BaseState _InUseState;
/// <summary>
/// Constructs a state info object when state is available.
/// </summary>
/// <param name="isFeedbackPending">Specifieds whether feedback is pending or not.</param>
public StateInfo(bool isFeedbackPending = false)
{
_InUseState = isFeedbackPending
? (BaseState)new StateFeedbackPendingInfo()
: new StateAvailableInfo();
}
/// <summary>
/// Constructs a state info object when state is available.
/// </summary>
/// <param name="isFeedbackPending">Specifieds whether feedback is pending or not.</param>
public StateInfo(bool isFeedbackPending = false)
{
_InUseState = isFeedbackPending
? (BaseState)new StateFeedbackPendingInfo()
: new StateAvailableInfo();
}
/// <summary>
/// Constructs a state info object when state is requested.
/// </summary>
/// <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="dateTimeNowProvider">Date time provider to calculate reaining time.</param>
public StateInfo(
Func<DateTime> dateTimeNowProvider,
DateTime requestedAt,
string mailAddress,
string code)
{
// Todo: Handle p_oFrom == null here.
// Todo: Handle p_oDuration == null here.
_InUseState = new StateRequestedInfo(
dateTimeNowProvider ?? (() => DateTime.Now),
requestedAt,
mailAddress,
code);
}
/// <summary>
/// Constructs a state info object when state is requested.
/// </summary>
/// <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="dateTimeNowProvider">Date time provider to calculate reaining time.</param>
public StateInfo(
Func<DateTime> dateTimeNowProvider,
DateTime requestedAt,
string mailAddress,
string code)
{
// Todo: Handle p_oFrom == null here.
// Todo: Handle p_oDuration == null here.
_InUseState = new StateRequestedInfo(
dateTimeNowProvider ?? (() => DateTime.Now),
requestedAt,
mailAddress,
code);
}
/// <summary>
/// Constructs a state info object when state is booked.
/// </summary>
/// <param name="p_oBookedAt">Date time when bike was booked</param>
/// <param name="p_strMailAddress">Mail address of user which booked bike.</param>
/// <param name="p_strCode">Booking code.</param>
public StateInfo(
DateTime p_oBookedAt,
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,
p_strCode);
}
/// <summary>
/// Constructs a state info object when state is booked.
/// </summary>
/// <param name="p_oBookedAt">Date time when bike was booked</param>
/// <param name="p_strMailAddress">Mail address of user which booked bike.</param>
/// <param name="p_strCode">Booking code.</param>
public StateInfo(
DateTime p_oBookedAt,
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,
p_strCode);
}
/// <summary>
/// Gets the state value of object.
/// </summary>
public InUseStateEnum Value
{
get { return _InUseState.Value; }
}
/// <summary>
/// Gets the state value of object.
/// </summary>
public InUseStateEnum Value
{
get { return _InUseState.Value; }
}
/// <summary>
/// Member for serialization purposes.
/// </summary>
internal BaseState StateInfoObject
{
get { return _InUseState; }
}
/// Transforms object to string.
/// </summary>
/// <returns></returns>
public new string ToString()
{
return _InUseState.Value.ToString("g");
}
/// <summary>
/// Member for serialization purposes.
/// </summary>
internal BaseState StateInfoObject
{
get { return _InUseState; }
}
/// Transforms object to string.
/// </summary>
/// <returns></returns>
public new string ToString()
{
return _InUseState.Value.ToString("g");
}
/// <summary>
/// Date of request/ bookeing action.
/// </summary>
public DateTime? From
{
get
{
var l_oNotDisposableInfo = _InUseState as INotAvailableState;
return l_oNotDisposableInfo != null ? l_oNotDisposableInfo.From : (DateTime?)null;
}
}
/// <summary>
/// Date of request/ bookeing action.
/// </summary>
public DateTime? From
{
get
{
var l_oNotDisposableInfo = _InUseState as INotAvailableState;
return l_oNotDisposableInfo != null ? l_oNotDisposableInfo.From : (DateTime?)null;
}
}
/// <summary>
/// Mail address.
/// </summary>
public string MailAddress
{
get
{
var l_oNotDisposableInfo = _InUseState as INotAvailableState;
return l_oNotDisposableInfo?.MailAddress;
}
}
/// <summary>
/// Mail address.
/// </summary>
public string MailAddress
{
get
{
var l_oNotDisposableInfo = _InUseState as INotAvailableState;
return l_oNotDisposableInfo?.MailAddress;
}
}
/// <summary>
/// Reservation code.
/// </summary>
public string Code
{
get
{
var l_oNotDisposableInfo = _InUseState as INotAvailableState;
return l_oNotDisposableInfo?.Code;
}
}
/// <summary>
/// Reservation code.
/// </summary>
public string Code
{
get
{
var l_oNotDisposableInfo = _InUseState as INotAvailableState;
return l_oNotDisposableInfo?.Code;
}
}
/// <summary>
/// Tries update
/// </summary>
/// <returns>True if reservation span has not exeeded and state remains reserved, false otherwise.</returns>
/// <todo>Implement logging of time stamps.</todo>
public bool GetIsStillReserved(out TimeSpan? p_oRemainingTime)
{
var l_oReservedInfo = _InUseState as StateRequestedInfo;
if (l_oReservedInfo == null)
{
p_oRemainingTime = null;
return false;
}
/// <summary>
/// Tries update
/// </summary>
/// <returns>True if reservation span has not exeeded and state remains reserved, false otherwise.</returns>
/// <todo>Implement logging of time stamps.</todo>
public bool GetIsStillReserved(out TimeSpan? p_oRemainingTime)
{
var l_oReservedInfo = _InUseState as StateRequestedInfo;
if (l_oReservedInfo == null)
{
p_oRemainingTime = null;
return false;
}
return l_oReservedInfo.GetIsStillReserved(out p_oRemainingTime);
}
}
return l_oReservedInfo.GetIsStillReserved(out p_oRemainingTime);
}
}
}

View file

@ -1,13 +1,13 @@
namespace TINK.Model.State
{
public static class StateInfoHelper
{
/// <summary>
/// Gets whether bike is available or occupied, i.e. reserved or booked.
/// </summary>
/// <param name="state">State to be info from.</param>
/// <returns>True if bike is reserved to booked.</returns>
public static bool IsOccupied(this InUseStateEnum state)
=> state != InUseStateEnum.Disposable && state != InUseStateEnum.FeedbackPending;
}
public static class StateInfoHelper
{
/// <summary>
/// Gets whether bike is available or occupied, i.e. reserved or booked.
/// </summary>
/// <param name="state">State to be info from.</param>
/// <returns>True if bike is reserved to booked.</returns>
public static bool IsOccupied(this InUseStateEnum state)
=> state != InUseStateEnum.Disposable && state != InUseStateEnum.FeedbackPending;
}
}

View file

@ -2,296 +2,296 @@
namespace TINK.Model.State
{
using System.ComponentModel;
using System.Runtime.Serialization;
using System.ComponentModel;
using System.Runtime.Serialization;
/// <summary>
/// Manges the state of a bike.
/// </summary>
[DataContract]
public class StateInfoMutable : INotifyPropertyChanged, IStateInfoMutable
{
/// <summary>
/// Provider for current date time to calculate remainig time on demand for state of type reserved.
/// </summary>
private readonly Func<DateTime> _DateTimeNowProvider;
/// <summary>
/// Manges the state of a bike.
/// </summary>
[DataContract]
public class StateInfoMutable : INotifyPropertyChanged, IStateInfoMutable
{
/// <summary>
/// Provider for current date time to calculate remainig time on demand for state of type reserved.
/// </summary>
private readonly Func<DateTime> _DateTimeNowProvider;
// Holds the current disposable state value
private StateInfo _StateInfo;
// Holds the current disposable state value
private StateInfo _StateInfo;
/// <summary>
/// Backs up remaining time of child object.
/// </summary>
private TimeSpan? _RemainingTime = null;
/// <summary>
/// Backs up remaining time of child object.
/// </summary>
private TimeSpan? _RemainingTime = null;
/// <summary> Notifies clients about state changes. </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary> Notifies clients about state changes. </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Constructs a state object from source.
/// </summary>
/// <param name="state">State info to load from.</param>
public StateInfoMutable(
Func<DateTime> dateTimeNowProvider = null,
IStateInfo state = null)
{
// Back up date time provider to be able to pass this to requested- object if state changes to requested.
_DateTimeNowProvider = dateTimeNowProvider != null
? dateTimeNowProvider
: () => DateTime.Now;
/// <summary>
/// Constructs a state object from source.
/// </summary>
/// <param name="state">State info to load from.</param>
public StateInfoMutable(
Func<DateTime> dateTimeNowProvider = null,
IStateInfo state = null)
{
// Back up date time provider to be able to pass this to requested- object if state changes to requested.
_DateTimeNowProvider = dateTimeNowProvider != null
? dateTimeNowProvider
: () => DateTime.Now;
_StateInfo = Create(state, dateTimeNowProvider);
}
_StateInfo = Create(state, dateTimeNowProvider);
}
/// <summary>
/// Loads state from immutable source.
/// </summary>
/// <param name="state">State to load from.</param>
public void Load(IStateInfo state)
{
if (state == null)
{
throw new ArgumentException("Can not load state info, object must not be null.");
}
/// <summary>
/// Loads state from immutable source.
/// </summary>
/// <param name="state">State to load from.</param>
public void Load(IStateInfo state)
{
if (state == null)
{
throw new ArgumentException("Can not load state info, object must not be null.");
}
// Back up last state value and remaining time value
// to be able to check whether an event has to be fired or not.
var l_oLastState = Value;
var l_oLastRemainingTime = _RemainingTime;
// Back up last state value and remaining time value
// to be able to check whether an event has to be fired or not.
var l_oLastState = Value;
var l_oLastRemainingTime = _RemainingTime;
// Create new state info object from source.
_StateInfo = Create(state, _DateTimeNowProvider);
// Create new state info object from source.
_StateInfo = Create(state, _DateTimeNowProvider);
// Update remaining time value.
_StateInfo.GetIsStillReserved(out _RemainingTime);
// Update remaining time value.
_StateInfo.GetIsStillReserved(out _RemainingTime);
if (l_oLastState == _StateInfo.Value
&& l_oLastRemainingTime == _RemainingTime)
{
return;
}
if (l_oLastState == _StateInfo.Value
&& l_oLastRemainingTime == _RemainingTime)
{
return;
}
// State has changed, notify clients.
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(State)));
}
// State has changed, notify clients.
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(State)));
}
/// <summary>
/// Creates a state info object.
/// </summary>
/// <param name="state">State to load from.</param>
private static StateInfo Create(
IStateInfo state,
Func<DateTime> dateTimeNowProvider)
{
switch (state != null ? state.Value : InUseStateEnum.Disposable)
{
case InUseStateEnum.Disposable:
case InUseStateEnum.FeedbackPending:
return new StateInfo(state != null ? state.Value == InUseStateEnum.FeedbackPending : false);
/// <summary>
/// Creates a state info object.
/// </summary>
/// <param name="state">State to load from.</param>
private static StateInfo Create(
IStateInfo state,
Func<DateTime> dateTimeNowProvider)
{
switch (state != null ? state.Value : InUseStateEnum.Disposable)
{
case InUseStateEnum.Disposable:
case InUseStateEnum.FeedbackPending:
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.MailAddress,
state.Code);
case InUseStateEnum.Reserved:
// Todo: Handle p_oFrom == null here.
// Todo: Handle p_oDuration == null here.
return new StateInfo(
dateTimeNowProvider,
state.From.Value,
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.
return new StateInfo(
state.From.Value,
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.
return new StateInfo(
state.From.Value,
state.MailAddress,
state.Code);
default:
// Todo: New state Busy has to be defined.
throw new Exception(string.Format("Can not create new state info object. Unknown state {0} detected.", state.Value));
}
}
default:
// Todo: New state Busy has to be defined.
throw new Exception(string.Format("Can not create new state info object. Unknown state {0} detected.", state.Value));
}
}
/// <summary>
/// Gets the state value of object.
/// </summary>
public InUseStateEnum Value
=> _StateInfo.Value;
/// <summary>
/// Gets the state value of object.
/// </summary>
public InUseStateEnum Value
=> _StateInfo.Value;
/// <summary>
/// Member for serialization purposes.
/// </summary>
[DataMember]
private BaseState StateInfoObject
{
get { return _StateInfo.StateInfoObject; }
set
{
var l_oStateOccupied = value as StateOccupiedInfo;
if (l_oStateOccupied != null)
{
_StateInfo = new StateInfo(l_oStateOccupied.From, l_oStateOccupied.MailAddress, l_oStateOccupied.Code);
return;
}
/// <summary>
/// Member for serialization purposes.
/// </summary>
[DataMember]
private BaseState StateInfoObject
{
get { return _StateInfo.StateInfoObject; }
set
{
var l_oStateOccupied = value as StateOccupiedInfo;
if (l_oStateOccupied != null)
{
_StateInfo = new StateInfo(l_oStateOccupied.From, l_oStateOccupied.MailAddress, l_oStateOccupied.Code);
return;
}
var l_oStateRequested = value as StateRequestedInfo;
if (l_oStateRequested != null)
{
_StateInfo = new StateInfo(_DateTimeNowProvider, l_oStateRequested.From, l_oStateRequested.MailAddress, l_oStateRequested.Code);
return;
}
var l_oStateRequested = value as StateRequestedInfo;
if (l_oStateRequested != null)
{
_StateInfo = new StateInfo(_DateTimeNowProvider, l_oStateRequested.From, l_oStateRequested.MailAddress, l_oStateRequested.Code);
return;
}
_StateInfo = new StateInfo();
_StateInfo = new StateInfo();
}
}
/// Transforms object to string.
/// </summary>
/// <returns></returns>
public new string ToString()
{
return _StateInfo.ToString();
}
}
}
/// Transforms object to string.
/// </summary>
/// <returns></returns>
public new string ToString()
{
return _StateInfo.ToString();
}
/// <summary>
/// Checks and updates state if required.
/// </summary>
/// <returns>Value indicating wheter state has changed</returns>
public void UpdateOnTimeElapsed()
{
switch (_StateInfo.Value)
{
// State is disposable or booked. No need to update "OnTimeElapsed"
case InUseStateEnum.Disposable:
case InUseStateEnum.Booked:
return;
}
/// <summary>
/// Checks and updates state if required.
/// </summary>
/// <returns>Value indicating wheter state has changed</returns>
public void UpdateOnTimeElapsed()
{
switch (_StateInfo.Value)
{
// State is disposable or booked. No need to update "OnTimeElapsed"
case InUseStateEnum.Disposable:
case InUseStateEnum.Booked:
return;
}
// Check if maximum reserved time has elapsed.
if (!_StateInfo.GetIsStillReserved(out _RemainingTime))
{
// Time has elapsed, switch state to disposable and notfiy client
_StateInfo = new StateInfo();
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(State)));
return;
}
// Check if maximum reserved time has elapsed.
if (!_StateInfo.GetIsStillReserved(out _RemainingTime))
{
// Time has elapsed, switch state to disposable and notfiy client
_StateInfo = new StateInfo();
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(State)));
return;
}
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(RemainingTime)));
}
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(RemainingTime)));
}
/// <summary> Updates state from webserver. </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="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,
string mailAddress = null,
string code = null,
Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel notifyLevel = Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel.All)
{
var lastState = _StateInfo.Value;
/// <summary> Updates state from webserver. </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="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,
string mailAddress = null,
string code = null,
Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel notifyLevel = Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel.All)
{
var lastState = _StateInfo.Value;
switch (state)
{
case InUseStateEnum.Disposable:
_StateInfo = new StateInfo();
switch (state)
{
case InUseStateEnum.Disposable:
_StateInfo = new StateInfo();
// Set value to null. Otherwise potentially obsolete value will be taken remaining time.
_RemainingTime = null;
break;
// Set value to null. Otherwise potentially obsolete value will be taken remaining time.
_RemainingTime = null;
break;
case InUseStateEnum.Reserved:
// Todo: Handle p_oFrom == null here.
// Todo: Handle p_oDuration == null here.
_StateInfo = new StateInfo(
_DateTimeNowProvider,
from.Value,
mailAddress,
code);
case InUseStateEnum.Reserved:
// Todo: Handle p_oFrom == null here.
// Todo: Handle p_oDuration == null here.
_StateInfo = new StateInfo(
_DateTimeNowProvider,
from.Value,
mailAddress,
code);
// Set value to null. Otherwise potentially obsolete value will be taken remaining time.
_RemainingTime = null;
break;
// Set value to null. Otherwise potentially obsolete value will be taken remaining time.
_RemainingTime = null;
break;
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.
_StateInfo = new StateInfo(
from.Value,
mailAddress,
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.
_StateInfo = new StateInfo(
from.Value,
mailAddress,
code);
// Set value to null. Otherwise potentially obsolete value will be taken remaining time.
_RemainingTime = null;
break;
// Set value to null. Otherwise potentially obsolete value will be taken remaining time.
_RemainingTime = null;
break;
default:
// Todo: New state Busy has to be defined.
break;
}
default:
// Todo: New state Busy has to be defined.
break;
}
if (lastState != _StateInfo.Value
&& notifyLevel == Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel.All)
{
// State has changed, notify clients.
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(State)));
}
}
if (lastState != _StateInfo.Value
&& notifyLevel == Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel.All)
{
// State has changed, notify clients.
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(State)));
}
}
/// <summary>
/// If bike is reserved time raimaining while bike stays reserved, null otherwise.
/// </summary>
public TimeSpan? RemainingTime
{
get
{
switch (_StateInfo.Value)
{
// State is either available or occupied.
case InUseStateEnum.Disposable:
case InUseStateEnum.Booked:
return null;
}
/// <summary>
/// If bike is reserved time raimaining while bike stays reserved, null otherwise.
/// </summary>
public TimeSpan? RemainingTime
{
get
{
switch (_StateInfo.Value)
{
// State is either available or occupied.
case InUseStateEnum.Disposable:
case InUseStateEnum.Booked:
return null;
}
if (_RemainingTime.HasValue == false)
{
// Value was not yet querried.
// Do querry before returning object.
_StateInfo.GetIsStillReserved(out _RemainingTime);
}
if (_RemainingTime.HasValue == false)
{
// Value was not yet querried.
// Do querry before returning object.
_StateInfo.GetIsStillReserved(out _RemainingTime);
}
return _RemainingTime;
}
}
return _RemainingTime;
}
}
public DateTime? From
{
get
{
return _StateInfo.From;
}
}
public DateTime? From
{
get
{
return _StateInfo.From;
}
}
public string MailAddress
{
get
{
return _StateInfo.MailAddress;
}
}
public string MailAddress
{
get
{
return _StateInfo.MailAddress;
}
}
public string Code
{
get
{
return _StateInfo.Code;
}
}
}
public string Code
{
get
{
return _StateInfo.Code;
}
}
}
}

View file

@ -4,77 +4,77 @@ using Newtonsoft.Json;
namespace TINK.Model.State
{
/// <summary>
/// Manages state booked.
/// </summary>
[DataContract]
public sealed class StateOccupiedInfo : BaseState, IBaseState, INotAvailableState
{
/// <summary>
/// Prevents an invalid instance to be created.
/// </summary>
private StateOccupiedInfo() : base(InUseStateEnum.Booked)
{
}
/// <summary>
/// Manages state booked.
/// </summary>
[DataContract]
public sealed class StateOccupiedInfo : BaseState, IBaseState, INotAvailableState
{
/// <summary>
/// Prevents an invalid instance to be created.
/// </summary>
private StateOccupiedInfo() : base(InUseStateEnum.Booked)
{
}
/// <summary>
/// Constructs an object holding booked state info.
/// </summary>
/// <param name="p_oFrom">Date time when bike was booked</param>
/// <param name="p_strMailAddress"></param>
/// <param name="p_strCode"></param>
public StateOccupiedInfo(
DateTime p_oFrom,
string p_strMailAddress,
string p_strCode) : base(InUseStateEnum.Booked)
{
From = p_oFrom;
MailAddress = p_strMailAddress;
Code = p_strCode;
}
/// <summary>
/// Constructs an object holding booked state info.
/// </summary>
/// <param name="p_oFrom">Date time when bike was booked</param>
/// <param name="p_strMailAddress"></param>
/// <param name="p_strCode"></param>
public StateOccupiedInfo(
DateTime p_oFrom,
string p_strMailAddress,
string p_strCode) : base(InUseStateEnum.Booked)
{
From = p_oFrom;
MailAddress = p_strMailAddress;
Code = p_strCode;
}
/// <summary> Constructor for Json serialization. </summary>
/// <param name="Value">Unused value.</param>
/// <param name="From">Date time when bike was booked</param>
/// <param name="MailAddress"></param>
/// <param name="Code"></param>
[JsonConstructor]
private StateOccupiedInfo(
InUseStateEnum Value,
DateTime From,
string MailAddress,
string Code) : this(From, MailAddress, Code)
{
}
/// <summary> Constructor for Json serialization. </summary>
/// <param name="Value">Unused value.</param>
/// <param name="From">Date time when bike was booked</param>
/// <param name="MailAddress"></param>
/// <param name="Code"></param>
[JsonConstructor]
private StateOccupiedInfo(
InUseStateEnum Value,
DateTime From,
string MailAddress,
string Code) : this(From, MailAddress, Code)
{
}
/// <summary>
/// Gets the info that state is reserved.
/// Setter exists only for serialization purposes.
/// </summary>
public override InUseStateEnum Value
{
get
{
return InUseStateEnum.Booked;
}
}
/// <summary>
/// Gets the info that state is reserved.
/// Setter exists only for serialization purposes.
/// </summary>
public override InUseStateEnum Value
{
get
{
return InUseStateEnum.Booked;
}
}
/// <summary>
/// Prevents an invalid instance to be created.
/// </summary>
[DataMember]
public DateTime From { get; }
/// <summary>
/// Prevents an invalid instance to be created.
/// </summary>
[DataMember]
public DateTime From { get; }
/// <summary>
/// Mail address of user who bookec the bike.
/// </summary>
[DataMember]
public string MailAddress { get; }
/// <summary>
/// Mail address of user who bookec the bike.
/// </summary>
[DataMember]
public string MailAddress { get; }
/// <summary>
/// Booking code.
/// </summary>
[DataMember]
public string Code { get; }
}
/// <summary>
/// Booking code.
/// </summary>
[DataMember]
public string Code { get; }
}
}

View file

@ -4,110 +4,110 @@ using Newtonsoft.Json;
namespace TINK.Model.State
{
/// <summary>
/// Manages state reserved.
/// </summary>
[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>
/// Manages state reserved.
/// </summary>
[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
// Reference to date time provider.
private Func<DateTime> _DateTimeNowProvider;
// Reference to date time provider.
private Func<DateTime> _DateTimeNowProvider;
/// <summary>
/// Prevents an invalid instance to be created.
/// Used by serializer only.
/// </summary>
private StateRequestedInfo() : base(InUseStateEnum.Reserved)
{
// Is called in context of JSON deserialization.
_DateTimeNowProvider = () => DateTime.Now;
}
/// <summary>
/// Prevents an invalid instance to be created.
/// Used by serializer only.
/// </summary>
private 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.
/// </summary>
/// <param name="p_oRemainingTime">Time span which holds duration how long bike still will be reserved.</param>
[JsonConstructor]
private StateRequestedInfo(
InUseStateEnum Value,
DateTime From,
string MailAddress,
string Code) : this(() => DateTime.Now, From, MailAddress, Code)
{
}
/// <summary>
/// Reservation performed with other device/ before start of app.
/// Date time info when bike was reserved has been received from webserver.
/// </summary>
/// <param name="p_oRemainingTime">Time span which holds duration how long bike still will be reserved.</param>
[JsonConstructor]
private StateRequestedInfo(
InUseStateEnum Value,
DateTime From,
string MailAddress,
string Code) : this(() => DateTime.Now, From, MailAddress, Code)
{
}
/// <summary>
/// Reservation performed with other device/ before start of app.
/// Date time info when bike was reserved has been received from webserver.
/// </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.
/// </param>
public StateRequestedInfo(
Func<DateTime> dateTimeNowProvider,
DateTime from,
string mailAddress,
string code) : base(InUseStateEnum.Reserved)
{
_DateTimeNowProvider = dateTimeNowProvider ?? (() => DateTime.Now);
From = from;
MailAddress = mailAddress;
Code = code;
}
/// <summary>
/// Reservation performed with other device/ before start of app.
/// Date time info when bike was reserved has been received from webserver.
/// </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.
/// </param>
public StateRequestedInfo(
Func<DateTime> dateTimeNowProvider,
DateTime from,
string mailAddress,
string code) : base(InUseStateEnum.Reserved)
{
_DateTimeNowProvider = dateTimeNowProvider ?? (() => DateTime.Now);
From = from;
MailAddress = mailAddress;
Code = code;
}
/// <summary>
/// Tries update
/// </summary>
/// <returns>True if reservation span has not exeeded and state remains reserved, false otherwise.</returns>
/// <todo>Implement logging of time stamps.</todo>
public bool GetIsStillReserved(out TimeSpan? p_oRemainingTime)
{
var l_oTimeReserved = _DateTimeNowProvider().Subtract(From);
if (l_oTimeReserved > MaximumReserveTime)
/// <summary>
/// Tries update
/// </summary>
/// <returns>True if reservation span has not exeeded and state remains reserved, false otherwise.</returns>
/// <todo>Implement logging of time stamps.</todo>
public bool GetIsStillReserved(out TimeSpan? p_oRemainingTime)
{
var l_oTimeReserved = _DateTimeNowProvider().Subtract(From);
if (l_oTimeReserved > MaximumReserveTime)
{
// Reservation has elapsed. To not update remaining time.
p_oRemainingTime = null;
return false;
}
{
// Reservation has elapsed. To not update remaining time.
p_oRemainingTime = null;
return false;
}
p_oRemainingTime = MaximumReserveTime - l_oTimeReserved;
return true;
}
p_oRemainingTime = MaximumReserveTime - l_oTimeReserved;
return true;
}
/// <summary>
/// State reserved.
/// Setter exists only for serialization purposes.
/// </summary>
public override InUseStateEnum Value
{
get
{
return InUseStateEnum.Reserved;
}
}
/// <summary>
/// State reserved.
/// Setter exists only for serialization purposes.
/// </summary>
public override InUseStateEnum Value
{
get
{
return InUseStateEnum.Reserved;
}
}
/// <summary>
/// Date time when bike was reserved.
/// </summary>
[DataMember]
public DateTime From { get; }
/// <summary>
/// Date time when bike was reserved.
/// </summary>
[DataMember]
public DateTime From { get; }
/// <summary>
/// Mail address of user who reserved the bike.
/// </summary>
[DataMember]
public string MailAddress { get; }
/// <summary>
/// Mail address of user who reserved the bike.
/// </summary>
[DataMember]
public string MailAddress { get; }
/// <summary>
/// Booking code.
/// </summary>
[DataMember]
public string Code { get; }
}
/// <summary>
/// Booking code.
/// </summary>
[DataMember]
public string Code { get; }
}
}