private static void ProcessConnectionCore(NamedPipeServerStream stream) { Debug.Assert(stream.IsConnected); try { var reader = new ClientReader(stream); var action = reader.ReadString(); var argument = reader.ReadString(); switch (action) { case Constants.ActionDiscover: Discover(stream, argument); break; case Constants.ActionRunAll: RunAll(stream, argument); break; case Constants.ActionRunSpecific: RunSpecific(stream, argument); break; default: Debug.Fail($"Invalid action {action}"); break; } } catch (Exception ex) { // Happens during a rude disconnect by the client Console.WriteLine(ex.Message); } finally { stream.Dispose(); } }
public void CloseConnection() { lock (clientLocker) { if (ClientConnected) { try { ClientWriter.WriteLine("-- " + Properties.strings.cya); ClientWriter.Flush(); } catch (IOException) { } ConnectedServer.WriteToAllClients("-- " + string.Format(Properties.strings.disconnectedClient, Name + "@" + ClientIep.Address, ClientIep.Port)); ClientWriter.Close(); ClientReader.Close(); ClientStream.Close(); ClientSocket.Close(); ClientConnected = false; ConnectedServer.connectedClients.Remove(this); } } ConnectedServer.RefreshInfo(); }
public IDriver AddDriver(short id, string name, string assembly, string className) { if (reader == null) { reader = new ClientReader(this, id, name);//server应为远程主机名/IP,从本地字符串解析获取 } return(reader); }
void AcceptResponse(string line = null) { if (line == null) { line = ClientReader.ReadLine(); } ProcessMessage(new FtpResponse(line)); }
internal ClientStream(StrongConnect pc, Socket c) { client = c; wtr = new ClientWriter(client); rdr = new ClientReader(client); rdr.buf.pos = 2; rdr.buf.len = 0; }
/// <summary> /// Read out the set of test case display names to run. /// </summary> private static List <string> ReadTestCaseDisplayNames(Stream stream) { using (var reader = new ClientReader(stream)) { var list = new List <string>(); while (reader.ReadKind() == TestDataKind.Value) { list.Add(reader.ReadString()); } return(list); } }
private void selectFolderButton_Click(object sender, EventArgs e) { textBox1.Text = ""; dataGridView1.DataSource = null; if (openFileDialog.ShowDialog() == DialogResult.OK) { if (!openFileDialog.FileName.Equals("")) { ClientReader reader; reader = new ClientReader(new ConverterXml <ClientInfo>("CLIENTE")); textBox1.Text = openFileDialog.FileName; dataGridView1.DataSource = reader.ProcessFile(openFileDialog.FileName); } } }
protected async Task <string> ReadLineAsync(bool throwOnEmptyMessage = true) { ConfiguredTaskAwaitable <string>?readLineAwaitable = ClientReader?.ReadLineAsync().ConfigureAwait(false); string message = readLineAwaitable.HasValue ? await readLineAwaitable.Value : null; if (message != null) { return(message); } DisconnectForced("Empty message received from server."); if (throwOnEmptyMessage) { throw new InvalidOperationException("Received no message. Socket got disconnected."); } return(null); }
private static void ProcessConnectionCore(NamedPipeServerStream stream) { Debug.Assert(stream.IsConnected); try { var reader = new ClientReader(stream); var action = reader.ReadString(); var assemblyFileName = reader.ReadString(); switch (action) { case Constants.ActionDiscover: Discover(stream, assemblyFileName); break; case Constants.ActionRunAll: RunAll(stream, assemblyFileName); break; case Constants.ActionRunSpecific: RunSpecific(stream, assemblyFileName); break; default: Debug.Fail($"Invalid action {action}"); break; } } catch (Exception ex) { // Happens during a rude disconnect by the client Console.WriteLine(ex.Message); } finally { stream.Dispose(); } }
private void DisconnectForced(string reason) { bool clientWasConnected = Client?.Connected == true; ReceivedLines.Clear(); Client?.Dispose(); ClientStream?.Dispose(); ClientReader?.Dispose(); ClientWriter?.Dispose(); Client = null; ClientStream = null; ClientReader = null; ClientWriter = null; Connected = false; ReadLoopTask = null; KeepAliveTask = null; if (clientWasConnected) { ConnectionClosed?.Invoke(this, new EventArgs <string>(reason)); } }
void ProcessMessage(FtpResponse response, bool suppressSet = false) { var code = response.Code; var multiline = response.Multiline; var message = response.Message; var raw = response.Raw; if (ResponseReceived != null) { ResponseReceived(this, new ResponseReceivedEventArgs(response)); } // Log the message LogMessage(code, message); // Set flags indicating whether the response // indicates success or failure var state = ClientState.None; if (code.IsInRange(100, 300)) { state |= ClientState.GoodResponse; } else if (code.IsInRange(300, 600)) { state |= ClientState.BadResponse; } // Check the message code and act accordingly switch (code) { case 110: // Restart marker reply break; case 120: // Service ready in nnn minutes break; case 125: // Data connection already open; transfer starting break; case 150: // File status okay; about to open data connection break; case 200: // Command okay break; case 202: // Command not implemented, superfluous at this site break; case 211: // System status, or system help reply // Response to FEAT if (multiline) { string line = ClientReader.ReadLine(); while (!Regex.IsMatch(line, RegexConstants.Multiline_End)) { ProcessMessage(new FtpResponse(000, line, false), true); line = ClientReader.ReadLine(); } AcceptResponse(line); } break; case 212: // Directory status break; case 213: // File status break; case 214: // Help message break; case 215: // System type break; case 220: // Service ready for new user //if (ServiceReady) // suppressSet = true; //ServiceReady = true; break; case 221: // Service closing control connection break; case 225: // Data connection open; no traClientStreamfer in progress break; case 226: // Closing data connection if (DataConnectionClosed != null) { DataConnectionClosed(this, EventArgs.Empty); } break; case 227: // Entering passive mode (h1,h2,h3,h4,p1,p2) IPEndPoint endpoint = null; try { endpoint = Parsers.ParsePasvResponse(message); Data.EndPoint = endpoint; } catch (Exception e) { LogMessage(000, string.Format("Error parsing endpoint: {0}", e.Message)); } state |= ClientState.OperationFailed; break; case 230: // User logged in, proceed break; case 250: // Requested file action okay, completed break; case 257: // "PATHNAME" created break; case 331: // User name okay, need password if (string.IsNullOrEmpty(Password)) { state |= ClientState.ExitRequested; } break; case 332: // Need account for login break; case 350: // Requested file action pending further information case 421: // Service not available, closing control connection // Also: Login time exceeded state |= ClientState.ExitRequested; break; case 425: // Can't open data connection break; case 426: // Connection closed; transfer aborted break; case 450: // Requested file action not taken break; case 451: // Requested action aborted. Local error in processing break; case 452: // Requested action not taken // Insufficient storage space in system break; case 500: // Syntax error or // Command unrecognized break; case 501: // Syntax error in parameters or arguments break; case 502: // Command not implemented break; case 503: // Bad sequence of commands break; case 504: // Command not implemented for that parameter break; case 530: // Not logged in break; case 532: // Need account for storing files break; case 550: // Requested action not taken break; case 551: // Requested action aborted. Page type unknown break; case 552: // Requested file action aborted // Exceeded storage allocation break; case 553: // Requested action not taken // File name not allowed break; } // Allow the operation to continue CurrentState = state; if (!suppressSet) { MessageHandler.Set(); MessageHandler.Reset(); } }
private void ClientListening() { string message; lock (clientLocker) { if (ClientConnected) { try { ClientWriter.WriteLine("-- " + Properties.strings.motd + ": " + ConnectedServer.WelcomeMessage); ClientWriter.Flush(); ClientWriter.Write("-- " + Properties.strings.enterNickname + ": "); ClientWriter.Flush(); } catch (IOException) { } } } try { do { string name = ClientReader.ReadLine(); if (string.IsNullOrWhiteSpace(name)) { lock (clientLocker) { if (ClientConnected) { ClientWriter.Write("-- " + Properties.strings.enterNickname + ": "); ClientWriter.Flush(); } } } else { Name = name; } } while (string.IsNullOrWhiteSpace(name)); } catch (IOException) { } ConnectedServer.RefreshInfo(); ConnectedServer.WriteToAllClients("-- " + string.Format(Properties.strings.connectedWithClient, Name + "@" + ClientIep.Address, ClientIep.Port)); lock (clientLocker) { if (ClientConnected) { try { ClientWriter.WriteLine("-- " + Properties.strings.commands); ClientWriter.Flush(); } catch (IOException) { } } } while (ClientConnected) { try { message = ClientReader.ReadLine(); if (message != null) { //Handles available commands if (!string.IsNullOrWhiteSpace(message)) { if (message[0] == '#') { if (message == Properties.strings.exit) { lock (clientLocker) if (ClientConnected) { CloseConnection(); } } else if (message == Properties.strings.list) { lock (clientLocker) if (ClientConnected) { ConnectedServer.List(this); } } else if (message == Properties.strings.cmd) { lock (clientLocker) { if (ClientConnected) { ClientWriter.WriteLine("-- " + Properties.strings.availableCommands + ": "); ClientWriter.Flush(); ClientWriter.WriteLine("\t-- " + Properties.strings.cmd + ": " + Properties.strings.cmdInfo); ClientWriter.Flush(); ClientWriter.WriteLine("\t-- " + Properties.strings.exit + ": " + Properties.strings.exitInfo); ClientWriter.Flush(); ClientWriter.WriteLine("\t-- " + Properties.strings.list + ": " + Properties.strings.listInfo); ClientWriter.Flush(); } } } else { lock (clientLocker) { if (ClientConnected) { ClientWriter.WriteLine("-- " + Properties.strings.unknownCmd); ClientWriter.Flush(); } } } } else { ConnectedServer.WriteToAllClients("|| " + Name + "@" + ClientIep.Address + " >> " + message); } } else { lock (clientLocker) { if (ClientConnected) { ClientWriter.WriteLine("-- " + Properties.strings.enterMessage); ClientWriter.Flush(); } } } } else { CloseConnection(); } } catch (IOException) { break; } } CloseConnection(); }
internal BackgroundReader(ConcurrentQueue <T> queue, ClientReader reader, Func <ClientReader, T> readValue) { _queue = queue; _reader = reader; _readValue = readValue; }
/// <summary> /// Read out the set of test case display names to run. /// </summary> private static List<string> ReadTestCaseDisplayNames(Stream stream) { using (var reader = new ClientReader(stream)) { var list = new List<string>(); while (reader.ReadKind() == TestDataKind.Value) { list.Add(reader.ReadString()); } return list; } }
internal Connection(NamedPipeClientStream stream) { _stream = stream; _reader = new ClientReader(stream); }