public void FillProviderCreatedItem(Contact contact, ContactEntry c)
		{
			c.Title.Text = contact.GetFullName(this.Notation);

			foreach (Microsoft.Communications.Contacts.PhoneNumber phone in contact.PhoneNumbers)
			{
				Google.GData.Extensions.PhoneNumber p = new Google.GData.Extensions.PhoneNumber();
			}
		}
示例#2
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         // Don't dispose of the source contact.  This is just a view over it.
         _contact = null;
         _disposed = true;
     }
 }
示例#3
0
 public GroupView(Contact contact)
     : base(contact)
 {
     if (contact.ContactType != ContactTypes.Group)
     {
         throw new ArgumentException("Contact is not a group.", "contact");
     }
     _manager = contact.Manager;
 }
示例#4
0
		public Microsoft.Communications.Contacts.Contact GetCanonicalContact(Microsoft.LiveFX.Client.Contact c)
		{
			Microsoft.Communications.Contacts.Contact contact = new Microsoft.Communications.Contacts.Contact();
			//LiveItemCollection<Profile, ProfileResource> profiles = c.Profiles;

			contact.Names.Add(new Name(c.Resource.GivenName, c.Resource.MiddleName, c.Resource.FamilyName, NameCatenationOrder.FamilyGivenMiddle));

			foreach (ContactPhone cp in c.Resource.PhoneNumbers)
			{
				PhoneNumber pn = new PhoneNumber(cp.Value);
				if (cp.Type == ContactPhone.ContactPhoneType.Business ||
					cp.Type == ContactPhone.ContactPhoneType.Business2)
					contact.PhoneNumbers.Add(pn, PhoneLabels.Voice, PropertyLabels.Business);
				else if (cp.Type == ContactPhone.ContactPhoneType.BusinessMobile)
					contact.PhoneNumbers.Add(pn, PhoneLabels.Cellular, PropertyLabels.Business);
				else if (cp.Type == ContactPhone.ContactPhoneType.Mobile)
					contact.PhoneNumbers.Add(pn, PhoneLabels.Cellular);
				else if (cp.Type == ContactPhone.ContactPhoneType.Personal)
					contact.PhoneNumbers.Add(pn, PhoneLabels.Voice, PropertyLabels.Personal);
				else if (cp.Type == ContactPhone.ContactPhoneType.Personal2)
					contact.PhoneNumbers.Add(pn, PhoneLabels.Voice, PropertyLabels.Personal);
				else if (cp.Type == ContactPhone.ContactPhoneType.Other)
					contact.PhoneNumbers.Add(pn, PhoneLabels.Voice);
				else if (cp.Type == ContactPhone.ContactPhoneType.OtherFax)
					contact.PhoneNumbers.Add(pn, PhoneLabels.Fax);
				else if (cp.Type == ContactPhone.ContactPhoneType.Fax)
					contact.PhoneNumbers.Add(pn, PhoneLabels.Fax);
				else 
					contact.PhoneNumbers.Add(pn);
			}

			if (c.Resource.WindowsLiveId != null && c.Resource.WindowsLiveId.Trim() != null)
				contact.EmailAddresses.Add(new EmailAddress(c.Resource.WindowsLiveId, "Windows Live ID"), PropertyLabels.Preferred);

			foreach (ContactEmail ce in c.Resource.Emails)
			{
				EmailAddress ea = new EmailAddress(ce.Value);
				if (ce.Type == ContactEmail.ContactEmailType.Personal)
					contact.EmailAddresses.Add(ea, PropertyLabels.Personal);
				else if (ce.Type == ContactEmail.ContactEmailType.Business)
					contact.EmailAddresses.Add(ea, PropertyLabels.Business);
				else if (ce.Type == ContactEmail.ContactEmailType.Other)
					contact.EmailAddresses.Add(ea);
				else
					contact.EmailAddresses.Add(ea);
			}

			DateTime lastChanged = c.Resource.LastUpdatedTime.DateTime.ToUniversalTime();
			contact.Dates.Add(lastChanged, "LastModificationTime");

			string absoluteUri = c.Resource.Id;
			Guid guid = new Guid(absoluteUri.PadLeft(32, '0'));
			contact.ContactIds.Add(guid, "Live");

			return contact;
		}
