Exemple #1
0
 public void ReadFileStream()
 {
     try
     {
         using (StreamReader readFile = new StreamReader("people.txt"))
         {
             string line;
             int    counter = 1;
             OnFileRead();
             while ((line = readFile.ReadLine()) != null)
             {
                 Console.WriteLine(counter + ". " + line);
                 counter += 1;
             }
         }
     }
     catch (Exception e)
     {
         FileManipulator createFile = new WriteFile();
         createFile.fileManipulator("Andrei Kovacs");
         FileManipulator appendFile = new AppendFile();
         appendFile.fileManipulator("Ionut Unguru");
         OnFileDoesNotExist();
         ReadFile readFile = new ReadFile();
         readFile.ReadFileStream();
     }
 }
Exemple #2
0
        static void Main(string[] args)
        {
            ConsoleLogger consoleLogger = new ConsoleLogger();
            ReadFile      readFile      = new ReadFile();

            readFile.FileRead         += consoleLogger.OnFileRead;
            readFile.FileDoesNotExist += consoleLogger.OnFileDoesNotExist;

            readFile.ReadFileStream();

            while (true)
            {
                string userOption = consoleLogger.DisplayOptions();

                switch (userOption)
                {
                case "1":
                    Console.Write("Please enter the new name: ");
                    string     person        = Console.ReadLine();
                    AppendFile appendNewUser = new AppendFile();
                    appendNewUser.fileManipulator(person);
                    readFile.ReadFileStream();
                    break;

                case "2":
                    Console.WriteLine("Here we will delete a name from the list!");
                    break;

                case "3":
                    return;

                default:
                    Console.WriteLine("Wrong option! Please pick again:");
                    consoleLogger.DisplayOptions();
                    break;
                }
            }
        }