Beispiel #1
0
    public void OnWebSocketWithThriftServiceTestClick()
    {
        WebSocket ws = new WebSocket("ws://127.0.0.1:8092/chat/1");

        ws.OnMessage += (sender, e) => {
            MemoryStream stream = new MemoryStream(e.RawData);
            Thrift.Protocol.TProtocol        tProtocol = new Thrift.Protocol.TBinaryProtocol(new Thrift.Transport.TStreamTransport(stream, null));
            idl.MultiplicationService.Client client    = new idl.MultiplicationService.Client(tProtocol);
            int aa = client.recv_multiply();

            Debug.Log("recv :" + aa);
        };

        ws.OnOpen += (object sender, System.EventArgs e) => {
            MemoryStream stream = new MemoryStream(256);
            Thrift.Protocol.TProtocol        tProtocol = new Thrift.Protocol.TBinaryProtocol(new Thrift.Transport.TStreamTransport(null, stream));
            idl.MultiplicationService.Client client    = new idl.MultiplicationService.Client(tProtocol);
            client.send_multiply(11, 22);
            ws.SendAsync(stream.ToArray(), (bool s) => {
                Debug.Log("sent :" + s);
            });
        };

        ws.OnError += (object sender, NetworkLib.WebSocketSharp.ErrorEventArgs e) => {
            Debug.Log("error :" + e.Exception.Message);
        };

        ws.OnClose += (object sender, CloseEventArgs e) => {
            Debug.Log("close");
        };

        ws.ConnectAsync();
    }
Beispiel #2
0
        static void Main(string[] args)
        {
            //�������ݿ�����
            TTransport transport = new TSocket("192.168.10.2", 9160);
            TProtocol protocol = new TBinaryProtocol(transport);
            Cassandra.Client client = new Cassandra.Client(protocol);
            transport.Open();

            System.Text.Encoding utf8Encoding = System.Text.Encoding.UTF8;
            long timeStamp = DateTime.Now.Millisecond;
            ColumnPath nameColumnPath = new ColumnPath()
            {
                Column_family = "Standard1",
                Column = utf8Encoding.GetBytes("age")
            };
            //�����
            client.insert("Keyspace1",
                          "studentA",
                          nameColumnPath,
                          utf8Encoding.GetBytes("18"),
                          timeStamp,
                          ConsistencyLevel.ONE);

               //��ȡ����
            ColumnOrSuperColumn returnedColumn = client.get("Keyspace1", "studentA", nameColumnPath, ConsistencyLevel.ONE);
            Console.WriteLine("Keyspace1/Standard1: age: {0}, value: {1}", utf8Encoding.GetString(returnedColumn.Column.Name), utf8Encoding.GetString(returnedColumn.Column.Value));

               //�ر�����
               transport.Close();
        }
Beispiel #3
0
        private static void Main()
        {
            TTransport framedTransport = new TFramedTransport(new TSocket("localhost", 9160));
            TTransport socketTransport = new TSocket("localhost", 9160);
            TProtocol framedProtocol = new TBinaryProtocol(framedTransport);
            TProtocol socketProtocol = new TBinaryProtocol(socketTransport);

            var client = new Cassandra.Client(framedProtocol, framedProtocol); // all framed
            //var client = new Cassandra.Client(socketProtocol, socketProtocol); // all socket
            //var client = new Cassandra.Client(framedProtocol, socketProtocol); // in: framed out: socket
            //var client = new Cassandra.Client(socketProtocol, framedProtocol); // in: socket out: framed

            framedTransport.Open();
            socketTransport.Open();
            Console.WriteLine("Start");

            client.set_keyspace("Keyspace1");

            Console.WriteLine("Count Key");
            var key = Encoding.ASCII.GetBytes("MyKey");
            var columns = new List<byte[]>(new[] { Encoding.ASCII.GetBytes("MyColumn") });
            var column_parent = new ColumnParent {
                Column_family = "Standard1"
            };
            var predicate = new SlicePredicate {
                Column_names = columns
            };
            client.get_count(key, column_parent, predicate, ConsistencyLevel.ALL);

            Console.WriteLine("Done");
            Console.Read();
        }
