Exemplo n.º 1
0
        public bool IsMatch(string input, Filter filter)
        {
            if (string.IsNullOrEmpty(filter.IncludePattern)
                    && string.IsNullOrEmpty(filter.ExcludePattern))
            {
                return true;
            }

            if (string.IsNullOrEmpty(filter.IncludePattern)
                && !string.IsNullOrEmpty(filter.ExcludePattern))
            {
                // Only download if exclude pattern doesn't match
                return !Regex.IsMatch(input, filter.ExcludePattern);
            }

            if (!string.IsNullOrEmpty(filter.IncludePattern)
                     && string.IsNullOrEmpty(filter.ExcludePattern))
            {
                // Only download if include pattern matches
                return Regex.IsMatch(input, filter.IncludePattern);
            }

            if (!string.IsNullOrEmpty(filter.IncludePattern)
                     && !string.IsNullOrEmpty(filter.ExcludePattern))
            {
                // Only download if include pattern matches
                // and exclude pattern does not
                return Regex.IsMatch(input, filter.IncludePattern)
                       && !Regex.IsMatch(input, filter.ExcludePattern);
            }

            return false;
        }
Exemplo n.º 2
0
        private void Download(Filter filter, SyndicationItem item)
        {
            var args = new TorrentArguments();
            var pattern = filter.IncludePattern;
            var input = item.Title.Text;
            var modifiers = _rssRepository.GetModifiersByFilterId(filter.Id);

            if (modifiers != null)
            {
                foreach (var modifier in modifiers)
                {
                    var regex = new Regex(pattern, RegexOptions.ExplicitCapture);
                    var match = regex.Match(input);
                    var value = modifier.Value;

                    foreach (var groupName in regex.GetGroupNames().Skip(1))
                    {
                        var group = match.Groups[groupName];
                        value = value.Replace(string.Format("${{{0}}}", groupName), group.Value);
                    }

                    switch (modifier.Target)
                    {
                        case ModifierTarget.Label:
                            args.Label = value;
                            break;

                        case ModifierTarget.SavePath:
                            args.SavePath = value;
                            break;
                    }
                }
            }

            var data = _httpClient.GetByteArrayAsync(item.Links.First().Uri).Result;
            _messageBus.Publish(new AddTorrentMessage(data) {Label = args.Label, SavePath = args.SavePath});
        }
Exemplo n.º 3
0
 public void UpdateFilter(Filter filter)
 {
     _rssRepository.UpdateFilter(filter);
 }
Exemplo n.º 4
0
 public Filter CreateFilter(Filter filter)
 {
     _rssRepository.CreateFilter(filter);
     return filter;
 }
Exemplo n.º 5
0
 public void UpdateFilter(Filter filter)
 {
     var query = @"update Rss_Filter set IncludePattern = @IncludePattern, ExcludePattern = @ExcludePattern, AutoStart = @AutoStart where Id = @Id";
     _connection.Execute(query, filter);
 }
Exemplo n.º 6
0
 public void CreateFilter(Filter filter)
 {
     var query = @"insert into Rss_Filter (FeedId, IncludePattern, ExcludePattern, AutoStart) values(@FeedId, @IncludePattern, @ExcludePattern, @AutoStart); select last_insert_rowid();";
     filter.Id = _connection.Query<int>(query, filter).First();
 }