Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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();
                }
            }
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
 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());
     }
 }
Esempio n. 6
0
        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;
        }
Esempio n. 7
0
        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();
            }
        }
Esempio n. 9
0
        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();
                }
            }
        }
Esempio n. 10
0
        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();
                }
            }
        }
Esempio n. 11
0
        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);
            }
        }
Esempio n. 12
0
        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);
                }
            }
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        /*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;
            }
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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);
            }
        }
Esempio n. 17
0
        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")));
            }
        }
Esempio n. 18
0
        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;
            }
        }
Esempio n. 19
0
        public static void Main()
        {
            try
            {
                TTransport     transport = new TSocket("localhost", 9090);
                TProtocol      protocol  = new TBinaryProtocol(transport);
                SendLog.Client client    = new SendLog.Client(protocol);

                transport.Open();
                try
                {
                    Random         ran        = new Random();
                    string         strContent = "";
                    List <LogInfo> lstLogInfo = new List <LogInfo>();
                    for (int i = 0; i < 1000; i++)
                    {
                        LogInfo info = new LogInfo();
                        info.Content    = strContent;
                        strContent     += i;
                        info.DeviceName = i.ToString();
                        info.Time       = (int)DateTime.UtcNow.Ticks;
                        info.Category   = "category" + i;
                        lstLogInfo.Add(info);
                    }

                    client.send_log(lstLogInfo);
                }
                finally
                {
                    transport.Close();
                }
            }
            catch (TApplicationException x)
            {
                Console.WriteLine(x.StackTrace);
            }
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            int flag = 0;

            while (true)
            {
                for (int i = 0; i < 10; i++)
                {
                    ThriftRequest request = new ThriftRequest
                    {
                        RequestAddress = "APIName",
                        Data           = $"Request {flag++}"
                    };

                    ThriftResponse response = null;
                    using (TTransport trans = new TSocket(_serverIP, _port))
                    {
                        trans.Open();
                        using (TProtocol Protocol = new TBinaryProtocol(trans))
                        {
                            //多服务
                            using (TMultiplexedProtocol muprotocol = new TMultiplexedProtocol(Protocol, _serverName))
                            {
                                using (var client = new ServerService.Client(muprotocol))
                                {
                                    response = client.Invoke(request);
                                }
                            }
                        }
                    }

                    Console.WriteLine($"Server Response: Status {response.Status}, Data {response.Data}, ErrMsg {response.ErrMsg}");
                }

                Console.ReadKey();
            }
        }
Esempio n. 21
0
        private void PopulateMeciTable()
        {
            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.findAllMeci();

            transport.Close();

            var all = retreive(dtos);

            foreach (Meci s in all)
            {
                if (s.numarBileteDisponibile > 0)
                {
                    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;
                }
                else
                {
                    var          row = new string[] { s.id, s.home, s.away, s.date.ToShortDateString(), "SOLD OUT" };
                    ListViewItem lvi = new ListViewItem(row);
                    lvi.ForeColor = Color.Red;
                    listaMeciuri.Items.Add(lvi);
                    lvi.Tag = s;
                }
            }
        }
        public void ConnectAndListern(int port, string ip = "127.0.0.1")
        {
            //Tsocket: TCP/IP Socket接口
            TSocket tSocket = new TSocket(ip, port);
            //消息结构协议
            TProtocol protocol = new TBinaryProtocol(tSocket);

            try
            {
                if (client == null)
                {
                    client = new global::HelloWorldBidirectionService.Client(protocol);
                    tSocket.Open();        //建立连接
                    StartListern(tSocket); //启动监听线程
                }
                //cli.SayHello(msg);
                //tSocket.Close();
                //cli.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 23
0
        public List <byte[]> QuerySenceImg(string ID, string day)
        {
            TTransport transport = new TSocket(GlobalCache.Host, GlobalCache.Port);
            TProtocol  protocol  = new TBinaryProtocol(transport);

            BusinessServer.Client _BusinessServerClient = new BusinessServer.Client(protocol);
            List <byte[]>         listImageBytes        = new List <byte[]>();

            try
            {
                #region
                //打开连接
                if (!transport.IsOpen)
                {
                    transport.Open();
                }
                //调用接口获得抓拍照片
                listImageBytes = _BusinessServerClient.QuerySenceImg(ID, day);
                if (transport.IsOpen)
                {
                    transport.Close();
                }
                #endregion
            }
            catch (Exception ex)
            {
                if (transport.IsOpen)
                {
                    transport.Close();
                }
                //MB_MODULES.Views.MyMessage.showYes("网络异常,稍后重试");
                MB_MODULES.Views.MyMessage.showYes("网络异常,稍后重试!");
                return(null);
            }
            return(listImageBytes);
        }
Esempio n. 24
0
        public static void Delete(string configname, string table, string rowid)
        {
            //实例化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);
            using (var client = new HBase.Thrift2.THBaseService.Client(tProtocol))
            {
                transport.Open();
                try
                {
                    TDelete del = new TDelete(rowidbytes);
                    client.deleteSingle(tablenamebytes, del);
                }
                finally
                {
                    transport.Close();
                }
            }
        }
Esempio n. 25
0
        private void button1_Click(object sender, EventArgs e)
        {
            string username = usernameBox.Text;
            string password = passwordBox.Text;

            if (username != null && password != null)
            {
                TTransport transport = new TSocket("localhost", 9091);
                TProtocol  protocol  = new TBinaryProtocol(transport);
                transport.Open();

                TransformerService.Client client = new TransformerService.Client(protocol);
                observerServerPort = getAvailablePort(9092);
                Debug.WriteLine("port for client's server: " + observerServerPort);
                String response = client.login(username, password, "localhost", observerServerPort);
                Console.WriteLine("CSharp client received: {0}", response);
                transport.Close();

                string id = "null";
                if (response.Equals("error"))
                {
                    throw new Exception("authentification failed");
                }
                else
                {
                    id = response;
                }
                Random   random    = new Random();
                string   sessionId = random.NextDouble().ToString();
                Client   myClient  = new Client(id, sessionId, username, password, "localhost", observerServerPort);
                MainPage form2     = new MainPage(observerServerPort, myClient);
                form2.Text = "Form for " + username;
                form2.Show();
                this.Hide();
            }
        }
        private static void Main(string[] args)
        {
            var transport = new TSocket("localhost", 9090);
            var protocol  = new TBinaryProtocol(transport);
            var client    = new LibraryService.Client(protocol);

            transport.Timeout = 100;

            try
            {
                transport.Open();

                var allBooks = client.GetAllBooks(); // Thrift call

                Console.WriteLine("Total number of books: {0}\n", allBooks.Count);

                if (allBooks.Count > 0)
                {
                    Console.Write("Getting the first book: ");
                    var firstBook = client.GetBook(allBooks.First().Id); // Thrift call

                    Console.WriteLine("Id: {0}, {1} by {2}", firstBook.Id, firstBook.Title, firstBook.Author);
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine("Could not connect to the server: {0}.", e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occured: {0}", e.Message);
            }

            Console.WriteLine("\nDone. Press any key to continue...");
            Console.ReadKey(true);
        }
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var trasport             = new TSocket("localhost", 8081);
            var binaryProtocol       = new TBinaryProtocol(trasport);
            var turismServerProtocol = new TMultiplexedProtocol(binaryProtocol, nameof(ITransportServer.Iface));
            var server = new ITransportServer.Client(turismServerProtocol);

            try
            {
                trasport.Open();
                Application.Run(new Login(server));
            }
            catch (Exception e)
            {
                MessageBox.Show(e.StackTrace);
            }
            finally
            {
                trasport.Close();
            }
        }
Esempio n. 28
0
        public void logout()
        {
            //Console.WriteLine("Ctrl logout");
            // ctrl.logout(CurrentUser);
            // CurrentUser = null;
            // ctrl.updateEvent -= userUpdate;
            TTransport transport = new TSocket("localhost", 9091);
            TProtocol  protocol  = new TBinaryProtocol(transport);

            transport.Open();

            AppService.Client client = new AppService.Client(protocol);

            String response = client.logOut(this.currentClient, "localhost", port);

            transport.Close();

            if (!response.Equals("loggedOut"))
            {
                throw new Exception("Eroare la logout!");
            }
            loginWindow.Enabled = true;
            loginWindow.Show();
        }
        private static void Main()
        {
            GamePlatform.Client client = null;
            while (true)
            {
                switch (Console.ReadLine())
                {
                case "Start":
                    var thread = new Thread(StartServer);
                    thread.Start();
                    break;

                case "Connect":
                    Console.WriteLine("Connecting to Unity...");
                    var transport = new TSocket("localhost", 9091);
                    var protocol  = new TBinaryProtocol(transport);
                    client = new GamePlatform.Client(protocol);
                    transport.Open();
                    break;

                case "Send":
                    Console.WriteLine("Message Sent From Server");
                    if (client != null)
                    {
                        client.SendMessageFromPlatform();
                    }
                    break;

                case "q":
                {
                    Environment.Exit(0);
                }
                break;
                }
            }
        }
Esempio n. 30
0
        private void button1_Click(object sender, EventArgs e)
        {
            String nume   = this.numeCBox.Text;
            String bilete = this.locuriCBox.Text;
            int    locuri = -1;

            int.TryParse(bilete, out locuri);

            if (nume.Length > 0 && bilete.Length > 0 && locuri != -1)
            {
                if (this.listaMeciuri.SelectedItems.Count > 0)
                {
                    ListViewItem item = this.listaMeciuri.SelectedItems[0];

                    Meci selectedMatch = (Meci)item.Tag;

                    if (selectedMatch.numarBileteDisponibile < locuri)
                    {
                        MessageBox.Show("Nu sunt destule bilete disponibile!");
                    }
                    else
                    {
                        selectedMatch.numarBileteDisponibile = selectedMatch.numarBileteDisponibile - locuri;

                        TTransport transport = new TSocket("localhost", 9091);
                        TProtocol  protocol  = new TBinaryProtocol(transport);
                        transport.Open();

                        TransformerService.Client client = new TransformerService.Client(protocol);
                        TipMeciDTO tipdto = (TipMeciDTO)Enum.ToObject(typeof(TipMeciDTO), selectedMatch.tip);
                        MeciDTO    mdto   = new MeciDTO
                        {
                            Id   = selectedMatch.id,
                            Home = selectedMatch.home,
                            Away = selectedMatch.away,
                            Date = selectedMatch.date.Ticks,
                            Tip  = tipdto,
                            NumarBileteDisponibile = selectedMatch.numarBileteDisponibile
                        };
                        ClientDTO cdto = new ClientDTO
                        {
                            Id       = myClient.id,
                            Nume     = nume,
                            Password = myClient.password,
                            Ip       = myClient.host,
                            Port     = myClient.port
                        };
                        client.ticketsSold(mdto, cdto);
                        transport.Close();

                        checkForUpdates(true);
                        PopulateMeciTable();

                        MessageBox.Show("Ati cumparat biletele!");
                    }
                }
                else
                {
                    MessageBox.Show("Nu ati selectat un meci din lista!");
                }
            }
            else
            {
                MessageBox.Show("Nu ati introdus bine datele!");
            }
        }