示例#1
0
        protected override void WriteMetaToItem(string meta, ContactItem item)
        {
            Fonlow.VCard.VCard vcard = VCardReader.ParseText(meta);
            item.LastName   = vcard.Surname;
            item.FirstName  = vcard.GivenName;
            item.MiddleName = vcard.MiddleName;
            item.Title      = vcard.Title;
            item.Suffix     = vcard.Suffix;
            //   item.FullName = vcard.FormattedName;//This must be after lastName to Suffix, otherwise, item.FullName will be recomposed by Outlook
            item.Body = vcard.Note;

            item.CompanyName = vcard.Org;
            item.Department  = vcard.Department;
            item.JobTitle    = vcard.Role;

            if (vcard.Birthday > DateTime.MinValue)
            {
                item.Birthday = vcard.Birthday;
            }

            PhoneNumber phoneNumber = vcard.Phones.GetItemsOfTypes(PhoneTypes.CELL).FirstOrDefault();

            if (phoneNumber != null)
            {
                item.MobileTelephoneNumber = phoneNumber.Number;
            }

            //Home phones
            IEnumerable <PhoneNumber> numbers = vcard.Phones.GetItemsOfTypes(PhoneTypes.VOICE, HomeWorkTypes.HOME);

            phoneNumber = numbers.FirstOrDefault();
            if (phoneNumber != null)
            {
                item.HomeTelephoneNumber = phoneNumber.Number;
                if (numbers.Count() > 1)
                {
                    item.Home2TelephoneNumber = numbers.ElementAt(1).Number;
                }
            }

            //Home fax
            numbers     = vcard.Phones.GetItemsOfTypes(PhoneTypes.FAX, HomeWorkTypes.HOME);
            phoneNumber = numbers.FirstOrDefault();
            if (phoneNumber != null)
            {
                item.HomeFaxNumber = phoneNumber.Number;
            }

            //Work phones
            numbers     = vcard.Phones.GetItemsOfTypes(PhoneTypes.VOICE, HomeWorkTypes.WORK);
            phoneNumber = numbers.FirstOrDefault();
            if (phoneNumber != null)
            {
                item.BusinessTelephoneNumber = phoneNumber.Number;
                if (numbers.Count() > 1)
                {
                    item.Business2TelephoneNumber = numbers.ElementAt(1).Number;
                }
            }

            //Work fax
            numbers     = vcard.Phones.GetItemsOfTypes(PhoneTypes.FAX, HomeWorkTypes.WORK);
            phoneNumber = numbers.FirstOrDefault();
            if (phoneNumber != null)
            {
                item.BusinessFaxNumber = phoneNumber.Number;
            }

            //Other phone
            numbers     = vcard.Phones.GetItemsOfTypesExactly(PhoneTypes.VOICE, HomeWorkTypes.None);
            phoneNumber = numbers.FirstOrDefault();
            if (phoneNumber != null)
            {
                item.OtherTelephoneNumber = phoneNumber.Number;
            }

            //Other fax
            numbers     = vcard.Phones.GetItemsOfTypesExactly(PhoneTypes.FAX, HomeWorkTypes.None);
            phoneNumber = numbers.FirstOrDefault();
            if (phoneNumber != null)
            {
                item.OtherFaxNumber = phoneNumber.Number;
            }

            phoneNumber = vcard.Phones.GetPreferredItems().FirstOrDefault(n => (n.HomeWorkTypes == HomeWorkTypes.HOME) || (n.HomeWorkTypes == HomeWorkTypes.None));
            if (phoneNumber != null)
            {
                item.PrimaryTelephoneNumber = phoneNumber.Number;
            }

            phoneNumber = vcard.Phones.GetPreferredItems().FirstOrDefault(n => n.HomeWorkTypes == HomeWorkTypes.WORK);
            if (phoneNumber != null)
            {
                item.CompanyMainTelephoneNumber = phoneNumber.Number;
            }

            phoneNumber = vcard.Phones.GetItemsOfTypes(PhoneTypes.PAGER).FirstOrDefault();
            if (phoneNumber != null)
            {
                item.PagerNumber = phoneNumber.Number;
            }

            EmailAddress email = vcard.Emails.FirstOrDefault();

            if (email != null)
            {
                item.Email1Address = email.Address;
                if (vcard.Emails.Count() > 1)
                {
                    item.Email2Address = vcard.Emails.ElementAt(1).Address;
                }

                if (vcard.Emails.Count() > 2)
                {
                    item.Email3Address = vcard.Emails.ElementAt(2).Address;
                }
            }

            Address address = vcard.Addresses.FirstOrDefault(n => n.HomeWorkType == HomeWorkTypes.HOME);

            if (address != null)
            {
                item.HomeAddressCity          = address.Locality;
                item.HomeAddressCountry       = address.Country;
                item.HomeAddressPostalCode    = address.Postcode;
                item.HomeAddressPostOfficeBox = address.POBox;
                item.HomeAddressState         = address.Region;
                item.HomeAddressStreet        = address.Street;
            }

            address = vcard.Addresses.FirstOrDefault(n => n.HomeWorkType == HomeWorkTypes.WORK);
            if (address != null)
            {
                item.BusinessAddressCity          = address.Locality;
                item.BusinessAddressCountry       = address.Country;
                item.BusinessAddressPostalCode    = address.Postcode;
                item.BusinessAddressPostOfficeBox = address.POBox;
                item.BusinessAddressState         = address.Region;
                item.BusinessAddressStreet        = address.Street;
            }

            URL url = vcard.URLs.FirstOrDefault(n => n.HomeWorkTypes == HomeWorkTypes.HOME);

            if (url != null)
            {
                item.PersonalHomePage = url.Address;
            }

            url = vcard.URLs.FirstOrDefault(n => n.HomeWorkTypes == HomeWorkTypes.WORK);
            if (url != null)
            {
                item.BusinessHomePage = url.Address;
            }
        }
