/// <summary> /// Throws an exception if the given service configuration cannot be validated. /// </summary> private void ValidateConfigOrThrow(EmsApiServiceConfiguration config) { if (!config.Validate(out string error)) { throw new EmsApiConfigurationException(error); } }
public void UpdateConfiguration(EmsApiServiceConfiguration config) { m_serviceConfig = config; m_authUrl = string.Format("{0}/token", m_serviceConfig.Endpoint); // Set the token to invalid in case we need to use different authentication now. m_tokenExpiration = DateTime.UtcNow; Authenticated = false; }
/// <summary> /// Internally sets the current service configuration without validation. This is used /// with the default constructor so that the user can specify a configuration using the /// ServiceConfig property without forcing a validation (because the default config is /// invalid without a credential). /// </summary> private void SetServiceConfigInternal(EmsApiServiceConfiguration config) { m_config = config; m_clientHandler.ServiceConfig = config; // Reset the default headers, they may have changed with the config. m_httpClient.DefaultRequestHeaders.Clear(); m_config.AddDefaultRequestHeaders(m_httpClient.DefaultRequestHeaders); // See if the endpoint has changed. if (m_config.Endpoint != m_endpoint) { m_endpoint = m_config.Endpoint; // Reset the BaseAddress, and create a new refit service stub. // It's bound to the HttpClient's base address when it's constructed. m_httpClient.BaseAddress = new Uri(m_config.Endpoint); RefitApi = RestService.For <IEmsApi>(m_httpClient); } }
/// <summary> /// Provides access to the EMS API using the provided configuration settings. /// At a minimum, a username and password must be specified. /// </summary> public EmsApiService(EmsApiServiceConfiguration config) { Initialize(); ServiceConfig = config; }
/// <summary> /// Provides access to the EMS API using the provided configuration settings. /// At a minimum, a username and password must be specified. /// </summary> public EmsApiService(EmsApiServiceConfiguration config) { ValidateConfigOrThrow(config); m_config = config; Initialize(); }
/// <summary> /// Provides access to the EMS API. The <seealso cref="ServiceConfig"/> property /// must be set on this class before any API methods can be used. /// </summary> public EmsApiService() { m_config = new EmsApiServiceConfiguration(); Initialize(); }
public EmsApiTokenHandler(EmsApiServiceConfiguration serviceConfig) { UpdateConfiguration(serviceConfig); }