Пример #1
0
        public void SamplevCardReadAndWriteTestWithPhotos()
        {
            string base64Photo = @"/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQY
 GBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYa
 KCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAAR
 CAA3AEgDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAA
 AgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkK
 FhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWG
 h4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl
 5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREA
 AgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYk
 NOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOE
 hYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk
 5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwC3KUf7wwaiFvuPDDHrVh0yaiMeWrarK2pw
 wi2KLeFfvuD9KiuY4SmI1JPris3xHq0ek2jGMq1zjcseCeB3OK4+HxZdy3DPcXKwRkbVVEHX
 8a5f3k1dLQ6Y0ktzt4oBGc7efellkYDl1UflXAf23Pf+dbC/lSR8iOTdgA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hlnspHDCCZ4zjoSDg4/nV/wJNC+t
 xW91Ek0UoZGV1yMjoR+VFFdc4r2TXkYSep2euafZ6ftlsrdY95+YLxnFa+iOY9MUHqSTRRXl
 PWKMZtsyNal3Tge1FFFdtKK5UZM//9k=";


            vCard card = new vCard();

            card.EmailAddresses.Add(new vCardEmailAddress()
            {
                Address = "*****@*****.**", EmailType = vCardEmailAddressType.Internet, IsPreferred = true, ItemType = ItemType.WORK
            });
            card.Photos.Add(new vCardPhoto(base64Photo, true));
            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);
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            CardDav.Client client = new CardDav.Client(this.urlTxt.Text, this.usernameTxt.Text, this.passwordTxt.Text);

            CardDavResponse response = client.Get();

            /** Output the results from the Listing **/

            resultsTxt.Text = response.ToString();

            /** Set the client to the proper Address Book server URL **/
            client.SetServer(response.AddressBooks.First().Url.ToString());
            vCard card = client.GetVCard(response.Cards.First().Id);

            resultsTxt.Text = resultsTxt.Text + "\r\n\r\n\r\n" + card.ToString();
        }
Пример #3
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);
            }
        }
Пример #4
0
        public static string ConvertDatatableToVcf(DataTable dt, string fName)
        {
            var myCard = new vCard();
            int num;

            if (System.IO.Directory.Exists("NewVCF"))
            {
                System.IO.Directory.Delete("NewVCF", true);
            }
            System.IO.Directory.CreateDirectory("NewVCF");
            if (System.IO.File.Exists("NewVCF\\" + fName + ".vcf"))
            {
                System.IO.File.Delete("NewVCF\\" + fName + ".vcf");
            }
            try
            {
                foreach (DataRow dataRow in dt.Rows)
                {
                    num              = 0;
                    myCard.Title     = dataRow.ItemArray[num++].ToString();
                    myCard.FirstName = dataRow.ItemArray[num++].ToString();
                    myCard.LastName  = dataRow.ItemArray[num++].ToString();
                    myCard.Phone     = Convert.ToString(dataRow.ItemArray[num++]);
                    myCard.Mobile    = Convert.ToString(dataRow.ItemArray[num]);
                    using (var file = System.IO.File.Open(Directory.GetCurrentDirectory() + "\\NewVCF" + "\\" + fName + ".vcf", FileMode.Append))
                        using (var writer = new StreamWriter(file))
                        {
                            writer.Write(myCard.ToString());
                        }

                    /* foreach (var item in dataRow.ItemArray)
                     * {
                     *   System.Diagnostics.Debug.WriteLine(item);
                     * }*/
                }
                return(fName + ".vcf");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
            return(fName + ".vcf");
        }
Пример #5
0
        static void Main(string[] args)
        {
            string uri      = "https://contacts.cloze.com/carddav/addressbooks/[email protected]/default/";
            string username = "******";
            string password = "******";

            CardDav.Client client = new CardDav.Client(uri, username, password);

            CardDavResponse response = client.Get();

            /** Output the results from the Listing **/

            string results = response.ToString();

            /** Set the client to the proper Address Book server URL **/
            client.SetServer(response.AddressBooks.First().Url.ToString());
            vCard card = client.GetVCard(response.Cards.First().Id);

            results = results + "\r\n\r\n\r\n" + card.ToString();
        }
Пример #6
0
        public bool Update(vCard vcard, string id)
        {
            Dictionary <string, string> results = this.Query(this.serverUrl + id, "PUT", vcard.ToString(), "text/vcard");

            if (results.ContainsKey("status"))
            {
                string status = results["status"];

                if (status.Equals("200") || status.Equals("207") || status.Equals("204") || status.Equals("201") || status.ToLower().Equals("ok"))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(false);
        }
Пример #7
0
        public string Add(vCard vcard)
        {
            string vCardId = null;

            vCardId = this.GenerateVCardId();

            Dictionary <string, string> results = this.Query(this.serverUrl + vCardId, "PUT", vcard.ToString(), "text/vcard");

            if (results.ContainsKey("status"))
            {
                string status = results["status"];

                if (status.Equals("200") || status.Equals("207") || status.Equals("204") || status.Equals("201") || status.ToLower().Equals("ok"))
                {
                    return(vCardId);
                }
                else
                {
                    throw new HTTPException("Whoops something went wrong! The server returned a status code of: " + status);
                }
            }
            else
            {
                throw new HTTPException("No status code returned from HTTP Request");
            }
        }
Пример #8
0
        // 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);
        }