Close() public méthode

public Close ( ) : void
Résultat void
        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();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //�������ݿ�����
            TTransport transport = new TSocket("192.168.10.2", 9160);
            TProtocol protocol = new TBinaryProtocol(transport);
            Cassandra.Client client = new Cassandra.Client(protocol);
            transport.Open();

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

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

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

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

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

                    Work work = new Work();

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

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

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

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

        }
Exemple #4
0
        static void Main(string[] args)
        {
            var transport = new TSocket("localhost", 7911);
            var protocol = new TBinaryProtocol(transport);
            var client = new UserStorage.Client(protocol);

            transport.Open();
            var userdata = new UserProfile();
            userdata.Name = "Jeske";

            client.store(userdata);
            transport.Close();
        }
Exemple #5
0
        internal string InvokeTest()
        {
            TTransport transport = new TSocket(host, port);
            var client = new TSampleService.Client(new TBinaryProtocol(transport));

            try
            {
                transport.Open();
                return client.invokeTest();
            }
            finally
            {
                if (transport.IsOpen)
                {
                    transport.Close();
                }
            }
        }
        public void BlogModelScenario()
        {
            TTransport transport = new TSocket("localhost", 9160);
            TProtocol protocol = new TBinaryProtocol(transport);
            var client = new Cassandra.Client(protocol);

            Console.WriteLine("Opening Connection");
            transport.Open();

            string entryTitle = "now with bonus batch writes";
            string entryAuthor = "josh";
            string entryBody = "This is my blog entry yet again";
            string entryPostDate = DateTime.Now.ToShortDateString();

            var cfmap = new Dictionary<string, List<ColumnOrSuperColumn>>();

            //Column families are case sensitive
            //"BlogEntries"
            cfmap.Add("Standard1", new List<ColumnOrSuperColumn>
            {
                new ColumnOrSuperColumn(new Column("title", entryTitle)),
                new ColumnOrSuperColumn(new Column("body", entryBody)),
                new ColumnOrSuperColumn(new Column("author", entryAuthor)),
                new ColumnOrSuperColumn(new Column("postDate", entryPostDate)),
            });

            client.batch_insert("Keyspace1", entryTitle, cfmap, ConsistencyLevel.ONE);

            //Now Read it back.
            var predicate = new SlicePredicate(new SliceRange(false, 10));
            var parent = new ColumnParent("Standard1"); //"BlogEntries");

            var results = client.get_slice("Keyspace1", entryTitle, parent, predicate, ConsistencyLevel.ONE);

            foreach (ColumnOrSuperColumn resultColumn in results)
            {
                Column column = resultColumn.Column;
                Console.WriteLine("Name: {0}, value: {1}",
                    column.Name.UTFDecode(),
                    column.Value.UTFDecode());
            }
            Console.WriteLine("closing connection");
            transport.Close();
        }
        public List<Account> Get()
        {
            List<Account> accounts;

            using (var transport = new TSocket("localhost", 18801))
            {
                using (var protocol = new TBinaryProtocol(transport))
                {
                    using (var client = new AccountService.Client(protocol))
                    {
                        transport.Open();
                        accounts = client.GetAccounts(123456);
                        transport.Close();
                    }
                }
            }

            return accounts;
        }
Exemple #8
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 runHelloWorldSocketExample()
        {
            TTransport transport = new TSocket("localhost", 9090);
            TProtocol protocol = new TBinaryProtocol(transport);
            HelloWorld.Client client = new HelloWorld.Client(protocol);

            transport.Open();

            client.ping();
            Console.WriteLine("ping()");

            string msg = client.sayHello();
            Console.WriteLine(msg);

            msg = client.sayMsg(Constants.HELLO_IN_KOREAN);
            Console.WriteLine(msg);

            HelloStruct hellostruct = client.structTest(Constants.HELLO_IN_JAPANESE);
            Console.WriteLine(hellostruct.Id);

            transport.Close();
        }
Exemple #10
0
        public static void Start()
        {
            try
            {
                TTransport transport = new TSocket("128.208.4.237", 9090);
                TProtocol protocol = new TBinaryProtocol(transport);
                Rpc.Client client = new Rpc.Client(protocol);

                transport.Open();

                client.ping();
                Console.WriteLine("ping");
                Console.WriteLine(client.getObjects());
                Console.WriteLine("getObjects");

                transport.Close();
            }
            catch (TApplicationException x)
            {
                Console.WriteLine(x.StackTrace);
            }
        }
