public async Task CreateContactAsync(AttendingUser contact) { var contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); var contactLists = await contactStore.FindContactListsAsync(); var contactList = contactLists.FirstOrDefault(f => f.DisplayName == ContactListDisplayName) ?? await contactStore.CreateContactListAsync(ContactListDisplayName); var theContact = new Contact { FirstName = contact.FirstName, LastName = contact.Name, Phones = { new ContactPhone { Kind = ContactPhoneKind.Company, Number = contact.PhoneNumber } }, Emails = { new ContactEmail { Kind = ContactEmailKind.Work, Address = contact.EmailAddress } } }; await contactList.SaveContactAsync(theContact); }
// Info Stuff ########################################## private async Task ComposeEmail(Windows.ApplicationModel.Contacts.Contact recipient, string messageBody, StorageFile attachmentFile) { var emailMessage = new Windows.ApplicationModel.Email.EmailMessage(); emailMessage.Body = messageBody; if (attachmentFile != null) { var stream = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(attachmentFile); var attachment = new Windows.ApplicationModel.Email.EmailAttachment( attachmentFile.Name, stream); emailMessage.Attachments.Add(attachment); } var email = recipient.Emails.FirstOrDefault <Windows.ApplicationModel.Contacts.ContactEmail>(); if (email != null) { var emailRecipient = new Windows.ApplicationModel.Email.EmailRecipient(email.Address); emailMessage.To.Add(emailRecipient); } await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage); }
public async void Communicate(Contact kontakt) { //Email Message Objekat var emailMessage = new Windows.ApplicationModel.Email.EmailMessage(); //tekst poruke emailMessage.Body = textPoruke; StorageFile attachmentFile = null; //ako neko hoce da doda attachment na poruku moze ucitati file i proslijediti ga ovako //ovo se nikad nece pozvati, samo kao primjer kako se attachment doda if (attachmentFile != null) { var stream = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(attachmentFile); var attachment = new Windows.ApplicationModel.Email.EmailAttachment( attachmentFile.Name, stream); emailMessage.Attachments.Add(attachment); } //prvi mail koji se nadje var email = kontakt.Emails.FirstOrDefault<ContactEmail>(); if (email != null) { //postaviti kao recipient var emailRecipient = new Windows.ApplicationModel.Email.EmailRecipient(email.Address); //lista, moze se dodati vise kontakata emailMessage.To.Add(emailRecipient); } //poziva napokon api sa spremnom template porukom. Korisnik je naknadno moze izmjeniti koristeci mail client await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage); }
private async void button_Click(object sender, RoutedEventArgs e) { pickedContact = null; var contactPicker = new Windows.ApplicationModel.Contacts.ContactPicker(); contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber); var contact = await contactPicker.PickContactAsync(); if (contact != null) { string msg = "Got contact " + contact.DisplayName + " with phone numbers: "; foreach (var phone in contact.Phones) { msg += (phone.Kind.ToString() + " " + phone.Number); } var dlg = new Windows.UI.Popups.MessageDialog(msg); await dlg.ShowAsync(); pickedContact = contact; } }
// To facilitate design time data public ContactEx(string firsName, string lastName) { Contact = new Contact { FirstName = firsName, LastName = lastName }; }
static Contact Extract(Windows.ApplicationModel.Contacts.Contact contact, ContactSearchParams searchParams) { var phones = contact.Phones.Select(p => new Contact.Phone { Number = p.Number, Type = p.Kind.ToString() }).ToList(); var result = new Contact { Id = contact.Id, FirstName = contact.FirstName, MiddleName = contact.MiddleName, LastName = contact.LastName, DisplayName = contact.DisplayName, PhoneNumbers = phones, Emails = contact.Emails.Select(e => e.Address).ToList(), Prefix = searchParams.IncludePrefix ? contact.HonorificNamePrefix : null, Suffix = searchParams.IncludeSuffix ? contact.HonorificNameSuffix : null, Nickname = searchParams.IncludeNickName ? contact.Nickname : null, Notes = searchParams.IncludeNotes ? contact.Notes : null, Relationships = searchParams.IncludeRelationships ? contact.SignificantOthers.Select(r => r.Name).ToList() : null, Websites = searchParams.IncludeWebsites ? contact.Websites.Select(w => w.Uri?.ToString()).ToList() : null, }; if (searchParams.IncludeOrganizations) { result.Organizations = contact.JobInfo.Select(og => new Contact.Organization { JobTitle = og.Title, CompanyName = og.CompanyName }).ToList(); } if (searchParams.IncludeImAccounts) { result.InstantMessagingAccounts = contact.ConnectedServiceAccounts.Select(ims => new Contact.InstantMessagingAccount { Service = ims.ServiceName, UserId = ims.Id }).ToList(); } if (searchParams.IncludeAddresses) { result.Addresses = contact.Addresses.Select(ad => new Contact.Address { City = ad.Locality, Country = ad.Country, PostalCode = ad.PostalCode, Region = ad.Region, StreetAddress = ad.StreetAddress }).ToList(); } return(result); }
private ContactInfo CreateContactInfo(WinContacts.Contact contact) { return(new ContactInfo() { Id = contact.Id, FamilyName = contact.LastName, AdditionalName = contact.MiddleName, GivenName = contact.FirstName }); }
public void ShowContactCardMini(Contact contact, FrameworkElement element) { if (contact != null) { Rect rect = GetElementRect(element); // Show with default placement. ContactManager.ShowContactCard(contact, rect); } }
public async void pickContact() { //kako zatraziti kontakta, moze i vise kontakata tako sto se PickContactsAsync pozove u mnozini var contactPicker = new ContactPicker(); //sta nas sve interesuje od odabranog kontakta contactPicker.SelectionMode = Windows.ApplicationModel.Contacts.ContactSelectionMode.Fields; contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber); contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Email); trenutniKontakt = await contactPicker.PickContactAsync(); // ImeKontakta = "Trenutni Kontakt:" + trenutniKontakt.LastName + " " + trenutniKontakt.FirstName; }
public void Communicate(Contact kontakt) { //izvuci broj korisnika iz kontakta string telBroj = kontakt.Phones.FirstOrDefault<ContactPhone>().Number; //potrebno je prvo dodati referencu u projekat Windows Mobile Extensions for the UWP if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.ApplicationModel.Calls.PhoneCallManager")) { //pozvati ui koji preuzima poziv Windows.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI(telBroj, kontakt.Name); } }
public void Send(Contact recipient, string messageBody, StorageFile attachmentFile, string mimeType) { var phone = recipient.Phones.FirstOrDefault(); if (phone != null) { Send(phone.Number, messageBody, attachmentFile, mimeType); } }
private async void GetThumbnail(Contact contact) { if (contact.Thumbnail != null) { IRandomAccessStreamWithContentType stream = await contact.Thumbnail.OpenReadAsync(); if (stream != null && stream.Size > 0) { Thumbnail = new BitmapImage(); Thumbnail.SetSource(stream); } } }
public void ShowContactCardFull(Contact contact) { if (contact != null) { // Try to share the screen half/half with the full contact card. FullContactCardOptions options = new FullContactCardOptions { DesiredRemainingView = ViewSizePreference.UseHalf }; // Show the full contact card. ContactManager.ShowFullContactCard(contact, options); } }
/// <summary> /// Initializes a new instance of the ContactItemAdapter class. /// </summary> /// <param name="contact"></param> public ContactItemAdapter(Contact contact) { this.Name = contact.DisplayName; if (contact.Emails.Count > 0) { this.SecondaryText = contact.Emails[0].Address; } else if (contact.Phones.Count > 0) { this.SecondaryText = contact.Phones[0].Number; } this.GetThumbnail(contact); }
private async void ComposeEmail(Windows.ApplicationModel.Contacts.Contact recipient, string messageBody) { var emailMessage = new Windows.ApplicationModel.Email.EmailMessage(); emailMessage.Body = messageBody; var email = recipient.Emails.FirstOrDefault <Windows.ApplicationModel.Contacts.ContactEmail>(); if (email != null) { var emailRecipient = new Windows.ApplicationModel.Email.EmailRecipient(email.Address); emailMessage.To.Add(emailRecipient); } await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage); }
public static async Task<DDContact> CreateFromContact(Contact contact) { Uri contactPlaceholder = new Uri("ms-appx:///Assets/contactPlaceholder.png"); var image = new BitmapImage(contactPlaceholder); if (contact.Thumbnail != null) { var imageStream = await contact.Thumbnail.OpenReadAsync(); await image.SetSourceAsync(imageStream); } return new DDContact() { Name = contact.FirstName, Thumbnail = image, Id = contact.Id, Phone = contact.Phones.First(c => c.Kind == ContactPhoneKind.Mobile).Number }; }
public ContactItemAdapter(Contact contact) { Name = contact.DisplayName; if (contact.Emails.Count > 0) { SecondaryText = contact.Emails[0].Address; } else if (contact.Phones.Count > 0) { SecondaryText = contact.Phones[0].Number; } else if (contact.Addresses.Count > 0) { List<string> addressParts = (new List<string> { contact.Addresses[0].StreetAddress, contact.Addresses[0].Locality, contact.Addresses[0].Region, contact.Addresses[0].PostalCode }); string unstructuredAddress = string.Join(", ", addressParts.FindAll(s => !string.IsNullOrEmpty(s))); SecondaryText = unstructuredAddress; } GetThumbnail(contact); }
private async Task <Windows.ApplicationModel.Contacts.Contact> findContact(string emailAddress) { if (contactStore == null) { contactStore = await ContactManager.RequestStoreAsync(); contactStore.ContactChanged += ContactStore_ContactChanged; contactStore.ChangeTracker.Enable(); } IReadOnlyList <Windows.ApplicationModel.Contacts.Contact> contacts = null; contacts = await contactStore.FindContactsAsync(emailAddress); Windows.ApplicationModel.Contacts.Contact contact = contacts[0]; return(contact); }
private async void OpenContact_Click(object sender, RoutedEventArgs e) { // Get the selection rect of the button pressed to show contact card. FrameworkElement element = (FrameworkElement)sender; Windows.UI.Xaml.Media.GeneralTransform buttonTransform = element.TransformToVisual(null); Windows.Foundation.Point point = buttonTransform.TransformPoint(new Windows.Foundation.Point()); Windows.Foundation.Rect rect = new Windows.Foundation.Rect(point, new Windows.Foundation.Size(element.ActualWidth, element.ActualHeight)); // helper method to find a contact just for illustrative purposes. Windows.ApplicationModel.Contacts.Contact contact = await findContact("*****@*****.**"); //Show Contact in contact Application FullContactCardOptions options = new FullContactCardOptions(); options.DesiredRemainingView = ViewSizePreference.UseHalf; // Show the full contact card. ContactManager.ShowFullContactCard(contact, options); }
private async void DoneContactClick(object sender, RoutedEventArgs e) { var contact = new Windows.ApplicationModel.Contacts.Contact(); contact.FirstName = name; ContactEmail email = new ContactEmail(); email.Address = mail; email.Kind = ContactEmailKind.Other; contact.Emails.Add(email); ContactPhone phone = new ContactPhone(); phone.Number = number; phone.Kind = ContactPhoneKind.Mobile; contact.Phones.Add(phone); ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); ContactList contactList; IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync(); if (0 == contactLists.Count) { contactList = await store.CreateContactListAsync("TestContactList"); } else { contactList = contactLists[0]; } await contactList.SaveContactAsync(contact); }
/// <summary> /// Creates a new instance of an NdefVcardRecord and imports /// the payload into the ContactData instance. /// </summary> /// <param name="other">An NDEF record that contains /// valid vCard data as its payload and has the right type information.</param> public NdefVcardRecord(NdefRecord other) : base(other) { ContactData = ParseDataToContact(_payload); }
/// <summary> /// Map the Windows 8 Contact class to a vCard object from the vCard library. /// This mapping is not 1:1, as Contact has differnet properties than supported /// in the vCard standard. /// The method maps / converts as much information as possible. /// </summary> /// <param name="contact">Source contact to convert to a vCard object.</param> /// <returns>New vCard object with information from the source contact mapped /// as completely as possible.</returns> public vCard ConvertContactToVCard(Contact contact) { var vc = new vCard { FamilyName = contact.LastName, GivenName = contact.FirstName, NamePrefix = contact.HonorificNamePrefix, NameSuffix = contact.HonorificNameSuffix }; // Phone numbers foreach (var phone in contact.Phones) { vc.Phones.Add(new vCardPhone(phone.Number, ConvertPhoneTypeToVcard(phone.Kind))); } // Email foreach (var email in contact.Emails) { vc.EmailAddresses.Add(new vCardEmailAddress(email.Address, ConvertEmailTypeToVcard(email.Kind))); } // Postal address foreach (var address in contact.Addresses) { vc.DeliveryAddresses.Add(ConvertAddressToVcard(address)); } // Notes if (!String.IsNullOrEmpty(contact.Notes)) { vc.Notes.Add(new vCardNote(contact.Notes)); } // Dates foreach (var importantDate in contact.ImportantDates) { if (importantDate.Kind == ContactDateKind.Birthday) { if (importantDate.Year != null && (importantDate.Month != null && importantDate.Day != null)) { vc.BirthDate = new DateTime((int)importantDate.Year, (int)importantDate.Month, (int)importantDate.Day); } } } // Websites foreach (var website in contact.Websites) { vc.Websites.Add(ConvertWebsiteToVcard(website)); } // Job info foreach (var jobInfo in contact.JobInfo) { // Set company name / organisation if not yet set and present in the source info if (!String.IsNullOrEmpty(jobInfo.CompanyName) && String.IsNullOrEmpty(vc.Organization)) { vc.Organization = jobInfo.CompanyName; } // Set department if not yet set and present in the source info if (!String.IsNullOrEmpty(jobInfo.Department) && String.IsNullOrEmpty(vc.Department)) { vc.Department = jobInfo.Department; } // Set position / job if not yet set and present in the source info if (!String.IsNullOrEmpty(jobInfo.Title) && String.IsNullOrEmpty(vc.Title)) { vc.Title = jobInfo.Title; } } return vc; }
public ContactEx(Contact contact) { Contact = contact; }
private string GetThumbnail(Contact contact) { return (contact.Thumbnail != null) ? ((StorageFile)contact.Thumbnail).Path : "ms-appx:///Images/default.png"; }
private void HandleContactClicked(AttendeeViewModel attendee) { var contact = new Windows.ApplicationModel.Contacts.Contact(); contact.YomiGivenName = attendee.User.Name; contact.Name = attendee.User.Name; ContactEmail workEmail = new ContactEmail(); workEmail.Address = attendee.User.Email; workEmail.Kind = ContactEmailKind.Work; contact.Emails.Add(workEmail); // Try to share the screen half/half with the full contact card. FullContactCardOptions options = new FullContactCardOptions(); options.DesiredRemainingView = ViewSizePreference.UseHalf; // Show the full contact card. ContactManager.ShowFullContactCard(contact, options); }
internal static Contact ConvertContact(Windows.ApplicationModel.Contacts.Contact contact) { if (contact == null) { return(default);
public async Task<bool> DeleteContact(Contact contact) { try { ContactStore allAccessStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly); var contactLists = await allAccessStore.FindContactListsAsync(); string contactListId = string.Empty; if (contactLists.Count != 0) { contactListId = contactLists.FirstOrDefault().Id; return false; } var contactList = await allAccessStore.GetContactListAsync(contactListId); await contactList.DeleteContactAsync(contact); return true; } catch { return false; } }
public async Task InserNewContact(string firstName, string lastName, string phone, string email) { var contactInfo = new Contact { FirstName = firstName, LastName = lastName }; contactInfo.Phones.Add(new ContactPhone() { Number = phone }); contactInfo.Emails.Add(new ContactEmail() { Address = email }); ContactStore allAccessStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly); var contactLists = await allAccessStore.FindContactListsAsync(); string contactListId = string.Empty; if (contactLists.Count != 0) { contactListId = contactLists.FirstOrDefault().Id; return; } var contactList = await allAccessStore.GetContactListAsync(contactListId); await contactList.SaveContactAsync(contactInfo); }
private void ApplyPatternMatching(OcrResult ocrResult) { Contact contact = new Contact(); //set the picture contact.SourceDisplayPicture = _photoFile; // this method uses an action that will run as a 'callback' for the method // more info here https://msdn.microsoft.com/en-us/library/018hxwa8(v=vs.110).aspx RepeatForOcrWords(ocrResult, (result, word) => { bool isNumber = false; //check the recognized type and then add the type to the contact switch (CardRecognizer.Recognize(word.Text)) { case RecognitionType.Other: break; case RecognitionType.Email: contact.Emails.Add(new ContactEmail() { Address = word.Text }); break; case RecognitionType.Name: contact.FirstName = word.Text; break; case RecognitionType.Number: isNumber = true; //NOTE: Phone numbers are not as easy to validate because OCR results splits the numbers if they contain spaces. _phoneNumber += word.Text; RecognitionType type = CardRecognizer.Recognize(_phoneNumber); if (type == RecognitionType.PhoneNumber) { contact.Phones.Add(new ContactPhone() { Number = _phoneNumber }); } break; case RecognitionType.WebPage: try { contact.Websites.Add(new ContactWebsite() { Uri = new Uri(word.Text) }); } catch (Exception) { Debug.WriteLine("OCR Result cannot be converted to a URI"); } break; default: break; } //Encounted a word or a value other than a number. //If we havent validated as a phone number at this stage it is clearly not a phone number so clear the string if (!isNumber) { _phoneNumber = string.Empty; } }); if (!contact.Phones.Any()) //contact must have either a phone or email when calling ContactManager.ShowContactCard. { if (!contact.Emails.Any()) { Debug.WriteLine("Contact must have phone or email info."); return; } } Rect rect = GetElementRect(GetDetailsButton); ContactManager.ShowContactCard(contact, rect, Windows.UI.Popups.Placement.Default); }
public async void Communicate(Contact kontakt) { if (device == null) { try { //dobavljanje device, api vrati standardno null ako bilo sta nije uredu ヽ(ಠ_ಠ)ノ //treba i capability u manifestu device = SmsDevice2.GetDefault(); } catch (Exception ex) { throw ex; } } if (device != null) { string msgStr; try { //kreirati poruku SmsTextMessage2 msg = new SmsTextMessage2(); //na koji broj string telBroj = kontakt.Phones.FirstOrDefault<ContactPhone>().Number; msg.To = telBroj; //koji tekst msg.Body = textPoruke; //poslati poruku SmsSendMessageResult result = await device.SendMessageAndGetResultAsync(msg); if (result.IsSuccessful) { //povratni info slanja poruke msgStr = ""; msgStr += "Text message sent, cellularClass: " + result.CellularClass.ToString(); IReadOnlyList<Int32> messageReferenceNumbers = result.MessageReferenceNumbers; for (int i = 0; i < messageReferenceNumbers.Count; i++) { msgStr += "\n\t\tMessageReferenceNumber[" + i.ToString() + "]: " + messageReferenceNumbers[i].ToString(); } } else { //povratni info neuspjesnog slanja poruke msgStr = ""; msgStr += "ModemErrorCode: " + result.ModemErrorCode.ToString(); msgStr += "\nIsErrorTransient: " + result.IsErrorTransient.ToString(); if (result.ModemErrorCode == SmsModemErrorCode.MessagingNetworkError) { msgStr += "\n\tNetworkCauseCode: " + result.NetworkCauseCode.ToString(); if (result.CellularClass == CellularClass.Cdma) { msgStr += "\n\tTransportFailureCause: " + result.TransportFailureCause.ToString(); } throw new Exception(msgStr); } } } catch (Exception ex) { //exceptione je dobro ponekad proslijediti onome ko koristi ovu metodu da moze obraditi sta da uradi u tim situacijama throw ex; } } else { //ako je device null ne zna se zasto, pa se kaze da nema device throw new Exception("Nema SMS device"); } }
private async void CreateContact_Click(object sender, RoutedEventArgs e) { Windows.ApplicationModel.Contacts.Contact contact = new Windows.ApplicationModel.Contacts.Contact(); contact.FirstName = "TestContactWhatsApp"; Windows.ApplicationModel.Contacts.ContactEmail email = new Windows.ApplicationModel.Contacts.ContactEmail(); email.Address = "*****@*****.**"; email.Kind = Windows.ApplicationModel.Contacts.ContactEmailKind.Other; contact.Emails.Add(email); Windows.ApplicationModel.Contacts.ContactPhone phone = new Windows.ApplicationModel.Contacts.ContactPhone(); phone.Number = "4255550101"; phone.Kind = Windows.ApplicationModel.Contacts.ContactPhoneKind.Mobile; contact.Phones.Add(phone); Windows.ApplicationModel.Contacts.ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite); ContactList contactList; IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync(); if (0 == contactLists.Count) { contactList = await store.CreateContactListAsync("WhatsAppContactList"); } else { contactList = contactLists[0]; } await contactList.SaveContactAsync(contact); //Add Annotation ContactAnnotationStore annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite); ContactAnnotationList annotationList; IReadOnlyList <ContactAnnotationList> annotationLists = await annotationStore.FindAnnotationListsAsync(); if (0 == annotationLists.Count) { annotationList = await annotationStore.CreateAnnotationListAsync(); } else { annotationList = annotationLists[0]; } ContactAnnotation annotation = new ContactAnnotation(); annotation.ContactId = contact.Id; annotation.RemoteId = phone.Number; //associate the ID of a contact to an ID that your app uses internally to identify that user. annotation.SupportedOperations = ContactAnnotationOperations.Message | ContactAnnotationOperations.AudioCall | ContactAnnotationOperations.VideoCall | ContactAnnotationOperations.ContactProfile; await annotationList.TrySaveAnnotationAsync(annotation); }
private async void sendEmail(object sender, RoutedEventArgs e) { var emailMessage = new Windows.ApplicationModel.Email.EmailMessage(); Contact c = new Contact(); c.Emails.Add(new ContactEmail() { Address = "*****@*****.**" }); var email = c.Emails.FirstOrDefault<ContactEmail>(); if (email != null) { var emailRecipient = new EmailRecipient(email.Address); emailMessage.To.Add(emailRecipient); } await EmailManager.ShowComposeNewEmailAsync(emailMessage); }
/// <summary> /// Construct a new vCard record based on the WinRT contact instance, /// which is automatically converted to a vCard for the payload of this record. /// </summary> /// <param name="contact">Contact instance that should be converted to a vCard /// for this payload's record.</param> public NdefVcardRecord(Contact contact) { ContactData = contact; }
private string GetPhoneNumber(Contact contact) { return (contact.Phones.Count > 0) ? contact.Phones[0].Number : ""; }
/// <summary> /// Create a new vCard record based on the string that contains valid vCard /// information. Automatically parses the vCard data and populates fields in /// the WinRT Contact instance accessible through ContactData. /// </summary> /// <param name="vCardString">String that contains vCard data.</param> public NdefVcardRecord(string vCardString) { ContactData = ParseDataToContact(Encoding.UTF8.GetBytes(vCardString)); }
private void BtnWriteBusinessCard_Click(object sender, RoutedEventArgs e) { var contact = new Contact { FirstName = "Andreas", LastName = "Jakl" }; // Add the personal email address to the Contact object’s emails vector var personalEmail = new ContactEmail { Address = "*****@*****.**", Kind = ContactEmailKind.Work }; contact.Emails.Add(personalEmail); // Adds the home phone number to the Contact object’s phones vector var homePhone = new ContactPhone { Number = "+1234", Kind = ContactPhoneKind.Home }; contact.Phones.Add(homePhone); // Adds the address to the Contact object’s addresses vector var workAddress = new ContactAddress { StreetAddress = "Street 1", Locality = "Vienna", Region = "Austria", PostalCode = "1234", Kind = ContactAddressKind.Work }; contact.Addresses.Add(workAddress); contact.Websites.Add(new ContactWebsite { Uri = new Uri("http://www.nfcinteractor.com/") }); contact.JobInfo.Add(new ContactJobInfo { CompanyName = "Andreas Jakl", Title = "Mobility Evangelist" }); contact.Notes = "Developer of the NFC Library"; //var record = new NdefVcardRecord(contact); //// Publish the record using the proximity device //PublishRecord(record, true); }
/// <summary> /// Create a new vCard record based on the byte array that contains valid vCard /// information. Automatically parses the vCard data and populates fields in /// the WinRT Contact instance accessible through ContactData. /// </summary> /// <param name="vCardByte">Byte array that contains vCard data.</param> public NdefVcardRecord(byte[] vCardByte) { ContactData = ParseDataToContact(vCardByte); }
public static string GetContactResult(Contact contact) { var result = new StringBuilder(); //result.AppendFormat("Display name: {0}", contact.DisplayName); //result.AppendLine(); //foreach (ContactEmail email in contact.Emails) //{ // result.AppendFormat("Email address ({0}): {1}", email.Kind, email.Address); // result.AppendLine(); //} foreach (ContactPhone phone in contact.Phones) { //result.AppendFormat("Phone ({0}): {1}", phone.Kind, phone.Number); result.AppendFormat("{0}", phone.Number); result.AppendLine(); } return result.ToString(); }
/// <summary> /// Convert the byte array to a WinRT Contact. /// Matching is not 1:1, but this methods tries to convert as much of the data as possible. /// </summary> /// <param name="vCardByte">Business card vCard string as a UTF8 encoded byte array.</param> private Contact ParseDataToContact(byte[] vCardByte) { var vcReader = new vCardStandardReader(); var vc = vcReader.Read(new StringReader(Encoding.UTF8.GetString(vCardByte, 0, vCardByte.Length))); var convertedContact = new Contact { FirstName = vc.GivenName, LastName = vc.FamilyName, HonorificNamePrefix = vc.NamePrefix, HonorificNameSuffix = vc.NameSuffix }; // Phone numbers foreach (var phone in vc.Phones) { convertedContact.Phones.Add(ConvertVcardToPhone(phone)); } // Email foreach (var email in vc.EmailAddresses) { convertedContact.Emails.Add(ConvertVcardToEmail(email)); } // Postal address foreach (var address in vc.DeliveryAddresses) { convertedContact.Addresses.Add(ConvertVcardToAddress(address)); } // Notes foreach (var note in vc.Notes) { if (convertedContact.Notes != null) { convertedContact.Notes += "\n" + note.Text; } else { convertedContact.Notes = note.Text; } } // Dates if (vc.BirthDate != null) { var birthDay = (DateTime) vc.BirthDate; convertedContact.ImportantDates.Add(new ContactDate { Kind = ContactDateKind.Birthday, Year = birthDay.Year, Month = (uint?) birthDay.Month, Day = (uint?) birthDay.Day }); } // Websites foreach (var website in vc.Websites) { convertedContact.Websites.Add(ConvertVcardToWebsite(website)); } // Job info if (!String.IsNullOrEmpty(vc.Organization) || !String.IsNullOrEmpty(vc.Department) || !String.IsNullOrEmpty(vc.Title)) { var jobInfo = new ContactJobInfo(); if (!String.IsNullOrEmpty(vc.Organization)) { jobInfo.CompanyName = vc.Organization; } if (!String.IsNullOrEmpty(vc.Department)) { jobInfo.Department = vc.Department; } if (!String.IsNullOrEmpty(vc.Title)) { jobInfo.Title = vc.Title; } convertedContact.JobInfo.Add(jobInfo); } return convertedContact; }