Пример #1
0
        internal static object Deserialize(string clientFunction, byte[] data)
        {
            var        serialstream = new MemoryStream(data);
            TTransport transport    = new TStreamTransport(serialstream, serialstream);

            transport.Open();
            TProtocol  protocol        = new TCompactProtocol(transport);
            var        client          = new TalkService.Client(protocol);
            MethodInfo callingFunction = client.GetType().GetMethod(clientFunction);

            //Magic to redirect the possible exception to the end user's code
            //or at least the nearest TalkException catch
            try
            {
                return(callingFunction.Invoke(client, null));
            }
            catch (TargetInvocationException E)
            {
                if (E.InnerException is TalkException)
                {
                    throw E.InnerException;
                }
            }
            return(null);
        }
Пример #2
0
        internal static byte[] SerializeOperation(Operation O)
        {
            var        serialstream = new MemoryStream(4096);
            TTransport transport    = new TStreamTransport(serialstream, serialstream);

            transport.Open();
            TProtocol protocol = new TCompactProtocol(transport);
            var       client   = new TalkService.Client(protocol);

            //.MakeGenericMethod(
            //hook.Invoke(Client, parameters);

            O.Write(protocol);


            byte[] data = serialstream.ToArray();
            //MemoryStream serialstream = new MemoryStream(4096);
            //TTransport transport = new TStreamTransport(serialstream, serialstream); transport.Open();


            return(data);
        }
Пример #3
0
        //This shit only exists because the internal LINE client transport doesn't handle
        //more than a single connection at a time, so if it was being used for long polling,
        //we'd be f****d because it would probably freeze the entire thing and prevent any
        //other calls from happening. It's not something I'm proud to have written but it
        //works wonders if you need to call something in parallel. It's just expensive. :O

        internal static byte[] Serialize(string clientFunction, object[] parameters)
        {
            var        serialstream = new MemoryStream(4096);
            TTransport transport    = new TStreamTransport(serialstream, serialstream);

            transport.Open();
            TProtocol protocol = new TCompactProtocol(transport);
            var       client   = new TalkService.Client(protocol);

            //.MakeGenericMethod(
            //hook.Invoke(Client, parameters);
            MethodInfo callingFunction = client.GetType().GetMethod(clientFunction);

            callingFunction.Invoke(client, parameters);

            byte[] data = serialstream.ToArray();
            //MemoryStream serialstream = new MemoryStream(4096);
            //TTransport transport = new TStreamTransport(serialstream, serialstream); transport.Open();


            return(data);
        }
Пример #4
0
        static void Main(string[] args)
        {
            if (args.Length < 4)
            {
                Console.WriteLine("server [ns] [hc] [keyname] [key]");
                return;
            }

            var ns      = args[0];
            var hc      = args[1];
            var keyname = args[2];
            var key     = args[3];

            var tokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(keyname, key);
            var sendAddress   = new Uri($"sb://{ns}/{hc}");
            var relayClient   = new HybridConnectionClient(sendAddress, tokenProvider);

            try
            {
                var relayConnection = relayClient.CreateConnectionAsync().GetAwaiter().GetResult();

                TTransport        transport = new TStreamTransport(relayConnection, relayConnection);
                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);
            }
        }
Пример #5
0
        public async Task Run(string sendAddress, string sendToken)
        {
            try
            {
                var relayClient     = new RelayClient(sendAddress, TokenProvider.CreateSharedAccessSignatureTokenProvider(sendToken));
                var relayConnection = relayClient.Connect();

                TTransport        transport = new TStreamTransport(relayConnection, relayConnection);
                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);
            }
        }
Пример #6
0
        internal static object Deserialize(string ClientFunction, byte[] data)
        {
            MemoryStream serialstream = new MemoryStream(data);
            TTransport   transport    = new TStreamTransport(serialstream, serialstream); transport.Open();
            TProtocol    protocol     = new TCompactProtocol(transport);

            TalkService.Client Client          = new TalkService.Client(protocol);
            MethodInfo         CallingFunction = Client.GetType().GetMethod(ClientFunction);

            try
            {
                return(CallingFunction.Invoke(Client, null));
            }
            catch (TargetInvocationException E)
            {
                if (E.InnerException is TalkException)
                {
                    throw E.InnerException;
                }
            }
            return(null);
        }