public InstallationRepositoriesEventHandler(
     IAppTelemetry telemetry,
     ILogger <InstallationRepositoriesEventHandler> logger)
 {
     this.telemetry = telemetry;
     this.logger    = logger;
 }
        public SpillableMemoryCache(IServiceProvider serviceProvider, ILoggerFactory loggerFactory)
        {
            logger       = loggerFactory.CreateLogger <SpillableMemoryCache>();
            appTelemetry = serviceProvider.GetRequiredService <IAppTelemetry>();
            var configration = serviceProvider.GetRequiredService <IConfiguration>();

            cacheSettings = configration.GetConfiguredSettings <CacheSettings>();
            var binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            if (binFolder == null)
            {
                throw new InvalidOperationException("invalid bin folder");
            }
            cacheFolder = Path.Combine(binFolder, cacheSettings.FileCache.CacheFolder);
            logger.LogInformation($"set cache folder to: {cacheFolder}");
            if (!Directory.Exists(cacheFolder))
            {
                logger.LogInformation($"create cache folder: {cacheFolder}");
                Directory.CreateDirectory(cacheFolder);
            }

            var cacheOptions = new MemoryCacheOptions
            {
                Clock = new SystemClock(),
                CompactionPercentage    = cacheSettings.MemoryCache.CompactionPercentage,
                SizeLimit               = cacheSettings.MemoryCache.SizeLimit,
                ExpirationScanFrequency = cacheSettings.TimeToLive
            };

            memoryCache = new MemoryCache(new OptionsWrapper <MemoryCacheOptions>(cacheOptions));
        }
        public AzureServiceBus(
            IOptions <AzureServiceBusSettings> settings,
            IAppTelemetry telemetry,
            ILogger <AzureServiceBus> logger)
        {
            this.telemetry = telemetry;
            this.logger    = logger;
            this.settings  = settings.Value;

            serviceBusClient = new ServiceBusClient(
                this.settings.ConnectionString,
                new ServiceBusClientOptions
            {
                TransportType = ServiceBusTransportType.AmqpWebSockets
            });

            // create a sender for the topic
            sender = serviceBusClient.CreateSender(this.settings.TopicName);

            // create a processor that we can use to process the messages
            processor = serviceBusClient.CreateProcessor(
                this.settings.TopicName,
                this.settings.SubscriptionName,
                new ServiceBusProcessorOptions
            {
                MaxConcurrentCalls         = 10,
                MaxAutoLockRenewalDuration = TimeSpan.FromDays(3)     // auto lock renewal max 3 days to allow us to process long running events
            });
        }
 public PullRequestEventHandler(
     IGitHubClientAdapterFactory gitHubClientAdapterFactory,
     IAppTelemetry telemetry,
     ILogger <PullRequestEventHandler> logger)
 {
     this.gitHubClientAdapterFactory = gitHubClientAdapterFactory;
     this.telemetry = telemetry;
     this.logger    = logger;
 }
Example #5
0
 public BlobCache(IServiceProvider serviceProvider, ILoggerFactory loggerFactory)
 {
     logger = loggerFactory.CreateLogger<BlobCache>();
     appTelemetry = serviceProvider.GetRequiredService<IAppTelemetry>();
     var configuration = serviceProvider.GetRequiredService<IConfiguration>();
     cacheSettings = configuration.GetConfiguredSettings<CacheSettings>();
     blobClient = new BlobClient(serviceProvider, loggerFactory,
         new OptionsWrapper<BlobStorageSettings>(cacheSettings.BlobCache));
 }
Example #6
0
 public BatchCreator(IConfiguration configuration, ILoggerFactory loggerFactory, IAppTelemetry appTelemetry,
                     IBlobClient blobClient, IRangeHelper <TField> rangeHelper)
 {
     _batchSetting = configuration.GetConfiguredSettings <BatchSetting <TField> >();
     _logger       = loggerFactory.CreateLogger <BatchCreator <TField> >();
     _appTelemetry = appTelemetry;
     _blobClient   = blobClient;
     _rangeHelper  = rangeHelper;
     _getBlobName  = t => $"{_batchSetting.Name}-{t.Sequence}";
 }
 public GitHubEventHost(
     IEventBus eventBus,
     IAppTelemetry telemetry,
     IEnumerable <IGitHubEventHandler> gitHubEventHandlers,
     ILogger <GitHubEventHost> logger)
 {
     this.eventBus            = eventBus;
     this.telemetry           = telemetry;
     this.logger              = logger;
     this.gitHubEventHandlers = gitHubEventHandlers.ToDictionary(h => h.EventType);
 }
