public void FillInfo(TorrentInfo torrent) { string torrentInfo = _transmissionRemoteWrapper.ExecuteCommand(string.Format("-t {0} -i", torrent.Id)); foreach (string line in torrentInfo.Split(new [] { Environment.NewLine }, StringSplitOptions.None)) { string attribute = line.Trim(); if (attribute.StartsWith("Location:")) { torrent.Location = attribute.Replace("Location: ", string.Empty); } } _logger.DebugFormat("Obtained the information of the torrent \"{0}\".", torrent.FileName); }
public bool Remove(TorrentInfo torrent) { string output = _transmissionRemoteWrapper.ExecuteCommand(string.Format("-t {0} -r", torrent.Id)); bool ret = output.TrimEnd().EndsWith("responded: \"success\""); if (!ret) { _logger.ErrorFormat("The torrent \"{0}\" cannot be removed: {1}.", torrent.FileName, output); } else { _logger.DebugFormat("The torrent \"{0}\" has been removed properly.", torrent.FileName); } return(ret); }
TorrentInfo parseTorrentInfo(string torrenInfo) { string text = torrenInfo.Trim().Replace("\t", " "); Regex regex = new Regex("\\s(\\s)+"); text = regex.Replace(text, "\t"); string[] fields = text.Split('\t'); TorrentInfo torrent = new TorrentInfo { Id = long.Parse(fields [0].Replace("*", string.Empty)), FileName = fields [8] }; TorrentStatus status; if (!Enum.TryParse(homogenizeStatus(fields [7]), out status)) { _logger.ErrorFormat("The torrent status \"{0}\" is unknown.", fields [7]); status = TorrentStatus.Unknown; } torrent.Status = status; return(torrent); }