Beispiel #1
0
 /// <summary>
 /// Traitement du résultat de la demande de récupération de la fiche d'identité
 /// </summary>
 /// <param name="sender">Objet représentant la routine ayant fait appel à cette méthode</param>
 /// <param name="iq">Requète représentant le résultat de la demande</param>
 /// <param name="data">Identifiant de la requète</param>
 private void retrieveIqResult(object sender, agsXMPP.protocol.client.IQ iq, object data)
 {
     string iqID = data as string;
     // si on a une erreur alors on en informe la librairie
     if (iq.Type == agsXMPP.protocol.client.IqType.error) {
         return;
     }
         // sinon et seulement si c'est le résultat, on lance le traitement
     else if (iq.Type == agsXMPP.protocol.client.IqType.result) {
         // si la requette nous transmet la carte de visite
         if (iq.Vcard != null) {
             _birthday = iq.Vcard.Birthday;
             _description = (iq.Vcard.Description != null) ? iq.Vcard.Description.Trim() : string.Empty;
             _fullname = (iq.Vcard.Fullname != null) ? iq.Vcard.Fullname.Trim() : string.Empty;
             _name = new Name();
             _name.firstname = (iq.Vcard.Name != null && iq.Vcard.Name.Given != null) ? iq.Vcard.Name.Given.Trim() : string.Empty;
             _name.middle = (iq.Vcard.Name != null && iq.Vcard.Name.Middle != null) ? iq.Vcard.Name.Middle.Trim() : string.Empty;
             _name.lastname = (iq.Vcard.Name != null && iq.Vcard.Name.Family != null) ? iq.Vcard.Name.Family.Trim() : string.Empty;
             if (iq.Vcard.Nickname != null) {
                 nickname = iq.Vcard.Nickname.Trim();
             }
             _organization = new Organization();
             _organization.name = (iq.Vcard.Organization != null && iq.Vcard.Organization.Name != null) ? iq.Vcard.Organization.Name.Trim() : string.Empty;
             _organization.unit = (iq.Vcard.Organization != null && iq.Vcard.Organization.Unit != null) ? iq.Vcard.Organization.Unit.Trim() : string.Empty;
             _role = (iq.Vcard.Role != null) ? iq.Vcard.Role.Trim() : string.Empty;
             _title = (iq.Vcard.Title != null) ? iq.Vcard.Title.Trim() : string.Empty;
             _url = (iq.Vcard.Url != null) ? iq.Vcard.Url.Trim() : string.Empty;
             if (iq.Vcard.GetEmailAddresses() != null) {
                 _email.Clear();
                 foreach (agsXMPP.protocol.iq.vcard.Email em in iq.Vcard.GetEmailAddresses()) {
                     if (em != null && em.UserId != null) {
                         Email m = new Email();
                         m.type = Enums.EmailTypeConverter(em.Type);
                         m.address = em.UserId;
                         _email.Add(m);
                     }
                 }
             }
             if (iq.Vcard.GetTelephoneNumbers() != null) {
                 _telephone.Clear();
                 foreach (agsXMPP.protocol.iq.vcard.Telephone phone in iq.Vcard.GetTelephoneNumbers()) {
                     if (phone != null && phone.Number != null) {
                         Telehone t = new Telehone();
                         t.location = Enums.LocationTypeConverter(phone.Location);
                         t.type = Enums.PhoneTypeConverter(phone.Type);
                         t.number = phone.Number;
                         _telephone.Add(t);
                     }
                 }
             }
             if (iq.Vcard.GetAddresses() != null) {
                 _address.Clear();
                 foreach (agsXMPP.protocol.iq.vcard.Address ad in iq.Vcard.GetAddresses()) {
                     if (ad != null) {
                         Address a = new Address();
                         a.location = Enums.AddressLocationTypeConverter(ad.Location);
                         a.city = (ad.Locality != null) ? ad.Locality.Trim() : string.Empty;
                         a.country = (ad.Country != null) ? ad.Country.Trim() : string.Empty;
                         a.extra = (ad.ExtraAddress != null) ? ad.ExtraAddress.Trim() : string.Empty;
                         a.region = (ad.Region != null) ? ad.Region.Trim() : string.Empty;
                         a.street = (ad.Street != null) ? ad.Street.Trim() : string.Empty;
                         a.zipcode = (ad.PostalCode != null) ? ad.PostalCode.Trim() : string.Empty;
                         _address.Add(a);
                     }
                 }
             }
             photo = (iq.Vcard.Photo != null) ? iq.Vcard.Photo.Image : null;
             onIdentityRetrieved();
         }
     }
     if (Jabber.xmpp.IqGrabber != null) { Jabber.xmpp.IqGrabber.Remove(iqID); }
 }
