public Vcard Get(string username) { Vcard vcard = null; using (SqlDataContext dc = new SqlDataContext()) { try { var user = dc.DatabaseUserItems.Single(x => string.Compare(username, x.Username, true) == 0); var data = HeaderManager.Load(username); vcard = new Vcard(); vcard.Nickname = user.Nickname; vcard.Description = user.Signature; vcard.Jid = JIDEscaping.Escape(user.Username) + "@gjtalk.com"; vcard.AddEmail(new Email(user.Mail)); if (data != null) { vcard.Photo = new Photo(data, ImageFormat.Png); } } catch (System.Exception ex) { } } return(vcard); }
public void VCardTest() { storage.RemoveUser(username); var vcard1 = new Vcard { Fullname = username }; storage.SetVCard(username, vcard1); var vcard2 = storage.GetVCard(username); Assert.IsNull(vcard2); var u = new XmppUser(username, "password"); storage.SaveUser(u); vcard2 = storage.GetVCard(username); Assert.IsNull(vcard2); storage.SetVCard(username, vcard1); vcard2 = storage.GetVCard(username); Assert.AreEqual(vcard1.ToString(), vcard2.ToString()); vcard2 = storage.GetVCard("sss"); Assert.IsNull(vcard2); storage.SetVCard(username, null); vcard2 = storage.GetVCard(username); Assert.IsNull(vcard2); storage.RemoveUser(username); }
/// <summary> /// The xmpp on on registered. /// </summary> /// <param name="sender"> /// The sender. /// </param> private void XmppOnOnRegistered(object sender) { this.myPresence.Type = PresenceType.available; this.myPresence.Show = ShowType.chat; this.MucManager = new MucManager(this.xmpp); var room = new Jid("lobby@conference." + this.Config.ChatHost); this.MucManager.AcceptDefaultConfiguration(room); // MucManager.JoinRoom(room,Username,Password,false); this.Me = new User(this.xmpp.MyJID); this.Me.SetStatus(UserStatus.Online); this.xmpp.PresenceManager.Subscribe(this.xmpp.MyJID); var v = new Vcard(); var e = new Email { UserId = this.email, Type = EmailType.INTERNET, Value = this.email }; v.AddChild(e); v.JabberId = new Jid(this.Username + "@" + this.Config.ChatHost); var vc = new VcardIq(IqType.set, v); vc.To = this.Config.ChatHost; vc.GenerateId(); this.xmpp.Send(vc); if (this.OnRegisterComplete != null) { this.OnRegisterComplete.Invoke(this, RegisterResults.Success); } }
private void VcardResult(object sender, IQ iq, object data) { if (InvokeRequired) { // Windows Forms are not Thread Safe, we need to invoke this :( // We're not in the UI thread, so we need to call BeginInvoke BeginInvoke(new IqCB(VcardResult), new object[] { sender, iq, data }); return; } if (iq.Type == IqType.result) { Vcard vcard = iq.Vcard; if (vcard != null) { txtFullname.Text = vcard.Fullname; txtNickname.Text = vcard.Nickname; txtBirthday.Text = vcard.Birthday.ToString(); txtDescription.Text = vcard.Description; Photo photo = vcard.Photo; if (photo != null) picPhoto.Image = vcard.Photo.Image; } } }
public virtual void SetVCard(Jid jid, Vcard vcard) { if (jid == null) { throw new ArgumentNullException("jid"); } if (vcard == null) { throw new ArgumentNullException("vcard"); } try { ExecuteNonQuery( new SqlInsert("jabber_vcard", true) .InColumnValue("jid", jid.Bare.ToLowerInvariant()) .InColumnValue("vcard", ElementSerializer.SerializeElement(vcard))); lock (vcardsCache) { vcardsCache[jid.Bare.ToLowerInvariant()] = vcard; } } catch (Exception e) { throw new JabberException("Could not save VCard.", e); } }
public void SetVCard(string user, Vcard vcard) { if (string.IsNullOrEmpty(user)) { throw new ArgumentNullException("user"); } if (vcard == null) { throw new ArgumentNullException("vcard"); } if (CoreContext.UserManager.IsUserNameExists(user)) { throw new JabberForbiddenException(); } try { lock (vcardsCache) { ExecuteNonQuery("insert or replace into VCard(UserName, VCard) values (@userName, @vCard)", new[] { "userName", "vCard" }, new object[] { user, ElementSerializer.SerializeElement(vcard) } ); vcardsCache[user] = vcard; } } catch (Exception e) { throw new JabberServiceUnavailableException("Could not set vcard", e); } }
public static string ExportVcard(IList <string> lists, string suffix) { var file = GetRandomPath(suffix, "vcf"); Vcard.Export(lists, file); return(file); }
public override Vcard GetVCard(Jid jid) { ASCContext.SetCurrentTenant(jid.Server); jid = new Jid(jid.Bare.ToLowerInvariant()); var ui = ASCContext.UserManager.GetUserByUserName(jid.User); if (ui != null) { var vcard = (Vcard)cache.Get(jid.ToString()); if (vcard != null) { return(vcard); } vcard = new Vcard(); vcard.Name = new Name(ui.LastName, ui.FirstName, null); vcard.Fullname = UserFormatter.GetUserName(ui); vcard.Nickname = ui.UserName; vcard.Description = ui.Notes; if (ui.BirthDate != null) { vcard.Birthday = ui.BirthDate.Value; } vcard.JabberId = jid; if (ui.Sex.HasValue) { vcard.Gender = ui.Sex.Value ? Gender.MALE : Gender.FEMALE; } var index = ui.Contacts.FindIndex(c => string.Compare(c, "phone", true) == 0) + 1; if (0 < index && index < ui.Contacts.Count) { vcard.AddTelephoneNumber(new Telephone(TelephoneLocation.WORK, TelephoneType.NUMBER, ui.Contacts[index])); } vcard.AddEmailAddress(new Email(EmailType.INTERNET, ui.Email, true)); var tenant = ASCContext.GetCurrentTenant(); var departments = string.Join(", ", CoreContext.UserManager.GetUserGroups(ui.ID).Select(d => HttpUtility.HtmlEncode(d.Name)).ToArray()); if (tenant != null) { vcard.Organization = new Organization(tenant.Name, departments); } vcard.Title = ui.Title; var image = PreparePhoto(ASCContext.UserManager.GetUserPhoto(ui.ID, Guid.Empty)); if (image != null) { vcard.Photo = new Photo(image, ImageFormat.Png); image.Dispose(); } cache.Insert(jid.ToString(), vcard, CACHE_TIMEOUT); return(vcard); } else { return(base.GetVCard(jid)); } }
public Vcard GetVCard(string user) { try { if (string.IsNullOrEmpty(user)) { throw new ArgumentNullException("user"); } if (CoreContext.UserManager.IsUserNameExists(user)) { var ui = CoreContext.UserManager.GetUserByUserName(user); var vcard = new Vcard(); vcard.Fullname = vcard.Nickname = string.Format("{0} {1}", ui.LastName, ui.FirstName); if (ui.BirthDate != null) { vcard.Birthday = ui.BirthDate.Value; } vcard.JabberId = new Jid(ui.UserName); vcard.AddTelephoneNumber(new Telephone(TelephoneLocation.WORK, TelephoneType.NUMBER, ui.PhoneOffice)); vcard.AddTelephoneNumber(new Telephone(TelephoneLocation.WORK, TelephoneType.FAX, ui.Fax)); vcard.AddTelephoneNumber(new Telephone(TelephoneLocation.HOME, TelephoneType.NUMBER, ui.PhoneHome)); vcard.AddTelephoneNumber(new Telephone(TelephoneLocation.HOME, TelephoneType.CELL, ui.PhoneMobile)); vcard.AddEmailAddress(new Email(EmailType.INTERNET, ui.Email, true)); vcard.Organization = new Organization(CoreContext.UserManager.GetCompanyName(), ui.Department); vcard.Title = ui.Title; vcard.AddAddress(new Address(AddressLocation.HOME, null, ui.PrimaryAddress, ui.City, ui.State, ui.PostalCode, ui.Country, true)); vcard.Description = ui.Notes; var image = PreparePhoto(CoreContext.UserManager.GetUserPhoto(ui.ID, Guid.Empty)); if (image != null) { vcard.Photo = new Photo(image, image.RawFormat); //image.Dispose(); } return(vcard); } else { lock (vcardsCache) { if (!vcardsCache.ContainsKey(user)) { var vcardStr = ExecuteScalar("select VCard from VCard where UserName = @userName", "userName", user) as string; vcardsCache[user] = !string.IsNullOrEmpty(vcardStr) ? ElementSerializer.DeSerializeElement <Vcard>(vcardStr) : null; } return(vcardsCache[user]); } } } catch (Exception e) { throw new JabberServiceUnavailableException("Could not get vcard", e); } }
public override void SetVCard(Jid jid, Vcard vcard) { ASCContext.SetCurrentTenant(jid.Server); if (ASCContext.UserManager.IsUserNameExists(jid.User)) { throw new JabberException(ErrorCode.Forbidden); } base.SetVCard(jid, vcard); }
public void SetVCard(string username, Vcard vcard) { CheckUsername(username); if (vcard == null) { elements.RemoveElements(new Jid(username), "vcard"); } else { elements.SaveElement(new Jid(username), "vcard", vcard); } }
public Vcard GetVCard(string user) { try { if (string.IsNullOrEmpty(user)) throw new ArgumentNullException("user"); if (CoreContext.UserManager.IsUserNameExists(user)) { var ui = CoreContext.UserManager.GetUserByUserName(user); var vcard = new Vcard(); //общие данные vcard.Fullname = vcard.Nickname = string.Format("{0} {1}", ui.LastName, ui.FirstName); if (ui.BirthDate != null) vcard.Birthday = ui.BirthDate.Value; vcard.JabberId = new Jid(ui.UserName); vcard.AddTelephoneNumber(new Telephone(TelephoneLocation.WORK, TelephoneType.NUMBER, ui.PhoneOffice)); vcard.AddTelephoneNumber(new Telephone(TelephoneLocation.WORK, TelephoneType.FAX, ui.Fax)); vcard.AddTelephoneNumber(new Telephone(TelephoneLocation.HOME, TelephoneType.NUMBER, ui.PhoneHome)); vcard.AddTelephoneNumber(new Telephone(TelephoneLocation.HOME, TelephoneType.CELL, ui.PhoneMobile)); vcard.AddEmailAddress(new Email(EmailType.INTERNET, ui.Email, true)); //организация vcard.Organization = new Organization(CoreContext.UserManager.GetCompanyName(), ui.Department); vcard.Title = ui.Title; //адрес vcard.AddAddress(new Address(AddressLocation.HOME, null, ui.PrimaryAddress, ui.City, ui.State, ui.PostalCode, ui.Country, true)); //о себе vcard.Description = ui.Notes; //фотография var image = PreparePhoto(CoreContext.UserManager.GetUserPhoto(ui.ID, Guid.Empty)); if (image != null) { vcard.Photo = new Photo(image, image.RawFormat); //image.Dispose(); } return vcard; } else { lock (vcardsCache) { if (!vcardsCache.ContainsKey(user)) { var vcardStr = ExecuteScalar("select VCard from VCard where UserName = @userName", "userName", user) as string; vcardsCache[user] = !string.IsNullOrEmpty(vcardStr) ? ElementSerializer.DeSerializeElement<Vcard>(vcardStr) : null; } return vcardsCache[user]; } } } catch (Exception e) { throw new JabberServiceUnavailableException("Could not get vcard", e); } }
public static Vcard CreateUserVcard(string username) { NetTalk.DAL.TbUsers user; NetTalk.BLL.Users api = new NetTalk.BLL.Users(); user = api.Find(username); Vcard card = null; if (user != null) { if (user.TbVcard != null) { card = new Vcard(); if (!string.IsNullOrEmpty(user.TbVcard.VcardEmail)) { card.AddEmailAddress(new agsXMPP.protocol.iq.vcard.Email(EmailType.NONE, user.TbVcard.VcardEmail, true)); } if (!string.IsNullOrEmpty(user.TbVcard.VcardTelFax)) { card.AddTelephoneNumber(new Telephone(TelephoneLocation.WORK, TelephoneType.FAX, "فکس: " + user.TbVcard.VcardTelFax)); } if (!string.IsNullOrEmpty(user.TbVcard.VcardTelCell)) { card.AddTelephoneNumber(new Telephone(TelephoneLocation.WORK, TelephoneType.CELL, "موبایل: " + user.TbVcard.VcardTelCell)); } if (!string.IsNullOrEmpty(user.TbVcard.VcardTelVoice)) { card.AddTelephoneNumber(new Telephone(TelephoneLocation.WORK, TelephoneType.VOICE, "داخلی: " + user.TbVcard.VcardTelVoice)); } if (!string.IsNullOrEmpty(user.TbVcard.VcardTelVoice2)) { card.AddTelephoneNumber(new Telephone(TelephoneLocation.WORK, TelephoneType.PREF, "مستقیم: " + user.TbVcard.VcardTelVoice2)); } card.Fullname = user.TbVcard.VcardFirstName + " " + user.TbVcard.VcardLastName; card.Name = new Name(user.TbVcard.VcardLastName, user.TbVcard.VcardFirstName, ""); //card.Organization = new Organization("شرکت خدمات انفورماتیک راهبر", cuser.ChatUserGroup); card.Nickname = username; card.JabberId = new agsXMPP.Jid(username + "@" + Config.AppSetting.domain); if (!string.IsNullOrEmpty(user.TbVcard.VcardPhoto)) { card.Photo = new Photo(); Element BINVAL = new Element("BINVAL"); BINVAL.Value = NetTalk.Web.Codes.ImageTools.ToBase64(user.TbVcard.VcardPhoto); card.Photo.AddChild(BINVAL); } } } return(card); }
static private void VcardResult(object sender, IQ iq, object data) { if (iq.Type == IqType.result) { Vcard vcard = iq.Vcard; if (vcard != null) { string fullname = vcard.Fullname; string nickname = vcard.Nickname; string description = vcard.Description; Photo photo = vcard.Photo; } } }
public void VCardTest() { var jid = new Jid("jid1", "s", "R1"); var vcard = new Vcard(); vcard.JabberId = jid; store.SetVCard(jid, vcard); var v = store.GetVCard(jid); Assert.IsNotNull(v); Assert.AreEqual(vcard.JabberId, v.JabberId); v = store.GetVCard(new Jid("jid2", "s", "R1")); Assert.IsNull(v); }
public bool Set(string username, Vcard vcard) { using (SqlDataContext dc = new SqlDataContext()) { try { var user = dc.DatabaseUserItems.Single(x => string.Compare(username, x.Username, true) == 0); user.Nickname = vcard.Nickname; user.Signature = vcard.Description; } catch (System.Exception ex) { return(false); } } return(true); }
public void SetVCard(string user, Vcard vcard) { if (string.IsNullOrEmpty(user)) throw new ArgumentNullException("user"); if (vcard == null) throw new ArgumentNullException("vcard"); lock (vcardsCache) { using (var connect = GetDbConnection()) using (var command = connect.CreateCommand()) { command.CommandText = "insert or replace into VCard(UserName, VCard) values (@userName, @vCard)"; AddCommandParameter(command, "userName", user); AddCommandParameter(command, "vCard", ElementSerializer.SerializeElement(vcard)); command.ExecuteNonQuery(); } vcardsCache[user] = vcard; } }
public bool Set(string username, Vcard vcard) { using (SqlDataContext dc=new SqlDataContext()) { try { var user = dc.DatabaseUserItems.Single(x => string.Compare(username, x.Username, true) == 0); user.Nickname = vcard.Nickname; user.Signature = vcard.Description; } catch (System.Exception ex) { return false; } } return true; }
public void PrivateStoreTest() { var jid = new Jid("n", "s", "r"); var el = new Vcard(); el.Fullname = "x"; store.SetPrivate(jid, el); var el2 = (Vcard)store.GetPrivate(jid, new Vcard()); Assert.AreEqual(el.Fullname, el2.Fullname); var el3 = store.GetPrivate(new Jid("n2", "s", "r"), new Vcard()); Assert.IsNull(el3); var el4 = store.GetPrivate(jid, new Roster()); Assert.IsNull(el4); }
public void SetVCard(string user, Vcard vcard) { if (string.IsNullOrEmpty(user)) throw new ArgumentNullException("user"); if (vcard == null) throw new ArgumentNullException("vcard"); if (CoreContext.UserManager.IsUserNameExists(user)) throw new JabberForbiddenException(); try { lock (vcardsCache) { ExecuteNonQuery("insert or replace into VCard(UserName, VCard) values (@userName, @vCard)", new[] { "userName", "vCard" }, new object[] { user, ElementSerializer.SerializeElement(vcard) } ); vcardsCache[user] = vcard; } } catch (Exception e) { throw new JabberServiceUnavailableException("Could not set vcard", e); } }
private void XmppOnOnRegistered(object sender) { Vcard v = new Vcard(); Email e = new Email { UserId = _email, Type = EmailType.INTERNET, Value = _email }; v.AddChild(e); v.JabberId = new Jid(this.Username + "@" + Host); VcardIq vc = new VcardIq(IqType.set, v); vc.To = Host; vc.GenerateId(); Xmpp.Send(vc); if (OnRegisterComplete != null) { OnRegisterComplete.Invoke(this, RegisterResults.Success); } }
private IQ SetVCardSearch(XmppStream stream, IQ iq, XmppHandlerContext context) { var answer = new IQ(IqType.result); answer.Id = iq.Id; answer.To = iq.From; answer.From = iq.To; var search = (Search)iq.Query; var pattern = new Vcard(); pattern.Nickname = search.Nickname; pattern.Name = new Name(search.Lastname, search.Firstname, null); //pattern.AddEmailAddress(new Email() { UserId = search.Email }); search = new Search(); foreach (var vcard in context.StorageManager.VCardStorage.Search(pattern)) { var item = new SearchItem(); item.Jid = vcard.JabberId; item.Nickname = vcard.Nickname; if (vcard.Name != null) { item.Firstname = vcard.Name.Given; item.Lastname = vcard.Name.Family; } var email = vcard.GetPreferedEmailAddress(); if (email != null) { item.Email = email.UserId; } search.AddChild(item); } answer.Query = search; return(answer); }
private void OnVcardResult(object sender, IQ iq, object data) { if (InvokeRequired) { BeginInvoke(new IqCB(OnVcardResult), new[] { sender, iq, data }); return; } if (iq.Type == IqType.result && iq.HasTag(typeof(Vcard))) { Vcard vcard = iq.Vcard; if (vcard != null) { if (iq.Id == _packetId) { pictureHead.Image = vcard.Photo.Image; labelControlName.Text = vcard.Nickname; } else { ChatListItem item = chatListBoxFriend.Items.Cast <ChatListItem>().FirstOrDefault(c => c.Text == data.ToString()); if (item != null) { ChatListSubItem subItem = item.SubItems.Cast <ChatListSubItem>().FirstOrDefault(sub => sub.JidUser == iq.From.Bare); if (subItem != null) { subItem.HeadImage = vcard.Photo.Image; subItem.NicName = vcard.Name.Given; subItem.DisplayName = vcard.Nickname; subItem.PersonalMsg = null; } } } } } }
public void SetVCard(string user, Vcard vcard) { if (string.IsNullOrEmpty(user)) { throw new ArgumentNullException("user"); } if (vcard == null) { throw new ArgumentNullException("vcard"); } lock (vcardsCache) { using (var connect = GetDbConnection()) using (var command = connect.CreateCommand()) { command.CommandText = "insert or replace into VCard(UserName, VCard) values (@userName, @vCard)"; AddCommandParameter(command, "userName", user); AddCommandParameter(command, "vCard", ElementSerializer.SerializeElement(vcard)); command.ExecuteNonQuery(); } vcardsCache[user] = vcard; } }
public Vcard Get(string username) { Vcard vcard = null; using (SqlDataContext dc=new SqlDataContext()) { try { var user = dc.DatabaseUserItems.Single(x => string.Compare(username, x.Username, true) == 0); var data=HeaderManager.Load(username); vcard = new Vcard(); vcard.Nickname = user.Nickname; vcard.Description = user.Signature; vcard.Jid = JIDEscaping.Escape(user.Username) + "@gjtalk.com"; vcard.AddEmail(new Email(user.Mail)); if (data != null) vcard.Photo = new Photo(data, ImageFormat.Png); } catch (System.Exception ex) { } } return vcard; }
public override ICollection <Vcard> Search(Vcard pattern) { throw new NotImplementedException(); }
public virtual ICollection <Vcard> Search(Vcard pattern) { return(new Vcard[0]); }
public bool Set(Jid jid, Vcard vcard) { return Set(JIDEscaping.Unescape(jid), vcard); }
public bool Set(Jid jid, Vcard vcard) { return(Set(JIDEscaping.Unescape(jid), vcard)); }
public VcardResult(Vcard card) { _card = card; }