示例#5
0
        /// <summary>
        /// Check whether a Contact contains properties for the paths of MAPI Groups.
        /// </summary>
        /// <param name="contact">The contact to check for MAPI-groupness</param>
        /// <returns>
        /// Returns true if the contact would have values for either MemberIds or
        /// MemberNameEmailPairs if the contact was viewed as a MAPI group.  False
        /// otherwise.
        /// </returns>
        /// <remarks>
        /// This does not check that the properties are valid, just that the property
        /// paths of MAPI Group properties exist in the given contact.
        /// </remarks>
        public static bool HasMapiProperties(Contact contact)
        {
            Verify.IsNotNull(contact, "contact");

            using (Stream stm = contact.GetBinaryProperty(_ContactIdKey, null))
            {
                if (null != stm)
                {
                    return true;
                }
            }

            using (Stream stm = contact.GetBinaryProperty(_NameEmailKey, null))
            {
                if (null != stm)
                {
                    return true;
                }
            }

            return false;
        }
示例#6
0
            private void _PopulateKnownContacts(ContactTypes type)
            {
                Assert.IsNotNull(_loader);
                Assert.IsNotNull(_dispatcher);
                Assert.IsTrue(_dispatcher.CheckAccess());
                Assert.IsNotNull(_knownContacts);
                Assert.AreEqual(0, _knownContacts.Count);

                // Go through all contacts associated with the manager and make the mapping of file paths to the ContactIds. 
                foreach (var entry in _loader.GetPropertiesCollection(type))
                {
                    // Not using these contacts for very long.  Don't need the ContactManager parameter.
                    using (var contact = new Contact(null, entry.Value, entry.Key))
                    {
                        ContactInfo info = default(ContactInfo);
                        info.Id = contact.Id;
                        string pathNormalized = contact.Path.ToUpperInvariant();
                        info.LastWrite = File.GetLastWriteTime(pathNormalized);
                        _knownContacts.Add(pathNormalized, info);
                    }
                }
            }
示例#7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contact"></param>
        /// <param name="filePath"></param>
        /// <remarks>This implementation is based on the VersitCard 2.1 specification.</remarks>
        /// <returns></returns>
        public static void EncodeToVCard(Contact contact, string filePath)
        {
            Verify.IsNotNull(contact, "contact");

            using (var sw = new StreamWriter(filePath, false, Encoding.ASCII))
            {
                _EncodeToVCardStream(contact, sw);
            }
        }
示例#8
0
 private static void _WriteUniqueIdentifier(Contact contact, TextWriter sw)
 {
     // UID:Universal identifier
     Assert.IsTrue(contact.ContactIds.Default.HasValue);
     _WriteStringProperty(sw, "UID", contact.ContactIds.Default.Value.ToString());
 }
示例#9
0
 private static void _WritePhoneNumbers(Contact contact, TextWriter sw)
 {
     // TEL:Telephone numbers
     for (int i = 0; i < contact.PhoneNumbers.Count; ++i)
     {
         PhoneNumber number = contact.PhoneNumbers[i];
         if (!string.IsNullOrEmpty(number.Number))
         {
             _WriteLabeledProperty(sw, "TEL", contact.PhoneNumbers.GetLabelsAt(i), null, number.Number);
         }
     }
 }
示例#10
0
 private static void _WriteNotes(Contact contact, TextWriter sw)
 {
     // NOTE:Notes
     string note = contact.Notes;
     if (!string.IsNullOrEmpty(note))
     {
         _WriteStringProperty(sw, "NOTE", note);
     }
 }
示例#11
0
 private static void _WriteMailer(Contact contact, TextWriter sw)
 {
     // MAILER:mailer
     string mailer = contact.Mailer;
     if (!string.IsNullOrEmpty(mailer))
     {
         _WriteStringProperty(sw, "MAILER", mailer);
     }
 }
示例#12
0
        private static void _ReadPhoneNumbers(_Property phoneProp, Contact contact)
        {
            Assert.IsNotNull(phoneProp);
            Assert.IsNotNull(contact);

            contact.PhoneNumbers.Add(new PhoneNumber(phoneProp.ValueString), phoneProp.GetLabels());
        }
