internal static Organization GetOrganization (ICursor c, Resources resources) { Organization o = new Organization(); o.Name = c.GetString (OrganizationData.Company); o.ContactTitle = c.GetString (OrganizationData.Title); OrganizationDataKind d = (OrganizationDataKind) c.GetInt (c.GetColumnIndex (CommonColumns.Type)); o.Type = d.ToOrganizationType(); o.Label = (d != OrganizationDataKind.Custom) ? OrganizationData.GetTypeLabel (resources, d, String.Empty) : c.GetString (CommonColumns.Label); return o; }
internal static Contact GetContact (ABPerson person) { Contact contact = new Contact (person) { DisplayName = person.ToString(), Prefix = person.Prefix, FirstName = person.FirstName, MiddleName = person.MiddleName, LastName = person.LastName, Suffix = person.Suffix, Nickname = person.Nickname }; contact.Notes = (person.Note != null) ? new [] { new Note { Contents = person.Note } } : new Note[0]; contact.Emails = person.GetEmails().Select (e => new Email { Address = e.Value, Type = GetEmailType (e.Label), Label = (e.Label != null) ? GetLabel (e.Label) : GetLabel (ABLabel.Other) }); contact.Phones = person.GetPhones().Select (p => new Phone { Number = p.Value, Type = GetPhoneType (p.Label), Label = (p.Label != null) ? GetLabel (p.Label) : GetLabel (ABLabel.Other) }); Organization[] orgs; if (person.Organization != null) { orgs = new Organization[1]; orgs[0] = new Organization { Name = person.Organization, ContactTitle = person.JobTitle, Type = OrganizationType.Work, Label = GetLabel (ABLabel.Work) }; } else orgs = new Organization[0]; contact.Organizations = orgs; contact.InstantMessagingAccounts = person.GetInstantMessages().Select (ima => new InstantMessagingAccount() { Service = GetImService ((NSString)ima.Value[ABPersonInstantMessageKey.Service]), ServiceLabel = (NSString)ima.Value[ABPersonInstantMessageKey.Service], Account = (NSString)ima.Value[ABPersonInstantMessageKey.Username] }); contact.Addresses = person.GetAddresses().Select (a => new Address() { Type = GetAddressType (a.Label), Label = (a.Label != null) ? GetLabel (a.Label) : GetLabel (ABLabel.Other), StreetAddress = (NSString)a.Value[ABPersonAddressKey.Street], City = (NSString)a.Value[ABPersonAddressKey.City], Region = (NSString)a.Value[ABPersonAddressKey.State], Country = (NSString)a.Value[ABPersonAddressKey.Country], PostalCode = (NSString)a.Value[ABPersonAddressKey.Zip] }); contact.Websites = person.GetUrls().Select (url => new Website { Address = url.Value }); contact.Relationships = person.GetRelatedNames().Select (p => new Relationship { Name = p.Value, Type = GetRelationType (p.Label) }); return contact; }
internal static IContact GetContact( ABPerson person ) { var contact = new Contact( person ) { DisplayName = person.ToString(), Prefix = person.Prefix, FirstName = person.FirstName, MiddleName = person.MiddleName, LastName = person.LastName, Suffix = person.Suffix, Nickname = person.Nickname, Notes = (person.Note != null) ? new[] {new Note {Contents = person.Note}} : new Note[0], }; try { contact.Emails = person.GetEmails() .Select( e => new Email { Address = e.Value, Type = GetEmailType( e.Label ), Label = (e.Label != null) ? GetLabel( e.Label ) : GetLabel( ABLabel.Other ) } ); } catch(Exception) { contact.Emails = new List<Email>(); } try { contact.Phones = person.GetPhones() .Select( p => new Phone { Number = p.Value, Type = GetPhoneType( p.Label ), Label = (p.Label != null) ? GetLabel( p.Label ) : GetLabel( ABLabel.Other ) } ); } catch(Exception) { contact.Phones = new List<Phone>(); } Organization[] orgs; if(person.Organization != null) { orgs = new Organization[1]; orgs[0] = new Organization { Name = person.Organization, ContactTitle = person.JobTitle, Type = OrganizationType.Work, Label = GetLabel( ABLabel.Work ) }; } else { orgs = new Organization[0]; } contact.Organizations = orgs; contact.InstantMessagingAccounts = person.GetInstantMessageServices() .Select( ima => new InstantMessagingAccount() { Service = GetImService( (NSString)ima.Value.Dictionary[ABPersonInstantMessageKey.Service] ), ServiceLabel = ima.Value.ServiceName, Account = ima.Value.Username } ); contact.Addresses = person.GetAllAddresses() .Select( a => new Address() { Type = GetAddressType( a.Label ), Label = (a.Label != null) ? GetLabel( a.Label ) : GetLabel( ABLabel.Other ), StreetAddress = a.Value.Street, City = a.Value.City, Region = a.Value.State, Country = a.Value.Country, PostalCode = a.Value.Zip } ); try { contact.Websites = person.GetUrls().Select( url => new Website {Address = url.Value} ); } catch(Exception) { contact.Websites = new List<Website>(); } contact.Relationships = person.GetRelatedNames().Select( p => new Relationship {Name = p.Value, Type = GetRelationType( p.Label )} ); return contact; }
internal static Contact GetContact(ABPerson person) { Contact contact = new Contact(person) { DisplayName = person.ToString(), Prefix = person.Prefix, FirstName = person.FirstName, MiddleName = person.MiddleName, LastName = person.LastName, Suffix = person.Suffix, Nickname = person.Nickname }; contact.Notes = (person.Note != null) ? new [] { new Note { Contents = person.Note } } : new Note[0]; contact.Emails = person.GetEmails().Select(e => new Email { Address = e.Value, Type = GetEmailType(e.Label), Label = (e.Label != null) ? GetLabel(e.Label) : GetLabel(ABLabel.Other) }); contact.Phones = person.GetPhones().Select(p => new Phone { Number = p.Value, Type = GetPhoneType(p.Label), Label = (p.Label != null) ? GetLabel(p.Label) : GetLabel(ABLabel.Other) }); Organization[] orgs; if (person.Organization != null) { orgs = new Organization[1]; orgs[0] = new Organization { Name = person.Organization, ContactTitle = person.JobTitle, Type = OrganizationType.Work, Label = GetLabel(ABLabel.Work) }; } else { orgs = new Organization[0]; } contact.Organizations = orgs; contact.InstantMessagingAccounts = person.GetInstantMessages().Select(ima => new InstantMessagingAccount() { Service = GetImService((NSString)ima.Value[ABPersonInstantMessageKey.Service]), ServiceLabel = (NSString)ima.Value[ABPersonInstantMessageKey.Service], Account = (NSString)ima.Value[ABPersonInstantMessageKey.Username] }); contact.Addresses = person.GetAddresses().Select(a => new Address() { Type = GetAddressType(a.Label), Label = (a.Label != null) ? GetLabel(a.Label) : GetLabel(ABLabel.Other), StreetAddress = (NSString)a.Value[ABPersonAddressKey.Street], City = (NSString)a.Value[ABPersonAddressKey.City], Region = (NSString)a.Value[ABPersonAddressKey.State], Country = (NSString)a.Value[ABPersonAddressKey.Country], PostalCode = (NSString)a.Value[ABPersonAddressKey.Zip] }); contact.Websites = person.GetUrls().Select(url => new Website { Address = url.Value }); contact.Relationships = person.GetRelatedNames().Select(p => new Relationship { Name = p.Value, Type = GetRelationType(p.Label) }); return(contact); }