/// <summary> /// Reads the persons existing in the given people.in file. /// </summary> /// <param name="args">contains the input information, included the full path of the "people.in".</param> /// <returns>A list of persons representing each of lines existing in "people.in".</returns> protected virtual IEnumerable <Person> ReadPeople(PeopleListCommandArgs args) { if (string.IsNullOrWhiteSpace(args.InFullPath)) { throw new ArgumentNullException(nameof(args.InFullPath)); } string[] lines; try { lines = ReadLines(args.InFullPath, "people.in"); } catch (Exception) { throw; } foreach (var line in lines) { var values = line.Split("|"); if ((values?.Length ?? 0) != 8) { throw new ApplicationException($"Bad formed line: {line}"); } yield return(new Person { PersonId = values[0], Name = values[1], LastName = values[2], CurrentRole = values[3], Country = values[4], Industry = values[5], NumberOfRecommendations = int.Parse(values[6], CultureInfo.InvariantCulture), NumberOfConnections = int.Parse(values[7], CultureInfo.InvariantCulture) }); } }
public virtual void List(PeopleListCommandArgs args) { var people = this.ReadPeople(args).ToList(); this.View(people); }