Example #1
0
    public bool login(string number, string password)
    {
        _logedUser = "";
        _logedPassword = "";

        Connection conn = Connection.getInstance();
        MessageFactory messageFactory = MessageFactory.getInstance();
        string message = messageFactory.loginMessage(number, password);
        string response = conn.sendMessage(message);

        ServerResponse serverResponse = new ServerResponse(response);
        if (serverResponse.getType() == "login")
        {
            if (serverResponse.getParams()["result"] == "success")
            {
                _logedUser = number;
                _logedPassword = password;
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
Example #2
0
    public string createAccount(string number, string password, string name, string surname, string email)
    {
        Connection conn = Connection.getInstance();
        MessageFactory messageFactory = MessageFactory.getInstance();
        string message = messageFactory.createAccountMessage(number, password, name, surname, email);
        string response = conn.sendMessage(message);

        ServerResponse serverResponse = new ServerResponse(response);
        if (serverResponse.getType() == "createAccount")
        {
            return serverResponse.getParams()["result"];            
        }
        else
        {
            return "fail";
        }
    }
Example #3
0
    public void refreshContactsStatus(MainForm main)
    {
        List<Contact> list = contacts.getList();
        List<string> usernames = new List<string>();

        foreach (Contact user in list)
        {
            usernames.Add(user.login);
        }

        Connection conn = Connection.getInstance();
        MessageFactory messageFactory = MessageFactory.getInstance();
        string message = messageFactory.refreshContactsStatusMessage(usernames);
        string response = conn.sendMessage(message);

        ServerResponse serverResponse = new ServerResponse(response);

        ServerResponseParams par = serverResponse.getParams();
        int index = 0;
        foreach (string login in usernames)
        {
            //MessageBox.Show(login + " " + par[login]);
            main.updateStatus(login, index, par[login]);
            index++;
        }        
    }
Example #4
0
    public List<CommunicatorMessage> readMessages()
    {
        Connection conn = Connection.getInstance();
        MessageFactory messageFactory = MessageFactory.getInstance();
        string message = messageFactory.getMessagesMessage(_user.logedUser);
        string response = conn.sendMessage(message);

        ServerResponse serverResponse = new ServerResponse(response);

        ServerResponseParams par = serverResponse.getParams();        
        int n = int.Parse(par["messages"]);

        List<CommunicatorMessage> result = new List<CommunicatorMessage>();

        for (int i = 1; i <= n; i++)
        {
            result.Add(new CommunicatorMessage(par.getExtraData(i), par[i]));
        }

        return result;
    }