public TranslatorApiEnumerationRepository(
            EnumerationRepositoryConfiguration configuration,
            IRestClient restClient,
            ISpiExecutionContextManager executionContextManager,
            ICacheProvider cacheProvider,
            ILoggerWrapper logger)
        {
            _configuration           = configuration;
            _restClient              = restClient;
            _executionContextManager = executionContextManager;
            _cacheProvider           = cacheProvider;
            _logger = logger;

            _restClient.BaseUrl = new Uri(configuration.TranslatorApiBaseUrl);
            if (!string.IsNullOrEmpty(configuration.TranslatorApiFunctionKey))
            {
                _restClient.DefaultParameters.Add(new Parameter(CommonHeaderNames.AzureFunctionKeyHeaderName,
                                                                configuration.TranslatorApiFunctionKey, ParameterType.HttpHeader));
            }

            if (!string.IsNullOrEmpty(configuration.TranslatorApiSubscriptionKey))
            {
                _restClient.DefaultParameters.Add(new Parameter(CommonHeaderNames.EapimSubscriptionKeyHeaderName,
                                                                configuration.TranslatorApiSubscriptionKey,
                                                                ParameterType.HttpHeader));
            }
        }
        /// <summary>
        /// Initialises a new instance of the
        /// <see cref="TranslationApiAdapter" /> class.
        /// </summary>
        /// <param name="loggerWrapper">
        /// An instance of type <see cref="ILoggerWrapper" />.
        /// </param>
        /// <param name="spiExecutionContextManager">
        /// An instance of type <see cref="ISpiExecutionContextManager" />.
        /// </param>
        /// <param name="translationApiAdapterSettingsProvider">
        /// An instance of type
        /// <see cref="ITranslationApiAdapterSettingsProvider" />.
        /// </param>
        public TranslationApiAdapter(
            ILoggerWrapper loggerWrapper,
            ISpiExecutionContextManager spiExecutionContextManager,
            ITranslationApiAdapterSettingsProvider translationApiAdapterSettingsProvider)
        {
            if (translationApiAdapterSettingsProvider == null)
            {
                throw new ArgumentNullException(
                          nameof(translationApiAdapterSettingsProvider));
            }

            this.loggerWrapper = loggerWrapper;
            this.spiExecutionContextManager = spiExecutionContextManager;

            Uri translationApiBaseUri =
                translationApiAdapterSettingsProvider.TranslationApiBaseUri;

            this.restClient = new RestClient(translationApiBaseUri);

            string translationApiSubscriptionKey =
                translationApiAdapterSettingsProvider.TranslationApiSubscriptionKey;

            this.restClient.AddDefaultHeader(
                CommonHeaderNames.EapimSubscriptionKeyHeaderName,
                translationApiSubscriptionKey);
        }
        public TranslatorApiClient(
            AuthenticationConfiguration authenticationConfiguration,
            IRestClient restClient,
            ICacheProvider cacheProvider,
            ISpiExecutionContextManager spiExecutionContextManager,
            TranslatorConfiguration configuration,
            ILoggerWrapper logger)
        {
            _restClient    = restClient;
            _cacheProvider = cacheProvider;
            _spiExecutionContextManager = spiExecutionContextManager;

            _restClient.BaseUrl = new Uri(configuration.BaseUrl);
            if (!string.IsNullOrEmpty(configuration.SubscriptionKey))
            {
                _restClient.DefaultParameters.Add(
                    new Parameter("Ocp-Apim-Subscription-Key", configuration.SubscriptionKey, ParameterType.HttpHeader));
            }

            _logger = logger;

            _oAuth2ClientCredentialsAuthenticator = new OAuth2ClientCredentialsAuthenticator(
                authenticationConfiguration.TokenEndpoint,
                authenticationConfiguration.ClientId,
                authenticationConfiguration.ClientSecret,
                authenticationConfiguration.Resource);
        }
 protected SpiAdapter(
     string baseUrl,
     string subscriptionKey,
     HttpClient httpClient,
     ISpiExecutionContextManager executionContextManager,
     ILoggerWrapper logger)
 {
     _baseUrl                 = baseUrl;
     _subscriptionKey         = subscriptionKey;
     _httpClient              = httpClient;
     _executionContextManager = executionContextManager;
     _logger = logger;
 }
 public SyncManager(
     ISyncQueue syncQueue,
     IRepository repository,
     IMatcher matcher,
     ILoggerWrapper logger,
     ISpiExecutionContextManager executionContextManager)
 {
     _syncQueue  = syncQueue;
     _repository = repository;
     _matcher    = matcher;
     _logger     = logger;
     _executionContextManager = executionContextManager;
 }
