Version 3.0.381

This commit is contained in:
Anja 2024-04-09 12:53:23 +02:00
parent f963c0a219
commit 3a363acf3a
1525 changed files with 60589 additions and 125098 deletions

View file

@ -0,0 +1,21 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class AuthorizationResponse : ResponseBase
{
[DataMember]
public int debuglevel { get; private set; }
/// <summary> Holds the group of the bike (ShareeBike, Citybike, ...).</summary>
[DataMember]
public string[] user_group { get; private set; }
/// <summary> Holds value of 0 if agb were not acknowledged.</summary>
[DataMember]
public string agb_checked { get; private set; }
}
}

View file

@ -0,0 +1,11 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class AuthorizationoutResponse : ResponseBase
{
}
}

View file

@ -0,0 +1,31 @@
using System;
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class BikeInfoAvailable : BikeInfoBase, IEquatable<BikeInfoAvailable>
{
/// <summary>Mini survey for bikes which were rented before and for which feedback is pending.</summary>
[DataMember]
public MiniSurveyResponse user_miniquery { get; private set; }
/// <summary> Information about Co2- saving for bikes which were rented before and for which feedback is pending.</summary>
[DataMember]
public string co2saving { get; private set; }
public static bool operator ==(BikeInfoAvailable first, BikeInfoAvailable second)
=> JsonConvert.SerializeObject(first) == JsonConvert.SerializeObject(second);
public static bool operator !=(BikeInfoAvailable first, BikeInfoAvailable second)
=> !(first == second);
public override bool Equals(object obj) => obj is BikeInfoAvailable target && target == this;
public override int GetHashCode() => JsonConvert.SerializeObject(this).GetHashCode();
public bool Equals(BikeInfoAvailable other) => other == this;
}
}

View file

@ -0,0 +1,113 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
/// <summary>
/// Holds info about a single bike.
/// </summary>
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class BikeInfoBase
{
/// <summary>
/// Id of the bike.
/// </summary>
[DataMember]
public string bike { get; private set; }
/// <summary>
/// Position of the bike.
/// </summary>
[DataMember]
public Position gps { get; private set; }
/// <summary>
/// Id of the station.
/// </summary>
[DataMember]
public string station { get; private set; }
/// <summary>
/// Holds the localized (German) description of the bike.
/// </summary>
[DataMember]
public string description { get; private set; }
/// <summary> Holds the group of the bike.</summary>
/// <remarks>
/// Copri returns values "ShareeBike", "Citybike".
/// </remarks>
[DataMember]
public string[] bike_group { get; private set; }
/// <summary>
/// Rental state.
/// </summary>
[DataMember]
public string state { get; private set; }
/// <summary>
/// Holds the uri where to reserve/ rent the bike.
/// </summary>
[DataMember]
public string uri_operator { get; private set; }
/// <summary> Holds whether bike is equipped with computer or if bike is a lock bike.</summary>
/// <remarks>
/// <table>
/// <tr><th>Value </th><th>Type of bike </th><th>Member to extract info.</th></tr>
/// <tr><td>LOCK </td><td>Bike with manualHtml lock. </td><td>TextToTypeHelper.GetIsNonBikeComputerBike</td></tr>
/// <tr><td>BC </td><td>Bike with a bord computer. </td><td></td></tr>
/// <tr><td>Ilockit </td><td>Bike with a bluetooth lock.</td><td></td></tr>
/// <tr><td>sigo </td><td>Sigo bike.</td><td></td></tr>
/// </table>
/// </remarks>
[DataMember]
public string system { get; private set; }
/// <summary> Holds the tariff information for a bike. </summary>
/// <remarks> This member is obsolete. Use <cref="rental_description"> instead.</cref></remarks>
[DataMember]
public TariffDescription tariff_description { get; private set; }
/// <summary> Holds the rental information for a bike. </summary>
[DataMember]
public RentalDescription rental_description { get; private set; }
[DataMember]
/// <summary> Describes type of the bike.</summary>
public BikeType bike_type { get; private set; }
/// <summary>
/// Holds whether bike is a AA bike (bike must be always returned a the same station) or AB bike (start and end stations can be different stations).
/// </summary>
[DataMember]
public string aa_ride { get; private set; }
/// <summary> Loading state of motor battery in % ]0..100[. </summary>
[DataMember]
public string bike_charge { get; private set; }
/// <summary> Locking state. </summary>
[DataMember]
public string lock_state { get; private set; }
[DataMember]
/// <summary> Full advertisement name.</summary>
public string Ilockit_ID { get; private set; }
[DataMember]
/// <summary> Full advertisement name.</summary>
public string Ilockit_GUID { get; private set; }
/// <summary>
/// Textual description of response.
/// </summary>
/// <returns>Object as text.</returns>
public override string ToString()
{
return $"Bike {bike}{(station != null ? $", at station {station}" : string.Empty)}{(!string.IsNullOrEmpty(description) ? $", {description}" : string.Empty)}{(!string.IsNullOrEmpty(state) ? $", status={state}" : string.Empty)}.";
}
}
}

