2022-08-30 15:42:25 +02:00
using System ;
2021-05-13 20:03:07 +02:00
using System.Collections.Generic ;
using System.Linq ;
2022-08-30 15:42:25 +02:00
using Newtonsoft.Json ;
2021-05-13 20:03:07 +02:00
namespace TINK.Model.Services.CopriApi.ServerUris
{
2022-09-06 16:08:19 +02:00
[JsonObject(MemberSerialization.OptIn)]
sealed public class CopriServerUriList
{
/// <summary>
/// Holds the rest resource root name.
/// </summary>
public const string REST_RESOURCE_ROOT = "APIjsonserver" ;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds the URL of the TINK/Konrad test server.</summary>
public const string TINK_DEVEL = @"https://tinkwwp.copri-bike.de/APIjsonserver" ;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds the URL the TINK/Konrad productive server.</summary>
public const string TINK_LIVE = @"https://app.tink-konstanz.de/APIjsonserver" ;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds the URL the Sharee server.</summary>
public const string SHAREE_DEVEL = @"https://shareeapp-primary.copri-bike.de/APIjsonserver" ;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Holds the URL the Sharee server.</summary>
public const string SHAREE_LIVE = @"https://shareeapp-primary.copri.eu/APIjsonserver" ;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>Constructs default uri list.</summary>
public CopriServerUriList ( Uri activeUri = null ) : this (
new List < Uri >
{
new Uri ( SHAREE_LIVE ) ,
new Uri ( TINK_LIVE ) ,
new Uri ( SHAREE_DEVEL ) ,
new Uri ( TINK_DEVEL )
} . ToArray ( ) ,
activeUri ? ? new Uri ( SHAREE_LIVE ) ) // Default URi which is used after install of app
{
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Constructs uris object. </summary>
/// <param name="p_oSource">Object to copy from.</param>
public CopriServerUriList ( CopriServerUriList p_oSource ) : this (
p_oSource . Uris . ToArray ( ) ,
p_oSource . ActiveUri )
{
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Constructs a valid uris object. </summary>
/// <param name="uris">Known uris.</param>
/// <param name="p_oActiveUri">Zero based index of active uri.</param>
/// <param name="p_oDevelUri">Uri of the development server.</param>
public CopriServerUriList (
Uri [ ] uris ,
Uri p_oActiveUri )
{
if ( uris = = null | | uris . Length < 1 )
{
throw new ArgumentException ( $"Can not construct {typeof(CopriServerUriList)}- object. Array of uris must not be null and contain at least one element." ) ;
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
if ( ! uris . Contains ( p_oActiveUri ) )
{
throw new ArgumentException ( $"Active uri {p_oActiveUri} not contained in ({string.Join(" ; ", uris.Select(x => x.AbsoluteUri))})." ) ;
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
Uris = new List < Uri > ( uris ) ;
ActiveUri = p_oActiveUri ;
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Gets the active uri. </summary>
[JsonProperty]
public Uri ActiveUri { get ; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Gets the active uri. </summary>
2021-06-26 20:57:55 +02:00
#if USCSHARP9
public static Uri DevelopUri = > new ( TINK_DEVEL ) ;
#else
2022-09-06 16:08:19 +02:00
public static Uri DevelopUri = > new Uri ( TINK_DEVEL ) ;
2021-06-26 20:57:55 +02:00
#endif
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Gets the known uris. </summary>
[JsonProperty]
public IList < Uri > Uris { get ; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary> Gets the default uri which is active after first installation. </summary>
public static Uri DefaultActiveUri
{
get { return new CopriServerUriList ( ) . ActiveUri ; }
}
}
2021-05-13 20:03:07 +02:00
}