Exemplo n.º 1
0
        public async void logout()
        {
            if (userInfo.IsLoggedIn == true)
            {
                view.appendConsole("Logging out ...\n");

                // Send message to server
                IAction action = new UserAction(new LogoutMessenger(userInfo, appInfo));
                MiddlewareService.Message response = await Task.Run(() => action.carryOut());

                if (response.operationStatus == true)
                {
                    // Update Model
                    userInfo.Username   = "";
                    userInfo.Password   = "";
                    userInfo.IsLoggedIn = false;

                    view.appendConsole("Logged out successfully !\n");
                }
                else
                {
                    view.appendConsole("ERROR : " + response.info + "\n");
                }
            }
            else
            {
                view.appendConsole("ERROR : Cannot log user out : Please log in first.\n");
            }
        }
Exemplo n.º 2
0
        public async void register(string username, string password, string email)
        {
            if (username != "" && password != "" && email.Contains("@"))
            {
                view.appendConsole("Registering ...\n");

                // Update model
                userInfo.Username = username;
                userInfo.Password = password;
                userInfo.Email    = email;

                // Send message to middleware
                IAction action = new UserAction(new RegisterMessenger(userInfo, appInfo));
                Client.MiddlewareService.Message response = await Task.Run(() => action.carryOut());

                if (response.operationStatus == true)
                {
                    view.appendConsole("Successfully created user !\n");
                }
                else
                {
                    view.appendConsole("ERROR : " + response.info + "\n");
                }
            }
            else
            {
                view.appendConsole("ERROR : Invalid username, password or email.\n");
            }
        }
Exemplo n.º 3
0
        public Message carryOut()
        {
            MiddlewareService.Message msg = messenger.writeMessage();
            Postman postman = new Postman();

            return(postman.sendMessage(msg));
        }
Exemplo n.º 4
0
        public MiddlewareService.Message writeMessage()
        {
            var msg = new MiddlewareService.Message();

            object[] data = new object[1];
            data[0] = userInfo.Username;

            msg.appToken         = appInfo.Token;
            msg.appVersion       = appInfo.Version;
            msg.operationName    = "serviceLogout";
            msg.operationVersion = "";
            msg.operationStatus  = false;
            msg.userToken        = userInfo.Token;
            msg.info             = "";
            msg.data             = data;

            return(msg);
        }
Exemplo n.º 5
0
        public async void decodeFiles(string[] files)
        {
            if (files.Length > 0)
            {
                // Retreiving file contents
                byte[][] contents = dao.getFilesContents(files);
                Dictionary <string, byte[]> data = new Dictionary <string, byte[]>();

                for (int i = 0; i < files.Length; i++)
                {
                    if (contents[i].Length > 0)
                    {
                        data.Add(files[i], contents[i]);
                    }
                }

                if (data.Count() > 0)
                {
                    view.appendConsole("Decoding file(s) ...\n");

                    // Sending message to server
                    IAction action = new UserAction(new FileDecodeMessenger(userInfo, appInfo, data));
                    MiddlewareService.Message response = await Task.Run(() => action.carryOut());

                    if (response.operationStatus == true)
                    {
                        view.appendConsole("Ok.\n");
                    }
                    else
                    {
                        view.appendConsole("ERROR : " + response.info + "\n");
                    }
                }
                else
                {
                    view.appendConsole("ERROR : Directory dosen't contain any files.\n");
                }
            }
            else
            {
                view.appendConsole("ERROR : No file selected.\n");
            }
        }
Exemplo n.º 6
0
        public async void login(string username, string password)
        {
            if (userInfo.IsLoggedIn == false)
            {
                if (username != "" && password != "")
                {
                    view.appendConsole("Logging in ...\n");

                    // Update Model
                    userInfo.Username = username;
                    userInfo.Password = password;

                    // Send message to middleware
                    IAction action = new UserAction(new LoginMessenger(userInfo, appInfo));
                    MiddlewareService.Message response = await Task.Run(() => action.carryOut());

                    if (response.operationStatus == true)
                    {
                        // Update model
                        userInfo.Token      = (string)response.data[0];
                        userInfo.IsLoggedIn = true;

                        view.appendConsole("Successfully logged in as " + userInfo.Username + "\n");
                    }
                    else
                    {
                        view.appendConsole("ERROR : " + response.info + "\n");
                    }
                }
                else
                {
                    view.appendConsole("ERROR : Invalid username or password.\n");
                }
            }
            else
            {
                view.appendConsole("ERROR : User is already logged in, please log out first !\n");
            }
        }