示例#2
0
        public override string ReadItemToText(ContactItem item)
        {
            Fonlow.VCard.VCard vcard = new Fonlow.VCard.VCard();
            vcard.FormattedName = item.FullName;//or fileAs
            vcard.GivenName     = item.FirstName;
            vcard.Surname       = item.LastName;
            vcard.MiddleName    = item.MiddleName;
            vcard.Title         = item.Title;
            vcard.Note          = item.Body;
            vcard.Org           = item.CompanyName;

            if ((item.Birthday != null) && (item.Birthday < outlookNullYear))
            {
                vcard.Birthday = item.Birthday;
            }

            vcard.Department = item.Department;
            vcard.Suffix     = item.Suffix;
            vcard.Role       = item.JobTitle;

            if (!String.IsNullOrEmpty(item.HomeTelephoneNumber))
            {
                vcard.Phones.Add(new PhoneNumber(item.HomeTelephoneNumber, HomeWorkTypes.HOME));
            }

            if (!String.IsNullOrEmpty(item.Home2TelephoneNumber))
            {
                vcard.Phones.Add(new PhoneNumber(item.Home2TelephoneNumber, HomeWorkTypes.HOME));
            }

            if (!String.IsNullOrEmpty(item.MobileTelephoneNumber))
            {
                vcard.Phones.Add(new PhoneNumber(item.MobileTelephoneNumber, HomeWorkTypes.None, PhoneTypes.CELL, false));
            }

            if (!String.IsNullOrEmpty(item.PagerNumber))
            {
                vcard.Phones.Add(new PhoneNumber(item.PagerNumber, HomeWorkTypes.None, PhoneTypes.PAGER, false));
            }

            if (!String.IsNullOrEmpty(item.HomeFaxNumber))
            {
                vcard.Phones.Add(new PhoneNumber(item.HomeFaxNumber, HomeWorkTypes.HOME, PhoneTypes.FAX, false));
            }

            if (!String.IsNullOrEmpty(item.PrimaryTelephoneNumber))
            {
                vcard.Phones.Add(new PhoneNumber(item.PrimaryTelephoneNumber, HomeWorkTypes.None, PhoneTypes.VOICE, true));
            }

            if (!String.IsNullOrEmpty(item.BusinessTelephoneNumber))
            {
                vcard.Phones.Add(new PhoneNumber(item.BusinessTelephoneNumber, HomeWorkTypes.WORK));
            }

            if (!String.IsNullOrEmpty(item.Business2TelephoneNumber))
            {
                vcard.Phones.Add(new PhoneNumber(item.Business2TelephoneNumber, HomeWorkTypes.WORK));
            }

            if (!String.IsNullOrEmpty(item.BusinessFaxNumber))
            {
                vcard.Phones.Add(new PhoneNumber(item.BusinessFaxNumber, HomeWorkTypes.WORK, PhoneTypes.FAX, false));
            }

            if (!String.IsNullOrEmpty(item.CompanyMainTelephoneNumber))
            {
                vcard.Phones.Add(new PhoneNumber(item.CompanyMainTelephoneNumber, HomeWorkTypes.WORK, PhoneTypes.VOICE, true));
            }

            if (!String.IsNullOrEmpty(item.OtherTelephoneNumber))
            {
                vcard.Phones.Add(new PhoneNumber(item.OtherTelephoneNumber, HomeWorkTypes.None, PhoneTypes.VOICE, false));
            }

            if (!String.IsNullOrEmpty(item.OtherFaxNumber))
            {
                vcard.Phones.Add(new PhoneNumber(item.OtherFaxNumber, HomeWorkTypes.None, PhoneTypes.FAX, false));
            }



            if (!String.IsNullOrEmpty(item.Email1Address))
            {
                vcard.Emails.Add(new EmailAddress(item.Email1Address, false));
            }

            if (!String.IsNullOrEmpty(item.Email2Address))
            {
                vcard.Emails.Add(new EmailAddress(item.Email2Address, false));
            }

            if (!String.IsNullOrEmpty(item.Email3Address))
            {
                vcard.Emails.Add(new EmailAddress(item.Email3Address, false));
            }

            Address homeAddress = new Address();

            homeAddress.Locality     = item.HomeAddressCity;
            homeAddress.Country      = item.HomeAddressCountry;
            homeAddress.Postcode     = item.HomeAddressPostalCode;
            homeAddress.POBox        = item.HomeAddressPostOfficeBox;
            homeAddress.Region       = item.HomeAddressState;
            homeAddress.Street       = item.HomeAddressStreet;
            homeAddress.HomeWorkType = HomeWorkTypes.HOME;
            if (homeAddress.HadContent)
            {
                vcard.Addresses.Add(homeAddress);
            }

            Address businessAddress = new Address();

            businessAddress.Locality     = item.BusinessAddressCity;
            businessAddress.Country      = item.BusinessAddressCountry;
            businessAddress.Postcode     = item.BusinessAddressPostalCode;
            businessAddress.POBox        = item.BusinessAddressPostOfficeBox;
            businessAddress.Region       = item.BusinessAddressState;
            businessAddress.Street       = item.BusinessAddressStreet;
            businessAddress.HomeWorkType = HomeWorkTypes.WORK;
            if (businessAddress.HadContent)
            {
                vcard.Addresses.Add(businessAddress);
            }

            if (!String.IsNullOrEmpty(item.PersonalHomePage))
            {
                vcard.URLs.Add(new URL(item.PersonalHomePage, HomeWorkTypes.HOME));
            }

            if (!String.IsNullOrEmpty(item.BusinessHomePage))
            {
                vcard.URLs.Add(new URL(item.BusinessHomePage, HomeWorkTypes.WORK));
            }

            return(VCardWriter.WriteToString(vcard));
        }
