protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console) { var rules = await client.GetRssAutoDownloadingRulesAsync(); Print(rules.Select(r => new RssRuleViewModel(r.Key, r.Value)), true); return(ExitCodes.Success); }
protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console) { var rules = await client.GetRssAutoDownloadingRulesAsync(); if (rules.ContainsKey(Name)) { throw new Exception($"The rule with the name \"{Name}\" already exists."); } var rule = new RssAutoDownloadingRule { Enabled = !Disabled, MustContain = MustContain ?? string.Empty, MustNotContain = MustNotContain ?? string.Empty, UseRegex = UseRegex, EpisodeFilter = EpisodeFilter ?? string.Empty, SmartFilter = SmartFilter, PreviouslyMatchedEpisodes = PreviouslyMatchedEpisodes, AffectedFeeds = AffectedFeeds, IgnoreDays = IgnoreDays, LastMatch = LastMatch, AddPaused = ConvertPauseState(Paused), AssignedCategory = Category ?? string.Empty, SavePath = SavePath ?? string.Empty }; await client.SetRssAutoDownloadingRuleAsync(Name, rule); return(ExitCodes.Success); }
protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console) { var rules = await client.GetRssAutoDownloadingRulesAsync(); if (!rules.TryGetValue(Name, out var rule)) { throw new Exception($"The rule with the name \"{Name}\" does not exist."); } Set(nameof(rule.Enabled), !Disabled); Set(nameof(rule.MustContain), MustContain); Set(nameof(rule.MustNotContain), MustNotContain); Set(nameof(rule.UseRegex), UseRegex); Set(nameof(rule.EpisodeFilter), EpisodeFilter); Set(nameof(rule.IgnoreDays), IgnoreDays); Set(nameof(rule.LastMatch), LastMatch); Set(nameof(rule.AssignedCategory), Category); Set(nameof(rule.SavePath), SavePath); if (Paused != null) { Set(nameof(rule.AddPaused), ConvertPauseState(Paused)); } if (PreviouslyMatchedEpisodes != null) { rule.PreviouslyMatchedEpisodes = PreviouslyMatchedEpisodes .Where(e => !string.IsNullOrWhiteSpace(e)) .ToList(); } if (AffectedFeeds != null) { rule.AffectedFeeds = AffectedFeeds.Where(e => e.IsAbsoluteUri).ToList(); } await client.SetRssAutoDownloadingRuleAsync(Name, rule); return(ExitCodes.Success); void Set <T>(string propertyName, T value) { if (value != null) { rule.GetType().GetProperty(propertyName).SetValue(rule, value); } } }