private void LoadVcfDirectory(string filename) { List <WabContact> wabContacts = new List <WabContact>(20); bool error = false; var files = Directory.GetFiles(filename, "*.vcf"); foreach (var file in files) { try { var wc = WabIO.ReadVcard(file); wabContacts.AddRange(wc); } catch (Exception) { error = true; } } if (error) { MessageBox.Show(this, "Es konnten nicht alle Daten gelesen werden!", App.PROGRAM_NAME, MessageBoxButton.OK, MessageBoxImage.Error); } InitData(filename, wabContacts); }
//public static WabContact[] WabContacts { get; private set; } public static void InitData(string filename) { try { WabContact[] WabContacts = WabIO.ReadCsv(filename); Data = new List <Contact>(WabContacts.Length); foreach (WabContact wabContact in WabContacts) { Contact cont = new Contact(wabContact); Data.Add(cont); } if (Data.Count == 0) { MessageBox.Show( "Die Datei \"" + Path.GetFileName(filename) + "\" enthält keine Telefonnummern.", "Telefonliste", MessageBoxButton.OK, MessageBoxImage.Information); Data = null; return; } Data.Sort(); } catch (Exception e) { Data = null; throw new Exception(e.Message, e); } }
private void LoadFile(string filename) { WabContact[] wabContacts; if (Path.GetExtension(filename) == ".csv") { wabContacts = WabIO.ReadCsv(filename); } else { wabContacts = WabIO.ReadVcard(filename); } InitData(filename, wabContacts); }