Beispiel #1
0
            protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
            {
                var apiVersion = await client.GetApiVersionAsync();

                var categories = apiVersion >= new ApiVersion(2, 1, 1)
                    ? await client.GetCategoriesAsync()
                    : (await client.GetPartialDataAsync()).CategoriesChanged;

                Print(categories.Values);
                return(ExitCodes.Success);
            }
Beispiel #2
0
                protected override async Task <int> OnExecuteTorrentSpecificAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                {
                    var partialData = await client.GetPartialDataAsync();

                    if (!partialData.TorrentsChanged.TryGetValue(Hash, out var info))
                    {
                        console.WriteLineColored($"No torrent matching hash {Hash} is found.", ColorScheme.Current.Warning);
                        return(ExitCodes.NotFound);
                    }

                    Print(info.Tags, true);
                    return(ExitCodes.Success);
                }
            protected override async Task <int> OnExecuteTorrentSpecificAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
            {
                var partialData = await client.GetPartialDataAsync();

                if (!partialData.TorrentsChanged.TryGetValue(Hash, out var info))
                {
                    console.WriteLineColored($"No torrent matching hash {Hash} is found.", ColorScheme.Current.Warning);
                    return(ExitCodes.NotFound);
                }

                var ratioLimit       = GetRatioLimit();
                var seedingTimeLimit = GetSeedingTimeLimit();

                if (ratioLimit != null || seedingTimeLimit != null)
                {
                    await client.SetShareLimitsAsync(Hash,
                                                     ratioLimit ?? info.RatioLimit ?? ShareLimits.Ratio.Global,
                                                     seedingTimeLimit ?? info.SeedingTimeLimit ?? ShareLimits.SeedingTime.Global);

                    return(ExitCodes.Success);
                }

                var(properties, global) = await TaskHelper.WhenAll(
                    client.GetTorrentPropertiesAsync(Hash),
                    client.GetPreferencesAsync());

                var viewModel = new TorrentShareViewModel(properties, info);

                _customFormatters = new Dictionary <string, Func <object, object> >
                {
                    [nameof(viewModel.RatioLimit)]       = FormatRatioLimit,
                    [nameof(viewModel.SeedingTimeLimit)] = FormatSeedingTimeLimit
                };
                Print(viewModel);

                return(ExitCodes.Success);

                object FormatRatioLimit(object arg)
                {
                    switch (arg)
                    {
                    case double value when Math.Abs(value - ShareLimits.Ratio.Global) < 0.0001:
                        var globalValue = global.MaxRatio >= 0 ? global.MaxRatio.Value.ToString("F3") : "None";

                        return($"Global ({globalValue})");

                    case double value when Math.Abs(value - ShareLimits.Ratio.Unlimited) < 0.0001:
                        return("None");

                    case double value:
                        return(value.ToString("F3"));

                    default:
                        return(null);
                    }
                }

                object FormatSeedingTimeLimit(object arg)
                {
                    var time = arg as TimeSpan?;

                    if (time == ShareLimits.SeedingTime.Global)
                    {
                        var globalValue = global.MaxSeedingTime >= 0 ? global.MaxSeedingTime.Value.ToString() : "None";
                        return($"Global ({globalValue})");
                    }

                    return(time == ShareLimits.SeedingTime.Unlimited ? "None" : time?.ToString());
                }
            }