Beispiel #4
0
		/// <summary>
		/// 
		/// </summary>
		private void InitTransportAndClient()
		{
			var socket = new TSocket(Server.Host, Server.Port, Server.Timeout * 1000);

			switch (ConnectionType)
			{
				case ConnectionType.Simple:
					_transport = socket;
					break;

				case ConnectionType.Buffered:
					_transport = new TBufferedTransport(socket, BufferSize);
					break;

				case ConnectionType.Framed:
					_transport = new TFramedTransport(socket);
					break;

				default:
					goto case ConnectionType.Framed;
			}

			var protocol = new TBinaryProtocol(_transport);
			_client = new Cassandra.Client(protocol);
		}
Beispiel #5
0
        //获取连接
        public ThriftHadoopFileSystem.Client Connect(out TBufferedTransport tsport)
        {
            if (HostServer == null)
               {
               throw new ArgumentNullException("HostServer");
               }

               if (Port == 0)
               {
               throw new ArgumentNullException("Port");
               }

               TSocket hadoop_socket = new TSocket(HostServer, Port);

               //hadoop_socket.Timeout = 10000;// Ten seconds

               tsport = new TBufferedTransport(hadoop_socket);

               TBinaryProtocol hadoop_protocol = new TBinaryProtocol(tsport, false, false);

               ThriftHadoopFileSystem.Client client = new ThriftHadoopFileSystem.Client(hadoop_protocol);
               try
               {
               tsport.Open();
               return client;
               }
               catch (Exception ex)
               {
               //throw (new Exception("打开连接失败!", ex));
               tsport = null;
               return null;

               }
        }
        public IClient Create(IEndpoint endpoint, IClientPool ownerPool)
        {
            TSocket socket = null;
            TTransport transport = null;
            if (endpoint.Timeout == 0)
            {
                socket = new TSocket(endpoint.Address, endpoint.Port);
            }
            else
            {
                socket = new TSocket(endpoint.Address, endpoint.Port, endpoint.Timeout);
            }
            TcpClient tcpClient = socket.TcpClient;

            if (this.isBufferSizeSet)
            {
                transport = new TBufferedTransport(socket, this.bufferSize);
            }
            else
            {
                transport = new TBufferedTransport(socket);
            }

            TProtocol protocol = new TBinaryProtocol(transport);
            CassandraClient cassandraClient = new CassandraClient(protocol);
            IClient client = new DefaultClient() {
                CassandraClient = cassandraClient,
                Endpoint = endpoint,
                OwnerPool = ownerPool,
                TcpClient = tcpClient,
                Created = DateTime.Now
            };

            return client;
        }
        static void Main(string[] args)
        {
            MessageObject mo1 = new MessageObject{TimeStamp = DateTime.Now, Message="begin process...."};
            LogHelper.WriteLogInfo(typeof(Program), mo1);

			TTransport transport = new TSocket("localhost", 7911);
            TProtocol protocol = new TBinaryProtocol(transport);
			ThriftCase.Client client = new ThriftCase.Client(protocol);
			transport.Open();
			Console.WriteLine("Client calls .....");
			map.Add("blog", "http://www.javabloger.com");

			client.testCase1(10, 21, "3");
			client.testCase2(map);
			client.testCase3();

			Blog blog = new Blog();
			//blog.setContent("this is blog content".getBytes());
            blog.CreatedTime = DateTime.Now.Ticks;
			blog.Id = "123456";
			blog.IpAddress = "127.0.0.1";
			blog.Topic = "this is blog topic";
			blogs.Add(blog);
			
			client.testCase4(blogs);
			
			transport.Close();
            //LogHelper.WriteLog(typeof(Program), "end process......");
            Console.ReadKey();
        }
 public Wrapper()
 {
     Uri userStoreUrl = new Uri("https://" + evernoteHost + "/edam/user");
     TTransport userStoreTransport = new THttpClient(userStoreUrl);
     TProtocol userStoreProtocol = new TBinaryProtocol(userStoreTransport);
     userStore = new UserStore.Client(userStoreProtocol);
 }