示例#13
0
        private static void _ReadNotes(_Property notesProp, Contact contact)
        {
            Assert.IsNotNull(notesProp);
            Assert.IsNotNull(contact);

            contact.Notes = notesProp.ValueString;
        }
示例#14
0
        private static void _ReadName(_Property nameProp, Contact contact)
        {
            Assert.IsNotNull(nameProp);
            Assert.IsNotNull(contact);

            var nb = new NameBuilder(contact.Names.Default);
            string[] names = _TokenizeEscapedMultipropString(nameProp.ValueString);

            switch (names.Length)
            {
                default: // too many.  Ignore extras
                case 5:
                    nb.Suffix = names[4];
                    goto case 4;
                case 4:
                    nb.Prefix = names[3];
                    goto case 3;
                case 3:
                    nb.MiddleName = names[2];
                    goto case 2;
                case 2:
                    nb.GivenName = names[1];
                    goto case 1;
                case 1:
                    nb.FamilyName = names[0];
                    break;
                case 0:
                    Assert.Fail("Tokenize shouldn't have yielded an empty array.");
                    break;
            }
            contact.Names.Default = nb;
        }
示例#15
0
        private static void _ReadMailer(_Property mailerProp, Contact contact)
        {
            Assert.IsNotNull(mailerProp);
            Assert.IsNotNull(contact);

            contact.Mailer = mailerProp.ValueString;
        }
示例#16
0
 private static void _WriteBirthday(Contact contact, TextWriter sw)
 {
     DateTime? bday = contact.Dates[DateLabels.Birthday];
     if (null != bday)
     {
         // ISO 8601 format
         _WriteStringProperty(sw, "BDAY", bday.Value.ToString("s", CultureInfo.InvariantCulture));
     }
 }
示例#17
0
 private static void _WriteEmailAddresses(Contact contact, TextWriter sw)
 {
     // EMAIL:E-mail addresses
     for (int i = 0; i < contact.EmailAddresses.Count; ++i)
     {
         EmailAddress email = contact.EmailAddresses[i];
         if (!string.IsNullOrEmpty(email.Address))
         {
             string addInternet = null;
             if (string.IsNullOrEmpty(email.AddressType)
                 || string.Equals("SMTP", email.AddressType, StringComparison.OrdinalIgnoreCase))
             {
                 addInternet = "INTERNET";
             }
             _WriteLabeledProperty(sw, "EMAIL", contact.EmailAddresses.GetLabelsAt(i), addInternet, email.Address);
         }
     }
 }
示例#18
0
        private static void _ReadPhonetic(_Property nameProp, Contact contact)
        {
            Assert.IsNotNull(nameProp);
            Assert.IsNotNull(contact);

            // Don't expect multiple names so just coalesce FN, N, and SOUND to the default Name.
            // Explicitly ignoring any labels set on the name, except that phonetic must be a URL.
            if (nameProp.Types.Contains(_DeclareValue + _UrlType))
            {
                contact.Names.Default = new NameBuilder(contact.Names.Default)
                {
                    Phonetic = nameProp.ValueString
                };
            }
        }
示例#19
0
        private static void _WriteName(Contact contact, TextWriter sw)
        {
            // The VCF spec implies that name isn't multi-valued, so don't mess with enumerating them.
            // Just use the default.

            // FN:Formatted Name
            Name name = contact.Names.Default;
            if (!string.IsNullOrEmpty(name.FormattedName))
            {
                _WriteStringProperty(sw, "FN", name.FormattedName);
            }

            // SOUND:Phonetic of FN.
            if (!string.IsNullOrEmpty(name.Phonetic))
            {
                _WriteStringProperty(sw, "SOUND", name.Phonetic);
            }

            // N:Name;Structured
            // Escape ';' in multiprops with a '\'
            // Note that WAB doesn't actually escape the ; properly, so it may mess up on this read.
            var nPropBuilder = new StringBuilder();
            nPropBuilder
                .Append(name.FamilyName.Replace(";", "\\;")).Append(";")
                .Append(name.GivenName.Replace(";", "\\;")).Append(";")
                .Append(name.MiddleName.Replace(";", "\\;")).Append(";")
                .Append(name.Prefix.Replace(";", "\\;")).Append(";")
                .Append(name.Suffix.Replace(";", "\\;"));
            string nProp = nPropBuilder.ToString();
            // If there aren't any properties then don't write this.
            if (nProp.Replace(";", null).Length > 0)
            {
                _WriteStringProperty(sw, "N", nProp);
            }
        }
