コード例 #1
0
        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)));
        }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
 public TorrentLabelChangedMessage(ITorrent torrent)
 {
     if (torrent == null)
     {
         throw new ArgumentNullException("torrent");
     }
     _torrent = torrent;
 }
コード例 #4
0
 public TorrentCompletedMessage(ITorrent torrent)
 {
     if (torrent == null)
     {
         throw new ArgumentNullException("torrent");
     }
     _torrent = torrent;
 }
コード例 #5
0
ファイル: RuleFinder.cs プロジェクト: originalmoose/hadouken
 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();
 }
コード例 #6
0
ファイル: RuleFinder.cs プロジェクト: originalmoose/hadouken
        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());
        }
コード例 #7
0
 public TorrentResult(ITorrent torrent)
 {
     Name        = torrent.Name;
     SizeInBytes = torrent.SizeInBytes;
     AddedDate   = torrent.AddedDate;
     FileCount   = torrent.FileCount;
     TrackerName = torrent.TrackerName;
     TrackerUrl  = torrent.TrackerUrl;
 }
コード例 #8
0
        public string GetValue(ITorrent torrent, ParameterSource source)
        {
            switch (source)
            {
                case ParameterSource.Label:
                    return torrent.Label;
                case ParameterSource.Name:
                    return torrent.Name;
            }

            return string.Empty;
        }
コード例 #9
0
        public string GetValue(ITorrent torrent, ParameterSource source)
        {
            switch (source)
            {
            case ParameterSource.Label:
                return(torrent.Label);

            case ParameterSource.Name:
                return(torrent.Name);
            }

            return(string.Empty);
        }
コード例 #10
0
ファイル: Torrent.cs プロジェクト: nikitazu/NyaWatch
 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);
     }
 }
コード例 #11
0
        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));
        }
コード例 #12
0
ファイル: RuleFinder.cs プロジェクト: originalmoose/hadouken
 private bool MatchesTorrent(ITorrent torrent, Parameter parameter)
 {
     var sourceValue = _sourceValueProvider.GetValue(torrent, parameter.Source);
     return Regex.IsMatch(sourceValue, parameter.Pattern);
 }
コード例 #13
0
ファイル: RuleFinder.cs プロジェクト: originalmoose/hadouken
        private bool MatchesTorrent(ITorrent torrent, Parameter parameter)
        {
            var sourceValue = _sourceValueProvider.GetValue(torrent, parameter.Source);

            return(Regex.IsMatch(sourceValue, parameter.Pattern));
        }
コード例 #14
0
 public TorrentEventArgs(ITorrent torrent)
 {
     this.torrent = torrent;
 }
コード例 #15
0
ファイル: Tracker.cs プロジェクト: pedrolimajesus/template
 public void RemoveTorrent(ITorrent torrent)
 {
     this.RemoveTorrent(torrent.TorrentFileUri);
 }
コード例 #16
0
ファイル: Tracker.cs プロジェクト: pedrolimajesus/template
 public void AddTorrent(ITorrent torrent)
 {
     AddATorrent(torrent.TorrentFileUri.LocalPath);
 }
コード例 #17
0
 public TorrentLabelChangedMessage(ITorrent torrent)
 {
     if (torrent == null) throw new ArgumentNullException("torrent");
     _torrent = torrent;
 }
コード例 #18
0
 public TorrentCompletedMessage(ITorrent torrent)
 {
     if (torrent == null) throw new ArgumentNullException("torrent");
     _torrent = torrent;
 }