Ejemplo n.º 1
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(Enumerations.EmailTypeConverter(m.type), m.address, false));
     }
     foreach (Telehone t in telephone)
     {
         vcard.AddTelephoneNumber(new agsXMPP.protocol.iq.vcard.Telephone(Enumerations.LocationTypeConverter(t.location), Enumerations.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     = Enumerations.AddressLocationTypeConverter(a.location);
         ad.PostalCode   = a.zipcode;
         ad.Region       = a.region;
         ad.Street       = a.street;
         vcard.AddAddress(ad);
     }
     return(vcard);
 }
Ejemplo n.º 2
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)
            {
                throw new Exception(iq.Error.Code.ToString() + " - " + iq.Error.Message);
            }
            // 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;
                    nickname           = (iq.Vcard.Nickname != null) ? iq.Vcard.Nickname.Trim() : string.Empty;
                    _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    = Enumerations.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 = Enumerations.LocationTypeConverter(phone.Location);
                                t.type     = Enumerations.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 = Enumerations.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);
            }
        }