Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public static void SendInfo(string fromuser, string touser)
        {
            int FromUserIndex;

            ThreadTools.Users.Online.IsAuthenticated(fromuser, out FromUserIndex);

            NetTalk.BLL.Users   apiusers = new NetTalk.BLL.Users();
            NetTalk.DAL.TbUsers user     = apiusers.Find(touser);
            if (user != null)
            {
                string CardDataHtml = "<p>", CardDataText = "";


                if (user.TbVcard != null)
                {
                    if (!string.IsNullOrEmpty(user.TbVcard.VcardEmail))
                    {
                        CardDataHtml += "ایمیل: " + user.TbVcard.VcardEmail + "<br />";
                        CardDataText += "ایمیل: " + user.TbVcard.VcardEmail + ",";
                    }
                    if (!string.IsNullOrEmpty(user.TbVcard.VcardTelFax))
                    {
                        CardDataHtml += "فکس: " + user.TbVcard.VcardTelFax + "<br />";
                        CardDataText += "فکس: " + user.TbVcard.VcardTelFax + ",";
                    }
                    if (!string.IsNullOrEmpty(user.TbVcard.VcardTelCell))
                    {
                        CardDataHtml += "موبایل: " + user.TbVcard.VcardTelCell + "<br />";
                        CardDataText += "موبایل: " + user.TbVcard.VcardTelCell + ",";
                    }
                    if (!string.IsNullOrEmpty(user.TbVcard.VcardTelVoice))
                    {
                        CardDataHtml += "داخلی: " + user.TbVcard.VcardTelVoice + "<br />";
                        CardDataText += "داخلی: " + user.TbVcard.VcardTelVoice + ",";
                    }
                    if (!string.IsNullOrEmpty(user.TbVcard.VcardTelVoice2))
                    {
                        CardDataHtml += "مستقیم: " + user.TbVcard.VcardTelVoice2 + "<br />";
                        CardDataText += "مستقیم: " + user.TbVcard.VcardTelVoice2 + ",";
                    }
                }
                CardDataHtml += "</p>";

                ThreadTools.Users.Online[FromUserIndex].Send(
                    XML.Messages.Create(touser, fromuser, CardDataText, CardDataHtml, null));
            }
        }
Exemplo n.º 3
0
        public static string LastActivity(string fromuser, string touser)
        {
            IQ iq = new IQ();

            iq.From = new agsXMPP.Jid(touser + "@" + Config.AppSetting.domain);
            iq.To   = new agsXMPP.Jid(fromuser + "@" + Config.AppSetting.domain);
            Last lt = new Last();

            NetTalk.BLL.Users ApiUser = new NetTalk.BLL.Users();
            DateTime          dt      = ApiUser.LastActivity(touser);
            TimeSpan          sp      = DateTime.Now - dt;

            lt.Seconds = Convert.ToInt32(Math.Ceiling(sp.TotalSeconds));
            iq.Type    = IqType.result;
            iq.Query   = lt;

            return(iq.ToString());
        }
Exemplo n.º 4
0
        public static string FriendStatus(string username)
        {
            NetTalk.BLL.Users           api          = new NetTalk.BLL.Users();
            List <NetTalk.DAL.VwFriend> OnlineFriend = api.ListOnlinFriend(username);

            ShowType     userShowType;
            PresenceType userIsOnline;
            Presence     p;

            string list           = "";
            string userStatusText = "";

            for (int i = 0; i < OnlineFriend.Count; i++)
            {
                userStatusText = OnlineFriend[i].UserStatusText;
                userIsOnline   = PresenceType.available;
                userShowType   = (ShowType)OnlineFriend[i].UserStatus;

                p      = new Presence();
                p.From = new agsXMPP.Jid(OnlineFriend[i].FriendUserName + "@" + Config.AppSetting.domain);
                p.To   = new agsXMPP.Jid(username + "@" + Config.AppSetting.domain);
                p.Type = userIsOnline;
                p.Show = userShowType;
                if (!string.IsNullOrEmpty(userStatusText))
                {
                    p.Status = userStatusText;
                }
                if (!string.IsNullOrEmpty(OnlineFriend[i].VcardPhoto))
                {
                    Element xtag = new Element("x");
                    xtag.Namespace = "vcard-temp:x:update";
                    Element photo = new Element("photo");
                    photo.Value = OnlineFriend[i].VcardPhoto;
                    xtag.AddChild(photo);
                    p.AddChild(xtag);
                }

                list += p.ToString();
            }

            return(list);
        }