Beispiel #9
0
        public void GetHBaseImage(string rowKey = "20150822180801118")
        {
            var socket = new TSocket(hbaseThrif, hbaseThrifPort);
            var transport = new TBufferedTransport(socket);
            var protocol = new TBinaryProtocol(transport);
            Hbase.Client hbaseClient = new Hbase.Client(protocol);
            transport.Open();

            //List<byte[]> tableNames = hc.getTableNames();

            byte[] table = Encoding.UTF8.GetBytes("FiservImages");
            byte[] row = Encoding.UTF8.GetBytes(rowKey);
            byte[] column = Encoding.UTF8.GetBytes("ImageData:Image");

            List<TRowResult> results = hbaseClient.getRow(table, row, null);
            TCell t = new TCell();
            //t.

            foreach (TRowResult result in results)
            {
                //result.Columns[column]
                //result.Columns;
                Dictionary<byte[], TCell> konj;
                konj = result.Columns;

                //string s = Encoding.UTF8.GetString(result.Columns[column].Value);

                foreach (KeyValuePair<byte[], TCell> singleRow in konj)
                {
                    //File.WriteAllBytes(@"c:\test\output.docx", singleRow.Value.Value);
                    OpenFile(singleRow.Value.Value, "output.docx");
                }
            }
        }
        public IEnumerable<EverNote> GetDefaultNoteBookNotes(string authToken)
        {
            var noteStoreUrl = GetNoteStoreUrl(authToken);
            var transport = new THttpClient(new Uri(noteStoreUrl));
            var protocol = new TBinaryProtocol(transport);
            var noteStore = new NoteStore.Client(protocol);
            var notes = new List<EverNote>();

            var notebooks = noteStore.listNotebooks(authToken);

            foreach (Notebook notebook in notebooks)
            {
                if (notebook.DefaultNotebook)
                {
                    var findResult = noteStore.findNotes(authToken, new NoteFilter { NotebookGuid = notebook.Guid }, 0, int.MaxValue);
                    foreach (var note in findResult.Notes)
                    {
                        notes.Add(new EverNote(note.Guid, note.Title));
                    }
                    break;
                }
            }

            return notes;
        }
        public static void Main()
        {
            try
            {
                TTransport transport = new TSocket("localhost", 9090);
                TProtocol protocol = new TBinaryProtocol(transport);
                Calculator.Client client = new Calculator.Client(protocol);

                transport.Open();
                try
                {
                    client.ping();
                    Console.WriteLine("ping()");

                    int sum = client.add(1, 1);
                    Console.WriteLine("1+1={0}", sum);

                    Work work = new Work();

                    work.Op = Operation.DIVIDE;
                    work.Num1 = 1;
                    work.Num2 = 0;
                    try
                    {
                        int quotient = client.calculate(1, work);
                        Console.WriteLine("Whoa we can divide by 0");
                    }
                    catch (InvalidOperation io)
                    {
                        Console.WriteLine("Invalid operation: " + io.Why);
                    }

                    work.Op = Operation.SUBTRACT;
                    work.Num1 = 15;
                    work.Num2 = 10;
                    try
                    {
                        int diff = client.calculate(1, work);
                        Console.WriteLine("15-10={0}", diff);
                    }
                    catch (InvalidOperation io)
                    {
                        Console.WriteLine("Invalid operation: " + io.Why);
                    }

                    SharedStruct log = client.getStruct(1);
                    Console.WriteLine("Check log: {0}", log.Value);

                }
                finally
                {
                    transport.Close();
                }
            }
            catch (TApplicationException x)
            {
                Console.WriteLine(x.StackTrace);
            }

        }
