コード例 #1
0
        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;
        }
コード例 #2
0
 protected abstract void HandleData(ClientContext context, byte[] data);
コード例 #3
0
ファイル: TypeData.cs プロジェクト: John-Leitch/GenomeDotNet
 public TypeData(ClientContext context, string[] parts)
 {
     Context = context;
     Parts = parts;
 }
コード例 #4
0
 public RemoteConsole(ConsoleServerComponent server, ClientContext context, Guid id)
 {
     _component = server;
     _context = context;
     Id = id;
 }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        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;
            }
        }
コード例 #7
0
        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);
                    }
                }
            }
        }
コード例 #8
0
        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();
            }
        }
コード例 #9
0
 public BatchScriptExecutionEventArgs(ClientContext context, BatchScriptCommand command)
 {
     Context = context;
     Command = command;
 }