public static IEnumerable <UserInfomration> ToUserInfomation(this string input) { var splited = input.RemoveUnneededStuff().Split(ClassSeperator); splited = splited.Where(x => !string.IsNullOrEmpty(x)).ToArray(); var userInformationResult = new List <UserInfomration>(); foreach (var item in splited) { if (string.IsNullOrEmpty(item)) { continue; } var splitedInformation = item.Split(ItemSeperator); splitedInformation = splitedInformation.Where(x => !string.IsNullOrEmpty(x)).ToArray(); var userInformation = new UserInfomration { Calls = splitedInformation[0].Substring(CallText.Length), Answered = splitedInformation[1].Substring(AnsweredText.Length), DateTime = ConvertStringToDateTime(splitedInformation[2]) }; userInformationResult.Add(userInformation); } return(userInformationResult); }
private void WriteToFile(UserInfomration newUserInformation) { using (var tw = new StreamWriter(CentralFile, true)) { tw.WriteLine("*Total Calls: {0}", newUserInformation.Calls); tw.WriteLine("*Total Answered: {0}", newUserInformation.Answered); tw.WriteLine(); tw.WriteLine("*Stats for Name_{0}#", newUserInformation.DateTime.ToShortDateString()); tw.WriteLine(); } }
public void Save(UserInfomration newUserInformation) { try { var streamReader = new StreamReader(CentralFile); var sourceInformation = streamReader.ReadToEnd(); streamReader.Close(); var userCollection = (List <UserInfomration>)(sourceInformation.ToUserInfomation()); var checkItem = ShouldModify(userCollection); if (checkItem.Item1) { userCollection.Remove(checkItem.Item2); } newUserInformation.DateTime = DateTime.Today; userCollection.Add(newUserInformation); File.Delete(CentralFile); foreach (var userInfomration in userCollection) { WriteToFile(userInfomration); } } catch (Exception) { } }