Exemple #1
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (AMS.Web.RemoteScripting.InvokeMethod(this))            //if this is a callback function return
            {
                return;
            }

            txtMsg.Attributes.Add("onkeypress", "return clickButton(event,'btn')");

            if (!IsPostBack)
            {
                if (Request.QueryString["userid"] != null && Request.QueryString["userid"] != "")
                {
                    otherUser.Value = Request.QueryString["userid"];
                    ChatRoom room = ChatEngine.GetRoom(Session["UserName"].ToString(), Request.QueryString["userid"]);
                    string   s    = room.JoinRoom(Session["UserName"].ToString(), Session["UserName"].ToString());
                    txt.InnerText = s;
                    //	string strScript="<script>startTimer();</script>";
                    //	this.RegisterClientScriptBlock("timerScript",strScript);
                }
                else
                {
                    Response.Write("User id Missing");
                    pnlChat.Visible = false;
                }
            }
        }
Exemple #2
0
        public ChatRoom(string user1ID, string user1Name, string user2ID, string user2Name)

        {
            this.messages = new ArrayList();

            this.RoomID = ChatEngine.CreateRoomID(user1ID, user2ID);

            this.FirstUser = new ChatUser(user1ID, user1Name);

            this.SecondUser = new ChatUser(user2ID, user2Name);
        }
Exemple #3
0
 protected void btnExit_Click(object sender, System.EventArgs e)
 {
     try
     {
         ChatRoom room = ChatEngine.GetRoom(Session["UserName"].ToString(), Request.QueryString["userid"]);
         room.LeaveRoom(Session["UserName"].ToString());
         //	string  strScript = "<script language=javascript>self.close();</script>";
         //	RegisterClientScriptBlock("anything", strScript);
         Response.Redirect("default.aspx");
     }
     catch (Exception ex)
     {
     }
 }
Exemple #4
0
 /// <summary>
 /// This function is called from the client when the user is about to leave the room
 /// </summary>
 /// <param name="otherUser"></param>
 /// <returns></returns>
 public string LeaveRoom(string otherUser)
 {
     try
     {
         ChatRoom room = ChatEngine.GetRoom(Session["UserName"].ToString(), otherUser);
         if (room != null)
         {
             room.LeaveRoom(Session["UserName"].ToString());
         }
     }
     catch (Exception ex)
     {
     }
     return("");
 }
Exemple #5
0
 /// <summary>
 /// This function is called from the client script
 /// </summary>
 /// <param name="msg"></param>
 /// <param name="toUserID"></param>
 /// <returns></returns>
 public string SendMessage(string msg, string toUserID)
 {
     try
     {
         ChatRoom room = ChatEngine.GetRoom(Session["UserName"].ToString(), toUserID);
         string   res  = "";
         if (room != null)
         {
             res = room.SendMessage(msg, Session["UserName"].ToString(), toUserID);
         }
         return(res);
     }
     catch (Exception ex)
     {
     }
     return("");
 }
Exemple #6
0
 /// <summary>
 /// This function is called peridically called from the user to update the messages
 /// </summary>
 /// <param name="otherUserID"></param>
 /// <returns></returns>
 public string UpdateUser(string otherUserID)
 {
     try
     {
         ChatRoom room = ChatEngine.GetRoom(Session["UserName"].ToString(), otherUserID);
         if (room != null)
         {
             string res = "";
             if (room != null)
             {
                 res = room.UpdateUser(Session["UserName"].ToString());
             }
             return(res);
         }
     }
     catch (Exception ex)
     {
     }
     return("");
 }
Exemple #7
0
        /// <summary>
        /// Marks the user as inactive
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public void LeaveRoom(string userID)
        {
            //deactivate user
            ChatUser user = this.GetUser(userID);

            if (user == null)
            {
                return;
            }
            user.IsActive = false;
            user.LastSeen = DateTime.Now;
            this.RoomUsers.Remove(userID);

            //Add leaving message
            Message msg = new Message(user.UserName, "", MsgType.Left);

            this.AddMsg(msg);

            if (IsEmpty())
            {
                ChatEngine.DeleteRoom(this.RoomID);
            }
        }
Exemple #8
0
        //

        /// <summary>

        /// Marks the user as inactive

        /// </summary>

        /// <param name="userID"></param>

        /// <returns></returns>

        public string LeaveRoom(string userID)

        {
            //deactivate user

            ChatUser user = this.GetUser(userID);

            user.IsActive = false;

            user.LastSeen = DateTime.Now;


            //Add leaving message

            Message msg = new Message(user.UserName, "", MsgType.Left);

            this.AddMsg(msg);

            //Get all the messages to the user

            int lastMsgID;

            ArrayList previousMsgs = this.GetMessagesSince(user.LastMessageReceived, out lastMsgID);

            user.LastMessageReceived = lastMsgID;

            //return the messages to the user

            string str = GenerateMessagesString(previousMsgs);

            if (IsEmpty())
            {
                ChatEngine.DeleteRoom(this.RoomID);
            }

            return("");
        }