Exemplo n.º 1
0
        public DefaultAutoFetchHandler(IAppSettingsService appSettingsService,
                                       IRepositoryInformationAggregator repositoryInformationAggregator,
                                       IRepositoryWriter repositoryWriter)
        {
            AppSettingsService = appSettingsService ?? throw new ArgumentNullException(nameof(appSettingsService));
            RepositoryInformationAggregator = repositoryInformationAggregator ?? throw new ArgumentNullException(nameof(repositoryInformationAggregator));
            RepositoryWriter = repositoryWriter ?? throw new ArgumentNullException(nameof(repositoryWriter));
            AppSettingsService.RegisterInvalidationHandler(() => Mode = AppSettingsService.AutoFetchMode);

            _profiles = new Dictionary <AutoFetchMode, AutoFetchProfile>
            {
                { AutoFetchMode.Off, new AutoFetchProfile()
                  {
                      PauseBetweenFetches = TimeSpan.MaxValue
                  } },
                { AutoFetchMode.Discretely, new AutoFetchProfile()
                  {
                      PauseBetweenFetches = TimeSpan.FromMinutes(5)
                  } },
                { AutoFetchMode.Adequate, new AutoFetchProfile()
                  {
                      PauseBetweenFetches = TimeSpan.FromMinutes(1)
                  } },
                { AutoFetchMode.Aggresive, new AutoFetchProfile()
                  {
                      PauseBetweenFetches = TimeSpan.FromSeconds(2)
                  } }
            };

            _timer = new Timer(FetchNext, null, Timeout.Infinite, Timeout.Infinite);
        }