Beispiel #1
0
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            var msg = (ThriftMessage)message;
            var bp  = new TBinaryProtocol.Factory();
            var t   = new TThriftTransport(context.Channel, msg.Content, ThriftTransportType.Framed);
            var tp  = bp.GetProtocol(t);
            var mh  = tp.ReadMessageBegin();

            tp.ReadMessageEnd();
            var buf = msg.Content;

            byte[] req = new byte[buf.ReadableBytes];
            buf.ReadBytes(req);
            //ReadOnlySpan<byte> bytesBuffer = req;
            //ReadOnlySpan<sbyte> sbytesBuffer = MemoryMarshal.Cast<byte, sbyte>(bytesBuffer);
            //sbyte[] signed = sbytesBuffer.ToArray();
            string body = Encoding.UTF8.GetString(req);

            Trace.WriteLine($"recv order: {body}");
            string      currentTime = string.Compare(body, "query time", true) == 0 ? DateTime.Now.ToLongTimeString() : "bad order";
            IByteBuffer resp        = Unpooled.CopiedBuffer(currentTime, Encoding.UTF8);

            context.WriteAsync(resp);
            //string body = new string(signed, 0, req.Length, Encoding.UTF8);
            //base.ChannelRead(context, message);
        }
        /**
         * 点击事件
         **/
        public static void InputEvent(Int32 port, MouseEventType type)
        {
            TSocket socket = new TSocket("127.0.0.1", port, 1000);

            TFramedTransport.Factory factory = new
                                               TFramedTransport.Factory();
            TTransport transport = factory.GetTransport(socket);

            TBinaryProtocol.Factory factory1 =
                new TBinaryProtocol.Factory();
            TProtocol            protocol = factory1.GetProtocol(transport);
            TMultiplexedProtocol impl1
                = new TMultiplexedProtocol(protocol, "ScreenService");

            ScreenService.Client client =
                new ScreenService.Client(impl1);
            try
            {
                socket.Open();
                bool r
                    = client.InputEvent(type);
            }
            catch (Exception x)
            {
                Console.WriteLine(x.StackTrace);
            }
            finally
            {
                transport.Close();
            }
        }
        /**
         * 获取手机屏幕分辨率
         **/
        public static String sendPoint(Int32 port, Int32 x, Int32 y)
        {
            TSocket socket = new TSocket("127.0.0.1", port, 1000);

            TFramedTransport.Factory factory = new
                                               TFramedTransport.Factory();
            TTransport transport = factory.GetTransport(socket);

            TBinaryProtocol.Factory factory1 =
                new TBinaryProtocol.Factory();
            TProtocol            protocol = factory1.GetProtocol(transport);
            TMultiplexedProtocol impl1
                = new TMultiplexedProtocol(protocol, "ScreenService");

            ScreenService.Client client =
                new ScreenService.Client(impl1);
            try
            {
                socket.Open();
                return(client.sendPoint(x, y));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                transport.Close();
            }
            return("");
        }
        public static string RemoveProcess(Int32 port, String lineNumber)
        {
            TSocket socket = new TSocket("127.0.0.1", port, 3000);

            TFramedTransport.Factory factory = new
                                               TFramedTransport.Factory();
            TTransport transport = factory.GetTransport(socket);

            TBinaryProtocol.Factory factory1 =
                new TBinaryProtocol.Factory();
            TProtocol            protocol = factory1.GetProtocol(transport);
            TMultiplexedProtocol impl1
                = new TMultiplexedProtocol(protocol, "NodeService");

            NodeService.Client client =
                new NodeService.Client(impl1);
            try
            {
                socket.Open();
                return(client.RemoveProcess(lineNumber));
            }
            catch (Exception x)
            {
                Console.WriteLine(x.StackTrace);
            }
            finally
            {
                transport.Close();
            }
            return("");
        }
        private byte[] ConvertSpanToBytes(Span span)
        {
            var       buf      = new MemoryStream();
            TProtocol protocol = protocolFactory.GetProtocol(new TStreamTransport(buf, buf));

            span.Write(protocol);
            return(buf.ToArray());
        }
 public SamplingStrategyResponse GetSamplingStrategy(string serviceName)
 {
     try
     {
         var samplerUri = new UriBuilder("http", _hostPort)
         {
             Query = $"service={serviceName}"
         }.Uri;
         var httpTransport         = new THttpClientTransport(samplerUri, null);
         var protocol              = _protocolFactory.GetProtocol(httpTransport);
         var samplingManagerClient = new SamplingManager.Client(protocol);
         return(samplingManagerClient.getSamplingStrategyAsync(serviceName, CancellationToken.None).Result.FromThrift());
     }
     catch (Exception e)
     {
         throw new Exception("http call to get sampling strategy from local agent failed.", e);
     }
 }