using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Contacts
{
///
/// Manages the contacts database and facilitates viewing the database via searching and sorting. Contains methods to update the current view.
///
public class FileIO
{
public IEnumerable currentState { get; set; }
private readonly List _contacts = new();
//private string _filepath = "~/.contacts";
///
/// Create the FileIo object and set default view.
///
public FileIO()
{
currentState =
from c in _contacts
select c;
}
///
/// Facilitates incoming compatability with .vcf, .card, and .csv filetypes for contacts into this console-based
/// contacts manager.
///
///
public void Import(Resolver resolver)
{
resolver.Parse();
List contacts = resolver.Contacts;
foreach (Contact c in contacts)
_contacts.Add(c);
}
///
/// Facilitates outgoing compatability with .vcf, .card, and .csv filetypes for contacts into this console-based contacts manager.
///
///
public void Export(bool onIos)
{
// TODO
}
///
/// Save the contacts in the database to a file.
///
/// Path to the file on computer
public void Save()
{
using (StreamWriter writer = new StreamWriter("yourContacts.save"))
{
foreach (Contact c in _contacts)
{
writer.WriteLine($"{c.SaveString()}");
}
}
}
///
/// Load the saved contacts in the database.
///
public void Load()
{
using (StreamReader reader = new StreamReader("yourContacts.save"))
{
while (!reader.EndOfStream)
{
_contacts.Add(new Contact(reader.ReadLine()));
}
}
}
}
}