Exemple #11
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);
            }
        }
    /// <summary> Vector addition on DFE </summary>
    /// <param name = "size"> Size of arrays </param>
    /// <param name = "firstVector"> First vector </param>
    /// <param name = "secondVector"> Second vector </param>
    /// <param name = "scalar"> Scalar parameter </param>
    /// <returns> Data output </returns>
    public static List<int> VectorAdditionDfe(int size, List<int> firstVector, List<int> secondVector, int scalar)
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();

        // Make socket
        var transport = new TSocket("localhost", 9090);

        // Wrap in a protocol
        var protocol = new TBinaryProtocol(transport);

        // Create a client to use the protocol encoder
        var client = new VectorAdditionService.Client(protocol);

        sw.Stop();
        Console.WriteLine("Creating a client:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        List<int> dataOut = new List<int>();

        try
        {
            // Connect!
            sw.Reset();
            sw.Start();
            transport.Open();
            sw.Stop();
            Console.WriteLine("Opening connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Initialize maxfile
            sw.Reset();
            sw.Start();
            var maxfile = client.VectorAddition_init();
            sw.Stop();
            Console.WriteLine("Initializing maxfile:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Load DFE
            sw.Reset();
            sw.Start();
            var engine = client.max_load(maxfile, "*");
            sw.Stop();
            Console.WriteLine("Loading DFE:\t\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Allocate and send input streams to server
            sw.Reset();
            sw.Start();
            var address_x = client.malloc_int32_t(size);
            client.send_data_int32_t(address_x, firstVector);

            var address_y = client.malloc_int32_t(size);
            client.send_data_int32_t(address_y, secondVector);
            sw.Stop();
            Console.WriteLine("Sending input data:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Allocate memory for output stream on server
            sw.Reset();
            sw.Start();
            var address_out = client.malloc_float(size);
            sw.Stop();
            Console.WriteLine("Allocating memory for output stream on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Action writeLMem
            sw.Reset();
            sw.Start();
            var act = client.max_actions_init(maxfile, "writeLMem");
            client.max_set_param_uint64t(act, "address", 0);
            client.max_set_param_uint64t(act, "nbytes", size * 4);
            client.max_queue_input(act, "cpu_to_lmem", address_x, size * 4);
            client.max_run(engine, act);
            sw.Stop();
            Console.WriteLine("Writing to LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Action default
            sw.Reset();
            sw.Start();
            act = client.max_actions_init(maxfile, "default");
            client.max_set_param_uint64t(act, "N", size);
            client.max_set_param_uint64t(act, "A", scalar);
            client.max_queue_input(act, "y", address_y, size * 4);
            client.max_queue_output(act, "s", address_out, size * 4);
            client.max_run(engine, act);
            sw.Stop();
            Console.WriteLine("Vector addition time:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Unload DFE
            sw.Reset();
            sw.Start();
            client.max_unload(engine);
            sw.Stop();
            Console.WriteLine("Unloading DFE:\t\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Get output stream from server
            sw.Reset();
            sw.Start();
            dataOut = client.receive_data_int32_t(address_out, size);
            sw.Stop();
            Console.WriteLine("Getting output stream:\t(size = {0} bit)\t{1}s", size * 32, sw.Elapsed.TotalMilliseconds / 1000);

            // Free allocated memory for streams on server
            sw.Reset();
            sw.Start();
            client.free(address_x);
            client.free(address_y);
            client.free(address_out);
            sw.Stop();
            Console.WriteLine("Freeing allocated memory for streams on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Free allocated maxfile data
            sw.Reset();
            sw.Start();
            client.VectorAddition_free();
            sw.Stop();
            Console.WriteLine("Freeing allocated maxfile data:\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Close
            sw.Reset();
            sw.Start();
            transport.Close();
            sw.Stop();
            Console.WriteLine("Closing connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);
        }
        catch (SocketException e)
        {
            Console.WriteLine("Could not connect to the server: {0}.", e.Message);
            Environment.Exit(-1);
        }
        catch (Exception e)
        {
            Console.WriteLine("An error occured: {0}", e.Message);
            Environment.Exit(-1);
        }

        return dataOut;
    }
        public void SimpleScenario()
        {
            TTransport transport = new TSocket("localhost", 9160);
            TProtocol protocol = new TBinaryProtocol(transport);
            var client = new Cassandra.Client(protocol);

            Console.WriteLine("Opening Connection");
            transport.Open();

            //At this point we're using the standard configuration file
            var nameColumnPath = new ColumnPath("Standard1", null, "name");

            Console.WriteLine("Inserting a column");

            client.insert("Keyspace1",
                "1",
                nameColumnPath,
                "Josh Blogs".UTF(),
                Util.UnixTimestamp,
                ConsistencyLevel.ONE
                );

            client.insert("Keyspace1",
                "2",
                nameColumnPath,
                "Something else".UTF(),
                Util.UnixTimestamp,
                ConsistencyLevel.ONE);

            //Let's get something back out (this is our select statement)
            ColumnOrSuperColumn returnedColumn = client.get(
                "Keyspace1", //The database
                "1", //The actual key we want
                nameColumnPath, //Where that key sits
                ConsistencyLevel.ONE //HAZY
                );

            Console.WriteLine("We got Name: {0}, value {1}",
                returnedColumn.Column.Name.UTFDecode(),
                returnedColumn.Column.Value.UTFDecode());

            Console.WriteLine("Now let's try getting a range");

            //This is telling us the offest to get.  This is where paging would occur.
            var predicate = new SlicePredicate(new SliceRange(false, 10));
            var parent = new ColumnParent("Standard1");

            var keyedResults =
                client.multiget_slice("Keyspace1",
                    new List<string> { "1", "2" },
                    parent,
                    predicate,
                    ConsistencyLevel.ONE);

            foreach (var keyedResult in keyedResults)
            {
                Console.WriteLine("Key: {0}", keyedResult.Key);
                foreach (ColumnOrSuperColumn result in keyedResult.Value)
                {
                    Column column = result.Column;
                    Console.WriteLine("Name: {0}, value: {1}",
                        column.Name.UTFDecode(),
                        column.Value.UTFDecode());
                }
            }

            Console.WriteLine("closing connection");
            transport.Close();
        }
Exemple #14
0
    /// <summary> Simple on DFE </summary>
    /// <param name = "size"> Size of array </param>
    /// <param name = "dataIn"> Data input </param>
    /// <returns> Data output </returns>
    public static List<double> SimpleDFE(int size, List<double> dataIn)
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();

        // Make socket
        var transport = new TSocket("localhost", 9090);

        // Wrap in a protocol
        var protocol = new TBinaryProtocol(transport);

        // Create a client to use the protocol encoder
        var client = new SimpleService.Client(protocol);

        sw.Stop();
        Console.WriteLine("Creating a client:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        List<double> dataOut = new List<double>();

        try
        {
            // Connect!
            sw.Reset();
            sw.Start();
            transport.Open();
            sw.Stop();
            Console.WriteLine("Opening connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Allocate and send input streams to server
            sw.Reset();
            sw.Start();
            var address_dataIn = client.malloc_float(size);
            client.send_data_float(address_dataIn, dataIn);
            sw.Stop();
            Console.WriteLine("Sending input data:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Allocate memory for output stream on server
            sw.Reset();
            sw.Start();
            var address_dataOut = client.malloc_float(size);
            sw.Stop();
            Console.WriteLine("Allocating memory for output stream on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Action default
            sw.Reset();
            sw.Start();
            client.Simple(size, address_dataIn, address_dataOut);
            sw.Stop();
            Console.WriteLine("Simple time:\t\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Get output stream from server
            sw.Reset();
            sw.Start();
            dataOut = client.receive_data_float(address_dataOut, size);
            sw.Stop();
            Console.WriteLine("Getting output stream:\t(size = {0} bit)\t{1}s", size * 32, sw.Elapsed.TotalMilliseconds / 1000);

            // Free allocated memory for streams on server
            sw.Reset();
            sw.Start();
            client.free(address_dataIn);
            client.free(address_dataOut);
            sw.Stop();
            Console.WriteLine("Freeing allocated memory for streams on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            sw.Reset();
            sw.Start();
            transport.Close();
            sw.Stop();
            Console.WriteLine("Closing connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);
        }
        catch (SocketException e)
        {
            Console.WriteLine("Could not connect to the server: {0}.", e.Message);
            Environment.Exit(-1);
        }
        catch (Exception e)
        {
            Console.WriteLine("An error occured: {0}", e.Message);
            Environment.Exit(-1);
        }

        return dataOut;
    }
Exemple #15
0
    public static void Main(string[] args)
    {
        try {
            var transport = new TSocket("localhost", 9090);
            var protocol = new TBinaryProtocol(transport);
            var client = new SignExtService.Client(protocol);

            // Connect!
            transport.Open();

            if(args.Length != 2) {
                Console.WriteLine("Usage: $0 dfe_ip remote_ip");
                Environment.Exit(-1);
            }

            var dfe_ip_address = client.malloc_int64_t(5);
            client.inet_aton(args[0], dfe_ip_address);

            var remote_ip_address = client.malloc_int64_t(5);
            client.inet_aton(args[1], remote_ip_address);

            var netmask_address = client.malloc_int64_t(5);
            client.inet_aton("255.255.255.0", netmask_address);

            short port = 2000;

            // Initialize maxfile
            var maxfile = client.SignExt_init();

            // Load DFE
            var engine = client.max_load(maxfile, "*");

            max_config_key_bool_t_struct enumkey = new max_config_key_bool_t_struct();
            enumkey.Type = max_config_key_bool_t_enum.MAX_CONFIG_PRINTF_TO_STDOUT;
            client.max_config_set_bool(enumkey, 1);

            var actions = client.max_actions_init(maxfile, "default");

            client.max_run(engine, actions);
            client.max_actions_free(actions);

            var buffer_address = client.malloc_int64_t(1);
            int bufferSize = 4096 * 512;
            client.posix_memalign(buffer_address, 4096, bufferSize);

            long buffer = client.receive_data_int64_t(buffer_address, 1)[0];

            var toCpu = client.max_framed_stream_setup(engine, "toCPU",
                                                        buffer, bufferSize, -1);

            max_net_connection_t_struct enumconn = new max_net_connection_t_struct();
            enumconn.Type = max_net_connection_t_enum.MAX_NET_CONNECTION_QSFP_TOP_10G_PORT1;
            client.max_ip_config(engine, enumconn, dfe_ip_address, netmask_address);
            var dfe_socket = client.max_udp_create_socket(engine, "udpTopPort1");
            client.max_udp_bind(dfe_socket, port);
            client.max_udp_connect(dfe_socket, remote_ip_address, (short) 0);

            Console.WriteLine("Listening on {0} port {1}", args[0], port);

            Console.WriteLine("Waiting for kernel response...");

            var f_address = client.malloc_int64_t(1);
            var fsz_address = client.malloc_int64_t(1);
            int numMessageRx = 0;
            bool cond = true;

            while(cond) {
                if (client.max_framed_stream_read(toCpu, 1, f_address, fsz_address) == 1) {
                    numMessageRx += 1;

                    long fsz = client.receive_data_int64_t(fsz_address, 1)[0];
                    Console.WriteLine("CPU: Got output frame {0} - size {1} bytes", numMessageRx, fsz);

                    long f = client.receive_data_int64_t(f_address, 1)[0];

                    List<long> w = client.receive_data_int64_t(f, 3);

                    for (int i = 0; i < 3; i++) {
                        long wp;
                        if(w[i] < 0) {
                            wp = w[i] + (long)Math.Pow(2, 32) * (long)Math.Pow(2, 32);
                        } else {
                            wp = w[i];
                        }
                        Console.WriteLine("Frame [{0}] Word[{1}]: 0x{2:X}", numMessageRx, i, wp);
                    }

                    client.max_framed_stream_discard(toCpu, 1);

                    if (w[0] == 0 && w[1] == 0 && w[2] == 0) {
                        cond = false;
                    }

                } else {
                    Thread.Sleep(1/100000);
                }
            }

            client.max_udp_close(dfe_socket);
            client.max_framed_stream_release(toCpu);
            client.max_unload(engine);
            client.max_file_free(maxfile);
            client.free(dfe_ip_address);
            client.free(remote_ip_address);
            client.free(netmask_address);
            client.free(buffer_address);
            client.free(f_address);
            client.free(fsz_address);
            client.SignExt_free();

            Console.WriteLine("Done.");

            // Close!
            transport.Close();
            Environment.Exit(0);

        } catch (SocketException e) {
            Console.WriteLine("Could not connect to the server: {0}.", e.Message);
            Environment.Exit(-1);
        } catch (Exception e) {
            Console.WriteLine("An error occured: {0}", e.Message);
            Environment.Exit(-1);
        }
    }
Exemple #16
0
        public static void Main(string[] args)
        {
            /*
               	  +-------------------------------------------+
              | Server                                   |
              | (single-threaded, event-driven etc)      |
              +-------------------------------------------+
              | Processor                                |
              | (compiler generated)                     |
              +-------------------------------------------+
              | Protocol                                 |
              | (JSON, compact etc)                      |
              +-------------------------------------------+
              | Transport                                |
              | (raw TCP, HTTP etc)                      |
              +-------------------------------------------+
             */
            try{

                TTransport transport = new TSocket("localhost", 9090); 	// transport
                TProtocol protocol = new TBinaryProtocol(transport);	// protocol
                Calculator.Client client = new Calculator.Client(protocol);	// processor

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

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

                    Work work = new Work();

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

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

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

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

            Console.WriteLine ("Hello World!");
        }
    /// <summary> LMemLoopback on DFE </summary>
    /// <param name = "size"> Size of arrays </param>
    /// <param name = "inA"> First array </param>
    /// <param name = "inB"> Second array </param>
    /// <returns> Data output </returns>
    public static List<int> LMemLoopbackDFE(int size, List<int> inA, List<int> inB)
    {
        Stopwatch sw = new Stopwatch();
        List<int> outData = new List<int>();
        int sizeBytes = size * 4;
        try
        {
            // Connect!
            var transport = new TSocket("localhost", 9090);
            var protocol = new TBinaryProtocol(transport);
            var client = new LMemLoopbackService.Client(protocol);
            transport.Open();

            // Initialize maxfile
            sw.Reset();
            sw.Start();
            var maxfile = client.LMemLoopback_init();
            sw.Stop();
            Console.WriteLine("Initializing maxfile:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Load DFE
            sw.Reset();
            sw.Start();
            var engine = client.max_load(maxfile, "*");
            sw.Stop();
            Console.WriteLine("Loading DFE:\t\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Allocate and send input streams to server
            sw.Reset();
            sw.Start();
            var address_inA = client.malloc_int32_t(size);
            client.send_data_int32_t(address_inA, inA);

            var address_inB = client.malloc_int32_t(size);
            client.send_data_int32_t(address_inB, inB);
            sw.Stop();
            Console.WriteLine("Sending input data:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Allocate memory for output stream on server
            sw.Reset();
            sw.Start();
            var address_outData = client.malloc_int32_t(size);
            sw.Stop();
            Console.WriteLine("Allocating memory for output stream on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Writing to LMem
            sw.Reset();
            sw.Start();
            var actions = client.max_actions_init(maxfile, "writeLMem");
            client.max_set_param_uint64t(actions, "address", 0);
            client.max_set_param_uint64t(actions, "nbytes", sizeBytes);
            client.max_queue_input(actions, "cpu_to_lmem", address_inA, sizeBytes);

            client.max_run(engine, actions);

            actions = client.max_actions_init(maxfile, "writeLMem");
            client.max_set_param_uint64t(actions, "address", sizeBytes);
            client.max_set_param_uint64t(actions, "nbytes", sizeBytes);
            client.max_queue_input(actions, "cpu_to_lmem", address_inB, sizeBytes);

            client.max_run(engine, actions);
            sw.Stop();
            Console.WriteLine("Writing to LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Action default
            sw.Reset();
            sw.Start();
            actions = client.max_actions_init(maxfile, "default");
            client.max_set_param_uint64t(actions, "N", size);

            client.max_run(engine, actions);
            sw.Stop();
            Console.WriteLine("LMemLoopback time:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Reading from LMem
            sw.Reset();
            sw.Start();
            actions = client.max_actions_init(maxfile, "readLMem");
            client.max_set_param_uint64t(actions, "address", 2 * sizeBytes);
            client.max_set_param_uint64t(actions, "nbytes", sizeBytes);
            client.max_queue_output(actions, "lmem_to_cpu", address_outData, sizeBytes);

            client.max_run(engine, actions);
            client.free(actions);
            sw.Stop();
            Console.WriteLine("Reading from LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Unload DFE
            sw.Reset();
            sw.Start();
            client.max_unload(engine);
            sw.Stop();
            Console.WriteLine("Unloading DFE:\t\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Get output stream from server
            sw.Reset();
            sw.Start();
            outData = client.receive_data_int32_t(address_outData, size);
            sw.Stop();
            Console.WriteLine("Getting output stream:\t(size = {0} bit)\t{1}s", size * 32, sw.Elapsed.TotalMilliseconds / 1000);

            // Free allocated memory for streams on server
            sw.Reset();
            sw.Start();
            client.free(address_inA);
            client.free(address_inB);
            client.free(address_outData);
            sw.Stop();
            Console.WriteLine("Freeing allocated memory for streams on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Free allocated maxfile data
            sw.Reset();
            sw.Start();
            client.LMemLoopback_free();
            sw.Stop();
            Console.WriteLine("Freeing allocated maxfile data:\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Close!
            sw.Reset();
            sw.Start();
            transport.Close();
            sw.Stop();
            Console.WriteLine("Closing connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);
        }
        catch (SocketException e)
        {
            Console.WriteLine("Could not connect to the server: {0}.", e.Message);
            Environment.Exit(-1);
        }
        catch (Exception e)
        {
            Console.WriteLine("An error occured: {0}", e.Message);
            Environment.Exit(-1);
        }

        return outData;
    }
            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;
            }
Exemple #19
0
    /// <summary> Simple on DFE </summary>
    /// <param name = "size"> Size of array </param>
    /// <param name = "dataIn"> Data input </param>
    /// <returns> Data output </returns>
    public static List<double> SimpleDFE(int size, List<double> dataIn)
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();

        // Make socket
        var transport = new TSocket("localhost", 9090);

        // Wrap in a protocol
        var protocol = new TBinaryProtocol(transport);

        // Create a client to use the protocol encoder
        var client = new SimpleService.Client(protocol);

        sw.Stop();
        Console.WriteLine("Creating a client:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        List<double> dataOut = new List<double>();
        int sizeBytes = size * 4;

        try
        {
            // Connect!
            sw.Reset();
            sw.Start();
            transport.Open();
            sw.Stop();
            Console.WriteLine("Opening connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Initialize maxfile
            sw.Reset();
            sw.Start();
            var maxfile = client.Simple_init();
            sw.Stop();
            Console.WriteLine("Initializing maxfile:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Load DFE
            sw.Reset();
            sw.Start();
            var engine = client.max_load(maxfile, "*");
            sw.Stop();
            Console.WriteLine("Loading DFE:\t\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Allocate and send input streams to server
            sw.Reset();
            sw.Start();
            var address_dataIn = client.malloc_float(size);
            client.send_data_float(address_dataIn, dataIn);
            sw.Stop();
            Console.WriteLine("Sending input data:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Allocate memory for output stream on server
            sw.Reset();
            sw.Start();
            var address_dataOut = client.malloc_float(size);
            sw.Stop();
            Console.WriteLine("Allocating memory for output stream on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Action default
            sw.Reset();
            sw.Start();
            var actions = client.max_actions_init(maxfile, "default");
            client.max_set_param_uint64t(actions, "N", size);
            client.max_queue_input(actions, "x", address_dataIn, sizeBytes);
            client.max_queue_output(actions, "y", address_dataOut, sizeBytes);

            client.max_run(engine, actions);
            sw.Stop();
            Console.WriteLine("Simple time:\t\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Unload DFE
            sw.Reset();
            sw.Start();
            client.max_unload(engine);
            sw.Stop();
            Console.WriteLine("Unloading DFE:\t\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Get output stream from server
            sw.Reset();
            sw.Start();
            dataOut = client.receive_data_float(address_dataOut, size);
            sw.Stop();
            Console.WriteLine("Getting output stream:\t(size = {0} bit)\t{1}s", size * 32, sw.Elapsed.TotalMilliseconds / 1000);

            // Free allocated memory for streams on server
            sw.Reset();
            sw.Start();
            client.free(address_dataIn);
            client.free(address_dataOut);
            sw.Stop();
            Console.WriteLine("Freeing allocated memory for streams on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Free allocated maxfile data
            sw.Reset();
            sw.Start();
            client.Simple_free();
            sw.Stop();
            Console.WriteLine("Freeing allocated maxfile data:\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            sw.Reset();
            sw.Start();
            transport.Close();
            sw.Stop();
            Console.WriteLine("Closing connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);
        }
        catch (SocketException e)
        {
            Console.WriteLine("Could not connect to the server: {0}.", e.Message);
            Environment.Exit(-1);
        }
        catch (Exception e)
        {
            Console.WriteLine("An error occured: {0}", e.Message);
            Environment.Exit(-1);
        }

        return dataOut;
    }
Exemple #20
0
        public void SeteBayOrder(int index, int max)
        {
            string host = "localhost";
            int port = 60031;
            int timeout = 10 * 1000;

            TSocket socket = new TSocket(host, port, timeout);
            TProtocol protocol = new TBinaryProtocol(socket);
            Inbound_PaymentService.Client client = new Inbound_PaymentService.Client(protocol);

            try
            {
                socket.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Socket Open [NG]!!");
                throw new Exception(ex.ToString());
            }
            Console.WriteLine("Socket Open [OK]!!");

            max += index;

            List<SeteBayOrderRequest> successRequest = new List<SeteBayOrderRequest>();

            while (index < max)
            {
                foreach (string[] s in SampleOderInfo.list)
                {
                    try
                    {
                        SeteBayOrderRequest r = GetSampleRequest(s, index);
                        int result = client.SeteBayOrder(r);

                        successRequest.Add(r);
                        index++;
                    }
                    catch (ThriftException ex)
                    {
                        System.Console.WriteLine(string.Format("ThriftException!! : {0} ", ex.ExceptionMessage));
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(string.Format("Exception!! : {0} ", ex.ToString()));
                    }

                    if (index >= max) break;
                }
            }

            socket.Close();

            foreach (SeteBayOrderRequest r in successRequest)
            {
                System.Console.WriteLine(string.Format("Insert : {0}  /  {1} ", r.TransactionID, r.ItemID));
            }
        }
Exemple #21
0
        public void SeteBayAccountInfo(string UserID, string eBayID, string eBayToken, string dateString)
        {
            string host = "localhost";
            int port = 60030;
            int timeout = 10 * 1000;

            TSocket socket = new TSocket(host, port, timeout);
            TProtocol protocol = new TBinaryProtocol(socket);
            Inbound_ItemService.Client client = new Inbound_ItemService.Client(protocol);

            try
            {
                socket.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Socket Open [NG]!!");
                throw new Exception(ex.ToString());
            }
            Console.WriteLine("Socket Open [OK]!!");

            SeteBayAccountInfoRequest Request = new SeteBayAccountInfoRequest();
            Request.UserID = UserID;
            Request.EbayUserID = eBayID;
            Request.EbayTokenID = eBayToken;
            Request.ExpireDate = dateString;

            try
            {
                int seteBayAccountInfo = client.SeteBayAccountInfo(Request);
                System.Console.WriteLine(string.Format("Result is {0}\n", seteBayAccountInfo));
            }
            catch (ThriftException ex)
            {
                System.Console.WriteLine(string.Format("ThriftException!! : {0} ", ex.ExceptionMessage));
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(string.Format("Exception!! : {0} ", ex.ToString()));
            }

            socket.Close();
        }
 public void Dispose()
 {
     _socket.Close();
     _socket = null;
     _sasl.Dispose();
 }
    /// <summary> LMemLoopback on DFE </summary>
    /// <param name = "size"> Size of arrays </param>
    /// <param name = "inA"> First array </param>
    /// <param name = "inB"> Second array </param>
    /// <returns> Data output </returns>
    public static List<int> LMemLoopbackDFE(int size, List<int> inA, List<int> inB)
    {
        List<int> outData = new List<int>();
        int sizeBytes = size * 4;
        Stopwatch sw = new Stopwatch();

        try
        {
            // Make socket
            sw.Start();
            var transport = new TSocket("localhost", 9090);

            // Wrap in a protocol
            var protocol = new TBinaryProtocol(transport);

            // Create a client to use the protocol encoder
            var client = new LMemLoopbackService.Client(protocol);
            sw.Stop();
            Console.WriteLine("Creating a client:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Connect!
            sw.Reset();
            sw.Start();
            transport.Open();
            sw.Stop();
            Console.WriteLine("Opening connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Allocate and send input streams to server
            sw.Reset();
            sw.Start();
            var address_inA = client.malloc_int32_t(size);
            client.send_data_int32_t(address_inA, inA);

            var address_inB = client.malloc_int32_t(size);
            client.send_data_int32_t(address_inB, inB);
            sw.Stop();
            Console.WriteLine("Sending input data:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Allocate memory for output stream on server
            sw.Reset();
            sw.Start();
            var address_outData = client.malloc_int32_t(size);
            sw.Stop();
            Console.WriteLine("Allocating memory for output stream on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Writing to LMem
            sw.Reset();
            sw.Start();
            client.LMemLoopback_writeLMem(0, sizeBytes, address_inA);
            client.LMemLoopback_writeLMem(sizeBytes, sizeBytes, address_inB);
            sw.Stop();
            Console.WriteLine("Writing to LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Action default
            sw.Reset();
            sw.Start();
            client.LMemLoopback(size);
            sw.Stop();
            Console.WriteLine("LMemLoopback time:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Reading from LMem
            sw.Reset();
            sw.Start();
            client.LMemLoopback_readLMem(2 * sizeBytes, sizeBytes, address_outData);
            sw.Stop();
            Console.WriteLine("Reading from LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Get output stream from server
            sw.Reset();
            sw.Start();
            outData = client.receive_data_int32_t(address_outData, size);
            sw.Stop();
            Console.WriteLine("Getting output stream:\t(size = {0} bit)\t{1}s", size * 32, sw.Elapsed.TotalMilliseconds / 1000);

            // Free allocated memory for streams on server
            sw.Reset();
            sw.Start();
            client.free(address_inA);
            client.free(address_inB);
            client.free(address_outData);
            sw.Stop();
            Console.WriteLine("Freeing allocated memory for streams on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Close!
            sw.Reset();
            sw.Start();
            transport.Close();
            sw.Stop();
            Console.WriteLine("Closing connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);
        }
        catch (SocketException e)
        {
            Console.WriteLine("Could not connect to the server: {0}.", e.Message);
            Environment.Exit(-1);
        }
        catch (Exception e)
        {
            Console.WriteLine("An error occured: {0}", e.Message);
            Environment.Exit(-1);
        }

        return outData;
    }
    /// <summary> Vector addition on DFE </summary>
    /// <param name = "size"> Size of arrays </param>
    /// <param name = "firstVector"> First vector </param>
    /// <param name = "secondVector"> Second vector </param>
    /// <param name = "scalar"> Scalar parameter </param>
    /// <returns> Data output </returns>
    public static List<int> VectorAdditionDfe(int size, List<int> firstVector, List<int> secondVector, int scalar)
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();

        // Make socket
        var transport = new TSocket("localhost", 9090);

        // Wrap in a protocol
        var protocol = new TBinaryProtocol(transport);

        // Create a client to use the protocol encoder
        var client = new VectorAdditionService.Client(protocol);

        sw.Stop();
        Console.WriteLine("Creating a client:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

        List<int> dataOut = new List<int>();

        try
        {
            // Connect!
            sw.Reset();
            sw.Start();
            transport.Open();
            sw.Stop();
            Console.WriteLine("Opening connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Allocate and send input streams to server
            sw.Reset();
            sw.Start();
            var address_x = client.malloc_int32_t(size);
            client.send_data_int32_t(address_x, firstVector);

            var address_y = client.malloc_int32_t(size);
            client.send_data_int32_t(address_y, secondVector);
            sw.Stop();
            Console.WriteLine("Sending input data:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Allocate memory for output stream on server
            sw.Reset();
            sw.Start();
            var address_out = client.malloc_float(size);
            sw.Stop();
            Console.WriteLine("Allocating memory for output stream on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Writing to LMem
            sw.Reset();
            sw.Start();
            client.VectorAddition_writeLMem(0, size * 4, address_x);
            sw.Stop();
            Console.WriteLine("Writing to LMem:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Action default
            sw.Reset();
            sw.Start();
            client.VectorAddition(scalar, size, address_y, address_out);
            sw.Stop();
            Console.WriteLine("Vector addition time:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Get output stream from server
            sw.Reset();
            sw.Start();
            dataOut = client.receive_data_int32_t(address_out, size);
            sw.Stop();
            Console.WriteLine("Getting output stream:\t(size = {0} bit)\t{1}s", size * 32, sw.Elapsed.TotalMilliseconds / 1000);

            // Free allocated memory for streams on server
            sw.Reset();
            sw.Start();
            client.free(address_x);
            client.free(address_y);
            client.free(address_out);
            sw.Stop();
            Console.WriteLine("Freeing allocated memory for streams on server:\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);

            // Close
            sw.Reset();
            sw.Start();
            transport.Close();
            sw.Stop();
            Console.WriteLine("Closing connection:\t\t\t\t{0}s", sw.Elapsed.TotalMilliseconds / 1000);
        }
        catch (SocketException e)
        {
            Console.WriteLine("Could not connect to the server: {0}.", e.Message);
            Environment.Exit(-1);
        }
        catch (Exception e)
        {
            Console.WriteLine("An error occured: {0}", e.Message);
            Environment.Exit(-1);
        }

        return dataOut;
    }