示例#20
0
        private static void _ReadPhoto(_Property photoProp, Contact contact)
        {
            Assert.IsNotNull(photoProp);
            Assert.IsNotNull(contact);

            Photo photo = _ReadPhotoProperty(photoProp);

            // Add any other labels on the Photo.  UserTile is implied by the PHOTO type.
            contact.Photos.Add(photo, photoProp.GetLabels(PhotoLabels.UserTile, null));
        }
示例#21
0
        private static void _WriteOrganization(Contact contact, TextWriter sw)
        {
            // Organizational properties
            Position position = contact.Positions[PropertyLabels.Business];

            // Title:
            if (!string.IsNullOrEmpty(position.JobTitle))
            {
                _WriteStringProperty(sw, "TITLE", position.JobTitle);
            }

            // ROLE:Business Category
            if (!string.IsNullOrEmpty(position.Role))
            {
                _WriteStringProperty(sw, "ROLE", position.Role);
            }

            // LOGO: Company logo
            // Contact schema doesn't directly associate the logo with the business, but it's also
            // only kind of implied by vCards that they are also.  Can use the [Business,Logo] labels here.
            Photo logo = contact.Photos[PropertyLabels.Business, PhotoLabels.Logo];
            if (logo != default(Photo))
            {
                _WritePhotoProperty(sw, "LOGO", logo);
            }

            // AGENT:Embedded vCard (Unsupported)
            // Contacts can contain links to other contacts, but not going to expose this through vCard export.

            // ORG: Structured organization description
            var oPropBuilder = new StringBuilder();
            // Only the first field is actually defined (Name), the others are just kindof open-ended,
            // so don't write unnecessary properties.  Unfortunately on read we also won't know what
            // these properties are actually supposed to represent.
            oPropBuilder.Append(position.Company.Replace(";", "\\;"));
            foreach (string orgInfo in new[] { position.Organization, position.Profession, position.Department, position.Office })
            {
                if (!string.IsNullOrEmpty(orgInfo))
                {
                    oPropBuilder.Append(";")
                        .Append(orgInfo.Replace(";", "\\;"));
                }
            }
            string oProp = oPropBuilder.ToString();
            // If there aren't any properties then don't write this.
            if (oProp.Replace(";", null).Length > 0)
            {
                _WriteStringProperty(sw, "ORG", oProp);
            }
        }
示例#22
0
        private static void _ReadOrganization(_Property orgProp, Contact contact)
        {
            // In VCF there are three related properties: ORG, ROLE, and TITLE.
            // There reasonably could be multiple organizations on a vcard but short
            // of property groupings there's no way to distinguish, and even then
            // no guarantee that the property groupings will be present in the case
            // of multiple sets of these properties.
            // So instead, treat this like name and assume only the default, but rather
            // than use .Default, use the PropertyLabels.Business indexer.
            Assert.IsNotNull(orgProp);
            Assert.IsNotNull(contact);

            var position = new PositionBuilder(contact.Positions[PropertyLabels.Business]);
            string[] elements = _TokenizeEscapedMultipropString(orgProp.ValueString);
            Assert.BoundedInteger(1, elements.Length, int.MaxValue);

            // ORG is weird in that it doesn't actually say what the tokens represent.
            // The first one can be safely assumed to be Company, but anything else it's probably
            // best to just put back the ';'s and stick the string somewhere visible.
            position.Company = elements[0];
            if (elements.Length > 1)
            {
                position.Office = string.Join(";", elements, 1, elements.Length -1);
            }
            contact.Positions[PropertyLabels.Business] = position;
        }
