示例#1
0
        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));
            }
        }
示例#2
0
        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);
            }
        }
示例#3
0
        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);
        }
示例#4
0
		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);
			}
		}