Пример #1
0
        public List <byte[]> QueryCapLogImageH(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.QueryCapLogImageH(ID, day);
                if (transport.IsOpen)
                {
                    transport.Close();
                }
                #endregion
            }
            catch (Exception ex)
            {
                if (transport.IsOpen)
                {
                    transport.Close();
                }
                MB_MODULES.Views.MyMessage.showYes("网络异常,稍后重试!");
                return(null);
            }
            return(listImageBytes);
        }
Пример #2
0
        /// <summary>
        /// 查询比对记录数(筛选)
        /// </summary>
        /// <param name="captureRecordQueryValue"></param>
        /// <returns></returns>
        public List <SCountInfo> QueryCapRecordTotalCountHSXC(CaptureRecordQueryValue captureRecordQueryValue, List <string> channelName)
        {
            TTransport transport = new TSocket(GlobalCache.Host, GlobalCache.Port, 5000);
            TProtocol  protocol  = new TBinaryProtocol(transport);

            BusinessServer.Client _BusinessServerClient = new BusinessServer.Client(protocol);
            List <SCountInfo>     recordsCount          = new List <SCountInfo>();

            try
            {
                #region
                if (!transport.IsOpen)
                {
                    transport.Open();
                }
                //得到总数
                recordsCount = _BusinessServerClient.QueryCapRecordTotalCountHSXC(channelName, captureRecordQueryValue.StartDayValue, captureRecordQueryValue.EndDayValue);
                if (transport.IsOpen)
                {
                    transport.Close();
                }
                #endregion
            }
            catch (Exception ex)
            {
                if (transport.IsOpen)
                {
                    transport.Close();
                }
                MB_MODULES.Views.MyMessage.showYes("网络异常,稍后重试!");

                return(null);
            }
            return(recordsCount);
        }
Пример #3
0
        public List <MyChannelCfg> QueryAllChannel()
        {
            List <MyChannelCfg>  myListChannelCfg = new List <MyChannelCfg>();
            List <ChannelCfgLBS> ListChannelCfg   = new List <ChannelCfgLBS>();
            TTransport           transport        = new TSocket(GlobalCache.Host, GlobalCache.Port);
            TProtocol            protocol         = new TBinaryProtocol(transport);

            BusinessServer.Client _BusinessServerClient = new BusinessServer.Client(protocol);
            try
            {
                if (!transport.IsOpen)
                {
                    transport.Open();
                }
                ListChannelCfg = _BusinessServerClient.QueryAllChannelLBS();
                transport.Close();
            }
            catch (Exception ex)
            {
                //_WriteLog.WriteToLog("QueryAllChannel", ex);
                if (transport.IsOpen)
                {
                    transport.Close();
                }
                //MB_MODULES.Views.MyMessage.showYes("网络异常,稍后重试");
            }
            //todo(暂时不需要) 包装返回类 使其返回需要的类
            foreach (ChannelCfgLBS cc in ListChannelCfg)
            {
                myListChannelCfg.Add(new MyChannelCfg().ChannelCfgToMyChannelCfgLBS(cc));
            }


            return(myListChannelCfg);
        }
