sharee.bike-App/TINKLib/Services/CopriApi/ServerUris/CopriServerUriList.cs
Anja Müller-Meißner 0468955d49 Version 3.0.338
2022-09-08 09:55:14 +02:00

92 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
namespace TINK.Model.Services.CopriApi.ServerUris
{
[JsonObject(MemberSerialization.OptIn)]
sealed public class CopriServerUriList
{
/// <summary>
/// Holds the rest resource root name.
/// </summary>
public const string REST_RESOURCE_ROOT = "APIjsonserver";
/// <summary> Holds the URL of the TINK/Konrad test server.</summary>
public const string TINK_DEVEL = @"https://tinkwwp.copri-bike.de/APIjsonserver";
/// <summary> Holds the URL the TINK/Konrad productive server.</summary>
public const string TINK_LIVE = @"https://app.tink-konstanz.de/APIjsonserver";
/// <summary> Holds the URL the Sharee server.</summary>
public const string SHAREE_DEVEL = @"https://shareeapp-primary.copri-bike.de/APIjsonserver";
/// <summary> Holds the URL the Sharee server.</summary>
public const string SHAREE_LIVE = @"https://shareeapp-primary.copri.eu/APIjsonserver";
/// <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
{
}
/// <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)
{
}
/// <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.");
}
if (!uris.Contains(p_oActiveUri))
{
throw new ArgumentException($"Active uri {p_oActiveUri} not contained in ({string.Join("; ", uris.Select(x => x.AbsoluteUri))}).");
}
Uris = new List<Uri>(uris);
ActiveUri = p_oActiveUri;
}
/// <summary> Gets the active uri. </summary>
[JsonProperty]
public Uri ActiveUri { get; }
/// <summary> Gets the active uri. </summary>
#if USCSHARP9
public static Uri DevelopUri => new (TINK_DEVEL);
#else
public static Uri DevelopUri => new Uri(TINK_DEVEL);
#endif
/// <summary> Gets the known uris. </summary>
[JsonProperty]
public IList<Uri> Uris { get; }
/// <summary> Gets the default uri which is active after first installation. </summary>
public static Uri DefaultActiveUri
{
get { return new CopriServerUriList().ActiveUri; }
}
}
}