Exemplo n.º 1
0
		public Message ResponseForMessage(Message message)
		{
			switch (message.MsgType)
			{
			case MessageTypes.LoginRequest:
				return ResponseForLoginRequestMessage ((LoginRequestMsg)message);
			case MessageTypes.TokenMsg:
				return ResponseForTokenMessage ((TokenMsg)message);	
			default:
				return new GeneralResponseMsg (true, true);
			}
		}
Exemplo n.º 2
0
		// IClientMessenger Interface Implementation

		public Message SendMessage(Message message)
		{
			var responseManager = new iOSResponseManager ();
			return responseManager.ResponseForMessage (message);
		}
Exemplo n.º 3
0
 public Message SendMessage(Message message)
 {
     return _clientResponseManager.HandleMessage(_client.StartClient(JsonConvert.SerializeObject(message, _jsonSettings) + "<EOF>"));
 }
Exemplo n.º 4
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);
            }
        }