示例#3
0
        public DataTable ImportDataToDataTable()
        {
            DataTable dt = BuildTableStructure();

            String Vcf = File.ReadAllText(FilePath);

            Fonlow.VCard.VCard vc = VCardReader.ParseText(Vcf);
            DataRow            dr = dt.NewRow();

            if (String.IsNullOrEmpty(vc.FormattedName) == false)
            {
                dr["Full Name"] = vc.FormattedName;
            }

            if (String.IsNullOrEmpty(vc.FormattedName) == false)
            {
                dr["Surname"] = vc.Surname;
            }

            if (String.IsNullOrEmpty(vc.GivenName) == false)
            {
                dr["GivenName"] = vc.GivenName;
            }

            if (String.IsNullOrEmpty(vc.MiddleName) == false)
            {
                dr["MiddleName"] = vc.MiddleName;
            }

            if (String.IsNullOrEmpty(vc.Title) == false)
            {
                dr["Title"] = vc.Title;
            }

            if (String.IsNullOrEmpty(vc.Prefix) == false)
            {
                dr["Prefix"] = vc.Prefix;
            }

            if (String.IsNullOrEmpty(vc.Suffix) == false)
            {
                dr["Suffix"] = vc.Suffix;
            }

            if (vc.Birthday > DateTime.MinValue)
            {
                dr["Birthday"] = vc.Birthday.ToLongDateString();
            }

            if (vc.Rev > DateTime.MinValue)
            {
                dr["Rev"] = vc.Rev.ToLongDateString();
            }

            if (String.IsNullOrEmpty(vc.Org) == false)
            {
                dr["Org"] = vc.Org;
            }

            for (int j = 0; j == vc.Phones.Count - 1; j++)
            {
                if (String.IsNullOrEmpty(dr["Phones"].ToString()) == false)
                {
                    dr["Phones"] = dr["Phones"] + " | " + ("Phone " + vc.Phones[j].PhoneTypes.ToString("G") + " " + vc.Phones[j].HomeWorkTypes.ToString() + " (Preferred = " +
                                                           (vc.Phones[j].Pref + ") =" + vc.Phones[j].Number));
                }
                else
                {
                    dr["Phones"] = ("Phone " + vc.Phones[j].PhoneTypes.ToString("G") + " " + vc.Phones[j].HomeWorkTypes.ToString() + " (Preferred = " +
                                    (vc.Phones[j].Pref + ") =" + vc.Phones[j].Number));
                }
            }

            for (int j = 0; j == vc.Emails.Count - 1; j++)
            {
                if (String.IsNullOrEmpty(dr["Emails"].ToString()) == false)
                {
                    dr["Emails"] = dr["Emails"] + " | " + ("Email " + " (Preferred = " + (vc.Emails[j].Pref.ToString()) + ") =" + vc.Emails[j].Address);
                }
                else
                {
                    dr["Emails"] = ("Email " + " (Preferred = " + (vc.Emails[j].Pref.ToString()) + ") =" + vc.Emails[j].Address);
                }
            }

            for (int j = 0; j == vc.URLs.Count - 1; j++)
            {
                if (String.IsNullOrEmpty(dr["URL"].ToString()) == false)
                {
                    dr["URL"] = dr["URL"] + " | " + ("URL " + vc.URLs[j].HomeWorkTypes.ToString() + " " + "=" + vc.URLs[j].Address);
                }
                else
                {
                    dr["URL"] = ("URL " + vc.URLs[j].HomeWorkTypes.ToString() + " " + "=" + vc.URLs[j].Address);
                }
            }

            for (int j = 0; j == vc.Addresses.Count - 1; j++)
            {
                if (String.IsNullOrEmpty(dr["Addresses"].ToString()) == false)
                {
                    dr["Addresses"] = dr["Addresses"] + " | " + ("Address " + vc.Addresses[j].HomeWorkType.ToString() + "=" + vc.Addresses[j].POBox + "," + vc.Addresses[j].Ext +
                                                                 ", " + vc.Addresses[j].Street + ", " + vc.Addresses[j].Locality + ", " + vc.Addresses[j].Region + ", " +
                                                                 vc.Addresses[j].Postcode + ", " + vc.Addresses[j].Country);
                }
                else
                {
                    dr["Addresses"] = ("Address " + vc.Addresses[j].HomeWorkType.ToString() + "=" + vc.Addresses[j].POBox + "," + vc.Addresses[j].Ext + ", " + vc.Addresses[j].Street + ", " +
                                       vc.Addresses[j].Locality + ", " + vc.Addresses[j].Region + ", " + vc.Addresses[j].Postcode + ", " + vc.Addresses[j].Country);
                }
            }


            if (String.IsNullOrEmpty(vc.Note) == false)
            {
                dr["Note"] = ("Note=" + vc.Note);
            }

            dt.Rows.Add(dr);
            Maindataset.Tables.Add(dt);
            return(dt);
        }