public BatchScriptCommand[] Execute(ClientContext context, string script) { var lines = script.SplitLines(StringSplitOptions.RemoveEmptyEntries); var results = new BatchScriptCommand[lines.Length]; if (CreatingConsole != null) { CreatingConsole(this, new BatchScriptExecutionEventArgs(context, null)); } using (var client = CreateConsole(context)) { if (ConsoleCreated != null) { ConsoleCreated(this, new BatchScriptExecutionEventArgs(context, null)); } client.ReadResponse(); for (int i = 0; i < lines.Length; i++) { if (CommandExecuting != null) { CommandExecuting(this, new BatchScriptExecutionEventArgs(context, new BatchScriptCommand(lines[i], null))); } results[i] = new BatchScriptCommand(lines[i], client.ExecuteCommand(lines[i])); if (CommandExecuted != null) { CommandExecuted(this, new BatchScriptExecutionEventArgs(context, results[i])); } } } return results; }
protected abstract void HandleData(ClientContext context, byte[] data);
public TypeData(ClientContext context, string[] parts) { Context = context; Parts = parts; }
public RemoteConsole(ConsoleServerComponent server, ClientContext context, Guid id) { _component = server; _context = context; Id = id; }
private void HandleGoodbyeMessage(ClientContext context) { InvokeGoodbyeReceived(context.Client); InvokeDisconnecting(context.Client); context.AcquireWriteLock(); try { context.Writer.WriteGoodbye(); } finally { context.ReleaseWriteLock(); } InvokeGoodbyeSent(context.Client); InvokeDisconnected(context.Client); context.DisconnectEventsTriggered = true; context.Client.Close(); //context.IsConnected = false; lock (_clients) { _clients.Remove(context); } }
private void HandleClientHello(ClientContext context, Message message) { switch (message.Type) { case MessageType.Hello: InvokeHelloReceived(context.Client); InvokeConnecting(context.Client); context.AcquireWriteLock(); try { context.Writer.WriteHello(); } finally { context.ReleaseWriteLock(); } InvokeHelloSent(context.Client); lock (_clients) { _clients.Add(context); } InvokeConnected(context.Client); break; default: context.AcquireWriteLock(); try { context.Writer.WriteError("Hello expected"); } finally { context.ReleaseWriteLock(); } break; } }
private void HandleClient(ClientContext context) { var state = SessionState.WaitingForHello; using (context) { while (context.Client.Connected) { context.AcquireReadLock(); Message m = null; try { m = context.Reader.ReadMessage(); } catch (Exception e) { InvokeClientErrorEncountered(new TcpClientError(context.Client, e)); } if (m == null) { context.ReleaseReadLock(); Thread.Sleep(1); continue; } switch (state) { case SessionState.WaitingForHello: HandleClientHello(context, m); state = SessionState.Initialized; break; case SessionState.Initialized: HandleArbitraryMessage(context, m); break; default: throw new InvalidOperationException(); } context.ReleaseReadLock(); } if (!context.DisconnectEventsTriggered) { InvokeDisconnecting(context.Client); InvokeDisconnected(context.Client); lock (_clients) { _clients.Remove(context); } } } }
private void HandleArbitraryMessage(ClientContext context, Message message) { switch (message.Type) { case MessageType.Data: HandleData(context, message.Data); break; case MessageType.Goodbye: HandleGoodbyeMessage(context); break; default: throw new InvalidOperationException(); } }
public BatchScriptExecutionEventArgs(ClientContext context, BatchScriptCommand command) { Context = context; Command = command; }