public static bool GetFromLine(string line, int sequence, out Tweet tweet) { tweet = null; if (line == null) { return(false); } StringBuilder user = new StringBuilder(); StringBuilder comment = new StringBuilder(); bool foundSeperator = false; for (int i = 0; i < line.Length; i++) { if (!foundSeperator) { if (line[i] == '>') { foundSeperator = true; continue; } user.Append(line[i]); } else { comment.Append(line[i]); } } if (!foundSeperator) { SimpleFileLogger.LogEvent("Tweet format error", DateTime.Now, string.Concat("Did not find feed seperator on line ", sequence)); return(false); } var commentResult = comment.ToString().Trim(); if (string.IsNullOrEmpty(commentResult)) { SimpleFileLogger.LogEvent("Tweet format error", DateTime.Now, string.Concat("Feed did not contain a message on line ", sequence)); return(false); } tweet = new Tweet() { Username = user.ToString().Trim(), Comment = commentResult, Sequence = sequence }; return(true); }
public static void ReadFeeds(string userFileName, string tweetFileName) { try { var users = new UserRepository(userFileName).GetAll().OrderBy(p => p.Name); var tweets = new TweetRepository(tweetFileName).GetAll().ToLookup(p => p.Username.ToUpper()); foreach (var user in users) { Console.WriteLine(user.Name); foreach (var tweet in GetTweetsForUser(user, tweets)) { Console.Write("\t@"); Console.Write(tweet.Username); Console.Write(": "); Console.WriteLine(tweet.Comment); } } } catch (Exception ex) { SimpleFileLogger.LogEvent("Read tweets exception", DateTime.Now, ex.Message, true); } }