Beispiel #12
0
        public static void query()
        {
            var transport = new TBufferedTransport(new TSocket("hserver", 10000));
            var protocol = new TBinaryProtocol(transport);
            var client = new ThriftHive.Client(protocol);

            transport.Open();

            //client.execute("CREATE TABLE r(a STRING, b INT, c DOUBLE)");
            //client.execute("LOAD TABLE LOCAL INPATH '/path' INTO TABLE r");
            client.execute("SELECT * FROM pokes where foo=180");
            while (true)
            {
                var row = client.fetchOne();
                if (string.IsNullOrEmpty(row))
                    break;
                System.Console.WriteLine(row);
            }
            client.execute("SELECT * FROM pokes");
            var all = client.fetchAll();

            System.Console.WriteLine(all);

            transport.Close();
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            // Initialize log4net
            l4n.Config.XmlConfigurator.Configure();

            // Create log
            var log = new LogEntry();
            log.Category = "Program";
            log.Message = "This is a test error message from the program";

            // Connect
            var socket = new TSocket("192.168.1.144",65510,300);
            var transport = new TFramedTransport(socket);
            var protocol = new TBinaryProtocol(transport,false,false);
            var scribeClient = new scribe.Client(protocol);
            transport.Open();

            // Send
            var logs = new List<LogEntry>();
            logs.Add(log);
            var result = scribeClient.Log(logs);

            // Close
            transport.Close();

            // use log4net to log
            var logger = l4n.LogManager.GetLogger("ScribeAppender.Test.Program");
            logger.Debug("This is a test error message from the logger");
        }
        public IClient Create(IEndpoint endpoint, IClientPool ownerPool)
        {
            TSocket socket = null;
            if (endpoint.Timeout == 0)
            {
                socket = new TSocket(endpoint.Address, endpoint.Port);
            }
            else
            {
                socket = new TSocket(endpoint.Address, endpoint.Port, endpoint.Timeout);
            }
            TcpClient tcpClient = socket.TcpClient;
            TProtocol protocol = new TBinaryProtocol(socket);
            CassandraClient cassandraClient = new CassandraClient(protocol);
            IClient client = new DefaultClient()
            {
                CassandraClient = cassandraClient,
                Endpoint = endpoint,
                OwnerPool = ownerPool,
                TcpClient = tcpClient,
                Created = DateTime.Now
            };

            return client;
        }
            public int Run()
            {
                int c = 0;

                try
                {
                    TTransport transport = new TSocket(Host, Port);
                    TProtocol protocol = new TBinaryProtocol(transport);
                    var client = new MultiplicationService.Client(protocol);

                    Console.WriteLine("Thrift client opening transport to {0} on port {1} ...", Host, Port);
                    transport.Open();

                    int a, b;
                    Console.Write("Enter 1st integer : ");
                    int.TryParse(Console.ReadLine(), out a);
                    Console.Write("Enter 2nd integer : ");
                    int.TryParse(Console.ReadLine(), out b);

                    c = client.multiply(a, b);

                    Console.WriteLine("{0} x {1} = {2}", a, b, c);
                    Console.WriteLine("Thrift client closing transport ...");
                    transport.Close();

                }
                catch (TApplicationException x)
                {
                    Console.WriteLine(x.StackTrace);

                }

                return c;
            }
Beispiel #16
0
 public static UserStore.Client GetUserStore()
 {
     var userStoreUrl = new Uri(Configuration.EvernoteUrl + "/edam/user");
     var userStoreTransport = new THttpClient(userStoreUrl);
     var userStoreProtocol = new TBinaryProtocol(userStoreTransport);
     return new UserStore.Client(userStoreProtocol);
 }
Beispiel #17
0
 private void btnExit_Click( object sender, EventArgs e )
 {
     TTransport trans = OpenTransport();
     TBinaryProtocol binaryProtocol = new TBinaryProtocol( trans );
     DataProvider.Client client = new DataProvider.Client( binaryProtocol );
     client.DeleteJob( m_JobNumber );
 }
        public CassandraClient Create(CassandraEndpoint endpoint)
        {
            TSocket socket = null;
            TTransport transport = null;
            if (endpoint.Timeout == 0)
            {
                socket = new TSocket(endpoint.Address, endpoint.Port);
            }
            else
            {
                socket = new TSocket(endpoint.Address, endpoint.Port, endpoint.Timeout);
            }

            if (this.isBufferSizeSet)
            {
                transport = new TBufferedTransport(socket, this.bufferSize);
            }
            else
            {
                transport = new TBufferedTransport(socket);
            }

            TProtocol protocol = new TBinaryProtocol(transport);
            Cassandra.Client cassandraClient = new Cassandra.Client(protocol);
            CassandraClient client = new CassandraClient(cassandraClient, endpoint);

            this.logger.Debug(logger.StringFormatInvariantCulture("Created a new connection using: '{0}'", endpoint.ToString()));

            return client;
        }