View file

@ -0,0 +1,46 @@
using System;
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class BikeInfoReservedOrBooked : BikeInfoBase, IEquatable<BikeInfoReservedOrBooked>
{
/// <summary>
/// Date from when bike was reserved from/ booked from.
/// Format: 2017-11-28 11:01:51.637747+01
/// </summary>
[DataMember]
public string start_time { get; private set; }
/// <summary> Booking code if bike is BC-bike.</summary>
[DataMember]
public string timeCode { get; private set; }
[DataMember]
/// <summary> Seed used to generate key for connecting to bluetooth lock.</summary>
public string K_seed { get; private set; }
[DataMember]
/// <summary> Key for connect to bluetooth lock as user.</summary>
public string K_u { get; private set; }
[DataMember]
/// <summary> Key for connect to bluetooth lock as admin.</summary>
public string K_a { get; private set; }
public static bool operator ==(BikeInfoReservedOrBooked first, BikeInfoReservedOrBooked second)
=> JsonConvert.SerializeObject(first) == JsonConvert.SerializeObject(second);
public static bool operator !=(BikeInfoReservedOrBooked first, BikeInfoReservedOrBooked second)
=> !(first == second);
public override bool Equals(object obj) => obj is BikeInfoReservedOrBooked target && target == this;
public override int GetHashCode() => JsonConvert.SerializeObject(this).GetHashCode();
public bool Equals(BikeInfoReservedOrBooked other) => other == this;
}
}

View file

@ -0,0 +1,89 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
/// <summary>
/// Holds info about a single bike.
/// </summary>
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class BikeType
{
/// <summary>
/// Holds the engine.
/// </summary>
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class Engine
{
/// <summary>
/// Manufacturer: ...
/// </summary>
[DataMember]
public string manufacturer { get; private set; }
}
/// <summary>
/// Holds the engine.
/// </summary>
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class Battery
{
/// <summary>
/// Holds the current charging level in bars.
/// </summary>
[DataMember]
public string charge_current_bars { get; private set; }
/// <summary>
/// Holds the current charging level of the battery in percent.
/// </summary>
[DataMember]
public string charge_current_percent { get; private set; }
/// <summary>
/// Holds the maximum charging level of the battery in bars.
/// </summary>
[DataMember]
public string charge_max_bars { get; private set; }
/// <summary>
/// Holds whether backend is aware of battery charging level.
/// </summary>
[DataMember]
public string backend_accessible { get; private set; }
/// <summary>
/// Holds whether to display battery level or not.
/// </summary>
[DataMember]
public string hidden { get; private set; }
}
/// <summary>
/// Category of the bike. Possible entries: "city", "cargo", ...
/// </summary>
[DataMember]
public string category { get; private set; }
/// <summary>
/// Count of wheels. There are trikes (3 wheels) and two wheeled bikes.
/// </summary>
[DataMember]
public string wheels { get; private set; }
/// <summary>
/// Holds engine information. .
/// </summary>
[DataMember]
public Engine engine { get; private set; }
/// <summary>
/// Holds battery information .
/// </summary>
[DataMember]
public Battery battery { get; private set; }
}
}

View file

@ -0,0 +1,37 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
/// <summary>
/// Holds the information about all bikes and is used for deserialization of copri answer.
/// </summary>
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class BikesAvailableResponse : ResponseBase
{
public BikesAvailableResponse()
{
bikes = new ComparableBikeDictionary<BikeInfoAvailable> ();
bikes_occupied = new ComparableBikeDictionary<BikeInfoReservedOrBooked> ();
}
/// <summary> Dictionary of bikes available.</summary>
[DataMember]
public ComparableBikeDictionary<BikeInfoAvailable> bikes { get; private set; }
/// <summary> Dictionary of bikes reserved or booked.</summary>
[DataMember]
public ComparableBikeDictionary<BikeInfoReservedOrBooked> bikes_occupied { get; private set; }
public static bool operator== (BikesAvailableResponse first, BikesAvailableResponse second)
=> JsonConvert.SerializeObject(first) == JsonConvert.SerializeObject(second);
public static bool operator !=(BikesAvailableResponse first, BikesAvailableResponse second)
=> !(first == second);
public override bool Equals(object obj) => obj is BikesAvailableResponse target && target == this;
public override int GetHashCode() => JsonConvert.SerializeObject(this).GetHashCode();
}
}

