예제 #1
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");
            }
        }
예제 #2
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="owner">Owner vCard.</param>
        internal PhoneNumberCollection(vCard owner)
        {
            m_pOwner      = owner;
            m_pCollection = new List<PhoneNumber>();

            foreach(Item item in owner.Items.Get("TEL")){
                m_pCollection.Add(PhoneNumber.Parse(item));
            }
        }
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="owner">Owner vCard.</param>
 internal DeliveryAddressCollection(vCard owner)
 {
     m_pOwner      = owner;
     m_pCollection = new List<DeliveryAddress>();
                 
     foreach(Item item in owner.Items.Get("ADR")){
         m_pCollection.Add(DeliveryAddress.Parse(item));
     }
 }
예제 #4
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="owner">Owner vCard.</param>
 internal EmailAddressCollection(vCard owner)
 {
     m_pOwner      = owner;
     m_pCollection = new List<EmailAddress>();
                 
     foreach(Item item in owner.Items.Get("EMAIL")){
         m_pCollection.Add(EmailAddress.Parse(item));
     }
 }
예제 #5
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;
        }
예제 #6
0
        public vCard GetVCard(string id)
        {
            Dictionary<string, string> results = this.Query(this.serverUrl + id, "GET");

            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"))
                {
                    if (results.ContainsKey("response"))
                    {
                        StringReader reader = new StringReader(results["response"]);
                        vCard card = new vCard();
                        card.Parse(reader);

                        return card;
                    }
                    else
                    {
                        throw new HTTPException("Arrgg. No response returned from the server!");
                    }
                }
                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");
            }
        }
예제 #7
0
파일: vCard.cs 프로젝트: jalsco/CardDavNet
 /// <summary>
 /// Parses multiple vCards from the specified file (Apple Address Book and Gmail exports)
 /// </summary>
 /// <param name="file">vCard file with path.</param>
 public static List<vCard> ParseMultiple(string file) {
     List<vCard> vCards = new List<vCard>();
     List<string> fileStrings = new List<string>();
     string line = "";
     bool hasBeginTag = false;
     using (FileStream fs = File.OpenRead(file)) {
         TextReader r = new StreamReader(fs, System.Text.Encoding.Default);          
         while (line != null) {
             line = r.ReadLine();
             if (line != null && line.ToUpper() == "BEGIN:VCARD") {
                 hasBeginTag = true;
             }
             if (hasBeginTag) {
                 fileStrings.Add(line);
                 if (line != null && line.ToUpper() == "END:VCARD") {
                     // on END line process the Vcard, reinitialize, and will repeat the same thing for any others.
                     vCard singleVcard = new vCard();
                     singleVcard.ParseStrings(fileStrings);
                     vCards.Add(singleVcard);
                     fileStrings.Clear();
                     hasBeginTag = false;
                 }
             }
         }
     }
     return vCards;
 }