Exemple #1
0
        //Threads to manage the conversation
        public void printConversation(object topic)
        {
            Topic topicReceived = (Topic)topic;

            Console.WriteLine("\t\t*** Last conversation ***");
            topicReceived.printTheConversations();

            while (true)
            {
                Message msg = Net.receiveMessage(comm.GetStream());
                if (msg.GetType().Name.Equals("MessageTopic"))
                {
                    MessageTopic receivedTopic = (MessageTopic)msg;

                    Console.WriteLine("Updated topic " + receivedTopic.Topic.Title);
                    Console.WriteLine("------------------------------------------------------");
                    receivedTopic.Topic.printTheConversations();

                    Console.WriteLine("Send a message : ");
                }
                else if (msg.GetType().Name.Equals("MessageNavigation"))
                {
                    break;
                }
            }
        }
        public static void SendEmailAsync(List <User> users, MessageTopic topic, string datastring = null,
                                          string message = null)
        {
            MailMessage email = new MailMessage
            {
                From =
                    new MailAddress(Settings.Smtp.Network.UserName, "Администрация столовой", System.Text.Encoding.UTF8)//,
                    //DeliveryNotificationOptions =
                    //    DeliveryNotificationOptions.OnFailure
            };

            users.Where(u => !u.Email.IsNullOrWhiteSpace()).ForEach(u =>
            {
                email.To.Add(new MailAddress(u.Email, u.LastName + " " + u.FirstName));
            });
            string template = EMailTemplate(topic).Result;

            email.Body    = string.Format(template, datastring, message);
            email.Subject = (topic == MessageTopic.MenuChanged)
                ? "Изменения в меню"
                : topic == MessageTopic.Registration
                    ? "Регистрация"
                    : "Создано меню для заказа";

            email.IsBodyHtml = true;
            try
            {
                Client.Send(email);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #3
0
        protected void RaiseMessageReceived(NetMQFrame topic, NetMQFrame value)
        {
            var          handler = MessageReceived;
            MessageTopic mt      = (MessageTopic)Enum.Parse(typeof(MessageTopic), topic.ConvertToString());

            handler?.Invoke(this, new StockTVMessageReceivedEventArgs(mt, value.ToByteArray(true)));
        }
        public void PublishTestDifferentMessageTypes()
        {
            var topic = new MessageTopic();

            object msgPublished = null;
            var    strPublished = false;

            topic.Register <object>()
            .Subscribe(o => msgPublished = o);
            topic.Register <string>()
            .Subscribe(_ => strPublished = true);

            var msg = new object();

            topic.Publish(msg);

            Assert.Equal(msg, msgPublished);
            Assert.False(strPublished);

            const string msgStr = "TestMsg";

            topic.Publish(msgStr);

            Assert.Equal(msgStr, msgPublished);
            Assert.True(strPublished);
        }
        public List<MoniverseNotification> GetNotificationsForGame(string gameId, MessageTopic Topic, NotificationLevel Level, DateTime start, DateTime end)
        {
            List<MoniverseNotification> notificationList = new List<MoniverseNotification>();
            string topic;
            string level = "Info";

            switch (Topic) {
                case MessageTopic.All:
                    topic = "Error";
                    break;
                default:
                    topic = Topic.ToString();
                    break;
            }

            string query = String.Format(@"select * from {5}
                                            WHERE GameID = '{0}'
                                            -- AND Topic = '{1}'
                                            -- AND Level = '{2}'
                                            AND CreatedAt BETWEEN '{3}' AND '{4}'
                                            ORDER BY CreatedAt DESC;",
                                       gameId,
                                       topic,
                                       level,
                                       start.ToString("yyyy-MM-dd HH:mm:ss"),
                                       end.ToString("yyyy-MM-dd HH:mm:ss"),
                                       NotificationTable
                                       );

            notificationList = DBManager.Instance.Query<MoniverseNotification>(Datastore.Monitoring, query).ToList<MoniverseNotification>();

            return notificationList;
        }
Exemple #6
0
        public void connectedActions(object firstTime)
        {
            bool firstTimeApp = (bool)firstTime;

            //Send all the info about the topics and convs...
            if (firstTimeApp == true)
            {
                firstTime = false;
                Net.sendMessage(comm.GetStream(), new MessageTopics(topics));
            }


            //Receive an action
            Message messageMainPage = Net.receiveMessage(comm.GetStream());

            if (messageMainPage.GetType().Name.Equals("MessageTopic"))
            {
                MessageTopic messageTopic = (MessageTopic)messageMainPage;


                foreach (Topic t in topics)
                {
                    if (t.Id_topic == messageTopic.Topic.Id_topic)
                    {
                        //Create the thread to display messages
                        Thread displayTopicThread = new Thread(new ParameterizedThreadStart(displayTopic));
                        displayTopicThread.Start(t);
                    }
                }
            }
        }
Exemple #7
0
        public void PublishTestBeforeRegisterGeneric()
        {
            var topic = new MessageTopic <object>();

            object objPublished = null;

            topic.Register <object>().Subscribe(o => objPublished = o);

            var obj = new object();

            topic.Publish(obj);

            object secondObjPublished = null;

            topic.Register <object>().Subscribe(o => secondObjPublished = o);

            Assert.Equal(obj, objPublished);

            Assert.Null(secondObjPublished);

            var obj2 = new object();

            topic.Publish(obj2);

            Assert.Equal(obj2, objPublished);
            Assert.Equal(obj2, secondObjPublished);
        }
Exemple #8
0
 public GameMessage(string fromEntityId, string toEntityId, MessageTopic topic, object payload)
 {
     FromEntityId = fromEntityId;
     ToEntityId   = toEntityId;
     Topic        = topic;
     Payload      = payload;
 }
        public Notifier(string gameId, MessageTopic topic, MoniverseNotification notification, NotificationLevel level = NotificationLevel.Info)
        {
            GameId = gameId;
            message = notification;
            NotificationId = notification.Id;
            Topic = topic;
            Level = level;

            switch (topic)
            {
                case MessageTopic.Error:
                    message.ARN = NotificationTopics.ServiceError;
                    if (level == NotificationLevel.Error)
                    {
                        message.ARN = NotificationTopics.ServiceError;
                    }
                    break;
                case MessageTopic.Users:
                    message.ARN = NotificationTopics.ServiceError;
                    break;
                case MessageTopic.Game:
                    break;
                case MessageTopic.Hosting:
                    break;

            }
        }
Exemple #10
0
        public void PublishTest()
        {
            var topic = new MessageTopic <object>();

            topic.Publish("Test");

            Assert.Throws <ArgumentNullException>(() => topic.Publish(null));
        }
 public Category(string a, MessageType messageType, MessageTopic messageTopic)
 {
     typ               = a;
     messagetype       = (int)messageType;
     messagetopic      = (int)messageTopic;
     this.messageType  = messageType;
     this.messageTopic = messageTopic;
 }
Exemple #12
0
            private void ResultSubscriber_ReceiveReady(object sender, NetMQSocketEventArgs e)
            {
                var message = (e.Socket as SubscriberSocket).ReceiveMultipartMessage();

                if (message.FrameCount >= 2)
                {
                    MessageTopic topic = (MessageTopic)Enum.Parse(typeof(MessageTopic), message[0].ConvertToString());
                    byte[]       value = message[1].ToByteArray();

                    messageReceiveAction?.Invoke(topic, value);
                }
            }
        public void displayTopic(object topicObject)
        {
            Topic topic = (Topic)topicObject;

            while (true)
            {
                Message msg = Net.receiveMessage(comm.GetStream());

                if (msg.GetType().Name.Equals("MessageTopic"))
                {
                    if (msg == null)
                    {
                        Console.WriteLine("Client stopped responding");
                        comm.Dispose();
                        return;
                    }
                    MessageTopic clientMessage = (MessageTopic)msg;

                    Conversation conv = new Conversation(clientMessage.Message, clientMessage.UserSender);

                    topic.Conversation.Add(conv);
                    topic.Number_messages += 1;

                    //Check for the clients we want to send the message to
                    foreach (KeyValuePair <User, List <TcpClient> > myClients in userTcps)
                    {
                        foreach (User u in topic.Chatters)
                        {
                            if (myClients.Key.Login.Equals(u.Login))
                            {
                                foreach (TcpClient tcp in myClients.Value)
                                {
                                    Net.sendMessage(tcp.GetStream(), new MessageTopic(topic));
                                    Console.WriteLine("\n *** Sending to " + tcp.Client.RemoteEndPoint + " ***");
                                    Console.WriteLine("Message received : " + clientMessage.Message + "\nFor the topic : " + clientMessage.Topic.Title + " from : " + clientMessage.UserSender.Login);
                                }
                            }
                        }
                    }
                }
                else if (msg.GetType().Name.Equals("MessageNavigation"))
                {
                    Console.WriteLine("Exit Topic for " + user.Login);

                    //Check for the clients we want to send the message to
                    topic.Chatters.Remove(user);
                    Net.sendMessage(comm.GetStream(), new MessageNavigation(user, "-1"));
                    break;
                }
            }
            connectedActions();
        }
Exemple #14
0
        public void RegisterTest()
        {
            var topic = new MessageTopic <object>();

            object msgPublished = null;

            topic.Register().Subscribe(o => msgPublished = o);

            var msg = new object();

            topic.Publish(msg);

            Assert.Equal(msg, msgPublished);
        }
        public static async Task <string> EMailTemplate(MessageTopic topic)
        {
            string template = topic == MessageTopic.MenuChanged
                ? "DayMenuChanged"
                : topic == MessageTopic.Registration ? "RegistrationCompleted" : "MenuCreateCompleted";
            var templateFilePath = HostingEnvironment.MapPath("~/Areas/SU_Area/Views/SU_/EmailTemplates/") + template +
                                   ".html";
            //string templateFilePath = AppDomain.CurrentDomain.BaseDirectory.Replace(@"UnitTestProject1\bin\Debug", @"ACSDining.Web\Areas\SU_Area\Views\SU_\EmailTemplates\") + template + ".html";
            string body;

            try
            {
                StreamReader objstreamreaderfile = new StreamReader(templateFilePath);
                body = objstreamreaderfile.ReadToEndAsync().Result;
                objstreamreaderfile.Close();
            }
            catch (Exception)
            {
                throw;
            }
            return(await Task.FromResult(body));
        }
Exemple #16
0
        public void displayTopic()
        {
            //Get the topic to display
            MessageTopic receivedTopic = (MessageTopic)Net.receiveMessage(comm.GetStream());
            Topic        topic         = receivedTopic.Topic;

            Console.WriteLine("\t\t*****************************************");
            Console.WriteLine("\t\t********** " + topic.Title + "***********");
            Console.WriteLine("\t\t*****************************************");

            printChatters(topic);
            printAuthor(topic);
            printNumber_message(topic);

            Thread printConversationThread = new Thread(new ParameterizedThreadStart(printConversation));

            printConversationThread.Start(topic);

            Thread sendMessageThread = new Thread(new ParameterizedThreadStart(sendMessage));

            sendMessageThread.Start(topic);
        }
        public async Task Publish(MessageTopic topic, ITraceable message, Guid correlationId)
        {
            message.CorrelationId = correlationId;
            var  queueName = topic.ToString().ToLowerInvariant();
            var  queue     = TableClient.GetQueueReference(queueName);
            bool retry;
            int  attempts = 0;

            do
            {
                retry = false;
                attempts++;

                try
                {
                    var msg = new CloudQueueMessage(JsonConvert.SerializeObject(message));
                    _logger.LogInformation($"Published message {queueName}:{message.CorrelationId}");
                    await queue.AddMessageAsync(msg);
                }
                catch (StorageException ex)
                {
                    _logger.LogError(ex, $"Error publishing message {queueName}:{message.CorrelationId}");
                    var ri = ex.RequestInformation;
                    if (ri.HttpStatusCode == 404) // if error response is 404 then queue does not exist
                    {
                        _logger.LogInformation($"Creating queue {queueName}");
                        await queue.CreateIfNotExistsAsync();

                        _logger.LogInformation($"Created queue {queueName} successfully");
                        retry = true;
                    }
                    else
                    {
                        throw;
                    }
                }
            } while (retry && attempts < 4);
        }
Exemple #18
0
        public void createTopic()
        {
            MessageTopic topic = (MessageTopic)Net.receiveMessage(comm.GetStream());

            Topic newTopic = topic.Topic;

            newTopic.Id_topic     = topics.Count + 1;
            newTopic.Conversation = new List <Conversation>();
            newTopic.Chatters     = new List <User>();

            topics.Add(newTopic);

            //Print the topics created
            Console.WriteLine("Table topics updated : ");

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

            connectedActions(false);
        }
Exemple #19
0
        public void displayTopic(object topicObject)
        {
            Topic topic = (Topic)topicObject;

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

            Conversation conv = new Conversation(clientMessage.Message, clientMessage.UserSender);

            topic.Conversation.Add(conv);
            topic.Number_messages += 1;

            Console.WriteLine("Yoyoyoyoyo");


            //Add the client associated with tcpClient
            foreach (KeyValuePair <User, List <TcpClient> > myClients in userTcps)
            {
                foreach (User u in topic.Chatters)
                {
                    if (myClients.Key.Login.Equals(u.Login))
                    {
                        foreach (TcpClient tcp in myClients.Value)
                        {
                            Net.sendMessage(tcp.GetStream(), new MessageTopic(topic));
                            Net.sendMessage(tcp.GetStream(), new MessageTopics(topics));
                            Console.WriteLine("\n *** Sending to " + tcp.Client.RemoteEndPoint + " ***");
                            Console.WriteLine("Message received : " + clientMessage.Message + "\nFor the topic : " + clientMessage.Topic.Title + " from : " + clientMessage.UserSender.Login);
                        }
                    }
                }
            }
            topic.printTheConversations();

            Thread connectedActionThread = new Thread(new ParameterizedThreadStart(connectedActions));

            connectedActionThread.Start(false);
        }
        public static void SendEmailAsync(List<User> users, MessageTopic topic, string datastring = null,
            string message = null)
        {
            
            MailMessage email = new MailMessage
            {
                From =
                    new MailAddress(Settings.Smtp.Network.UserName, "Администрация столовой", System.Text.Encoding.UTF8)//,
                //DeliveryNotificationOptions =
                //    DeliveryNotificationOptions.OnFailure
            };
            users.Where(u => !u.Email.IsNullOrWhiteSpace()).ForEach(u =>
            {
                email.To.Add(new MailAddress(u.Email, u.LastName + " " + u.FirstName));
            });
            string template = EMailTemplate(topic).Result;
            email.Body = string.Format(template, datastring, message);
            email.Subject = (topic == MessageTopic.MenuChanged)
                ? "Изменения в меню"
                : topic == MessageTopic.Registration
                    ? "Регистрация"
                    : "Создано меню для заказа";

            email.IsBodyHtml = true;
            try
            {
               
                Client.Send(email);
               
            }
            catch (Exception)
            {

                throw;
            }
        }
Exemple #21
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;
        }
Exemple #22
0
 public Category(string messageName, MessageType messageType, MessageTopic messageTopic)
 {
     _messageName  = messageName;
     _messageType  = messageType;
     _messageTopic = messageTopic;
 }
Exemple #23
0
 /// <summary>
 /// Конструктор класса категории
 /// </summary>
 /// <param name="name">
 /// Имя продукта
 /// </param>
 /// <param name="type">
 /// Тип сообщения
 /// </param>
 /// <param name="topic">
 /// Тема сообщения
 /// </param>
 public Category(string name, MessageType type, MessageTopic topic)
 {
     ProductName = name;
     Type        = type;
     Topic       = topic;
 }
Exemple #24
0
        protected void RaiseSubscriberMessageReceived(MessageTopic topic, byte[] value)
        {
            var handler = SubscriberMessageReceived;

            handler?.Invoke(this, new StockTVMessageReceivedEventArgs(topic, value));
        }
        public static async Task<string> EMailTemplate(MessageTopic topic)
        {
            string template = topic == MessageTopic.MenuChanged
                ? "DayMenuChanged"
                : topic == MessageTopic.Registration ? "RegistrationCompleted" : "MenuCreateCompleted";
            var templateFilePath = HostingEnvironment.MapPath("~/Areas/SU_Area/Views/SU_/EmailTemplates/") + template +
                                   ".html";
            //string templateFilePath = AppDomain.CurrentDomain.BaseDirectory.Replace(@"UnitTestProject1\bin\Debug", @"ACSDining.Web\Areas\SU_Area\Views\SU_\EmailTemplates\") + template + ".html";
            string body;
            try
            {
                StreamReader objstreamreaderfile = new StreamReader(templateFilePath);
                body = objstreamreaderfile.ReadToEndAsync().Result;
                objstreamreaderfile.Close();
            }
            catch (Exception)
            {

                throw;
            }
            return await Task.FromResult(body);
        }
Exemple #26
0
 public Category(string nameProduct, MessageType messageType, MessageTopic messageTopic)
 {
     NameProduct  = nameProduct;
     MessageType  = messageType;
     MessageTopic = messageTopic;
 }
Exemple #27
0
 public Category(string name, MessageType type, MessageTopic topic)
 {
     _name         = name;
     _messageType  = type;
     _messageTopic = topic;
 }
 public Category(string productName, MessageType messageType, MessageTopic messageTopic)
 {
     _productName  = productName;
     _messageType  = messageType;
     _messageTopic = messageTopic;
 }
        public List<MoniverseNotification> GetNotificationsForGame(string gameId, MessageTopic topic)
        {
            DateTime start = new DateTime(2015,01,01);

            return GetNotificationsForGame(gameId, topic, Level, start, DateTime.UtcNow);
        }
Exemple #30
0
 public Category(string title, MessageType messageType, MessageTopic messageTopic)
 {
     CurrentTitle        = title;
     CurrentMessageType  = messageType;
     CurrentMessageTopic = messageTopic;
 }
Exemple #31
0
 public void CtorTest()
 {
     var _ = new MessageTopic <object>();
 }
Exemple #32
0
 public Category(string message, MessageType type, MessageTopic topic)
 {
     Message = message;
     Type    = type;
     Topic   = topic;
 }
 public void CtorTest()
 {
     var _ = new MessageTopic();
 }
Exemple #34
0
 public Category(string name, MessageType type, MessageTopic topic)
 {
     this.name  = name;
     this.type  = type;
     this.topic = topic;
 }
Exemple #35
0
 public Category(string name, MessageType messageType, MessageTopic topic)
 {
     Name        = name;
     MessageType = messageType;
     Topic       = topic;
 }