Пример #4
0
        /// <summary>
        /// 查询抓拍记录(筛选)
        /// </summary>
        /// <param name="captureRecordQueryValue"></param>
        /// <param name="pflag"></param>
        /// <returns></returns>
        public List <MyCapFaceLogWithImg> QueryCapLogSXC(CaptureRecordQueryValue captureRecordQueryValue, List <string> channelList)
        {
            List <CapFaceLog>          listCapFaceLog          = new List <CapFaceLog>();
            List <MyCapFaceLogWithImg> listMyCapFaceLogWithImg = new List <MyCapFaceLogWithImg>();
            //声明客户端内容
            TTransport transport = new TSocket(GlobalCache.Host, GlobalCache.Port);
            TProtocol  protocol  = new TBinaryProtocol(transport);

            BusinessServer.Client _BusinessServerClient = new BusinessServer.Client(protocol);
            try
            {
                //获得查询数据
                if (!transport.IsOpen)
                {
                    transport.Open();
                }
                listCapFaceLog = _BusinessServerClient.QueryCapLogSXC(channelList, captureRecordQueryValue.StartDayValue, captureRecordQueryValue.EndDayValue, captureRecordQueryValue.StartRowValue, captureRecordQueryValue.PageRowValue);


                for (int i = listCapFaceLog.Count - 1; i >= 0; i--)
                {
                    MyCapFaceLogWithImg _MyCapFaceLogWithImg = new MyCapFaceLogWithImg();
                    _MyCapFaceLogWithImg.Id        = captureRecordQueryValue.MaxCount - captureRecordQueryValue.StartRowValue - i;
                    _MyCapFaceLogWithImg.ID        = listCapFaceLog[i].ID;        // 获得抓拍id
                    _MyCapFaceLogWithImg.ChannelID = listCapFaceLog[i].ChannelID; // 获得通道id

                    //获得通道名称
                    foreach (MyChannelCfg mcc in QueryAllChannel())
                    {
                        if (listCapFaceLog[i].ChannelID == mcc.TcChaneelID)
                        {
                            _MyCapFaceLogWithImg.ChannelName = mcc.Name;
                        }
                    }

                    long     longTime = listCapFaceLog[i].Time;
                    DateTime time     = new DateTime(1970, 1, 1);
                    time = time.AddSeconds(longTime);
                    _MyCapFaceLogWithImg.time = time.ToString("yyyy/MM/dd HH:mm:ss");; // 获得抓拍时间

                    listMyCapFaceLogWithImg.Add(_MyCapFaceLogWithImg);
                }

                transport.Close();
            }
            catch (Exception ex)
            {
                if (transport.IsOpen)
                {
                    transport.Close();
                }
                //MB_MODULES.Views.MyMessage.showYes("网络异常,稍后重试");
                MB_MODULES.Views.MyMessage.showYes("网络异常,稍后重试");
                return(null);
            }
            return(listMyCapFaceLogWithImg);
        }
Пример #5
0
        public Task <string> GetReponseAsync(string actionkey, string requestobject)
        {
            TTransport transport = new TSocket($"{Addr}", Port);;
            TProtocol  protocol  = new TBinaryProtocol(transport);

            tConnect.Client Client = new tConnect.Client(protocol);
            transport.Open();

            return(Task.Run(() =>
            {
                try
                {
                    tReponseMsg result = Client.GetReponseAsync(new tRequestMsg()
                    {
                        ActionKey = actionkey, RequestObject = requestobject
                    });
                    transport.Close();
                    protocol.Dispose();
                    Client.Dispose();
                    return Newtonsoft.Json.JsonConvert.SerializeObject(new { result.ErrorCode, result.ErrorInfo, result.Result });
                    //thrift hack 否则这货会自动增加一个属性返回值很难看
                }
                catch (Exception ex)
                {
                    return Newtonsoft.Json.JsonConvert.SerializeObject(new tReponseMsg()
                    {
                        ErrorCode = ex.HResult, ErrorInfo = ex.Message
                    });
                }
            }));
        }
Пример #6
0
    public static RetInt createRoom()
    {
        TTransport transport = null;
        RetInt     result    = null;

        try
        {
            transport = new TSocket(AR_CLOUD_ADDR, AR_CLOUD_PORT);
            transport.Open();
            TProtocol      protocol = new TBinaryProtocol(transport);
            ARCloud.Client client   = new ARCloud.Client(protocol);

            result = client.createRoom();
        }
        catch (TException e)
        {
            Debug.LogError(e.Message);
        }
        finally
        {
            if (transport != null)
            {
                transport.Close();
            }
        }

        return(result);
    }
Пример #7
0
    public static RetStr saveAnchorId(int roomId, String anchorId)
    {
        TTransport transport = null;
        RetStr     result    = null;

        try
        {
            transport = new TSocket(AR_CLOUD_ADDR, AR_CLOUD_PORT);
            transport.Open();
            TProtocol      protocol = new TBinaryProtocol(transport);
            ARCloud.Client client   = new ARCloud.Client(protocol);
            result = client.saveAnchor(roomId, anchorId);
        }
        catch (TTransportException e)
        {
            Debug.LogError(e.Message);
            return(null);
        }
        finally
        {
            if (transport != null)
            {
                transport.Close();
            }
        }
        return(result);
    }
