using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; namespace TINK.Model.Services.CopriApi.ServerUris { [JsonObject(MemberSerialization.OptIn)] sealed public class CopriServerUriList { /// /// Holds the rest resource root name. /// public const string REST_RESOURCE_ROOT = "APIjsonserver"; /// Holds the URL of the TINK/Konrad test server. public const string TINK_DEVEL = @"https://tinkwwp.copri-bike.de/APIjsonserver"; /// Holds the URL the TINK/Konrad productive server. public const string TINK_LIVE = @"https://app.tink-konstanz.de/APIjsonserver"; /// Holds the URL the Sharee server. public const string SHAREE_DEVEL = @"https://shareeapp-primary.copri-bike.de/APIjsonserver"; /// Holds the URL the Sharee server. public const string SHAREE_LIVE = @"https://shareeapp-primary.copri.eu/APIjsonserver"; /// Constructs default uri list. public CopriServerUriList(Uri activeUri = null) : this ( new List { 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 { } /// Constructs uris object. /// Object to copy from. public CopriServerUriList(CopriServerUriList p_oSource) : this( p_oSource.Uris.ToArray(), p_oSource.ActiveUri) { } /// Constructs a valid uris object. /// Known uris. /// Zero based index of active uri. /// Uri of the development server. 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(uris); ActiveUri = p_oActiveUri; } /// Gets the active uri. [JsonProperty] public Uri ActiveUri { get; } /// Gets the active uri. #if USCSHARP9 public static Uri DevelopUri => new (TINK_DEVEL); #else public static Uri DevelopUri => new Uri(TINK_DEVEL); #endif /// Gets the known uris. [JsonProperty] public IList Uris { get ; } /// Gets the default uri which is active after first installation. public static Uri DefaultActiveUri { get { return new CopriServerUriList().ActiveUri; } } } }