protected string ReadStream(string request) { using (var clientSocket = new TcpClient()) { NetworkStream serverStream; string readerPort = ConfigurationUtil.GetSetting(request); clientSocket.Connect("localhost", Convert.ToInt32(readerPort)); serverStream = clientSocket.GetStream(); if (serverStream.CanWrite && serverStream.CanRead) { byte[] outStream = System.Text.Encoding.ASCII.GetBytes(request); serverStream.Write(outStream, 0, outStream.Length); serverStream.Flush(); byte[] inStream = new byte[clientSocket.ReceiveBufferSize]; var numberOfBytesRead = serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize); string returndata = System.Text.Encoding.ASCII.GetString(inStream, 0, numberOfBytesRead); return returndata; } } return ""; }
public IEnumerable <PersonalData> ReadData() { ReaderType type; // Comment about the exercise: Add a key to app.config to define which component to use. if (Enum.TryParse(ConfigurationUtil.GetSetting("DefaultReader"), out type)) { // Comment about the exercise: Use Factory pattern to instantiate the component handler. return(ReaderHandlerFactory.CreateReader(type).ReadData()); } return(null); }