コード例 #1
0
        public async Task Execute(CancellationToken cancellationToken, IProgress <double> progress)
        {
            var settings = _configurationRepository.GetSingle();

            if (!settings.WizardFinished)
            {
                Log.Warning("Movie sync task not running because wizard is not finished yet!");
                return;
            }
            progress.Report(15);

            _embyClient.SetAddressAndUrl(settings.EmbyServerAddress, settings.AccessToken);
            var systemInfoReponse = await _embyClient.GetServerInfoAsync();

            progress.Report(35);
            var pluginsResponse = await _embyClient.GetInstalledPluginsAsync();

            progress.Report(55);
            var drives = await _embyClient.GetLocalDrivesAsync();

            progress.Report(75);

            var systemInfo  = Mapper.Map <ServerInfo>(systemInfoReponse);
            var localDrives = Mapper.Map <IList <Drives> >(drives);

            _embyServerInfoRepository.UpdateOrAdd(systemInfo);
            progress.Report(85);
            _embyPluginRepository.RemoveAllAndInsertPluginRange(pluginsResponse);
            progress.Report(95);
            _embyDriveRepository.ClearAndInsertList(localDrives.ToList());
            progress.Report(100);
        }
コード例 #2
0
        public async Task Execute(CancellationToken cancellationToken, IProgress <double> progress)
        {
            _settings = _configurationRepository.GetSingle();
            if (!_settings.WizardFinished)
            {
                Log.Warning("Movie sync task not running because wizard is not finished yet!");
                return;
            }

            _embyClient.SetAddressAndUrl(_settings.EmbyServerAddress, _settings.AccessToken);

            Log.Information("First delete all existing movies and root movie collections from database so we have a clean start.");
            CleanUpDatabase();
            progress.Report(10);

            var rootItems = await GetMovieRootItems(_settings.EmbyUserId, cancellationToken);

            AddRootItemsToDb(rootItems);
            Log.Information($"Found {rootItems.Count} root items, getting ready for processing");
            progress.Report(20);

            cancellationToken.ThrowIfCancellationRequested();

            for (var i = 0; i < rootItems.Count; i++)
            {
                cancellationToken.ThrowIfCancellationRequested();
                Log.Information($"Asking Emby all movies for parent ({rootItems[i].Id}) {rootItems[i].Name}");
                var movies = (await GetMoviesFromEmby(rootItems[i].Id, cancellationToken)).ToList();
                movies.ForEach(x => x.CollectionId = rootItems[i].Id);

                await ProcessGenresFromEmby(rootItems[i].Id, movies.SelectMany(x => x.MediaGenres, (movie, genre) => genre.GenreId), cancellationToken);

                progress.Report(Math.Round(20 + (80 / (double)rootItems.Count * i) + (80 / (double)rootItems.Count * i) / 4));
                await ProcessPeopleFromEmby(rootItems[i].Id, movies.SelectMany(x => x.ExtraPersons, (movie, person) => person.PersonId), cancellationToken);

                progress.Report(Math.Round(20 + (80 / (double)rootItems.Count * i) + (80 / (double)rootItems.Count * i) / 2));

                var j = 0;
                foreach (var movie in movies)
                {
                    j++;
                    cancellationToken.ThrowIfCancellationRequested();
                    Log.Information($"Processing movie ({movie.Id}) {movie.Name}");
                    AddMoviesToDb(movie);
                    progress.Report(Math.Round(20 + (80 / (double)rootItems.Count * i) + ((80 / (double)rootItems.Count * i) / 2) / movies.Count * j));
                }
            }
        }
コード例 #3
0
ファイル: EmbyService.cs プロジェクト: yangkghjh/EmbyStat
        public async void FireSmallSyncEmbyServerInfo()
        {
            var settings = _configurationRepository.GetSingle();

            _embyClient.SetAddressAndUrl(settings.EmbyServerAddress, settings.AccessToken);
            var systemInfoReponse = await _embyClient.GetServerInfoAsync();

            var pluginsResponse = await _embyClient.GetInstalledPluginsAsync();

            var drives = await _embyClient.GetLocalDrivesAsync();

            var systemInfo  = Mapper.Map <ServerInfo>(systemInfoReponse);
            var localDrives = Mapper.Map <IList <Drives> >(drives);

            _embyServerInfoRepository.UpdateOrAdd(systemInfo);
            _embyPluginRepository.RemoveAllAndInsertPluginRange(pluginsResponse);
            _embyDriveRepository.ClearAndInsertList(localDrives.ToList());
        }
コード例 #4
0
ファイル: PersonService.cs プロジェクト: yangkghjh/EmbyStat
        public async Task <Person> GetPersonById(string id)
        {
            var person = _personRepository.GetPersonById(id);

            if (person == null || !person.Synced)
            {
                var settings = _configurationRepository.GetSingle();
                var query    = new ItemQuery {
                    UserId = settings.EmbyUserId
                };

                _embyClient.SetAddressAndUrl(settings.EmbyServerAddress, settings.AccessToken);
                var rawPerson = await _embyClient.GetItemAsync(query, id, CancellationToken.None);

                person = PersonHelper.ConvertToPerson(rawPerson);
                _personRepository.AddOrUpdatePerson(person);
            }

            return(person);
        }