Beispiel #19
0
    public static void Main(string[] args)
    {
        int port = 9090;
        for (int i = 0; i < args.Length; i++)
        {
            switch(args[i])
            {
                case "--port":
                    port = int.Parse(args[++i]);
                    break;
                case "--help":
                    Console.WriteLine("--port: Port used to connect with the server. (int)");
                    break;
            }
        }

        try
        {
            TSocket tSocket = new TSocket("localhost", port);
            tSocket.TcpClient.NoDelay = true;
            TTransport transport = tSocket;
            TProtocol protocol = new TBinaryProtocol(transport);
            Game.Client client = new Game.Client(protocol);
            transport.Open();
            playGame(client);
            transport.Close();
        }
        catch (TApplicationException x)
        {
            Console.WriteLine(x.StackTrace);
        }
    }
Beispiel #20
0
 private void initClient()
 {
     transport = new TFramedTransport(new TSocket(SERVER_IP, SERVER_PORT, TIME_OUT));
     TProtocol protocol = new TBinaryProtocol(transport);
     client = new BigQueueService.Client(protocol);
     transport.Open();
 }
        public EvernoteServiceSDK1(EFDbEvernoteCredentials credentials)
        {
            this.credentials = credentials;

            THttpClient noteStoreTransport = new THttpClient(new Uri(credentials.NotebookUrl));
            TBinaryProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport);
            noteStore = new NoteStore.Client(noteStoreProtocol);
        }
Beispiel #22
0
 internal static UserStore.Client GetUserStoreClient(string edamBaseUrl)
 {
     Uri userStoreUrl = new Uri(edamBaseUrl + "/edam/user");
     TTransport userStoreTransport = new THttpClient(userStoreUrl);
     TProtocol userStoreProtocol = new TBinaryProtocol(userStoreTransport);
     UserStore.Client userStore = new UserStore.Client(userStoreProtocol);
     return userStore;
 }
Beispiel #23
0
 public EpmService()
 {
     disposed = false;
     pool = new ConnectionProvider();
     transport = pool.GetConnection();
     TProtocol protocol = new TBinaryProtocol(transport);
     client = new Datahouse.Client(protocol);
 }
 public void Setup()
 {
     var socket = new TSocket(host, port);
     transport = new TFramedTransport(socket);
     var protocol = new TBinaryProtocol(transport);
     Client = new ZipkinCollector.Client(protocol);
     transport.Open();
 }
Beispiel #25
0
 internal static NoteStore.Client GetNoteStoreClient(String edamBaseUrl, User user)
 {
     Uri noteStoreUrl = new Uri(edamBaseUrl + "/edam/note/" + user.ShardId);
     TTransport noteStoreTransport = new THttpClient(noteStoreUrl);
     TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport);
     NoteStore.Client noteStore = new NoteStore.Client(noteStoreProtocol);
     return noteStore;
 }
 /// <summary>
 /// UserStoreの取得
 /// </summary>
 /// <returns></returns>
 private UserStore.Client GetUserStore()
 {
     Uri userStoreUrl = new Uri("https://" + mEvernoteHost + "/edam/user");
     TTransport userStoreTransport = new THttpClient(userStoreUrl);
     TProtocol userStoreProtocol = new TBinaryProtocol(userStoreTransport);
     UserStore.Client userStore = new UserStore.Client(userStoreProtocol);
     return userStore;
 }
Beispiel #27
0
        static void StartClient(string userName)
        {
            TTransport transport = new TSocket("localhost", 12000);
            TProtocol protocol = new TBinaryProtocol(transport);

            transport.Open();


        }
			// ! DO NOT INSTANTIATE THIS OBJECT DIRECTLY. GET ONE FROM AN AUTHENTICATED ENSESSION !

			internal ENUserStoreClient(string userStoreUrl, string authToken)
			{
				Uri url = new Uri(userStoreUrl);

				TTransport transport = new THttpClient(url);
				TProtocol protocol = new TBinaryProtocol(transport);
				Client = new UserStore.Client(protocol);
				AuthenticationToken = authToken;
			}
        public LegacyThriftClient(string host, int port)
        {
            if (host == null) throw new ArgumentNullException("host");

            _transport = new TSocket(host, port);
            TProtocol protocol = new TBinaryProtocol(_transport);
            _client = new ThriftFlumeEventServer.Client(protocol);
            _transport.Open();
        }
Beispiel #30
0
 public static Cassandra.Client GetClient(string keyspace, ref TTransport transport)
 {
     TTransport frameTransport = new TFramedTransport(new TSocket("localhost", 9160));
     TProtocol frameProtocol = new TBinaryProtocol(frameTransport);
     var client = new Cassandra.Client(frameProtocol, frameProtocol);
     frameTransport.Open();
     client.set_keyspace(keyspace);
     transport = frameTransport;
     return client;
 }
        public override void Open(string hostname)
        {
            base.Open(hostname);

            TTransport transport = new TFramedTransport(new TSocket(hostname, 9160));
            TProtocol protocol = new TBinaryProtocol(transport);
            _client = new Cassandra.Client(protocol);

            transport.Open();
        }
Beispiel #32
0
 /// <summary>
 /// Gets bytes that represents the current object.
 /// </summary>
 /// <returns></returns>
 public static byte[] GetBytes <T>(T tobj) where T : TAbstractBase
 {
     using (var trans = new Thrift.Transport.TMemoryBuffer())
     {
         using (var oprot = new Thrift.Protocol.TBinaryProtocol(trans))
         {
             tobj.Write(oprot);
             return(trans.GetBuffer());
         }
     }
 }
Beispiel #33
0
        /// <summary>
        /// Creates a new instance from the byte array provided.
        /// </summary>
        /// <param name="bytes"></param>
        public static T CreateObject <T>(byte[] bytes) where T : TBase, new()
        {
            using (var trans = new Thrift.Transport.TMemoryBuffer(bytes))
            {
                using (var oprot = new Thrift.Protocol.TBinaryProtocol(trans))
                {
                    var tobj = new T();

                    tobj.Read(oprot);
                    return(tobj);
                }
            }
        }
Beispiel #34
0
    public void OnWebSocketWithThriftTestClick()
    {
        ThriftHandler <idl.Protocol> thandler = new ThriftHandler <idl.Protocol> ();

        thandler.AddHandler(idl.Protocol.Test1, (idl.TestAck ack) => {
            Debug.Log("Laputa says: " + ack.ToString());
        });

        thandler.AddHandler(idl.Protocol.Test2, (idl.Test2Ack ack) => {
            Debug.Log("Laputa says: " + ack.ToString());
        });

        WebSocket ws = new WebSocket("ws://127.0.0.1:8091/chat/1");

        ws.OnMessage += (sender, e) => {
            MemoryStream stream = new MemoryStream(e.RawData);
            Thrift.Protocol.TProtocol tProtocol = new Thrift.Protocol.TBinaryProtocol(new Thrift.Transport.TStreamTransport(stream, null));
            tProtocol.ReadStructBegin();
            tProtocol.ReadFieldBegin();
            idl.Header header = new idl.Header();
            header.Read(tProtocol);
            stream.Position = 0;

            thandler.DoHandle(header.Key, tProtocol);
        };

        ws.OnOpen += (object sender, System.EventArgs e) => {
            idl.TestReq shared = new idl.TestReq();
            shared.Header     = new idl.Header();
            shared.Header.Key = idl.Protocol.Test1;
            shared.Key        = 11;
            shared.Value      = "aaa";

            ws.SendAsync(shared, (bool s) => {
                Debug.Log("sent :" + s);
            });
        };

        ws.OnError += (object sender, NetworkLib.WebSocketSharp.ErrorEventArgs e) => {
            Debug.Log("error :" + e.Exception.Message);
        };

        ws.OnClose += (object sender, CloseEventArgs e) => {
            Debug.Log("close");
        };

        ws.ConnectAsync();
    }