View file

@ -0,0 +1,34 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
/// <summary>
/// Holds the information about a booking request (reserve, cancel reservation, book or cancel booking) and is used for deserialization of copri answer.
/// </summary>
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class BikesReservedOccupiedResponse : BookingActionResponse
{
public BikesReservedOccupiedResponse()
{
bikes_occupied = new ComparableBikeDictionary<BikeInfoReservedOrBooked> ();
}
/// <summary>
/// Dictionary of bikes.
/// </summary>
[DataMember]
public ComparableBikeDictionary<BikeInfoReservedOrBooked> bikes_occupied { get; private set; }
public static bool operator ==(BikesReservedOccupiedResponse first, BikesReservedOccupiedResponse second)
=> JsonConvert.SerializeObject(first) == JsonConvert.SerializeObject(second);
public static bool operator !=(BikesReservedOccupiedResponse first, BikesReservedOccupiedResponse second)
=> !(first == second);
public override bool Equals(object obj) => obj is BikesReservedOccupiedResponse target && target == this;
public override int GetHashCode() => JsonConvert.SerializeObject(this).GetHashCode();
}
}

View file

@ -0,0 +1,21 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
/// <summary>
/// Holds the information about a booking request (reserve, cancel reservation, book or cancel booking) and is used for deserialization of copri answer.
/// </summary>
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class BookingActionResponse : ResponseBase
{
/// <summary>
/// Id of the bike which was target of the booking request.
/// </summary>
[DataMember]
public string bike { get; private set; }
}
}

View file

@ -0,0 +1,64 @@
using System.Linq;
using System.Runtime.Serialization;
namespace ShareeBike.Repository.Response
{
public class ComparableBikeDictionary<S> : ComparableDictionary<S> where S : BikeInfoBase
{
[OnDeserialized]
internal void OnDeserializedMethod(StreamingContext context)
{
var toCorrectDictionary = this.Where( x =>
!string.IsNullOrEmpty(x.Value.bike)
&& x.Key != x.Value.bike).ToArray();
foreach (var element in toCorrectDictionary)
{
Remove(element.Key);
if (ContainsKey(element.Value.bike))
{
// Remove duplicates.
Remove(element.Value.bike);
continue;
}
Add(element.Value.bike, element.Value);
}
}
/// <summary>
/// Removes a bike from dictionary.
/// </summary>
/// <typeparam name="T">Type of dictionary values to remove.</typeparam>
/// <param name="bikeId">If of bike to remove.</param>
/// <returns>True if at least one bike was removed, false if no bike was removed.</returns>
public bool RemoveByBikeId<T>(
string bikeId)
{
if (string.IsNullOrEmpty(bikeId))
{
// Nothing to do.
return false;
}
var bikeToRemove = this.FirstOrDefault(x => bikeId == x.Value.bike);
if (string.IsNullOrEmpty(bikeToRemove.Key))
{
// Bike is not contained in dictionary.
return false;
}
return Remove(bikeToRemove.Key);
}
/// <summary>
/// Gets a bike by bike id from dictionary.
/// </summary>
/// <typeparam name="T">Type of dictionary values to remove.</typeparam>
/// <param name="bikeId">If of bike to get.</param>
/// <returns>True if at least one bike was removed, false if no bike was removed.</returns>
public S GetByBikeId(
string bikeId)
=> this.FirstOrDefault(x => bikeId == x.Value.bike).Value;
}
}

View file

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
/// <summary>
/// Holds a dictionary of comparable elements.
/// </summary>
/// <typeparam name="S">Type of the element.</typeparam>
[DataContract]
public class ComparableDictionary<S> : Dictionary<string, S>, IEquatable<ComparableDictionary<S>>
{
public bool Equals(ComparableDictionary<S> other)
{
return this.OrderBy(x => x.Key).SequenceEqual(other.OrderBy(x => x.Key));
}
public static bool operator ==(ComparableDictionary<S> first, ComparableDictionary<S> second)
=> JsonConvert.SerializeObject(first) == JsonConvert.SerializeObject(second);
public static bool operator !=(ComparableDictionary<S> first, ComparableDictionary<S> second)
=> !(first == second);
public override bool Equals(object obj) => obj is ComparableDictionary<S> target && target == this;
public override int GetHashCode() => JsonConvert.SerializeObject(this).GetHashCode();
}
}

