Пример #1
0
        static void Main(string[] args)
        {
            Console.Title = "Resonance Shared Memory Demo";

            Console.WriteLine("Resonance Shared Memory Demo.");
            Console.WriteLine();

            Console.Write("Adapter Address: ");
            String address = Console.ReadLine();

            Console.WriteLine("Connecting...");

            IResonanceTransporter transporter = ResonanceTransporter.Builder
                                                .Create()
                                                .WithSharedMemoryAdapter()
                                                .WithAddress(address)
                                                .WithJsonTranscoding()
                                                .Build();

            transporter.StateChanged += (_, e) =>
            {
                if (e.NewState == ResonanceComponentState.Failed)
                {
                    Console.WriteLine();
                    Console.WriteLine($"Transporter Disconnected.\n{transporter.FailedStateException.Message}");
                }
            };

            transporter.RegisterMessageHandler <SharedMemoryMessage>((t, msg) =>
            {
                Console.WriteLine();
                Console.WriteLine($"Message Received: {msg.Object.Text}");
                Console.Write("Send Message: ");
            });

            transporter.Connect();

            Console.WriteLine("Connected.");

            while (true)
            {
                Console.Write("Send Message: ");
                String text = Console.ReadLine();

                if (text.ToLower() == "exit")
                {
                    Console.WriteLine("Disconnecting...");
                    transporter.Disconnect();
                    Console.ReadLine();
                    return;
                }

                transporter.Send(new SharedMemoryMessage()
                {
                    Text = text
                });
            }
        }
Пример #2
0
        protected override bool TrySetMember(Type interfaceType, string name, object value)
        {
            ResonanceMessageConfig config = new ResonanceMessageConfig();

            var prop = interfaceType.GetProperty(name);
            var att  = prop.GetRpcAttribute();

            if (att != null)
            {
                config = att.ToMessageConfig();
            }

            config.RPCSignature = RPCSignature.FromMemberInfo(prop);
            config.RequireACK   = true;

            _transporter.Send(value, config);
            return(true);
        }