示例#23
0
 private static void _WritePhoto(Contact contact, TextWriter sw)
 {
     Photo userTile = contact.Photos[PhotoLabels.UserTile];
     if (userTile != default(Photo))
     {
         _WritePhotoProperty(sw, "PHOTO", userTile);
     }
 }
示例#24
0
        private static void _ReadTitle(_Property titleProp, Contact contact)
        {
            // In VCF there are three related properties: ORG, ROLE, and TITLE.
            // There reasonably could be multiple organizations on a vcard but short
            // of property groupings there's no way to distinguish, and even then
            // no guarantee that the property groupings will be present in the case
            // of multiple sets of these properties.
            // So instead, treat this like name and assume only the default, but rather
            // than use .Default, use the PropertyLabels.Business indexer.
            Assert.IsNotNull(titleProp);
            Assert.IsNotNull(contact);

            var position = new PositionBuilder(contact.Positions[PropertyLabels.Business])
            {
                JobTitle = titleProp.ValueString
            };
            contact.Positions[PropertyLabels.Business] = position;
        }
示例#25
0
 private static void _WriteUrls(Contact contact, TextWriter sw)
 {
     // URL:Webpages
     for (int i = 0; i < contact.Urls.Count; ++i)
     {
         Uri uri = contact.Urls[i];
         if (null != uri && !string.IsNullOrEmpty(uri.ToString()))
         {
             _WriteLabeledProperty(sw, "URL", contact.Urls.GetLabelsAt(i), null, uri.ToString());
         }
     }
 }
示例#26
0
 private static void _ReadUniqueIdentifier(_Property nameProp, Contact contact)
 {
     // Someone (maybe us) bothered to put a UID on the contact, so if it matches
     //    our ContactId's GUID format then go ahead and use it.
     Guid id;
     if (Utility.GuidTryParse(nameProp.ValueString, out id))
     {
         contact.ContactIds.Default = id;
     }
 }
示例#27
0
        // This function writes vCard properties as they're described in the vCard 2.1 specification.
        // For several of the properties in the spec it lists valid type tags (Property Parameters)
        //   that can be added, the equivalent of the Contact Schema's labels.  Not all properties
        //   have these types, even though most of them really should, e.g. e-mails and urls.
        // It also supports groupings of properties, but it doesn't really say how they're supposed
        //   to be consumed.  This doesn't exactly map to a concept in Contacts other than to
        //   ensure that the same node contains data disparate in the vcard, e.g. Org-Role-Title.
        //   That there's a grouping implies that it's OK with multiple values for any property, but
        //   I really don't think most applications are expecting to consume multiple name properties.
        // The spec doesn't say that the property parameters are strictly limited to the enumerated
        //   properties.  In fact, WAB writes HOME and WORK on the URLs.  It also doesn't say whether
        //   the enumerated properties are the only ones that can be added.  For properties where it's
        //   reasonable for VCFs to have multiple values I add the additional mapped Contact labels.
        //   For types, such as EmailType, I'm just going to embed the string as the label.  The types
        //   of e-mail addresses in 1996 doesn't make sense in 2007, and any updated list isn't going
        //   to make sense in 2018, so it seems silly to try and guess (GMAIL as PRODIGY, anyone?)
        //
        // 2.1 is much more ubiquitous than 3.0, and 3.0 has more ambiguities regarding a lot of this
        //   than 2.1 does.  Neither do a great job of addressing globalization issues.  Since this
        //   is just a transport mechanism (vcard itself is just designed to be embedded in mime) I'm
        //   sticking with 2.1.
        private static void _EncodeToVCardStream(Contact contact, StreamWriter sw)
        {
            Verify.IsNotNull(contact, "contact");
            Assert.IsNotNull(sw);

            // VCard properties that are not written:
            // * TZ:TimeZone
            // * GEO: latitude/longitude coordinates
            // * AGENT: nor any other kind of embedded reference to other contacts
            // * CERT: Certificates.

            _WriteStringProperty(sw, "BEGIN", "VCARD");
            _WriteStringProperty(sw, "VERSION", "2.1");
            _WriteName(contact, sw);
            _WritePhoto(contact, sw);
            _WriteBirthday(contact, sw);
            _WriteAddresses(contact, sw);
            _WritePhoneNumbers(contact, sw);
            _WriteEmailAddresses(contact, sw);
            _WriteMailer(contact, sw);
            _WriteOrganization(contact, sw);
            _WriteNotes(contact, sw);
            _WriteUrls(contact, sw);
            _WriteUniqueIdentifier(contact, sw);
            _WriteStringProperty(sw, "REV", DateTime.UtcNow.ToString("s", CultureInfo.InvariantCulture));
            _WriteStringProperty(sw, "END", "VCARD");

            sw.Flush();
        }