Пример #8
0
    public void executeAgent()
    {
        TTransport transport = new TSocket(AJANServer, AJANPort);
        TProtocol protocol = new TBinaryProtocol(transport);
        MAJANService.Client client = new MAJANService.Client(protocol);
        transport.Open();

        Debug.Log(caIndex);
        AJANExecute = caList[caIndex];

        try
        {
            MRDFGraph knowledge = new MRDFGraph();
            knowledge.ContentType = "text/turtle";
            string graph = getTaskList();
            if (graph == "")
                graph = "_:test <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Resource> .";
            knowledge.Graph = graph;
            AgentURI = client.ExecuteAgent(name, AJANExecute, knowledge);
        }
        finally
        {
            transport.Close();
        }
    }
Пример #9
0
        static void Main(string[] args)
        {
            try
            {
                TTransport            transport = new TSocket("localhost", 9091);
                TProtocol             protocol  = new TBinaryProtocol(transport);
                ClusterNodeRPC.Client client    = new ClusterNodeRPC.Client(protocol);

                transport.Open();
                try
                {
                    client.appendLogEntry("+ 5");
                    Console.WriteLine("+ 5");
                    client.appendLogEntry("* 3");
                    Console.WriteLine("* 3");
                    client.appendLogEntry("- 2");
                    Console.WriteLine("- 2");
                    int res = client.getTestNum();
                    Console.WriteLine(String.Format("res is {0}", res));
                }
                finally
                {
                    transport.Close();
                }
            }
            catch (TApplicationException x)
            {
                Console.WriteLine(x.StackTrace);
            }
        }
Пример #10
0
        public static Retorno enviarRequisicaoParaServidor_DeleteAresta(int identificadorServidor, Aresta a)
        {
            Retorno         retorno  = new Retorno(true);
            ServidorVizinho servidor = VariaveisGlobais.servidoresVizinhos.Where(p => p.Identificador == (identificadorServidor + 1)).FirstOrDefault();

            try
            {
                TTransport transport = new TSocket(servidor.IP, Convert.ToInt32(servidor.Porta));
                transport.Open();
                TProtocol protocol = new TBinaryProtocol(transport);
                VariaveisGlobais.client_servidor1 = new thriftGrafo.GrafoService.Client(protocol);

                retorno = VariaveisGlobais.client_servidor1.deleteAresta(a);

                transport.Close();
            }
            catch (Exception ex)
            {
                retorno.Sucesso  = false;
                retorno.Mensagem = "Não foi possível iniciar o servidor. " + ex.Message;
                return(retorno);
            }

            return(retorno);
        }
Пример #11
0
        public MainPage(int observerServerPort, Client myClient)
        {
            this.myClient = myClient;
            InitializeComponent();
            this.observerServerPort = observerServerPort;
            Task.Run(() => checkForUpdate());


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

            transport.Open();

            TransformerService.Client client = new TransformerService.Client(protocol);
            List <MeciDTO>            dtos   = client.findAllMeci();

            meciuriData = retreive(dtos);
            transport.Close();

            MessageServer messageServer = new MessageServer(observerServerPort); // start mini-server as observer on the client

            PopulateMeciTable();
            this.locuriCBox.Text            = "0";
            this.listaMeciuri.FullRowSelect = true;
        }
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void 测试联接是否成功_Click(object sender, EventArgs e)
    {
        TTransport transport = null;

        try
        {
            //192.168.2.111:60010
            //实例化Socket连接
            transport = new TSocket("192.168.2.111", 9090);
            //实例化一个协议对象
            TProtocol tProtocol = new TBinaryProtocol(transport);
            //实例化一个Hbase的Client对象
            var client = new Hbase.Client(tProtocol);
            //打开连接
            transport.Open();

            Label1.Text = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;联接成功..";
        }
        catch (Exception ex)
        {
            Label1.Text  = "联接失败..";
            Label1.Text += ex;
        }

        finally
        {
            if (transport != null)
            {
                transport.Close();
            }
        }
    }