View file

@ -0,0 +1,13 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class CopriVersion
{
[DataMember]
public string copri_version { get; private set; }
}
}

View file

@ -0,0 +1,77 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class DoReturnResponse : BikesReservedOccupiedResponse
{
/// <summary>
/// Holds information about the returned bike.
/// </summary>
[DataContract]
public class BikeReturned
{
/// <summary>
/// Rental state.
/// </summary>
[DataMember]
public string state { get; private set; }
/// <summary>
/// Id of the bike.
/// </summary>
[DataMember]
public string bike { get; private set; }
/// <summary> Locking state. </summary>
[DataMember]
public string lock_state { get; private set; }
/// <summary>
/// Id of the station.
/// </summary>
[DataMember]
public string station { get; private set; }
/// <summary>
/// Amount of Co2Saving.
/// </summary>
[DataMember]
public string co2saving { get; private set; }
/// <summary>
/// Driven Distance.
/// </summary>
[DataMember]
public string distance { get; private set; }
/// <summary>
/// Duration of finished rental.
/// </summary>
[DataMember]
public string real_clock { get; private set; }
/// <summary>
/// Accruing costs for rental.
/// </summary>
[DataMember]
public string total_price { get; private set; }
}
/// <summary> Mini survey.</summary>
[DataMember]
public MiniSurveyResponse user_miniquery { get; private set; }
[DataMember]
public string co2saving { get; private set; }
/// <summary>
/// Holds information about the returned bike.
/// </summary>
[DataMember]
public BikeReturned bike_returned { get; private set; }
}
}

View file

@ -0,0 +1,29 @@
using Serilog;
using ShareeBike.Repository.Exception;
namespace ShareeBike.Repository.Response
{
public static class JsonConvertRethrow
{
/// <summary>
/// Deserializes COPRI responses in a consitent way for entire app.
/// </summary>
/// <typeparam name="T">Type of object to serialize to.</typeparam>
/// <param name="response">JSON to deserialize.</param>
/// <returns>Deserialized object.</returns>
public static T DeserializeObject<T>(string response)
{
try
{
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(response);
}
catch (System.Exception ex)
{
Log.Error("Deserializing response failed. {@Exception}",ex);
throw new DeserializationException(ex);
}
}
public static string SerializeObject(object value) => Newtonsoft.Json.JsonConvert.SerializeObject(value);
}
}

View file

@ -0,0 +1,19 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
/// <summary> Holds information about map area to display.</summary>
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class MapSpan
{
/// <summary> Center position of the map. </summary>
[DataMember]
public Position center { get; private set; }
/// <summary> Radius to the map area. </summary>
[DataMember]
public string radius { get; private set; }
}
}

View file

@ -0,0 +1,34 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace ShareeBike.Repository.Response
{
[DataContract]
public class MiniSurveyResponse
{
[DataContract]
public class Question
{
[DataMember]
public string quest_text { get; private set; }
[DataMember]
public string type { get; private set; }
[DataMember]
public Dictionary<string, string> query { get; private set; }
}
[DataMember]
public string title { get; private set; }
[DataMember]
public string subtitle { get; private set; }
[DataMember]
public string footer { get; private set; }
[DataMember]
public Dictionary<string, Question> questions { get; private set; }
}
}

View file

@ -0,0 +1,19 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
/// <summary> Holds position info. </summary>
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class Position
{
/// <summary> Latitude position (bike, station, map center...). </summary>
[DataMember]
public string latitude { get; private set; }
/// <summary> Longitude position (bike, station, map center...). </summary>
[DataMember]
public string longitude { get; private set; }
}
}

View file

@ -0,0 +1,49 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
/// <summary>
/// Successor of TarifDescription- object.
/// Manages tariff- and rental info.
/// </summary>
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class RentalDescription
{
/// <summary>
/// Name of the tariff.
/// </summary>
[DataMember]
public string name { get; private set; }
/// <summary>
/// Id of the tariff.
/// </summary>
[DataMember]
public string id { get; private set; }
/// <summary>
/// Holds the time span in minutes for which a bike can be reserved.
/// </summary>
[DataMember]
public string reserve_timerange { get; private set; }
/// <summary> Holds tariff entires to show to user.</summary>
[DataMember]
public Dictionary<
string /* Key of tariff object for sorting purposes*/,
string[] /* Holds two Elements: first element is the description of the element (example: "Max Gebühr"), second is the value (example: "9.00 € / Tag")*/>
tarif_elements
{ get; private set; }
/// <summary> Holds tariff entires to show to user.</summary>
[DataMember]
public Dictionary<
string /* Key of info object for sorting purposes*/,
string[] /* Holds two Elements: first element is the key of the element (example: "Tracking"), second is the value (example: "Ich stimme der Speicherung (Tracking) meiner Fahrstrecke ....")*/>
rental_info
{ get; private set; }
}
}

