private void RegisterUser(RegistrationRequest r, string queueName)
        {
            if (string.IsNullOrEmpty(r.Email) || string.IsNullOrEmpty(r.Password))
            {
                Logger.Error($"{nameof(RegisterUser)}: Email or password is empty!");
                BackError error = new BackError("Email or password is empty!");
                channel.BasicPublish(exchange: "", routingKey: queueName, basicProperties: null, body: error.Serializer());
                return;
            }

            if (UserRepository.IsExistEmail(r.Email))
            {
                Logger.Error($"{nameof(RegisterUser)}: Email address is already used!");
                RegistrationError regError = new RegistrationError("Email address is already used!");
                channel.BasicPublish(exchange: "", routingKey: queueName, basicProperties: null, body: regError.Serializer());
            }
            Guid key     = Guid.NewGuid();
            User newUser = new User()
            {
                Email     = r.Email,
                QueueName = queueName,
                Salt      = key.ToString(),
                Password  = UserRepository.HashCode(r.Password + key)
            };

            UserRepository.AddUser(newUser);
            Logger.Info($"{nameof(RegisterUser)}: new client has been registered");
            RegistrationResponse regResponse = new RegistrationResponse();

            channel.BasicPublish(exchange: "", routingKey: queueName, basicProperties: null, body: regResponse.Serializer());
        }
        private void BackErrorHandler(BackError er)
        {
            switch (er)
            {
            case RegistrationError re:
                RegistrationError(er.ErrorDescription);
                break;

            case LoginError le:
                LoginError(le.ErrorDescription);
                break;

            case LoginBySessionError lbse:
                LoginBySessionError(lbse.ErrorDescription);
                break;

            case BackError be:
                BackError(be.ErrorDescription);
                break;

            default:
                throw new Exception($"Unknown error type!");
                break;
            }
        }
        //set new session to db
        private void Login(LoginRequest lr, string queueName)
        {
            if (string.IsNullOrEmpty(lr.Email) || string.IsNullOrEmpty(lr.Password))
            {
                BackError error = new BackError("Email or password is empty!");
                channel.BasicPublish(exchange: "", routingKey: queueName, basicProperties: null, body: error.Serializer());
                return;
            }
            User user = UserRepository.GetUserByEmail(lr.Email);

            if (user == null)
            {
                LoginError regError = new LoginError("Incorrect login or password!l");//incorrect login
                channel.BasicPublish(exchange: "", routingKey: queueName, basicProperties: null, body: regError.Serializer());
                return;
            }
            else
            {
                if (UserRepository.HashCode(lr.Password + user.Salt) == user.Password)
                {
                    string NewSessionId = Guid.NewGuid().ToString();
                    SessionRepository.SetUserSession(user.Id, NewSessionId);
                    LoginResponse logResponse = new LoginResponse(NewSessionId);
                    channel.BasicPublish(exchange: "", routingKey: queueName, basicProperties: null, body: logResponse.Serializer());
                    return;
                }
                else
                {
                    LoginError regError = new LoginError("Incorrect login or password!p");//incorrect password
                    channel.BasicPublish(exchange: "", routingKey: queueName, basicProperties: null, body: regError.Serializer());
                    return;
                }
            }
        }