示例#28
0
        private static void _ReadUrl(_Property urlProp, Contact contact)
        {
            Assert.IsNotNull(urlProp);
            Assert.IsNotNull(contact);

            Uri uri;
            if (Uri.TryCreate(urlProp.ValueString, UriKind.RelativeOrAbsolute, out uri))
            {
                contact.Urls.Add(uri, urlProp.GetLabels());
            }
        }
示例#29
0
		public Contact GetCanonicalContact(PIMPersonalInfo pim, PIMNumbers num, IList<PIMAddresses> adr)
		{
			if (pim == null)
				return null;

			Contact contact = new Contact();

			if (pim.FormalName != null)
			{
				string[] names = pim.FormalName.Split(new char[] { ' ' });

				if (pim.FirstName == null && pim.LastName == null && pim.MiddleName == null)
				{
					if (names.Length > 2)
						pim.FirstName = names[0];
					else if (names.Length == 2)
						pim.FirstName = names[1];
					else if (names.Length > 0)
						pim.FirstName = names[0];

					if (names.Length == 3)
						pim.MiddleName = names[1];
					else if (names.Length > 3)
						pim.MiddleName = names[names.Length - 2];

					if (names.Length >= 3)
						pim.LastName = names[2];
					else if (names.Length > 1)
						pim.LastName = names[0];
				}
			}

			Name name = new Name(
				pim.FormalName,
				pim.GivenNamePronunciation, 
				null,
				pim.Title,
				pim.FirstName,
				pim.MiddleName,
				pim.LastName,
				null,
				pim.Suffix,
				pim.Nick);

			name.FormattedName = pim.LastName;
			if (name.FormattedName != null &&
				name.FormattedName != "")
				name.FormattedName += " ";
			name.FormattedName += pim.FirstName;
			if (name.FormattedName != null &&
				name.FormattedName != "")
				name.FormattedName += " ";
			name.FormattedName += pim.MiddleName;
			name.FormattedName = name.FormattedName.Trim();

			contact.Names.Add(name);

			PhoneNumber phone = null;
			
			if (num.Mobile.Count > 0)
			{
				foreach (string ph in num.Mobile) {
					phone = new PhoneNumber(ph);
					contact.PhoneNumbers.Add(phone, PhoneLabels.Cellular);
				}
			}

			if (num.MobileHome.Count > 0)
			{
				foreach (string ph in num.MobileHome) {
					phone = new PhoneNumber(ph);
					contact.PhoneNumbers.Add(phone, PhoneLabels.Cellular, PropertyLabels.Personal);
				}
			}

			if (num.MobileWork.Count > 0)
			{
				foreach (string ph in num.MobileWork) {
					phone = new PhoneNumber(ph);
					contact.PhoneNumbers.Add(phone, PhoneLabels.Cellular, PropertyLabels.Business);
				}
			}

			if (num.Telephone.Count > 0)
			{
				foreach (string ph in num.Telephone)
				{
					phone = new PhoneNumber(ph);
					contact.PhoneNumbers.Add(phone, PhoneLabels.Voice);
				}
			}

			if (num.Home.Count > 0)
			{
				foreach (string ph in num.Home)
				{
					phone = new PhoneNumber(ph);
					contact.PhoneNumbers.Add(phone, PhoneLabels.Voice, PropertyLabels.Personal);
				}
			}

			if (num.Work.Count > 0)
			{
				foreach (string ph in num.Work)
				{
					phone = new PhoneNumber(ph);
					contact.PhoneNumbers.Add(phone, PhoneLabels.Voice, PropertyLabels.Business);
				}
			}

			if (num.Fax.Count > 0)
			{
				foreach (string ph in num.Fax)
				{
					phone = new PhoneNumber(ph);
					contact.PhoneNumbers.Add(phone, PhoneLabels.Fax);
				}
			}

			if (num.FaxHome.Count > 0)
			{
				foreach (string ph in num.FaxHome)
				{
					phone = new PhoneNumber(ph);
					contact.PhoneNumbers.Add(phone, PhoneLabels.Fax, PropertyLabels.Personal);
				}
			}

			if (num.FaxWork.Count > 0)
			{
				foreach (string ph in num.FaxWork)
				{
					phone = new PhoneNumber(ph);
					contact.PhoneNumbers.Add(phone, PhoneLabels.Fax, PropertyLabels.Business);
				}
			}

			if (num.Pager.Count > 0)
			{
				foreach (string ph in num.Pager)
				{
					phone = new PhoneNumber(ph);
					contact.PhoneNumbers.Add(phone, PhoneLabels.Pager);
				}
			}

			if (num.Video.Count > 0)
			{
				foreach (string ph in num.Video)
				{
					phone = new PhoneNumber(ph);
					contact.PhoneNumbers.Add(phone, PhoneLabels.Video);
				}
			}

			if (num.VideoHome.Count > 0)
			{
				foreach (string ph in num.VideoHome)
				{
					phone = new PhoneNumber(ph);
					contact.PhoneNumbers.Add(phone, PhoneLabels.Video, PropertyLabels.Personal);
				}
			}

			if (num.VideoWork.Count > 0)
			{
				foreach (string ph in num.VideoWork)
				{
					phone = new PhoneNumber(ph);
					contact.PhoneNumbers.Add(phone, PhoneLabels.Video, PropertyLabels.Business);
				}
			}

			foreach (PIMAddresses a in adr)
			{
				PhysicalAddress phys = new PhysicalAddress(
					a.POBox, a.Street, a.City, a.State, a.PostalCode, a.Country,
					null, null);

				if (a.Private != null)
				{
					contact.Addresses.Add(phys, PropertyLabels.Personal);
				}
				else if (a.Business != null)
				{
					contact.Addresses.Add(phys, PropertyLabels.Business);
				}
				else
				{
					contact.Addresses.Add(phys, PropertyLabels.Personal);
				}
			}

			Position pos = new Position(null, null, pim.Company, null, null, pim.JobTitle, null);
			contact.Positions.Add(pos, PropertyLabels.Business);

			DateTime lastChanged = DateTime.Now;
			contact.Dates.Add(lastChanged, new string[] { "LastModificationTime" });
			
			return contact;
		}
