예제 #1
0
        public static void Avatar(string username, IQ iq)
        {
            DAL.TbUsers cuser;
            BLL.Users   api = new BLL.Users();
            switch (iq.Type)
            {
            case IqType.get:
                if (iq.To != null)
                {
                    cuser = api.Find(iq.To.User);
                }
                else
                {
                    cuser = api.Find(username);
                }

                if (cuser != null)
                {
                    if (!string.IsNullOrEmpty(cuser.TbVcard.VcardPhoto))
                    {
                        iq.SwitchDirection();
                        iq.Type            = IqType.result;
                        iq.Query.Namespace = "jabber:iq:avatar";
                        iq.Query.ChildNodes.Clear();
                        Element dataEl = new Element("data");
                        dataEl.Value = ImageTools.ToBase64(cuser.TbVcard.VcardPhoto);

                        iq.Query.AddChild(dataEl);
                        int index;
                        if (ThreadTools.Users.Online.IsAuthenticated(username, out index))
                        {
                            ThreadTools.Users.Online[index].Send(iq);
                        }
                    }
                }
                break;

            case IqType.set:
            case IqType.result:
                if (iq.Query.HasTag("data"))
                {
                    Element el = iq.Query.SelectSingleElement("data");
                    cuser = api.Find(username);
                    string pname;
                    bool   isSaved;
                    pname = ImageTools.SaveAvatar(el.Value, out isSaved);
                    if (isSaved)
                    {
                        api.ChangeUserPicture(username, pname);
                        Rosters.SendStatus(username);
                    }
                }
                break;
            }
        }
예제 #2
0
        public static void Write(string SID, string txt)
        {
            int index;

            if (Codes.ThreadTools.Users.Online.IsSessionExists(SID, out index))
            {
                Guid?UserId = null;
                if (!string.IsNullOrEmpty(Codes.ThreadTools.Users.Online[index].Username))
                {
                    BLL.Users   api  = new BLL.Users();
                    DAL.TbUsers user = api.Find(Codes.ThreadTools.Users.Online[index].Username);
                    if (user != null)
                    {
                        UserId = user.UserId;
                    }
                }

                Api.Insert(Codes.ThreadTools.Users.Online[index].IPAddress,
                           SID, UserId, txt);
            }
            else
            {
                Api.Insert(null, null, null, txt);
            }
        }