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>
 /// Convertit la fiche d'identité au format utilisé par la librairie agsXMPP
 /// </summary>
 /// <returns>Carte de visite</returns>
 public agsXMPP.protocol.iq.vcard.Vcard toVcard()
 {
     agsXMPP.protocol.iq.vcard.Vcard vcard = new agsXMPP.protocol.iq.vcard.Vcard();
     vcard.Birthday     = birthday;
     vcard.Description  = description;
     vcard.Fullname     = fullname;
     vcard.JabberId     = new agsXMPP.Jid(jabberID.full);
     vcard.Name         = new agsXMPP.protocol.iq.vcard.Name(name.lastname, name.firstname, name.middle);
     vcard.Nickname     = nickname;
     vcard.Organization = new agsXMPP.protocol.iq.vcard.Organization(organization.name, organization.unit);
     if (photoFormat != null)
     {
         vcard.Photo = new agsXMPP.protocol.iq.vcard.Photo(photo, photoFormat);
     }
     else
     {
         vcard.Photo = null;
     }
     vcard.Role  = role;
     vcard.Title = title;
     vcard.Url   = url;
     foreach (Email m in email)
     {
         vcard.AddEmailAddress(new agsXMPP.protocol.iq.vcard.Email(Enums.EmailTypeConverter(m.type), m.address, false));
     }
     foreach (Telehone t in telephone)
     {
         vcard.AddTelephoneNumber(new agsXMPP.protocol.iq.vcard.Telephone(Enums.LocationTypeConverter(t.location), Enums.PhoneTypeConverter(t.type), t.number));
     }
     foreach (Address a in address)
     {
         agsXMPP.protocol.iq.vcard.Address ad = new agsXMPP.protocol.iq.vcard.Address();
         ad.Country      = a.country;
         ad.ExtraAddress = a.extra;
         ad.Locality     = a.city;
         ad.Location     = Enums.AddressLocationTypeConverter(a.location);
         ad.PostalCode   = a.zipcode;
         ad.Region       = a.region;
         ad.Street       = a.street;
         vcard.AddAddress(ad);
     }
     return(vcard);
 }