示例#30
0
        private static void _WriteAddresses(Contact contact, TextWriter sw)
        {
            for (int i = 0; i < contact.Addresses.Count; ++i)
            {
                PhysicalAddress address = contact.Addresses[i];
                // ADR:Address;Structured
                // Escape ';' in multiprops with a '\'
                // Note that WAB doesn't actually escape the ; properly, so it may mess up on this read.
                var adrPropBuilder = new StringBuilder();
                adrPropBuilder
                    .Append(address.POBox.Replace(";", "\\;")).Append(";")
                    .Append(address.ExtendedAddress.Replace(";", "\\;")).Append(";")
                    .Append(address.Street.Replace(";", "\\;")).Append(";")
                    .Append(address.City.Replace(";", "\\;")).Append(";")
                    .Append(address.State.Replace(";", "\\;")).Append(";")
                    .Append(address.ZipCode.Replace(";", "\\;")).Append(";")
                    .Append(address.Country.Replace(";", "\\;"));
                string adrProp = adrPropBuilder.ToString();
                // If there aren't any properties then don't write this.
                if (adrProp.Replace(";", null).Length > 0)
                {
                    _WriteLabeledProperty(sw, "ADR", contact.Addresses.GetLabelsAt(i), null, adrProp);
                }

                if (!string.IsNullOrEmpty(address.AddressLabel))
                {
                    _WriteLabeledProperty(sw, "LABEL", contact.Addresses.GetLabelsAt(i), null, address.AddressLabel);
                }
            }
        }