private static void SerializeContactToStream(ContactDbEntry item, Stream stream, string formattedName) { SerializePropertyToStream(stream, "BEGIN", "VCARD"); SerializePropertyToStream(stream, "VERSION", "2.1"); SerializePropertyToStream(stream, "N", GetStructuredName(item)); SerializePropertyToStream(stream, "FN", formattedName); if (string.IsNullOrEmpty(item.Organization) == false) { SerializePropertyToStream(stream, "ORG", item.Organization); } if (string.IsNullOrEmpty(item.JobTitle) == false) { SerializePropertyToStream(stream, "ORG", item.JobTitle); } if (string.IsNullOrEmpty(item.WorkPhone) == false) { SerializePropertyToStream(stream, "TEL;WORK;VOICE", item.WorkPhone); } if (string.IsNullOrEmpty(item.MobilePhone) == false) { SerializePropertyToStream(stream, "TEL;CELL;VOICE", item.MobilePhone); } if (string.IsNullOrEmpty(item.EMail) == false) { SerializePropertyToStream(stream, "EMAIL;PREF;INTERNET", item.EMail); } if (item.ModificationDate != DateTimeOffset.MinValue) { var dateStr = item.ModificationDate.ToUniversalTime().ToString("yyyyMMddTHHmmssZ"); SerializePropertyToStream(stream, "REF", dateStr); } SerializePropertyToStream(stream, "END", "VCARD"); }
public static void Save(ContactDbEntry item) { string fomattedName = GetFormattedName(item); var outputFile = fomattedName + ".vcard"; using (var stream = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.Read)) { SerializeContactToStream(item, stream, fomattedName); } }
private static string GetFormattedName(ContactDbEntry item) { var result = StringExtensions.JoinIgnoreEmptyValues(" ", item.Prefix, item.First, item.Middle, item.Last, item.Suffix); if (string.IsNullOrWhiteSpace(result)) { result = item.Organization; } return(result); }
public IEnumerable <ContactDbEntry> GetAllItems() { var command = Connection.CreateCommand(); command.CommandText = "SELECT " + "ROWID," + "guid," + "First," + "Last," + "Middle," + "Organization," + "Note," + "Prefix," + "Suffix," + "DisplayName" + " FROM ABPerson"; using (var reader = command.ExecuteReader()) { while (reader.Read()) { var result = new ContactDbEntry { Id = reader.GetInt32(0), Guid = reader.GetGuidAtStartOfString(1), First = reader.GetValueOrDefault <string>(2), Last = reader.GetValueOrDefault <string>(3), Middle = reader.GetValueOrDefault <string>(4), Organization = reader.GetValueOrDefault <string>(5), Note = reader.GetValueOrDefault <string>(6), Prefix = reader.GetValueOrDefault <string>(7), Suffix = reader.GetValueOrDefault <string>(8), DisplayName = reader.GetValueOrDefault <string>(9), }; yield return(result); } } Connection.Close(); }
public IEnumerable <ContactDbEntry> GetAllItems() { var command = Connection.CreateCommand(); #pragma warning disable CA2100 // Review SQL queries for security vulnerabilities command.CommandText = "SELECT " + "ROWID" + ",guid" + ",ModificationDate" + ",First" + ",Last" + ",Middle" + ",Prefix" + ",Suffix" + ",Birthday" + ",JobTitle" + ",Department" + ",Organization" + ",(select value from ABMultiValue where property = 3 and record_id = ABPerson.ROWID and label = (select ROWID from ABMultiValueLabel where value = '_$!<Work>!$_')) as WorkPhone" + ",(select value from ABMultiValue where property = 3 and record_id = ABPerson.ROWID and label = (select ROWID from ABMultiValueLabel where value = '_$!<Mobile>!$_')) as MobilePhone" + ",(select value from ABMultiValue where property = 3 and record_id = ABPerson.ROWID and label = (select ROWID from ABMultiValueLabel where value = '_$!<Home>!$_')) as HomePhone" + ",(select value from ABMultiValue where property = 4 and record_id = ABPerson.ROWID and label is null) as Email" + ",(select value from ABMultiValueEntry where parent_id in (select ROWID from ABMultiValue where record_id = ABPerson.ROWID) and key = (select ROWID from ABMultiValueEntryKey where lower(value) = 'street')) as Street" + ",(select value from ABMultiValueEntry where parent_id in (select ROWID from ABMultiValue where record_id = ABPerson.ROWID) and key = (select ROWID from ABMultiValueEntryKey where lower(value) = 'city')) as City" + ",(select value from ABMultiValueEntry where parent_id in (select ROWID from ABMultiValue where record_id = ABPerson.ROWID) and key = (select ROWID from ABMultiValueEntryKey where lower(value) = 'state')) as State" + ",(select value from ABMultiValueEntry where parent_id in (select ROWID from ABMultiValue where record_id = ABPerson.ROWID) and key = (select ROWID from ABMultiValueEntryKey where lower(value) = 'zip')) as ZIP" + ",(select value from ABMultiValueEntry where parent_id in (select ROWID from ABMultiValue where record_id = ABPerson.ROWID) and key = (select ROWID from ABMultiValueEntryKey where lower(value) = 'country')) as Country" + " FROM ABPerson" + " ORDER BY ROWID"; #pragma warning restore CA2100 // Review SQL queries for security vulnerabilities using (var reader = command.ExecuteReader()) { while (reader.Read()) { var result = new ContactDbEntry { Id = reader.GetInt32(0), Guid = reader.GetGuidAtStartOfString(1), ModificationDate = reader.GetDateTimeOffsetFromLongMacTime(2), First = reader.GetValueOrDefault <string>(3), Last = reader.GetValueOrDefault <string>(4), Middle = reader.GetValueOrDefault <string>(5), Prefix = reader.GetValueOrDefault <string>(6), Suffix = reader.GetValueOrDefault <string>(7), Birthday = reader.GetDateTimeOffsetFromStringMacTime(8), JobTitle = reader.GetValueOrDefault <string>(9), Department = reader.GetValueOrDefault <string>(10), Organization = reader.GetValueOrDefault <string>(11), WorkPhone = reader.GetValueOrDefault <string>(12), MobilePhone = reader.GetValueOrDefault <string>(13), HomePhone = reader.GetValueOrDefault <string>(14), EMail = reader.GetValueOrDefault <string>(15), Street = reader.GetValueOrDefault <string>(16), City = reader.GetValueOrDefault <string>(17), State = reader.GetValueOrDefault <string>(18), ZIP = reader.GetValueOrDefault <string>(19), Country = reader.GetValueOrDefault <string>(20), }; yield return(result); } } Connection.Close(); }
private static string GetStructuredName(ContactDbEntry item) { return(string.Join(";", item.Last, item.First, item.Middle, item.Prefix, item.Suffix)); }