コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FanArtMovieProvider" /> class.
 /// </summary>
 /// <param name="httpClient">The HTTP client.</param>
 /// <param name="logManager">The log manager.</param>
 /// <param name="configurationManager">The configuration manager.</param>
 /// <param name="providerManager">The provider manager.</param>
 /// <exception cref="System.ArgumentNullException">httpClient</exception>
 public FanArtMovieProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
     : base(logManager, configurationManager)
 {
     if (httpClient == null)
     {
         throw new ArgumentNullException("httpClient");
     }
     HttpClient = httpClient;
     _providerManager = providerManager;
     Current = this;
 }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FanArtMovieProvider" /> class.
 /// </summary>
 /// <param name="httpClient">The HTTP client.</param>
 /// <param name="logManager">The log manager.</param>
 /// <param name="configurationManager">The configuration manager.</param>
 /// <param name="providerManager">The provider manager.</param>
 /// <exception cref="System.ArgumentNullException">httpClient</exception>
 public FanArtMovieProvider(IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager)
     : base(logManager, configurationManager)
 {
     if (httpClient == null)
     {
         throw new ArgumentNullException("httpClient");
     }
     HttpClient       = httpClient;
     _providerManager = providerManager;
     Current          = this;
 }
コード例 #3
0
        /// <summary>
        /// Runs the specified progress.
        /// </summary>
        /// <param name="progress">The progress.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        public async Task Run(IProgress <double> progress, CancellationToken cancellationToken)
        {
            if (!_config.Configuration.EnableInternetProviders)
            {
                progress.Report(100);
                return;
            }

            var path = FanArtMovieProvider.GetMoviesDataPath(_config.CommonApplicationPaths);

            Directory.CreateDirectory(path);

            var timestampFile = Path.Combine(path, "time.txt");

            var timestampFileInfo = new FileInfo(timestampFile);

            // Don't check for tvdb updates anymore frequently than 24 hours
            if (timestampFileInfo.Exists && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(timestampFileInfo)).TotalDays < 1)
            {
                return;
            }

            // Find out the last time we queried for updates
            var lastUpdateTime = timestampFileInfo.Exists ? File.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty;

            var existingDirectories = Directory.EnumerateDirectories(path).Select(Path.GetFileName).ToList();

            // If this is our first time, don't do any updates and just record the timestamp
            if (!string.IsNullOrEmpty(lastUpdateTime))
            {
                var moviesToUpdate = await GetMovieIdsToUpdate(existingDirectories, lastUpdateTime, cancellationToken).ConfigureAwait(false);

                progress.Report(5);

                await UpdateMovies(moviesToUpdate, progress, cancellationToken).ConfigureAwait(false);
            }

            var newUpdateTime = Convert.ToInt64(DateTimeToUnixTimestamp(DateTime.UtcNow)).ToString(UsCulture);

            File.WriteAllText(timestampFile, newUpdateTime, Encoding.UTF8);

            progress.Report(100);
        }