using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; namespace ShareeBike.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 ShareeBike/Citybike test server. public const string ShareeBike_DEVEL = @"https://tinkwwp.copri-bike.de/APIjsonserver"; /// Holds the URL the ShareeBike/Citybike productive server. public const string ShareeBike_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(ShareeBike_LIVE), new Uri(SHAREE_DEVEL), new Uri(ShareeBike_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 (ShareeBike_DEVEL); #else public static Uri DevelopUri => new Uri(ShareeBike_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; } } } }