Exemplo n.º 1
0
        public static void InitEventServer()
        {
            var eventServer = new EventServer(GetIpAddress());

            eventServer.Start();

            var eventClient1 = new EventClient(GetIpAddress());

            eventClient1.AddToGroup("Task", "Random");
            eventClient1.Connect();
            eventClient1.PublishEvent += (s, a) =>
            {
                Console.WriteLine("CLIENT1: " + a.Arguments.ToString());
            };

            var eventClient2 = new EventClient(GetIpAddress());

            eventClient2.Connect();
            eventClient2.AddToGroup("Task");
            eventClient2.PublishEvent += (s, a) =>
            {
                Console.WriteLine("CLIENT2: " + a.Arguments.ToString());
            };

            var eventClient3 = new EventClient(GetIpAddress());

            eventClient3.Connect();
            eventClient3.AddToGroup("Task", "Random");
            eventClient3.PublishEvent += (s, a) =>
            {
                Console.WriteLine("CLIENT3: " + a.Arguments.ToString());
            };

            while (true)
            {
                eventClient1.SendEventToAll(new CustomEventData()
                {
                    FirstName = "Event to All",
                    LastName  = "B"
                });
                eventClient1.SendEventToOthers(new CustomEventData()
                {
                    FirstName = "Event To Others",
                    LastName  = "D"
                });
                eventClient1.SendEventToAllInGroup(new CustomEventData()
                {
                    FirstName = "Event to all in Group Task",
                    LastName  = "D"
                }, "Task");
                eventClient1.SendEventToRandomInGroup(new CustomEventData()
                {
                    FirstName = "Event to random in Group Random",
                    LastName  = "D"
                }, "Random");

                Console.WriteLine("Message sent");
                Console.ReadLine();
            }
        }