sharee.bike-App/SharedBusinessLogic/Services/CopriApi/ServerUris/CopriServerUriList.cs

93 lines
2.9 KiB
C#
Raw Normal View History

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
2024-04-09 12:53:23 +02:00
namespace ShareeBike.Model.Services.CopriApi.ServerUris
2021-05-13 20:03:07 +02:00
{
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
2024-04-09 12:53:23 +02:00
/// <summary> Holds the URL of the ShareeBike/Citybike test server.</summary>
public const string ShareeBike_DEVEL = @"https://tinkwwp.copri-bike.de/APIjsonserver";
2021-05-13 20:03:07 +02:00
2024-04-09 12:53:23 +02:00
/// <summary> Holds the URL the ShareeBike/Citybike productive server.</summary>
public const string ShareeBike_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),
2024-04-09 12:53:23 +02:00
new Uri(ShareeBike_LIVE),
2022-09-06 16:08:19 +02:00
new Uri(SHAREE_DEVEL),
2024-04-09 12:53:23 +02:00
new Uri(ShareeBike_DEVEL)
2022-09-06 16:08:19 +02:00
}.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
2024-04-09 12:53:23 +02:00
public static Uri DevelopUri => new (ShareeBike_DEVEL);
2021-06-26 20:57:55 +02:00
#else
2024-04-09 12:53:23 +02:00
public static Uri DevelopUri => new Uri(ShareeBike_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
}