Ejemplo n.º 1
0
        /// <summary>
        ///     Writes a card, then reads it back and compares fields.
        /// </summary>
        public static void CycleStandard21(vCard card)
        {

            if (card == null)
                throw new ArgumentNullException("cycle");

            // Create a memory stream to hold the contents of the card.

            MemoryStream stream = new MemoryStream();

            StreamWriter textWriter = new StreamWriter(stream);

            // Create a standard vCard writer and export the
            // card data to the stream.

            vCardStandardWriter writer = new vCardStandardWriter();
            writer.Write(card, textWriter);
            textWriter.Flush();

            // Reset the stream (back to its beginning), then
            // create a stream reader capable of reading text
            // lines from the stream.

            stream.Seek(0, SeekOrigin.Begin);
            StreamReader streamReader = new StreamReader(stream);

            vCardStandardReader standardReader = new vCardStandardReader();
            vCard reloaded = standardReader.Read(streamReader);

            Equals(card, reloaded);

        }
        public void EncodeEscaped_Comma_Text_Comma()
        {

            vCardStandardWriter writer = new vCardStandardWriter();

            Assert.AreEqual(
                @"\,text\,",
                writer.EncodeEscaped(",text,"));

        }
 public static string FixNote (string vcardData, vCardStandardWriter writer)
 {
   // Reformat NOTE attribute since quoted-printable is deprecated
   var noteMatch = Regex.Match(vcardData, "NOTE;ENCODING=QUOTED-PRINTABLE:(.*?)\r\n");
   if (noteMatch.Success)
   {
     string decodedNote = vCardStandardReader.DecodeQuotedPrintable (noteMatch.Groups[1].Value).Replace("\r\n", "\n");
     return Regex.Replace (vcardData, "NOTE;ENCODING=QUOTED-PRINTABLE:(.*?)\r\n", writer.EncodeEscaped ("NOTE:" + decodedNote) + "\r\n");
   }
   return vcardData;
 }
Ejemplo n.º 4
0
        public void SaveAs(string path)
        {
            if (this.cards == null || this.cards.Count == 0)
            {
                throw new InvalidDataException("No data to be saved");
            }
            vCardStandardWriter writer = new vCardStandardWriter();
            using (TextWriter tw = File.CreateText(path))
            {
                foreach (var card in this.cards)
                {
                    writer.Write(card.ToVCard(), tw);
                }
            }

        }
Ejemplo n.º 5
0
        private static void WriteCards(string peopleUrl, string folder)
        {
            var retriever = new PeopleRetriever(_credentials);
            var cards = retriever.GetVCards(peopleUrl);
            foreach (var card in cards)
            {
                var writer = new vCardStandardWriter
                                 {
                                     EmbedInternetImages = false,
                                     EmbedLocalImages = true,
                                     Options = vCardStandardWriterOptions.IgnoreCommas
                                 };

                var fileName = folder + card.DisplayName + ".vcf";
                writer.Write(card, fileName);
            }
        }
Ejemplo n.º 6
0
        public void SamplevCardReadAndWriteTestWithEmailTypeFormat()
        {

            vCard card = new vCard();

            card.EmailAddresses.Add(new vCardEmailAddress() { Address = "*****@*****.**", EmailType = vCardEmailAddressType.Internet, IsPreferred = true, ItemType = ItemType.WORK });


            card.UniqueId = Guid.NewGuid().ToString("N");

            string text = card.ToString();

            vCardStandardWriter writer = new vCardStandardWriter();

            using (StringWriter sw = new StringWriter())
            {

                writer.Write(card, sw);

                sw.Flush();
                text = sw.ToString();
                sw.Close();
            }


            Assert.IsNotNull(text);


            vCardStandardReader reader = new vCardStandardReader();

            using (StringReader sr = new StringReader(text))
            {

                vCard cardFromReader = reader.Read(sr);

                Assert.AreEqual(1, cardFromReader.EmailAddresses.Count);

                var email = cardFromReader.EmailAddresses.First();
                Assert.AreEqual(true, email.IsPreferred);
                Assert.AreEqual(ItemType.WORK, email.ItemType);
                Assert.AreEqual(vCardEmailAddressType.Internet, email.EmailType);
                Assert.AreEqual("*****@*****.**", email.Address);
            }

        }
        public void EncodeProperty_Null()
        {

            vCardStandardWriter writer =
                new vCardStandardWriter();

            writer.EncodeProperty(null);

        }
        public void EncodeProperty_Name_Value()
        {

            vCardStandardWriter writer =
                new vCardStandardWriter();

            vCardProperty property =
                new vCardProperty("NAME", "VALUE");

            Assert.AreEqual(
                "NAME:VALUE",
                writer.EncodeProperty(property));

        }
        public void EncodeProperty_Name_Subproperty_Subvalue_Subproperty_Value()
        {

            vCardStandardWriter writer =
                new vCardStandardWriter();

            vCardProperty property =
                new vCardProperty("NAME", "VALUE");

            property.Subproperties.Add("SUB1", "SUBVALUE");
            property.Subproperties.Add("SUB2");

            Assert.AreEqual(
                "NAME;SUB1=SUBVALUE;SUB2:VALUE",
                writer.EncodeProperty(property));

        }
        public void EncodeProperty_Name_Subproperty()
        {

            vCardStandardWriter writer =
                new vCardStandardWriter();

            vCardProperty property =
                new vCardProperty("NAME");

            property.Subproperties.Add("SUB");

            Assert.AreEqual(
                "NAME;SUB:",
                writer.EncodeProperty(property));

        }
        public void EncodeEscaped_Semicolon_CRLF()
        {

            vCardStandardWriter writer = new vCardStandardWriter();

            Assert.AreEqual(
                @"\;\r\n",
                writer.EncodeEscaped(";\r\n"));

        }
        public void EncodeEscaped_Semicolon_Space_Semicolon()
        {

            vCardStandardWriter writer = new vCardStandardWriter();

            Assert.AreEqual(
                @"\; \;",
                writer.EncodeEscaped("; ;"));

        }