View file

@ -0,0 +1,17 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
/// <summary>
/// Holds the information about a booking request and is used for deserialization of copri answer.
/// </summary>
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class ReservationBookingResponse : BikesReservedOccupiedResponse
{
/// <summary> Booking code for BC- bikes. </summary>
[DataMember]
public string timeCode { get; private set; }
}
}

View file

@ -0,0 +1,59 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class ResponseBase : CopriVersion
{
[DataMember]
public string response_state { get; private set; }
[DataMember]
public string response { get; private set; }
[DataMember]
public string response_text { get; private set; }
[DataMember]
public string authcookie { get; private set; }
/// <summary> Message shown to user.</summary>
[DataMember]
public string merchant_message { get; private set; }
/// <summary> Initial map display area.</summary>
[DataMember]
public MapSpan init_map { get; private set; }
/// <summary> Url of page holding agb info. </summary>
[DataMember]
public string agb_html { get; private set; }
/// <summary> Url of page holding instructions how to rent bikes. </summary>
[DataMember]
public string bike_info_html { get; private set; }
/// <summary> Url of page holding privacy info. </summary>
[DataMember]
public string privacy_html { get; private set; }
/// <summary> Url of page holding impress info. </summary>
[DataMember]
public string impress_html { get; private set; }
/// <summary> Url of page holding tariff info. </summary>
[DataMember]
public string tariff_info_html { get; private set; }
/// <summary> Textual description of response. </summary>
public override string ToString()
{
return $"Response state is \"{response_state ?? string.Empty}\", " +
$"auth cookie is \"{authcookie ?? string.Empty}\" and response is \"{response_text ?? string.Empty}\", " +
$"code \"{response ?? string.Empty}\"" +
$"response text \"{response_text ?? string.Empty}\".";
}
}
}

View file

@ -0,0 +1,27 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class ResponseContainer<T>
{
[DataMember]
public T shareejson { get; private set; }
/// <summary>
/// Serializes object to string.
/// </summary>
/// <returns></returns>
public override string ToString()
{
if (shareejson == null)
{
return "Response container does not hold no entry.";
}
return shareejson.ToString();
}
}
}

View file

