public string Replace(ITorrent torrent, IEnumerable <Parameter> parameters, string targetPath) { var tokens = new Dictionary <string, string>(); foreach (var parameter in parameters) { var sourceValue = _sourceValueProvider.GetValue(torrent, parameter.Source); var regex = new Regex(parameter.Pattern, RegexOptions.ExplicitCapture | RegexOptions.Singleline); var match = regex.Match(sourceValue); foreach (var groupName in regex.GetGroupNames().Skip(1)) { if (tokens.ContainsKey(groupName)) { continue; } var group = match.Groups[groupName]; tokens.Add(groupName, group.Value); } } return(tokens.Aggregate(targetPath, (current, token) => current.Replace(string.Format("${{{0}}}", token.Key), token.Value))); }
public TorrentDownloader( Uri torrentDescriptionFileUri, TorrentSettings torrentSettings, ClientEngine clientEngine) { try { torrent = MonoTorrent.Common.Torrent.Load(torrentDescriptionFileUri.LocalPath); this.Torrent = new TorrentFile(torrentDescriptionFileUri.LocalPath, torrent.Publisher); var config = Catalog.Factory.Resolve <IConfig>(); defaultSaveFolder = config[BitTorrentSettings.DownloadFolder]; var relativePath = torrent.Publisher; var absolutePath = Path.Combine(defaultSaveFolder, relativePath); var saveFolder = Path.GetDirectoryName(absolutePath); if (saveFolder != null && !Directory.Exists(saveFolder)) { Directory.CreateDirectory(saveFolder); } manager = new TorrentManager(torrent, saveFolder, torrentSettings); State = TorrentState.Downloading; manager.TorrentStateChanged += ManagerOnTorrentStateChanged; engine = clientEngine; engine.Register(manager); } catch (Exception) { throw; } }
public TorrentLabelChangedMessage(ITorrent torrent) { if (torrent == null) { throw new ArgumentNullException("torrent"); } _torrent = torrent; }
public TorrentCompletedMessage(ITorrent torrent) { if (torrent == null) { throw new ArgumentNullException("torrent"); } _torrent = torrent; }
public Rule FindRule(ITorrent torrent) { var rules = _autoMoveRepository.GetRules() ?? new Rule[] {}; return (from rule in rules let parameters = _autoMoveRepository.GetParametersByRuleId(rule.Id) ?? new Parameter[] {} where parameters.All(p => MatchesTorrent(torrent, p)) select rule).FirstOrDefault(); }
public Rule FindRule(ITorrent torrent) { var rules = _autoMoveRepository.GetRules() ?? new Rule[] {}; return((from rule in rules let parameters = _autoMoveRepository.GetParametersByRuleId(rule.Id) ?? new Parameter[] {} where parameters.All(p => MatchesTorrent(torrent, p)) select rule).FirstOrDefault()); }
public TorrentResult(ITorrent torrent) { Name = torrent.Name; SizeInBytes = torrent.SizeInBytes; AddedDate = torrent.AddedDate; FileCount = torrent.FileCount; TrackerName = torrent.TrackerName; TrackerUrl = torrent.TrackerUrl; }
public string GetValue(ITorrent torrent, ParameterSource source) { switch (source) { case ParameterSource.Label: return torrent.Label; case ParameterSource.Name: return torrent.Name; } return string.Empty; }
public string GetValue(ITorrent torrent, ParameterSource source) { switch (source) { case ParameterSource.Label: return(torrent.Label); case ParameterSource.Name: return(torrent.Name); } return(string.Empty); }
static void DeserializeTorrent(IDictionary<string, string> item, ITorrent torrent) { try { torrent.RawTitle = item.RequireString("title"); torrent.CleanTitle = Parsing.NameCleaner.Clean(torrent.RawTitle); torrent.Seeders = item.RequireInt("seeders"); torrent.Leechers = item.RequireInt("leechers"); torrent.ReleaseGroup = item.OptionalString("releaseGroup") ?? string.Empty; torrent.Category = ParseCategory(item.RequireString("category")); } catch (Exception e) { throw new DeserializeFailedException (item, e); } }
public string Replace(ITorrent torrent, IEnumerable<Parameter> parameters, string targetPath) { var tokens = new Dictionary<string, string>(); foreach (var parameter in parameters) { var sourceValue = _sourceValueProvider.GetValue(torrent, parameter.Source); var regex = new Regex(parameter.Pattern, RegexOptions.ExplicitCapture | RegexOptions.Singleline); var match = regex.Match(sourceValue); foreach (var groupName in regex.GetGroupNames().Skip(1)) { if (tokens.ContainsKey(groupName)) continue; var group = match.Groups[groupName]; tokens.Add(groupName, group.Value); } } return tokens.Aggregate(targetPath, (current, token) => current.Replace(string.Format("${{{0}}}", token.Key), token.Value)); }
private bool MatchesTorrent(ITorrent torrent, Parameter parameter) { var sourceValue = _sourceValueProvider.GetValue(torrent, parameter.Source); return Regex.IsMatch(sourceValue, parameter.Pattern); }
private bool MatchesTorrent(ITorrent torrent, Parameter parameter) { var sourceValue = _sourceValueProvider.GetValue(torrent, parameter.Source); return(Regex.IsMatch(sourceValue, parameter.Pattern)); }
public TorrentEventArgs(ITorrent torrent) { this.torrent = torrent; }
public void RemoveTorrent(ITorrent torrent) { this.RemoveTorrent(torrent.TorrentFileUri); }
public void AddTorrent(ITorrent torrent) { AddATorrent(torrent.TorrentFileUri.LocalPath); }
public TorrentLabelChangedMessage(ITorrent torrent) { if (torrent == null) throw new ArgumentNullException("torrent"); _torrent = torrent; }
public TorrentCompletedMessage(ITorrent torrent) { if (torrent == null) throw new ArgumentNullException("torrent"); _torrent = torrent; }