public Entry Parse(string textSample)
        {
            var entry = new Entry();
            textSample = textSample.Trim();
            var lines = textSample.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries).Select(l => l.Trim()).ToList();

            if (lines.Count < 4)
            {
                return Empty;
            }
            
            MapFrom(lines, entry);
            MapSent(lines, entry);
            MapTitle(lines, entry);
            MapLink(lines, entry);

            lines.RemoveRange(0, 4);
            lines.RemoveRange(lines.Count - 1, 1);
            
            entry.Body = string.Join("\n\n", lines);
            
            entry.Body = entry.Body.Replace("\n\n[embedded content]\n\n", "\n\n");
            
            RegexOptions options = RegexOptions.None;
            Regex regex = new Regex(@"[ ]{2,}", options);
            entry.Body = regex.Replace(entry.Body, @" ");

            return entry;
        }
        private void MapTitle(List<string> lines, Entry entry)
        {
            entry.Title = TrimTag("Subject", lines[3]);

            if (entry.Title.Trim() == "Subject:")
            {
                entry.Title = "";
            }
        }
        public void ProcessSingleItem(Entry entry, Publication publication)
        {
            _currentArticleId = _currentArticleId + 1;
            entry.Writer.Id = _writers.CreateOrRetrieveId(entry.Writer);
            entry.Id = _currentArticleId;
            entry.PublicationId = publication.Id;

            var entrySql = _sqlGen.GenerateSqlFor(entry);
            _writer.WriteLine(entrySql);
        }
Пример #4
0
 public string GenerateSqlFor(Entry item)
 {
     return string.Format("\n" + ArticleInsert,
         EncodeMySqlString(item.Id.ToString()),
         EncodeMySqlString(item.Title),
         EncodeMySqlString(item.Body.TrimStart()),
         EncodeMySqlString(item.Uri),
         EncodeMySqlString(item.Timestamp.ToString()),
         EncodeMySqlString(item.PublicationId.ToString()),
         EncodeMySqlString(item.Writer.Id.ToString()));
 }
Пример #5
0
 public string GenerateSqlFor(Entry item)
 {
     return string.Format(ArticleInsert,
         item.Id.ToEscapedString(),
         item.Title.ToEscapedString(),
         item.Body.TrimStart().ToEscapedString(),
         item.Uri.ToEscapedString(),
         item.Timestamp.ToEscapedString(),
         item.PublicationId.ToEscapedString(),
         item.Writer.Id.ToEscapedString());
 }
        private void MapFrom(List<string> lines, Entry entry)
        {
            var trimmed = TrimTag("From", lines[0]);
            var trimmedParts = trimmed.Split(new[] { '(' });

            if (trimmedParts.Length <= 1)
            {
                entry.Writer = new Writer {Name = trimmedParts.First().Trim(), Email = string.Empty};
                return;
            }
            
            entry.Writer = new Writer
            {
                Email = trimmedParts.First().Trim(),
                Name = trimmedParts.Skip(1).First().Trim().Replace(")", "")
            };
        }
        public Entry Parse(string textSample)
        {
            var entry = new Entry();
            textSample = textSample.Trim();
            var lines = textSample.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries).Select(l => l.Trim()).ToList();

            if (lines.Count < 4)
            {
                return Empty;
            }
            
            MapFrom(lines, entry);
            MapSent(lines, entry);
            MapTitle(lines, entry);
            MapLink(lines, entry);

            lines.RemoveRange(0, 4);
            lines.RemoveRange(lines.Count - 1, 1);
            entry.Body = string.Join("\n\n", lines);

            SanitiseBody(entry);

            return entry;
        }
 private void MapSent(List<string> lines, Entry entry)
 {
     entry.Timestamp = DateTime.Parse(TrimTag("Sent", lines[1]), new DateTimeFormatInfo(), DateTimeStyles.None);
 }
 private void MapLink(List<string> lines, Entry entry)
 {
     var articleSlugLine = lines.Last();
     var cutDown = articleSlugLine.Replace("View article... <", "").Replace(">", "");
     entry.Uri = cutDown.Trim();
 }
 private static void SanitiseBody(Entry entry)
 {
     entry.Body = entry.Body.Replace("\n\n[embedded content]\n\n", "\n\n");
     entry.Body = new Regex(@"[ ]{2,}", RegexOptions.None).Replace(entry.Body, @" ");
 }
 public void SetUp()
 {
     var parser = new RssFeedToSql.DataSources.DirectoryAndTextFile.TextFileDataParser();
     _entry = parser.Parse(_textSample); 
 }