Exemplo n.º 1
0
        void MainForm_Load(object sender, EventArgs e)
        {
            log.InfoFormat("Manager is starting...");
            var name   = GetType().Name;
            var client = new RabbitBroker();

            client.Open();
            Client = client;
            log.InfoFormat("Manager is started!");
            var id = client.Id;

            client.Subscribe <HelloMessage>(id.Broad, OnResponse);
            foreach (var pair in AddinExtensions.GetFiltered <ResponseDescAttribute, IResponse>())
            {
                var resp     = pair.Value;
                var rType    = resp.GetType();
                var subName  = nameof(client.Subscribe);
                var subMeth  = client.GetType().GenericMe(subName, rType);
                var hndlMeth = GetType().GenericMe(nameof(OnResponse), rType);
                var act      = typeof(Action <,>).MakeGenericType(typeof(IIdentity), rType);
                var dlgt     = Delegate.CreateDelegate(act, this, hndlMeth);
                Invoke(client, subMeth, id.Uni, dlgt, rType);
                Invoke(client, subMeth, id.Multi, dlgt, rType);
            }
        }
Exemplo n.º 2
0
        static void ServerLoop(object state)
        {
            var addr   = (ITransfer)state;
            var server = new RabbitBroker();

            server.Open();
            Thread.Sleep(2 * 1000);
            server.Subscribe <string>(addr, (s, m) => Console.WriteLine($"{s.Uni} => {m}"));
        }
Exemplo n.º 3
0
        static void ClientLoop(object state)
        {
            var addr   = (ITransfer)state;
            var client = new RabbitBroker();

            client.Open();
            Thread.Sleep(3 * 1000);
            client.Publish(addr, $"Hello, I am a client ({addr})");
        }
Exemplo n.º 4
0
        public void Start()
        {
            Handlers = new Dictionary <Type, IRequestHandler>();
            log.InfoFormat("Service is starting...");
            var name   = GetType().Name;
            var client = new RabbitBroker();

            client.Open();
            Client = client;
            log.InfoFormat("Service is started!");
            var id = client.Id;

            client.Publish(id.Broad, new HelloMessage
            {
                Machine = Environment.MachineName,
                User    = Environment.UserName,
                Local   = client.LocalEndpoint.ToShortString(),
                Remote  = client.RemoteEndpoint.ToShortString()
            });
            foreach (var pair in AddinExtensions.GetFiltered <ReqHandlerFilterAttribute, IRequestHandler>())
            {
                var handler  = pair.Value;
                var intfName = typeof(IRequestHandler <>).Name;
                foreach (var intf in handler.GetType().GetInterfaces())
                {
                    if (!(intf.Name.Equals(intfName)))
                    {
                        continue;
                    }
                    var reqType = intf.GetGenericArguments()[0];
                    GetType().GenericMe(nameof(Subscribe), reqType).Invoke(this, null);
                    log.InfoFormat("Found '{0}' for '{1}'.", handler, reqType);
                    Handlers[reqType] = handler;
                }
            }
        }