Exemplo n.º 1
0
        protected void BroadcastToClient(ClientAction action, params object[] args)
        {
            for (int index = 0; index < _clientList.Count; index++)
            {
                try
                {
                    var client = _clientList[index];

                    string errorMessage = client.OpenTransaction();

                    if (string.IsNullOrEmpty(errorMessage) == false)
                    {
                        ServerLogger.logError("[BroadcastToClient]", string.Format(CLIENT_ERROR_FORMAT, errorMessage));
                        continue;
                    }

                    string result = SendNotifyToClient(client, action, args);
                    ServerLogger.logInfo("[BroadcastToClient]", string.Format(CLIENT_RESULT_FORMAT, result));

                    client.CloseTransaction();
                }
                catch (Exception exc)
                {
                    ServerLogger.logError("[BroadcastToClient]", exc);
                }
            }
        }
        public TUser Login(string userName, string password, string senderIP, string senderPort)
        {
            try
            {
                ServerLogger.logInfo("Login", string.Format("User login [{0}] - [{1}] - [{2}] - [{3}]", userName, password, senderIP, senderPort), serverView);
                using (UserBusiness business = new UserBusiness())
                {
                    //bool loginSuccess = business.Users.Any(u => u.user_name == userName && u.password == password && u.active_status && !u.deleted);
                    User user = business.ValidateUser(userName, password, Constants.UserRole.Staff.ToString());

                    if (user == null)
                    {
                        string failMessage = "Login Fail";
                        //if (user == null) failMessage = "Không tồn tại người dùng: " + userName;
                        //else if (user.password != password) failMessage = "Nhập sai mật khẩu";
                        //else if (user.active_status == false) failMessage = "Người dùng này đã bị khóa.";

                        ServerLogger.logInfo("Login", string.Format("login result: {0}", failMessage), serverView);
                        return(new TUser());
                    }

                    AddClientStation(userName, senderIP, int.Parse(senderPort));

                    return(ThriftUtil.ConvertToTUser(user));
                }
            }
            catch (Exception exc)
            {
                ServerLogger.logError("[Login]", exc);
                return(new TUser());
            }
        }
        public string Logout(string userName, string senderIP, string senderPort)
        {
            try
            {
                ServerLogger.logInfo("Login", string.Format("User Logout [userName: {0}] - [Port: {1}]", userName, senderPort), serverView);

                ClientStation client = _clientList.FirstOrDefault(c => c.UserName == userName && c.IPAddress == senderIP && c.Port == int.Parse(senderPort));
                if (client != null)
                {
                    _clientList.Remove(client);
                    return("");
                }
                return("Người dùng này chưa được Đăng Nhập");
            }
            catch (Exception exc)
            {
                ServerLogger.logError("[Logout]", exc);
                return(exc.Message);
            }
        }
Exemplo n.º 4
0
        private void StartServer()
        {
            try
            {
                string startMessage = string.Format("server start with IP: {0} - Port: {1}", _serverIP, _serverPort);

                ServerLogger.logInfo("StartServer", startMessage);
                btnStart.Visible = false;
                btnStop.Visible  = true;

                _serverThread = new Thread(new ThreadStart(InitTransportService));
                _serverThread.Start();

                OutputAction(startMessage);
            }
            catch (Exception exc)
            {
                ServerLogger.logError("[StopServer]", exc);
            }
        }