@ -0,0 +1,230 @@
using System.Linq;
using ShareeBike.MultilingualResources;
using ShareeBike.Repository.Exception;
namespace ShareeBike.Repository.Response
{
public static class ResponseHelper
{
public const string RESPONSE_OK = "OK";
/// <summary> Holds the description of the action return bike. </summary>
public const string RESPONSE_AUTHCOOKIE_EXPRIED = "Failure 1001:";
/// <summary> Holds the description of the action logout. </summary>
public const string BIKES_LOGOUT_ACTIONTEXT = "Abmeldung fehlgeschlagen.";
/// <summary> Holds the description of the action get stations available. </summary>
public const string STATIONS_AVAILABLE_ACTIONTEXT = "Abfrage der verfügbaren Stationen fehlgeschlagen.";
/// <summary> Holds the description of the action get bikes available. </summary>
public const string BIKES_AVAILABLE_ACTIONTEXT = "Abfrage der verfügbaren Fahrräder fehlgeschlagen.";
/// <summary> Holds the description of the action get bikes occupied. </summary>
public const string BIKES_OCCUPIED_ACTIONTEXT = "Abfrage der reservierten/ gebuchten Fahrräder fehlgeschlagen.";
/// <summary> Holds the description of the action return bike. </summary>
public const string BIKES_RETURNBIKE_ACTIONTEXT = "Rückgabe des Rads fehlgeschlagen.";
/// <summary>
/// Checks if log in response is ok.
/// </summary>
/// <param name="response">Response to check whether it is valid.</param>
/// <param name="mail">Mail address used to create details error message in case log in response is invalid.</param>
/// <returns></returns>
public static AuthorizationResponse GetIsResponseOk(this AuthorizationResponse response, string mail)
{
if (response == null)
{
throw new InvalidResponseException<AuthorizationResponse>("Anmeldung fehlgeschlagen.", null);
}
if (response.response_state.ToUpper() == InvalidAuthorizationResponseException.AUTH_FAILURE_STATUS_MESSAGE_UPPERCASE)
{
throw new InvalidAuthorizationResponseException(mail, response);
}
else if (!response.response_state.Trim().ToUpper().StartsWith(RESPONSE_OK))
{
throw new InvalidResponseException<AuthorizationResponse>($"Anmeldung {mail} fehlgeschlagen.\r\nServer Antwort: {response.response_text}", response);
}
return response;
}
/// <summary>
/// Checks if log out response is ok.
/// </summary>
/// <param name="p_oResponse">Response to check whether it is valid.</param>
/// <returns></returns>
public static AuthorizationoutResponse GetIsResponseOk(this AuthorizationoutResponse p_oResponse)
{
if (AuthcookieNotDefinedException.IsAuthcookieNotDefined(p_oResponse, BIKES_LOGOUT_ACTIONTEXT, out AuthcookieNotDefinedException exception))
{
throw exception;
}
GetIsResponseOk(p_oResponse, BIKES_LOGOUT_ACTIONTEXT);
if (p_oResponse.authcookie != "1")
{
throw new InvalidResponseException<AuthorizationoutResponse>(
BIKES_LOGOUT_ACTIONTEXT,
p_oResponse);
}
return p_oResponse;
}
/// <summary>Gets if a call to reserve bike succeeded or not by checking a booking response.</summary>
/// <param name="bikeId">Id of bike which should be booked.</param>
/// <param name="sessionCookie">Session cookie of logged in user.</param>
/// <param name="bookingResponse">Response to check.</param>
/// <returns></returns>
public static BikeInfoReservedOrBooked GetIsReserveResponseOk(
this ReservationBookingResponse bookingResponse,
string bikeId)
{
GetIsResponseOk(bookingResponse, string.Format(AppResources.ErrorReservingBike, bikeId));
if (BookingDeclinedException.IsBookingDeclined(bookingResponse.response_state, out BookingDeclinedException exception))
{
throw exception;
}
// Get bike which has to be booked.
var bikeInfoRequestedOccupied = bookingResponse?.bikes_occupied?.Values?.FirstOrDefault(x => x.bike == bikeId);
if (bikeInfoRequestedOccupied == null)
{
throw new System.Exception(string.Format(
AppResources.ErrorReservingBikeUnavailalbe,
bikeId,
!string.IsNullOrWhiteSpace(bookingResponse?.response_text) ? $"\r\n{bookingResponse.response_text}" : string.Empty));
}
return bikeInfoRequestedOccupied;
}
/// <summary> Gets if a booking call succeeded or not by checking a booking response. </summary>
/// <param name="bikeId">Id of bike which should be booked.</param>
/// <param name="bookingResponse">Response to check.</param>
/// <returns></returns>
public static BikeInfoReservedOrBooked GetIsBookingResponseOk(
this ReservationBookingResponse bookingResponse,
string bikeId)
{
GetIsResponseOk(bookingResponse, string.Format(AppResources.ErrorRentingBike, bikeId));
// Get bike which has to be booked.
var bikeInfoRequestedOccupied = bookingResponse?.bikes_occupied?.Values?.FirstOrDefault(x => x.bike == bikeId);
if (bikeInfoRequestedOccupied == null)
{
throw new System.Exception(string.Format(
AppResources.ErrorRentingBikeUnavailalbe,
bikeId,
!string.IsNullOrWhiteSpace(bookingResponse?.response_text) ? $"\r\n{bookingResponse.response_text}" : string.Empty));
}
return bikeInfoRequestedOccupied;
}
/// <summary> Gets if request is ok.</summary>
/// <param name="response">Response to verify.</param>
/// <param name="textOfAction">Text describing request which is shown if validation fails.</param>
/// <returns>Verified response.</returns>
public static BikesReservedOccupiedResponse GetIsResponseOk(this BikesReservedOccupiedResponse response, string textOfAction)
{
if (response == null || response.response_state == null)
{
throw new InvalidResponseException<BikesReservedOccupiedResponse>(textOfAction, null);
}
if (AuthcookieNotDefinedException.IsAuthcookieNotDefined(response, textOfAction, out AuthcookieNotDefinedException exception))
{
throw exception;
}
if (response.response_state.Trim().ToUpper().StartsWith(RESPONSE_AUTHCOOKIE_EXPRIED.ToUpper()))
{
throw new AuthcookieNotDefinedException(
$"{textOfAction}\r\n{AppResources.ErrorAccountInvalidAuthorization}",
response);
}
GetIsResponseOk((ResponseBase)response, textOfAction);
return response;
}
/// <summary> Gets if request is ok.</summary>
/// <param name="response">Response to verify.</param>
/// <param name="textOfAction">Text describing request which is shown if validation fails.</param>
/// <returns>Verified response.</returns>
public static T GetIsResponseOk<T>(this T response, string textOfAction) where T : ResponseBase
{
if (response == null || response.response_state == null)
{
throw new InvalidResponseException<T>(textOfAction, null);
}
if (AuthcookieNotDefinedException.IsAuthcookieNotDefined(response, textOfAction, out AuthcookieNotDefinedException exception))
{
throw exception;
}
if (!response.response_state.Trim().ToUpper().StartsWith(RESPONSE_OK))
{
throw new InvalidResponseException<T>(
$"{textOfAction}\r\nServer Antwort: {response.response_text}",
response);
}
return response;
}
/// <summary> Gets if return bike request is ok.</summary>
/// <param name="returnBikeResponse">Response to verify.</param>
/// <param name="textOfAction">Text describing request which is shown if validation fails.</param>
/// <param name="bikeId">Id of bike.</param>
/// <returns>Verified response.</returns>
public static DoReturnResponse GetIsReturnBikeResponseOk(
this DoReturnResponse returnBikeResponse,
string bikeId)
{
// Check if bike is at station.
if (NotAtStationException.IsNotAtStation(returnBikeResponse.response_state.ToUpper(), out NotAtStationException notAtStationException))
{
throw notAtStationException;
}
// Check if GPS data was send to copri.
if (NoGPSDataException.IsNoGPSData(returnBikeResponse.response_state.ToUpper(), out NoGPSDataException noGPSDataException))
{
throw noGPSDataException;
}
GetIsResponseOk<ResponseBase>(returnBikeResponse, BIKES_RETURNBIKE_ACTIONTEXT);
// Get bike which has to be booked.
var l_oBikeInfo = returnBikeResponse?.bikes_occupied?.Values?.FirstOrDefault(x => x.bike == bikeId);
if (l_oBikeInfo != null)
{
throw new ReturnBikeException(
returnBikeResponse,
$"{BIKES_RETURNBIKE_ACTIONTEXT} Aufruf wurde erfolgreich ausgeführt, aber Rad ist noch in Liste der gemieteten Räder enthalten.");
}
return returnBikeResponse;
}
/// <summary>
/// Gets the response for bikes occupied request with no bikes reserved.
/// </summary>
/// <param name="p_strSesstionCookie"></param>
/// <returns></returns>
public static BikesReservedOccupiedResponse GetBikesOccupiedNone(string p_strSesstionCookie = null)
{
var l_oJson = CopriCallsMonkeyStore.BIKESOCCUPIED.Replace(@"""authcookie"": """"", @"""authcookie"": """ + (p_strSesstionCookie ?? string.Empty) + @"""");
return CopriCallsStatic.DeserializeResponse(@"{ ""shareejson"" : " + l_oJson + "}", (version) => new BikesReservedOccupiedResponse());
}
}
}

View file

@ -0,0 +1,21 @@
using System.Runtime.Serialization;
namespace ShareeBike.Repository.Response.Stations.Station
{
/// <summary>
/// Holds a single bike group.
/// </summary>
[DataContract]
public class BikeGroup
{
/// <summary> Holds the count of bikes for the group. </summary>
[DataMember]
public string bike_count { get; private set;}
/// <summary>
/// Holds the group identifying the bike group type.
/// </summary>
[DataMember]
public string bike_group { get; private set; }
}
}

View file

@ -0,0 +1,27 @@
using System.Runtime.Serialization;
namespace ShareeBike.Repository.Response.Stations.Station
{
/// <summary>
/// Holds info about operator data.
/// </summary>
[DataContract]
public class OperatorData
{
[DataMember]
public string operator_name { get; private set; }
[DataMember]
public string operator_phone { get; private set; }
[DataMember]
public string operator_hours { get; private set; }
[DataMember]
public string operator_email { get; private set; }
[DataMember]
public string operator_color { get; private set; }
}
}

View file

@ -0,0 +1,62 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response.Stations.Station
{
/// <summary>
/// Holds info about a single station.
/// </summary>
[DataContract]
public class StationInfo
{
/// <summary>
/// Unique id of the station.
/// </summary>
[DataMember]
public string station { get; private set; }
[DataMember]
public string[] station_group { get; private set; }
[DataMember]
public string description { get; private set; }
/// <summary>
/// Position of the station.
/// </summary>
[DataMember]
public Position gps { get; private set; }
[DataMember]
public OperatorData operator_data { get; private set; }
/// <summary>
/// Holds the count of available bikes at the station.
/// </summary>
[DataMember]
public string bike_count { get; set; }
/// <summary>
/// Holds the count type of station, i.e. which bikes are located at station.
/// </summary>
[DataMember]
public Dictionary<string, BikeGroup> station_type { get; private set; }
/// <summary>
/// Holds the uri of the operator which manages the bikes at station/ the station.
/// </summary>
[DataMember]
public string uri_operator { get; private set; }
public static bool operator ==(StationInfo first, StationInfo second)
=> JsonConvert.SerializeObject(first) == JsonConvert.SerializeObject(second);
public static bool operator !=(StationInfo first, StationInfo second)
=> !(first == second);
public override bool Equals(object obj) => obj is StationInfo target && target == this;
public override int GetHashCode() => JsonConvert.SerializeObject(this).GetHashCode();
}
}

View file

@ -0,0 +1,41 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
using ShareeBike.Repository.Response.Stations.Station;
namespace ShareeBike.Repository.Response.Stations
{
/// <summary>
/// Holds the information about all stations and is used for deserialization of copri answer.
/// </summary>
[DataContract]
public class StationsAvailableResponse : ResponseBase
{
public StationsAvailableResponse()
{
stations = new ComparableDictionary< StationInfo>();
bikes_occupied = new ComparableBikeDictionary<BikeInfoReservedOrBooked> { };
}
/// <summary>
/// Dictionary of bikes.
/// </summary>
[DataMember]
public ComparableDictionary< StationInfo> stations { get; private set; }
/// <summary>
/// Dictionary of bikes reserved (requested) and rented (occupied) by current user if user is logged in and has reserved or rented bikes.
/// </summary>
[DataMember]
public ComparableBikeDictionary<BikeInfoReservedOrBooked> bikes_occupied { get; private set; }
public static bool operator ==(StationsAvailableResponse first, StationsAvailableResponse second)
=> JsonConvert.SerializeObject(first) == JsonConvert.SerializeObject(second);
public static bool operator !=(StationsAvailableResponse first, StationsAvailableResponse second)
=> !(first == second);
public override bool Equals(object obj) => obj is StationsAvailableResponse target && target == this;
public override int GetHashCode() => JsonConvert.SerializeObject(this).GetHashCode();
}
}

View file

@ -0,0 +1,11 @@
using Newtonsoft.Json;
using System.Runtime.Serialization;
namespace ShareeBike.Repository.Response
{
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class SubmitFeedbackResponse : ResponseBase
{
}
}

View file

@ -0,0 +1,57 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
/// <summary>
/// Holds tariff info for a single bike.
/// </summary>
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
#if USCSHARP9
public record TariffDescription
#else
public class TariffDescription
#endif
{
/// <summary>
/// Name of the tariff.
/// </summary>
[DataMember]
public string name { get; private set; }
/// <summary>
/// Number of the tariff.
/// </summary>
[DataMember]
public string number { get; private set; }
/// <summary>
/// Costs per hour in euro.
/// </summary>
[DataMember]
public string eur_per_hour { get; private set; }
/// <summary>
/// Costs of the abo per month.
/// </summary>
[DataMember]
public string abo_eur_per_month { get; private set; }
/// <summary>
/// Costs per hour in euro.
/// </summary>
[DataMember]
public string free_hours { get; private set; }
/// <summary>
/// Maximum fee per day.
/// </summary>
[DataMember]
public string max_eur_per_day { get; private set; }
/// <summary> Text which informs users about GPS tracking if tracking is on. </summary>
[DataMember]
public string track_info { get; private set; }
}
}

View file

@ -0,0 +1,24 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
namespace ShareeBike.Repository.Response
{
[DataContract]
[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)]
public class VersionindependentResponse
{
private CopriVersion _shareejson;
/// <summary> Root element for versions 4.0 and older. </summary>
[DataMember]
public CopriVersion tinkjson { get; private set; }
/// <summary> Root element from 4.1 and later. </summary>
[DataMember]
public CopriVersion shareejson
{
get => _shareejson ?? tinkjson;
private set { _shareejson = value; }
}
}
}