public void Stop() { if (this.client != null) { this.client.TorrentsUpdated -= OnTorrentsUpdated; this.client.TorrentFinishedDownloading -= OnTorrentFinishedDownloading; this.client.Dispose(); this.client = null; } this.knownTorrents = null; }
private void CheckConnection(object sender, RoutedEventArgs e) { try { var model = ((SettingsWindowModel)FindResource("model")); var client = new UTorrentWebClient(model.UTorrentAddress, model.UTorrentUserName, model.UTorrentPassword); var test = client.Settings.Count; Trace.WriteLine(string.Format("Check connection: success - loaded {0} settings", test)); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void Start(string address, string userName, string password) { Stop(); try { this.knownTorrents = new HashSet <string>(); this.client = new UTorrentWebClient(address, userName, password, true, this.dispatcher); this.client.MinimumTimeBetweenUpdates = TimeSpan.FromSeconds(30); this.client.TorrentsUpdated += OnTorrentsUpdated; this.client.TorrentFinishedDownloading += OnTorrentFinishedDownloading; ReportReadyTorrents(); } catch (Exception ex) { this.Error = ex; Stop(); } }
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { using (UTorrentWebClient webClient = new UTorrentWebClient(Properties.Settings.Default.ServerAddress, Properties.Settings.Default.UserName, Properties.Settings.Default.Password)) { webClient.TorrentAdded += new TorrentEventHandler(webClient_TorrentAdded); if (backgroundWorker.CancellationPending) { e.Cancel = true; return; } if (this.IsMagnetLink) { webClient.AddTorrentFromUrl(this.TorrentURI); } else { webClient.AddTorrent(this.TorrentURI); } if (backgroundWorker.CancellationPending) { lock (this.storedTorrentLock) { if (this.storedTorrent != null) { webClient.TorrentRemove(this.storedTorrent, true); } } e.Cancel = true; return; } } }