//creates a new tweet object private Tweet createTweet(string userName, string tweet, DateTime currentTimeStamp) { Utility myUtility = new Utility(); Tweet myTweet = new Tweet { UserName = myUtility.formatUpperCase(userName), SingleTweet = tweet, TimeStamp = currentTimeStamp }; return myTweet; }
//objectifies the data from the text file into user and tweet objects private void objectifyData(string fileName) { DataReader myDataReader = new DataReader(); Utility myUtility = new Utility(); List<string> fileContents = new List<string>(); //iterares through each file in directory //processes data only if user.txt or tweet.txt file foreach (FileInfo file in files) { if (file.Name == fileName) { if (file.Length > 0) { if (fileName == "user.txt") { fileContents = myDataReader.readContent(file); if (myUtility.formatValid(fileContents, "user")) { objectifyUsers(fileContents); } else { throw (new FileException("Please ensure the format of the " + fileName + " file is correct.")); } } else if (fileName == "tweet.txt") { fileContents = myDataReader.readContent(file); if (myUtility.formatValid(fileContents, "tweet")) { objectifyTweets(fileContents); } else { throw (new FileException("Please ensure the format of the " + fileName + " file is correct.")); } } } else { throw (new FileException("Please ensure that the " + fileName + " file has data.")); } } } }
//creates a new user object private User createUser(string userName) { Utility myUtility = new Utility(); User myUser = new User { UserName = myUtility.formatUpperCase(userName) }; return myUser; }