Example #1
0
        public PictureparkServiceClientSettings(IOptions <PictureparkConfiguration> config)
        {
            var auth = new AccessTokenAuthClient(config.Value.BaseUrl, config.Value.AccessToken, config.Value.CustomerAlias);

            AuthClient    = auth;
            BaseUrl       = config.Value.BaseUrl;
            CustomerAlias = config.Value.CustomerAlias;
            HttpTimeout   = TimeSpan.FromMinutes(10);
        }
Example #2
0
        public PictureparkAccessTokenServiceSettings(PictureparkConfiguration config)
        {
            var auth = new AccessTokenAuthClient(config.ApiBaseUrl, config.AccessToken, config.CustomerAlias);

            AuthClient      = auth;
            BaseUrl         = config.ApiBaseUrl;
            CustomerAlias   = config.CustomerAlias;
            HttpTimeout     = TimeSpan.FromMinutes(10);
            DisplayLanguage = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
        }
        public static async Task Main(string[] args)
        {
            await new HostBuilder()
            .ConfigureLogging(
                (ctx, logging) =>
            {
                logging.AddConsole();
                logging.AddDebug();
            })
            .ConfigureAppConfiguration(
                (ctx, app) =>
            {
                app.SetBasePath(Directory.GetCurrentDirectory());
                app.AddJsonFile("appsettings.json", optional: true);
                app.AddCommandLine(args);
            })
            .ConfigureServices(
                (ctx, services) =>
            {
                services.AddOptions();
                services.Configure <SampleConfiguration>(ctx.Configuration.GetSection("config"));

                services.AddLogging();

                services.AddHostedService <ContentBatchDownloadService>();
                services.AddHostedService <LiveStreamSubscriber>();

                services.AddSingleton <IApplicationEventHandlerFactory, ApplicationEventHandlerFactory>();
                services.AddTransient <IApplicationEventHandler, BusinessRuleFiredEventHandler>();
                services.AddTransient <IApplicationEventHandler, BusinessProcessCancellationRequestedEventHandler>();

                services.AddSingleton <ContentIdQueue>();

                services.AddSingleton <Func <IPictureparkService> >(
                    s =>
                {
                    return(() =>
                    {
                        var config = s.GetRequiredService <IOptions <SampleConfiguration> >();

                        var authClient = new AccessTokenAuthClient(config.Value.ApiUrl, config.Value.AccessToken, config.Value.CustomerAlias);
                        var client = new PictureparkService(new PictureparkServiceSettings(authClient));

                        return client;
                    });
                });

                services.AddSingleton <IBusinessProcessCancellationManager, BusinessProcessCancellationManager>();
            })
            .UseConsoleLifetime()
            .RunConsoleAsync().ConfigureAwait(false);
        }
Example #4
0
        public PictureparkPerRequestClientSettings(IOptions <PictureparkConfiguration> config, IHttpContextAccessor httpContextAccessor)
        {
            _contextAccessor = httpContextAccessor;

            var accessToken = httpContextAccessor.HttpContext.GetTokenAsync("access_token").Result;

            var auth = new AccessTokenAuthClient(config.Value.BaseUrl, accessToken, config.Value.CustomerAlias);

            AuthClient    = auth;
            BaseUrl       = config.Value.BaseUrl;
            CustomerAlias = config.Value.CustomerAlias;
            HttpTimeout   = TimeSpan.FromMinutes(10);
        }
Example #5
0
        public async Task InitAsync()
        {
            if (_client == null)
            {
                var accessToken = await _authenticator.GetAccessTokenAsync();

                var authClient = new AccessTokenAuthClient(_appOptions.ApiBaseUrl, accessToken, _appOptions.CustomerAlias);

                var settings = new PictureparkServiceSettings(authClient);

                _client = new PictureparkService(settings, _httpClient);
            }
        }
Example #6
0
        public PictureparkPerRequestServiceSettings(PictureparkConfiguration config, IHttpContextAccessor httpContextAccessor)
        {
            _contextAccessor = httpContextAccessor;

            var accessToken = httpContextAccessor.HttpContext.GetTokenAsync("access_token").Result;

            var auth = new AccessTokenAuthClient(config.ApiBaseUrl, accessToken, config.CustomerAlias);

            AuthClient      = auth;
            BaseUrl         = config.ApiBaseUrl;
            CustomerAlias   = config.CustomerAlias;
            HttpTimeout     = TimeSpan.FromMinutes(10);
            DisplayLanguage = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
        }
Example #7
0
        public PictureparkService GetLocalizedPictureparkService(string language)
        {
            var authClient = new AccessTokenAuthClient(_configuration.Server, _configuration.AccessToken, _configuration.CustomerAlias);

            var settings = new PictureparkServiceSettings(authClient)
            {
                DisplayLanguage = language,
                HttpTimeout     = TimeSpan.FromMinutes(5)
            };

            var httpClient = new HttpClient(s_httpHandler)
            {
                Timeout = settings.HttpTimeout
            };

            return(new PictureparkService(settings, httpClient));
        }
        public ClientFixture()
        {
            ProjectDirectory = Path.GetFullPath(Path.GetDirectoryName(typeof(ClientFixture).GetTypeInfo().Assembly.Location) + "/../../../");

            // Fix
            if (!File.Exists(ProjectDirectory + "Configuration.json"))
            {
                ProjectDirectory += "../";
            }

            if (!Directory.Exists(TempDirectory))
            {
                Directory.CreateDirectory(TempDirectory);
            }

            var configurationJson = File.ReadAllText(ProjectDirectory + "Configuration.json");

            _configuration = JsonConvert.DeserializeObject <TestConfiguration>(configurationJson);

            var authClient = new AccessTokenAuthClient(_configuration.Server, _configuration.AccessToken, _configuration.CustomerAlias);

            _client = new PictureparkClient(new PictureparkClientSettings(authClient));
        }