Пример #13
0
        /**
         * Thrift入口函数:
         * service emsg_inf_push {
         *    string process(1:string licence,2:string sn,3:string content)
         *    string process_batch(1:string licence,2:string sn,3:list<string> contents)
         *}
         *
         * content样例:
         * {
         *          "envelope": {
         *              "id": "id",
         *              "type": 1,
         *              "from": "fromuser",
         *              "to": "touser",
         *              "ack": 1
         *          },
         *          "vsn": "0.0.1",
         *          "payload": {
         *              "attrs": {
         *                  "message_type": "contact",
         *                  "action": "reject",
         *                  "contact_icon": "头像",
         *                  "contact_nickname": "昵称",
         *                  "contact_id": "好友的用户id"
         *              }
         *          }
         *      }
         */
        private void button1_Click(object sender, EventArgs e)
        {
            TTransport transport = null;

            try
            {
                transport = new TSocket(host, port);
                TProtocol            protocol = new TBinaryProtocol(transport);
                emsg_inf_push.Client client   = new emsg_inf_push.Client(protocol);
                transport.Open();
                string content = createContent();
                var    req     = client.process(licence, sn, content);
                Console.WriteLine(string.Format("requst : {0}", req));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                if (null != transport)
                {
                    //close
                    transport.Close();
                }
            }
        }
    /// <summary>
    /// 删除表
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void  除表_Click(object sender, EventArgs e)
    {
        TTransport transport = null;

        try
        {
            //192.168.2.111:60010
            //实例化Socket连接
            transport = new TSocket("192.168.2.111", 9090);
            //实例化一个协议对象
            TProtocol tProtocol = new TBinaryProtocol(transport);
            //实例化一个Hbase的Client对象
            var client = new Hbase.Client(tProtocol);
            //打开连接
            transport.Open();

            client.deleteTable(txt表名.Text.ToUTF8Bytes());

            lab创建表信息状态.Text = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;删除成功..";
        }
        catch (Exception ex)
        {
            lab创建表信息状态.Text  = "删除表失败";
            lab创建表信息状态.Text += ex;
        }

        finally
        {
            if (transport != null)
            {
                transport.Close();
            }
        }
    }
    protected void 获取表_Click(object sender, EventArgs e)
    {
        TTransport transport = null;

        try
        {
            //192.168.2.111:60010
            //实例化Socket连接
            transport = new TSocket("192.168.2.111", 9090);
            //实例化一个协议对象
            TProtocol tProtocol = new TBinaryProtocol(transport);
            //实例化一个Hbase的Client对象
            var client = new Hbase.Client(tProtocol);
            //打开连接
            transport.Open();

            当前所有表(client);
        }
        catch (Exception ex)
        {
            ;
            lab创建表信息状态.Text += ex;
        }

        finally
        {
            if (transport != null)
            {
                transport.Close();
            }
        }
    }
Пример #16
0
        static void Main(string[] args)
        {
            TTransport transport = new TSocket("localhost", 9090);
            TProtocol  protocol  = new TBinaryProtocol(transport);

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

            transport.Open();
            try
            {
                string hello = client.hello("World");
                Console.WriteLine(hello);

                string ipaddr = client.ipaddr();
                Console.WriteLine(ipaddr);

                int random = client.random(5);
                Console.WriteLine(random);

                string uuid = client.uuid();
                Console.WriteLine(uuid);

                Calc calc = client.calculator(5, 7);
                Console.WriteLine(calc);
            }
            catch (SampleException e)
            {
                Console.WriteLine(e.StackTrace);
            }

            transport.Close();

            Console.ReadKey();
        }
Пример #17
0
        static void Main(string[] args)
        {
            TTransport transport = new TSocket("127.0.0.1", 7911);
            TProtocol  protocol  = new TBinaryProtocol(transport);

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

            transport.Open();
            try
            {
                int i = client.testCase1(1, 2, "3");
                Console.WriteLine(i);

                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("num1", "1");
                dic.Add("num2", "2");
                List <string> values = client.testCase2(dic);
                foreach (var item in values)
                {
                    Console.WriteLine(item);
                }
            }
            catch (Thrift.TApplicationException x)
            {
                Console.WriteLine(x.StackTrace);
            }
            finally
            {
                transport.Close();
            }

            Console.ReadKey();
        }
Пример #18
0
        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();
        }
Пример #19
0
        static void Main(string[] args)
        {
            try
            {
                TTransport transport            = new TSocket("localhost", 9091);
                TProtocol  protocol             = new TBinaryProtocol(transport);
                HelloWorldService.Client client = new HelloWorldService.Client(protocol);

                transport.Open();
                try
                {
                    String recv = client.hello("C# Client Send Hello.");
                    Console.WriteLine(recv);

                    recv = client.hello("C# Client Send World.");
                    Console.WriteLine(recv);
                }
                finally
                {
                    transport.Close();
                }
            }
            catch (TApplicationException x)
            {
                Console.WriteLine(x.StackTrace);
            }
        }