Пример #6
0
        public RegistryApiRegistryProvider(
            IRestClient restClient,
            RegistryConfiguration configuration,
            ISpiExecutionContextManager executionContextManager,
            ILoggerWrapper logger)
        {
            _restClient = restClient;
            _executionContextManager = executionContextManager;
            _restClient.BaseUrl      = new Uri(configuration.RegistryApiBaseUrl, UriKind.Absolute);
            if (!string.IsNullOrEmpty(configuration.RegistryApiFunctionKey))
            {
                _restClient.DefaultParameters.Add(new Parameter(CommonHeaderNames.AzureFunctionKeyHeaderName, configuration.RegistryApiFunctionKey,
                                                                ParameterType.HttpHeader));
            }
            if (!string.IsNullOrEmpty(configuration.RegistryApiSubscriptionKey))
            {
                _restClient.DefaultParameters.Add(new Parameter(CommonHeaderNames.EapimSubscriptionKeyHeaderName, configuration.RegistryApiSubscriptionKey,
                                                                ParameterType.HttpHeader));
            }

            _logger = logger;
        }
Пример #7
0
        public SquasherEntityRepository(
            IRestClient restClient,
            EntityRepositoryConfiguration configuration,
            ISpiExecutionContextManager executionContextManager,
            ILoggerWrapper logger)
        {
            _restClient              = restClient;
            _restClient.Timeout      = 600 * 1000; // 600s - 10m
            _executionContextManager = executionContextManager;
            _restClient.BaseUrl      = new Uri(configuration.SquasherApiBaseUrl, UriKind.Absolute);
            if (!string.IsNullOrEmpty(configuration.SquasherApiFunctionKey))
            {
                _restClient.DefaultParameters.Add(new Parameter(CommonHeaderNames.AzureFunctionKeyHeaderName, configuration.SquasherApiFunctionKey,
                                                                ParameterType.HttpHeader));
            }
            if (!string.IsNullOrEmpty(configuration.SquasherApiSubscriptionKey))
            {
                _restClient.DefaultParameters.Add(new Parameter(CommonHeaderNames.EapimSubscriptionKeyHeaderName, configuration.SquasherApiSubscriptionKey,
                                                                ParameterType.HttpHeader));
            }

            _logger = logger;
        }
Пример #8
0
        /// <summary>
        /// Initialises a new instance of the <see cref="LoggerWrapper"/> class.
        /// class.
        /// </summary>
        /// <param name="logger">
        /// An instance of type <see cref="ILogger" />.
        /// </param>
        /// <param name="spiExecutionContextManager">
        /// An instance of type <see cref="ISpiExecutionContextManager" />.
        /// </param>
        public LoggerWrapper(
            ILogger logger,
            ISpiExecutionContextManager spiExecutionContextManager)
        {
            this.logger = logger;
            this.spiExecutionContextManager = spiExecutionContextManager;

            this.logDebug = LoggerMessage.Define <string, Guid?, string>(
                LogLevel.Debug,
                new EventId(1001),
                LogMessagePattern);
            this.logInfo = LoggerMessage.Define <string, Guid?, string>(
                LogLevel.Information,
                new EventId(1002),
                LogMessagePattern);
            this.logWarning = LoggerMessage.Define <string, Guid?, string>(
                LogLevel.Warning,
                new EventId(1003),
                LogMessagePattern);
            this.logError = LoggerMessage.Define <string, Guid?, string>(
                LogLevel.Error,
                new EventId(1004),
                LogMessagePattern);
        }
 public IStoreDataAdapter(EntitySquasherConfiguration configuration, HttpClient httpClient, ISpiExecutionContextManager executionContextManager, ILoggerWrapper logger)
     : base(configuration.IStore.Url, configuration.IStore.SubscriptionKey, httpClient, executionContextManager, logger)
 {
 }