public bool GetDoorState(Int32 deviceId, Int32 doorIndex) { Log.Info("Invoke WebSocketOperation..."); var operation = new WebSocketOperation(deviceId); var getDoorStateRequest = new GetDoorStateRequest() { Token = operation.Token, DoorIndex = doorIndex }; string rawRequest = DataContractSerializationHelper.Serialize(getDoorStateRequest); Log.DebugFormat("Request: {0}", rawRequest); var rawResponse = operation.Execute(rawRequest); Log.DebugFormat("Response: {0}", rawResponse); var response = DataContractSerializationHelper.Deserialize <GetDoorStateResponse>(rawResponse); Log.InfoFormat("Get door state, index:[{0}] for device id:[{1}], result:[{2}]", doorIndex, deviceId, response.ResultType); if (response.ResultType != ResultType.OK) { throw new Exception(string.Format("Get door state, index:[{0}] for device id:[{1}], result:[{2}]", doorIndex, deviceId, response.ResultType)); } return(response.DoorStateInfo.Opened); }
public GetDoorStateResponse Process(GetDoorStateRequest request) { try { var dao = new DoorInfoDao(); var doorStates = dao.GetDoorStates(request.DoorIndex); return(new GetDoorStateResponse() { Token = request.Token, ResultType = ResultType.OK, DoorStateInfo = doorStates }); } catch (Exception ex) { Log.Error(ex); return(new GetDoorStateResponse() { Token = request.Token, ResultType = ResultType.Error }); } }