Пример #20
0
            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);
            }
            private void AcceptOn(TSocket tsocket)
            {
                try
                {
                    _acceptSockets.Add(tsocket);
                    lock (_sockets)
                    {
                        _sockets.Add(tsocket.Fd, tsocket);
                    }

                    EPollInterop.EPollControl(_epollFd,
                                              EPOLL_CTL_ADD,
                                              tsocket.Fd,
                                              EPOLLIN,
                                              tsocket.Fd);
                }
                catch
                {
                    tsocket.Close();
                    _acceptSockets.Remove(tsocket);
                    lock (_sockets)
                    {
                        _sockets.Remove(tsocket.Fd);
                    }
                    throw;
                }
            }
Пример #22
0
    public void createAgent()
    {
        Debug.Log(atIndex);
        foreach (AgentTemplate entry in templateList)
        {
            if (entry.label.Equals(atList[atIndex]))
            {
                AJANTemplate = entry.uri;
                break;
            }

        }
        Debug.Log(AJANTemplate);
        if (AJANTemplate != null)
        {
            TTransport transport = new TSocket(AJANServer, AJANPort);
            TProtocol protocol = new TBinaryProtocol(transport);
            MAJANService.Client client = new MAJANService.Client(protocol);
            transport.Open();

            try
            {
                MRDFGraph knowledge = new MRDFGraph();
                knowledge.ContentType = "text/turtle";
                knowledge.Graph = InitializeGraph();
                AgentURI = client.CreateAgent(name, AJANTemplate, knowledge);
            }
            finally
            {
                transport.Close();
            }
        }
    }
            private void AcceptOn(TSocket tsocket)
            {
                try
                {
                    _acceptSockets.Add(tsocket);
                    lock (_sockets)
                    {
                        _sockets.Add(tsocket.Fd, tsocket);
                    }

                    EPollInterop.EPollControl(_epollFd,
                                              EPollOperation.Add,
                                              tsocket.Fd,
                                              EPollEvents.Readable,
                                              EPollData(tsocket.Fd));
                }
                catch
                {
                    tsocket.Close();
                    _acceptSockets.Remove(tsocket);
                    lock (_sockets)
                    {
                        _sockets.Remove(tsocket.Fd);
                    }
                    throw;
                }
            }
Пример #24
0
        static void Main(string[] args)
        {
            TTransport transport = new TSocket("localhost", 10240);

            transport.Open();

            TProtocol protocol = new TBinaryProtocol(transport);

            SampleService.Client cli = new SampleService.Client(protocol);

            ServiceVersion ver = cli.GetVersion();

            System.Console.WriteLine("Remote Service Version: {0} - v{1}", ver.Name, ver.Version);

            //while (true) {
            var hellos = cli.SayHello("Thrift" + DateTime.Now.ToString());

            foreach (string item in hellos)
            {
                System.Console.WriteLine(item);
            }

            System.Threading.Thread.Sleep(1000);
            //}

            System.Console.ReadKey();
            transport.Close();
        }
        /// <summary>
        /// Operation the specified loginSite, imageUrl and image.
        /// </summary>
        /// <param name="loginSite">Login site.</param>
        /// <param name="imageUrl">Image URL.</param>
        /// <param name="image">Image.</param>
        public string Operation(string loginSite, string imageUrl = "", Image image = null)
        {
            string     result    = "";
            TTransport transport = new TSocket(_host, _port);

            try
            {
                TProtocol protocol            = new TBinaryProtocol(transport);
                ThriftOperation.Client client = new ThriftOperation.Client(protocol);
                transport.Open();
                OperationObj operationObj = new OperationObj()
                {
                    LoginSite = loginSite,
                    ImageUrl  = imageUrl,
                    //Image = ImageHelper.GetBytesByImage(image)
                };

                result = client.Operation(operationObj);
            }
            catch (Exception ex)
            {
                ILog logger = LogManager.GetLogger(typeof(ThriftHelper));
                logger.Error("Operation Not Found!" + Environment.NewLine + ex.ToString());
            }
            finally {
                transport.Close();
            }
            return(result);
        }
        public graph G(bool scan)
        {
            if (this.raftNode.current_state == Raft.Node.State.Leader)   //CONSULTAS NÃO FAZEM COMITIS APENAS VALIDAM SE O NODO É O LIDER, APENAS UM LIDER PODE CONVERSAR COM O CLIENTE.
            {
                if (!scan || this.servers.Count() == 1)
                {
                    return(this.g);
                }

                graph G = new graph();
                foreach (string server in this.servers.Keys)
                {
                    TTransport             transport = new TSocket(server.Split(':')[0], int.Parse(server.Split(':')[1]));
                    TProtocol              protocol  = new TBinaryProtocol(transport);
                    Thrift.TheGraph.Client client    = new Thrift.TheGraph.Client(protocol);
                    transport.Open();

                    G.V.AddRange(client.G(false).V);
                    G.E.AddRange(client.G(false).E);

                    transport.Close();
                }

                return(G);
            }
            else
            {
                Console.WriteLine("APENAS LIDERES PODEM CONSULTAR");
                return(null);
            }
        }
