/// <summary> /// Method to remove a new vCard from the collection /// </summary> /// <param name="vcard">vCard object to be removed</param> public void Remove(vCard vcard) { List.Remove(vcard); }
private void BuildProperties_NAME( vCardPropertyCollection properties, vCard card) { if (!string.IsNullOrEmpty(card.DisplayName)) { vCardProperty property = new vCardProperty("NAME", card.DisplayName); properties.Add(property); } }
private void BuildProperties_PHOTO( vCardPropertyCollection properties, vCard card) { foreach (vCardPhoto photo in card.Photos) { if (photo.Url == null) { // This photo does not have a URL associated // with it. Therefore a property can be // generated only if the image data is loaded. // Otherwise there is not enough information. if (photo.IsLoaded) { properties.Add( new vCardProperty("PHOTO", photo.GetBytes())); } } else { // This photo has a URL associated with it. The // PHOTO property can either be linked as an image // or embedded, if desired. bool doEmbedded = photo.Url.IsFile ? this.embedLocalImages : this.embedInternetImages; if (doEmbedded) { // According to the settings of the card writer, // this linked image should be embedded into the // vCard data. Attempt to fetch the data. try { //photo.Fetch(); // PCL } catch { // An error was encountered. The image can // still be written as a link, however. doEmbedded = false; } } // At this point, doEmbedded is true only if (a) the // writer was configured to embed the image, and (b) // the image was successfully downloaded. if (doEmbedded) { properties.Add( new vCardProperty("PHOTO", photo.GetBytes())); } else { vCardProperty uriPhotoProperty = new vCardProperty("PHOTO"); // Set the VALUE property to indicate that // the data for the photo is a URI. uriPhotoProperty.Subproperties.Add("VALUE", "URI"); uriPhotoProperty.Value = photo.Url.ToString(); properties.Add(uriPhotoProperty); } } } }
private void BuildProperties_CLASS( vCardPropertyCollection properties, vCard card) { vCardProperty property = new vCardProperty("CLASS"); switch (card.AccessClassification) { case vCardAccessClassification.Unknown: // No value is written. return; case vCardAccessClassification.Confidential: property.Value = "CONFIDENTIAL"; break; case vCardAccessClassification.Private: property.Value = "PRIVATE"; break; case vCardAccessClassification.Public: property.Value = "PUBLIC"; break; default: throw new NotSupportedException(); } properties.Add(property); }
/// <summary> /// Builds KEY properties. /// </summary> private void BuildProperties_KEY( vCardPropertyCollection properties, vCard card) { // A KEY field contains an embedded security certificate. foreach (vCardCertificate certificate in card.Certificates) { vCardProperty property = new vCardProperty(); property.Name = "KEY"; property.Value = certificate.Data; property.Subproperties.Add(certificate.KeyType); properties.Add(property); } }
private void BuildProperties_TZ( vCardPropertyCollection properties, vCard card) { if (!string.IsNullOrEmpty(card.TimeZone)) { properties.Add(new vCardProperty("TZ", card.TimeZone)); } }
/// <summary> /// Writes a vCard to an output text writer. /// </summary> public override void Write(vCard card, TextWriter output) { if (card == null) throw new ArgumentNullException("card"); if (output == null) throw new ArgumentNullException("output"); // Get the properties of the vCard. vCardPropertyCollection properties = BuildProperties(card); Write(properties, output); }
public frmvCard() { InitializeComponent(); vCard card = new vCard(); }
public Customer(vCard card) : base(card) { this.typeField = UserRole.Customer; }
/// <summary> /// Parses a vCard contact /// </summary> /// <param name="vCard"></param> /// <returns></returns> private static Contact ParseVCard(vCard vCard) { Contact contact = new Contact(false); contact.ID = vCard.UniqueId; if (contact.ID == string.Empty) { contact.ID = IDGenerator.GenerateID(); } #region Name { Name name = Name.TryParse(vCard.FormattedName); if (name == null) { name = new Name(); } if (vCard.GivenName != string.Empty) { name.FirstName = vCard.GivenName; } if (vCard.AdditionalNames != string.Empty) { name.MiddleName = vCard.AdditionalNames; } if (vCard.FamilyName != string.Empty) { name.LastName = vCard.FamilyName; } if (vCard.NamePrefix != string.Empty) { name.Title = vCard.NamePrefix; } if (vCard.NameSuffix != string.Empty) { name.Suffix = vCard.NameSuffix; } contact.Name = name; } #endregion #region Delivery Address { vCardDeliveryAddressCollection vAddresses = vCard.DeliveryAddresses; int count = vAddresses.Count; Address[] addresses = new Address[count]; for (int i = 0; i < count; i++) { vCardDeliveryAddress vAddress = vAddresses[i]; Address address = new Address(); address.City = vAddress.City; address.Country = vAddress.Country; address.State = vAddress.Region; address.Street = vAddress.Street.TrimEnd(','); address.ZIP = vAddress.PostalCode; address.Type = vAddress.AddressType.ToString(); addresses[i] = address; } contact.Addresses = addresses; } #endregion #region Email Address { vCardEmailAddressCollection vEmails = vCard.EmailAddresses; int count = vEmails.Count; Email[] emails = new Email[count]; for (int i = 0; i < count; i++) { vCardEmailAddress vEmail = vEmails[i]; Email email = new Email(); email.Address = vEmail.Address; email.Type = vEmail.EmailType.ToString(); emails[i] = email; } contact.Emails = emails; } #endregion #region Website { vCardWebsiteCollection vWebsites = vCard.Websites; int count = vWebsites.Count; Website[] websites = new Website[count]; for (int i = 0; i < count; i++) { vCardWebsite vWebsite = vWebsites[i]; Website website = new Website(); website.Url = vWebsite.Url; website.Type = vWebsite.WebsiteType.ToString(); websites[i] = website; } contact.Websites = websites; } #endregion #region Notes { FlowDocument notes = new FlowDocument(); foreach (vCardNote each in vCard.Notes) { Paragraph para = new Paragraph(new Run(each.Text)); if (each.Language != string.Empty) { try { para.Language = XmlLanguage.GetLanguage(each.Language); } catch { } } notes.Blocks.Add(para); } contact.NotesDocument = notes; } #endregion #region Phone { vCardPhoneCollection vPhones = vCard.Phones; int count = vPhones.Count; PhoneNumber[] phones = new PhoneNumber[count]; for (int i = 0; i < count; i++) { vCardPhone vPhone = vPhones[i]; PhoneNumber phone = new PhoneNumber(); phone.Number = vPhone.FullNumber; phone.Type = InsertSpaces(vPhone.PhoneType.ToString()); phones[i] = phone; } contact.PhoneNumbers = phones; } #endregion if (vCard.BirthDate.HasValue) { contact.SpecialDates = new SpecialDate[] { new SpecialDate("Birthday", vCard.BirthDate.Value) } } ; contact.Private = vCard.AccessClassification.HasFlag(vCardAccessClassification.Confidential) || vCard.AccessClassification.HasFlag(vCardAccessClassification.Private); contact.Work = new Work() { Company = vCard.Organization, Department = vCard.Department, Office = vCard.Office, Title = vCard.Title }; contact.Gender = (Gender)vCard.Gender; if (vCard.IMAddress != string.Empty) { contact.IM = new IM[] { new IM("IM", vCard.IMAddress) } } ; foreach (vCardPhoto photo in vCard.Photos) { if (photo.Url != null) { try { photo.Fetch(); contact.encodeTile(photo.GetBytes()); //contact.Tile = Create96By96Tile(ConvertBytesToBitmapSource(photo.GetBytes())); break; } catch { } } else { contact.encodeTile(photo.GetBytes()); //contact.Tile = Create96By96Tile(ConvertBytesToBitmapSource(photo.GetBytes())); break; } } return(contact); }
protected override IEnumerable <DistributionListMember> GetMembers(vCard source, DistributionListSychronizationContext context, IEntitySynchronizationLogger synchronizationLogger, ILog logger) { return(source.Members.Select(v => new DistributionListMember(v.EmailAddress, v.DisplayName))); }
public void ParseXPalmWithPhoto() { // 01 BEGIN:VCARD // 02 VERSION:2.1 // 03 N:Leonhard;Gerd // 04 FN:Gerd Leonhard // 05 TITLE:CEO // 06 ORG:ThinkAndLink, MusicFuturist, Sonific // 07 ADR;WORK:;;Terrassenstrasse 26;Arlesheim;;4144;Switzerland // 08 URL;WORK:www.gerdleonhard.com // 09 TEL;WORK:+41617018882 // 10 EMAIL:[email protected] // 11 EMAIL:[email protected] // 12 TEL;CELL:+41797935384 // 13 TEL;PAGER:US:14158467093 // 14 TEL;FAX:+4112742899 // 15 TEL:SkypeL gleonhard // 16 X-Palm-Custom1:www.thinkandlink.biz // 17 X-Palm-Custom2:www.musicfuturist.com // 18 X-Palm-Custom3:Skype: gleonhard // 19 X-Palm-Custom4:www.sonific.com // 20 X-PALM-IM;Yahoo:[email protected] // 21 PHOTO;JPEG;BASE64: // 22 (mime data) vCard card = new vCard( new StreamReader(new MemoryStream(SampleCards.XPalmWithPhoto))); // 03 N:Leonhard;Gerd Assert.AreEqual( "Leonhard", card.FamilyName, "N (family name) on line 3 failed."); Assert.AreEqual( "Gerd", card.GivenName, "N (given name) on line 3 failed."); // 04 FN:Gerd Leonhard Assert.AreEqual( "Gerd Leonhard", card.FormattedName, "FN on line 4 failed."); // 05 TITLE:CEO Assert.AreEqual( "CEO", card.Title, "TITLE on line 5 failed."); // 06 ORG:ThinkAndLink, MusicFuturist, Sonific Assert.AreEqual( "ThinkAndLink, MusicFuturist, Sonific", card.Organization, "ORG on line 6 failed."); // 07 ADR;WORK:;;Terrassenstrasse 26;Arlesheim;;4144;Switzerland Assert.AreEqual( 1, card.DeliveryAddresses.Count, "One delivery address expected on line 7."); Assert.IsTrue( card.DeliveryAddresses[0].IsWork, "ADR on line 7 is a work address."); Assert.AreEqual( "Terrassenstrasse 26", card.DeliveryAddresses[0].Street, "ADR on line 7 has a different street address."); Assert.AreEqual( "Arlesheim", card.DeliveryAddresses[0].City, "ADR on line 7 has a different city."); Assert.AreEqual( "4144", card.DeliveryAddresses[0].PostalCode, "ADR on line 7 has a different postal code."); Assert.AreEqual( "Switzerland", card.DeliveryAddresses[0].Country, "ADR on line 7 has a different country."); // 08 URL;WORK:www.gerdleonhard.com Assert.AreEqual( 1, card.Websites.Count, "Only one URL is located in the file (line 8)."); Assert.IsTrue( card.Websites[0].IsWorkSite, "URL on line 8 is a work-related web site."); Assert.AreEqual( "www.gerdleonhard.com", card.Websites[0].Url, "URL on line 8 has a different value."); // 09 TEL;WORK:+41617018882 Assert.AreEqual( 5, card.Phones.Count, "The vCard has four numbers at lines 4, 12, 13, 14 and 15."); Assert.IsTrue( card.Phones[0].IsWork, "TEL on line 9 is a work-related number."); Assert.AreEqual( "+41617018882", card.Phones[0].FullNumber, "TEL on line 9 has a different wrong phone number."); // 10 EMAIL:[email protected] // 11 EMAIL:[email protected] Assert.AreEqual( 2, card.EmailAddresses.Count, "There are two email addresses beginning at line 10."); Assert.AreEqual( "*****@*****.**", card.EmailAddresses[0].Address, "EMAIL at line 10 has a different value."); Assert.AreEqual( "*****@*****.**", card.EmailAddresses[1].Address, "EMAIL at line 11 has a different value."); // 12 TEL;CELL:+41797935384 Assert.IsTrue( card.Phones[1].IsCellular, "TEL at line 12 is a cellular phone number."); Assert.AreEqual( "+41797935384", card.Phones[1].FullNumber, "TEL at line 12 has a different value."); // 13 TEL;PAGER:US:14158467093 Assert.IsTrue( card.Phones[2].IsPager, "TEL at line 13 is a pager number."); Assert.AreEqual( "US:14158467093", card.Phones[2].FullNumber, "TEL at line 13 has a different value."); // 14 TEL;FAX:+4112742899 Assert.IsTrue( card.Phones[3].IsFax, "TEL at line 14 is a fax number."); Assert.AreEqual( "+4112742899", card.Phones[3].FullNumber, "TEL at line 14 has a different value."); // 15 TEL:SkypeL gleonhard Assert.AreEqual( "SkypeL gleonhard", card.Phones[4].FullNumber, "TEL at line 15 has a different value."); // Note: The X-PALM custom properties are skipped. // 21 PHOTO;JPEG;BASE64: Assert.AreEqual( 1, card.Photos.Count, "There is a single photo starting at line 21."); Assert.IsTrue( card.Photos[0].IsLoaded, "The photo is embedded and therefore should have been loaded."); // The bitmap is 82x96. // The important thing is demonstrating the ability // to create a bitmap object from data. using (Bitmap bitmap = card.Photos[0].GetBitmap()) { Assert.AreEqual( 82, bitmap.Size.Width, "The width is incorrect."); Assert.AreEqual( 96, bitmap.Size.Height, "The height is incorrect."); } }
private static string Serialize(vCard vcard, Version version) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("BEGIN:VCARD" + Environment.NewLine); stringBuilder.Append("REV:" + DateTime.Now.ToString("yyyyMMddTHHmmssZ") + Environment.NewLine); stringBuilder.Append("N:" + vcard.FamilyName + ";" + vcard.GivenName + ";" + vcard.MiddleName + ";" + vcard.Prefix + ";" + vcard.Suffix + Environment.NewLine); stringBuilder.Append("FN:" + vcard.FormattedName + Environment.NewLine); if (!string.IsNullOrEmpty(vcard.Organization)) { stringBuilder.Append("ORG:" + vcard.Organization + Environment.NewLine); } if (!string.IsNullOrEmpty(vcard.Title)) { stringBuilder.Append("TITLE:" + vcard.Title + Environment.NewLine); } if (!string.IsNullOrEmpty(vcard.Url)) { stringBuilder.Append("URL:" + vcard.Url + Environment.NewLine); } if (!string.IsNullOrEmpty(vcard.NickName)) { stringBuilder.Append("NICKNAME:" + vcard.NickName + Environment.NewLine); } if (!string.IsNullOrEmpty(vcard.Language)) { stringBuilder.Append("LANG:" + vcard.Language + Environment.NewLine); } if (!string.IsNullOrEmpty(vcard.BirthPlace)) { stringBuilder.Append("BIRTHPLACE:" + vcard.BirthPlace + Environment.NewLine); } if (!string.IsNullOrEmpty(vcard.DeathPlace)) { stringBuilder.Append("DEATHPLACE:" + vcard.DeathPlace + Environment.NewLine); } if (!string.IsNullOrEmpty(vcard.TimeZone)) { stringBuilder.Append("TZ:" + vcard.TimeZone + Environment.NewLine); } if (!string.IsNullOrEmpty(vcard.Note)) { stringBuilder.Append("NOTE:" + vcard.Note); } if (!string.IsNullOrEmpty(vcard.XSkypeDisplayName)) { stringBuilder.Append("X-SKYPE-DISPLAYNAME:" + vcard.XSkypeDisplayName + Environment.NewLine); } if (!string.IsNullOrEmpty(vcard.XSkypePstnNumber)) { stringBuilder.Append("X-SKYPE-PSTNNUMBER:" + vcard.XSkypePstnNumber + Environment.NewLine); } stringBuilder.Append("KIND:" + vcard.Kind.ToString().ToUpper() + Environment.NewLine); stringBuilder.Append("GENDER:" + vcard.Gender.ToString().ToUpper() + Environment.NewLine); if (vcard.Geo != null) { stringBuilder.Append("GEO:" + vcard.Geo.Longitude + ";" + vcard.Geo.Latitude); } if (vcard.BirthDay != null) { var birthDay = (DateTime)vcard.BirthDay; stringBuilder.Append("BDAY:" + birthDay.Year + birthDay.Month.ToString("00") + birthDay.Day.ToString("00")); } if (version == Version.V2) { stringBuilder.Append("VERSION:2.1" + Environment.NewLine); stringBuilder.Append(V2Serializer.Serialize(vcard)); } else if (version == Version.V3) { stringBuilder.Append("VERSION:3.0" + Environment.NewLine); stringBuilder.Append(V3Serializer.Serialize(vcard)); } else { stringBuilder.Append("VERSION:4.0" + Environment.NewLine); stringBuilder.Append(V4Serializer.Serialize(vcard)); } stringBuilder.Append(Environment.NewLine); stringBuilder.Append("END:VCARD"); return(stringBuilder.ToString()); }
public void LogEntityExists(WebResourceName entityId, vCard vCard) { _addressesByEntityId[entityId] = vCard.EmailAddresses.Select(a => a.Address).ToArray(); }
/// <summary> /// Updates a vCard object based on the contents of a vCardProperty. /// </summary> /// <param name="card"> /// An initialized vCard object. /// </param> /// <param name="property"> /// An initialized vCardProperty object. /// </param> /// <remarks> /// <para> /// This method examines the contents of a property /// and attempts to update an existing vCard based on /// the property name and value. This function must /// be updated when new vCard properties are implemented. /// </para> /// </remarks> public void ReadInto(vCard card, vCardProperty property) { if (card == null) throw new ArgumentNullException("card"); if (property == null) throw new ArgumentNullException("property"); if (string.IsNullOrEmpty(property.Name)) return; switch (property.Name.ToUpperInvariant()) { case "ADR": ReadInto_ADR(card, property); break; case "BDAY": ReadInto_BDAY(card, property); break; case "CATEGORIES": ReadInto_CATEGORIES(card, property); break; case "CLASS": ReadInto_CLASS(card, property); break; case "EMAIL": ReadInto_EMAIL(card, property); break; case "FN": ReadInto_FN(card, property); break; case "GEO": ReadInto_GEO(card, property); break; case "KEY": ReadInto_KEY(card, property); break; case "LABEL": ReadInto_LABEL(card, property); break; case "MAILER": ReadInto_MAILER(card, property); break; case "N": ReadInto_N(card, property); break; case "NAME": ReadInto_NAME(card, property); break; case "NICKNAME": ReadInto_NICKNAME(card, property); break; case "NOTE": ReadInto_NOTE(card, property); break; case "ORG": ReadInto_ORG(card, property); break; case "PHOTO": ReadInto_PHOTO(card, property); break; case "PRODID": ReadInto_PRODID(card, property); break; case "REV": ReadInto_REV(card, property); break; case "ROLE": ReadInto_ROLE(card, property); break; case "SOURCE": ReadInto_SOURCE(card, property); break; case "TEL": ReadInto_TEL(card, property); break; case "TITLE": ReadInto_TITLE(card, property); break; case "TZ": ReadInto_TZ(card, property); break; case "UID": ReadInto_UID(card, property); break; case "URL": ReadInto_URL(card, property); break; case "X-WAB-GENDER": ReadInto_X_WAB_GENDER(card, property); break; default: // The property name is not recognized and // will be ignored. break; } }
private byte[] GeneratevCard(Person person, string site) { // create the card var vCard = new vCard(); // name information vCard.FamilyName = person.LastName; vCard.GivenName = person.FirstName; vCard.NamePrefix = person.Salutation; // job information vCard.Organization = person.GetLatestRegistration(site).Firm.Name; vCard.Title = person.GetLatestRegistration(site).Title; // picture if (person.MainProfilePicture != null) { vCard.Photos.Add(new vCardPhoto(person.MainProfilePicture)); } // add contact information based on authorization if (person.ContactInformationRelease) { // contact information vCard.EmailAddresses.Add(new vCardEmailAddress(person.User.UserName)); // business address only var busAddr = person.Addresses.Where(a => a.AddressType.Id.ToString() == StaticIndexes.Address_Business).FirstOrDefault(); if (busAddr != null) { var addr = new vCardDeliveryAddress() { AddressType = vCardDeliveryAddressTypes.Work, City = busAddr.City, Country = busAddr.Country.Name, IsWork = true, PostalCode = busAddr.Zip, Street = string.Format("{0} {1}", busAddr.Line1, busAddr.Line2 ?? string.Empty), Region = busAddr.State }; vCard.DeliveryAddresses.Add(addr); } } // prepare the writer to write the vcard output var writer = new vCardStandardWriter(); writer.EmbedInternetImages = false; writer.EmbedLocalImages = true; writer.Options = vCardStandardWriterOptions.IgnoreCommas; // put the data into a memory stream var stream = new MemoryStream(); var streamWriter = new StreamWriter(stream); // write the data to the stream writer.Write(vCard, streamWriter); // write to the memory stream streamWriter.Flush(); streamWriter.Close(); var bytes = stream.ToArray(); return(bytes); }
/// <summary> /// Builds TEL properties. /// </summary> private void BuildProperties_TEL( vCardPropertyCollection properties, vCard card) { // The TEL property indicates a telephone number of // the person (including non-voice numbers like fax // and BBS numbers). // // TEL;VOICE;WORK:1-800-929-5805 foreach (vCardPhone phone in card.Phones) { // A telephone entry has the property name TEL and // can have zero or more subproperties like FAX // or HOME. Examples: // // TEL;HOME:+1-612-555-1212 // TEL;FAX;HOME:+1-612-555-1212 vCardProperty property = new vCardProperty(); property.Name = "TEL"; if (phone.IsBBS) property.Subproperties.Add("BBS"); if (phone.IsCar) property.Subproperties.Add("CAR"); if (phone.IsCellular) property.Subproperties.Add("CELL"); if (phone.IsFax) property.Subproperties.Add("FAX"); if (phone.IsHome) property.Subproperties.Add("HOME"); if (phone.IsISDN) property.Subproperties.Add("ISDN"); if (phone.IsMessagingService) property.Subproperties.Add("MSG"); if (phone.IsModem) property.Subproperties.Add("MODEM"); if (phone.IsPager) property.Subproperties.Add("PAGER"); if (phone.IsPreferred) property.Subproperties.Add("PREF"); if (phone.IsVideo) property.Subproperties.Add("VIDEO"); if (phone.IsVoice) property.Subproperties.Add("VOICE"); if (phone.IsWork) property.Subproperties.Add("WORK"); property.Value = phone.FullNumber; properties.Add(property); } }
public void ParseOutlookSimple() { // 01 BEGIN:VCARD // 02 VERSION:2.1 // 03 N:Pinch;David;John // 04 FN:David John Pinch // 05 NICKNAME:Dave // 06 ORG:Thought Project // 07 TITLE:Dictator // 08 TEL;WORK;VOICE:800-929-5805 // 09 TEL;HOME;VOICE:612-269-6017 // 10 ADR;HOME:;;129 15th Street #3;Minneapolis;MN;55403;United States of America // 11 LABEL;HOME;ENCODING=QUOTED-PRINTABLE:129 15th Street #3=0D=0AMinneapolis, MN 55403=0D=0AUnited States of America // 12 URL;WORK:http://www.thoughtproject.com // 13 EMAIL;PREF;INTERNET:[email protected] // 14 REV:20061130T234000Z // 15 END:VCARD vCard card = new vCard( new StreamReader(new MemoryStream(SampleCards.OutlookSimple))); // 03 N:Pinch;David;John Assert.AreEqual( "Pinch", card.FamilyName, "N at line 3 has a different family name."); Assert.AreEqual( "David", card.GivenName, "N at line 3 has a different given name."); Assert.AreEqual( "John", card.AdditionalNames, "N at line 3 has a different middle name."); // 04 FN:David John Pinch Assert.AreEqual( "David John Pinch", card.FormattedName, "FN at line 4 has a different formatted name."); // 05 NICKNAME:Dave Assert.AreEqual( 1, card.Nicknames.Count, "Exactly one nickname is located at line 5."); Assert.AreEqual( "Dave", card.Nicknames[0], "NICKNAME at line 5 has a different value."); // 06 ORG:Thought Project Assert.AreEqual( "Thought Project", card.Organization, "ORG at line 6 has a different value."); // 07 TITLE:Dictator Assert.AreEqual( "Dictator", card.Title, "TITLE at line 7 has a different value."); // 08 TEL;WORK;VOICE:800-929-5805 // 09 TEL;HOME;VOICE:612-269-6017 Assert.AreEqual( 2, card.Phones.Count, "Two telephone numbers are defined at lines 8 and 9."); Assert.IsTrue( card.Phones[0].IsWork, "TEL at line 8 is a work number."); Assert.IsTrue( card.Phones[0].IsVoice, "TEL at line 8 is a voice number."); Assert.AreEqual( "800-929-5805", card.Phones[0].FullNumber, "TEL at line 8 has a different value."); // 09 TEL;HOME;VOICE:612-269-6017 Assert.IsTrue( card.Phones[1].IsHome, "TEL at line 9 is a home number."); Assert.IsTrue( card.Phones[1].IsVoice, "TEL at line 9 is a voice number."); Assert.AreEqual( "612-269-6017", card.Phones[1].FullNumber, "TEL at line 9 has a different value."); // 10 ADR;HOME:;;129 15th Street #3;Minneapolis;MN;55403;United States of America Assert.AreEqual( 1, card.DeliveryAddresses.Count, "There is one delivery address at line 10."); Assert.AreEqual( "129 15th Street #3", card.DeliveryAddresses[0].Street, "ADR at line 10 has a different street."); Assert.AreEqual( "Minneapolis", card.DeliveryAddresses[0].City, "ADR at line 10 has a different city."); Assert.AreEqual( "MN", card.DeliveryAddresses[0].Region, "ADR at line 10 has a different region/state."); Assert.AreEqual( "55403", card.DeliveryAddresses[0].PostalCode, "ADR at line 10 has a different postal code."); Assert.AreEqual( "United States of America", card.DeliveryAddresses[0].Country, "ADR at line 10 has a different country."); // 11 LABEL;HOME;ENCODING=QUOTED-PRINTABLE:129 15th Street #3=0D=0AMinneapolis, MN 55403=0D=0AUnited States of America Assert.AreEqual( 1, card.DeliveryLabels.Count, "There is one delivery label at line 11."); Assert.IsTrue( card.DeliveryLabels[0].IsHome, "LABEL at line 11 is a home delivery address."); Assert.AreEqual( "129 15th Street #3\r\nMinneapolis, MN 55403\r\nUnited States of America", card.DeliveryLabels[0].Text, "LABEL at line 11 has a different decoded value."); // 12 URL;WORK:http://www.thoughtproject.com Assert.AreEqual( 1, card.Websites.Count, "There is one web site (URL) at line 12."); Assert.IsTrue( card.Websites[0].IsWorkSite, "The web site at line 12 is a work-related web site."); Assert.AreEqual( "http://www.thoughtproject.com", card.Websites[0].Url, "URL at line 12 has a different value."); // 13 EMAIL;PREF;INTERNET:[email protected] Assert.AreEqual( 1, card.EmailAddresses.Count, "There is one email address at line 13."); Assert.IsTrue( card.EmailAddresses[0].IsPreferred, "The email address at line 13 is the preferred email address."); Assert.AreEqual( "*****@*****.**", card.EmailAddresses[0].Address, "EMAIL at line 13 has a different value."); // 14 REV:20061130T234000Z Assert.AreEqual( vCardStandardReader.ParseDate("20061130T234000Z").Value, card.RevisionDate.Value, "REV at line 14 has a different value."); }
private void BuildProperties_X_WAB_GENDER( vCardPropertyCollection properties, vCard card) { // The X-WAB-GENDER property is an extended (custom) // property supported by Microsoft Outlook. switch (card.Gender) { case vCardGender.Female: properties.Add(new vCardProperty("X-WAB-GENDER", "1")); break; case vCardGender.Male: properties.Add(new vCardProperty("X-WAB-GENDER", "2")); break; } }
public void ParseOutlookCertificate() { // 01 BEGIN:VCARD // 02 VERSION:2.1 // 03 N:Pinch;David;John // 04 FN:David John Pinch // 05 NICKNAME:Dave // 06 ORG:Thought Project // 07 TITLE:Dictator // 08 TEL;WORK;VOICE:800-929-5805 // 09 TEL;HOME;VOICE:612-269-6017 // 10 KEY;X509;ENCODING=BASE64: // 11 MIICZDCCAc2gAwIBAgIQRMnJkySZCu8S15WhdyuljjANBgkqhkiG9w0BAQUFADBiMQswCQYD // 12 VQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkgTHRkLjEsMCoGA1UE // 13 AxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3VpbmcgQ0EwHhcNMDcwNTExMTU0NTI2 // 14 WhcNMDgwNTEwMTU0NTI2WjBJMR8wHQYDVQQDExZUaGF3dGUgRnJlZW1haWwgTWVtYmVyMSYw // 15 JAYJKoZIhvcNAQkBFhdkYXZlQHRob3VnaHRwcm9qZWN0LmNvbTCBnzANBgkqhkiG9w0BAQEF // 16 AAOBjQAwgYkCgYEAmLhq0UDsgB8paOBzXCtv9SbwccPYJhJr6f7bK3JO1xkCbKmzoLhCZUVB // 17 4zP5bWTBnQYpolA9t1Pbrd29flX90xizEljCuL2uOz4cFc+NoF7h0h5nFvnFVAmzsJmLnCop // 18 vp0GD4jy3cpQhBNAoSqQbwjSuqyFtHeVMIbNlU3Y/Y8CAwEAAaM0MDIwIgYDVR0RBBswGYEX // 19 ZGF2ZUB0aG91Z2h0cHJvamVjdC5jb20wDAYDVR0TAQH/BAIwADANBgkqhkiG9w0BAQUFAAOB // 20 gQCuMF4mUI5NWv0DqblQH/pqJN0eCjj2j4iQhJNTHtfhrS0ETbakgldJCzg5Rv+8V2Dil7gs // 21 4zMmwOuDrHVBqWDvF0/hXzMn5KKWEmzCZshVyFJ24IWkIj4t3wOMG21NdSA+zX7TEc3s7oWh // 22 zi6q4lcDj3pOzUyDmaEEBYcyWLKXpA== // 23 // 24 // 25 EMAIL;PREF;INTERNET:[email protected] // 26 REV:20070511T163814Z // 27 END:VCARD vCard card = new vCard( new StreamReader(new MemoryStream(SampleCards.OutlookCertificate))); // 03 N:Pinch;David;John Assert.AreEqual( "Pinch", card.FamilyName, "N at line 3 has a different family name."); Assert.AreEqual( "David", card.GivenName, "N at line 3 has a different given name."); Assert.AreEqual( "John", card.AdditionalNames, "N at line 3 has a different middle name."); Assert.AreEqual( 1, card.Certificates.Count, "Only one certificate was expected."); // 04 FN:David John Pinch Assert.AreEqual( "David John Pinch", card.FormattedName, "FN at line 4 has a different formatted name."); // 05 NICKNAME:Dave Assert.AreEqual( 1, card.Nicknames.Count, "Exactly one nickname is located at line 5."); Assert.AreEqual( "Dave", card.Nicknames[0], "NICKNAME at line 5 has a different value."); // 06 ORG:Thought Project Assert.AreEqual( "Thought Project", card.Organization, "ORG at line 6 has a different value."); // 07 TITLE:Dictator Assert.AreEqual( "Dictator", card.Title, "TITLE at line 7 has a different value."); // 08 TEL;WORK;VOICE:800-929-5805 // 09 TEL;HOME;VOICE:612-269-6017 Assert.AreEqual( 2, card.Phones.Count, "Two telephone numbers are defined at lines 8 and 9."); Assert.IsTrue( card.Phones[0].IsWork, "TEL at line 8 is a work number."); Assert.IsTrue( card.Phones[0].IsVoice, "TEL at line 8 is a voice number."); Assert.AreEqual( "800-929-5805", card.Phones[0].FullNumber, "TEL at line 8 has a different value."); // 09 TEL;HOME;VOICE:612-269-6017 Assert.IsTrue( card.Phones[1].IsHome, "TEL at line 9 is a home number."); Assert.IsTrue( card.Phones[1].IsVoice, "TEL at line 9 is a voice number."); Assert.AreEqual( "612-269-6017", card.Phones[1].FullNumber, "TEL at line 9 has a different value."); // 10 KEY;X509;ENCODING=BASE64: Assert.AreEqual( 1, card.Certificates.Count, "There is one certificate starting on line 10."); Assert.AreEqual( "X509", card.Certificates[0].KeyType, "KEY on line 10 has a different key type."); // Create an instance of the certificate. X509Certificate2 cert = new X509Certificate2(card.Certificates[0].Data); Assert.AreEqual( KeyIssuer, cert.Issuer, "The key issuer has a different value."); Assert.AreEqual( KeySubject, cert.Subject, "The key subject has a different value."); }
/// <summary> /// Builds the BDAY property. /// </summary> private void BuildProperties_BDAY( vCardPropertyCollection properties, vCard card) { // The BDAY property indicates the birthdate // of the person. The output format here is based on // Microsoft Outlook, which writes the date as YYYMMDD. if (card.BirthDate.HasValue) { vCardProperty property = new vCardProperty("BDAY", card.BirthDate.Value); properties.Add(property); } }
private void button2_Click(object sender, EventArgs e)//opening vcf file { try { label3Percentage.Text = "0%"; progressBar1.Value = 0; string F = ""; string L = ""; string M = ""; string E = ""; OpenFileDialog op2 = new OpenFileDialog(); op2.Filter = "VCF Files|*.vcf"; if (op2.ShowDialog() == DialogResult.Cancel) { return; } //wrzucam zawartość pliku vcf do stringa: StringBuilder sb = new StringBuilder(); using (StreamReader sr = new StreamReader(op2.FileName)) { String line; while ((line = sr.ReadLine()) != null) { sb.AppendLine(line); } } string allines = sb.ToString(); //tne na kawałki wg stringa "BEGIN:VCARD" i kazwałki te od razu wrzucam do tablicy splitText String[] splitText = allines.Split(new string[] { "BEGIN:VCARD" }, StringSplitOptions.None); ShowProgress(progressBar1, splitText.Length, 0); for (int x = 1; x < splitText.Length; x++) //tu nie od x=0 ponieważ pierwszy element to "Begin:VCARD" - chcę go pominąć { F = ""; L = ""; M = ""; E = ""; pic = null; TextReader input = new StringReader("BEGIN:VCARD" + splitText[x]); //do każdego otrzymanego stringa muszę dokleić "BEGIN:VCARD", bo powyżej split usunął //z każdym elementem listy tworzę obiekt klasy vCard, która wydobędzie z niego dane vCard card = new vCard(input); //niestety biblioteka ta nie zwraca osobno firstname i lastname tylko wszzystko razem - FormattedName if (card.FormattedName != null) { String[] splitText2 = card.FormattedName.Split(new char[] { ' ' }); //pocięcie imie i nazwsko spacjami i wrzucenie do tablicy F = splitText2[0]; //zakładam, że pierwszy element to imię if (splitText2.Length > 1) //jeśli jest więcej elementów niż 1 , to wrzucam je wszystkie do textBox2LastName oddzielając spacją { for (int i = 1; i < splitText2.Length; i++) { L += splitText2[i] + " "; } L = L.Trim();//ucinam ostatnią spację L = L.TrimEnd(); } } else { F = ""; L = ""; } if (card.Phones.GetFirstChoice(vCardPhoneTypes.Cellular) != null) { M = card.Phones.GetFirstChoice(vCardPhoneTypes.Cellular).FullNumber; } else { M = ""; } if (card.EmailAddresses.GetFirstChoice(vCardEmailAddressType.Internet) != null) { E = card.EmailAddresses.GetFirstChoice(vCardEmailAddressType.Internet).Address; } else { E = ""; } if (card.Photos.Count > 0) { pic = card.Photos[0].GetBytes();//do zmiennej typu byte[] wczytuje zdjęcie } //każdy obiekt wrzucam na listę (łącznie ze ewentualnymi zdjęciami, aby potem pokazać w pictureboxie oraz/lub móc dodać do bazy) //byte[] First = Encoding.Default.GetBytes(F); //byte[] Last = Encoding.Default.GetBytes(L); //F = Encoding.UTF8.GetString(First); //F = Encoding.UTF8.GetString(Last); vCardss.Add(new CreateVcard { FirstName = F, LastName = L, Mobile = M, Email = E, Image = pic }); itemsBinding.ResetBindings(false); //odświeżenie wiązań listy ShowProgress(progressBar1, splitText.Length, x + 1); //update progressbara label3Percentage.Text = ShowProgress(progressBar1, splitText.Length, x + 1); } } catch { MessageBox.Show("Invalid file"); } label2.Text = vCardss.Count.ToString(); }
private void BuildProperties_FN( vCardPropertyCollection properties, vCard card) { // The FN property indicates the formatted // name of the person. This can be something // like "John Smith". if (!string.IsNullOrEmpty(card.FormattedName)) { vCardProperty property = new vCardProperty("FN", card.FormattedName); properties.Add(property); } }
private void SavePhone(vCard NewCard, vCard card) { //HomePhone if (NewCard.Phones.GetFirstChoice(vCardPhoneTypes.Home) != null) { if (card.Phones.GetFirstChoice(vCardPhoneTypes.Home) != null) { card.Phones.GetFirstChoice(vCardPhoneTypes.Home).FullNumber = NewCard.Phones.GetFirstChoice(vCardPhoneTypes.Home).FullNumber; } else { card.Phones.Add(new vCardPhone(NewCard.Phones.GetFirstChoice(vCardPhoneTypes.Home).FullNumber, vCardPhoneTypes.Home)); } } else { if (card.Phones.GetFirstChoice(vCardPhoneTypes.Home) != null) { card.Phones.GetFirstChoice(vCardPhoneTypes.Home).FullNumber = string.Empty; } } //Cellular if (NewCard.Phones.GetFirstChoice(vCardPhoneTypes.Cellular) != null) { if (card.Phones.GetFirstChoice(vCardPhoneTypes.Cellular) != null) { card.Phones.GetFirstChoice(vCardPhoneTypes.Cellular).FullNumber = NewCard.Phones.GetFirstChoice(vCardPhoneTypes.Cellular).FullNumber; } else { card.Phones.Add(new vCardPhone(NewCard.Phones.GetFirstChoice(vCardPhoneTypes.Cellular).FullNumber, vCardPhoneTypes.Cellular)); } } else { if (card.Phones.GetFirstChoice(vCardPhoneTypes.Cellular) != null) { card.Phones.GetFirstChoice(vCardPhoneTypes.Cellular).FullNumber = string.Empty; } } //Work if (NewCard.Phones.GetFirstChoice(vCardPhoneTypes.Work) != null) { if (card.Phones.GetFirstChoice(vCardPhoneTypes.Work) != null) { card.Phones.GetFirstChoice(vCardPhoneTypes.Work).FullNumber = NewCard.Phones.GetFirstChoice(vCardPhoneTypes.Work).FullNumber; } else { card.Phones.Add(new vCardPhone(NewCard.Phones.GetFirstChoice(vCardPhoneTypes.Work).FullNumber, vCardPhoneTypes.Work)); } } else { if (card.Phones.GetFirstChoice(vCardPhoneTypes.Work) != null) { card.Phones.GetFirstChoice(vCardPhoneTypes.Work).FullNumber = string.Empty; } } }
/// <summary> /// Builds the MAILER property. /// </summary> private void BuildProperties_MAILER( vCardPropertyCollection properties, vCard card) { // The MAILER property indicates the software that // generated the vCard. See section 2.4.3 of the // vCard 2.1 specification. Support is not widespread. if (!string.IsNullOrEmpty(card.Mailer)) { vCardProperty property = new vCardProperty("MAILER", card.Mailer); properties.Add(property); } }
/// <summary> /// Builds TEL properties. /// </summary> private void BuildProperties_TEL( vCardPropertyCollection properties, vCard card) { // The TEL property indicates a telephone number of // the person (including non-voice numbers like fax // and BBS numbers). // // TEL;VOICE;WORK:1-800-929-5805 foreach (vCardPhone phone in card.Phones) { // A telephone entry has the property name TEL and // can have zero or more subproperties like FAX // or HOME. Examples: // // TEL;HOME:+1-612-555-1212 // TEL;FAX;HOME:+1-612-555-1212 vCardProperty property = new vCardProperty(); property.Name = "TEL"; if (phone.IsBBS) { property.Subproperties.Add("TYPE", "BBS"); } if (phone.IsCar) { property.Subproperties.Add("TYPE", "CAR"); } if (phone.IsCellular) { property.Subproperties.Add("TYPE", "CELL"); } if (phone.IsFax) { if (!phone.IsHome && !phone.IsWork) { property.Subproperties.Add("TYPE", "OTHER"); } property.Subproperties.Add("TYPE", "FAX"); } if (phone.IsHome) { property.Subproperties.Add("TYPE", "HOME"); } if (phone.IsISDN) { property.Subproperties.Add("TYPE", "ISDN"); } if (phone.IsMessagingService) { property.Subproperties.Add("TYPE", "MSG"); } if (phone.IsModem) { property.Subproperties.Add("TYPE", "MODEM"); } if (phone.IsPager) { property.Subproperties.Add("TYPE", "PAGER"); } if (phone.IsPreferred) { property.Subproperties.Add("TYPE", "PREF"); } if (phone.IsVideo) { property.Subproperties.Add("TYPE", "VIDEO"); } if (phone.IsVoice) { if (!phone.IsHome && !phone.IsWork) { property.Subproperties.Add("TYPE", "OTHER"); } property.Subproperties.Add("TYPE", "VOICE"); } if (phone.IsWork) { property.Subproperties.Add("TYPE", "WORK"); } if (phone.IsMain) { property.Subproperties.Add("TYPE", "MAIN"); } property.Value = phone.FullNumber; properties.Add(property); } }
/// <summary> /// Builds the NOTE property. /// </summary> private void BuildProperties_NOTE( vCardPropertyCollection properties, vCard card) { foreach (vCardNote note in card.Notes) { if (!string.IsNullOrEmpty(note.Text)) { vCardProperty property = new vCardProperty(); property.Name = "NOTE"; property.Value = note.Text; if (!string.IsNullOrEmpty(note.Language)) { property.Subproperties.Add("language", note.Language); } property.Subproperties.Add("ENCODING", "QUOTED-PRINTABLE"); properties.Add(property); } } }
// The next set of functions generate raw vCard properties // from an object in the vCard object model. Every method // has a collection (into which new properties should be // placed) and a vCard object (from which the properties // should be generated). #region [ BuildProperties ] /// <summary> /// Builds a collection of standard properties based on /// the specified vCard. /// </summary> /// <returns> /// A <see cref="vCardPropertyCollection"/> that contains all /// properties for the current vCard, including the header /// and footer properties. /// </returns> /// <seealso cref="vCard"/> /// <seealso cref="vCardProperty"/> private vCardPropertyCollection BuildProperties( vCard card) { vCardPropertyCollection properties = new vCardPropertyCollection(); // The BEGIN:VCARD line marks the beginning of // the vCard contents. Later it will end with END:VCARD. // See section 2.1.1 of RFC 2426. properties.Add(new vCardProperty("BEGIN", "VCARD")); properties.Add(new vCardProperty("VERSION", "3.0")); BuildProperties_NAME( properties, card); BuildProperties_SOURCE( properties, card); BuildProperties_N( properties, card); BuildProperties_FN( properties, card); BuildProperties_ADR( properties, card); BuildProperties_BDAY( properties, card); BuildProperties_CATEGORIES( properties, card); BuildProperties_CLASS( properties, card); BuildProperties_EMAIL( properties, card); BuildProperties_GEO( properties, card); BuildProperties_KEY( properties, card); BuildProperties_LABEL( properties, card); BuildProperties_MAILER( properties, card); BuildProperties_NICKNAME( properties, card); BuildProperties_NOTE( properties, card); BuildProperties_ORG( properties, card); BuildProperties_PHOTO( properties, card); BuildProperties_PRODID( properties, card); BuildProperties_REV( properties, card); BuildProperties_ROLE( properties, card); BuildProperties_TEL( properties, card); BuildProperties_TITLE( properties, card); BuildProperties_TZ( properties, card); BuildProperties_UID( properties, card); BuildProperties_URL( properties, card); BuildProperties_X_WAB_GENDER( properties, card); BuildProperties_IMPP( properties, card); // The end of the vCard is marked with an END:VCARD. properties.Add(new vCardProperty("END", "VCARD")); return(properties); }
/// <summary> /// Builds the REV property. /// </summary> private void BuildProperties_REV( vCardPropertyCollection properties, vCard card) { if (card.RevisionDate.HasValue) { vCardProperty property = new vCardProperty("REV", card.RevisionDate.Value.ToString()); properties.Add(property); } }
/// <summary> /// Builds ADR properties. /// </summary> private void BuildProperties_ADR( vCardPropertyCollection properties, vCard card) { foreach (vCardDeliveryAddress address in card.DeliveryAddresses) { // Do not generate a postal address (ADR) property // if the entire address is blank. if ( (!string.IsNullOrEmpty(address.City)) || (!string.IsNullOrEmpty(address.Country)) || (!string.IsNullOrEmpty(address.PostalCode)) || (!string.IsNullOrEmpty(address.Region)) || (!string.IsNullOrEmpty(address.Street))) { // The ADR property contains the following // subvalues in order. All are required: // // - Post office box // - Extended address // - Street address // - Locality (e.g. city) // - Region (e.g. province or state) // - Postal code (e.g. ZIP code) // - Country name vCardValueCollection values = new vCardValueCollection(';'); values.Add(string.Empty); values.Add(string.Empty); values.Add(!string.IsNullOrEmpty(address.Street) ? address.Street.Replace("\r\n", "\n") : string.Empty); values.Add(address.City); values.Add(address.Region); values.Add(address.PostalCode); values.Add(address.Country); vCardProperty property = new vCardProperty("ADR", values); if (address.IsDomestic) { property.Subproperties.Add("TYPE", "DOM"); } if (address.IsInternational) { property.Subproperties.Add("TYPE", "INTL"); } if (address.IsParcel) { property.Subproperties.Add("TYPE", "PARCEL"); } if (address.IsPostal) { property.Subproperties.Add("TYPE", "POSTAL"); } if (address.IsHome) { property.Subproperties.Add("TYPE", "HOME"); } if (address.IsWork) { property.Subproperties.Add("TYPE", "WORK"); } properties.Add(property); } } }
/// <summary> /// Reads a vCard (VCF) file from an input stream. /// </summary> /// <param name="card"> /// An initialized vCard. /// </param> /// <param name="reader"> /// A text reader pointing to the beginning of /// a standard vCard file. /// </param> /// <returns> /// The vCard with values updated from the file. /// </returns> public override void ReadInto(vCard card, TextReader reader) { vCardProperty property; do { property = ReadProperty(reader); if (property != null) { if ( (string.Compare("END", property.Name, StringComparison.OrdinalIgnoreCase) == 0) && (string.Compare("VCARD", property.ToString(), StringComparison.OrdinalIgnoreCase) == 0)) { // This is a special type of property that marks // the last property of the vCard. break; } else { ReadInto(card, property); } } } while (property != null); }
/// <summary> /// Builds EMAIL properties. /// </summary> private void BuildProperties_EMAIL( vCardPropertyCollection properties, vCard card) { // The EMAIL property contains an electronic // mail address for the purpose. A vCard may contain // as many email addresses as needed. The format also // supports various vendors, such as CompuServe addresses // and Internet SMTP addresses. // // EMAIL;INTERNET:[email protected] foreach (vCardEmailAddress emailAddress in card.EmailAddresses) { vCardProperty property = new vCardProperty(); property.Name = "EMAIL"; property.Value = emailAddress.Address; if (emailAddress.IsPreferred) { property.Subproperties.Add("TYPE", "PREF"); } switch (emailAddress.EmailType) { case vCardEmailAddressType.Internet: property.Subproperties.Add("TYPE", "INTERNET"); break; case vCardEmailAddressType.AOL: property.Subproperties.Add("TYPE", "AOL"); break; case vCardEmailAddressType.AppleLink: property.Subproperties.Add("TYPE", "AppleLink"); break; case vCardEmailAddressType.AttMail: property.Subproperties.Add("TYPE", "ATTMail"); break; case vCardEmailAddressType.CompuServe: property.Subproperties.Add("TYPE", "CIS"); break; case vCardEmailAddressType.eWorld: property.Subproperties.Add("TYPE", "eWorld"); break; case vCardEmailAddressType.IBMMail: property.Subproperties.Add("TYPE", "IBMMail"); break; case vCardEmailAddressType.MCIMail: property.Subproperties.Add("TYPE", "MCIMail"); break; case vCardEmailAddressType.PowerShare: property.Subproperties.Add("TYPE", "POWERSHARE"); break; case vCardEmailAddressType.Prodigy: property.Subproperties.Add("TYPE", "PRODIGY"); break; case vCardEmailAddressType.Telex: property.Subproperties.Add("TYPE", "TLX"); break; case vCardEmailAddressType.X400: property.Subproperties.Add("TYPE", "X400"); break; default: property.Subproperties.Add("TYPE", "INTERNET"); break; } switch (emailAddress.ItemType) { case ItemType.HOME: property.Subproperties.Add("TYPE", "HOME"); break; case ItemType.WORK: property.Subproperties.Add("TYPE", "WORK"); break; } properties.Add(property); } }
/// <summary> /// Builds SOURCE properties. /// </summary> private void BuildProperties_SOURCE( vCardPropertyCollection properties, vCard card) { foreach (vCardSource source in card.Sources) { vCardProperty property = new vCardProperty(); property.Name = "SOURCE"; property.Value = source.Uri.ToString(); if (!string.IsNullOrEmpty(source.Context)) property.Subproperties.Add("CONTEXT", source.Context); properties.Add(property); } }
private void BuildProperties_PHOTO( vCardPropertyCollection properties, vCard card) { foreach (vCardPhoto photo in card.Photos) { if (photo.Url == null) { // This photo does not have a URL associated // with it. Therefore a property can be // generated only if the image data is loaded. // Otherwise there is not enough information. if (photo.IsLoaded) { var property = new vCardProperty("PHOTO", photo.GetBytes()); property.Subproperties.Add("TYPE", "JPEG"); properties.Add(property); } } else { // This photo has a URL associated with it. The // PHOTO property can either be linked as an image // or embedded, if desired. bool doEmbedded = photo.Url.IsFile ? this.embedLocalImages : this.embedInternetImages; if (doEmbedded) { // According to the settings of the card writer, // this linked image should be embedded into the // vCard data. Attempt to fetch the data. try { photo.Fetch(); } catch { // An error was encountered. The image can // still be written as a link, however. doEmbedded = false; } } // At this point, doEmbedded is true only if (a) the // writer was configured to embed the image, and (b) // the image was successfully downloaded. if (doEmbedded) { properties.Add( new vCardProperty("PHOTO", photo.GetBytes())); } else { vCardProperty uriPhotoProperty = new vCardProperty("PHOTO"); // Set the VALUE property to indicate that // the data for the photo is a URI. uriPhotoProperty.Subproperties.Add("VALUE", "URI"); uriPhotoProperty.Value = photo.Url.ToString(); properties.Add(uriPhotoProperty); } } } }
private void BuildProperties_TITLE( vCardPropertyCollection properties, vCard card) { // The TITLE property specifies the job title of // the person. Example: // // TITLE:Systems Analyst // TITLE:President if (!string.IsNullOrEmpty(card.Title)) { vCardProperty property = new vCardProperty("TITLE", card.Title); properties.Add(property); } }
public void Cleanup(vCard entity) { _decorated.Cleanup(entity); }
private void BuildProperties_URL( vCardPropertyCollection properties, vCard card) { foreach (vCardWebsite webSite in card.Websites) { if (!string.IsNullOrEmpty(webSite.Url)) { vCardProperty property = new vCardProperty("URL", webSite.Url.ToString()); if (webSite.IsWorkSite) property.Subproperties.Add("WORK"); properties.Add(property); } } }
public Task <EntityVersion <WebResourceName, string> > TryUpdate(WebResourceName entityId, string version, vCard entityToUpdate, Func <vCard, Task <vCard> > entityModifier, TContext context) { return(_decorated.TryUpdate(entityId, version, entityToUpdate, entityModifier, context)); }
// The next set of functions generate raw vCard properties // from an object in the vCard object model. Every method // has a collection (into which new properties should be // placed) and a vCard object (from which the properties // should be generated). #region [ BuildProperties ] /// <summary> /// Builds a collection of standard properties based on /// the specified vCard. /// </summary> /// <returns> /// A <see cref="vCardPropertyCollection"/> that contains all /// properties for the current vCard, including the header /// and footer properties. /// </returns> /// <seealso cref="vCard"/> /// <seealso cref="vCardProperty"/> private vCardPropertyCollection BuildProperties( vCard card) { vCardPropertyCollection properties = new vCardPropertyCollection(); // The BEGIN:VCARD line marks the beginning of // the vCard contents. Later it will end with END:VCARD. // See section 2.1.1 of RFC 2426. properties.Add(new vCardProperty("BEGIN", "VCARD")); BuildProperties_NAME( properties, card); BuildProperties_SOURCE( properties, card); BuildProperties_N( properties, card); BuildProperties_FN( properties, card); BuildProperties_ADR( properties, card); BuildProperties_BDAY( properties, card); BuildProperties_CATEGORIES( properties, card); BuildProperties_CLASS( properties, card); BuildProperties_EMAIL( properties, card); BuildProperties_GEO( properties, card); BuildProperties_KEY( properties, card); BuildProperties_LABEL( properties, card); BuildProperties_MAILER( properties, card); BuildProperties_NICKNAME( properties, card); BuildProperties_NOTE( properties, card); BuildProperties_ORG( properties, card); BuildProperties_PHOTO( properties, card); BuildProperties_PRODID( properties, card); BuildProperties_REV( properties, card); BuildProperties_ROLE( properties, card); BuildProperties_TEL( properties, card); BuildProperties_TITLE( properties, card); BuildProperties_TZ( properties, card); BuildProperties_UID( properties, card); BuildProperties_URL( properties, card); BuildProperties_X_WAB_GENDER( properties, card); // The end of the vCard is marked with an END:VCARD. properties.Add(new vCardProperty("END", "VCARD")); return properties; }
/// <summary> /// Method to export contacts to remote uri. Generates the /// xml format for the contacts and provides that to the /// method used to generate the POST request. /// </summary> /// <param name="uri">string</param> /// <param name="cred">VATRPCredential</param> /// <returns>void</returns> private async Task ExecuteRemoteExport(string uri, VATRPCredential cred) { var cardWriter = new vCardWriter(); this.MyContacts = new ContactList(); this.MyContacts.VCards = new List <vCard>(); foreach (var contactVM in this.Contacts) { var card = new vCard() { GivenName = contactVM.Contact.Fullname, FormattedName = contactVM.Contact.Fullname, Title = contactVM.Contact.RegistrationName }; card.Telephone.Uri = contactVM.Contact.RegistrationName; this.MyContacts.VCards.Add(card); } // Add the namespaces XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance"); ns.Add("xsd", "http://www.w3.org/2001/XMLSchema"); this.MyContacts.Namespaces = ns; // Serialize contacts into xml string if (this.MyContacts.VCards != null) { XmlAttributes atts = new XmlAttributes(); atts.Xmlns = true; XmlAttributeOverrides xover = new XmlAttributeOverrides(); xover.Add(typeof(List <vCard>), "Namespaces", atts); XmlSerializer xsSubmit = new XmlSerializer(typeof(List <vCard>), xover); var xml = ""; //XmlWriterSettings settings = new XmlWriterSettings(); //settings.OmitXmlDeclaration = true; // is this necessary? using (var sww = new StringWriter()) { using (XmlWriter writer = XmlWriter.Create(sww)) { xsSubmit.Serialize(writer, this.MyContacts.VCards); xml = sww.ToString(); // the final xml output xml = xml.Replace("ArrayOfVcard", "vcards"); // replace incorrect tag with correct one xml = xml.Replace("utf-16", "utf-8"); // TODO - fix this with formatting } } try { await JsonWebRequest.MakeXmlWebPostAuthenticatedAsync(uri, cred, xml); } catch (JsonException ex) { Debug.WriteLine($"ERROR -- Failed to POST contacts to {uri}."); } } }
/// <summary> /// Builds ADR properties. /// </summary> private void BuildProperties_ADR( vCardPropertyCollection properties, vCard card) { foreach (vCardDeliveryAddress address in card.DeliveryAddresses) { // Do not generate a postal address (ADR) property // if the entire address is blank. if ( (!string.IsNullOrEmpty(address.City)) || (!string.IsNullOrEmpty(address.Country)) || (!string.IsNullOrEmpty(address.PostalCode)) || (!string.IsNullOrEmpty(address.Region)) || (!string.IsNullOrEmpty(address.Street))) { // The ADR property contains the following // subvalues in order. All are required: // // - Post office box // - Extended address // - Street address // - Locality (e.g. city) // - Region (e.g. province or state) // - Postal code (e.g. ZIP code) // - Country name vCardValueCollection values = new vCardValueCollection(';'); values.Add(string.Empty); values.Add(string.Empty); values.Add(address.Street); values.Add(address.City); values.Add(address.Region); values.Add(address.PostalCode); values.Add(address.Country); vCardProperty property = new vCardProperty("ADR", values); if (address.IsDomestic) property.Subproperties.Add("DOM"); if (address.IsInternational) property.Subproperties.Add("INTL"); if (address.IsParcel) property.Subproperties.Add("PARCEL"); if (address.IsPostal) property.Subproperties.Add("POSTAL"); if (address.IsHome) property.Subproperties.Add("HOME"); if (address.IsWork) property.Subproperties.Add("WORK"); properties.Add(property); } } }
protected override void SetUid(vCard entity, string uid) { entity.UniqueId = uid; }
private void BuildProperties_CATEGORIES( vCardPropertyCollection properties, vCard card) { if (card.Categories.Count > 0) { vCardValueCollection values = new vCardValueCollection(','); foreach (string category in card.Categories) { if (!string.IsNullOrEmpty(category)) values.Add(category); } properties.Add( new vCardProperty("CATEGORIES", values)); } }
protected override string GetUid(vCard entity) { return(entity.UniqueId); }
/// <summary> /// Builds EMAIL properties. /// </summary> private void BuildProperties_EMAIL( vCardPropertyCollection properties, vCard card) { // The EMAIL property contains an electronic // mail address for the purpose. A vCard may contain // as many email addresses as needed. The format also // supports various vendors, such as CompuServe addresses // and Internet SMTP addresses. // // EMAIL;INTERNET:[email protected] foreach (vCardEmailAddress emailAddress in card.EmailAddresses) { vCardProperty property = new vCardProperty(); property.Name = "EMAIL"; property.Value = emailAddress.Address; if (emailAddress.IsPreferred) { property.Subproperties.Add("PREF"); } switch (emailAddress.EmailType) { case vCardEmailAddressType.Internet: property.Subproperties.Add("INTERNET"); break; case vCardEmailAddressType.AOL: property.Subproperties.Add("AOL"); break; case vCardEmailAddressType.AppleLink: property.Subproperties.Add("AppleLink"); break; case vCardEmailAddressType.AttMail: property.Subproperties.Add("ATTMail"); break; case vCardEmailAddressType.CompuServe: property.Subproperties.Add("CIS"); break; case vCardEmailAddressType.eWorld: property.Subproperties.Add("eWorld"); break; case vCardEmailAddressType.IBMMail: property.Subproperties.Add("IBMMail"); break; case vCardEmailAddressType.MCIMail: property.Subproperties.Add("MCIMail"); break; case vCardEmailAddressType.PowerShare: property.Subproperties.Add("POWERSHARE"); break; case vCardEmailAddressType.Prodigy: property.Subproperties.Add("PRODIGY"); break; case vCardEmailAddressType.Telex: property.Subproperties.Add("TLX"); break; case vCardEmailAddressType.X400: property.Subproperties.Add("X400"); break; default: property.Subproperties.Add("INTERNET"); break; } properties.Add(property); } }
private void saveAsButton_Click(object sender, EventArgs e) { DialogResult result = this.savevCardDialog.ShowDialog(); if (result == DialogResult.OK) { try { vCard card = new vCard(); card.Name.GivenName = this.firstNameTextbox.Text; card.Name.FamilyName = this.lastNameTextbox.Text; if (this.companyTextbox.Text != string.Empty) { card.Organization.Add(this.companyTextbox.Text); } if (this.officePhoneTextbox.Text != string.Empty) { card.TelephoneNumbers.Add(this.officePhoneTextbox.Text, TelephoneNumberSingleType.Work); } if (this.homePhoneTextbox.Text != string.Empty) { card.TelephoneNumbers.Add(this.homePhoneTextbox.Text, TelephoneNumberSingleType.Home); } if (this.mobilePhoneTextbox.Text != string.Empty) { card.TelephoneNumbers.Add(this.mobilePhoneTextbox.Text, TelephoneNumberSingleType.Cellular); } if (this.emailTextbox.Text != string.Empty) { card.EmailAddresses.Add(this.emailTextbox.Text); } if (this.birthdayDatePicker.Value != DateTime.Now) { card.Birthday = this.birthdayDatePicker.Value; } if (this.photoPictureBox.Image != null) { Image image = this.photoPictureBox.Image; MemoryStream stream = new MemoryStream(); image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); card.Photo = stream.ToArray(); } card.SaveToFile(this.savevCardDialog.FileName); MessageBox.Show(string.Format("The file {0} was saved successfully.", Path.GetFileName(this.savevCardDialog.FileName))); } catch (Exception ex) { MessageBox.Show("Error while trying to save the vCard file."); } } }
/// <summary> /// Builds the GEO property. /// </summary> private void BuildProperties_GEO( vCardPropertyCollection properties, vCard card) { // The GEO properties contains the latitude and // longitude of the person or company of the vCard. if (card.Latitude.HasValue && card.Longitude.HasValue) { vCardProperty property = new vCardProperty(); property.Name = "GEO"; property.Value = card.Latitude.ToString() + ";" + card.Longitude.ToString(); properties.Add(property); } }
/// <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); }
private void BuildProperties_LABEL( vCardPropertyCollection properties, vCard card) { foreach (vCardDeliveryLabel label in card.DeliveryLabels) { if (label.Text.Length > 0) { vCardProperty property = new vCardProperty("LABEL", label.Text); if (label.IsDomestic) property.Subproperties.Add("DOM"); if (label.IsInternational) property.Subproperties.Add("INTL"); if (label.IsParcel) property.Subproperties.Add("PARCEL"); if (label.IsPostal) property.Subproperties.Add("POSTAL"); if (label.IsHome) property.Subproperties.Add("HOME"); if (label.IsWork) property.Subproperties.Add("WORK"); // Give a hint to use QUOTED-PRINTABLE. property.Subproperties.Add("ENCODING", "QUOTED-PRINTABLE"); properties.Add(property); } } }
// The following functions export a vCard and then re-read it back // as a new vCard. All fields and collections are compared to ensure // the full fidelity of the export/import process. #region [ CycleStandard ] public static void CycleStandard(vCard card) { CycleStandard21(card); }
private void BuildProperties_N( vCardPropertyCollection properties, vCard card) { // The property has the following components: Family Name, // Given Name, Additional Names, Name Prefix, and Name // Suffix. Example: // // N:Pinch;David // N:Pinch;David;John // // The N property is required (see section 3.1.2 of RFC 2426). vCardValueCollection values = new vCardValueCollection(';'); values.Add(card.FamilyName); values.Add(card.GivenName); values.Add(card.AdditionalNames); values.Add(card.NamePrefix); values.Add(card.NameSuffix); vCardProperty property = new vCardProperty("N", values); properties.Add(property); }
// The following functions compare two vCard-related objects. #region [ Equals(vCard) ] public static void Equals(vCard c1, vCard c2) { // Start by comparing the base fields. Assert.AreEqual( c1.AdditionalNames, c2.AdditionalNames, "AdditionalNames does not match."); Assert.AreEqual( c1.BirthDate, c2.BirthDate, "BirthDate does not match."); Assert.AreEqual( c1.DisplayName, c2.DisplayName, "DisplayName does not match."); Assert.AreEqual( c1.FamilyName, c2.FamilyName, "FamilyName does not match."); Assert.AreEqual( c1.FormattedName, c2.FormattedName, "FormattedName does not match."); Assert.AreEqual( c1.Gender, c2.Gender, "Gender does not match."); Assert.AreEqual( c1.GivenName, c2.GivenName, "GivenName does not match."); Assert.AreEqual( c1.Mailer, c2.Mailer, "Mailer does not match."); Assert.AreEqual( c1.NamePrefix, c2.NamePrefix, "NamePrefix does not match."); Assert.AreEqual( c1.NameSuffix, c2.NameSuffix, "NameSuffix does not match."); Assert.AreEqual( c1.Organization, c2.Organization, "Organization does not match."); Assert.AreEqual( c1.ProductId, c2.ProductId, "ProductId does not match."); Assert.AreEqual( c1.RevisionDate, c2.RevisionDate, "RevisionDate does not match."); Assert.AreEqual( c1.Role, c2.Role, "Role does not match."); Assert.AreEqual( c1.TimeZone, c2.TimeZone, "TimeZone does not match."); Assert.AreEqual( c1.Title, c2.Title, "Title does not match."); Assert.AreEqual( c1.ToString(), c2.ToString(), "ToString() does not match."); Assert.AreEqual( c1.UniqueId, c2.UniqueId, "UniqueId does not match."); // Compare collections Equals( c1.Categories, c2.Categories); Equals( c1.DeliveryAddresses, c2.DeliveryAddresses); Equals( c1.DeliveryLabels, c2.DeliveryLabels); Equals( c1.EmailAddresses, c2.EmailAddresses); Equals( c1.Nicknames, c2.Nicknames); Equals( c1.Notes, c2.Notes); Equals( c1.Phones, c2.Phones); Equals( c1.Photos, c2.Photos); Equals( c1.Sources, c2.Sources); Equals( c1.Websites, c2.Websites); }
/// <summary> /// Builds the NICKNAME property. /// </summary> private void BuildProperties_NICKNAME( vCardPropertyCollection properties, vCard card) { // The NICKNAME property specifies the familiar name // of the person, such as Jim. This is defined in // section 3.1.3 of RFC 2426. Multiple names can // be listed, separated by commas. if (card.Nicknames.Count > 0) { // A NICKNAME property is a comma-separated // list of values. Create a value list and // add the nicknames collection to it. vCardValueCollection values = new vCardValueCollection(','); values.Add(card.Nicknames); // Create the new properties with each name separated // by a comma. vCardProperty property = new vCardProperty("NICKNAME", values); properties.Add(property); } }
public void ParseOutlook2007() { // 01: BEGIN:VCARD // 02: VERSION:2.1 // 03: N;LANGUAGE=en-us:Pinch;David;John;Mr. // 04: FN:Mr. David John Pinch // 05: NICKNAME:Dave // 06: ORG:Thought Project // 07: TITLE:Dictator // 08: NOTE:Generated with Outlook 2007. // 09: TEL;WORK;VOICE:800-929-5805 // 10: TEL;HOME;VOICE:612-269-6017 // 11: TEL;CELL;VOICE:612-269-6017 // 12: ADR;WORK:;;;;;;United States of America // 13: ADR;HOME;PREF:;;3247 Upton Avenue N,;Minneapolis;MN;55412;United States of America // 14: LABEL;HOME;PREF;ENCODING=QUOTED-PRINTABLE:3247 Upton Avenue N,=0D=0A= // 15: Minneapolis, MN 55412 // 16: X-MS-OL-DEFAULT-POSTAL-ADDRESS:1 // 17: X-WAB-GENDER:2 // 18: URL;WORK:http://www.thoughtproject.com // 19: ROLE:Programmer // 20: BDAY:20090414 // 21: KEY;X509;ENCODING=BASE64: // 22: MIICZDCCAc2gAwIBAgIQRMnJkySZCu8S15WhdyuljjANBgkqhkiG9w0BAQUFADBiMQswCQYD // 23: VQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkgTHRkLjEsMCoGA1UE // 24: AxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3VpbmcgQ0EwHhcNMDcwNTExMTU0NTI2 // 25: WhcNMDgwNTEwMTU0NTI2WjBJMR8wHQYDVQQDExZUaGF3dGUgRnJlZW1haWwgTWVtYmVyMSYw // 26: JAYJKoZIhvcNAQkBFhdkYXZlQHRob3VnaHRwcm9qZWN0LmNvbTCBnzANBgkqhkiG9w0BAQEF // 27: AAOBjQAwgYkCgYEAmLhq0UDsgB8paOBzXCtv9SbwccPYJhJr6f7bK3JO1xkCbKmzoLhCZUVB // 28: 4zP5bWTBnQYpolA9t1Pbrd29flX90xizEljCuL2uOz4cFc+NoF7h0h5nFvnFVAmzsJmLnCop // 29: vp0GD4jy3cpQhBNAoSqQbwjSuqyFtHeVMIbNlU3Y/Y8CAwEAAaM0MDIwIgYDVR0RBBswGYEX // 30: ZGF2ZUB0aG91Z2h0cHJvamVjdC5jb20wDAYDVR0TAQH/BAIwADANBgkqhkiG9w0BAQUFAAOB // 31: gQCuMF4mUI5NWv0DqblQH/pqJN0eCjj2j4iQhJNTHtfhrS0ETbakgldJCzg5Rv+8V2Dil7gs // 32: 4zMmwOuDrHVBqWDvF0/hXzMn5KKWEmzCZshVyFJ24IWkIj4t3wOMG21NdSA+zX7TEc3s7oWh // 33: zi6q4lcDj3pOzUyDmaEEBYcyWLKXpA== // 34: // 35: EMAIL;PREF;INTERNET:[email protected] // 36: X-MS-IMADDRESS:[email protected] // 37: PHOTO;TYPE=JPEG;ENCODING=BASE64: // 38: /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQY // 39: GBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYa // 40: KCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAAR // 41: CAA3AEgDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAA // 42: AgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkK // 43: FhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWG // 44: h4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl // 45: 5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREA // 46: AgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYk // 47: NOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOE // 48: hYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk // 49: 5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwC3KUf7wwaiFvuPDDHrVh0yaiMeWrarK2pw // 50: wi2KLeFfvuD9KiuY4SmI1JPris3xHq0ek2jGMq1zjcseCeB3OK4+HxZdy3DPcXKwRkbVVEHX // 51: 8a5f3k1dLQ6Y0ktzt4oBGc7efellkYDl1UflXAf23Pf+dbC/lSR8iOTdgA9gccVys012929t // 52: ctdyXCttZM96hU5vRs29nHqes3FzbqhaW6jwOD84pkSxzwiWE70PQiuJsYksIrYXcjiSWQKk // 53: PmEjJOOnSu58ORMbFgfugjH1wM05R5epnKNitNbjHIorUnh5orRSdjFm6RzUNyTHDI64DAEj // 54: NWShzXK/EKa4h0lI4Nw81yGYdgAa6KkeZ2FRTbsjm3uhe6m6wjzmZtssj8nnPT2r0bwl8PbX // 55: WkQTJkOcMw4K1434SWeS5crkhWz9TXtWjeNL62RUsbEKYQPnKnBx159awrNqVketQgoxba1J // 56: L/4GPFqUklpKGhjG4Ajlq8o8Z6i+m6rLDYpCXVArMUyQfTNfTcPxBYaJb382nSyGWQxbIsn5 // 57: sZ544FfKPjW6sLjxNqrQvIiPcu+NucZOcfhVRSlruYT9ptJWK/hQf2lrol1OR55kUvCB8qof // 58: p3r1bw8mLGQej4/QV5n4Njt/7Zi8mV3cI2QVx2+tepaAP9Fn/wCup/kKjEJKyRzu9ncS5XBo // 59: pNUYxwyMvUDiiiEbo53ubgIrN8QQefp8oVBIVG7Yeje1Le38VlA007YRRn3P0rzjVviBfS3c // 60: kNrEkEe7ardWx/Ku2VCc37oUW07ot6FaLaSQ3ESnyZTnawwV7YNev6Jqun2nhq6eWKBJVjOD // 61: gDJxXik+tui20wybdkCvj+Fh1qGXUDrV59ne5ZbZV+VVPDH3FctWk+bU9mnW5Vdnufwq8S6X // 62: cm6tbqeNwxDqG6bhnp74r5d8R3sVzr+oz2/+rluJHQexY4r0AJpunaN9os3PmF9nQjBxya8+ // 63: uNEfzA0dxEQ3IzxWtKHIr9DKtUU5PubnwzzLr7Z52wk/yFev6EmLSf8A66n+Qryz4c2Mmn6p // 64: cTXDJtaMKCpz1I/wr1bQmBs5COhkJrLEatHFOVmylrp227+/FFQeIXOFUHqaK0pR905Wzh9Z // 65: 1P8AtdWmZiVUYxyB9MVw2ptJDqLM2MqR09+9FFe7XSVNWN6as7HU+CZI7u9u7C5BZJcSLnse // 66: 9dLF8OWursHS7sQSMeFcZX/61FFeRXk4zdjqi/dOWuGkhlnspHDCCZ4zjoSDg4/nV/wJNC+t // 67: xW91Ek0UoZGV1yMjoR+VFFdc4r2TXkYSep2euafZ6ftlsrdY95+YLxnFa+iOY9MUHqSTRRXl // 68: PWKMZtsyNal3Tge1FFFdtKK5UZM//9k= // 69: // 70: X-MS-OL-DESIGN;CHARSET=utf-8:<card xmlns="http://schemas.microsoft.com/office/outlook/12/electronicbusinesscards" ver="1.0" layout="left" bgcolor="ffffff"><img xmlns="" align="tleft" area="32" use="photo"/><fld xmlns="" prop="name" align="left" dir="ltr" style="b" color="000000" size="10"/><fld xmlns="" prop="org" align="left" dir="ltr" color="000000" size="8"/><fld xmlns="" prop="title" align="left" dir="ltr" color="000000" size="8"/><fld xmlns="" prop="telwork" align="left" dir="ltr" color="000000" size="8"><label align="right" color="626262">Work</label></fld><fld xmlns="" prop="telcell" align="left" dir="ltr" color="000000" size="8"><label align="right" color="626262">Mobile</label></fld><fld xmlns="" prop="telhome" align="left" dir="ltr" color="000000" size="8"><label align="right" color="626262">Home</label></fld><fld xmlns="" prop="email" align="left" dir="ltr" color="000000" size="8"/><fld xmlns="" prop="addrhome" align="left" dir="ltr" color="000000" size="8"/><fld xmlns="" prop="webwork" align="left" dir="ltr" color="000000" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/></card> // 71: REV:20090825T194011Z // 72: END:VCARD vCard card = new vCard( new StreamReader(new MemoryStream(SampleCards.Outlook2007))); // 03: N:Pinch;David;John Assert.AreEqual( "Pinch", card.FamilyName, "N at line 3 has a different family name."); Assert.AreEqual( "David", card.GivenName, "N at line 3 has a different given name."); Assert.AreEqual( "John", card.AdditionalNames, "N at line 3 has a different middle name."); // 04: FN:Mr. David John Pinch Assert.AreEqual( "Mr. David John Pinch", card.FormattedName, "FN at line 4 has a different formatted name."); // 05: NICKNAME:Dave Assert.AreEqual( 1, card.Nicknames.Count, "Exactly one nickname is located at line 5."); Assert.AreEqual( "Dave", card.Nicknames[0], "NICKNAME at line 5 has a different value."); // 06: ORG:Thought Project Assert.AreEqual( "Thought Project", card.Organization, "ORG at line 6 has a different value."); // 07: TITLE:Dictator Assert.AreEqual( "Dictator", card.Title, "TITLE at line 7 has a different value."); // 08: NOTE:Generated with Outlook 2007. Assert.AreEqual( 1, card.Notes.Count, "Only one note should be in the card."); Assert.AreEqual( "Generated with Outlook 2007.", card.Notes[0].Text, "NOTE at line 8 has a different value."); // 09: TEL;WORK;VOICE:800-929-5805 Assert.AreEqual( 3, card.Phones.Count, "Three phone numbers should have been loaded."); Assert.AreEqual( "800-929-5805", card.Phones[0].FullNumber, "TEL at line 9 has the wrong phone number."); Assert.AreEqual( vCardPhoneTypes.WorkVoice, card.Phones[0].PhoneType, "TEL at line 9 has the wrong phone types."); // 10: TEL;HOME;VOICE:612-269-6017 Assert.AreEqual( "612-269-6017", card.Phones[1].FullNumber, "TEL at line 10 has the wrong phone number."); Assert.AreEqual( vCardPhoneTypes.HomeVoice, card.Phones[1].PhoneType, "TEL at line 10 has the wrong phone types."); // 11: TEL;CELL;VOICE:612-269-6017 Assert.AreEqual( "612-269-6017", card.Phones[2].FullNumber, "TEL at line 11 has the wrong phone number."); Assert.AreEqual( vCardPhoneTypes.CellularVoice, card.Phones[2].PhoneType, "TEL at line 11 has the wrong phone types."); // 12: ADR;WORK:;;;;;;United States of America Assert.AreEqual( 2, card.DeliveryAddresses.Count, "Two delivery addresses should be defined."); Assert.AreEqual( vCardDeliveryAddressTypes.Work, card.DeliveryAddresses[0].AddressType, "ADR on line 12 has the wrong address type."); Assert.AreEqual( string.Empty, card.DeliveryAddresses[0].City, "ADR on line 12 should have a blank city."); Assert.AreEqual( "United States of America", card.DeliveryAddresses[0].Country, "ADR on line 12 has the wrong country."); Assert.AreEqual( string.Empty, card.DeliveryAddresses[0].PostalCode, "ADR on line 12 should have a blank postal code."); Assert.AreEqual( string.Empty, card.DeliveryAddresses[0].Region, "ADR on line 12 should have a blank region."); Assert.AreEqual( string.Empty, card.DeliveryAddresses[0].Street, "ADR on line 12 should have a blank street."); // 13: ADR;HOME;PREF:;;3247 Upton Avenue N,;Minneapolis;MN;55412;United States of America Assert.AreEqual( "Minneapolis", card.DeliveryAddresses[1].City, "ADR on line 13 has the wrong city."); Assert.AreEqual( "United States of America", card.DeliveryAddresses[1].Country, "ADR on line 13 has the wrong country."); Assert.IsTrue( card.DeliveryAddresses[1].IsHome, "ADR on line 13 should be a home address."); Assert.AreEqual( "55412", card.DeliveryAddresses[1].PostalCode, "ADR on line 13 has the wrong postal code."); Assert.AreEqual( card.DeliveryAddresses[1].Region, "MN", "ADR on line 13 has the wrong region (state/province)."); Assert.AreEqual( "3247 Upton Avenue N,", card.DeliveryAddresses[1].Street, "ADR on line 13 has the wrong street."); // 14: LABEL;HOME;PREF;ENCODING=QUOTED-PRINTABLE:3247 Upton Avenue N,=0D=0A= // 15: Minneapolis, MN 55412 Assert.AreEqual( 1, card.DeliveryLabels.Count, "LABEL on line 14-15 should be the only delivery label."); Assert.AreEqual( "3247 Upton Avenue N,\r\nMinneapolis, MN 55412", card.DeliveryLabels[0].Text, "LABEL on lines 14-15 does not match."); // 16: X-MS-OL-DEFAULT-POSTAL-ADDRESS:1 // Unknown? Need to look this up. // 17: X-WAB-GENDER:2 Assert.AreEqual( vCardGender.Male, card.Gender, "X-WAB-GENDER on line 17 should indicate the male gender."); // 18: URL;WORK:http://www.thoughtproject.com Assert.AreEqual( 1, card.Websites.Count, "URL on line 18 should be the only website in the card."); Assert.IsTrue( card.Websites[0].IsWorkSite, "URL on line 18 indicates a work site."); Assert.AreEqual( "http://www.thoughtproject.com", card.Websites[0].Url, "URL on line 18 mismatch."); // 19: ROLE:Programmer Assert.AreEqual( "Programmer", card.Role, "ROLE on line 19 mismatch."); // 20: BDAY:20090414 Assert.IsNotNull( card.BirthDate, "BDAY on line 20 should have been loaded (property is null)."); Assert.AreEqual( new DateTime(2009, 4, 14), card.BirthDate.Value, "BDAY on line 20 mismatch."); // 21: KEY;X509;ENCODING=BASE64: Assert.AreEqual( 1, card.Certificates.Count, "KEY on line 21 should be the only certificate."); Assert.AreEqual( "X509", card.Certificates[0].KeyType, "KEY on line 21 has the wrong key type."); X509Certificate2 cert = new X509Certificate2(card.Certificates[0].Data); Assert.AreEqual( KeyIssuer, cert.Issuer, "The key issuer has a different value."); Assert.AreEqual( KeySubject, cert.Subject, "The key subject has a different value."); // 35: EMAIL;PREF;INTERNET:[email protected] Assert.AreEqual( 1, card.EmailAddresses.Count, "EMAIL on line 35 should be the only email address."); Assert.AreEqual( "*****@*****.**", card.EmailAddresses[0].Address, "EMAIL on line 35 has the wrong email address."); Assert.IsTrue( card.EmailAddresses[0].IsPreferred, "EMAIL on line 35 should be preferred."); Assert.AreEqual( vCardEmailAddressType.Internet, card.EmailAddresses[0].EmailType, "EMAIL on line 35 should be an Internet email address."); // 36: X-MS-IMADDRESS:[email protected] // Not supported (yet) // 37: PHOTO;TYPE=JPEG;ENCODING=BASE64: Assert.AreEqual( 1, card.Photos.Count, "PHOTO on line 37 should be the only photo."); // This should work without exception using (card.Photos[0].GetBitmap()) { } }
/// <summary> /// Builds the ORG property. /// </summary> private void BuildProperties_ORG( vCardPropertyCollection properties, vCard card) { // The ORG property specifies the name of the // person's company or organization. Example: // // ORG:FairMetric LLC if (!string.IsNullOrEmpty(card.Organization)) { vCardProperty property = new vCardProperty("ORG", card.Organization); properties.Add(property); } }
public Contact() { card = new vCard(); isSelected = false; isDirty = false; }
/// <summary> /// Builds PRODID properties. /// </summary> private void BuildProperties_PRODID( vCardPropertyCollection properties, vCard card) { if (!string.IsNullOrEmpty(card.ProductId)) { vCardProperty property = new vCardProperty(); property.Name = "PRODID"; property.Value = card.ProductId; properties.Add(property); } }
/// <summary> /// Reads the X-WAB-GENDER property. /// </summary> private void ReadInto_X_WAB_GENDER(vCard card, vCardProperty property) { // The X-WAB-GENDER property is a custom property generated by // Microsoft Outlook 2003. It contains the value 1 for females // or 2 for males. It is not known if other PIM clients // recognize this value. int genderId; if (int.TryParse(property.ToString(), out genderId)) { switch (genderId) { case 1: card.Gender = vCardGender.Female; break; case 2: card.Gender = vCardGender.Male; break; } } }
/// <summary> /// Builds the ROLE property. /// </summary> private void BuildProperties_ROLE( vCardPropertyCollection properties, vCard card) { // The ROLE property identifies the role of // the person at his/her organization. if (!string.IsNullOrEmpty(card.Role)) { vCardProperty property = new vCardProperty("ROLE", card.Role); properties.Add(property); } }
/// <summary> /// Method to add a new vCard to the collection /// </summary> /// <param name="vcard">vCard object to be added</param> public void Add(vCard vcard) { List.Add(vcard); }