Ejemplo n.º 13
0
        public void ShouldReadvCardWithAllCBFieldsFilledOutFromiPhoneNAB()
        {
            string text = @"BEGIN:VCARD
VERSION:3.0
PRODID:-//Apple Inc.//iOS 6.0.1//EN
N:iOS;Nic;;;
FN:Nic iOS
ORG:Ibm;
TITLE:Sales Guy
item1.EMAIL;type=INTERNET;type=pref:[email protected]
EMAIL;type=INTERNET;type=WORK:[email protected]
EMAIL;type=INTERNET;type=WORK:[email protected]
EMAIL;type=INTERNET;type=HOME:[email protected]
EMAIL;type=INTERNET;type=HOME:[email protected]
TEL;type=CELL;type=VOICE;type=pref:(202) 333-4555
TEL;type=IPHONE;type=CELL;type=VOICE:(202) 333-4444
TEL;type=HOME;type=VOICE:(333) 222-2222
TEL;type=WORK;type=VOICE:(809) 555-6666 x444
TEL;type=MAIN:(609) 888-7777
TEL;type=HOME;type=FAX:(555) 444-4443
TEL;type=WORK;type=FAX:33322222222
item2.TEL:(999) 777-7999
item2.X-ABLabel:personal
item3.ADR;type=HOME;type=pref:;;8230 Boone Blvd;Vinna;VA;22182;United States
item3.X-ABADR:us
item4.URL;type=pref:http://facebook.com/max.solender
item4.X-ABLabel:Profile
item5.URL:www.ibm.com
item5.X-ABLabel:_$!<HomePage>!$_
item6.X-MSN:msnname
item6.X-ABLabel:_$!<Other>!$_
item7.X-AIM:aolname
item7.X-ABLabel:_$!<Other>!$_
item8.X-YAHOO:yahooname
item8.X-ABLabel:_$!<Other>!$_
item9.X-JABBER:jabbername
item9.X-ABLabel:_$!<Other>!$_
IMPP;X-SERVICE-TYPE=Skype;type=HOME;type=pref:skype:skypeusernameee
IMPP;X-SERVICE-TYPE=Skype;type=WORK:skype:worksyokeusername
item10.IMPP;X-SERVICE-TYPE=MSN:msnim:msnname
item10.X-ABLabel:_$!<Other>!$_
item11.IMPP;X-SERVICE-TYPE=AIM:aim:aolname
item11.X-ABLabel:_$!<Other>!$_
item12.IMPP;X-SERVICE-TYPE=GoogleTalk:xmpp:gtalkname
item12.X-ABLabel:_$!<Other>!$_
item13.IMPP;X-SERVICE-TYPE=Yahoo:ymsgr:yahooname
item13.X-ABLabel:_$!<Other>!$_
item14.IMPP;X-SERVICE-TYPE=Facebook:xmpp:fbchatname
item14.X-ABLabel:_$!<Other>!$_
item15.IMPP;X-SERVICE-TYPE=Jabber:xmpp:jabbername
item15.X-ABLabel:_$!<Other>!$_
X-SOCIALPROFILE;type=linkedin;x-user=nicatlinkedin:http://www.linkedin.com/in/nicatlinkedin
X-SOCIALPROFILE;type=twitter;x-user=tiffanystone:http://twitter.com/tiffanystone
X-SOCIALPROFILE;type=facebook;x-user=tiffatfacebook:http://www.facebook.com/tiffatfacebook
X-SOCIALPROFILE;type=twitter;x-user=gregabedard:http://twitter.com/gregabedard
END:VCARD";

            vCardStandardReader reader = new vCardStandardReader();
            using (StringReader sr = new StringReader(text))
            {

                vCard c = reader.Read(sr);

                Assert.AreEqual(5, c.EmailAddresses.Count);

                CheckEmail(c.EmailAddresses, "*****@*****.**", ItemType.UNSPECIFIED, vCardEmailAddressType.Internet, true);
                CheckEmail(c.EmailAddresses, "*****@*****.**", ItemType.WORK, vCardEmailAddressType.Internet, false);
                CheckEmail(c.EmailAddresses, "*****@*****.**", ItemType.WORK, vCardEmailAddressType.Internet, false);
                CheckEmail(c.EmailAddresses, "*****@*****.**", ItemType.HOME, vCardEmailAddressType.Internet, false);
                CheckEmail(c.EmailAddresses, "*****@*****.**", ItemType.HOME, vCardEmailAddressType.Internet, false);




                Assert.AreEqual("Sales Guy", c.Title);
                Assert.AreEqual("Ibm", c.Organization);
                Assert.AreEqual("Nic", c.GivenName);
                Assert.AreEqual("iOS", c.FamilyName);

    

                Assert.AreEqual(8, c.Phones.Count);

                CheckPhone(c.Phones, "(202) 333-4555", vCardPhoneTypes.Preferred | vCardPhoneTypes.Cellular | vCardPhoneTypes.Voice, true);
        public void EncodeEscaped_Empty()
        {

            vCardStandardWriter writer = new vCardStandardWriter();

            Assert.AreEqual(
                string.Empty,
                writer.EncodeEscaped(string.Empty));

        }
Ejemplo n.º 15
0
        public void UT_vCardLibTest()
        {
            vCard card = new vCard();

            // Simple properties

            //card.AdditionalNames = AdditionalNames.Text;
            card.FamilyName = "刘";
            card.FormattedName = "刘杨";
            card.GivenName = "杨";
            //card.NamePrefix = NamePrefix.Text;
            //card.NameSuffix = NameSuffix.Text;
            card.Organization = "微软";
            //card.Role = Role.Text;
            card.Title = "高级研发经理";

            // ---------------------------------------------------------------
            // Email Addresses
            // ---------------------------------------------------------------
            // A vCard supports any number of email addresses.

            //card.EmailAddresses.Add(
            //    new vCardEmailAddress("浦驰路 1809弄 104号 701"));

            // ---------------------------------------------------------------
            // Nicknames
            // ---------------------------------------------------------------

            //string[] nicklist = new string[] { "泡沫刘" };
            //foreach (string nick in nicklist)
            //{
            //    if (nick.Length > 0)
            //        card.Nicknames.Add(nick);
            //}

            // ---------------------------------------------------------------
            // Notes
            // ---------------------------------------------------------------
            // The vCard specification allows for multiple notes, although
            // most applications seem to support a maximum of one note.

            //if (Note.Text.Length > 0)
            //{
            //    card.Notes.Add(new vCardNote(Note.Text));
            //}

            // ---------------------------------------------------------------
            // Phones
            // ---------------------------------------------------------------
            //
            // A vCard supports any number of telephones.  Each telephone can
            // have a different type (such as a video phone or a fax) and a
            // purpose (e.g. a home number or a work number).

            //if (!string.IsNullOrEmpty(WorkPhone.Text))
            //{
            //    card.Phones.Add(
            //        new vCardPhone(WorkPhone.Text, vCardPhoneTypes.WorkVoice));
            //}

            card.Phones.Add(
                new vCardPhone("13681765654", vCardPhoneTypes.Cellular));

            //if (!string.IsNullOrEmpty(WorkFax.Text))
            //{
            //    card.Phones.Add(
            //        new vCardPhone(WorkFax.Text, vCardPhoneTypes.WorkFax));
            //}

            // ---------------------------------------------------------------
            // Web Sites
            // ---------------------------------------------------------------

            //if (WorkWebSite.Text.Length > 0)
            //{
            //    card.Websites.Add(
            //        new vCardWebsite(WorkWebSite.Text, vCardWebsiteTypes.Work));
            //}

            var writer = new vCardStandardWriter();
            writer.EmbedInternetImages = false;
            writer.EmbedLocalImages = true;
            writer.Options = vCardStandardWriterOptions.IgnoreCommas;

            StringBuilder sb = new StringBuilder();
            using (var textWriter = new StringWriter(sb))
            {
                writer.Write(card, textWriter);
            }

            var expected = @"BEGIN:VCARD
            N:刘;杨;;;
            FN:刘杨
            ORG:微软
            TEL;CELL:13681765654
            TITLE:高级研发经理
            END:VCARD
            ";
            Assert.AreEqual(expected, sb.ToString());
        }
        public void EncodeEscaped_CRLF_Text()
        {

            vCardStandardWriter writer = new vCardStandardWriter();

            Assert.AreEqual(
                @"\r\ntext",
                writer.EncodeEscaped("\r\ntext"));

        }
        public void EncodeEscaped_Null()
        {

            vCardStandardWriter writer = new vCardStandardWriter();

            Assert.AreEqual(
                null,
                writer.EncodeEscaped((string)null));

        }