コード例 #1
0
        public void Clean()
        {
            //TODO: We should remove this before merging it into develop
            _logger.Debug("Updating Anime Categories for newznab indexers");

            var indexers = _indexerFactory.All().Where(i => i.Implementation == typeof(Newznab).Name);

            foreach (var indexer in indexers)
            {
                var settings = indexer.Settings as NewznabSettings;

                if (settings.Url.ContainsIgnoreCase("nzbs.org") && settings.Categories.Contains(NZBS_ORG_ANIME_ID))
                {
                    var animeCategories = new List <int>(settings.AnimeCategories);
                    animeCategories.Add(NZBS_ORG_ANIME_ID);

                    settings.AnimeCategories = animeCategories;

                    settings.Categories = settings.Categories.Where(c => c != NZBS_ORG_ANIME_ID);

                    indexer.Settings = settings;
                    _indexerFactory.Update(indexer);
                }

                else if (settings.Categories.Contains(NEWZNAB_ANIME_ID))
                {
                    var animeCategories = new List <int>(settings.AnimeCategories);
                    animeCategories.Add(NEWZNAB_ANIME_ID);

                    settings.AnimeCategories = animeCategories;

                    settings.Categories = settings.Categories.Where(c => c != NEWZNAB_ANIME_ID);

                    indexer.Settings = settings;
                    _indexerFactory.Update(indexer);
                }
            }
        }
コード例 #2
0
        public IActionResult SaveAll(IndexerEditorResource resource)
        {
            var indexersToUpdate = _indexerService.AllProviders(false).Select(x => (IndexerDefinition)x.Definition).Where(d => resource.IndexerIds.Contains(d.Id));

            foreach (var indexer in indexersToUpdate)
            {
                if (resource.Enable.IsNotNullOrWhiteSpace())
                {
                    indexer.Enable = bool.Parse(resource.Enable);
                }

                if (resource.AppProfileId.HasValue)
                {
                    indexer.AppProfileId = resource.AppProfileId.Value;
                }

                if (resource.Tags != null)
                {
                    var newTags   = resource.Tags;
                    var applyTags = resource.ApplyTags;

                    switch (applyTags)
                    {
                    case ApplyTags.Add:
                        newTags.ForEach(t => indexer.Tags.Add(t));
                        break;

                    case ApplyTags.Remove:
                        newTags.ForEach(t => indexer.Tags.Remove(t));
                        break;

                    case ApplyTags.Replace:
                        indexer.Tags = new HashSet <int>(newTags);
                        break;
                    }
                }
            }

            _indexerService.Update(indexersToUpdate);

            var indexers = _indexerService.All();

            foreach (var definition in indexers)
            {
                _indexerService.SetProviderCharacteristics(definition);
            }

            return(Accepted(_resourceMapper.ToResource(indexers)));
        }