Ejemplo n.º 1
0
        /// <summary>
        /// Calls the specified method with the specified arguments using the specified means of communication.
        /// </summary>
        /// <param name="communication">The means of communication with the server.</param>
        /// <param name="service">The Thrift service containing the method.</param>
        /// <param name="methodName">The .NET method name.</param>
        /// <param name="args">The method arguments.</param>
        /// <returns>The method result.</returns>
        internal static async Task <T> CallMethodAsync <T>(ThriftCommunication communication, ThriftService service, string methodName, params object[] args)
        {
            // The attributes parser guarantees that there are 0 or 1 tokens per method
            var token = args.OfType <CancellationToken>().FirstOrDefault();

            using (var protocol = communication.CreateProtocol(token))
            {
                var method     = service.Methods[methodName];
                var methodArgs = args.Where(a => !(a is CancellationToken)).ToArray();

                for (int n = 0; n < methodArgs.Length; n++)
                {
                    if (methodArgs[n] == null)
                    {
                        throw ThriftSerializationException.NullParameter(method.Parameters[n].Name);
                    }
                }

                ThriftClientMessageWriter.Write(method, methodArgs, protocol);

                await protocol.FlushAndReadAsync();

                if (method.IsOneWay)
                {
                    return(default(T));
                }

                return(ThriftClientMessageReader.Read <T>(method, protocol));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a proxy for the specified interface type using the specified protocol.
        /// </summary>
        /// <typeparam name="T">The interface type.</typeparam>
        /// <param name="communication">The means of communication with the server.</param>
        /// <returns>A dynamically generated proxy to the Thrift service.</returns>
        public static T Create <T>(ThriftCommunication communication)
        {
            var proxy = DispatchProxy.Create <T, Implementation>();

            var proxyAsImpl = (Implementation)(object)proxy;

            proxyAsImpl.Communication = communication;
            proxyAsImpl.Service       = ThriftAttributesParser.ParseService(typeof(T).GetTypeInfo());

            return(proxy);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the ThriftCommunication class as a second part of the build step with the specified transport factory.
 /// </summary>
 private ThriftCommunication(ThriftCommunication comm, Func <CancellationToken, IThriftTransport> transportCreator)
 {
     _protocolCreator  = comm._protocolCreator;
     _transportCreator = transportCreator;
 }