public string showFollowed(string User) { FileInfo fi = TweetRepository.GetUsersFollowerFile(User); string FollowedUsers = ""; if (fi.Exists == false) { //nobody is being followed here... return(""); } using (StreamReader sr = fi.OpenText()) { // read all the elments and bind them into a CSV string string s = ""; while ((s = sr.ReadLine()) != null) { FollowedUsers += ("," + s); } sr.Close(); } return(FollowedUsers); }
private void LoadMessages() { /* * all tweets are stored in a central file. This will help with ordering by time of arrival * the default is the logged in users documents directory. All usrs are assumed to be logging on the same terminal * and using the same id... */ FileInfo fi = TweetRepository.GetFileRepository(); if (fi.Exists == false) { return; } TextFieldParser messageParser = new TextFieldParser(fi.FullName); messageParser.Delimiters = new string[] { "\t" }; messageParser.HasFieldsEnclosedInQuotes = false; while (messageParser.EndOfData == false) { string[] Messageparts = messageParser.ReadFields(); tweetyMessage newmessage = new tweetyMessage(); newmessage.user = Messageparts[0]; newmessage.messageText = Messageparts[1]; newmessage.messageDateTime = Convert.ToDateTime(Messageparts[2]); messages.Add(newmessage); } messageParser.Close(); }
public void writeMessage() { /* * if the save file does not exist then create it. otherwise write the contents of the message * to the file... * */ FileInfo fi = TweetRepository.GetFileRepository(); string MessageToWrite = String.Format("{0}\t{1}\t{2}\n", tm.user, tm.messageText, tm.messageDateTime); if (fi.Exists) { System.IO.File.AppendAllText(fi.FullName, MessageToWrite); } else { System.IO.File.WriteAllText(fi.FullName, MessageToWrite); } }
public followUser(string p1, string p2) { // TODO: Complete member initialization this.user = p1; this.followeduser = p2; // FileInfo fi = TweetRepository.GetUsersFollowerFile(this.user); StreamWriter sw = new StreamWriter(fi.FullName, true); //write this followed user to the follows file. sw.WriteLine(followeduser); sw.Close(); //tell the world who the user is following tweetyMessage fm = new tweetyMessage(user, string.Format("{0} is following {1}", user, followeduser)); TweetMessageWriter tm = new TweetMessageWriter(fm); tm.writeMessage(); }