/// <exception cref="ArgumentException"></exception> /// > /// <exception cref="SocketException"></exception> /// > public OperationResponseDto SendOperation(OperationDto operationDto) { //PRE-CONDITION //TODO LOGGING operationDto.Params.ToList() .ForEach(x => CodeContract.PreCondition <ArgumentException>(x >= 0 && x <= 65535)); var paramBytes = new List <byte>(); foreach (var param in operationDto.Params) { paramBytes.Add(GetDataType(param)); paramBytes.AddRange(ValueToBytes(param)); } var payload = new List <byte> { operationDto.Operation, operationDto.Device }.Concat(paramBytes).ToArray(); try { _socketClient.Connect(); _socketClient.Send(payload); var response = _socketClient.Recieve(); //POST-CONDITIONS //TODO LOGGING CodeContract.PostCondition <SocketException>( !response.SequenceEqual(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 })); CodeContract.PostCondition <ArgumentException>(response[1] > 0 && response[1] < 4); CodeContract.PostCondition <ArgumentException>(response[0] > 0); CodeContract.PostCondition <ArgumentException>(response.Length == 8); return(new OperationResponseDto { Status = response[0], Returns = BytesToValue(response.Skip(1).ToArray()) }); } finally { _socketClient.Close(); } }