Ejemplo n.º 1
0
        public MiHomeManager(
            IMiCommunicationFactory communicationFactory,
            IDevicesKeeper devicesKeeper,
            ITokenKeeper tokenKeeper,
            IDevicesMap devicesMap,
            IKeyGeneratorFactory keyGeneratorFactory)
        {
            _devicesKeeper = devicesKeeper;
            _tokenKeeper   = tokenKeeper;
            _devicesMap    = devicesMap;
            var keyGenerator = keyGeneratorFactory.Build(_devicesMap, _tokenKeeper);

            _communication = communicationFactory.Build(CommandListener, keyGenerator);
        }
Ejemplo n.º 2
0
 public ResponseManager(ISmartpoolDB smartpoolDb)
 {
     _tokenKeeper = new TokenKeeper(new TokenStringGenerator(), 10);
     _smartpoolDb = smartpoolDb;
     _tokenMsgResponse = new TokenMsgResponse(_smartpoolDb);
     try
     {
         _smartpoolDb.UserAccess.IsEmailInUse("qa"); //error with first call to db taking an excess amount of time
     }
     catch (Exception)
     {
         Console.WriteLine("Could not connect to database. Make sure VPN is active");
     }
     
 }
Ejemplo n.º 3
0
 public KeyGenerator(IDevicesMap map, ITokenKeeper tokenKeeper, IGatewayPasswordKeeper passwordKeeper)
 {
     _map            = map;
     _tokenKeeper    = tokenKeeper;
     _passwordKeeper = passwordKeeper;
 }
Ejemplo n.º 4
0
        public void SetUp()
        {
            _tokenKeeperSub = Substitute.For<ITokenKeeper>();
            _tokenMsgResponseSub = Substitute.For<ITokenMsgResponse>();
            _smartpoolDbSub = Substitute.For<ISmartpoolDB>();
            _uut = new ResponseManager(_tokenKeeperSub, _tokenMsgResponseSub, _smartpoolDbSub);

            _smartpoolDbSub.UserAccess.ValidatePassword("KnownEmail", "CorrectPassword").Returns(true);

            //_tokenMsgResponse.HandleTokenMsg(new TokenMsg("KnownEmail", "CorrectTokenString")).Returns(new TokenResponseMsg(true));

            _tokenKeeperSub.CreateNewToken("KnownEmail").Returns("CorrectTokenString");
            _tokenKeeperSub.TokenActive("KnownEmail", "CorrectTokenString").Returns(true);
            _tokenKeeperSub.TokenActive("KnownEmail", "IncorrectTokenString").Returns(false);
        }
Ejemplo n.º 5
0
 public void Setup()
 {
     _subForSmartpoolDb = Substitute.For<ISmartpoolDB>();
     _subForTokenKeeper = Substitute.For<ITokenKeeper>();
     _uut = new TokenMsgResponse(_subForSmartpoolDb);
 }