Пример #27
0
        public static void Put <T>(string configname, string table, string family, string rowid, T obj, Func <T, IEnumerable <KeyValuePair <string, object> > > fun)
        {
            //实例化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[] familybytes    = Encoding.UTF8.GetBytes(family);
            byte[] rownamebytes   = Encoding.UTF8.GetBytes(rowid);
            using (var client = new HBase.Thrift2.THBaseService.Client(tProtocol))
            {
                transport.Open();

                try
                {
                    List <TColumnValue> columnvaluelist = new List <TColumnValue>();
                    foreach (var kv in fun(obj))
                    {
                        columnvaluelist.Add(new TColumnValue(familybytes, Encoding.UTF8.GetBytes(kv.Key),
                                                             Serializer.TSerializer.GetBytes(kv.Value)));
                    }

                    client.put(tablenamebytes, new HBase.Thrift2.TPut(rownamebytes, columnvaluelist));
                }
                finally
                {
                    transport.Close();
                }
            }
        }
Пример #28
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();
        }
Пример #29
0
        public void ThrifTestMethod1()
        {
            //服务端:开始Thrift rpc服务
            new Thread(() =>
            {
                var processor1 = new HelloThrift.Processor(new HelloThriftHandler());
                TMultiplexedProcessor processor = new TMultiplexedProcessor();
                processor.RegisterProcessor("HelloThriftHandler", processor1);
                var serverTransport = new TServerSocket(9090);
                var server1         = new TThreadedServer(processor, serverTransport);
                Console.WriteLine("向客户端输出服务开启");
                server1.Serve();
            }).Start();

            //客户端:调用服务端的HelloThrift的HelloWorld方法
            TTransport           transport = new TSocket("localhost", 9090);
            TProtocol            protocol  = new TBinaryProtocol(transport);
            TMultiplexedProtocol mp1       = new TMultiplexedProtocol(protocol, "HelloThriftHandler");

            HelloThrift.Client client = new HelloThrift.Client(mp1);
            transport.Open();
            client.HelloWorld();
            client.adding(2, 3);
            Console.WriteLine(client.GetData(1));
            transport.Close();
        }
Пример #30
0
        static void RunThriftBio()
        {
            //TTransport transport = new TSocket("localhost", 7911);
            //TProtocol protocol = new TBinaryProtocol(transport);
            //Helloword.Client client = new Helloword.Client(protocol);
            //transport.Open();
            //String user = "******";
            //CodeTimerAdvance.TimeByConsole("thrift bio", _count, a =>
            //{
            //    var reply = client.SayHello(new HelloRequest { Name = user });
            //}, _threadcount);
            //transport.Close();


            //多线程不能复用TSocket故需每次实例化。
            String user = "******";

            CodeTimerAdvance.TimeByConsole("thrift bio", _count, a =>
            {
                TTransport transport = new TSocket("localhost", 7911);
                transport.Open();
                TProtocol protocol = new TBinaryProtocol(transport);
                using (Helloword.Client client = new Helloword.Client(protocol))
                {
                    var reply = client.SayHello(new HelloRequest {
                        Name = user
                    });
                }
                transport.Close();
            }, _threadcount);
        }