Exemplo n.º 5
0
        public static void SendStatus(string username)
        {
            NetTalk.BLL.Users           api          = new NetTalk.BLL.Users();
            List <NetTalk.DAL.VwFriend> OnlineFriend = api.ListOnlinFriend(username);

            Presence pre = GetPresence(username);

            pre.From = new agsXMPP.Jid(username + "@" + Config.AppSetting.domain);

            int index;

            foreach (NetTalk.DAL.VwFriend f in OnlineFriend)
            {
                if (ThreadTools.Users.Online.IsAuthenticated(f.FriendUserName, out index))
                {
                    pre.To = new agsXMPP.Jid(f.FriendUserName + "@" + Config.AppSetting.domain);
                    ThreadTools.Users.Online[index].Send(pre);
                }
            }
        }
Exemplo n.º 6
0
        public static Presence GetPresence(string username)
        {
            Presence p = new Presence();

            NetTalk.BLL.Users   api  = new NetTalk.BLL.Users();
            NetTalk.DAL.TbUsers user = api.Find(username);

            p.Show   = GetShowType(user.TbUserStatus.UserStatus);
            p.Type   = (user.TbUserStatus.UserIsOnline) ? PresenceType.available : PresenceType.unavailable;
            p.Status = user.TbUserStatus.UserStatusText;

            if (!string.IsNullOrEmpty(user.TbVcard.VcardPhoto))
            {
                Element xtag = new Element("x");
                xtag.Namespace = "vcard-temp:x:update";
                Element photo = new Element("photo");
                photo.Value = user.TbVcard.VcardPhoto;
                xtag.AddChild(photo);
                p.AddChild(xtag);
            }

            return(p);
        }
Exemplo n.º 7
0
 public static void GetUserPicture(string username, Presence pren)
 {
     if (Config.AppSetting.access.changepic)
     {
         Element             av = pren.SelectSingleElement("x");
         NetTalk.DAL.TbUsers user;
         NetTalk.BLL.Users   api = new NetTalk.BLL.Users();
         user = api.Find(username);
         if (user != null)
         {
             if (av.HasTag("hash"))
             {
                 if (user.TbVcard != null)
                 {
                     Element elhash = av.SelectSingleElement("hash");
                     if (!elhash.Value.Equals(user.TbVcard.VcardPhoto))
                     {
                         IQ uav = new IQ();
                         uav.Vcard = new Vcard();
                         uav.Type  = IqType.get;
                         int Index;
                         ThreadTools.Users.Online.IsAuthenticated(username, out Index);
                         if (Index > -1)
                         {
                             ThreadTools.Users.Online[Index].Send(uav);
                         }
                     }
                 }
             }
             else
             {
                 api.ChangeUserPicture(username, null);
             }
         }
     }
 }
Exemplo n.º 8
0
        public static void PresenceProccessTypes(string username, Presence pre)
        {
            NetTalk.BLL.Users api;
            switch (pre.Type)
            {
            case PresenceType.available:
                ShowType show       = ShowType.NONE;
                string   StatusText = string.Empty;
                if (!string.IsNullOrEmpty(pre.Status))
                {
                    StatusText = pre.Status;
                }
                if (pre.HasTag("show"))
                {
                    show = pre.Show;
                }

                int UserIndex;
                ThreadTools.Users.Online.IsAuthenticated(username, out UserIndex);
                if (UserIndex > -1)
                {
                    ThreadTools.Users.Online[UserIndex].UserStatus     = show;
                    ThreadTools.Users.Online[UserIndex].UserStatusText = StatusText;
                }
                ChangeStatus(username, StatusText, show, (UserIndex > -1));
                SendStatus(username);

                break;

            case PresenceType.subscribe:
                if (pre.To != null)
                {
                    if (!string.IsNullOrEmpty(pre.To.User))
                    {
                        api = new NetTalk.BLL.Users();
                        NetTalk.DAL.TbFriend f = api.FindFriend(username, pre.To.User);
                        if (f == null)
                        {
                            api.AddFriend(username, pre.To.User, "");
                            int FIndexSubscribe;
                            if (ThreadTools.Users.Online.IsAuthenticated(pre.To.User, out FIndexSubscribe))
                            {
                                ThreadTools.Users.Online[FIndexSubscribe].Send(pre);
                            }
                        }
                    }
                }
                break;

            case PresenceType.subscribed:
                api = new NetTalk.BLL.Users();
                if (pre.To != null)
                {
                    if (!string.IsNullOrEmpty(pre.To.User))
                    {
                        api.ChangeFriendStatus(username, pre.To.User, "", (byte)2);
                        api.ChangeFriendStatus(pre.To.User, username, "", (byte)2);
                        int FUserSub, UserSub;
                        if (ThreadTools.Users.Online.IsAuthenticated(pre.To.User, out FUserSub))
                        {
                            ThreadTools.Users.Online[FUserSub].Send(pre);
                            ThreadTools.Users.Online[FUserSub].Send(GetPresence(username));
                        }
                        if (ThreadTools.Users.Online.IsAuthenticated(username, out UserSub))
                        {
                            ThreadTools.Users.Online[UserSub].Send(GetPresence(pre.To.User));
                        }
                    }
                }
                break;

            case PresenceType.unsubscribe:
            case PresenceType.unsubscribed:
                api = new NetTalk.BLL.Users();
                if (pre.To != null)
                {
                    if (!string.IsNullOrEmpty(pre.To.User))
                    {
                        api.DeleteFriend(username, pre.To.User);
                    }
                }
                break;
            }
        }