Ejemplo n.º 6
0
        public Message HandleTokenMsg(Message message, string messageString, ITokenKeeper tokenKeeper)
        {
            var tokenMsg = JsonConvert.DeserializeObject<TokenMsg>(messageString, _jsonSettings);
            switch (tokenMsg.SubMsgType)
            {
                //Pool messages
                case TokenSubMessageTypes.AddPoolRequest:
                    var apMsg = JsonConvert.DeserializeObject<AddPoolRequestMsg>(messageString);
                    var poolCreatedSuccessfully = _smartpoolDb.PoolAccess.AddPool(apMsg.Username, apMsg.PoolName,
                        apMsg.Volume);
                    if (poolCreatedSuccessfully)
                        _poolKeeper.AddPoolToKeeper(apMsg.Username, apMsg.PoolName);
                    return new GeneralResponseMsg(true, poolCreatedSuccessfully); 

                case TokenSubMessageTypes.UpdatePoolRequest:
                    var upMsg = JsonConvert.DeserializeObject<UpdatePoolRequestMsg>(messageString);
                    var newNameSuccess = true;
                    var newVolumeSuccess = true;
                    if (upMsg.NewPoolName != "")
                    {
                        newNameSuccess = _smartpoolDb.PoolAccess.EditPoolName(upMsg.Username, upMsg.OldPoolName, upMsg.NewPoolName);
                    }
                    if (upMsg.NewPoolVolume != 0)
                    {
                        newVolumeSuccess = _smartpoolDb.PoolAccess.EditPoolVolume(upMsg.Username, upMsg.OldPoolName, upMsg.NewPoolVolume);
                    }
                    if (newVolumeSuccess && newNameSuccess)
                    return new GeneralResponseMsg(true, true);
                    else
                    {
                        return new GeneralResponseMsg(true, false) {MessageInfo = "An error happened. Data was not saved"};
                    }

                case TokenSubMessageTypes.RemovePoolRequest:
                    var rpMsg = JsonConvert.DeserializeObject<RemovePoolRequestMsg>(messageString);
                    return new GeneralResponseMsg(true, _smartpoolDb.PoolAccess.RemovePool(rpMsg.Username, rpMsg.PoolName)); 

                case TokenSubMessageTypes.AddPoolPictureRequest:
                    var appMsg = JsonConvert.DeserializeObject<AddPoolPictureRequestMsg>(messageString);
                    return new GeneralResponseMsg(true, false) { MessageInfo = "Not implemented" };

                case TokenSubMessageTypes.GetPoolDataRequest:
                    var gpdMsg = JsonConvert.DeserializeObject<GetPoolDataRequestMsg>(messageString);
                    if (gpdMsg.GetAllNamesOnly)
                    {
                        var pools = _smartpoolDb.PoolAccess.FindAllPoolsOfUser(gpdMsg.Username);
                        var poolNamesListTuple =
                            pools.Select(pool => Tuple.Create(pool.Name, _random.NextDouble() > 0.5)).ToList();
                        return new GetPoolDataResponseMsg() {AllPoolNamesListTuple = poolNamesListTuple};
                    }
                    else //return data for one pool only
                        return new GetPoolDataResponseMsg(GetSensorValues(gpdMsg.Username, gpdMsg.PoolName, gpdMsg.GetHistoryDays));
                        //return new GetPoolDataResponseMsg(_fakePoolKeeper.GetPools()[0].GetSensorValuesList());

                case TokenSubMessageTypes.GetPoolInfoRequest:
                    var gpiMsg = JsonConvert.DeserializeObject<GetPoolInfoRequestMsg>(messageString);
                    var poolToReturn = _smartpoolDb.PoolAccess.FindSpecificPool(gpiMsg.Username, gpiMsg.PoolName);
                    return new GetPoolInfoResponseMsg(poolToReturn.Volume, "GTP8H-H8D8D-DDTKD-MT8W6-PTD6M");

                //User messages
                case TokenSubMessageTypes.ChangePasswordRequest:
                    var cpMsg = JsonConvert.DeserializeObject<ChangePasswordRequestMsg>(messageString);
                    return new GeneralResponseMsg(true, _smartpoolDb.UserAccess.EditUserPassword(cpMsg.Username, cpMsg.NewPassword));

                case TokenSubMessageTypes.LogoutRequest:
                    var loMsg = JsonConvert.DeserializeObject<LogoutRequestMsg>(messageString);
                    tokenKeeper.RemoveToken(loMsg.Username);
                    return new GeneralResponseMsg(true, true);
                
                case TokenSubMessageTypes.AllowAccessToPoolDataRequest:
                    return new GeneralResponseMsg(true, false) {MessageInfo = "Not implemented"};
                //Monitor unit messages
                case TokenSubMessageTypes.ChangeSensorTargetValueRequest:
                    return new GeneralResponseMsg(true, false) { MessageInfo = "Not implemented" };
                //Default
                default:
                    return new GeneralResponseMsg(true, false);
            }
        }
Ejemplo n.º 7
0
 public IKeyGenerator Build(IDevicesMap map, ITokenKeeper tokenKeeper)
 {
     return(new KeyGenerator(map, tokenKeeper, _passwordKeeper));
 }
Ejemplo n.º 8
0
 public ResponseManager(ITokenKeeper tokenKeeper, ITokenMsgResponse tokenMsgResponse, ISmartpoolDB smartpoolDb)
 {
     _tokenKeeper = tokenKeeper;
     _tokenMsgResponse = tokenMsgResponse;
     _smartpoolDb = smartpoolDb;
 }