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
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue