public SwarmSettings ToSettings() { SwarmSettings settings = new SwarmSettings(); if (Connector != null) { settings.Connector = Connector == "on"; } if (Listener != null) { settings.Listener = Listener == "on"; } if (settings.Listener && Port != null) { settings.ListenerPort = Int32.Parse(Port); } if (Accept != null) { settings.Filter = new GeonFilter(Accept); } if (Strategy != null) { settings.Strategy = Strategy; } if (Metadata != null) { settings.Metadata = Metadata == "on"; } if (Exchange != null) { settings.Exchange = Exchange == "on"; } return(settings); }
public static async Task MainAsync(string[] args) { CommandLine options = Argument.Parse <CommandLine>(args); if (options.IsValid()) { string[] trackers = options.Trackers; FileHash hash = FileHash.Parse(options.Hash); SwarmSettings settings = options.ToSettings(); using (SwarmClient client = new SwarmClient(settings)) { Reporter reporter = options.ToReporter(); SwarmSession session = await client.ConnectAsync(hash, trackers); Console.WriteLine($"Hash: {hash}"); switch (options.Command) { case "download": session.Download(options.Destination, options.Destination); break; case "seed": session.Seed(options.Destination, options.Destination); break; } foreach (Notification notification in session.All()) { if (reporter.Handle(notification) == false) { break; } } } } }