Exemplo n.º 1
0
        public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
        {
            Console.WriteLine("Exception: " + exception);
            context.CloseAsync();

            SocketClientHandler.OutputException(exception);
            SocketClientHandler.ShutDown(1);
        }
Exemplo n.º 2
0
        static async Task RunClientAsync(BuildRunRequest request)
        {
            var group = new MultithreadEventLoopGroup();

            string targetHost = null;

            try
            {
                SocketClientHandler.OutputMessage("Pre bootstrap");
                var bootstrap = new Bootstrap();
                bootstrap
                .Group(group)
                .Channel <TcpSocketChannel>()
                .Option(ChannelOption.TcpNodelay, true)
                .Handler(new ActionChannelInitializer <ISocketChannel>(channel =>
                {
                    SocketClientHandler.OutputMessage("In handler");
                    IChannelPipeline pipeline = channel.Pipeline;

                    pipeline.AddLast(new LoggingHandler());
                    pipeline.AddLast("framing-enc", new LengthFieldPrepender(2));
                    pipeline.AddLast("framing-dec", new LengthFieldBasedFrameDecoder(ushort.MaxValue, 0, 2, 0, 2));

                    pipeline.AddLast("echo", new SocketClientHandler(request));

                    SocketClientHandler.OutputMessage("Handlers added");
                }));

                SocketClientHandler.OutputMessage("Pre channel connect");
                IChannel clientChannel = await bootstrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(_host), _port));

                SocketClientHandler.OutputMessage("Post channel connect");

                string s = Console.ReadLine();
                while (string.IsNullOrEmpty(s))
                {
                    Console.ReadLine();
                }
                SocketClientHandler.OutputMessage("Post inner readline");

                await clientChannel.CloseAsync();
            }
            finally
            {
                await group.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
            }
        }
Exemplo n.º 3
0
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            SocketClientHandler.OutputMessage("Channel reading");
            var byteBuffer = message as IByteBuffer;

            if (byteBuffer != null)
            {
                try
                {
                    string s = byteBuffer.ToString(Encoding.UTF8);

                    _log.Info($"RECEIVED RAW: {s}");
                    var obj = JsonConvert.DeserializeObject(s, new JsonSerializerSettings {
                        TypeNameHandling = TypeNameHandling.All
                    });

                    StatusMessage       statusMessage = obj as StatusMessage;
                    TestExecutionResult testResult    = obj as TestExecutionResult;

                    if (testResult != null)
                    {
                        OutputTestMessage(testResult);
                    }

                    if (statusMessage != null)
                    {
                        if (statusMessage.Message == "DONE")
                        {
                            OutputMessage("Test run complete");
                            ShutDown(0);
                        }
                        OutputStatusMessage(statusMessage);
                    }
                    else
                    {
                        OutputMessage(obj.GetType().FullName);
                    }
                }
                catch (Exception ex)
                {
                    HanldeException(ex);
                    ShutDown(1);
                }
            }
        }
Exemplo n.º 4
0
        static async Task Main(string[] args)
        {
            XmlConfigurator.Configure();

            if (args.Length == 0)
            {
                throw new ArgumentException("Usage: reactiveclient host build");
            }

            var host = args[0];

            var port = 1055;

            var build            = args[1];
            var image            = args[2];
            var yamlFileLocation = args[3];

            string yaml = File.ReadAllText(yamlFileLocation);

            BuildRunRequest request = new BuildRunRequest
            {
                Build = build,
                Yaml  = yaml
            };

            try
            {
                SocketClientHandler.OutputMessage("Starting wait");
                await RunClientAsync(request).ConfigureAwait(true);

                for (int i = 0; i < 1000; i++)
                {
                    Thread.Sleep(1000);
                }
            }
            catch (Exception e)
            {
                SocketClientHandler.OutputException(e);
                SocketClientHandler.ShutDown(1);
            }

            SocketClientHandler.OutputMessage("Before Readline");
            Console.ReadLine();
            SocketClientHandler.OutputMessage("Exiting");
        }
Exemplo n.º 5
0
 public override void ChannelActive(IChannelHandlerContext context)
 {
     SocketClientHandler.OutputMessage("Channel Active pre write");
     context.WriteAndFlushAsync(this.byteBuffer);
     SocketClientHandler.OutputMessage("Channel Active post write");
 }