mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-06-22 05:47:28 +02:00
Version 3.0.357
This commit is contained in:
parent
5980410182
commit
5c0b2e70c9
84 changed files with 1012 additions and 449 deletions
129
TINKLib/Model/Connector/Updater/BikeCollectionFactory.cs
Normal file
129
TINKLib/Model/Connector/Updater/BikeCollectionFactory.cs
Normal file
|
@ -0,0 +1,129 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using TINK.Model.Bikes.BikeInfoNS.BC;
|
||||
using TINK.Model.Bikes;
|
||||
using TINK.Repository.Response;
|
||||
using Serilog;
|
||||
|
||||
namespace TINK.Model.Connector.Updater
|
||||
{
|
||||
public static class BikeCollectionFactory
|
||||
{
|
||||
/// <summary> Gets bikes available from copri server response.</summary>
|
||||
/// <param name="bikesAvailableResponse">Response to create collection from.</param>
|
||||
/// <param name="dataSource">Specified the data source</param>
|
||||
/// <returns>New collection of available bikes.</returns>
|
||||
public static BikeCollection GetBikesAvailable(
|
||||
this BikesAvailableResponse bikesAvailableResponse,
|
||||
DataSource dataSource)
|
||||
=> GetBikesAll(
|
||||
bikesAvailableResponse?.bikes?.Values,
|
||||
new BikesReservedOccupiedResponse()?.bikes_occupied?.Values, // There are no occupied bikes.
|
||||
string.Empty,
|
||||
() => DateTime.Now,
|
||||
dataSource);
|
||||
|
||||
/// <summary> Gets bikes occupied from copri server response. </summary>
|
||||
/// <param name="bikesOccupiedResponse">Response to create bikes from.</param>
|
||||
/// <param name="dataSource">Specified the data source</param>
|
||||
/// <returns>New collection of occupied bikes.</returns>
|
||||
public static BikeCollection GetBikesOccupied(
|
||||
this BikesReservedOccupiedResponse bikesOccupiedResponse,
|
||||
string mail,
|
||||
Func<DateTime> dateTimeProvider,
|
||||
DataSource dataSource)
|
||||
=> GetBikesAll(
|
||||
new BikesAvailableResponse()?.bikes?.Values,
|
||||
bikesOccupiedResponse?.bikes_occupied?.Values,
|
||||
mail,
|
||||
dateTimeProvider,
|
||||
dataSource);
|
||||
|
||||
/// <summary> Gets bikes occupied from copri server response. </summary>
|
||||
/// <param name="bikesAvailable">Response to create bikes available from.</param>
|
||||
/// <param name="bikesOccupied">Response to create bikes occupied from.</param>
|
||||
/// <returns>New collection of occupied bikes.</returns>
|
||||
public static BikeCollection GetBikesAll(
|
||||
IEnumerable<BikeInfoAvailable> bikesAvailable,
|
||||
IEnumerable<BikeInfoReservedOrBooked> bikesOccupied,
|
||||
string mail,
|
||||
Func<DateTime> dateTimeProvider,
|
||||
DataSource dataSource)
|
||||
{
|
||||
var bikesDictionary = new Dictionary<string, BikeInfo>();
|
||||
var duplicates = new Dictionary<string, BikeInfo>();
|
||||
|
||||
// Get bikes from Copri/ file/ memory, ....
|
||||
if (bikesAvailable != null)
|
||||
{
|
||||
foreach (var bikeInfoResponse in bikesAvailable)
|
||||
{
|
||||
var bikeInfo = BikeInfoFactory.Create(bikeInfoResponse, dataSource);
|
||||
if (bikeInfo == null)
|
||||
{
|
||||
// Response is not valid.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bikesDictionary.ContainsKey(bikeInfo.Id))
|
||||
{
|
||||
// Duplicates are not allowed.
|
||||
Log.Error($"Duplicate bike with id {bikeInfo.Id} detected evaluating bikes available. Bike status is {bikeInfo.State.Value}.");
|
||||
|
||||
if (!duplicates.ContainsKey(bikeInfo.Id))
|
||||
{
|
||||
duplicates.Add(bikeInfo.Id, bikeInfo);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
bikesDictionary.Add(bikeInfo.Id, bikeInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// Get bikes from Copri/ file/ memory, ....
|
||||
if (bikesOccupied != null)
|
||||
{
|
||||
foreach (var bikeInfoResponse in bikesOccupied)
|
||||
{
|
||||
BikeInfo bikeInfo = BikeInfoFactory.Create(
|
||||
bikeInfoResponse,
|
||||
mail,
|
||||
dateTimeProvider,
|
||||
dataSource);
|
||||
|
||||
if (bikeInfo == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bikesDictionary.ContainsKey(bikeInfo.Id))
|
||||
{
|
||||
// Duplicates are not allowed.
|
||||
Log.Error($"Duplicate bike with id {bikeInfo.Id} detected evaluating bikes occupied. Bike status is {bikeInfo.State.Value}.");
|
||||
if (!duplicates.ContainsKey(bikeInfo.Id))
|
||||
{
|
||||
duplicates.Add(bikeInfo.Id, bikeInfo);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
bikesDictionary.Add(bikeInfo.Id, bikeInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove entries which are not unique.
|
||||
foreach (var l_oDuplicate in duplicates)
|
||||
{
|
||||
bikesDictionary.Remove(l_oDuplicate.Key);
|
||||
}
|
||||
|
||||
return new BikeCollection(bikesDictionary);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Serilog;
|
||||
using TINK.Model.Bikes.BikeInfoNS.BC;
|
||||
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
|
||||
using TINK.Model.MiniSurvey;
|
||||
using TINK.Model.State;
|
||||
|
@ -20,7 +21,10 @@ namespace TINK.Model.Connector.Updater
|
|||
|
||||
/// <summary> Creates a bike info object from copri response. </summary>
|
||||
/// <param name="bikeInfo">Copri response for a disposable bike. </param>
|
||||
public static BikeInfo Create(BikeInfoAvailable bikeInfo)
|
||||
/// <param name="dataSource">Specifies the data source.</param>
|
||||
public static BikeInfo Create(
|
||||
BikeInfoAvailable bikeInfo,
|
||||
DataSource dataSource)
|
||||
{
|
||||
if (bikeInfo == null) throw new ArgumentNullException(nameof(bikeInfo));
|
||||
|
||||
|
@ -74,6 +78,7 @@ namespace TINK.Model.Connector.Updater
|
|||
bikeInfo.GetTypeOfBike(),
|
||||
bikeInfo.description),
|
||||
DriveFactory.Create(bikeInfo?.bike_type),
|
||||
dataSource,
|
||||
bikeInfo.station,
|
||||
new Bikes.BikeInfoNS.CopriLock.LockInfo.Builder { State = bikeInfo.GetCopriLockingState() }.Build(),
|
||||
bikeInfo.GetState() == InUseStateEnum.FeedbackPending,
|
||||
|
@ -103,6 +108,7 @@ namespace TINK.Model.Connector.Updater
|
|||
bikeInfo.GetTypeOfBike(),
|
||||
bikeInfo.description),
|
||||
DriveFactory.Create(bikeInfo?.bike_type),
|
||||
dataSource,
|
||||
bikeInfo.GetBluetoothLockId(),
|
||||
bikeInfo.GetBluetoothLockGuid(),
|
||||
bikeInfo.station,
|
||||
|
@ -133,10 +139,12 @@ namespace TINK.Model.Connector.Updater
|
|||
/// <param name="bikeInfo">Copri response. </param>
|
||||
/// <param name="mailAddress">Mail address of user.</param>
|
||||
/// <param name="dateTimeProvider">Date and time provider function.</param>
|
||||
/// <param name="dataSource">Specified the source of the data.</param>
|
||||
public static BikeInfo Create(
|
||||
BikeInfoReservedOrBooked bikeInfo,
|
||||
string mailAddress,
|
||||
Func<DateTime> dateTimeProvider)
|
||||
Func<DateTime> dateTimeProvider,
|
||||
DataSource dataSource)
|
||||
{
|
||||
if (bikeInfo == null) throw new ArgumentNullException(nameof(bikeInfo));
|
||||
|
||||
|
@ -178,6 +186,7 @@ namespace TINK.Model.Connector.Updater
|
|||
bikeInfo.GetTypeOfBike(),
|
||||
bikeInfo.description),
|
||||
DriveFactory.Create(bikeInfo?.bike_type),
|
||||
dataSource,
|
||||
lockSerial,
|
||||
lockGuid,
|
||||
bikeInfo.GetUserKey(),
|
||||
|
@ -207,6 +216,7 @@ namespace TINK.Model.Connector.Updater
|
|||
bikeInfo.GetTypeOfBike(),
|
||||
bikeInfo.description),
|
||||
DriveFactory.Create(bikeInfo?.bike_type),
|
||||
dataSource,
|
||||
bikeInfo.GetFrom(),
|
||||
mailAddress,
|
||||
bikeInfo.station,
|
||||
|
@ -247,6 +257,7 @@ namespace TINK.Model.Connector.Updater
|
|||
bikeInfo.GetTypeOfBike(),
|
||||
bikeInfo.description),
|
||||
DriveFactory.Create(bikeInfo?.bike_type),
|
||||
dataSource,
|
||||
lockSerial,
|
||||
bikeInfo.GetBluetoothLockGuid(),
|
||||
bikeInfo.GetUserKey(),
|
||||
|
@ -275,6 +286,7 @@ namespace TINK.Model.Connector.Updater
|
|||
bikeInfo.GetTypeOfBike(),
|
||||
bikeInfo.description),
|
||||
DriveFactory.Create(bikeInfo?.bike_type),
|
||||
dataSource,
|
||||
bikeInfo.GetIsDemo(),
|
||||
bikeInfo.GetGroup(),
|
||||
bikeInfo.station,
|
||||
|
@ -298,6 +310,7 @@ namespace TINK.Model.Connector.Updater
|
|||
bikeInfo.GetTypeOfBike(),
|
||||
bikeInfo.description),
|
||||
DriveFactory.Create(bikeInfo?.bike_type),
|
||||
DataSource.Copri,
|
||||
bikeInfo.GetFrom(),
|
||||
mailAddress,
|
||||
bikeInfo.station,
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Serilog;
|
||||
using TINK.Model.Bikes;
|
||||
using TINK.Model.Bikes.BikeInfoNS.BC;
|
||||
using TINK.Model.State;
|
||||
using TINK.Model.Station;
|
||||
using TINK.Model.Station.Operator;
|
||||
|
@ -26,11 +27,8 @@ namespace TINK.Model.Connector.Updater
|
|||
/// <param name="notifyLevel">Controls whether notify property changed events are fired or not.</param>
|
||||
public static void Load(
|
||||
this IBikeInfoMutable bike,
|
||||
Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel notifyLevel)
|
||||
{
|
||||
|
||||
bike.State.Load(InUseStateEnum.Disposable, notifyLevel: notifyLevel);
|
||||
}
|
||||
NotifyPropertyChangedLevel notifyLevel)
|
||||
=> bike.State.Load(InUseStateEnum.Disposable, notifyLevel: notifyLevel);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all statsion for station provider and add them into station list.
|
||||
|
@ -126,7 +124,7 @@ namespace TINK.Model.Connector.Updater
|
|||
this IBikeInfoMutable bike,
|
||||
BikeInfoReservedOrBooked bikeInfo,
|
||||
string mailAddress,
|
||||
Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel notifyLevel = Bikes.BikeInfoNS.BC.NotifyPropertyChangedLevel.All)
|
||||
NotifyPropertyChangedLevel notifyLevel = NotifyPropertyChangedLevel.All)
|
||||
{
|
||||
if (bike is Bikes.BikeInfoNS.BluetoothLock.BikeInfoMutable btBikeInfo)
|
||||
{
|
||||
|
@ -170,113 +168,5 @@ namespace TINK.Model.Connector.Updater
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary> Gets bikes available from copri server response.</summary>
|
||||
/// <param name="bikesAvailableResponse">Response to create collection from.</param>
|
||||
/// <returns>New collection of available bikes.</returns>
|
||||
public static BikeCollection GetBikesAvailable(
|
||||
this BikesAvailableResponse bikesAvailableResponse)
|
||||
=> GetBikesAll(
|
||||
bikesAvailableResponse?.bikes?.Values,
|
||||
new BikesReservedOccupiedResponse()?.bikes_occupied?.Values, // There are no occupied bikes.
|
||||
string.Empty,
|
||||
() => DateTime.Now);
|
||||
|
||||
/// <summary> Gets bikes occupied from copri server response. </summary>
|
||||
/// <param name="p_oBikesAvailable">Response to create bikes from.</param>
|
||||
/// <returns>New collection of occupied bikes.</returns>
|
||||
public static BikeCollection GetBikesOccupied(
|
||||
this BikesReservedOccupiedResponse bikesOccupiedResponse,
|
||||
string mail,
|
||||
Func<DateTime> dateTimeProvider)
|
||||
{
|
||||
return GetBikesAll(
|
||||
new BikesAvailableResponse()?.bikes?.Values,
|
||||
bikesOccupiedResponse?.bikes_occupied?.Values,
|
||||
mail,
|
||||
dateTimeProvider);
|
||||
}
|
||||
|
||||
/// <summary> Gets bikes occupied from copri server response. </summary>
|
||||
/// <param name="bikesAvailable">Response to create bikes available from.</param>
|
||||
/// <param name="bikesOccupied">Response to create bikes occupied from.</param>
|
||||
/// <returns>New collection of occupied bikes.</returns>
|
||||
public static BikeCollection GetBikesAll(
|
||||
IEnumerable<BikeInfoAvailable> bikesAvailable,
|
||||
IEnumerable<BikeInfoReservedOrBooked> bikesOccupied,
|
||||
string mail,
|
||||
Func<DateTime> dateTimeProvider)
|
||||
{
|
||||
var bikesDictionary = new Dictionary<string, BikeInfo>();
|
||||
var duplicates = new Dictionary<string, BikeInfo>();
|
||||
|
||||
// Get bikes from Copri/ file/ memory, ....
|
||||
if (bikesAvailable != null)
|
||||
{
|
||||
foreach (var bikeInfoResponse in bikesAvailable)
|
||||
{
|
||||
var bikeInfo = BikeInfoFactory.Create(bikeInfoResponse);
|
||||
if (bikeInfo == null)
|
||||
{
|
||||
// Response is not valid.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bikesDictionary.ContainsKey(bikeInfo.Id))
|
||||
{
|
||||
// Duplicates are not allowed.
|
||||
Log.Error($"Duplicate bike with id {bikeInfo.Id} detected evaluating bikes available. Bike status is {bikeInfo.State.Value}.");
|
||||
|
||||
if (!duplicates.ContainsKey(bikeInfo.Id))
|
||||
{
|
||||
duplicates.Add(bikeInfo.Id, bikeInfo);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
bikesDictionary.Add(bikeInfo.Id, bikeInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// Get bikes from Copri/ file/ memory, ....
|
||||
if (bikesOccupied != null)
|
||||
{
|
||||
foreach (var bikeInfoResponse in bikesOccupied)
|
||||
{
|
||||
BikeInfo bikeInfo = BikeInfoFactory.Create(
|
||||
bikeInfoResponse,
|
||||
mail,
|
||||
dateTimeProvider);
|
||||
|
||||
if (bikeInfo == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bikesDictionary.ContainsKey(bikeInfo.Id))
|
||||
{
|
||||
// Duplicates are not allowed.
|
||||
Log.Error($"Duplicate bike with id {bikeInfo.Id} detected evaluating bikes occupied. Bike status is {bikeInfo.State.Value}.");
|
||||
if (!duplicates.ContainsKey(bikeInfo.Id))
|
||||
{
|
||||
duplicates.Add(bikeInfo.Id, bikeInfo);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
bikesDictionary.Add(bikeInfo.Id, bikeInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove entries which are not unique.
|
||||
foreach (var l_oDuplicate in duplicates)
|
||||
{
|
||||
bikesDictionary.Remove(l_oDuplicate.Key);
|
||||
}
|
||||
|
||||
return new BikeCollection(bikesDictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue