private void checkForUpdatesImpl(bool isUpdate) { if (isUpdate) { PopulateMeciTable(); } else { TTransport transport = new TSocket("localhost", 9091); TProtocol protocol = new TBinaryProtocol(transport); transport.Open(); TransformerService.Client client = new TransformerService.Client(protocol); var dtos = client.findAllMeci(); transport.Close(); meciuriData = retreive(dtos); PopulateMeciTable(); } }
static void Main(string[] args) { try { //设置服务端端口号和地址 TTransport transport = new TSocket("localhost", 8080); transport.Open(); //设置传输协议为二进制传输协议 TProtocol protocol = new TBinaryProtocol(transport); //创建客户端对象 HelloService.Client client = new HelloService.Client(protocol); //调用服务端的方法 Console.WriteLine(client.HelloString("HelloThrift")); Console.ReadKey(); } catch (TTransportException e) { Console.WriteLine(e.Message); } }
public MainWindow() { InitializeComponent(); try { TTransport transport = new TSocket("localhost", 9091); transport.Open(); TProtocol protocol = new TBinaryProtocol(transport); client = new thriftGrafo.GrafoService.Client(protocol); }catch (Exception ex) { MessageBox.Show("Erro ao conectar ao servidor " + ex.Message); Application.Current.Shutdown(); } cbBidirecionalAresta.SelectedIndex = 1; cbBidirecionalAresta_Update.SelectedIndex = 1; cbBidirecionalAresta_Delete.SelectedIndex = 1; }
public TTransport GetTransport(Service service) { ThriftService thriftService = service as ThriftService; if (thriftService == null) { throw new NullReferenceException("thriftService"); } return(_connectionStore.GetOrAdd(thriftService, tmp => { TSocket socket = new TSocket(new TcpClient(tmp.Address, tmp.Port)); if (!socket.IsOpen) { socket.Open(); } return socket; })); }
public static void Run(int times) { Parallel.For(0, times, i => { using (TSocket socket = new TSocket("localhost", 8005)) { using (TTransport transport = new TBufferedTransport(socket)) { using (TProtocol protocol = new TCompactProtocol(transport)) { using (var client = new IUserService.Client(protocol)) { transport.Open(); var list = client.GetAll(); } } } } }); }
public static void CheckAndDelete(string configname, string table, string rowid, string family, string columnname, object columnvalue, string[] delcolumns) { //实例化Socket连接 //transport = new TSocket("2.5.172.38", 30001); var transport = new TSocket(configname); //实例化一个协议对象 TProtocol tProtocol = new TBinaryProtocol(transport); byte[] tablenamebytes = Encoding.UTF8.GetBytes(table); byte[] rowidbytes = Encoding.UTF8.GetBytes(rowid); byte[] familybytes = Encoding.UTF8.GetBytes(family); byte[] columnnamebytes = Encoding.UTF8.GetBytes(columnname); byte[] columnvaluebytes = null; if (columnvalue != null) { columnvaluebytes = Serializer.TSerializer.GetBytes(columnvalue); } using (var client = new HBase.Thrift2.THBaseService.Client(tProtocol)) { transport.Open(); try { TDelete del = new TDelete(rowidbytes); if (delcolumns != null && delcolumns.Length > 0) { del.Columns = new List <TColumn>(); foreach (var col in delcolumns) { var tdelcol = new TColumn(familybytes); tdelcol.Qualifier = Encoding.UTF8.GetBytes(col); del.Columns.Add(tdelcol); } } client.checkAndDelete(tablenamebytes, rowidbytes, familybytes, columnnamebytes, columnvaluebytes, del); } finally { transport.Close(); } } }
static void Main(string[] args) { Console.WriteLine("Credits API Simple Demo"); if (args.Length != 4) { Console.WriteLine("Usage: CreditsCSAPIDemo NodeIpAddress YourPublicKey YourPrivateKey TargetPublicKey"); return; } var SourceKeys = new Keys { PublicKey = args[1], PrivateKey = args[2] }; var TargetKeys = new Keys { PublicKey = args[3], }; using (var transport = new TSocket(args[0], 9090)) { using (var protocol = new TBinaryProtocol(transport)) { using (var client = new API.Client(protocol)) { transport.Open(); var balance = client.WalletBalanceGet(SourceKeys.PublicKeyBytes); Console.WriteLine($"[{SourceKeys.PublicKey}] Balance: {balance.Balance.ToString()}"); var clientEx = new ClientEx(client, SourceKeys, TargetKeys); Console.WriteLine(clientEx.ExecuteTransaction()); } } } Console.WriteLine("Press [Enter] to exit..."); Console.ReadLine(); }
static void _DropDataBase(string baseName, string columnFamily) { if (string.IsNullOrWhiteSpace(baseName)) { return; } if (string.IsNullOrWhiteSpace(columnFamily)) { return; } var socket = null as TSocket; var transport = null as TBufferedTransport; try { // Сделаем вычисление апи хоста по базе данных socket = new TSocket(getHost(baseName, columnFamily), Port); transport = new TBufferedTransport(socket); var proto = new TBinaryProtocol(transport); var hbase = new Hbase.Client(proto); transport.Open(); var tableName = getBaseTableHbase(baseName, columnFamily); if (hbase.isTableEnabled(tableName)) { hbase.disableTable(tableName); hbase.deleteTable(tableName); } } finally { if (transport != null) { transport.Close(); transport = null; } } }
static void Main(string[] args) { Console.WriteLine("Apache thrift client"); try { TTransport transport = new TSocket("localhost", 9090); TProtocol protocol = new TBinaryProtocol(transport); StorageService.Client client = new StorageService.Client(protocol); transport.Open(); try { client.ping(); Console.WriteLine("ping()"); var list = client.storagePoints(); foreach (var item in list) { string description = ""; if (!string.IsNullOrEmpty(item.Description)) { description = item.Description; } Console.WriteLine(string.Format("ID: {0} name:{1} description:{2}", item.StorageId, item.Name, description)); } var result = client.read(0); bool r = client.write(0, "new value"); result = client.read(0); } finally { transport.Close(); } } catch (TApplicationException x) { Console.WriteLine(x.StackTrace); } }
public ThriftConnection(IConnectionConfigurationValues connectionSettings) { this._connectionSettings = connectionSettings; this._timeout = connectionSettings.Timeout; this._poolSize = Math.Max(1, connectionSettings.MaximumAsyncConnections); this._resourceLock = new Semaphore(_poolSize, _poolSize); int seed; bool shouldPingHint; for (var i = 0; i <= connectionSettings.MaximumAsyncConnections; i++) { var uri = this._connectionSettings.ConnectionPool.GetNext(null, out seed, out shouldPingHint); var host = uri.Host; var port = uri.Port; var tsocket = new TSocket(host, port); var transport = new TBufferedTransport(tsocket, 1024); var protocol = new TBinaryProtocol(transport); var client = new Rest.Client(protocol); _clients.Enqueue(client); } }
public RunnerDelegate PrepareAction(IGatEvent evt, bool forceClone) { //we clone anyways, regardless of whether forced since we go over the wire GatEvent clonedEvt = BuildThriftEvent(evt); TTransport transport = new TSocket(_host, _port); GatConsumer.Client client = new GatConsumer.Client(new TBinaryProtocol(transport)); transport.Open(); return(new RunnerDelegate(delegate() { try { return new ThriftEventResponse(client.onEvent(clonedEvt)); } finally { try { transport.Close(); } catch (Exception) { } } })); }
public static void Say(int port, string msg, string ip = "127.0.0.1") { TTransport transport = new TSocket(ip, port); TProtocol protocol = new TBinaryProtocol(transport); HelloWorldService.Client client = new HelloWorldService.Client(protocol); transport.Open(); try { client.SayHello(msg); } catch (TApplicationException x) { Console.WriteLine(x.StackTrace); } finally { transport.Close(); } }
public static void Conectar() { Transporte = new TSocket("localhost", 9090); Transporte.Open(); ProtocoloBinario = new TBinaryProtocol(Transporte); CuentaServiceProtocolo = new TMultiplexedProtocol(ProtocoloBinario, nameof(CuentaService)); ExperienciaEducativaServiceProtocolo = new TMultiplexedProtocol(ProtocoloBinario, nameof(ExperienciaEducativaService)); SalonDeClasesServiceProtocolo = new TMultiplexedProtocol(ProtocoloBinario, nameof(SalonDeClasesService)); ChatServiceProtocolo = new TMultiplexedProtocol(ProtocoloBinario, nameof(ChatService)); PresentacionServiceProtocolo = new TMultiplexedProtocol(ProtocoloBinario, nameof(PresentacionService)); CuentaServiceCliente = new CuentaService.Client(CuentaServiceProtocolo); ExperienciaEducativaServiceCliente = new ExperienciaEducativaService.Client(ExperienciaEducativaServiceProtocolo); SalonDeClasesServiceCliente = new SalonDeClasesService.Client(SalonDeClasesServiceProtocolo); ChatServiceCliente = new ChatService.Client(ChatServiceProtocolo); PresentacionServiceCliente = new PresentacionService.Client(PresentacionServiceProtocolo); EstaConectado = true; }
static void Main(string[] args) { try { var port = 9095; TTransport transport = new TSocket("localhost", port); TProtocol protocol = new TBinaryProtocol(transport); ThriftTestService.Client client = new ThriftTestService.Client(protocol); Console.WriteLine("ThriftTest opening transport on port {0}", port); transport.Open(); try { RunTests(client); Console.WriteLine("Tests completed."); } finally { transport.Close(); Console.WriteLine("Transport closed."); } } catch (Exception x) { //} catch (TApplicationException x) { Console.WriteLine(x.ToString()); } }
public static void Test(string configname, string table, string rowid, string family, string columnname, TCompareOp op, object columnvalue, string[] delcolumns) { //实例化Socket连接 //transport = new TSocket("2.5.172.38", 30001); var transport = new TSocket(configname); //实例化一个协议对象 TProtocol tProtocol = new TBinaryProtocol(transport); byte[] tablenamebytes = Encoding.UTF8.GetBytes(table); byte[] rowidbytes = Encoding.UTF8.GetBytes(rowid); byte[] familybytes = Encoding.UTF8.GetBytes(family); byte[] columnnamebytes = Encoding.UTF8.GetBytes(columnname); byte[] columnvaluebytes = null; if (columnvalue != null) { columnvaluebytes = Serializer.TSerializer.GetBytes(columnvalue); } using (var client = new HBase.Thrift2.THBaseService.Client(tProtocol)) { transport.Open(); try { TRowMutations rowmutations = new TRowMutations(); rowmutations.Row = rowidbytes; rowmutations.Mutations = new List <TMutation>(); foreach (var col in delcolumns) { rowmutations.Mutations.Add(new TMutation { //Put=new TPut() }); } client.checkAndMutate(tablenamebytes, rowidbytes, familybytes, columnnamebytes, op, columnvaluebytes, rowmutations); } finally { transport.Close(); } } }
public static T Get <T>(string configname, string table, string rowid, Func <Type, string, System.Reflection.PropertyInfo> funGetProperty) where T : new() { //实例化Socket连接 //transport = new TSocket("2.5.172.38", 30001); var transport = new TSocket(configname); //实例化一个协议对象 TProtocol tProtocol = new TBinaryProtocol(transport); byte[] tablenamebytes = Encoding.UTF8.GetBytes(table); byte[] rownamebytes = Encoding.UTF8.GetBytes(rowid); using (var client = new HBase.Thrift2.THBaseService.Client(tProtocol)) { transport.Open(); try { var rows = client.get(tablenamebytes, new HBase.Thrift2.TGet(rownamebytes)); if (rows.ColumnValues != null && rows.ColumnValues.Count > 0) { T instance = (T)System.Activator.CreateInstance(typeof(T)); var typet = typeof(T); foreach (var cv in rows.ColumnValues) { var columname = Encoding.UTF8.GetString(cv.Qualifier); var pop = funGetProperty(typet, columname); pop.SetValue(instance, TSerializer.GetObject(pop.PropertyType, cv.Value)); } return(instance); } else { return(default(T)); } } finally { transport.Close(); } } }
static void Main(string[] args) { try { TTransport transport = new TSocket("localhost", 3030); TProtocol protocol = new TBinaryProtocol(transport); ContactsService.Client client = new ContactsService.Client(protocol); transport.Open(); try { var contacts = client.getContacts(); foreach (var e in contacts) { Console.WriteLine(e); } contacts = client.addContacts(new List <Contact> { new Contact { FirstName = "Bruce", LastName = "Wayne", Email = "*****@*****.**" }, new Contact { FirstName = "Clark", LastName = "Kent", Email = "*****@*****.**" } }); foreach (var e in contacts) { Console.WriteLine(e); } } finally { transport.Close(); } } catch (TApplicationException exception) { Console.WriteLine(exception.StackTrace); } }
public ClusterNode(IPEndPoint myIPandPort, List <IPEndPoint> ClusterNodeList, List <int> nodeIdList) { //设定各个状态的初始值 myIPandPort_ = myIPandPort; node_should_stop_ = false; // 获取其他所有节点的transport和client,存于ExClusterNodeList,不包括自身 ExClusterNodeList_ = new List <ClusterNodeSocket>(); OriginalIPEndPointList_ = new List <IPEndPoint>(); int _id = -1; for (int i = 0; i < ClusterNodeList.Count; ++i) { IPEndPoint IPPort = ClusterNodeList[i]; if (myIPandPort_.Equals(IPPort)) { _id = nodeIdList[i]; continue; } OriginalIPEndPointList_.Add(IPPort); TTransport transport = new TSocket(IPPort.Address.ToString(), IPPort.Port, Config.Heartbeat_interval * 2); //timeout ms TProtocol protocol = new TBinaryProtocol(transport); ClusterNodeRPC.Client client = new ClusterNodeRPC.Client(protocol); ExClusterNodeList_.Add(new ClusterNodeSocket(transport, client, IPPort, nodeIdList[i])); } //初始化Server ServerHandler_ = new ServerHandler(0, _id, NodeRole.Follower, ExClusterNodeList_); ClusterNodeRPC.Processor processor = new ClusterNodeRPC.Processor(ServerHandler_); ServerTransport_ = new TServerSocket(myIPandPort.Port); Server_ = new TThreadPoolServer(processor, ServerTransport_); // 初始化线程 TServer_ = new Thread(server_thread); Tconnect_ = new Thread(connect); TStateChecker_ = new Thread(state_checker); Tcommit_ = new Thread(commit); }
public Dictionary <byte[], TCell> GetHBaseImage() { var socket = new TSocket(_hbaseThrif, _hbaseThrifPort); var transport = new TBufferedTransport(socket); var protocol = new TBinaryProtocol(transport); Hbase.Client hbaseClient = new Hbase.Client(protocol); Dictionary <byte[], TCell> hbaseResult = new Dictionary <byte[], TCell>(); transport.Open(); //List<byte[]> tableNames = hc.getTableNames(); byte[] table = Encoding.UTF8.GetBytes("FiservImages"); byte[] row = Encoding.UTF8.GetBytes(_documentId); 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; hbaseResult = 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); // Main a = new Main(); // a.OpenFile(singleRow.Value.Value, "output.docx"); //} } return(hbaseResult); }
/*private void button1_Click(object sender, EventArgs e) * { * string username = usernameBox.Text; * string password = passwordBox.Text; * Employee es = new Employee() { Username = username, Password = password }; * if (username!=null && password!= null){ * try * { * ctrl.login(es); * //MessageBox.Show("Login succeded"); * mainPage chatWin = new mainPage(es,ctrl,this); * chatWin.Text = "Chat window for " + username; * chatWin.Show(); * this.Hide(); * } * catch (Exception ex) * { * MessageBox.Show("Nu exista cont cu aceste date de logare! Va rugam incercati din nou!"); * return; * } * } * }*/ private void button1_Click(object sender, EventArgs e) { string username = usernameBox.Text; string password = passwordBox.Text; try { TTransport transport = new TSocket("localhost", 9091); TProtocol protocol = new TBinaryProtocol(transport); transport.Open(); AppService.Client client = new AppService.Client(protocol); port = getFreePort(9092); String response = client.login(username, password, "localhost", port); transport.Close(); if (response.Equals("loggedIn")) { mainPage chatWin = new mainPage(port, this, username); chatWin.Text = "Window for " + username; chatWin.Show(); this.Hide(); } else if (response.Equals("alreadyLoggedIn")) { throw new Exception("Utilizator deja conectat!"); } else { throw new Exception("Nu exista cont cu aceste date de logare! Va rugam incercati din nou!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
private void PopulateShowTable(bool isUpdated) { if (isUpdated) { foreach (ShowDTO s in showData.ToList <ShowDTO>()) { var row = new string[] { s.Id.ToString(), s.ArtistName, s.Location, s.DataTimp.Split('T')[0], s.NrAvailableSeats.ToString(), s.NrSoldSeats.ToString() }; var lvi = new ListViewItem(row); if (s.NrAvailableSeats == 0) { lvi.BackColor = Color.Red; } listaShow.Items.Add(lvi); } } else { TTransport transport = new TSocket("localhost", 9091); TProtocol protocol = new TBinaryProtocol(transport); transport.Open(); AppService.Client client = new AppService.Client(protocol); showData = client.findAllShows(); transport.Close(); listaShow.Items.Clear(); foreach (ShowDTO s in showData.ToList <ShowDTO>()) { var row = new string[] { s.Id.ToString(), s.ArtistName, s.Location, s.DataTimp.Split('T')[0], s.NrAvailableSeats.ToString(), s.NrSoldSeats.ToString() }; var lvi = new ListViewItem(row); if (s.NrAvailableSeats == 0) { lvi.BackColor = Color.Red; } listaShow.Items.Add(lvi); } } }
public static GW.Client GetNetwork(string text) { var arr = text.Split(":"[0]); var ip = arr[0]; int port = int.Parse(arr[1]); TTransport transport = new TSocket(ip, port, 100000); TProtocol protocol = new TBinaryProtocol(transport); try { transport.Open(); } catch { return(null); } var c = new Client.GW.Client(protocol); Global.Network = c; return(c); }
/// <summary> /// Connect to impalad and construct ImpalaService.Client. /// </summary> protected void Connect() { var socket = new TSocket(this.ConnectionParameter.Host, this.ConnectionParameter.Port); this.disposer.Add(socket); this.transport = new TBufferedTransport(socket); this.disposer.Add(this.transport); this.transport.Open(); var protocol = new TBinaryProtocol(this.transport); this.disposer.Add(protocol); this.service = new ImpalaService.Client(protocol); this.disposer.Add(this.service); var pingResult = this.service.PingImpalaService(); this.ServerVersion = pingResult.Version; }
public async Task <string> ClientStart(string jsonFormate, string serverName, string zkIpAddress, string domain = "", int port = 8080) { var resultData = await ZkConnect(zkIpAddress, serverName); var ipAndPort = resultData.Split(':'); domain = ipAndPort[0]; port = Convert.ToInt32(ipAndPort[1]); TTransport transport = new TSocket(domain, port); TProtocol protocol = new TBinaryProtocol(transport); var client = ThriftClient.InstanceObject.Instance(protocol); client.InputProtocol.Transport.Open(); var result = client.JsonSend(jsonFormate); transport.Close(); return(result); }
public Tuple <TSocket, TSocket> CalculateSockets(SpaceshipSegment other, TDirection direction) { TSocket socket1 = this.SocketUp; TSocket socket2 = other.SocketDown; if (direction == TDirection.Right) { socket1 = this.SocketRight; socket2 = other.SocketLeft; } if (direction == TDirection.Down) { socket1 = this.SocketDown; socket2 = other.SocketUp; } if (direction == TDirection.Left) { socket1 = this.SocketLeft; socket2 = other.SocketRight; } return(new Tuple <TSocket, TSocket>(socket1, socket2)); }
public bool check(string userName, string password, int port) { bool reusit = false; foreach (Angajat angajat in service.GetAllAngajati()) { if (angajat.username.Equals(userName) && angajat.password.Equals(password)) { reusit = true; TTransport transport = new TSocket("localhost", port); transport.Open(); TProtocol protocol = new TBinaryProtocol(transport); UpdateClient.UpdateService.Client client = new UpdateClient.UpdateService.Client(protocol); service.addClient(client); Console.WriteLine("Received update client on port " + port); break; } } return(reusit); }
static void Main(string[] args) { try { //设置服务端端口号和地址 TTransport transport = new TSocket("localhost", 8800); transport.Open(); //设置传输协议为二进制传输协议 TProtocol protocol = new TBinaryProtocol(transport); //创建客户端对象 UserService.Client client = new UserService.Client(protocol); //调用服务端的方法 Console.WriteLine(client.GetUserName(11)); Console.WriteLine(client.GetUserInfo(11)); var c = client.GetUserInfo(11); Console.WriteLine(c.UserId); Console.WriteLine(c.UserName); Console.WriteLine(c.TrueName); Console.ReadKey(); } catch (TTransportException e) { Console.WriteLine(e.Message); } }
public void InsertReadData() { //实例化Socket连接 //transport = new TSocket("2.5.172.38", 30001); var transport = new TSocket("hbaseclient1"); //实例化一个协议对象 TProtocol tProtocol = new TBinaryProtocol(transport); string logtablename = "logs"; //using (var client = new HBase.Thrift.Hbase.Client(tProtocol)) //{ // transport.Open(); // var rows = client.getRow(Encoding.UTF8.GetBytes(logtablename), Encoding.UTF8.GetBytes("row1"), null); //} using (var client = new HBase.Thrift2.THBaseService.Client(tProtocol)) { transport.Open(); var rows = client.get(Encoding.UTF8.GetBytes(logtablename), new Thrift2.TGet(Encoding.UTF8.GetBytes("row1"))); } }
/// <summary> /// /// </summary> /// <param name="host">host ip</param> /// <param name="port">import port</param> /// <param name="timeout">timeout</param> /// <param name="bServerClient">ref </param> /// <returns></returns> public static TTransport Init(string host, int port, int timeout, ref BusinessServer.Client bServerClient) { TTransport transport = null; try { if (timeout > 0) { transport = new TSocket(host, port, timeout); } else { transport = new TSocket(host, port, 1200000); } TProtocol protocol = new TBinaryProtocol(transport); bServerClient = new BusinessServer.Client(protocol); } catch (Exception ex) { Logger <SocketOpter> .Log.Error("Init", ex); } return(transport); }
private void FilterNotSoldOut() { listaMeciuri.Items.Clear(); TTransport transport = new TSocket("localhost", 9091); TProtocol protocol = new TBinaryProtocol(transport); transport.Open(); TransformerService.Client client = new TransformerService.Client(protocol); var dtos = client.findAllMeciWithTickets().OrderBy(x => x.NumarBileteDisponibile).Reverse().ToList(); transport.Close(); var all = retreive(dtos); foreach (Meci s in all) { var row = new string[] { s.id, s.home, s.away, s.date.ToShortDateString(), s.numarBileteDisponibile.ToString() }; var lvi = new ListViewItem(row); listaMeciuri.Items.Add(lvi); lvi.Tag = s; } }
public packethandler(TSocket arg_socket) { sock = arg_socket.sock; }