Ejemplo n.º 1
0
        public static void Subscribe(MessageTopics messageName, UnityAction <Message> subscriber)
        {
            // Check if action is anonymous
            if (subscriber.Method.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Any())
            {
                Debug.LogError("An anonymous method is trying to register a message bus subscription without providing an ID. This is not allowed since it would be impossible to cancel subscription. Get your shit together!");
            }
            ;

            SubscribeWithId(messageName, subscriber, "");
        }
Ejemplo n.º 2
0
        private void MainPage_Load(object sender, EventArgs e)
        {
            usernameLabel.Text = LoginForm.user.Login;
            this.Text          = "Welcome to the chat application " + usernameLabel.Text;

            //Ask for the list of topics
            MessageTopics topics = (MessageTopics)Net.receiveMessage(comm.GetStream());

            foreach (Topic t in topics.Topics)
            {
                this.topicList.Items.Add(t);
            }
        }
Ejemplo n.º 3
0
        public static void PublishNews <T>(MessageTopics topic, T message)
        {
            var registration = messageRegistrations.FirstOrDefault(s => s.Topic == topic);

            if (registration == null)
            {
                if (!GameSettings.Instance.MutedTopics.HasFlag(topic))
                {
                    Debug.LogWarning($"Message has been posted but no one is listening! MessageName{topic}");
                    return;
                }
            }


            registration.PublishThis <T> (message);
        }
Ejemplo n.º 4
0
        public void displayTopics()
        {
            MessageTopics topics = (MessageTopics)Net.receiveMessage(comm.GetStream());

            Console.WriteLine("\t\t" + topics.Topics.Count + " topics are online");

            //Display the topic's titles
            int i = 1;

            foreach (Topic t in topics.Topics)
            {
                Console.WriteLine("\t\t" + i + ". " + t.Title);
                i++;
            }

            joinTopic();
        }
Ejemplo n.º 5
0
        public static void SubscribeWithId(MessageTopics messageName, UnityAction <Message> subscriber, string id)
        {
            // Make sure this id does not subsribe to this message alreaedy
            if (messageRegistrations.Any(s => s.Topic == messageName && s.CheckForSubscriber(subscriber)))
            {
                Debug.LogWarning($"subscriber is trying to subsribe to a topic that its already subscribed to! Subscriber ID :{id} Message name :{messageName}  ");
                return;
            }

            MessageType messageType = messageRegistrations.FirstOrDefault(s => s.Topic == messageName);

            if (messageType == null)
            {
                messageType = new MessageType(messageName, id, subscriber);
                messageRegistrations.Add(messageType);
                return;
            }

            messageType.AddSubscriber(id, subscriber);
        }
Ejemplo n.º 6
0
        private void sendButton_Click(object sender, EventArgs e)
        {
            Topic topic = (Topic)this.topicList.SelectedItem;

            //Notify that it's a messageTopic that we are sending
            Net.sendMessage(comm.GetStream(), new MessageTopic(topic, messageTextBox.Text, user));

            //Send the actual message Topic
            Net.sendMessage(comm.GetStream(), new MessageTopic(topic, messageTextBox.Text, user));

            MessageTopic topicReceived = (MessageTopic)Net.receiveMessage(comm.GetStream());

            messageTextBox.Text = string.Empty;

            //Update objects of the listBox of topics
            MessageTopics topics = (MessageTopics)Net.receiveMessage(comm.GetStream());

            this.topicList.Items.Clear();


            int i = 0;
            int j = 0;

            foreach (Topic t in topics.Topics)
            {
                this.topicList.Items.Add(t);
                if (t.Id_topic == topicReceived.Topic.Id_topic)
                {
                    i = j;
                }
                j++;
            }


            this.topicList.SelectedIndex = i;
        }
Ejemplo n.º 7
0
 public static void UnSubscribeById(MessageTopics messageName, string id)
 {
     messageRegistrations.Where(mr => mr.Topic == messageName).ToList()
     .ForEach(s => s.RemoveSubscriberByKey(id));
 }
Ejemplo n.º 8
0
        public static void UnSubscribe(MessageTopics messageName, UnityAction <Message> subscriber)
        {
            var subscription = messageRegistrations.FirstOrDefault(s => s.Topic == messageName);

            subscription.RemoveSubscriberBysubscriber(subscriber);
        }
Ejemplo n.º 9
0
 public void ClearSolo()
 {
     SoloTopics = 0;
 }
Ejemplo n.º 10
0
 public MessageType(MessageTopics topic, string subscriberId, UnityAction <Message> subscriber)
 {
     Topic = topic;
     Subscribers.Add(subscriberId, subscriber);
     Debug.Log($"Added subscriber ID {subscriberId}. Total subscribers: {Subscribers.Count ()}");
 }