Пример #1
0
        /// <summary>
        ///     Reads the TEL property.
        /// </summary>
        private void ReadInto_TEL(vCard card, vCardProperty property)
        {

            vCardPhone phone = new vCardPhone();

            // The full telephone number is stored as the 
            // value of the property.  Currently no formatted
            // rules are applied since the vCard specification
            // is somewhat confusing on this matter.

            phone.FullNumber = property.ToString();
            if (string.IsNullOrEmpty(phone.FullNumber))
                return;

            foreach (vCardSubproperty sub in property.Subproperties)
            {

                // If this subproperty is a TYPE subproperty
                // and it has a value, then it is expected
                // to contain a comma-delimited list of phone types.

                if (
                    (string.Compare(sub.Name, "TYPE", StringComparison.OrdinalIgnoreCase) == 0) &&
                    (!string.IsNullOrEmpty(sub.Value)))
                {
                    // This is a vCard 3.0 subproperty.  It defines the
                    // the list of phone types in a comma-delimited list.
                    // Note that the vCard specification allows for
                    // multiple TYPE subproperties (why ?!).

                    phone.PhoneType |=
                        ParsePhoneType(sub.Value.Split(new char[] { ',' }));

                }
                else
                {

                    // The other subproperties in a TEL property
                    // define the phone type.  The only exception
                    // are meta fields like ENCODING, CHARSET, etc,
                    // but these are probably rare with TEL.

                    phone.PhoneType |= ParsePhoneType(sub.Name);

                }

            }

            card.Phones.Add(phone);

        }
Пример #2
0
 /// <summary>
 /// Utility method to convert phone information from the vCard library to a
 /// WinRT ContactPhone instance.
 /// No 1:1 matching is possible between both classes, the method tries to
 /// keep the conversion as accurate as possible.
 /// </summary>
 /// <param name="phone">Phone information from the vCard library.</param>
 /// <returns>The phone information from the vCard library converted to a 
 /// WinRT ContactPhone instance.</returns>
 private ContactPhone ConvertVcardToPhone(vCardPhone phone)
 {
     var cp = new ContactPhone
     {
         Number = phone.FullNumber
     };
     if (phone.IsWork)
     {
         cp.Kind = ContactPhoneKind.Work;
     }
     else if (phone.IsCellular)
     {
         cp.Kind = ContactPhoneKind.Mobile;
     }
     else if (phone.IsHome)
     {
         cp.Kind = ContactPhoneKind.Home;
     }
     else
     {
         cp.Kind = ContactPhoneKind.Other;
     }
     return cp;
 }
Пример #3
0
        /// <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);
        }
 private static void MapPhoneNumbers1To2(ContactItem source, vCard target)
 {
     if (!string.IsNullOrEmpty(source.PrimaryTelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.PrimaryTelephoneNumber, vCardPhoneTypes.Main);
         phoneNumber.IsPreferred = true;
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.MobileTelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.MobileTelephoneNumber, vCardPhoneTypes.Cellular);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.HomeTelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.HomeTelephoneNumber, vCardPhoneTypes.Home);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.Home2TelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.Home2TelephoneNumber, vCardPhoneTypes.HomeVoice);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.HomeFaxNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.HomeFaxNumber, vCardPhoneTypes.Fax | vCardPhoneTypes.Home);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.BusinessTelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.BusinessTelephoneNumber, vCardPhoneTypes.Work);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.Business2TelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.Business2TelephoneNumber, vCardPhoneTypes.WorkVoice);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.BusinessFaxNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.BusinessFaxNumber, vCardPhoneTypes.WorkFax);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.PagerNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.PagerNumber, vCardPhoneTypes.Pager);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.CarTelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.CarTelephoneNumber, vCardPhoneTypes.Car);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.ISDNNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.ISDNNumber, vCardPhoneTypes.ISDN);
         phoneNumber.IsPreferred = (target.Phones.Count == 0);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.OtherTelephoneNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.OtherTelephoneNumber, vCardPhoneTypes.Voice);
         target.Phones.Add(phoneNumber);
     }
     if (!string.IsNullOrEmpty(source.OtherFaxNumber))
     {
         vCardPhone phoneNumber = new vCardPhone(source.OtherFaxNumber, vCardPhoneTypes.Fax);
         target.Phones.Add(phoneNumber);
     }
 }
Пример #5
0
        /// <summary>
        ///     Asserts that two vCard phones are identical.
        /// </summary>
        public static void Equals(vCardPhone p1, vCardPhone p2)
        {
            Assert.AreEqual(
                p1.FullNumber,
                p2.FullNumber,
                "vCardPhone.FullNumber differs.");

            Assert.AreEqual(
                p1.IsBBS,
                p2.IsBBS,
                "vCardPhone.IsBBS does not match.");

            Assert.AreEqual(
                p1.IsCar,
                p2.IsCar,
                "vCardPhone.IsCar does not match.");

            Assert.AreEqual(
                p1.IsCellular,
                p2.IsCellular,
                "vCardPhone.IsCellular does not match.");

            Assert.AreEqual(
                p1.IsFax,
                p2.IsFax,
                "vCardPhone.IsFax does not match.");

            Assert.AreEqual(
                p1.IsHome,
                p2.IsHome,
                "vCardPhone.IsHome does not match.");

            Assert.AreEqual(
                p1.IsISDN,
                p2.IsISDN,
                "vCardPhone.IsISDN does not match.");

            Assert.AreEqual(
                p1.IsMessagingService,
                p2.IsMessagingService,
                "vCardPhone.IsMessagingService does not match.");

            Assert.AreEqual(
                p1.IsModem,
                p2.IsModem,
                "vCardPhone.IsModem does not match.");

            Assert.AreEqual(
                p1.IsPager,
                p2.IsPager,
                "vCardPhone.IsPager does not match.");

            Assert.AreEqual(
                p1.IsPreferred,
                p2.IsPreferred,
                "vCardPhone.IsPreferred differs.");

            Assert.AreEqual(
                p1.IsVideo,
                p2.IsVideo,
                "vCardPhone.IsVideo does not match.");

            Assert.AreEqual(
                p1.IsVoice,
                p2.IsVoice,
                "vCardPhone.IsVoice does not match.");

            Assert.AreEqual(
                p1.IsWork,
                p2.IsWork,
                "vCardPhone.IsWork does not match.");

            Assert.AreEqual(
                p1.PhoneType,
                p2.PhoneType,
                "vCardPhone.PhoneType differs.");

            Assert.AreEqual(
                p1.ToString(),
                p2.ToString(),
                "vCardPhone.ToString differs.");
        }