Example #8
0
        public GitHubClientAdapterFactory(
            IReadOnlyDictionary <string, IGitHubJwtFactory> gitHubJwtFactories,
            IOptions <GitHubAppFlavorSettings> gitHubAppFlavorSettings,
            IAppTelemetry appTelemetry)
        {
            ArgumentCheck.ParameterIsNotNull(gitHubJwtFactories, nameof(gitHubJwtFactories));
            ArgumentCheck.ParameterIsNotNull(gitHubAppFlavorSettings, nameof(gitHubAppFlavorSettings));
            ArgumentCheck.ParameterIsNotNull(appTelemetry, nameof(appTelemetry));

            this.gitHubJwtFactories      = gitHubJwtFactories;
            this.appTelemetry            = appTelemetry;
            this.gitHubAppFlavorSettings = gitHubAppFlavorSettings.Value;
        }
Example #9
0
        public GitHubWebhookController(
            IOptions <GitHubAppFlavorSettings> gitHubAppFlavorSettings,
            IAppTelemetry appTelemetry,
            IEventBus eventBus)
        {
            ArgumentCheck.ParameterIsNotNull(gitHubAppFlavorSettings, nameof(gitHubAppFlavorSettings));
            ArgumentCheck.ParameterIsNotNull(gitHubAppFlavorSettings, nameof(gitHubAppFlavorSettings));
            ArgumentCheck.ParameterIsNotNull(appTelemetry, nameof(appTelemetry));

            this.appTelemetry            = appTelemetry;
            this.eventBus                = eventBus;
            this.gitHubAppFlavorSettings = gitHubAppFlavorSettings.Value;
        }
 public InstallationEventHandler(
     IAppTelemetry telemetry,
     ILogger <InstallationEventHandler> logger,
     IGitHubClientAdapterFactory gitHubClientAdapterFactory,
     IFileSystem fileSystem,
     IBlobStorage blobStorage)
 {
     this.telemetry = telemetry;
     this.logger    = logger;
     this.gitHubClientAdapterFactory = gitHubClientAdapterFactory;
     this.fileSystem  = fileSystem;
     this.blobStorage = blobStorage;
 }
Example #11
0
        public CacheProvider(IServiceProvider serviceProvider, ILoggerFactory loggerFactory)
        {
            logger       = loggerFactory.CreateLogger <CacheProvider>();
            appTelemetry = serviceProvider.GetRequiredService <IAppTelemetry>();
            var configuration = serviceProvider.GetRequiredService <IConfiguration>();

            settings = configuration.GetConfiguredSettings <CacheSettings>();
            if (settings.MemoryCache == null)
            {
                throw new InvalidOperationException("Memory cache is not configured");
            }

            cacheEntryOptions = new DistributedCacheEntryOptions
            {
                SlidingExpiration = settings.TimeToLive
            };

            multilayerCache = new MultilayerCache(new SpillableMemoryCache(serviceProvider, loggerFactory))
            {
                PopulateLayersOnGet = true
            };
            if (settings.BlobCache != null)
            {
                multilayerCache.AppendLayer(new BlobCache(serviceProvider, loggerFactory));
                blobCacheClient = new BlobClient(
                    serviceProvider,
                    loggerFactory,
                    new OptionsWrapper <BlobStorageSettings>(settings.BlobCache));
            }

            if (settings.RedisCache != null)
            {
                var kvClient      = serviceProvider.GetRequiredService <IKeyVaultClient>();
                var vaultSettings = configuration.GetConfiguredSettings <VaultSettings>();
                var accessKey     = kvClient.GetSecretAsync(vaultSettings.VaultUrl, settings.RedisCache.AccessKeySecretName)
                                    .GetAwaiter().GetResult();
                var connStr           = $"{settings.RedisCache.HostName},password={accessKey.Value},ssl=True,abortConnect=False";
                var redisCacheOptions = new RedisCacheOptions
                {
                    Configuration = connStr
                };
                var redisCache = new RedisCache(new OptionsWrapper <RedisCacheOptions>(redisCacheOptions));
                multilayerCache.AppendLayer(redisCache);
            }
        }
Example #12
0
        public AzureServiceBus(
            IOptions <AzureServiceBusSettings> settings,
            IAppTelemetry telemetry,
            ILogger <AzureServiceBus> logger)
        {
            this.telemetry = telemetry;
            this.logger    = logger;
            this.settings  = settings.Value;

            serviceBusClient = new ServiceBusClient(this.settings.ConnectionString);

            // create a sender for the topic
            sender = serviceBusClient.CreateSender(this.settings.TopicName);

            // create a processor that we can use to process the messages
            processor = serviceBusClient.CreateProcessor(
                this.settings.TopicName,
                this.settings.SubscriptionName,
                new ServiceBusProcessorOptions
            {
                MaxConcurrentCalls = 10
            });
        }
 public GitHubClientMessageHandler(IAppTelemetry metrics)
 {
     AllowAutoRedirect = false;
     this.metrics      = metrics;
 }
Example #14
0
 public KeepAlive(ILogger <KeepAlive> log, IAppTelemetry metrics)
 {
     this.log     = log;
     this.metrics = metrics;
 }