/// <summary> /// Loads server from a dictionary object (provided by JSON) /// </summary> /// <param name="obj">Key/value dictionary with <c>server_type</c>, <c>base_url</c>, <c>display_name</c>, <c>country_code</c> and <c>support_contact</c> elements.</param> /// <exception cref="eduJSON.InvalidParameterTypeException"><paramref name="obj"/> type is not <c>Dictionary<string, object></c></exception> public virtual void Load(object obj) { if (!(obj is Dictionary <string, object> obj2)) { throw new eduJSON.InvalidParameterTypeException(nameof(obj), typeof(Dictionary <string, object>), obj.GetType()); } // Set base URI. Endpoints = null; Profiles = null; Base = new Uri(eduJSON.Parser.GetValue <string>(obj2, "base_url")); // Set support contact URLs. SupportContacts.Clear(); if (eduJSON.Parser.GetValue(obj2, "support_contact", out List <object> support_contact)) { foreach (var c in support_contact) { if (c is string cStr) { SupportContacts.Add(new Uri(cStr)); } } } }
/// <summary> /// Gets and loads server endpoints /// </summary> /// <param name="ct">The token to monitor for cancellation requests</param> /// <returns>Server endpoints</returns> public ServerEndpoints GetEndpoints(CancellationToken ct = default) { lock (EndpointsLock) { if (Endpoints != null) { return(Endpoints); } try { // Get and load API endpoints. var endpoints = new ServerEndpoints(); var uriBuilder = new UriBuilder(Base); uriBuilder.Path += ".well-known/vpn-user-portal"; Trace.TraceInformation("Loading endpoints {0}", uriBuilder.Uri); endpoints.LoadJSON(Xml.Response.Get( uri: uriBuilder.Uri, ct: ct).Value, ct); return(Endpoints = endpoints); } catch (OperationCanceledException) { throw; } catch (Exception ex) { throw new AggregateException(Resources.Strings.ErrorEndpointsLoad, ex); } } }