protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                        {
                            var prefs = await client.GetPreferencesAsync();

                            var currentNetworks = (prefs.BypassAuthenticationSubnetWhitelist ?? Enumerable.Empty <string>())
                                                  .Select(IPNetwork.Parse)
                                                  .ToHashSet();
                            bool modified = false;

                            foreach (var network in Networks.Select(IPNetwork.Parse))
                            {
                                if (!currentNetworks.Contains(network))
                                {
                                    currentNetworks.Add(network);
                                    modified = true;
                                }
                            }

                            if (modified)
                            {
                                prefs = new Preferences
                                {
                                    BypassAuthenticationSubnetWhitelist = currentNetworks.Select(n => n.ToString()).ToList()
                                };
                                await client.SetPreferencesAsync(prefs);
                            }

                            return(ExitCodes.Success);
                        }
                    protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var prefs = await client.GetPreferencesAsync();

                        var  currentTrackers = prefs.AdditinalTrackers ?? new List <string>();
                        bool modified        = false;

                        foreach (var tracker in Trackers)
                        {
                            if (!currentTrackers.Contains(tracker))
                            {
                                currentTrackers.Add(tracker);
                                modified = true;
                            }
                        }

                        if (modified)
                        {
                            prefs = new Preferences {
                                AdditinalTrackers = currentTrackers
                            };
                            await client.SetPreferencesAsync(prefs);
                        }

                        return(ExitCodes.Success);
                    }
Ejemplo n.º 3
0
                    protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var prefs = await client.GetPreferencesAsync();

                        var  banList  = prefs.BannedIpAddresses ?? new List <string>();
                        bool modified = false;

                        foreach (var address in Addresses)
                        {
                            if (!banList.Contains(address))
                            {
                                banList.Add(address);
                                modified = true;
                            }
                        }

                        if (modified)
                        {
                            prefs = new Preferences {
                                BannedIpAddresses = banList
                            };
                            await client.SetPreferencesAsync(prefs);
                        }

                        return(ExitCodes.Success);
                    }
                    protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var prefs = new Preferences {
                            ScanDirectories = new Dictionary <string, SaveLocation>()
                        };
                        await client.SetPreferencesAsync(prefs);

                        return(ExitCodes.Success);
                    }
                        protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                        {
                            var prefs = new Preferences {
                                BypassAuthenticationSubnetWhitelist = new string[0]
                            };
                            await client.SetPreferencesAsync(prefs);

                            return(ExitCodes.Success);
                        }
                    protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var saveLocation = GetSaveLocation();
                        var prefs        = await client.GetPreferencesAsync();

                        var dirs = prefs?.ScanDirectories ?? new Dictionary <string, SaveLocation>();

                        dirs[Folder] = saveLocation;
                        prefs        = new Preferences {
                            ScanDirectories = dirs
                        };
                        await client.SetPreferencesAsync(prefs);

                        return(ExitCodes.Success);

                        SaveLocation GetSaveLocation()
                        {
                            if (SaveToDefault && SaveToMonitoredFolder)
                            {
                                throw new InvalidOperationException("Only single of the options --save-to-default or --save-to-monitored can be used simultaneously.");
                            }
                            if (SaveToDefault && SaveToCustom)
                            {
                                throw new InvalidOperationException("Only single of the options --save-to-default or --save-to can be used simultaneously.");
                            }
                            if (SaveToCustom && SaveToMonitoredFolder)
                            {
                                throw new InvalidOperationException("Only single of the options --save-to or --save-to-monitored can be used simultaneously.");
                            }

                            if (SaveToCustom)
                            {
                                return(new SaveLocation(SaveTo));
                            }
                            if (SaveToMonitoredFolder)
                            {
                                return(new SaveLocation(StandardSaveLocation.MonitoredFolder));
                            }
                            return(new SaveLocation(StandardSaveLocation.Default));
                        }
                    }
                protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                {
                    await Prepare(client, app, console);

                    var props =
                        (from prop in GetType().GetTypeInfo().DeclaredProperties
                         let option = prop.GetCustomAttribute <OptionAttribute>()
                                      where option != null
                                      where prop.GetCustomAttribute <IgnoreAttribute>() == null
                                      let value = prop.GetValue(this)
                                                  where value != null && (option.OptionType != CommandOptionType.NoValue || !false.Equals(value))
                                                  let autoSet = prop.GetCustomAttribute <NoAutoSetAttribute>() == null
                                                                let minApiVersion = prop.GetCustomAttribute <MinApiVersionAttribute>()
                                                                                    let maxApiVersion = prop.GetCustomAttribute <MaxApiVersionAttribute>()
                                                                                                        select(prop.Name, value, autoSet, minApiVersion, maxApiVersion))
                        .ToList();

                    var minVersionProps = props
                                          .Where(p => p.minApiVersion != null)
                                          .ToLookup(
                        p => (p.minApiVersion.MinVersion, p.minApiVersion.Message),
                        p => p.value);

                    foreach (var pair in minVersionProps)
                    {
                        var(minVersion, message) = pair.Key;
                        var values = pair.ToArray();
                        await WarnIfNotSupported(client, console, minVersion, message, false, values);
                    }

                    var maxVersionProps = props
                                          .Where(p => p.maxApiVersion != null)
                                          .ToLookup(
                        p => (MaxVersion: p.maxApiVersion.MaxVersionExclusive, p.maxApiVersion.Message),
                        p => p.value);

                    foreach (var pair in maxVersionProps)
                    {
                        var(maxVersion, message) = pair.Key;
                        var values = pair.ToArray();
                        await WarnIfNotSupported(client, console, maxVersion, message, true, values);
                    }

                    if (props.Any())
                    {
                        var prefs = new Preferences();
                        foreach (var prop in props.Where(p => p.autoSet))
                        {
                            typeof(Preferences).GetProperty(prop.Name).SetValue(prefs, prop.value);
                        }

                        CustomFillPreferences(prefs);
                        await client.SetPreferencesAsync(prefs);
                    }
                    else
                    {
                        var prefs = await client.GetPreferencesAsync();

                        PrintPreferences(client, prefs);
                    }

                    return(ExitCodes.Success);
                }