public virtual int Save(NewznabDefinition definition) { //Cleanup the URL if it is not null or whitespace if (!String.IsNullOrWhiteSpace(definition.Url)) definition.Url = (new Uri(definition.Url).ParentUriString()); if (definition.Id == 0) { Logger.Debug("Adding Newznab definitions for {0}", definition.Name); return Convert.ToInt32(_database.Insert(definition)); } Logger.Debug("Updating Newznab definitions for {0}", definition.Name); return _database.Update(definition); }
public void Save_should_clean_url_before_inserting_when_url_is_not_empty() { //Setup var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "" }; var expectedUrl = ""; var db = TestDbHelper.GetEmptyDatabase(); Mocker.SetConstant(db); //Act var result = Mocker.Resolve<NewznabProvider>().Save(newznab); //Assert db.Single<NewznabDefinition>(result).Url.Should().Be(expectedUrl); }
public void Save_should_clean_url_before_inserting() { //Setup var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "http://www.nzbdrone.com/gibberish/test.aspx?hello=world" }; var expectedUrl = "http://www.nzbdrone.com"; var db = TestDbHelper.GetEmptyDatabase(); Mocker.SetConstant(db); //Act var result = Mocker.Resolve<NewznabProvider>().Save(newznab); //Assert db.Single<NewznabDefinition>(result).Url.Should().Be(expectedUrl); }
public void Save_should_clean_url_before_updating_when_url_is_not_empty() { //Setup var newznab = new NewznabDefinition { Name = "Newznab Provider", Enable = true, Url = "http://www.nzbdrone.com" }; var expectedUrl = ""; var newUrl = ""; var db = TestDbHelper.GetEmptyDatabase(); Mocker.SetConstant(db); newznab.Id = Convert.ToInt32(db.Insert(newznab)); newznab.Url = newUrl; //Act var result = Mocker.Resolve<NewznabProvider>().Save(newznab); //Assert db.Single<NewznabDefinition>(result).Url.Should().Be(expectedUrl); }
public virtual void InitializeNewznabIndexers(IList<NewznabDefinition> indexers) { Logger.Debug("Initializing Newznab indexers. Count {0}", indexers.Count); var currentIndexers = All(); foreach (var feedProvider in indexers) { NewznabDefinition indexerLocal = feedProvider; if (!currentIndexers.Exists(c => c.Name == indexerLocal.Name)) { var settings = new NewznabDefinition { Enable = false, Name = indexerLocal.Name, Url = indexerLocal.Url, ApiKey = indexerLocal.ApiKey }; Save(settings); } } }
public ActionResult GetNewznabProviderView(NewznabDefinition provider) { ViewData["ProviderId"] = provider.Id; return PartialView("NewznabProvider", provider); }
public PartialViewResult AddNewznabProvider() { var newznab = new NewznabDefinition { Enable = false, Name = "Newznab Provider" }; var id = _newznabProvider.Save(newznab); newznab.Id = id; ViewData["ProviderId"] = id; return PartialView("NewznabProvider", newznab); }
public virtual void InitializeNewznabIndexers(IList<NewznabDefinition> indexers) { Logger.Debug("Initializing Newznab indexers. Count {0}", indexers.Count); try { var currentIndexers = All(); Logger.Debug("Deleting broken Newznab indexer"); var brokenIndexers = currentIndexers.Where(i => String.IsNullOrEmpty(i.Name) || String.IsNullOrWhiteSpace(i.Url)).ToList(); brokenIndexers.ForEach(e => _database.Delete<NewznabDefinition>(e.Id)); currentIndexers = All(); foreach(var feedProvider in indexers) { try { NewznabDefinition indexerLocal = feedProvider; var currentIndexer = currentIndexers .FirstOrDefault( c => new Uri(c.Url.ToLower()).Host == new Uri(indexerLocal.Url.ToLower()).Host); if (currentIndexer == null) { var settings = new NewznabDefinition { Enable = false, Name = indexerLocal.Name, Url = indexerLocal.Url, ApiKey = indexerLocal.ApiKey, BuiltIn = true }; Save(settings); } else { currentIndexer.Url = indexerLocal.Url; currentIndexer.BuiltIn = true; Save(currentIndexer); } } catch (Exception ex) { Logger.ErrorException("An error occurred while setting up indexer: " + feedProvider.Name, ex); } } } catch(Exception ex) { Logger.ErrorException("An Error occurred while initializing Newznab Indexers", ex); } }