Esempio n. 1
0
        public void CallMethod(MethodDescriptor method, IRpcController controller, IMessage request, IMessage responsePrototype, Action<IMessage> done)
        {
            uint hash = method.Service.GetHash();
            ExternalService externalService = exportedServicesIds[hash];

            var requestId = externalService.GetNextRequestId();
            callbacks.Enqueue(new Callback { Action = done, Builder = responsePrototype.WeakToBuilder(), RequestId = requestId });

            ServerPacket data = new ServerPacket(externalService.Id, (int)GetMethodId(method), requestId, ListenerId).WriteMessage(request);
            Send(data);
        }
Esempio n. 2
0
        private void Send(ServerPacket packet)
        {
            byte[] data = packet.Data;
            IMessage msg = packet.Message;

            // Logging
            Console.WriteLine("BN: Sending data: length = {0}", data.Length);
            Console.WriteLine(msg.DescriptorForType.FullName);

            Console.WriteLine("HEX View:");
            data.PrintHex();

            Console.WriteLine("Text View:");
            Console.WriteLine(msg.ToString());

            this.stream.Write(data, 0, data.Length);
        }
Esempio n. 3
0
        private void Handle(CodedInputStream stream)
        {
            var packet = new ClientPacket(stream);

            if (packet.Service == PrevService)
            {
                //packet.Method should be 0, if there is no errors
                Callback callback = callbacks.Dequeue();
                if (callback.RequestId != packet.RequestId)
                    throw new InvalidOperationException("Callback does not match!");
                callback.Action(packet.ReadMessage(callback.Builder));
                return;
            }

            IService service = importedServices[packet.Service];

            MethodDescriptor method = service.DescriptorForType.Methods.Single(m => GetMethodId(m) == packet.Method);

            Action<IMessage> done =
                response =>
                {
                    ServerPacket data = new ServerPacket(PrevService, (int)ErrorCode, packet.RequestId, 0).WriteMessage(response);
                    Send(data);
                    if (ErrorCode != AuthError.None)
                    {
                        DisconnectNotification dcNotify = DisconnectNotification.CreateBuilder().SetErrorCode((uint)ErrorCode).Build();
                        ConnectionService.CreateStub(this).ForceDisconnect(null, dcNotify, r => { });
                        Disconnect();
                    }
                };

            IMessage requestProto = service.GetRequestPrototype(method);

            IMessage message = packet.ReadMessage(requestProto.WeakToBuilder());

            // Logging
            Console.WriteLine(requestProto.GetType());
            Console.WriteLine("Text View:");
            Console.WriteLine(message.ToString());

            service.CallMethod(method, null, message, done);
        }