public async Task <IActionResult> TestSendReceive([FromBody] XmlPageRequestBody xmlPageRequestBody) { ILogger logger = new ConsoleLogger(); JsonResult jsonResult; RequestResponseFrame responseFrame; object jsonObject; string methodName = "TestSendReceive"; logger.WriteEntry(methodName + " entry."); if (ModelState.IsValid) { logger.WriteEntry(methodName + " ModelState is valid."); string receiveUrl = xmlPageRequestBody.ReceiveUrl; string receiveSearch = xmlPageRequestBody.ReceiveSearch; GeneralClassLibrary.XmlPageRequestFrame xmlPageRequestFrame = new XmlPageRequestFrame(xmlPageRequestBody); // Transform the API request to an ITcpFrame. byte[] sendFrameBytes = xmlPageRequestFrame.ToByteArray(); RequestResponseFrame requestFrame = new RequestResponseFrame(sendFrameBytes); // Connect to the server and obtain a network stream. BufferedStream bufferedStream = await SendReceiveReply.ConnectToServer(RemoteHostName, RemotePortNumber, SizeStreamBuffer, logger); // Send and receive data via the stream. responseFrame = await SendReceiveReply.RequestReceiveResponse(bufferedStream, requestFrame, logger); ITcpFrame tcpFrame = responseFrame; byte[] replyFrameBytes = tcpFrame.FramePacket; IpcFrameBase ipcFrameBase = ( IpcFrameBase )IpcFrameBase.FromByteArray(replyFrameBytes); // Transform the ITcpFrame to an API response. logger.WriteEntry(methodName + " building the JSON result."); XmlPageReplyFrame xmlPageReplyFrame = ( XmlPageReplyFrame )ipcFrameBase; jsonObject = new { textArray = xmlPageReplyFrame.ResultList, isSuccess = true }; } else { logger.WriteEntry(methodName + " ModelState is not valid!"); jsonObject = new { textArray = new List <string>(), isSuccess = false }; } logger.WriteEntry(methodName + " exit."); jsonResult = new JsonResult(jsonObject); return(jsonResult); }
public IPerformService CreateService(ITcpFrame requestFrame, ILogger logger) { IPerformService performService; IpcFrameBase ipcFrameBase = ( IpcFrameBase )IpcFrameBase.ByteArrayToObject(requestFrame.FramePacket); switch (ipcFrameBase.ServiceActionEnum) { case ServiceActionEnum.XmlPageRequestServiceAction: XmlPageRequestFrame xmlPageRequestFrame = ( XmlPageRequestFrame )ipcFrameBase; XmlPageService xmlPageService = new XmlPageService(xmlPageRequestFrame); performService = xmlPageService; break; case ServiceActionEnum.SizeServiceActionEnum: default: performService = null; break; } return(performService); }