/// <summary> /// Sends a Torrent started notification. /// </summary> /// <param name="torrent">Started Torrent to notify.</param> public void sendOnTorrentStarted(Torrent torrent) { /* // torrent has been queued if (torrent.status_message.Equals("Queued")) { // format language StringBuilder body = new StringBuilder("[torrent_name]"); body.Replace("[torrent_name]", torrent.name); // notify GC.Notification notification = new GC.Notification(Configuration.application_name, "STARTED", null, "Queued", body.ToString()); Configuration.growl.Notify(notification); torrent.notified_started = true; } */ // torrent has started if (torrent.status_message.Equals("Downloading")) { // format language StringBuilder body = new StringBuilder("[torrent_name]"); body.Replace("[torrent_name]", torrent.name); // notify GC.Notification notification = new GC.Notification(Configuration.application_name, "STARTED", null, "Downloading", body.ToString()); Configuration.growl.Notify(notification); torrent.notified_started = true; } }
/// <summary> /// Sends a Torrent completion notification. /// </summary> /// <param name="torrent">Completed Torrent to notify.</param> public void sendOnTorrentCompletion(Torrent torrent) { // torrent has finished if (torrent.status_message.Equals("Finished") || torrent.status_message.Equals("Seeding")) { // format language StringBuilder body = new StringBuilder("[torrent_name]"); body.Replace("[torrent_name]", torrent.name); // notify GC.Notification notification = new GC.Notification(Configuration.application_name, "COMPLETED", null, "Completed", body.ToString()); Configuration.growl.Notify(notification); torrent.notified_completed = true; } }
/// <summary> /// Returns the torrents from a uTorrent JSON response /// </summary> /// <param name="json">uTorrent JSON response</param> /// <returns>List of Torrents</returns> public List<Torrent> getModifiedTorrentsFromJSON(String json, List<Torrent> active_torrents) { try { // convert json to xml XmlDocument response = (XmlDocument)JsonConvert.DeserializeXmlNode(json, "root"); // navigate xml to torrents XPathNavigator xml_response = response.CreateNavigator(); XPathNodeIterator xml_iterator = xml_response.Select("/root/torrentp"); // import new torrent data into the model while (xml_iterator.MoveNext()) { var current = xml_iterator.Current; Boolean exists = false; Torrent temp = new Torrent(current); foreach (Torrent t in active_torrents) { // if the torrent already exists in the model, update it. if (t.exists(current)) { exists = true; t.update(current); continue; } } // if torrent doesn't exist, insert it if (!exists && !temp.isComplete()) { active_torrents.Add(new Torrent(current)); } } } catch (Exception e) { Debug.WriteLine(e); throw (e); } return active_torrents; }