Beispiel #2
0
        /// <summary>
        /// Charge la fiche d'identité locale
        /// </summary>
        public void Load(string vCardFilePath)
        {
            if (!Directory.Exists(Path.GetDirectoryName(vCardFilePath))) {
                try {
                    Directory.CreateDirectory(vCardFilePath);
                } catch {
                }
            }
            if (File.Exists(vCardFilePath)) {
                try {
                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(vCardFilePath);
                    XmlElement vcard = xDoc["vcard"];
                    XmlElement xAddresses = vcard["addresses"];
                    if (xAddresses.HasChildNodes) {
                        _address.Clear();
                        foreach (XmlNode xAddress in xAddresses.ChildNodes) {
                            Address a = new Address();
                            if (xAddress.Attributes["location"].Value == Enums.LocationType.Home.ToString()) {
                                a.location = Enums.LocationType.Home;
                            } else if (xAddress.Attributes["location"].Value == Enums.LocationType.Work.ToString()) {
                                a.location = Enums.LocationType.Work;
                            } else {
                                a.location = Enums.LocationType.None;
                            }
                            a.city = (xAddress["city"].InnerText != null) ? xAddress["city"].InnerText : string.Empty;
                            a.country = (xAddress["country"].InnerText != null) ? xAddress["country"].InnerText : string.Empty;
                            a.extra = (xAddress["extra"].InnerText != null) ? xAddress["extra"].InnerText : string.Empty;
                            a.region = (xAddress["region"].InnerText != null) ? xAddress["region"].InnerText : string.Empty;
                            a.street = (xAddress["street"].InnerText != null) ? xAddress["street"].InnerText : string.Empty;
                            a.zipcode = (xAddress["zipcode"].InnerText != null) ? xAddress["zipcode"].InnerText : string.Empty;
                            _address.Add(a);
                        }
                    }
                    _birthday = (vcard["birthday"].InnerText != null) ? DateTime.Parse(vcard["birthday"].InnerText) : DateTime.Now;
                    _description = (vcard["description"].InnerText != null) ? vcard["description"].InnerText : string.Empty;
                    XmlElement xEmails = vcard["emails"];
                    if (xEmails.HasChildNodes) {
                        _email.Clear();
                        foreach (XmlNode xEmail in xEmails.ChildNodes) {
                            Email m = new Email();
                            if (xEmail.Attributes["type"].Value == Enums.EmailType.Home.ToString()) {
                                m.type = Enums.EmailType.Home;
                            } else if (xEmail.Attributes["type"].Value == Enums.EmailType.Internet.ToString()) {
                                m.type = Enums.EmailType.Internet;
                            } else if (xEmail.Attributes["type"].Value == Enums.EmailType.Work.ToString()) {
                                m.type = Enums.EmailType.Work;
                            } else if (xEmail.Attributes["type"].Value == Enums.EmailType.X400.ToString()) {
                                m.type = Enums.EmailType.X400;
                            } else {
                                m.type = Enums.EmailType.None;
                            }
                            m.address = (xEmail.InnerText != null) ? xEmail.InnerText : string.Empty;
                            _email.Add(m);
                        }
                    }
                    _fullname = (vcard["fullname"].InnerText != null) ? vcard["fullname"].InnerText : string.Empty;
                    XmlElement xName = vcard["name"];
                    Name n = new Name();
                    n.firstname = (xName["firstname"].InnerText != null) ? xName["firstname"].InnerText : string.Empty;
                    n.lastname = (xName["lastname"].InnerText != null) ? xName["lastname"].InnerText : string.Empty;
                    n.middle = (xName["middle"].InnerText != null) ? xName["middle"].InnerText : string.Empty;
                    _name = n;
                    nickname = (vcard["nickname"].InnerText != null) ? vcard["nickname"].InnerText : string.Empty;
                    XmlElement xOrganization = vcard["organization"];
                    Organization o = new Organization();
                    o.name = (xOrganization["name"].InnerText != null) ? xOrganization["name"].InnerText : string.Empty;
                    o.unit = (xOrganization["unit"].InnerText != null) ? xOrganization["unit"].InnerText : string.Empty;
                    _organization = o;
                    if (vcard["photo"].HasChildNodes && vcard["photo"].HasAttribute("format")) {
                        string format = vcard["photo"].Attributes["format"].Value;
                        ImageFormat ift = null;
                        if (format == ImageFormat.Bmp.ToString()) { ift = ImageFormat.Bmp; } else if (format == ImageFormat.Gif.ToString()) { ift = ImageFormat.Gif; } else if (format == ImageFormat.Icon.ToString()) { ift = ImageFormat.Icon; } else if (format == ImageFormat.Jpeg.ToString()) { ift = ImageFormat.Jpeg; } else if (format == ImageFormat.Png.ToString()) { ift = ImageFormat.Png; } else { ift = null; }
                        if (ift != null) {
                            byte[] bts = Convert.FromBase64String(vcard["photo"].ChildNodes[0].Value);
                            MemoryStream ms = new MemoryStream(bts);
                            photo = Image.FromStream(ms);
                            byte[] hash = SHA1.Create().ComputeHash(ms.ToArray());
                            ms.Close();
                            ms.Dispose();
                            string hashString = string.Empty;
                            foreach (byte b in hash) {
                                string hex = b.ToString("X").ToLower();
                                hex = ((hex.Length == 1) ? "0" : string.Empty) + hex;
                                hashString += hex;
                            }
                            hash = null;
                            _photoHash = hashString;
                            hashString = string.Empty;
                        }
                    }
                    _role = (vcard["role"].InnerText != null) ? vcard["role"].InnerText : string.Empty;
                    XmlElement xTel = vcard["telephones"];
                    if (xTel.HasChildNodes) {
                        _telephone.Clear();
                        foreach (XmlNode xT in xTel.ChildNodes) {
                            Telehone t = new Telehone();
                            if (xT.Attributes["location"].Value == Enums.LocationType.Home.ToString()) {
                                t.location = Enums.LocationType.Home;
                            } else if (xT.Attributes["location"].Value == Enums.LocationType.Work.ToString()) {
                                t.location = Enums.LocationType.Work;
                            } else {
                                t.location = Enums.LocationType.None;
                            }
                            if (xT.Attributes["type"].Value == Enums.PhoneType.Bbs.ToString()) {
                                t.type = Enums.PhoneType.Bbs;
                            } else if (xT.Attributes["type"].Value == Enums.PhoneType.Cell.ToString()) {
                                t.type = Enums.PhoneType.Cell;
                            } else if (xT.Attributes["type"].Value == Enums.PhoneType.Fax.ToString()) {
                                t.type = Enums.PhoneType.Fax;
                            } else if (xT.Attributes["type"].Value == Enums.PhoneType.Isdn.ToString()) {
                                t.type = Enums.PhoneType.Isdn;
                            } else if (xT.Attributes["type"].Value == Enums.PhoneType.Modem.ToString()) {
                                t.type = Enums.PhoneType.Modem;
                            } else if (xT.Attributes["type"].Value == Enums.PhoneType.Msg.ToString()) {
                                t.type = Enums.PhoneType.Msg;
                            } else if (xT.Attributes["type"].Value == Enums.PhoneType.Number.ToString()) {
                                t.type = Enums.PhoneType.Number;
                            } else if (xT.Attributes["type"].Value == Enums.PhoneType.Pager.ToString()) {
                                t.type = Enums.PhoneType.Pager;
                            } else if (xT.Attributes["type"].Value == Enums.PhoneType.Pcs.ToString()) {
                                t.type = Enums.PhoneType.Pcs;
                            } else if (xT.Attributes["type"].Value == Enums.PhoneType.Pref.ToString()) {
                                t.type = Enums.PhoneType.Pref;
                            } else if (xT.Attributes["type"].Value == Enums.PhoneType.Video.ToString()) {
                                t.type = Enums.PhoneType.Video;
                            } else if (xT.Attributes["type"].Value == Enums.PhoneType.Voice.ToString()) {
                                t.type = Enums.PhoneType.Voice;
                            } else {
                                t.type = Enums.PhoneType.None;
                            }
                            t.number = (xT.InnerText != null) ? xT.InnerText : string.Empty;
                            _telephone.Add(t);
                        }
                    }
                    _title = (vcard["title"].InnerText != null) ? vcard["title"].InnerText : string.Empty;
                    _url = (vcard["url"].InnerText != null) ? vcard["url"].InnerText : string.Empty;
                    onIdentityRetrieved();
                } catch {

                }
            } else {
                this.retrieve();
            }
        }