Exemple #1
0
 public void AddMovie(Movie movie)
 {
     if (movie is null)
     {
         throw new ArgumentNullException();
     }
     else if (StoredMovies.Contains(movie))
     {
         throw new ArgumentException(MovieExistsMessage, nameof(movie));
     }
     else if (FindMovieByTitle(movie.GetTitle(), out _))
     {
         throw new ArgumentException(MovieExistsMessage, nameof(movie.GetTitle));
     }
     else if (FindMovieById(movie.GetId(), out _))
     {
         throw new ArgumentException(MovieExistsMessage, nameof(movie.GetId));
     }
     else
     {
         StoredMovies.Add(movie);
         if (File.Exists(_fileName))
         {
             File.Copy(_fileName, _fileName + ".bak", true);
         }
         using (var output = new StreamWriter(_fileName, true))
         {
             output.WriteLine(movie.ToString());
         }
     }
 }
 private static void StartCsvInput()
 {
     SetFileName(_fileName);
     if (File.Exists(_fileName))
     {
         using (var file = new StreamReader(_fileName))
         {
             var count = 0;
             try
             {
                 while (!file.EndOfStream)
                 {
                     if (count++ == 0)
                     {
                         file.ReadLine();
                     }
                     var line = file.ReadLine();
                     StoredMovies.Add(MovieFactoryInstance.NewMovie(line, RegularExpression));
                 }
             }
             catch (Exception ex)
             {
                 Logger.Error("{0} {1} {2} {3}", ExceptionMessage, ex.Source, ex.Message, ex.StackTrace);
             }
         }
     }
     else
     {
         Logger.Warn(FileNotExistMessage);
     }
 }