Exemplo n.º 9
0
 public static void ChangeStatus(string username, string statustext, ShowType show, bool IsOnline)
 {
     NetTalk.BLL.Users api = new NetTalk.BLL.Users();
     api.ChangeUserStatus(username, statustext, (short)show, IsOnline);
 }
Exemplo n.º 10
0
        public static void SubmitChangePassForm(string username, IQ formdata)
        {
            ErrorCondition Error = ErrorCondition.NotAllowed;
            Register       reg   = formdata.Query as Register;

            if (formdata.Type == IqType.set)
            {
                if (reg.HasTag("x"))
                {
                    if (reg.Data.Type == XDataFormType.submit)
                    {
                        Field oldpass = reg.Data.GetField("oldpassword");
                        Field pass    = reg.Data.GetField("password");
                        if (oldpass != null && pass != null)
                        {
                            if (!string.IsNullOrEmpty(oldpass.Value) && !string.IsNullOrEmpty(pass.Value))
                            {
                                NetTalk.BLL.Users     api    = new NetTalk.BLL.Users();
                                NetTalk.BLL.BLLResult result = api.ChangePassword(username, oldpass.Value, pass.Value);
                                if (!result.IsSuccess)
                                {
                                    Error = ErrorCondition.NotAcceptable;
                                }
                            }
                            else
                            {
                                Error = ErrorCondition.NotAcceptable;
                            }
                        }
                        else
                        {
                            Error = ErrorCondition.Forbidden;
                        }
                    }
                    else
                    {
                        Error = ErrorCondition.Forbidden;
                    }
                }
                else
                {
                    Error = ErrorCondition.Forbidden;
                }
            }
            else
            {
                Error = ErrorCondition.FeatureNotImplemented;
            }

            int cindex;

            if (ThreadTools.Users.Online.IsAuthenticated(username, out cindex))
            {
                switch (Error)
                {
                case ErrorCondition.NotAcceptable:
                    IQ eiq = new IQ();
                    if (formdata.HasAttribute("id"))
                    {
                        eiq.Id = formdata.Id;
                    }
                    eiq.Type            = IqType.error;
                    eiq.Error           = new agsXMPP.protocol.client.Error();
                    eiq.Error.Type      = ErrorType.modify;
                    eiq.Error.Condition = ErrorCondition.NotAcceptable;
                    eiq.Error.Code      = ErrorCode.NotAcceptable;

                    ThreadTools.Users.Online[cindex].Send(eiq);
                    break;

                case ErrorCondition.Forbidden:
                    ThreadTools.Users.Online[cindex].Send(SendChangePassForm(username, formdata.Id));
                    break;

                case ErrorCondition.FeatureNotImplemented:
                    IQ eiq2 = new IQ();
                    if (formdata.HasAttribute("id"))
                    {
                        eiq2.Id = formdata.Id;
                    }
                    eiq2.Type            = IqType.error;
                    eiq2.Error           = new agsXMPP.protocol.client.Error();
                    eiq2.Error.Type      = ErrorType.modify;
                    eiq2.Error.Condition = ErrorCondition.FeatureNotImplemented;
                    eiq2.Error.Code      = ErrorCode.NotImplemented;

                    ThreadTools.Users.Online[cindex].Send(eiq2);
                    break;

                default:
                    IQ success = new IQ();
                    if (formdata.HasAttribute("id"))
                    {
                        success.Id = formdata.Id;
                    }
                    success.Type = IqType.result;
                    ThreadTools.Users.Online[cindex].Send(success);
                    break;
                }
            }
        }