private void OnErrorRaised(Enumerations.ErrorType type, string message) { try { ErrorRaised(type, message); } catch { } }
/// <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); }
/// <summary> /// Change l'�tat de son status /// </summary> public void applyStatus() { if (Jabber.xmpp.Authenticated) { agsXMPP.protocol.client.Presence p = new agsXMPP.protocol.client.Presence(); p.From = Jabber.xmpp.MyJID; p.Priority = Jabber.xmpp.Priority; p.Type = Enumerations.PresenceTypeConverter(_status.type); if (p.Type == agsXMPP.protocol.client.PresenceType.available) { p.Show = Enumerations.StatusTypeConverter(_status.type); p.Status = _status.message; p.XDelay = new agsXMPP.protocol.x.Delay(); p.XDelay.Stamp = DateTime.Now; p.AddChild(Queries.getCapabilities()); Jabber.xmpp.Show = p.Show; Jabber.xmpp.Status = p.Status; p.Nickname = new agsXMPP.protocol.extensions.nickname.Nickname(Jabber._identity.nickname); } Jabber.xmpp.Send(p); } }
/// <summary> /// Change son activit� /// </summary> /// <param name="type">Type de l'activit�</param> /// <param name="text">Description</param> public void setActivity(Enumerations.ActivityType type, string text) { if (Jabber.xmpp.Authenticated && Jabber._pepCapable) { agsXMPP.protocol.client.IQ iq = new agsXMPP.protocol.client.IQ(); iq.Type = agsXMPP.protocol.client.IqType.set; iq.GenerateId(); agsXMPP.Xml.Dom.Element pb = new agsXMPP.Xml.Dom.Element("pubsub"); pb.Namespace = "http://jabber.org/protocol/pubsub"; agsXMPP.Xml.Dom.Element ps = new agsXMPP.Xml.Dom.Element("publish"); ps.Attributes.Add("node", "http://jabber.org/protocol/activity"); agsXMPP.Xml.Dom.Element item = new agsXMPP.Xml.Dom.Element("item"); item.Attributes.Add("id", "current"); agsXMPP.Xml.Dom.Element activity = new agsXMPP.Xml.Dom.Element("activity"); activity.Namespace = "http://jabber.org/protocol/activity"; agsXMPP.Xml.Dom.Element activityType = new agsXMPP.Xml.Dom.Element(Enum.GetName(typeof(Enumerations.ActivityType), type)); activity.AddChild(activityType); agsXMPP.Xml.Dom.Element activityText = new agsXMPP.Xml.Dom.Element("text"); activityText.Value = text; activity.AddChild(activityText); item.AddChild(activity); ps.AddChild(item); pb.AddChild(ps); agsXMPP.Xml.Dom.Element conf = new agsXMPP.Xml.Dom.Element("configure"); agsXMPP.Xml.Dom.Element x = new agsXMPP.Xml.Dom.Element("x"); agsXMPP.Xml.Dom.Element field1 = new agsXMPP.Xml.Dom.Element("field"); field1.Attributes.Add("type", "hidden"); field1.Attributes.Add("var", "FORM_TYPE"); agsXMPP.Xml.Dom.Element value1 = new agsXMPP.Xml.Dom.Element("value"); value1.Value = "http://jabber.org/protocol/pubsub#node_config"; field1.AddChild(value1); x.AddChild(field1); agsXMPP.Xml.Dom.Element field2 = new agsXMPP.Xml.Dom.Element("field"); field2.Attributes.Add("var", "pubsub#access_model"); agsXMPP.Xml.Dom.Element value2 = new agsXMPP.Xml.Dom.Element("value"); value2.Value = "presence"; field2.AddChild(value2); x.AddChild(field2); conf.AddChild(x); pb.AddChild(conf); iq.AddChild(pb); Jabber.xmpp.Send(iq); _activity = new Activity(); _activity.type = type; _activity.text = text; } }
/// <summary> /// Provoque un �v�nement d'erreur personnalis� /// </summary> /// <param name="type">Type de l'erreur</param> /// <param name="message">Description de l'erreur</param> public void custom(Enumerations.ErrorType type, string message) { OnErrorRaised(type, message); }
/// <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); } }