Example #1
0
 /// <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);
     }
 }
Example #2
0
            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;
            }
Example #3
0
        /// <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);
            }
        }
Example #4
0
 /// <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;
 }
Example #5
0
 /// <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();
 }
Example #6
0
 /// <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();
 }
Example #7
0
 public EmsApiTokenHandler(EmsApiServiceConfiguration serviceConfig)
 {
     UpdateConfiguration(serviceConfig);
 }