Ejemplo n.º 1
0
        public static DTO Login(AccConnectionController accConnectionController, ref Account account, ref bool loged, DTO dto)
        {
            MessageDTO messageDTO = null;

            if (dto is UserDTO && dto.getOperationType() == 1)
            {
                if (loged == true && dto.getOperationType() == 1)
                {
                    messageDTO = new MessageDTO(dto.getOperationType(), "You are already logged", false);
                }
                try
                {
                    account    = accConnectionController.LogIn(dto);
                    loged      = true;
                    messageDTO = new MessageDTO(dto.getOperationType(), "Welcome! You are now loged in.", true);
                }
                catch (Exception ex)
                {
                    string msg = ex.Message;
                    messageDTO = new MessageDTO(dto.getOperationType(), msg, false);
                }
            }
            else
            {
                messageDTO = new MessageDTO(dto.getOperationType(), "First you must log in!", false);
            }
            return(messageDTO);
        }
Ejemplo n.º 2
0
        public void connectionHandling()
        {
            Console.WriteLine("Tworze watek dla polaczenia");
            int max = 65565;

            Byte[] bytes = new Byte[max];
            int    i;
            bool   loged = false;
            AccConnectionController accConnectionController = new AccConnectionController(db);
            AccOperationController  accOperationController  = null;
            Account account = null;
            DTO     answer;

            while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
            {
                string     className  = ByteParser.byteToType(bytes);
                DtoFactory dtoFactory = new DtoFactory();
                DTO        dto        = dtoFactory.getDTO(className);
                dto.fromByteArray(bytes);
                answer = null;
                if (dto != null)
                {
                    if (loged == false)
                    {
                        answer = DTOUtil.Login(accConnectionController, ref account, ref loged, dto);
                    }
                    else if (loged == true && dto.getOperationType() == 1)
                    {
                        answer = DTOUtil.Login(accConnectionController, ref account, ref loged, dto);
                    }
                    else
                    {
                        if (dto.getOperationType() == 5)
                        {
                            answer = DTOUtil.Logout(dto, ref account, ref loged);
                        }
                        else
                        {
                            answer = DTOUtil.OperateOnAccount(accOperationController, account, dto);
                        }
                    }
                }
                byte[] data = answer.toByteArray();
                stream.Write(data, 0, data.Length);
            }
            client.Close();
        }