コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }